Package: gauche
GAUCHEis a collaborative, open-source software library that aims to make state-of-the-art
probabilistic modelling and black-box optimisation techniques more easily accessible to scientific
experts in chemistry, materials science and beyond. We provide 30+ bespoke kernels for molecules, chemical reactions and proteins and illustrate how they can be used for Gaussian processes and Bayesian optimisation in 10+ easy-to-adapt tutorial notebooks.Overview|Getting Started|Documentation|Paper (NeurIPS 2023)What's New?GAUCHE has been accepted to theNeurIPS 2023 Main Track! More details forthcoming!Check out our newMolecular Preference LearningandPreferential Bayesian Optimisationnotebooks that show how you can use GAUCHE to learn the latent utility function of a human medicinal chemist from pairwise preference feedback!Check out our newSparse GP Regression for Big Molecular Datanotebook that shows how you can scale molecular GPs to thousands of data points with sparse inducing point kernels!OverviewGeneral-purpose Gaussian process (GP) and Bayesian optimisation (BO) libraries do not cater for molecular representations. Likewise, general-purpose molecular machine learning libraries do not consider GPs and BO. To bridge this gap, GAUCHE provides a modular, robust and easy-to-use framework of 30+ parallelisable and batch-GP-compatible implementations of string, fingerprint and graph kernels that operate on a range of widely-used molecular representations.KernelsStandard GP packages typically assume continuous input spaces of low and fixed dimensionality. This makes it difficult to apply them to common molecular representations: molecular graphs are discrete objects, SMILES strings vary in length and topological fingerprints tend to be high-dimensional and sparse. To bridge this gap, GAUCHE provides:Fingerprint Kernelsthat measure the similarity between bit/count vectors of descriptor by examining the degree to which their elements overlap.String Kernelsthat measure the similarity between strings by examining the degree to which their sub-strings overlap.Graph Kernelsthat measure between graphs by examining the degree to which certain substructural motifs overlap.RepresentationsGAUCHE supports any representation that is based on bit/count vectors, strings or graphs. For rapid prototyping and benchmarking, we also provide a range of standard featurisation techniques for molecules, chemical reactions and proteins:DomainRepresentationMoleculesECFP Fingerprints [1], rdkit Fragments, Fragprints, Molecular Graphs [2], SMILES [3], SELFIES [4]Chemical ReactionsOne-Hot Encoding, Data-Driven Reaction Fingerprints [5], Differential Reaction Fingerprints [6], Reaction SMARTSProteinsSequences, Graphs [7]ExtensionsIf there are any specific kernels or representations that you would like to see included in GAUCHE, please reach out or submit an issue/pull request.Getting StartedThe easiest way to get started with GAUCHE is to check out our tutorial notebooks:GP Regression on MoleculesBayesian Optimisation Over MoleculesMultioutput Gaussian Processes for Multitask LearningTraining GPs on GraphsSparse GP Regression for Big Molecular DataMolecular Preference LearningPreferential Bayesian OptimisationInstallationWe recommend using a conda virtual environment:git clone https://github.com/leojklarner/gauche.git
cd gauche

conda env create -f conda_env.yml

pip install --no-deps rxnfp
pip install --no-deps drfp
pip install transformers
pip install mordred

