File size: 4,521 Bytes
55d9b0c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
import pandas as pd
import numpy as np
import os
from rdkit import Chem
from rdkit.Chem import Descriptors
import multiprocessing
from rdkit import Chem
from rdkit.Chem import RDConfig
import os
import sys
sys.path.append(os.path.join(RDConfig.RDContribDir, 'SA_Score'))
# now you can import sascore!
import sascorer
np.random.seed(42)
def calcLogPIfMol(smi):
m = Chem.MolFromSmiles(smi)
if m is not None:
return Descriptors.MolLogP(m)
else:
return None
def calcMol(smi):
return Chem.MolFromSmiles(smi)
def calcMolWeight(smi):
mol = Chem.MolFromSmiles(smi)
return Descriptors.ExactMolWt(mol)
def calcSascore(smi):
mol = Chem.MolFromSmiles(smi)
return sascorer.calculateScore(mol)
def calculateValues(smi: pd.Series):
with multiprocessing.Pool(8) as pool:
print("Starting logps")
logps = pool.map(calcLogPIfMol, smi)
print("Done logps")
valid_mols = ~pd.isna(logps)
logps = pd.Series(logps)[valid_mols]
smi = pd.Series(smi)[valid_mols]
logps.reset_index(drop=True,inplace=True)
smi.reset_index(drop=True,inplace=True)
print("Starting mol weights")
mol_weights = pool.map(calcMolWeight, smi)
print("Done mol weights")
print("Starting sascores")
sascores = pool.map(calcSascore, smi)
print("Done sascores")
return smi, logps, mol_weights,sascores
def calculateProperties(df):
smi, logps, mol_weights,sascores = calculateValues(df["smiles"])
out_df = pd.DataFrame({"smiles": smi, "logp":logps, "mol_weight":mol_weights, "sascore":sascores })
return out_df
if __name__ == "__main__":
cwd = os.path.dirname(__file__)
print("df_pc9")
df_pc9 = pd.read_parquet(os.path.join(cwd, "Full_PC9_GAP.parquet"))
df_pc9 = calculateProperties(df_pc9)
print("df_zinc_full")
df_zinc_full = pd.read_parquet(
os.path.join(cwd, "zinc", "zinc_processed.parquet")
)
df_zinc_full = df_zinc_full.sample(n=5_000_000)
df_zinc_full = calculateProperties(df_zinc_full)
print("df_zinc_qm9")
df_zinc_qm9 = pd.read_parquet(os.path.join(cwd,"qm9_zinc250k_cep", "qm9_zinc250_cep.parquet"))
df_zinc_qm9 = calculateProperties(df_zinc_qm9)
print("df_opv")
df_opv = pd.read_parquet(os.path.join(cwd,"opv", "opv.parquet"))
df_opv = calculateProperties(df_opv)
print("df_reddb")
# Source: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/F3QFSQ
df_reddb = pd.read_parquet(os.path.join(cwd,"RedDB_Full.parquet"))
df_reddb = calculateProperties(df_reddb)
print("df_chembl")
df_chembl = pd.read_parquet(
os.path.join(cwd, "chembl_log_sascore.parquet")
)
df_chembl = calculateProperties(df_chembl)
print("df_pubchemqc_2017")
df_pubchemqc_2017 = pd.read_parquet(
os.path.join(cwd, "pubchemqc_energy.parquet")
)
df_pubchemqc_2017 = calculateProperties(df_pubchemqc_2017)
print("df_pubchemqc_2020")
df_pubchemqc_2020 = pd.read_parquet(
os.path.join(cwd, "pubchemqc2020_energy.parquet")
)
df_pubchemqc_2020 = calculateProperties(df_pubchemqc_2020)
df_list = [
df_zinc_qm9,
df_opv,
df_pubchemqc_2017,
df_pubchemqc_2020,
df_zinc_full,
df_reddb,
df_pc9,
df_chembl,
]
print(f"ZINC QM9 {len(df_zinc_qm9)}")
print(f"df_opv {len(df_opv)}")
print(f"df_pubchemqc_2017 {len(df_pubchemqc_2017)}")
print(f"df_pubchemqc_2020 {len(df_pubchemqc_2020)}")
print(f"df_zinc_full {len(df_zinc_full)}")
print(f"df_reddb {len(df_reddb)}")
print(f"df_pc9 {len(df_pc9)}")
print(f"df_chembl {len(df_chembl)}")
all_columns = [
"smiles",
"logp",
"sascore",
"mol_weight"
] # set([*df_zinc_qm9.columns.tolist(),*df_pubchemqc_2017.columns.tolist(),*df_pubchemqc_2020.columns.tolist(),*df_zinc_full.columns.tolist()] )
print("concatenting")
df = pd.concat(
df_list, axis=0, ignore_index=True
) # pd.DataFrame(columns=all_columns)
df = df[all_columns] # .fillna(0)
# df = df.sample(n=7_500_000)
df.reset_index(drop=True, inplace=True)
df["mol_weight"] = df["mol_weight"] / 100.0
print(df.head())
print("saving")
print("Combined len:", len(df))
df.to_parquet(
os.path.join(cwd, "OrganiX13.parquet")
)
|