This video demonstrates how to predict lipophilicity values for external SMILES strings using a pre-trained graph neural network model. The process involves loading the fine-tuned model, converting SMILES strings to graph representations using RDKit and PyTorch Geometric, creating batch information for single molecules, and performing inference with torch.no_grad() to disable gradient calculation. The function takes a list of SMILES strings as input, converts each to a graph, and returns predicted lipophilicity values. The demonstration shows that polar molecules (like alcohols) have lower lipophilicity values while non-polar hydrocarbons have higher values, confirming the model's ability to predict molecular properties based on their chemical structure.
Predicting Lipophilicity from SMILES Strings with PyTorch Geometric
Added:hello everyone as we are approaching the end of this data science project I want to show you how you can define a function to predict uh lipop filicity values for any external smile strings for that I have made another Google collab notebook named predict from smiles and uh what we are going to do real quick is like before install rdkit and pyto geometric along with that uh pandas uh we want to import as speed we want to import torch and uh we want to import this from Smiles method from torch geometric so let's go ahead and do that now this is uh again uh similar stuff we are defining a device here if GPU is available it will use that else it will just use the CPU now if you remember from our previous uh video uh we had this pytorch _ lipo _ final Google collab notebook where we uh use the fine-tuned parameters and eventually uh train the model and evaluated it and in the end we also after model training we also saved the model as model liore tune. PT so we are going to be using this tuned uh model for making predictions so coming back to predict from smilees notebook uh what I'm doing here is uh so I have already uploaded model _ tuned uh model and we are going to be loading this model using torch to load and this is the uh path where our model is located here and of course we want to give the map location so map uncore location equal to device it ensures that the model is loaded on the appropriate device so uh for evaluation we need to call this eval uh method and this is the most important part here so we are defining a function called predict underscore lipop filicity which which would take in argument as list of smile strings so there could be one two three or four smile strings as an input and in here we are just creating an empty uh list uh called predictions in which we will later on ADD our predictions so since uh we have a list of smiles we will iterate through each smile strings now if you remember again going back to this uh notebook here if you remember we generated graphs for the whole data set so this was the code for that and it is pretty much the same code uh which I am using here so I am iterating through each smile strings so the uh in the first iteration the first smile string will come in and from Smiles method which uh we have imported here of pyo geometric would convert this smile strings into graph and then uh we want to convert this integer x uh or node features into uh float values so that's what I'm doing in here and of course we want to push our data to the device now one thing that is different in here is we are adding badge information so again if you go back we have not really added any badge information instead we down here we uh uh did the train test split and then we used a data loader method of uh I torch for generating train loader and test loader and in that we gave the batch size so since we are just dealing with uh single smilees or couple of smile strings we just need to provide batch information right here so G do H is equal to uh torch to tensor and then 0 into g into uh number of uh nodes so this creates a batch tensor uh indicating that all nodes belong to a single graph uh so yeah this is uh really important here because uh the uh input for the model also includes uh the batch information so we need to provide information here indicating that all the nodes belong to just a single graph and then we will perform the prediction with torch uh do no grad uh basically this means uh we are disabling gradient calculation which reduces memory consumption and would speed up the computations during inference and then predictions would be stored in variable called PR and uh this is the model that we have loaded up here and then we will input all these node features Edge index and Edge attributes and badge information and then we will just grab the predic items of from the prediction so the numerical value that we'll get using PR dot uh items so yeah that would be appended to this empty list over here and in the uh end we will return the predictions so this is the function for predicting lipop filicity and then uh we want to uh use this function to know the lipop filicity so basically let's just uh uh uh randomly draw some molecules here uh in my scem here so what we are going to do is we are going to draw some molecules let's just draw one highly polar molecule like this and one some highly lipophilic molecule something like that let's just copy the smile strings here for this molecule copy as smiles and then on camra uh I am just uh creating a list containing uh two smiles here so uh and that uh variable would be external underscore Smiles so one I have already copied and second for this hydrocarbon here let's copy as Smiles so here so we have a list of smiles for which we want to predict the lipop filicity values uh containing two smile strings and I'm storing that as external uncore Smiles so all we need to uh do is uh call this predictor lipophilicity function and put in this list of smiles so we want to store these predictions as lipophilicity uncore predictions so what you can do is just uh command this one out and just run this code but before that we need to run all these lines of code as well so so after that let's just run this and after that if you just print this one out you will get the prediction so uh this value is for uh this alcoholic uh molecule here and this value is for this uh hydrocarbon now just to make things more clear what I have done here is um I have used a zip uh method in here which would zip the smiles and the corresponding lipophilicity values so let me show you what I mean here uh uh so what I've done here is just uh copied and pasted this uh line of code here and I am printing this as as a list so you can see here this is a basically a tupal and it has Smile strings and the corresponding lipop filicity value so we want to print both the smiles as well as the corresponding lipop Felicity value so what I have done here is for smilees spread in zipo and zipping these two values and then I am printing these smile strings and the corresponding predictions so if you run this here you can see we have the smile strings and uh the predicted lipophilicity so this is just uh more uh readable so yeah if we compare these two molecules since this is alcoholic this would be less lipophilic and this just has the carbons and hydrogens and no polar groups so this would be the more lipophilic and I think that's the Trend that we have seen here uh this one was for the phenolic molecule or alcoholic containing molecule and this one has a less lipophilicity values and this one just carbons and hydrogens have more lipophilic values so this is how you can uh predict uh lipophilicity values for external smile strings yeah so let me know if you have any questions in the comments and that's it for now uh I will see you in the next video thank you for watching
Up Next

Graph Neural Networks for Molecular Design and Drug Discovery
@GAIA_GBG
13.6K views•2021-03-08

Building Real-Time ML Pipelines with Feature Stores and MLOps Frameworks
@ODSCAI
5.1K views•2022-02-20

Bypassing Tor Censorship: Bridges and Pluggable Transport Guide
@Coding_ForEveryone
397 views•2024-06-11

Neural Networks Explained: Math, Layers, and Learning Fundamentals
@3blue1brown
21.9M views•2017-10-05
Related Study Plans & Knowledge Roadmaps
Structured learning paths in Artificial Intelligence






































