-
Notifications
You must be signed in to change notification settings - Fork 14
/
MolSurf.cpp
326 lines (302 loc) · 11.5 KB
/
MolSurf.cpp
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// $Id$
//
// Copyright (C) 2007-2011 Greg Landrum
//
// @@ All Rights Reserved @@
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <GraphMol/RDKitBase.h>
#include <GraphMol/Descriptors/MolDescriptors.h>
#include <GraphMol/PartialCharges/GasteigerCharges.h>
#include <vector>
#include <algorithm>
namespace RDKit{
namespace Descriptors {
double getLabuteAtomContribs(const ROMol &mol,
std::vector<double> &Vi,
double &hContrib,
bool includeHs,
bool force){
TEST_ASSERT(Vi.size()==mol.getNumAtoms());
if(!force && mol.hasProp("_labuteAtomContribs")){
mol.getProp("_labuteAtomContribs",Vi);
mol.getProp("_labuteAtomHContrib",hContrib);
double res;
mol.getProp("_labuteASA",res);
return res;
}
unsigned int nAtoms=mol.getNumAtoms();
std::vector<double> rads(nAtoms);
for(unsigned int i=0;i<nAtoms;++i){
rads[i]=PeriodicTable::getTable()->getRb0(mol.getAtomWithIdx(i)->getAtomicNum());
Vi[i]=0.0;
}
for(ROMol::ConstBondIterator bondIt=mol.beginBonds();
bondIt!=mol.endBonds();++bondIt){
const double bondScaleFacts[4]={.1,0,.2,.3};
double Ri=rads[(*bondIt)->getBeginAtomIdx()];
double Rj=rads[(*bondIt)->getEndAtomIdx()];
double bij=Ri+Rj;
if(!(*bondIt)->getIsAromatic()){
if((*bondIt)->getBondType()<4){
bij -= bondScaleFacts[(*bondIt)->getBondType()];
}
} else {
bij -= bondScaleFacts[0];
}
double dij=std::min(std::max(fabs(Ri-Rj),bij),Ri+Rj);
Vi[(*bondIt)->getBeginAtomIdx()] += Rj*Rj-(Ri-dij)*(Ri-dij)/dij;
Vi[(*bondIt)->getEndAtomIdx()] += Ri*Ri-(Rj-dij)*(Rj-dij)/dij;
}
hContrib=0.0;
if(includeHs){
double Rj=PeriodicTable::getTable()->getRb0(1);
for(unsigned int i=0;i<nAtoms;++i){
double Ri=rads[i];
double bij=Ri+Rj;
double dij=std::min(std::max(fabs(Ri-Rj),bij),Ri+Rj);
Vi[i] += Rj*Rj-(Ri-dij)*(Ri-dij)/dij;
hContrib += Ri*Ri-(Rj-dij)*(Rj-dij)/dij;
}
}
double res=0.0;
for(unsigned int i=0;i<nAtoms;++i){
double Ri=rads[i];
Vi[i] = M_PI*Ri*(4.*Ri-Vi[i]);
res+=Vi[i];
}
if(includeHs){
double Rj=PeriodicTable::getTable()->getRb0(1);
hContrib = M_PI*Rj*(4.*Rj-hContrib);
res+=hContrib;
}
mol.setProp("_labuteAtomContribs",Vi,true);
mol.setProp("_labuteAtomHContrib",hContrib,true);
mol.setProp("_labuteASA",res,true);
return res;
}
double calcLabuteASA(const ROMol &mol,bool includeHs,bool force){
if(!force && mol.hasProp("_labuteASA")){
double res;
mol.getProp("_labuteASA",res);
return res;
}
std::vector<double> contribs;
contribs.resize(mol.getNumAtoms());
double hContrib;
double res;
res=getLabuteAtomContribs(mol,contribs,hContrib,includeHs,force);
return res;
}
double getTPSAAtomContribs(const ROMol &mol,
std::vector<double> &Vi,
bool force){
TEST_ASSERT(Vi.size()>=mol.getNumAtoms());
double res=0;
if(!force && mol.hasProp("_tpsaAtomContribs")){
mol.getProp("_tpsaAtomContribs",Vi);
mol.getProp("_tpsa",res);
return res;
}
unsigned int nAtoms=mol.getNumAtoms();
std::vector<int> nNbrs(nAtoms,0),nSing(nAtoms,0),nDoub(nAtoms,0),nTrip(nAtoms,0),nArom(nAtoms,0),nHs(nAtoms,0);
for(ROMol::ConstBondIterator bIt=mol.beginBonds();bIt!=mol.endBonds();++bIt){
const Bond *bnd=(*bIt);
if(bnd->getBeginAtom()->getAtomicNum()==1){
nNbrs[bnd->getEndAtomIdx()]-=1;
nHs[bnd->getEndAtomIdx()]+=1;
} else if(bnd->getEndAtom()->getAtomicNum()==1){
nNbrs[bnd->getBeginAtomIdx()]-=1;
nHs[bnd->getBeginAtomIdx()]+=1;
} else if(bnd->getIsAromatic()){
nArom[bnd->getBeginAtomIdx()]+=1;
nArom[bnd->getEndAtomIdx()]+=1;
} else {
switch(bnd->getBondType()){
case Bond::SINGLE:
nSing[bnd->getBeginAtomIdx()]+=1;
nSing[bnd->getEndAtomIdx()]+=1;
break;
case Bond::DOUBLE:
nDoub[bnd->getBeginAtomIdx()]+=1;
nDoub[bnd->getEndAtomIdx()]+=1;
break;
case Bond::TRIPLE:
nTrip[bnd->getBeginAtomIdx()]+=1;
nTrip[bnd->getEndAtomIdx()]+=1;
break;
default:
break;
}
}
}
for(unsigned int i=0;i<nAtoms;++i){
const Atom *atom=mol.getAtomWithIdx(i);
int atNum=atom->getAtomicNum();
if(atNum!=7 && atNum!=8) continue;
nHs[i] += atom->getTotalNumHs();
int chg=atom->getFormalCharge();
bool in3Ring = mol.getRingInfo()->isAtomInRingOfSize(i,3);
nNbrs[i]+=atom->getDegree();
double tmp=-1;
if(atNum==7){
switch(nNbrs[i]){
case 1:
if(nHs[i]==0 && chg==0 && nTrip[i]==1) tmp=23.79;
else if(nHs[i]==1 && chg==0 && nDoub[i]==1) tmp=23.85;
else if(nHs[i]==2 && chg==0 && nSing[i]==1) tmp=26.02;
else if(nHs[i]==2 && chg==1 && nDoub[i]==1) tmp=25.59;
else if(nHs[i]==3 && chg==1 && nSing[i]==1) tmp=27.64;
break;
case 2:
if(nHs[i]==0 && chg==0 && nSing[i]==1 && nDoub[i]==1) tmp=12.36;
else if(nHs[i]==0 && chg==0 && nTrip[i]==1 && nDoub[i]==1) tmp=13.60;
else if(nHs[i]==1 && chg==0 && nSing[i]==2 && in3Ring) tmp=21.94;
else if(nHs[i]==1 && chg==0 && nSing[i]==2 && !in3Ring) tmp=12.03;
else if(nHs[i]==0 && chg==1 && nTrip[i]==1 && nSing[i]==1) tmp=4.36;
else if(nHs[i]==1 && chg==1 && nDoub[i]==1 && nSing[i]==1) tmp=13.97;
else if(nHs[i]==2 && chg==1 && nSing[i]==2) tmp=16.61;
else if(nHs[i]==0 && chg==0 && nArom[i]==2) tmp=12.89;
else if(nHs[i]==1 && chg==0 && nArom[i]==2) tmp=15.79;
else if(nHs[i]==1 && chg==1 && nArom[i]==2) tmp=14.14;
break;
case 3:
if(nHs[i]==0 && chg==0 && nSing[i]==3 && in3Ring ) tmp=3.01;
else if(nHs[i]==0 && chg==0 && nSing[i]==3 && !in3Ring ) tmp=3.24;
else if(nHs[i]==0 && chg==0 && nSing[i]==1 && nDoub[i]==2 ) tmp=11.68;
else if(nHs[i]==0 && chg==1 && nSing[i]==2 && nDoub[i]==1 ) tmp=3.01;
else if(nHs[i]==1 && chg==1 && nSing[i]==3 ) tmp=4.44;
else if(nHs[i]==0 && chg==0 && nArom[i]==3 ) tmp=4.41;
else if(nHs[i]==0 && chg==0 && nSing[i]==1 && nArom[i]==2 ) tmp=4.93;
else if(nHs[i]==0 && chg==0 && nDoub[i]==1 && nArom[i]==2 ) tmp=8.39;
else if(nHs[i]==0 && chg==1 && nArom[i]==3 ) tmp=4.10;
else if(nHs[i]==0 && chg==1 && nSing[i]==1 && nArom[i]==2 ) tmp=3.88;
break;
case 4:
if(nHs[i]==0 && nSing[i]==4 && chg==1) tmp=0.0;
break;
}
if(tmp < 0.0){
tmp = 30.5 - nNbrs[i] * 8.2 + nHs[i] * 1.5;
if(tmp<0) tmp=0.0;
}
} else if(atNum==8){
switch(nNbrs[i]){
case 1:
if(nHs[i]==0 && chg==0 && nDoub[i]==1) tmp=17.07;
else if(nHs[i]==1 && chg==0 && nSing[i]==1 ) tmp=20.23;
else if(nHs[i]==0 && chg==-1 && nSing[i]==1 ) tmp=23.06;
break;
case 2:
if(nHs[i]==0 && chg==0 && nSing[i]==2 && in3Ring) tmp=12.53;
else if(nHs[i]==0 && chg==0 && nSing[i]==2 && !in3Ring) tmp=9.23;
else if(nHs[i]==0 && chg==0 && nArom[i]==2) tmp=13.14;
break;
}
if(tmp<0.0){
tmp=28.5-nNbrs[i]*8.6+nHs[i]*1.5;
if(tmp<0) tmp=0.0;
}
}
Vi[i]=tmp;
res+=tmp;
}
mol.setProp("_tpsaAtomContribs",Vi,true);
mol.setProp("_tpsa",res,true);
return res;
}
double calcTPSA(const ROMol &mol,bool force){
if(!force && mol.hasProp("_tpsa")){
double res;
mol.getProp("_tpsa",res);
return res;
}
std::vector<double> contribs;
contribs.resize(mol.getNumAtoms());
double res;
res=getTPSAAtomContribs(mol,contribs,force);
return res;
}
namespace {
void assignContribsToBins(const std::vector<double> &contribs,
const std::vector<double> &binProp,
std::vector<double> &bins,
std::vector<double> &res){
PRECONDITION(contribs.size()==binProp.size(),"mismatched array sizes");
PRECONDITION(res.size()>=bins.size()+1,"mismatched array sizes");
for(unsigned int i=0;i<contribs.size();++i){
double cVal = contribs[i];
double bVal = binProp[i];
unsigned int idx=std::upper_bound(bins.begin(),bins.end(),bVal)-bins.begin();
res[idx]+=cVal;
}
}
}
std::vector<double> calcSlogP_VSA(const ROMol &mol,std::vector<double> *bins,
bool force){
// FIX: use force value to include caching
std::vector<double> lbins;
if(!bins){
double blist[11]={-0.4,-0.2,0,0.1,0.15,0.2,0.25,0.3,0.4,0.5,0.6};
lbins.resize(11);
std::copy(blist,blist+11,lbins.begin());
} else {
lbins.resize(bins->size());
std::copy(bins->begin(),bins->end(),lbins.begin());
}
std::vector<double> res(lbins.size()+1,0);
std::vector<double> vsaContribs(mol.getNumAtoms());
double tmp;
getLabuteAtomContribs(mol,vsaContribs,tmp,true,force);
std::vector<double> logpContribs(mol.getNumAtoms());
std::vector<double> mrContribs(mol.getNumAtoms());
getCrippenAtomContribs(mol,logpContribs,mrContribs,force);
assignContribsToBins(vsaContribs,logpContribs,lbins,res);
return res;
}
std::vector<double> calcSMR_VSA(const ROMol &mol,std::vector<double> *bins,
bool force){
std::vector<double> lbins;
if(!bins){
double blist[9]={1.29, 1.82, 2.24, 2.45, 2.75, 3.05, 3.63,3.8,4.0};
lbins.resize(9);
std::copy(blist,blist+9,lbins.begin());
} else {
lbins.resize(bins->size());
std::copy(bins->begin(),bins->end(),lbins.begin());
}
std::vector<double> res(lbins.size()+1,0);
std::vector<double> vsaContribs(mol.getNumAtoms());
double tmp;
getLabuteAtomContribs(mol,vsaContribs,tmp,true,force);
std::vector<double> logpContribs(mol.getNumAtoms());
std::vector<double> mrContribs(mol.getNumAtoms());
getCrippenAtomContribs(mol,logpContribs,mrContribs,force);
assignContribsToBins(vsaContribs,mrContribs,lbins,res);
return res;
}
std::vector<double> calcPEOE_VSA(const ROMol &mol,std::vector<double> *bins,
bool force){
std::vector<double> lbins;
if(!bins){
double blist[13]={-.3,-.25,-.20,-.15,-.10,-.05,0,.05,.10,.15,.20,.25,.30};
lbins.resize(13);
std::copy(blist,blist+13,lbins.begin());
} else {
lbins.resize(bins->size());
std::copy(bins->begin(),bins->end(),lbins.begin());
}
std::vector<double> res(lbins.size()+1,0);
std::vector<double> vsaContribs(mol.getNumAtoms());
double tmp;
getLabuteAtomContribs(mol,vsaContribs,tmp,true,force);
std::vector<double> chgs(mol.getNumAtoms(),0.0);
computeGasteigerCharges(mol,chgs);
assignContribsToBins(vsaContribs,chgs,lbins,res);
return res;
}
} // end of namespace Descriptors
} // end of namespace RDKit