-
Notifications
You must be signed in to change notification settings - Fork 0
/
cns_mpo_single_molecule.py
166 lines (146 loc) · 4.88 KB
/
cns_mpo_single_molecule.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
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
166
import pandas as pd
from rdkit import Chem
from rdkit.Chem import Descriptors, Crippen, rdMolDescriptors
from math import log10
class CNS_MPO_single_molecule:
def __init__(self, smiles_list, pKa_list):
if len(smiles_list) != len(pKa_list):
raise ValueError(
"Length of smiles_list must be equal to length of pKa_list"
)
self.smiles_list = smiles_list
self.pKa_list = pKa_list
self._df = None
self.calculate()
def clogD(self, logP, pKa, pH=7.4):
return logP - log10(1 + 10 ** (pH - pKa))
def csv_file_preparation(self):
dictionary = {"MW": [], "LogP": [], "HBD": [], "TPSA": []}
for cpd in self.smiles_list:
molecule = Chem.MolFromSmiles(cpd)
if molecule is None:
# Handle invalid SMILES
dictionary["MW"].append(None)
dictionary["LogP"].append(None)
dictionary["HBD"].append(None)
dictionary["TPSA"].append(None)
continue
mol_mw = Descriptors.MolWt(molecule)
mol_logp = Crippen.MolLogP(molecule)
mol_hbd = rdMolDescriptors.CalcNumHBD(molecule)
mol_tpsa = Descriptors.TPSA(molecule)
dictionary["MW"].append(mol_mw)
dictionary["LogP"].append(mol_logp)
dictionary["HBD"].append(mol_hbd)
dictionary["TPSA"].append(mol_tpsa)
df_descriptors = pd.DataFrame(dictionary)
df_descriptors["pKa"] = self.pKa_list
df_descriptors["LogD"] = df_descriptors.apply(
lambda x: self.clogD(x["LogP"], x["pKa"]), axis=1
)
return df_descriptors
def mw_score_func(self, mw):
if mw is None:
return 0
if mw <= 360:
return 1
elif 360 < mw <= 500:
return -0.005 * mw + 2.5
else:
return 0
def logp_score_func(self, logp):
if logp is None:
return 0
if logp <= 3:
return 1
elif 3 < logp <= 5:
return -0.5 * logp + 2.5
else:
return 0
def logd_score_func(self, logd):
if logd is None:
return 0
if logd <= 2:
return 1
elif 2 < logd <= 4:
return -0.5 * logd + 2
else:
return 0
def pka_score_func(self, pka):
if pka is None:
return 0
if pka <= 8:
return 1
elif 8 < pka <= 10:
return -0.5 * pka + 5
else:
return 0
def tpsa_score_func(self, tpsa):
if tpsa is None:
return 0
if 40 <= tpsa <= 90:
return 1
elif 90 < tpsa <= 120:
return -0.0333 * tpsa + 4
elif 20 <= tpsa < 40:
return 0.05 * tpsa - 1
else:
return 0
def hbd_score_func(self, hbd):
if hbd is None:
return 0
if hbd == 0:
return 1
elif hbd == 1:
return 0.75
elif hbd == 2:
return 0.5
elif hbd == 3:
return 0.25
else:
return 0
def calcCNS_MPO(self):
df_descriptors = self.csv_file_preparation()
df_descriptors["MW_score"] = df_descriptors["MW"].apply(
self.mw_score_func
)
df_descriptors["LogP_score"] = df_descriptors["LogP"].apply(
self.logp_score_func
)
df_descriptors["LogD_score"] = df_descriptors["LogD"].apply(
self.logd_score_func
)
df_descriptors["pKa_score"] = df_descriptors["pKa"].apply(
self.pka_score_func
)
df_descriptors["TPSA_score"] = df_descriptors["TPSA"].apply(
self.tpsa_score_func
)
df_descriptors["HBD_score"] = df_descriptors["HBD"].apply(
self.hbd_score_func
)
df_descriptors["CNS_MPO"] = (
df_descriptors["MW_score"]
+ df_descriptors["LogP_score"]
+ df_descriptors["LogD_score"]
+ df_descriptors["pKa_score"]
+ df_descriptors["TPSA_score"]
+ df_descriptors["HBD_score"]
)
# Return only the specified columns
return df_descriptors[
["MW", "LogP", "HBD", "TPSA", "pKa", "LogD", "CNS_MPO"]
]
def calculate(self):
self._df = self.calcCNS_MPO()
def __getitem__(self, key):
if isinstance(key, (int, slice)):
return self._df.iloc[key]
elif isinstance(key, str):
return self._df[key]
else:
raise KeyError(f"Unsupported key type: {type(key)}")
def __repr__(self):
return repr(self._df)
def __str__(self):
return str(self._df)