# optional for running tests
pip install gpflow grakelExample Usage: GP Regression on MoleculesFitting a GP model with a kernel from GAUCHE and using it to predict the properties of new molecules is as easy as this. For more detail, check out ourGP Regression on Molecules Tutorialand the corresponding section in theDocs.importgpytorchfrombotorchimportfit_gpytorch_modelfromgauche.kernels.fingerprint_kernels.tanimoto_kernelimportTanimotoKernelclassTanimotoGP(gpytorch.models.ExactGP):def__init__(self,train_x,train_y,likelihood):super(TanimotoGP,self).__init__(train_x,train_y,likelihood)self.mean_module=gpytorch.means.ConstantMean()self.covar_module=gpytorch.kernels.ScaleKernel(TanimotoKernel())defforward(self,x):mean_x=self.mean_module(x)covar_x=self.covar_module(x)returngpytorch.distributions.MultivariateNormal(mean_x,covar_x)# initialise GP likelihood, model and# marginal log likelihood objectivelikelihood=gpytorch.likelihoods.GaussianLikelihood()model=TanimotoGP(X_train,y_train,likelihood)mll=gpytorch.mlls.ExactMarginalLogLikelihood(likelihood,model)# fit GP with BoTorch in order to use# the LBFGS-B optimiser (recommended)fit_gpytorch_model(mll)# use the trained GP to get predictions and# uncertainty estimates for new moleculesmodel.eval()likelihood.eval()preds=model(X_test)pred_means,pred_vars=preds.mean,preds.varianceExample Usage: Bayesian Optimisation Over MoleculesTutorial (Bayesian Optimisation Over Molecules)Docsfrombotorch.models.gp_regressionimportSingleTaskGPfromgprotorch.kernels.fingerprint_kernels.tanimoto_kernelimportTanimotoKernel# We define our custom GP surrogate model using the Tanimoto kernelclassTanimotoGP(SingleTaskGP):def__init__(self,train_X,train_Y):super().__init__(train_X,train_Y,GaussianLikelihood())self.mean_module=ConstantMean()self.covar_module=ScaleKernel(base_kernel=TanimotoKernel())self.to(train_X)# make sure we're on the right device/dtypedefforward(self,x):mean_x=self.mean_module(x)covar_x=self.covar_module(x)returnMultivariateNormal(mean_x,covar_x)Citing GAUCHEIf GAUCHE is useful for your work please consider citing the following paper:@misc{griffiths2022gauche,title={GAUCHE: A Library for Gaussian Processes in Chemistry},author={Ryan-Rhys Griffiths and Leo Klarner and Henry B. Moss and Aditya Ravuri and Sang Truong and Bojana Rankovic and Yuanqi Du and Arian Jamasb and Julius Schwartz and Austin Tripp and Gregory Kell and Anthony Bourached and Alex Chan and Jacob Moss and Chengzhi Guo and Alpha A. Lee and Philippe Schwaller and Jian Tang},year={2022},eprint={2212.04450},archivePrefix={arXiv},primaryClass={physics.chem-ph}}References[1] Rogers, D. and Hahn, M., 2010.Extended-connectivity fingerprints. Journal of Chemical Information and Modeling, 50(5), pp.742-754.[2] Fey, M., & Lenssen, J. E. (2019).Fast graph representation learning with PyTorch Geometric. arXiv preprint arXiv:1903.02428.[3] Weininger, D., 1988.SMILES, a chemical language and information system. 1. Introduction to methodology and encoding rules.Journal of Chemical Information and Computer Sciences, 28(1), pp.31-36.[4] Krenn, M., Häse, F., Nigam, A., Friederich, P. and Aspuru-Guzik, A., 2020.Self-referencing embedded strings (SELFIES): A 100% robust molecular string representation. Machine Learning: Science and Technology, 1(4), p.045024.[5] Probst, D., Schwaller, P. and Reymond, J.L., 2022.Reaction classification and yield prediction using the differential reaction fingerprint DRFP. Digital Discovery, 1(2), pp.91-97.[6] Schwaller, P., Probst, D., Vaucher, A.C., Nair, V.H., Kreutter, D., Laino, T. and Reymond, J.L., 2021.Mapping the space of chemical reactions using attention-based neural networks. Nature Machine Intelligence, 3(2), pp.144-152.[7] Jamasb, A., Viñas Torné, R., Ma, E., Du, Y., Harris, C., Huang, K., Hall, D., Lió, P. and Blundell, T., 2022.Graphein-a Python library for geometric deep learning and network analysis on biomolecular structures and interaction networks. Advances in Neural Information Processing Systems, 35, pp.27153-27167.