|
| 1 | +###################### |
| 2 | +# Import libraries |
| 3 | +###################### |
| 4 | +import numpy as np |
| 5 | +import pandas as pd |
| 6 | +import streamlit as st |
| 7 | +import pickle |
| 8 | +from PIL import Image |
| 9 | +from rdkit import Chem |
| 10 | +from rdkit.Chem import Descriptors |
| 11 | + |
| 12 | +###################### |
| 13 | +# Custom function |
| 14 | +###################### |
| 15 | +## Calculate molecular descriptors |
| 16 | +def AromaticProportion(m): |
| 17 | + aromatic_atoms = [m.GetAtomWithIdx(i).GetIsAromatic() for i in range(m.GetNumAtoms())] |
| 18 | + aa_count = [] |
| 19 | + for i in aromatic_atoms: |
| 20 | + if i==True: |
| 21 | + aa_count.append(1) |
| 22 | + AromaticAtom = sum(aa_count) |
| 23 | + HeavyAtom = Descriptors.HeavyAtomCount(m) |
| 24 | + AR = AromaticAtom/HeavyAtom |
| 25 | + return AR |
| 26 | + |
| 27 | +def generate(smiles, verbose=False): |
| 28 | + |
| 29 | + moldata= [] |
| 30 | + for elem in smiles: |
| 31 | + mol=Chem.MolFromSmiles(elem) |
| 32 | + moldata.append(mol) |
| 33 | + |
| 34 | + baseData= np.arange(1,1) |
| 35 | + i=0 |
| 36 | + for mol in moldata: |
| 37 | + |
| 38 | + desc_MolLogP = Descriptors.MolLogP(mol) |
| 39 | + desc_MolWt = Descriptors.MolWt(mol) |
| 40 | + desc_NumRotatableBonds = Descriptors.NumRotatableBonds(mol) |
| 41 | + desc_AromaticProportion = AromaticProportion(mol) |
| 42 | + |
| 43 | + row = np.array([desc_MolLogP, |
| 44 | + desc_MolWt, |
| 45 | + desc_NumRotatableBonds, |
| 46 | + desc_AromaticProportion]) |
| 47 | + |
| 48 | + if(i==0): |
| 49 | + baseData=row |
| 50 | + else: |
| 51 | + baseData=np.vstack([baseData, row]) |
| 52 | + i=i+1 |
| 53 | + |
| 54 | + columnNames=["MolLogP","MolWt","NumRotatableBonds","AromaticProportion"] |
| 55 | + descriptors = pd.DataFrame(data=baseData,columns=columnNames) |
| 56 | + |
| 57 | + return descriptors |
| 58 | + |
| 59 | +###################### |
| 60 | +# Page Title |
| 61 | +###################### |
| 62 | + |
| 63 | +image = Image.open('solubility-logo.jpg') |
| 64 | + |
| 65 | +st.image(image, use_column_width=True) |
| 66 | + |
| 67 | +st.write(""" |
| 68 | +# Molecular Solubility Prediction Web App |
| 69 | +
|
| 70 | +This app predicts the **Solubility (LogS)** values of molecules! |
| 71 | +
|
| 72 | +Data obtained from the John S. Delaney. [ESOL: Estimating Aqueous Solubility Directly from Molecular Structure](https://pubs.acs.org/doi/10.1021/ci034243x). ***J. Chem. Inf. Comput. Sci.*** 2004, 44, 3, 1000-1005. |
| 73 | +*** |
| 74 | +""") |
| 75 | + |
| 76 | + |
| 77 | +###################### |
| 78 | +# Input molecules (Side Panel) |
| 79 | +###################### |
| 80 | + |
| 81 | +st.sidebar.header('User Input Features') |
| 82 | + |
| 83 | +## Read SMILES input |
| 84 | +SMILES_input = "NCCCC\nCCC\nCN" |
| 85 | + |
| 86 | +SMILES = st.sidebar.text_area("SMILES input", SMILES_input) |
| 87 | +SMILES = "C\n" + SMILES #Adds C as a dummy, first item |
| 88 | +SMILES = SMILES.split('\n') |
| 89 | + |
| 90 | +st.header('Input SMILES') |
| 91 | +SMILES[1:] # Skips the dummy first item |
| 92 | + |
| 93 | +## Calculate molecular descriptors |
| 94 | +st.header('Computed molecular descriptors') |
| 95 | +X = generate(SMILES) |
| 96 | +X[1:] # Skips the dummy first item |
| 97 | + |
| 98 | +###################### |
| 99 | +# Pre-built model |
| 100 | +###################### |
| 101 | + |
| 102 | +# Reads in saved model |
| 103 | +load_model = pickle.load(open('solubility_model.pkl', 'rb')) |
| 104 | + |
| 105 | +# Apply model to make predictions |
| 106 | +prediction = load_model.predict(X) |
| 107 | +#prediction_proba = load_model.predict_proba(X) |
| 108 | + |
| 109 | +st.header('Predicted LogS values') |
| 110 | +prediction[1:] # Skips the dummy first item |
0 commit comments