-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathassemblyCalcs_cheminformatics.py
51 lines (38 loc) · 1.24 KB
/
assemblyCalcs_cheminformatics.py
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
import rdkit.Chem as Chem
import rdkit.Chem.rdMolDescriptors as Desc
from rdkit import RDLogger
import pickle
from tqdm import tqdm
import pandas as pd
import numpy
import os
def get_mw(inchi):
""" Finds the molecular weight for a given inchi string
Args:
inchi (str): inchi string of a SureChemBL compound
Returns:
float: molecular weight (or NaN if rdkit failure)
"""
try:
m = Chem.MolFromInchi(inchi)
return Desc.CalcExactMolWt(m)
except:
return numpy.nan
def main():
RDLogger.DisableLog('rdApp.*')
#Test: load an assembly subset, find MWs for all cpds
new_df = pd.DataFrame()
full_df = pd.DataFrame()
for f in tqdm(os.listdir("Data/AssemblyValues/")):
if f.startswith("assembly_values_1000_"):
data = pickle.load(file=open("Data/AssemblyValues/" + f, "rb"))
df = pd.DataFrame(data)
df["mw"] = df["inchi"].apply(get_mw)
if "FULL" in f:
full_df = full_df.append(df)
else:
new_df = new_df.append(df)
new_df.to_csv("Data/AssemblyValues/newCpds_AssemblyValues.csv")
full_df.to_csv("Data/AssemblyValues/fullCpds_AssemblyValues.csv")
if __name__ == "__main__":
main()