/src/openbabel/src/forcefields/forcefieldmmff94.cpp
Line | Count | Source |
1 | | /********************************************************************* |
2 | | forcefieldmmff94.cpp - MMFF94 force field |
3 | | |
4 | | Copyright (C) 2006-2008 by Tim Vandermeersch <tim.vandermeersch@gmail.com> |
5 | | |
6 | | This file is part of the Open Babel project. |
7 | | For more information, see <http://openbabel.org/> |
8 | | |
9 | | This program is free software; you can redistribute it and/or modify |
10 | | it under the terms of the GNU General Public License as published by |
11 | | the Free Software Foundation version 2 of the License. |
12 | | |
13 | | This program is distributed in the hope that it will be useful, |
14 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | GNU General Public License for more details. |
17 | | ***********************************************************************/ |
18 | | |
19 | | /* |
20 | | * Source code layout: |
21 | | * - Functions to calculate the actual interactions |
22 | | * - Parse parameter files |
23 | | * - Setup Functions |
24 | | * - Validation functions |
25 | | * - Calculate bond type, angle type, stretch-bend type, torsion type |
26 | | * - Various tables & misc. functions |
27 | | * |
28 | | */ |
29 | | |
30 | | #include <openbabel/babelconfig.h> |
31 | | #include <openbabel/obconversion.h> |
32 | | #include <openbabel/mol.h> |
33 | | #include <openbabel/locale.h> |
34 | | #include <openbabel/elements.h> |
35 | | #include <openbabel/bond.h> |
36 | | #include <openbabel/obiter.h> |
37 | | #include <openbabel/ring.h> |
38 | | |
39 | | #ifndef M_PI |
40 | | #define M_PI 3.14159265358979323846 |
41 | | #endif |
42 | | |
43 | | #include <iomanip> |
44 | | #include "forcefieldmmff94.h" |
45 | | |
46 | | using namespace std; |
47 | | |
48 | | namespace OpenBabel |
49 | | { |
50 | | //////////////////////////////////////////////////////////////////////////////// |
51 | | //////////////////////////////////////////////////////////////////////////////// |
52 | | // |
53 | | // Functions to calculate the actual interactions |
54 | | // |
55 | | //////////////////////////////////////////////////////////////////////////////// |
56 | | //////////////////////////////////////////////////////////////////////////////// |
57 | | |
58 | | double OBForceFieldMMFF94::Energy(bool gradients) |
59 | 5.33k | { |
60 | 5.33k | double energy; |
61 | | |
62 | 5.33k | IF_OBFF_LOGLVL_MEDIUM |
63 | 0 | OBFFLog("\nE N E R G Y\n\n"); |
64 | | |
65 | 5.33k | if (gradients) { |
66 | 1.81k | ClearGradients(); |
67 | 1.81k | energy = E_Bond<true>(); |
68 | 1.81k | energy += E_Angle<true>(); |
69 | 1.81k | energy += E_StrBnd<true>(); |
70 | 1.81k | energy += E_Torsion<true>(); |
71 | 1.81k | energy += E_OOP<true>(); |
72 | 1.81k | energy += E_VDW<true>(); |
73 | 1.81k | energy += E_Electrostatic<true>(); |
74 | 3.51k | } else { |
75 | 3.51k | energy = E_Bond<false>(); |
76 | 3.51k | energy += E_Angle<false>(); |
77 | 3.51k | energy += E_StrBnd<false>(); |
78 | 3.51k | energy += E_Torsion<false>(); |
79 | 3.51k | energy += E_OOP<false>(); |
80 | 3.51k | energy += E_VDW<false>(); |
81 | 3.51k | energy += E_Electrostatic<false>(); |
82 | 3.51k | } |
83 | | |
84 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
85 | 0 | snprintf(_logbuf, BUFF_SIZE, "\nTOTAL ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); |
86 | 0 | OBFFLog(_logbuf); |
87 | 0 | } |
88 | | |
89 | 5.33k | return energy; |
90 | 5.33k | } |
91 | | |
92 | | // |
93 | | // MMFF part I - page 494 |
94 | | // |
95 | | // kb_ij 7 |
96 | | // EB_ij = 143.9325 ------- /\r_ij^2 (1 + cs /\_rij + ---- cs^2 r_ij^2) |
97 | | // 2 12 |
98 | | // |
99 | | // kb_ij force constant (md/A) |
100 | | // |
101 | | // /\r_ij r_ij - r0_ij (A) |
102 | | // |
103 | | // cs cubic stretch constant = -2 A^(-1) |
104 | | // |
105 | | template<bool gradients> |
106 | | inline void OBFFBondCalculationMMFF94::Compute() |
107 | 0 | { |
108 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b)) { |
109 | 0 | energy = 0.0; |
110 | 0 | return; |
111 | 0 | } |
112 | | |
113 | 0 | double delta2; |
114 | |
|
115 | 0 | if (gradients) { |
116 | 0 | rab = OBForceField::VectorBondDerivative(pos_a, pos_b, force_a, force_b); |
117 | 0 | delta = rab - r0; |
118 | 0 | delta2 = delta * delta; |
119 | |
|
120 | 0 | const double dE = 143.9325 * kb * delta * (1.0 - 3.0 * delta + 14.0/3.0 * delta2); |
121 | |
|
122 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
123 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
124 | 0 | } else { |
125 | 0 | rab = OBForceField::VectorDistance(pos_a, pos_b); |
126 | 0 | delta = rab - r0; |
127 | 0 | delta2 = delta * delta; |
128 | 0 | } |
129 | |
|
130 | 0 | energy = kb * delta2 * (1.0 - 2.0 * delta + 7.0/3.0 * delta2); |
131 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFBondCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFBondCalculationMMFF94::Compute<false>() |
132 | | |
133 | | template<bool gradients> |
134 | | double OBForceFieldMMFF94::E_Bond() |
135 | 5.33k | { |
136 | 5.33k | double energy = 0.0; |
137 | | |
138 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
139 | 0 | OBFFLog("\nB O N D S T R E T C H I N G\n\n"); |
140 | 0 | OBFFLog("ATOM TYPES FF BOND IDEAL FORCE\n"); |
141 | 0 | OBFFLog(" I J CLASS LENGTH LENGTH CONSTANT DELTA ENERGY\n"); |
142 | 0 | OBFFLog("------------------------------------------------------------------------\n"); |
143 | 0 | } |
144 | | |
145 | | #ifdef _OPENMP |
146 | | #pragma omp parallel for reduction(+:energy) |
147 | | #endif |
148 | 5.33k | for (int i = 0; i < _bondcalculations.size(); ++i) { |
149 | 0 | _bondcalculations[i].template Compute<gradients>(); |
150 | 0 | energy += _bondcalculations[i].energy; |
151 | |
|
152 | 0 | #ifndef _OPENMP |
153 | 0 | if (gradients) { |
154 | 0 | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); |
155 | 0 | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); |
156 | 0 | } |
157 | 0 | #endif |
158 | |
|
159 | 0 | IF_OBFF_LOGLVL_HIGH { |
160 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", |
161 | 0 | atoi(_bondcalculations[i].a->GetType()), atoi(_bondcalculations[i].b->GetType()), |
162 | 0 | _bondcalculations[i].bt, _bondcalculations[i].rab, _bondcalculations[i].r0, |
163 | 0 | _bondcalculations[i].kb, _bondcalculations[i].delta, |
164 | 0 | 143.9325 * 0.5 * _bondcalculations[i].energy); |
165 | 0 | OBFFLog(_logbuf); |
166 | 0 | } |
167 | 0 | } |
168 | | |
169 | | #ifdef _OPENMP |
170 | | for (int i = 0; i < _bondcalculations.size(); ++i) { |
171 | | if (gradients) { |
172 | | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); |
173 | | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); |
174 | | } |
175 | | } |
176 | | #endif |
177 | | |
178 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
179 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL BOND STRETCHING ENERGY = %8.5f %s\n", 143.9325 * 0.5 * energy, GetUnit().c_str()); |
180 | 0 | OBFFLog(_logbuf); |
181 | 0 | } |
182 | | |
183 | 5.33k | return (143.9325 * 0.5 * energy); |
184 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_Bond<true>() Line | Count | Source | 135 | 1.81k | { | 136 | 1.81k | double energy = 0.0; | 137 | | | 138 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 139 | 0 | OBFFLog("\nB O N D S T R E T C H I N G\n\n"); | 140 | 0 | OBFFLog("ATOM TYPES FF BOND IDEAL FORCE\n"); | 141 | 0 | OBFFLog(" I J CLASS LENGTH LENGTH CONSTANT DELTA ENERGY\n"); | 142 | 0 | OBFFLog("------------------------------------------------------------------------\n"); | 143 | 0 | } | 144 | | | 145 | | #ifdef _OPENMP | 146 | | #pragma omp parallel for reduction(+:energy) | 147 | | #endif | 148 | 1.81k | for (int i = 0; i < _bondcalculations.size(); ++i) { | 149 | 0 | _bondcalculations[i].template Compute<gradients>(); | 150 | 0 | energy += _bondcalculations[i].energy; | 151 | |
| 152 | 0 | #ifndef _OPENMP | 153 | 0 | if (gradients) { | 154 | 0 | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); | 155 | 0 | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); | 156 | 0 | } | 157 | 0 | #endif | 158 | |
| 159 | 0 | IF_OBFF_LOGLVL_HIGH { | 160 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 161 | 0 | atoi(_bondcalculations[i].a->GetType()), atoi(_bondcalculations[i].b->GetType()), | 162 | 0 | _bondcalculations[i].bt, _bondcalculations[i].rab, _bondcalculations[i].r0, | 163 | 0 | _bondcalculations[i].kb, _bondcalculations[i].delta, | 164 | 0 | 143.9325 * 0.5 * _bondcalculations[i].energy); | 165 | 0 | OBFFLog(_logbuf); | 166 | 0 | } | 167 | 0 | } | 168 | | | 169 | | #ifdef _OPENMP | 170 | | for (int i = 0; i < _bondcalculations.size(); ++i) { | 171 | | if (gradients) { | 172 | | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); | 173 | | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); | 174 | | } | 175 | | } | 176 | | #endif | 177 | | | 178 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 179 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL BOND STRETCHING ENERGY = %8.5f %s\n", 143.9325 * 0.5 * energy, GetUnit().c_str()); | 180 | 0 | OBFFLog(_logbuf); | 181 | 0 | } | 182 | | | 183 | 1.81k | return (143.9325 * 0.5 * energy); | 184 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_Bond<false>() Line | Count | Source | 135 | 3.51k | { | 136 | 3.51k | double energy = 0.0; | 137 | | | 138 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 139 | 0 | OBFFLog("\nB O N D S T R E T C H I N G\n\n"); | 140 | 0 | OBFFLog("ATOM TYPES FF BOND IDEAL FORCE\n"); | 141 | 0 | OBFFLog(" I J CLASS LENGTH LENGTH CONSTANT DELTA ENERGY\n"); | 142 | 0 | OBFFLog("------------------------------------------------------------------------\n"); | 143 | 0 | } | 144 | | | 145 | | #ifdef _OPENMP | 146 | | #pragma omp parallel for reduction(+:energy) | 147 | | #endif | 148 | 3.51k | for (int i = 0; i < _bondcalculations.size(); ++i) { | 149 | 0 | _bondcalculations[i].template Compute<gradients>(); | 150 | 0 | energy += _bondcalculations[i].energy; | 151 | |
| 152 | 0 | #ifndef _OPENMP | 153 | 0 | if (gradients) { | 154 | 0 | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); | 155 | 0 | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); | 156 | 0 | } | 157 | 0 | #endif | 158 | |
| 159 | 0 | IF_OBFF_LOGLVL_HIGH { | 160 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 161 | 0 | atoi(_bondcalculations[i].a->GetType()), atoi(_bondcalculations[i].b->GetType()), | 162 | 0 | _bondcalculations[i].bt, _bondcalculations[i].rab, _bondcalculations[i].r0, | 163 | 0 | _bondcalculations[i].kb, _bondcalculations[i].delta, | 164 | 0 | 143.9325 * 0.5 * _bondcalculations[i].energy); | 165 | 0 | OBFFLog(_logbuf); | 166 | 0 | } | 167 | 0 | } | 168 | | | 169 | | #ifdef _OPENMP | 170 | | for (int i = 0; i < _bondcalculations.size(); ++i) { | 171 | | if (gradients) { | 172 | | AddGradient(_bondcalculations[i].force_a, _bondcalculations[i].idx_a); | 173 | | AddGradient(_bondcalculations[i].force_b, _bondcalculations[i].idx_b); | 174 | | } | 175 | | } | 176 | | #endif | 177 | | | 178 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 179 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL BOND STRETCHING ENERGY = %8.5f %s\n", 143.9325 * 0.5 * energy, GetUnit().c_str()); | 180 | 0 | OBFFLog(_logbuf); | 181 | 0 | } | 182 | | | 183 | 3.51k | return (143.9325 * 0.5 * energy); | 184 | 3.51k | } |
|
185 | | |
186 | | // |
187 | | // MMFF part I - page 495 |
188 | | // |
189 | | // ka_ijk |
190 | | // EA_ijk = 0.438449325 -------- /\0_ijk^2 (1 + cs /\0_ijk) |
191 | | // 2 |
192 | | // |
193 | | // ka_ijk force constant (md A/rad^2) |
194 | | // |
195 | | // /\0_ijk 0_ijk - 00_ijk (degrees) |
196 | | // |
197 | | // cs cubic bend constant = -0.007 deg^-1 = -0.4 rad^-1 |
198 | | // |
199 | | template<bool gradients> |
200 | | inline void OBFFAngleCalculationMMFF94::Compute() |
201 | 0 | { |
202 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b, idx_c)) { |
203 | 0 | energy = 0.0; |
204 | 0 | return; |
205 | 0 | } |
206 | | |
207 | 0 | double delta2, dE; |
208 | |
|
209 | 0 | if (gradients) { |
210 | 0 | theta = OBForceField::VectorAngleDerivative(pos_a, pos_b, pos_c, force_a, force_b, force_c); |
211 | |
|
212 | 0 | if (!isfinite(theta)) |
213 | 0 | theta = 0.0; // doesn't explain why GetAngle is returning NaN but solves it for us; |
214 | |
|
215 | 0 | delta = theta - theta0; |
216 | |
|
217 | 0 | if (linear) { |
218 | 0 | energy = 143.9325 * ka * (1.0 + cos((theta) * DEG_TO_RAD)); |
219 | 0 | dE = -sin((theta) * DEG_TO_RAD) * 143.9325 * ka; |
220 | 0 | } else { |
221 | 0 | delta2 = delta * delta; |
222 | 0 | energy = 0.043844 * 0.5 * ka * delta2 * (1.0 - 0.007 * delta); |
223 | 0 | dE = RAD_TO_DEG * 0.043844 * ka * delta * (1.0 - 1.5 * 0.007 * delta); |
224 | 0 | } |
225 | |
|
226 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
227 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
228 | 0 | OBForceField::VectorSelfMultiply(force_c, dE); |
229 | 0 | } else { |
230 | 0 | theta = OBForceField::VectorAngle(pos_a, pos_b, pos_c); |
231 | |
|
232 | 0 | if (!isfinite(theta)) |
233 | 0 | theta = 0.0; // doesn't explain why GetAngle is returning NaN but solves it for us; |
234 | |
|
235 | 0 | delta = theta - theta0; |
236 | |
|
237 | 0 | if (linear) { |
238 | 0 | energy = 143.9325 * ka * (1.0 + cos(theta * DEG_TO_RAD)); |
239 | 0 | } else { |
240 | 0 | delta2 = delta * delta; |
241 | 0 | energy = 0.043844 * 0.5 * ka * delta2 * (1.0 - 0.007 * delta); |
242 | 0 | } |
243 | |
|
244 | 0 | } |
245 | |
|
246 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFAngleCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFAngleCalculationMMFF94::Compute<false>() |
247 | | |
248 | | template<bool gradients> |
249 | | double OBForceFieldMMFF94::E_Angle() |
250 | 5.33k | { |
251 | 5.33k | double energy = 0.0; |
252 | | |
253 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
254 | 0 | OBFFLog("\nA N G L E B E N D I N G\n\n"); |
255 | 0 | OBFFLog("ATOM TYPES FF VALENCE IDEAL FORCE\n"); |
256 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE CONSTANT DELTA ENERGY\n"); |
257 | 0 | OBFFLog("-----------------------------------------------------------------------------\n"); |
258 | 0 | } |
259 | | |
260 | | #ifdef _OPENMP |
261 | | #pragma omp parallel for reduction(+:energy) |
262 | | #endif |
263 | 5.33k | for (int i = 0; i < _anglecalculations.size(); ++i) { |
264 | |
|
265 | 0 | _anglecalculations[i].template Compute<gradients>(); |
266 | 0 | energy += _anglecalculations[i].energy; |
267 | |
|
268 | 0 | #ifndef _OPENMP |
269 | 0 | if (gradients) { |
270 | 0 | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); |
271 | 0 | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); |
272 | 0 | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); |
273 | 0 | } |
274 | 0 | #endif |
275 | |
|
276 | 0 | IF_OBFF_LOGLVL_HIGH { |
277 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", |
278 | 0 | atoi(_anglecalculations[i].a->GetType()), atoi(_anglecalculations[i].b->GetType()), |
279 | 0 | atoi(_anglecalculations[i].c->GetType()), _anglecalculations[i].at, |
280 | 0 | _anglecalculations[i].theta, _anglecalculations[i].theta0, |
281 | 0 | _anglecalculations[i].ka, _anglecalculations[i].delta, |
282 | 0 | _anglecalculations[i].energy); |
283 | 0 | OBFFLog(_logbuf); |
284 | 0 | } |
285 | 0 | } |
286 | | |
287 | | #ifdef _OPENMP |
288 | | for (int i = 0; i < _anglecalculations.size(); ++i) { |
289 | | if (gradients) { |
290 | | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); |
291 | | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); |
292 | | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); |
293 | | } |
294 | | } |
295 | | #endif |
296 | | |
297 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
298 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ANGLE BENDING ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); |
299 | 0 | OBFFLog(_logbuf); |
300 | 0 | } |
301 | | |
302 | 5.33k | return energy; |
303 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_Angle<true>() Line | Count | Source | 250 | 1.81k | { | 251 | 1.81k | double energy = 0.0; | 252 | | | 253 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 254 | 0 | OBFFLog("\nA N G L E B E N D I N G\n\n"); | 255 | 0 | OBFFLog("ATOM TYPES FF VALENCE IDEAL FORCE\n"); | 256 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE CONSTANT DELTA ENERGY\n"); | 257 | 0 | OBFFLog("-----------------------------------------------------------------------------\n"); | 258 | 0 | } | 259 | | | 260 | | #ifdef _OPENMP | 261 | | #pragma omp parallel for reduction(+:energy) | 262 | | #endif | 263 | 1.81k | for (int i = 0; i < _anglecalculations.size(); ++i) { | 264 | |
| 265 | 0 | _anglecalculations[i].template Compute<gradients>(); | 266 | 0 | energy += _anglecalculations[i].energy; | 267 | |
| 268 | 0 | #ifndef _OPENMP | 269 | 0 | if (gradients) { | 270 | 0 | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); | 271 | 0 | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); | 272 | 0 | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); | 273 | 0 | } | 274 | 0 | #endif | 275 | |
| 276 | 0 | IF_OBFF_LOGLVL_HIGH { | 277 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 278 | 0 | atoi(_anglecalculations[i].a->GetType()), atoi(_anglecalculations[i].b->GetType()), | 279 | 0 | atoi(_anglecalculations[i].c->GetType()), _anglecalculations[i].at, | 280 | 0 | _anglecalculations[i].theta, _anglecalculations[i].theta0, | 281 | 0 | _anglecalculations[i].ka, _anglecalculations[i].delta, | 282 | 0 | _anglecalculations[i].energy); | 283 | 0 | OBFFLog(_logbuf); | 284 | 0 | } | 285 | 0 | } | 286 | | | 287 | | #ifdef _OPENMP | 288 | | for (int i = 0; i < _anglecalculations.size(); ++i) { | 289 | | if (gradients) { | 290 | | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); | 291 | | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); | 292 | | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); | 293 | | } | 294 | | } | 295 | | #endif | 296 | | | 297 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 298 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ANGLE BENDING ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 299 | 0 | OBFFLog(_logbuf); | 300 | 0 | } | 301 | | | 302 | 1.81k | return energy; | 303 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_Angle<false>() Line | Count | Source | 250 | 3.51k | { | 251 | 3.51k | double energy = 0.0; | 252 | | | 253 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 254 | 0 | OBFFLog("\nA N G L E B E N D I N G\n\n"); | 255 | 0 | OBFFLog("ATOM TYPES FF VALENCE IDEAL FORCE\n"); | 256 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE CONSTANT DELTA ENERGY\n"); | 257 | 0 | OBFFLog("-----------------------------------------------------------------------------\n"); | 258 | 0 | } | 259 | | | 260 | | #ifdef _OPENMP | 261 | | #pragma omp parallel for reduction(+:energy) | 262 | | #endif | 263 | 3.51k | for (int i = 0; i < _anglecalculations.size(); ++i) { | 264 | |
| 265 | 0 | _anglecalculations[i].template Compute<gradients>(); | 266 | 0 | energy += _anglecalculations[i].energy; | 267 | |
| 268 | 0 | #ifndef _OPENMP | 269 | 0 | if (gradients) { | 270 | 0 | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); | 271 | 0 | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); | 272 | 0 | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); | 273 | 0 | } | 274 | 0 | #endif | 275 | |
| 276 | 0 | IF_OBFF_LOGLVL_HIGH { | 277 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 278 | 0 | atoi(_anglecalculations[i].a->GetType()), atoi(_anglecalculations[i].b->GetType()), | 279 | 0 | atoi(_anglecalculations[i].c->GetType()), _anglecalculations[i].at, | 280 | 0 | _anglecalculations[i].theta, _anglecalculations[i].theta0, | 281 | 0 | _anglecalculations[i].ka, _anglecalculations[i].delta, | 282 | 0 | _anglecalculations[i].energy); | 283 | 0 | OBFFLog(_logbuf); | 284 | 0 | } | 285 | 0 | } | 286 | | | 287 | | #ifdef _OPENMP | 288 | | for (int i = 0; i < _anglecalculations.size(); ++i) { | 289 | | if (gradients) { | 290 | | AddGradient(_anglecalculations[i].force_a, _anglecalculations[i].idx_a); | 291 | | AddGradient(_anglecalculations[i].force_b, _anglecalculations[i].idx_b); | 292 | | AddGradient(_anglecalculations[i].force_c, _anglecalculations[i].idx_c); | 293 | | } | 294 | | } | 295 | | #endif | 296 | | | 297 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 298 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ANGLE BENDING ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 299 | 0 | OBFFLog(_logbuf); | 300 | 0 | } | 301 | | | 302 | 3.51k | return energy; | 303 | 3.51k | } |
|
304 | | |
305 | | // |
306 | | // MMFF part I - page 495 |
307 | | // |
308 | | // EBA_ijk = 2.51210 (kba_ijk /\r_ij + kba_kji /\r_kj) /\0_ijk |
309 | | // |
310 | | // kba_ijk force constant (md/rad) |
311 | | // kba_kji force constant (md/rad) |
312 | | // |
313 | | // /\r_xx see above |
314 | | // /\0_ijk see above |
315 | | // |
316 | | template<bool gradients> |
317 | | inline void OBFFStrBndCalculationMMFF94::Compute() |
318 | 0 | { |
319 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b, idx_c)) { |
320 | 0 | energy = 0.0; |
321 | 0 | return; |
322 | 0 | } |
323 | | |
324 | 0 | if (gradients) { |
325 | 0 | theta = OBForceField::VectorAngleDerivative(pos_a, pos_b, pos_c, |
326 | 0 | force_abc_a, force_abc_b, force_abc_c); |
327 | 0 | rab = OBForceField::VectorDistanceDerivative(pos_a, pos_b, force_ab_a, force_ab_b); |
328 | 0 | rbc = OBForceField::VectorDistanceDerivative(pos_b, pos_c, force_bc_b, force_bc_c); |
329 | 0 | } else { |
330 | 0 | theta = OBForceField::VectorAngle(pos_a, pos_b, pos_c); |
331 | 0 | rab = OBForceField::VectorDistance(pos_a, pos_b); |
332 | 0 | rbc = OBForceField::VectorDistance(pos_b, pos_c); |
333 | 0 | } |
334 | |
|
335 | 0 | if (!isfinite(theta)) |
336 | 0 | theta = 0.0; // doesn't explain why GetAngle is returning NaN but solves it for us; |
337 | |
|
338 | 0 | delta_theta = theta - theta0; |
339 | 0 | delta_rab = rab - rab0; |
340 | 0 | delta_rbc = rbc - rbc0; |
341 | 0 | const double factor = RAD_TO_DEG * (kbaABC * delta_rab + kbaCBA * delta_rbc); |
342 | |
|
343 | 0 | energy = DEG_TO_RAD * factor * delta_theta; |
344 | 0 | if (gradients) { |
345 | | //grada = 2.51210 * (kbaABC * rab_da * delta_theta + RAD_TO_DEG * theta_da * (kbaABC * delta_rab + kbaCBA * delta_rbc)); |
346 | 0 | OBForceField::VectorSelfMultiply(force_ab_a, (kbaABC*delta_theta)); |
347 | 0 | OBForceField::VectorSelfMultiply(force_abc_a, factor); |
348 | 0 | OBForceField::VectorAdd(force_ab_a, force_abc_a, force_ab_a); |
349 | 0 | OBForceField::VectorMultiply(force_ab_a, 2.51210, force_a); |
350 | | //gradc = 2.51210 * (kbaCBA * rbc_dc * delta_theta + RAD_TO_DEG * theta_dc * (kbaABC * delta_rab + kbaCBA * delta_rbc)); |
351 | 0 | OBForceField::VectorSelfMultiply(force_bc_c, (kbaCBA*delta_theta)); |
352 | 0 | OBForceField::VectorSelfMultiply(force_abc_c, factor); |
353 | 0 | OBForceField::VectorAdd(force_bc_c, force_abc_c, force_bc_c); |
354 | 0 | OBForceField::VectorMultiply(force_bc_c, 2.51210, force_c); |
355 | | //gradb = -grada - gradc; |
356 | 0 | OBForceField::VectorAdd(force_a, force_c, force_b); |
357 | 0 | OBForceField::VectorSelfMultiply(force_b, -1.0); |
358 | 0 | } |
359 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFStrBndCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFStrBndCalculationMMFF94::Compute<false>() |
360 | | |
361 | | template<bool gradients> |
362 | | double OBForceFieldMMFF94::E_StrBnd() |
363 | 5.33k | { |
364 | 5.33k | double energy = 0.0; |
365 | | |
366 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
367 | 0 | OBFFLog("\nS T R E T C H B E N D I N G\n\n"); |
368 | 0 | OBFFLog("ATOM TYPES FF VALENCE DELTA FORCE CONSTANT\n"); |
369 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE I J J K ENERGY\n"); |
370 | 0 | OBFFLog("---------------------------------------------------------------------------\n"); |
371 | 0 | } |
372 | | |
373 | | #ifdef _OPENMP |
374 | | #pragma omp parallel for reduction(+:energy) |
375 | | #endif |
376 | 5.33k | for (int i = 0; i < _strbndcalculations.size(); ++i) { |
377 | |
|
378 | 0 | _strbndcalculations[i].template Compute<gradients>(); |
379 | 0 | energy += _strbndcalculations[i].energy; |
380 | |
|
381 | 0 | #ifndef _OPENMP |
382 | 0 | if (gradients) { |
383 | 0 | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); |
384 | 0 | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); |
385 | 0 | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); |
386 | 0 | } |
387 | 0 | #endif |
388 | |
|
389 | 0 | IF_OBFF_LOGLVL_HIGH { |
390 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %8.3f %8.3f %8.3f %8.3f %8.3f\n", |
391 | 0 | atoi(_strbndcalculations[i].a->GetType()), atoi(_strbndcalculations[i].b->GetType()), |
392 | 0 | atoi(_strbndcalculations[i].c->GetType()), _strbndcalculations[i].sbt, |
393 | 0 | _strbndcalculations[i].theta, _strbndcalculations[i].delta_theta, |
394 | 0 | _strbndcalculations[i].kbaABC, _strbndcalculations[i].kbaCBA, |
395 | 0 | 2.51210 * _strbndcalculations[i].energy); |
396 | 0 | OBFFLog(_logbuf); |
397 | 0 | } |
398 | 0 | } |
399 | | |
400 | | #ifdef _OPENMP |
401 | | for (int i = 0; i < _strbndcalculations.size(); ++i) { |
402 | | if (gradients) { |
403 | | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); |
404 | | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); |
405 | | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); |
406 | | } |
407 | | } |
408 | | #endif |
409 | | |
410 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
411 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL STRETCH BENDING ENERGY = %8.5f %s\n", 2.51210 * energy, GetUnit().c_str()); |
412 | 0 | OBFFLog(_logbuf); |
413 | 0 | } |
414 | | |
415 | 5.33k | return (2.51210 * energy); |
416 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_StrBnd<true>() Line | Count | Source | 363 | 1.81k | { | 364 | 1.81k | double energy = 0.0; | 365 | | | 366 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 367 | 0 | OBFFLog("\nS T R E T C H B E N D I N G\n\n"); | 368 | 0 | OBFFLog("ATOM TYPES FF VALENCE DELTA FORCE CONSTANT\n"); | 369 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE I J J K ENERGY\n"); | 370 | 0 | OBFFLog("---------------------------------------------------------------------------\n"); | 371 | 0 | } | 372 | | | 373 | | #ifdef _OPENMP | 374 | | #pragma omp parallel for reduction(+:energy) | 375 | | #endif | 376 | 1.81k | for (int i = 0; i < _strbndcalculations.size(); ++i) { | 377 | |
| 378 | 0 | _strbndcalculations[i].template Compute<gradients>(); | 379 | 0 | energy += _strbndcalculations[i].energy; | 380 | |
| 381 | 0 | #ifndef _OPENMP | 382 | 0 | if (gradients) { | 383 | 0 | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); | 384 | 0 | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); | 385 | 0 | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); | 386 | 0 | } | 387 | 0 | #endif | 388 | |
| 389 | 0 | IF_OBFF_LOGLVL_HIGH { | 390 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 391 | 0 | atoi(_strbndcalculations[i].a->GetType()), atoi(_strbndcalculations[i].b->GetType()), | 392 | 0 | atoi(_strbndcalculations[i].c->GetType()), _strbndcalculations[i].sbt, | 393 | 0 | _strbndcalculations[i].theta, _strbndcalculations[i].delta_theta, | 394 | 0 | _strbndcalculations[i].kbaABC, _strbndcalculations[i].kbaCBA, | 395 | 0 | 2.51210 * _strbndcalculations[i].energy); | 396 | 0 | OBFFLog(_logbuf); | 397 | 0 | } | 398 | 0 | } | 399 | | | 400 | | #ifdef _OPENMP | 401 | | for (int i = 0; i < _strbndcalculations.size(); ++i) { | 402 | | if (gradients) { | 403 | | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); | 404 | | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); | 405 | | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); | 406 | | } | 407 | | } | 408 | | #endif | 409 | | | 410 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 411 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL STRETCH BENDING ENERGY = %8.5f %s\n", 2.51210 * energy, GetUnit().c_str()); | 412 | 0 | OBFFLog(_logbuf); | 413 | 0 | } | 414 | | | 415 | 1.81k | return (2.51210 * energy); | 416 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_StrBnd<false>() Line | Count | Source | 363 | 3.51k | { | 364 | 3.51k | double energy = 0.0; | 365 | | | 366 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 367 | 0 | OBFFLog("\nS T R E T C H B E N D I N G\n\n"); | 368 | 0 | OBFFLog("ATOM TYPES FF VALENCE DELTA FORCE CONSTANT\n"); | 369 | 0 | OBFFLog(" I J K CLASS ANGLE ANGLE I J J K ENERGY\n"); | 370 | 0 | OBFFLog("---------------------------------------------------------------------------\n"); | 371 | 0 | } | 372 | | | 373 | | #ifdef _OPENMP | 374 | | #pragma omp parallel for reduction(+:energy) | 375 | | #endif | 376 | 3.51k | for (int i = 0; i < _strbndcalculations.size(); ++i) { | 377 | |
| 378 | 0 | _strbndcalculations[i].template Compute<gradients>(); | 379 | 0 | energy += _strbndcalculations[i].energy; | 380 | |
| 381 | 0 | #ifndef _OPENMP | 382 | 0 | if (gradients) { | 383 | 0 | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); | 384 | 0 | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); | 385 | 0 | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); | 386 | 0 | } | 387 | 0 | #endif | 388 | |
| 389 | 0 | IF_OBFF_LOGLVL_HIGH { | 390 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %8.3f %8.3f %8.3f %8.3f %8.3f\n", | 391 | 0 | atoi(_strbndcalculations[i].a->GetType()), atoi(_strbndcalculations[i].b->GetType()), | 392 | 0 | atoi(_strbndcalculations[i].c->GetType()), _strbndcalculations[i].sbt, | 393 | 0 | _strbndcalculations[i].theta, _strbndcalculations[i].delta_theta, | 394 | 0 | _strbndcalculations[i].kbaABC, _strbndcalculations[i].kbaCBA, | 395 | 0 | 2.51210 * _strbndcalculations[i].energy); | 396 | 0 | OBFFLog(_logbuf); | 397 | 0 | } | 398 | 0 | } | 399 | | | 400 | | #ifdef _OPENMP | 401 | | for (int i = 0; i < _strbndcalculations.size(); ++i) { | 402 | | if (gradients) { | 403 | | AddGradient(_strbndcalculations[i].force_a, _strbndcalculations[i].idx_a); | 404 | | AddGradient(_strbndcalculations[i].force_b, _strbndcalculations[i].idx_b); | 405 | | AddGradient(_strbndcalculations[i].force_c, _strbndcalculations[i].idx_c); | 406 | | } | 407 | | } | 408 | | #endif | 409 | | | 410 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 411 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL STRETCH BENDING ENERGY = %8.5f %s\n", 2.51210 * energy, GetUnit().c_str()); | 412 | 0 | OBFFLog(_logbuf); | 413 | 0 | } | 414 | | | 415 | 3.51k | return (2.51210 * energy); | 416 | 3.51k | } |
|
417 | | |
418 | | int OBForceFieldMMFF94::GetElementRow(OBAtom *atom) |
419 | 0 | { |
420 | 0 | int row; |
421 | |
|
422 | 0 | row = 0; |
423 | |
|
424 | 0 | if (atom->GetAtomicNum() > 2) |
425 | 0 | row++; |
426 | 0 | if (atom->GetAtomicNum() > 10) |
427 | 0 | row++; |
428 | 0 | if (atom->GetAtomicNum() > 18) |
429 | 0 | row++; |
430 | 0 | if (atom->GetAtomicNum() > 36) |
431 | 0 | row++; |
432 | 0 | if (atom->GetAtomicNum() > 54) |
433 | 0 | row++; |
434 | 0 | if (atom->GetAtomicNum() > 86) |
435 | 0 | row++; |
436 | |
|
437 | 0 | return row; |
438 | 0 | } |
439 | | |
440 | | // |
441 | | // MMFF part I - page 495 |
442 | | // |
443 | | // ET_ijkl = 0.5 ( V1 (1 + cos(0_ijkl)) + V2 (1 - cos(2 0_ijkl)) + V3 (1 + cos(3 0_ijkl)) ) |
444 | | // |
445 | | // V1 force constant (md/rad) |
446 | | // V2 force constant (md/rad) |
447 | | // V3 force constant (md/rad) |
448 | | // |
449 | | // 0_ijkl torsion angle (degrees) |
450 | | // |
451 | | template<bool gradients> |
452 | | inline void OBFFTorsionCalculationMMFF94::Compute() |
453 | 0 | { |
454 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b, idx_c, idx_d)) { |
455 | 0 | energy = 0.0; |
456 | 0 | return; |
457 | 0 | } |
458 | | |
459 | 0 | double cosine, cosine2, cosine3; |
460 | 0 | double phi1, phi2, phi3; |
461 | 0 | double dE, sine, sine2, sine3; |
462 | |
|
463 | 0 | if (gradients) { |
464 | 0 | tor = OBForceField::VectorTorsionDerivative(pos_a, pos_b, pos_c, pos_d, |
465 | 0 | force_a, force_b, force_c, force_d); |
466 | 0 | if (!isfinite(tor)) |
467 | 0 | tor = 1.0e-3; |
468 | |
|
469 | 0 | sine = sin(DEG_TO_RAD * tor); |
470 | 0 | sine2 = sin(2.0 * DEG_TO_RAD * tor); |
471 | 0 | sine3 = sin(3.0 * DEG_TO_RAD * tor); |
472 | |
|
473 | 0 | dE = 0.5 * (v1 * sine - 2.0 * v2 * sine2 + 3.0 * v3 * sine3); // MMFF |
474 | |
|
475 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
476 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
477 | 0 | OBForceField::VectorSelfMultiply(force_c, dE); |
478 | 0 | OBForceField::VectorSelfMultiply(force_d, dE); |
479 | 0 | } else { |
480 | 0 | tor = OBForceField::VectorTorsion(pos_a, pos_b, pos_c, pos_d); |
481 | 0 | if (!isfinite(tor)) |
482 | 0 | tor = 1.0e-3; |
483 | 0 | } |
484 | |
|
485 | 0 | cosine = cos(DEG_TO_RAD * tor); |
486 | 0 | cosine2 = cos(DEG_TO_RAD * 2 * tor); |
487 | 0 | cosine3 = cos(DEG_TO_RAD * 3 * tor); |
488 | |
|
489 | 0 | phi1 = 1.0 + cosine; |
490 | 0 | phi2 = 1.0 - cosine2; |
491 | 0 | phi3 = 1.0 + cosine3; |
492 | |
|
493 | 0 | energy = (v1 * phi1 + v2 * phi2 + v3 * phi3); |
494 | |
|
495 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFTorsionCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFTorsionCalculationMMFF94::Compute<false>() |
496 | | |
497 | | template<bool gradients> |
498 | | double OBForceFieldMMFF94::E_Torsion() |
499 | 5.33k | { |
500 | 5.33k | double energy = 0.0; |
501 | | |
502 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
503 | 0 | OBFFLog("\nT O R S I O N A L\n\n"); |
504 | 0 | OBFFLog("ATOM TYPES FF TORSION FORCE CONSTANT\n"); |
505 | 0 | OBFFLog(" I J K L CLASS ANGLE V1 V2 V3 ENERGY\n"); |
506 | 0 | OBFFLog("--------------------------------------------------------------------\n"); |
507 | 0 | } |
508 | | |
509 | | #ifdef _OPENMP |
510 | | #pragma omp parallel for reduction(+:energy) |
511 | | #endif |
512 | 5.33k | for (int i = 0; i < _torsioncalculations.size(); ++i) { |
513 | |
|
514 | 0 | _torsioncalculations[i].template Compute<gradients>(); |
515 | 0 | energy += _torsioncalculations[i].energy; |
516 | |
|
517 | 0 | #ifndef _OPENMP |
518 | 0 | if (gradients) { |
519 | 0 | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); |
520 | 0 | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); |
521 | 0 | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); |
522 | 0 | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); |
523 | 0 | } |
524 | 0 | #endif |
525 | |
|
526 | 0 | IF_OBFF_LOGLVL_HIGH { |
527 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %d %8.3f %6.3f %6.3f %6.3f %8.3f\n", |
528 | 0 | atoi(_torsioncalculations[i].a->GetType()), atoi(_torsioncalculations[i].b->GetType()), |
529 | 0 | atoi(_torsioncalculations[i].c->GetType()), atoi(_torsioncalculations[i].d->GetType()), |
530 | 0 | _torsioncalculations[i].tt, _torsioncalculations[i].tor, _torsioncalculations[i].v1, |
531 | 0 | _torsioncalculations[i].v2, _torsioncalculations[i].v3, 0.5 * _torsioncalculations[i].energy); |
532 | 0 | OBFFLog(_logbuf); |
533 | 0 | } |
534 | |
|
535 | 0 | } |
536 | | |
537 | | #ifdef _OPENMP |
538 | | for (int i = 0; i < _torsioncalculations.size(); ++i) { |
539 | | if (gradients) { |
540 | | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); |
541 | | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); |
542 | | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); |
543 | | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); |
544 | | } |
545 | | } |
546 | | #endif |
547 | | |
548 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
549 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL TORSIONAL ENERGY = %8.5f %s\n", 0.5 * energy, GetUnit().c_str()); |
550 | 0 | OBFFLog(_logbuf); |
551 | 0 | } |
552 | | |
553 | 5.33k | return (0.5 * energy); |
554 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_Torsion<true>() Line | Count | Source | 499 | 1.81k | { | 500 | 1.81k | double energy = 0.0; | 501 | | | 502 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 503 | 0 | OBFFLog("\nT O R S I O N A L\n\n"); | 504 | 0 | OBFFLog("ATOM TYPES FF TORSION FORCE CONSTANT\n"); | 505 | 0 | OBFFLog(" I J K L CLASS ANGLE V1 V2 V3 ENERGY\n"); | 506 | 0 | OBFFLog("--------------------------------------------------------------------\n"); | 507 | 0 | } | 508 | | | 509 | | #ifdef _OPENMP | 510 | | #pragma omp parallel for reduction(+:energy) | 511 | | #endif | 512 | 1.81k | for (int i = 0; i < _torsioncalculations.size(); ++i) { | 513 | |
| 514 | 0 | _torsioncalculations[i].template Compute<gradients>(); | 515 | 0 | energy += _torsioncalculations[i].energy; | 516 | |
| 517 | 0 | #ifndef _OPENMP | 518 | 0 | if (gradients) { | 519 | 0 | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); | 520 | 0 | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); | 521 | 0 | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); | 522 | 0 | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); | 523 | 0 | } | 524 | 0 | #endif | 525 | |
| 526 | 0 | IF_OBFF_LOGLVL_HIGH { | 527 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %d %8.3f %6.3f %6.3f %6.3f %8.3f\n", | 528 | 0 | atoi(_torsioncalculations[i].a->GetType()), atoi(_torsioncalculations[i].b->GetType()), | 529 | 0 | atoi(_torsioncalculations[i].c->GetType()), atoi(_torsioncalculations[i].d->GetType()), | 530 | 0 | _torsioncalculations[i].tt, _torsioncalculations[i].tor, _torsioncalculations[i].v1, | 531 | 0 | _torsioncalculations[i].v2, _torsioncalculations[i].v3, 0.5 * _torsioncalculations[i].energy); | 532 | 0 | OBFFLog(_logbuf); | 533 | 0 | } | 534 | |
| 535 | 0 | } | 536 | | | 537 | | #ifdef _OPENMP | 538 | | for (int i = 0; i < _torsioncalculations.size(); ++i) { | 539 | | if (gradients) { | 540 | | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); | 541 | | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); | 542 | | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); | 543 | | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); | 544 | | } | 545 | | } | 546 | | #endif | 547 | | | 548 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 549 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL TORSIONAL ENERGY = %8.5f %s\n", 0.5 * energy, GetUnit().c_str()); | 550 | 0 | OBFFLog(_logbuf); | 551 | 0 | } | 552 | | | 553 | 1.81k | return (0.5 * energy); | 554 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_Torsion<false>() Line | Count | Source | 499 | 3.51k | { | 500 | 3.51k | double energy = 0.0; | 501 | | | 502 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 503 | 0 | OBFFLog("\nT O R S I O N A L\n\n"); | 504 | 0 | OBFFLog("ATOM TYPES FF TORSION FORCE CONSTANT\n"); | 505 | 0 | OBFFLog(" I J K L CLASS ANGLE V1 V2 V3 ENERGY\n"); | 506 | 0 | OBFFLog("--------------------------------------------------------------------\n"); | 507 | 0 | } | 508 | | | 509 | | #ifdef _OPENMP | 510 | | #pragma omp parallel for reduction(+:energy) | 511 | | #endif | 512 | 3.51k | for (int i = 0; i < _torsioncalculations.size(); ++i) { | 513 | |
| 514 | 0 | _torsioncalculations[i].template Compute<gradients>(); | 515 | 0 | energy += _torsioncalculations[i].energy; | 516 | |
| 517 | 0 | #ifndef _OPENMP | 518 | 0 | if (gradients) { | 519 | 0 | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); | 520 | 0 | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); | 521 | 0 | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); | 522 | 0 | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); | 523 | 0 | } | 524 | 0 | #endif | 525 | |
| 526 | 0 | IF_OBFF_LOGLVL_HIGH { | 527 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d %d %8.3f %6.3f %6.3f %6.3f %8.3f\n", | 528 | 0 | atoi(_torsioncalculations[i].a->GetType()), atoi(_torsioncalculations[i].b->GetType()), | 529 | 0 | atoi(_torsioncalculations[i].c->GetType()), atoi(_torsioncalculations[i].d->GetType()), | 530 | 0 | _torsioncalculations[i].tt, _torsioncalculations[i].tor, _torsioncalculations[i].v1, | 531 | 0 | _torsioncalculations[i].v2, _torsioncalculations[i].v3, 0.5 * _torsioncalculations[i].energy); | 532 | 0 | OBFFLog(_logbuf); | 533 | 0 | } | 534 | |
| 535 | 0 | } | 536 | | | 537 | | #ifdef _OPENMP | 538 | | for (int i = 0; i < _torsioncalculations.size(); ++i) { | 539 | | if (gradients) { | 540 | | AddGradient(_torsioncalculations[i].force_a, _torsioncalculations[i].idx_a); | 541 | | AddGradient(_torsioncalculations[i].force_b, _torsioncalculations[i].idx_b); | 542 | | AddGradient(_torsioncalculations[i].force_c, _torsioncalculations[i].idx_c); | 543 | | AddGradient(_torsioncalculations[i].force_d, _torsioncalculations[i].idx_d); | 544 | | } | 545 | | } | 546 | | #endif | 547 | | | 548 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 549 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL TORSIONAL ENERGY = %8.5f %s\n", 0.5 * energy, GetUnit().c_str()); | 550 | 0 | OBFFLog(_logbuf); | 551 | 0 | } | 552 | | | 553 | 3.51k | return (0.5 * energy); | 554 | 3.51k | } |
|
555 | | |
556 | | // // |
557 | | // a // |
558 | | // \ // |
559 | | // b---d plane = a-b-c // |
560 | | // / // |
561 | | // c // |
562 | | // // |
563 | | template<bool gradients> |
564 | | void OBFFOOPCalculationMMFF94::Compute() |
565 | 0 | { |
566 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b, idx_c, idx_d)) { |
567 | 0 | energy = 0.0; |
568 | 0 | return; |
569 | 0 | } |
570 | | |
571 | 0 | double angle2, dE; |
572 | |
|
573 | 0 | if (gradients) { |
574 | 0 | angle = OBForceField::VectorOOPDerivative(pos_a, pos_b, pos_c, pos_d, |
575 | 0 | force_a, force_b, force_c, force_d); |
576 | |
|
577 | 0 | dE = (-1.0 * RAD_TO_DEG * 0.043844 * angle * koop) / cos(angle * DEG_TO_RAD); |
578 | |
|
579 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
580 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
581 | 0 | OBForceField::VectorSelfMultiply(force_c, dE); |
582 | 0 | OBForceField::VectorSelfMultiply(force_d, dE); |
583 | 0 | } else { |
584 | 0 | angle = OBForceField::VectorOOP(pos_a, pos_b, pos_c, pos_d); |
585 | 0 | } |
586 | |
|
587 | 0 | if (!isfinite(angle)) |
588 | 0 | angle = 0.0; // doesn't explain why GetAngle is returning NaN but solves it for us; |
589 | |
|
590 | 0 | angle2 = angle * angle; |
591 | 0 | energy = koop * angle2; |
592 | |
|
593 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFOOPCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFOOPCalculationMMFF94::Compute<false>() |
594 | | |
595 | | template<bool gradients> |
596 | | double OBForceFieldMMFF94::E_OOP() |
597 | 5.33k | { |
598 | 5.33k | double energy = 0.0; |
599 | | |
600 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
601 | 0 | OBFFLog("\nO U T - O F - P L A N E B E N D I N G\n\n"); |
602 | 0 | OBFFLog("ATOM TYPES FF OOP FORCE\n"); |
603 | 0 | OBFFLog(" I J K L CLASS ANGLE CONSTANT ENERGY\n"); |
604 | 0 | OBFFLog("----------------------------------------------------------\n"); |
605 | 0 | } |
606 | | |
607 | | #ifdef _OPENMP |
608 | | #pragma omp parallel for reduction(+:energy) |
609 | | #endif |
610 | 5.33k | for (int i = 0; i < _oopcalculations.size(); ++i) { |
611 | |
|
612 | 0 | _oopcalculations[i].template Compute<gradients>(); |
613 | 0 | energy += _oopcalculations[i].energy; |
614 | |
|
615 | 0 | #ifndef _OPENMP |
616 | 0 | if (gradients) { |
617 | 0 | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); |
618 | 0 | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); |
619 | 0 | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); |
620 | 0 | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); |
621 | 0 | } |
622 | 0 | #endif |
623 | |
|
624 | 0 | IF_OBFF_LOGLVL_HIGH { |
625 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d 0 %8.3f %8.3f %8.3f\n", |
626 | 0 | atoi(_oopcalculations[i].a->GetType()), atoi(_oopcalculations[i].b->GetType()), |
627 | 0 | atoi(_oopcalculations[i].c->GetType()), atoi(_oopcalculations[i].d->GetType()), |
628 | 0 | _oopcalculations[i].angle, _oopcalculations[i].koop, |
629 | 0 | 0.043844 * 0.5 * _oopcalculations[i].energy); |
630 | 0 | OBFFLog(_logbuf); |
631 | 0 | } |
632 | 0 | } |
633 | | |
634 | | #ifdef _OPENMP |
635 | | for (int i = 0; i < _oopcalculations.size(); ++i) { |
636 | | if (gradients) { |
637 | | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); |
638 | | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); |
639 | | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); |
640 | | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); |
641 | | } |
642 | | } |
643 | | #endif |
644 | | |
645 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
646 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL OUT-OF-PLANE BENDING ENERGY = %8.5f %s\n", 0.043844 * 0.5 * energy, GetUnit().c_str()); |
647 | 0 | OBFFLog(_logbuf); |
648 | 0 | } |
649 | | |
650 | 5.33k | return (0.043844 * 0.5 * energy); |
651 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_OOP<true>() Line | Count | Source | 597 | 1.81k | { | 598 | 1.81k | double energy = 0.0; | 599 | | | 600 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 601 | 0 | OBFFLog("\nO U T - O F - P L A N E B E N D I N G\n\n"); | 602 | 0 | OBFFLog("ATOM TYPES FF OOP FORCE\n"); | 603 | 0 | OBFFLog(" I J K L CLASS ANGLE CONSTANT ENERGY\n"); | 604 | 0 | OBFFLog("----------------------------------------------------------\n"); | 605 | 0 | } | 606 | | | 607 | | #ifdef _OPENMP | 608 | | #pragma omp parallel for reduction(+:energy) | 609 | | #endif | 610 | 1.81k | for (int i = 0; i < _oopcalculations.size(); ++i) { | 611 | |
| 612 | 0 | _oopcalculations[i].template Compute<gradients>(); | 613 | 0 | energy += _oopcalculations[i].energy; | 614 | |
| 615 | 0 | #ifndef _OPENMP | 616 | 0 | if (gradients) { | 617 | 0 | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); | 618 | 0 | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); | 619 | 0 | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); | 620 | 0 | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); | 621 | 0 | } | 622 | 0 | #endif | 623 | |
| 624 | 0 | IF_OBFF_LOGLVL_HIGH { | 625 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d 0 %8.3f %8.3f %8.3f\n", | 626 | 0 | atoi(_oopcalculations[i].a->GetType()), atoi(_oopcalculations[i].b->GetType()), | 627 | 0 | atoi(_oopcalculations[i].c->GetType()), atoi(_oopcalculations[i].d->GetType()), | 628 | 0 | _oopcalculations[i].angle, _oopcalculations[i].koop, | 629 | 0 | 0.043844 * 0.5 * _oopcalculations[i].energy); | 630 | 0 | OBFFLog(_logbuf); | 631 | 0 | } | 632 | 0 | } | 633 | | | 634 | | #ifdef _OPENMP | 635 | | for (int i = 0; i < _oopcalculations.size(); ++i) { | 636 | | if (gradients) { | 637 | | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); | 638 | | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); | 639 | | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); | 640 | | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); | 641 | | } | 642 | | } | 643 | | #endif | 644 | | | 645 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 646 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL OUT-OF-PLANE BENDING ENERGY = %8.5f %s\n", 0.043844 * 0.5 * energy, GetUnit().c_str()); | 647 | 0 | OBFFLog(_logbuf); | 648 | 0 | } | 649 | | | 650 | 1.81k | return (0.043844 * 0.5 * energy); | 651 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_OOP<false>() Line | Count | Source | 597 | 3.51k | { | 598 | 3.51k | double energy = 0.0; | 599 | | | 600 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 601 | 0 | OBFFLog("\nO U T - O F - P L A N E B E N D I N G\n\n"); | 602 | 0 | OBFFLog("ATOM TYPES FF OOP FORCE\n"); | 603 | 0 | OBFFLog(" I J K L CLASS ANGLE CONSTANT ENERGY\n"); | 604 | 0 | OBFFLog("----------------------------------------------------------\n"); | 605 | 0 | } | 606 | | | 607 | | #ifdef _OPENMP | 608 | | #pragma omp parallel for reduction(+:energy) | 609 | | #endif | 610 | 3.51k | for (int i = 0; i < _oopcalculations.size(); ++i) { | 611 | |
| 612 | 0 | _oopcalculations[i].template Compute<gradients>(); | 613 | 0 | energy += _oopcalculations[i].energy; | 614 | |
| 615 | 0 | #ifndef _OPENMP | 616 | 0 | if (gradients) { | 617 | 0 | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); | 618 | 0 | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); | 619 | 0 | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); | 620 | 0 | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); | 621 | 0 | } | 622 | 0 | #endif | 623 | |
| 624 | 0 | IF_OBFF_LOGLVL_HIGH { | 625 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %2d %2d 0 %8.3f %8.3f %8.3f\n", | 626 | 0 | atoi(_oopcalculations[i].a->GetType()), atoi(_oopcalculations[i].b->GetType()), | 627 | 0 | atoi(_oopcalculations[i].c->GetType()), atoi(_oopcalculations[i].d->GetType()), | 628 | 0 | _oopcalculations[i].angle, _oopcalculations[i].koop, | 629 | 0 | 0.043844 * 0.5 * _oopcalculations[i].energy); | 630 | 0 | OBFFLog(_logbuf); | 631 | 0 | } | 632 | 0 | } | 633 | | | 634 | | #ifdef _OPENMP | 635 | | for (int i = 0; i < _oopcalculations.size(); ++i) { | 636 | | if (gradients) { | 637 | | AddGradient(_oopcalculations[i].force_a, _oopcalculations[i].idx_a); | 638 | | AddGradient(_oopcalculations[i].force_b, _oopcalculations[i].idx_b); | 639 | | AddGradient(_oopcalculations[i].force_c, _oopcalculations[i].idx_c); | 640 | | AddGradient(_oopcalculations[i].force_d, _oopcalculations[i].idx_d); | 641 | | } | 642 | | } | 643 | | #endif | 644 | | | 645 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 646 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL OUT-OF-PLANE BENDING ENERGY = %8.5f %s\n", 0.043844 * 0.5 * energy, GetUnit().c_str()); | 647 | 0 | OBFFLog(_logbuf); | 648 | 0 | } | 649 | | | 650 | 3.51k | return (0.043844 * 0.5 * energy); | 651 | 3.51k | } |
|
652 | | |
653 | | template<bool gradients> |
654 | | inline void OBFFVDWCalculationMMFF94::Compute() |
655 | 0 | { |
656 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b)) { |
657 | 0 | energy = 0.0; |
658 | 0 | return; |
659 | 0 | } |
660 | | |
661 | 0 | if (gradients) { |
662 | 0 | rab = OBForceField::VectorDistanceDerivative(pos_a, pos_b, force_a, force_b); |
663 | 0 | } else { |
664 | 0 | rab = OBForceField::VectorDistance(pos_a, pos_b); |
665 | 0 | } |
666 | |
|
667 | 0 | const double rab7 = rab*rab*rab*rab*rab*rab*rab; |
668 | |
|
669 | 0 | double erep = (1.07 * R_AB) / (rab + 0.07 * R_AB); //*** |
670 | 0 | double erep7 = erep*erep*erep*erep*erep*erep*erep; |
671 | |
|
672 | 0 | double eattr = (((1.12 * R_AB7) / (rab7 + 0.12 * R_AB7)) - 2.0); |
673 | |
|
674 | 0 | energy = epsilon * erep7 * eattr; |
675 | |
|
676 | 0 | if (gradients) { |
677 | 0 | const double q = rab / R_AB; |
678 | 0 | const double q6 = q*q*q*q*q*q; |
679 | 0 | const double q7 = q6 * q; |
680 | 0 | erep = 1.07 / (q + 0.07); |
681 | 0 | erep7 = erep*erep*erep*erep*erep*erep*erep; |
682 | 0 | const double term = q7 + 0.12; |
683 | 0 | const double term2 = term * term; |
684 | 0 | eattr = (-7.84 * q6) / term2 + ((-7.84 / term) + 14) / (q + 0.07); |
685 | 0 | const double dE = (epsilon / R_AB) * erep7 * eattr; |
686 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
687 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
688 | 0 | } |
689 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFVDWCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFVDWCalculationMMFF94::Compute<false>() |
690 | | |
691 | | template<bool gradients> |
692 | | double OBForceFieldMMFF94::E_VDW() |
693 | 5.33k | { |
694 | 5.33k | double energy = 0.0; |
695 | | |
696 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
697 | 0 | OBFFLog("\nV A N D E R W A A L S\n\n"); |
698 | 0 | OBFFLog("ATOM TYPES\n"); |
699 | 0 | OBFFLog(" I J Rij R*IJ EPSILON ENERGY\n"); |
700 | 0 | OBFFLog("--------------------------------------------------\n"); |
701 | | // XX XX -000.000 -000.000 -000.000 -000.000 |
702 | 0 | } |
703 | | |
704 | | #ifdef _OPENMP |
705 | | #pragma omp parallel for reduction(+:energy) |
706 | | #endif |
707 | 5.33k | for (int i = 0; i < _vdwcalculations.size(); ++i) { |
708 | | // Cut-off check |
709 | 0 | if (_cutoff) |
710 | 0 | if (!_vdwpairs.BitIsSet(_vdwcalculations[i].pairIndex)) |
711 | 0 | continue; |
712 | | |
713 | 0 | _vdwcalculations[i].template Compute<gradients>(); |
714 | 0 | energy += _vdwcalculations[i].energy; |
715 | |
|
716 | 0 | #ifndef _OPENMP |
717 | 0 | if (gradients) { |
718 | 0 | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); |
719 | 0 | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); |
720 | 0 | } |
721 | 0 | #endif |
722 | |
|
723 | 0 | IF_OBFF_LOGLVL_HIGH { |
724 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", |
725 | 0 | atoi(_vdwcalculations[i].a->GetType()), atoi(_vdwcalculations[i].b->GetType()), |
726 | 0 | _vdwcalculations[i].rab, _vdwcalculations[i].R_AB, _vdwcalculations[i].epsilon, _vdwcalculations[i].energy); |
727 | 0 | OBFFLog(_logbuf); |
728 | 0 | } |
729 | |
|
730 | 0 | } |
731 | | |
732 | | #ifdef _OPENMP |
733 | | for (int i = 0; i < _vdwcalculations.size(); ++i) { |
734 | | // Cut-off check |
735 | | if (_cutoff) |
736 | | if (!_vdwpairs.BitIsSet(i)) |
737 | | continue; |
738 | | |
739 | | if (gradients) { |
740 | | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); |
741 | | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); |
742 | | } |
743 | | } |
744 | | #endif |
745 | | |
746 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
747 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL VAN DER WAALS ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); |
748 | 0 | OBFFLog(_logbuf); |
749 | 0 | } |
750 | | |
751 | 5.33k | return energy; |
752 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_VDW<true>() Line | Count | Source | 693 | 1.81k | { | 694 | 1.81k | double energy = 0.0; | 695 | | | 696 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 697 | 0 | OBFFLog("\nV A N D E R W A A L S\n\n"); | 698 | 0 | OBFFLog("ATOM TYPES\n"); | 699 | 0 | OBFFLog(" I J Rij R*IJ EPSILON ENERGY\n"); | 700 | 0 | OBFFLog("--------------------------------------------------\n"); | 701 | | // XX XX -000.000 -000.000 -000.000 -000.000 | 702 | 0 | } | 703 | | | 704 | | #ifdef _OPENMP | 705 | | #pragma omp parallel for reduction(+:energy) | 706 | | #endif | 707 | 1.81k | for (int i = 0; i < _vdwcalculations.size(); ++i) { | 708 | | // Cut-off check | 709 | 0 | if (_cutoff) | 710 | 0 | if (!_vdwpairs.BitIsSet(_vdwcalculations[i].pairIndex)) | 711 | 0 | continue; | 712 | | | 713 | 0 | _vdwcalculations[i].template Compute<gradients>(); | 714 | 0 | energy += _vdwcalculations[i].energy; | 715 | |
| 716 | 0 | #ifndef _OPENMP | 717 | 0 | if (gradients) { | 718 | 0 | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); | 719 | 0 | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); | 720 | 0 | } | 721 | 0 | #endif | 722 | |
| 723 | 0 | IF_OBFF_LOGLVL_HIGH { | 724 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", | 725 | 0 | atoi(_vdwcalculations[i].a->GetType()), atoi(_vdwcalculations[i].b->GetType()), | 726 | 0 | _vdwcalculations[i].rab, _vdwcalculations[i].R_AB, _vdwcalculations[i].epsilon, _vdwcalculations[i].energy); | 727 | 0 | OBFFLog(_logbuf); | 728 | 0 | } | 729 | |
| 730 | 0 | } | 731 | | | 732 | | #ifdef _OPENMP | 733 | | for (int i = 0; i < _vdwcalculations.size(); ++i) { | 734 | | // Cut-off check | 735 | | if (_cutoff) | 736 | | if (!_vdwpairs.BitIsSet(i)) | 737 | | continue; | 738 | | | 739 | | if (gradients) { | 740 | | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); | 741 | | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); | 742 | | } | 743 | | } | 744 | | #endif | 745 | | | 746 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 747 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL VAN DER WAALS ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 748 | 0 | OBFFLog(_logbuf); | 749 | 0 | } | 750 | | | 751 | 1.81k | return energy; | 752 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_VDW<false>() Line | Count | Source | 693 | 3.51k | { | 694 | 3.51k | double energy = 0.0; | 695 | | | 696 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 697 | 0 | OBFFLog("\nV A N D E R W A A L S\n\n"); | 698 | 0 | OBFFLog("ATOM TYPES\n"); | 699 | 0 | OBFFLog(" I J Rij R*IJ EPSILON ENERGY\n"); | 700 | 0 | OBFFLog("--------------------------------------------------\n"); | 701 | | // XX XX -000.000 -000.000 -000.000 -000.000 | 702 | 0 | } | 703 | | | 704 | | #ifdef _OPENMP | 705 | | #pragma omp parallel for reduction(+:energy) | 706 | | #endif | 707 | 3.51k | for (int i = 0; i < _vdwcalculations.size(); ++i) { | 708 | | // Cut-off check | 709 | 0 | if (_cutoff) | 710 | 0 | if (!_vdwpairs.BitIsSet(_vdwcalculations[i].pairIndex)) | 711 | 0 | continue; | 712 | | | 713 | 0 | _vdwcalculations[i].template Compute<gradients>(); | 714 | 0 | energy += _vdwcalculations[i].energy; | 715 | |
| 716 | 0 | #ifndef _OPENMP | 717 | 0 | if (gradients) { | 718 | 0 | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); | 719 | 0 | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); | 720 | 0 | } | 721 | 0 | #endif | 722 | |
| 723 | 0 | IF_OBFF_LOGLVL_HIGH { | 724 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", | 725 | 0 | atoi(_vdwcalculations[i].a->GetType()), atoi(_vdwcalculations[i].b->GetType()), | 726 | 0 | _vdwcalculations[i].rab, _vdwcalculations[i].R_AB, _vdwcalculations[i].epsilon, _vdwcalculations[i].energy); | 727 | 0 | OBFFLog(_logbuf); | 728 | 0 | } | 729 | |
| 730 | 0 | } | 731 | | | 732 | | #ifdef _OPENMP | 733 | | for (int i = 0; i < _vdwcalculations.size(); ++i) { | 734 | | // Cut-off check | 735 | | if (_cutoff) | 736 | | if (!_vdwpairs.BitIsSet(i)) | 737 | | continue; | 738 | | | 739 | | if (gradients) { | 740 | | AddGradient(_vdwcalculations[i].force_a, _vdwcalculations[i].idx_a); | 741 | | AddGradient(_vdwcalculations[i].force_b, _vdwcalculations[i].idx_b); | 742 | | } | 743 | | } | 744 | | #endif | 745 | | | 746 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 747 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL VAN DER WAALS ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 748 | 0 | OBFFLog(_logbuf); | 749 | 0 | } | 750 | | | 751 | 3.51k | return energy; | 752 | 3.51k | } |
|
753 | | |
754 | | template<bool gradients> |
755 | | inline void OBFFElectrostaticCalculationMMFF94::Compute() |
756 | 0 | { |
757 | 0 | if (OBForceField::IgnoreCalculation(idx_a, idx_b)) { |
758 | 0 | energy = 0.0; |
759 | 0 | return; |
760 | 0 | } |
761 | | |
762 | 0 | if (gradients) { |
763 | 0 | rab = OBForceField::VectorDistanceDerivative(pos_a, pos_b, force_a, force_b); |
764 | 0 | rab += 0.05; // ?? |
765 | 0 | const double rab2 = rab * rab; |
766 | 0 | const double dE = -qq / rab2; |
767 | 0 | OBForceField::VectorSelfMultiply(force_a, dE); |
768 | 0 | OBForceField::VectorSelfMultiply(force_b, dE); |
769 | 0 | } else { |
770 | 0 | rab = OBForceField::VectorDistance(pos_a, pos_b); |
771 | 0 | rab += 0.05; // ?? |
772 | 0 | } |
773 | |
|
774 | 0 | energy = qq / rab; |
775 | 0 | } Unexecuted instantiation: void OpenBabel::OBFFElectrostaticCalculationMMFF94::Compute<true>() Unexecuted instantiation: void OpenBabel::OBFFElectrostaticCalculationMMFF94::Compute<false>() |
776 | | |
777 | | template<bool gradients> |
778 | | double OBForceFieldMMFF94::E_Electrostatic() |
779 | 5.33k | { |
780 | 5.33k | double energy = 0.0; |
781 | | |
782 | 5.33k | IF_OBFF_LOGLVL_HIGH { |
783 | 0 | OBFFLog("\nE L E C T R O S T A T I C I N T E R A C T I O N S\n\n"); |
784 | 0 | OBFFLog("ATOM TYPES\n"); |
785 | 0 | OBFFLog(" I J Rij Qi Qj ENERGY\n"); |
786 | 0 | OBFFLog("-----------------------------------------------------\n"); |
787 | | // XX XX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX |
788 | 0 | } |
789 | | |
790 | | #ifdef _OPENMP |
791 | | #pragma omp parallel for reduction(+:energy) |
792 | | #endif |
793 | 5.33k | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { |
794 | | // Cut-off check |
795 | 0 | if (_cutoff) |
796 | 0 | if (!_elepairs.BitIsSet(_electrostaticcalculations[i].pairIndex)) |
797 | 0 | continue; |
798 | | |
799 | 0 | _electrostaticcalculations[i].template Compute<gradients>(); |
800 | 0 | energy += _electrostaticcalculations[i].energy; |
801 | |
|
802 | 0 | #ifndef _OPENMP |
803 | 0 | if (gradients) { |
804 | 0 | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); |
805 | 0 | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); |
806 | 0 | } |
807 | 0 | #endif |
808 | |
|
809 | 0 | IF_OBFF_LOGLVL_HIGH { |
810 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", |
811 | 0 | atoi(_electrostaticcalculations[i].a->GetType()), atoi(_electrostaticcalculations[i].b->GetType()), |
812 | 0 | _electrostaticcalculations[i].rab, _electrostaticcalculations[i].a->GetPartialCharge(), |
813 | 0 | _electrostaticcalculations[i].b->GetPartialCharge(), _electrostaticcalculations[i].energy); |
814 | 0 | OBFFLog(_logbuf); |
815 | 0 | } |
816 | 0 | } |
817 | | |
818 | | #ifdef _OPENMP |
819 | | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { |
820 | | // Cut-off check |
821 | | if (_cutoff) |
822 | | if (!_elepairs.BitIsSet(i)) |
823 | | continue; |
824 | | |
825 | | if (gradients) { |
826 | | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); |
827 | | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); |
828 | | } |
829 | | } |
830 | | #endif |
831 | | |
832 | 5.33k | IF_OBFF_LOGLVL_MEDIUM { |
833 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ELECTROSTATIC ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); |
834 | 0 | OBFFLog(_logbuf); |
835 | 0 | } |
836 | | |
837 | 5.33k | return energy; |
838 | 5.33k | } double OpenBabel::OBForceFieldMMFF94::E_Electrostatic<true>() Line | Count | Source | 779 | 1.81k | { | 780 | 1.81k | double energy = 0.0; | 781 | | | 782 | 1.81k | IF_OBFF_LOGLVL_HIGH { | 783 | 0 | OBFFLog("\nE L E C T R O S T A T I C I N T E R A C T I O N S\n\n"); | 784 | 0 | OBFFLog("ATOM TYPES\n"); | 785 | 0 | OBFFLog(" I J Rij Qi Qj ENERGY\n"); | 786 | 0 | OBFFLog("-----------------------------------------------------\n"); | 787 | | // XX XX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX | 788 | 0 | } | 789 | | | 790 | | #ifdef _OPENMP | 791 | | #pragma omp parallel for reduction(+:energy) | 792 | | #endif | 793 | 1.81k | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { | 794 | | // Cut-off check | 795 | 0 | if (_cutoff) | 796 | 0 | if (!_elepairs.BitIsSet(_electrostaticcalculations[i].pairIndex)) | 797 | 0 | continue; | 798 | | | 799 | 0 | _electrostaticcalculations[i].template Compute<gradients>(); | 800 | 0 | energy += _electrostaticcalculations[i].energy; | 801 | |
| 802 | 0 | #ifndef _OPENMP | 803 | 0 | if (gradients) { | 804 | 0 | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); | 805 | 0 | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); | 806 | 0 | } | 807 | 0 | #endif | 808 | |
| 809 | 0 | IF_OBFF_LOGLVL_HIGH { | 810 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", | 811 | 0 | atoi(_electrostaticcalculations[i].a->GetType()), atoi(_electrostaticcalculations[i].b->GetType()), | 812 | 0 | _electrostaticcalculations[i].rab, _electrostaticcalculations[i].a->GetPartialCharge(), | 813 | 0 | _electrostaticcalculations[i].b->GetPartialCharge(), _electrostaticcalculations[i].energy); | 814 | 0 | OBFFLog(_logbuf); | 815 | 0 | } | 816 | 0 | } | 817 | | | 818 | | #ifdef _OPENMP | 819 | | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { | 820 | | // Cut-off check | 821 | | if (_cutoff) | 822 | | if (!_elepairs.BitIsSet(i)) | 823 | | continue; | 824 | | | 825 | | if (gradients) { | 826 | | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); | 827 | | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); | 828 | | } | 829 | | } | 830 | | #endif | 831 | | | 832 | 1.81k | IF_OBFF_LOGLVL_MEDIUM { | 833 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ELECTROSTATIC ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 834 | 0 | OBFFLog(_logbuf); | 835 | 0 | } | 836 | | | 837 | 1.81k | return energy; | 838 | 1.81k | } |
double OpenBabel::OBForceFieldMMFF94::E_Electrostatic<false>() Line | Count | Source | 779 | 3.51k | { | 780 | 3.51k | double energy = 0.0; | 781 | | | 782 | 3.51k | IF_OBFF_LOGLVL_HIGH { | 783 | 0 | OBFFLog("\nE L E C T R O S T A T I C I N T E R A C T I O N S\n\n"); | 784 | 0 | OBFFLog("ATOM TYPES\n"); | 785 | 0 | OBFFLog(" I J Rij Qi Qj ENERGY\n"); | 786 | 0 | OBFFLog("-----------------------------------------------------\n"); | 787 | | // XX XX XXXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX | 788 | 0 | } | 789 | | | 790 | | #ifdef _OPENMP | 791 | | #pragma omp parallel for reduction(+:energy) | 792 | | #endif | 793 | 3.51k | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { | 794 | | // Cut-off check | 795 | 0 | if (_cutoff) | 796 | 0 | if (!_elepairs.BitIsSet(_electrostaticcalculations[i].pairIndex)) | 797 | 0 | continue; | 798 | | | 799 | 0 | _electrostaticcalculations[i].template Compute<gradients>(); | 800 | 0 | energy += _electrostaticcalculations[i].energy; | 801 | |
| 802 | 0 | #ifndef _OPENMP | 803 | 0 | if (gradients) { | 804 | 0 | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); | 805 | 0 | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); | 806 | 0 | } | 807 | 0 | #endif | 808 | |
| 809 | 0 | IF_OBFF_LOGLVL_HIGH { | 810 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %2d %8.3f %8.3f %8.3f %8.3f\n", | 811 | 0 | atoi(_electrostaticcalculations[i].a->GetType()), atoi(_electrostaticcalculations[i].b->GetType()), | 812 | 0 | _electrostaticcalculations[i].rab, _electrostaticcalculations[i].a->GetPartialCharge(), | 813 | 0 | _electrostaticcalculations[i].b->GetPartialCharge(), _electrostaticcalculations[i].energy); | 814 | 0 | OBFFLog(_logbuf); | 815 | 0 | } | 816 | 0 | } | 817 | | | 818 | | #ifdef _OPENMP | 819 | | for (int i = 0; i < _electrostaticcalculations.size(); ++i) { | 820 | | // Cut-off check | 821 | | if (_cutoff) | 822 | | if (!_elepairs.BitIsSet(i)) | 823 | | continue; | 824 | | | 825 | | if (gradients) { | 826 | | AddGradient(_electrostaticcalculations[i].force_a, _electrostaticcalculations[i].idx_a); | 827 | | AddGradient(_electrostaticcalculations[i].force_b, _electrostaticcalculations[i].idx_b); | 828 | | } | 829 | | } | 830 | | #endif | 831 | | | 832 | 3.51k | IF_OBFF_LOGLVL_MEDIUM { | 833 | 0 | snprintf(_logbuf, BUFF_SIZE, " TOTAL ELECTROSTATIC ENERGY = %8.5f %s\n", energy, GetUnit().c_str()); | 834 | 0 | OBFFLog(_logbuf); | 835 | 0 | } | 836 | | | 837 | 3.51k | return energy; | 838 | 3.51k | } |
|
839 | | |
840 | | // |
841 | | // OBForceFieldMMFF member functions |
842 | | // |
843 | | //*********************************************** |
844 | | //Make a global instance |
845 | | OBForceFieldMMFF94 theForceFieldMMFF94("MMFF94", false); |
846 | | OBForceFieldMMFF94 theForceFieldMMFF94s("MMFF94s", false); |
847 | | //*********************************************** |
848 | | |
849 | | OBForceFieldMMFF94::~OBForceFieldMMFF94() |
850 | 0 | { |
851 | 0 | } |
852 | | |
853 | | OBForceFieldMMFF94 &OBForceFieldMMFF94::operator=(OBForceFieldMMFF94 &src) |
854 | 0 | { |
855 | 0 | _mol = src._mol; |
856 | 0 | _init = src._init; |
857 | 0 | return *this; |
858 | 0 | } |
859 | | |
860 | | //////////////////////////////////////////////////////////////////////////////// |
861 | | //////////////////////////////////////////////////////////////////////////////// |
862 | | // |
863 | | // Parse parameter files |
864 | | // |
865 | | //////////////////////////////////////////////////////////////////////////////// |
866 | | //////////////////////////////////////////////////////////////////////////////// |
867 | | |
868 | | bool OBForceFieldMMFF94::ParseParamFile() |
869 | 1 | { |
870 | | // Set the locale for number parsing to avoid locale issues: PR#1785463 |
871 | 1 | obLocale.SetLocale(); |
872 | | |
873 | 1 | vector<string> vs; |
874 | 1 | char buffer[80]; |
875 | | |
876 | | // open data/_parFile |
877 | 1 | ifstream ifs; |
878 | 1 | if (OpenDatafile(ifs, _parFile).length() == 0) { |
879 | 1 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open parameter file", obError); |
880 | 1 | return false; |
881 | 1 | } |
882 | | |
883 | 0 | while (ifs.getline(buffer, 80)) { |
884 | 0 | if (EQn(buffer, "#", 1)) continue; |
885 | | |
886 | 0 | tokenize(vs, buffer); |
887 | 0 | if (vs.size() < 2) |
888 | 0 | continue; |
889 | | |
890 | 0 | if (vs[0] == "prop") |
891 | 0 | ParseParamProp(vs[1]); |
892 | 0 | if (vs[0] == "def") |
893 | 0 | ParseParamDef(vs[1]); |
894 | 0 | if (vs[0] == "bond") |
895 | 0 | ParseParamBond(vs[1]); |
896 | 0 | if (vs[0] == "ang") |
897 | 0 | ParseParamAngle(vs[1]); |
898 | 0 | if (vs[0] == "bndk") |
899 | 0 | ParseParamBndk(vs[1]); |
900 | 0 | if (vs[0] == "chg") |
901 | 0 | ParseParamCharge(vs[1]); |
902 | 0 | if (vs[0] == "dfsb") |
903 | 0 | ParseParamDfsb(vs[1]); |
904 | 0 | if (vs[0] == "oop") |
905 | 0 | ParseParamOOP(vs[1]); |
906 | 0 | if (vs[0] == "pbci") |
907 | 0 | ParseParamPbci(vs[1]); |
908 | 0 | if (vs[0] == "stbn") |
909 | 0 | ParseParamStrBnd(vs[1]); |
910 | 0 | if (vs[0] == "tor") |
911 | 0 | ParseParamTorsion(vs[1]); |
912 | 0 | if (vs[0] == "vdw") |
913 | 0 | ParseParamVDW(vs[1]); |
914 | 0 | } |
915 | |
|
916 | 0 | if (ifs) |
917 | 0 | ifs.close(); |
918 | | |
919 | | // return the locale to the original one |
920 | 0 | obLocale.RestoreLocale(); |
921 | 0 | return true; |
922 | 1 | } |
923 | | |
924 | | bool OBForceFieldMMFF94::ParseParamBond(std::string &filename) |
925 | 0 | { |
926 | 0 | vector<string> vs; |
927 | 0 | char buffer[80]; |
928 | |
|
929 | 0 | OBFFParameter parameter; |
930 | | |
931 | | // open data/mmffbond.par |
932 | 0 | ifstream ifs; |
933 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
934 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffbond.par", obError); |
935 | 0 | return false; |
936 | 0 | } |
937 | | |
938 | 0 | while (ifs.getline(buffer, 80)) { |
939 | 0 | if (EQn(buffer, "*", 1)) continue; |
940 | 0 | if (EQn(buffer, "$", 1)) continue; |
941 | | |
942 | 0 | tokenize(vs, buffer); |
943 | |
|
944 | 0 | parameter.clear(); |
945 | 0 | parameter._ipar.push_back(atoi(vs[0].c_str())); // FF class |
946 | 0 | parameter.a = atoi(vs[1].c_str()); |
947 | 0 | parameter.b = atoi(vs[2].c_str()); |
948 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // kb |
949 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // r0 |
950 | 0 | _ffbondparams.push_back(parameter); |
951 | 0 | } |
952 | |
|
953 | 0 | if (ifs) |
954 | 0 | ifs.close(); |
955 | |
|
956 | 0 | return 0; |
957 | 0 | } |
958 | | |
959 | | bool OBForceFieldMMFF94::ParseParamBndk(std::string &filename) |
960 | 0 | { |
961 | 0 | vector<string> vs; |
962 | 0 | char buffer[80]; |
963 | |
|
964 | 0 | OBFFParameter parameter; |
965 | | |
966 | | // open data/mmffbndk.par |
967 | 0 | ifstream ifs; |
968 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
969 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffbndk.par", obError); |
970 | 0 | return false; |
971 | 0 | } |
972 | | |
973 | 0 | while (ifs.getline(buffer, 80)) { |
974 | 0 | if (EQn(buffer, "*", 1)) continue; |
975 | 0 | if (EQn(buffer, "$", 1)) continue; |
976 | | |
977 | 0 | tokenize(vs, buffer); |
978 | |
|
979 | 0 | parameter.clear(); |
980 | 0 | parameter.a = atoi(vs[0].c_str()); |
981 | 0 | parameter.b = atoi(vs[1].c_str()); |
982 | 0 | parameter._dpar.push_back(atof(vs[2].c_str())); // r0-ref |
983 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // kb-ref |
984 | 0 | _ffbndkparams.push_back(parameter); |
985 | 0 | } |
986 | |
|
987 | 0 | if (ifs) |
988 | 0 | ifs.close(); |
989 | |
|
990 | 0 | return 0; |
991 | 0 | } |
992 | | |
993 | | bool OBForceFieldMMFF94::ParseParamAngle(std::string &filename) |
994 | 0 | { |
995 | 0 | vector<string> vs; |
996 | 0 | char buffer[80]; |
997 | |
|
998 | 0 | OBFFParameter parameter; |
999 | | |
1000 | | // open data/mmffang.par |
1001 | 0 | ifstream ifs; |
1002 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1003 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffang.par", obError); |
1004 | 0 | return false; |
1005 | 0 | } |
1006 | | |
1007 | 0 | while (ifs.getline(buffer, 80)) { |
1008 | 0 | if (EQn(buffer, "*", 1)) continue; |
1009 | 0 | if (EQn(buffer, "$", 1)) continue; |
1010 | | |
1011 | 0 | tokenize(vs, buffer); |
1012 | |
|
1013 | 0 | parameter.clear(); |
1014 | 0 | parameter._ipar.push_back(atoi(vs[0].c_str())); // FF class |
1015 | 0 | parameter.a = atoi(vs[1].c_str()); |
1016 | 0 | parameter.b = atoi(vs[2].c_str()); |
1017 | 0 | parameter.c = atoi(vs[3].c_str()); |
1018 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // ka |
1019 | 0 | parameter._dpar.push_back(atof(vs[5].c_str())); // theta0 |
1020 | 0 | _ffangleparams.push_back(parameter); |
1021 | 0 | } |
1022 | |
|
1023 | 0 | if (ifs) |
1024 | 0 | ifs.close(); |
1025 | |
|
1026 | 0 | return 0; |
1027 | 0 | } |
1028 | | |
1029 | | bool OBForceFieldMMFF94::ParseParamStrBnd(std::string &filename) |
1030 | 0 | { |
1031 | 0 | vector<string> vs; |
1032 | 0 | char buffer[80]; |
1033 | |
|
1034 | 0 | OBFFParameter parameter; |
1035 | | |
1036 | | // open data/mmffstbn.par |
1037 | 0 | ifstream ifs; |
1038 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1039 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffstbn.par", obError); |
1040 | 0 | return false; |
1041 | 0 | } |
1042 | | |
1043 | 0 | while (ifs.getline(buffer, 80)) { |
1044 | 0 | if (EQn(buffer, "*", 1)) continue; |
1045 | 0 | if (EQn(buffer, "$", 1)) continue; |
1046 | | |
1047 | 0 | tokenize(vs, buffer); |
1048 | |
|
1049 | 0 | parameter.clear(); |
1050 | 0 | parameter._ipar.push_back(atoi(vs[0].c_str())); // FF class |
1051 | 0 | parameter.a = atoi(vs[1].c_str()); |
1052 | 0 | parameter.b = atoi(vs[2].c_str()); |
1053 | 0 | parameter.c = atoi(vs[3].c_str()); |
1054 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // kbaIJK |
1055 | 0 | parameter._dpar.push_back(atof(vs[5].c_str())); // kbaKJI |
1056 | 0 | _ffstrbndparams.push_back(parameter); |
1057 | 0 | } |
1058 | |
|
1059 | 0 | if (ifs) |
1060 | 0 | ifs.close(); |
1061 | |
|
1062 | 0 | return 0; |
1063 | 0 | } |
1064 | | |
1065 | | bool OBForceFieldMMFF94::ParseParamDfsb(std::string &filename) |
1066 | 0 | { |
1067 | 0 | vector<string> vs; |
1068 | 0 | char buffer[80]; |
1069 | |
|
1070 | 0 | OBFFParameter parameter; |
1071 | | |
1072 | | // open data/mmffdfsb.par |
1073 | 0 | ifstream ifs; |
1074 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1075 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffdfsb.par", obError); |
1076 | 0 | return false; |
1077 | 0 | } |
1078 | | |
1079 | 0 | while (ifs.getline(buffer, 80)) { |
1080 | 0 | if (EQn(buffer, "*", 1)) continue; |
1081 | 0 | if (EQn(buffer, "$", 1)) continue; |
1082 | | |
1083 | 0 | tokenize(vs, buffer); |
1084 | |
|
1085 | 0 | parameter.clear(); |
1086 | 0 | parameter.a = atoi(vs[0].c_str()); |
1087 | 0 | parameter.b = atoi(vs[1].c_str()); |
1088 | 0 | parameter.c = atoi(vs[2].c_str()); |
1089 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // kbaIJK |
1090 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // kbaKJI |
1091 | 0 | _ffdfsbparams.push_back(parameter); |
1092 | 0 | } |
1093 | |
|
1094 | 0 | if (ifs) |
1095 | 0 | ifs.close(); |
1096 | |
|
1097 | 0 | return 0; |
1098 | 0 | } |
1099 | | |
1100 | | bool OBForceFieldMMFF94::ParseParamOOP(std::string &filename) |
1101 | 0 | { |
1102 | 0 | vector<string> vs; |
1103 | 0 | char buffer[80]; |
1104 | |
|
1105 | 0 | OBFFParameter parameter; |
1106 | | |
1107 | | // open data/mmffoop.par |
1108 | 0 | ifstream ifs; |
1109 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1110 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffoop.par", obError); |
1111 | 0 | return false; |
1112 | 0 | } |
1113 | | |
1114 | 0 | while (ifs.getline(buffer, 80)) { |
1115 | 0 | if (EQn(buffer, "*", 1)) continue; |
1116 | 0 | if (EQn(buffer, "$", 1)) continue; |
1117 | | |
1118 | 0 | tokenize(vs, buffer); |
1119 | |
|
1120 | 0 | parameter.clear(); |
1121 | 0 | parameter.a = atoi(vs[0].c_str()); |
1122 | 0 | parameter.b = atoi(vs[1].c_str()); |
1123 | 0 | parameter.c = atoi(vs[2].c_str()); |
1124 | 0 | parameter.d = atoi(vs[3].c_str()); |
1125 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // koop |
1126 | 0 | _ffoopparams.push_back(parameter); |
1127 | 0 | } |
1128 | |
|
1129 | 0 | if (ifs) |
1130 | 0 | ifs.close(); |
1131 | |
|
1132 | 0 | return 0; |
1133 | 0 | } |
1134 | | |
1135 | | bool OBForceFieldMMFF94::ParseParamTorsion(std::string &filename) |
1136 | 0 | { |
1137 | 0 | vector<string> vs; |
1138 | 0 | char buffer[80]; |
1139 | |
|
1140 | 0 | OBFFParameter parameter; |
1141 | | |
1142 | | // open data/mmfftor.par |
1143 | 0 | ifstream ifs; |
1144 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1145 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmfftor.par", obError); |
1146 | 0 | return false; |
1147 | 0 | } |
1148 | | |
1149 | 0 | while (ifs.getline(buffer, 80)) { |
1150 | 0 | if (EQn(buffer, "*", 1)) continue; |
1151 | 0 | if (EQn(buffer, "$", 1)) continue; |
1152 | | |
1153 | 0 | tokenize(vs, buffer); |
1154 | |
|
1155 | 0 | parameter.clear(); |
1156 | 0 | parameter._ipar.push_back(atoi(vs[0].c_str())); // FF class |
1157 | 0 | parameter.a = atoi(vs[1].c_str()); |
1158 | 0 | parameter.b = atoi(vs[2].c_str()); |
1159 | 0 | parameter.c = atoi(vs[3].c_str()); |
1160 | 0 | parameter.d = atoi(vs[4].c_str()); |
1161 | 0 | parameter._dpar.push_back(atof(vs[5].c_str())); // v1 |
1162 | 0 | parameter._dpar.push_back(atof(vs[6].c_str())); // v2 |
1163 | 0 | parameter._dpar.push_back(atof(vs[7].c_str())); // v3 |
1164 | 0 | _fftorsionparams.push_back(parameter); |
1165 | 0 | } |
1166 | |
|
1167 | 0 | if (ifs) |
1168 | 0 | ifs.close(); |
1169 | |
|
1170 | 0 | return 0; |
1171 | 0 | } |
1172 | | |
1173 | | bool OBForceFieldMMFF94::ParseParamVDW(std::string &filename) |
1174 | 0 | { |
1175 | 0 | vector<string> vs; |
1176 | 0 | char buffer[80]; |
1177 | |
|
1178 | 0 | OBFFParameter parameter; |
1179 | | |
1180 | | // open data/mmffvdw.par |
1181 | 0 | ifstream ifs; |
1182 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1183 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffvdw.par", obError); |
1184 | 0 | return false; |
1185 | 0 | } |
1186 | | |
1187 | 0 | while (ifs.getline(buffer, 80)) { |
1188 | 0 | if (EQn(buffer, "*", 1)) continue; |
1189 | 0 | if (EQn(buffer, "$", 1)) continue; |
1190 | | |
1191 | 0 | tokenize(vs, buffer); |
1192 | |
|
1193 | 0 | parameter.clear(); |
1194 | 0 | parameter.a = atoi(vs[0].c_str()); |
1195 | 0 | parameter._dpar.push_back(atof(vs[1].c_str())); // alpha-i |
1196 | 0 | parameter._dpar.push_back(atof(vs[2].c_str())); // N-i |
1197 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // A-i |
1198 | 0 | parameter._dpar.push_back(atof(vs[4].c_str())); // G-i |
1199 | 0 | if (EQn(vs[5].c_str(), "-", 1)) |
1200 | 0 | parameter._ipar.push_back(0); |
1201 | 0 | else if (EQn(vs[5].c_str(), "D", 1)) |
1202 | 0 | parameter._ipar.push_back(1); // hydrogen bond donor |
1203 | 0 | else if (EQn(vs[5].c_str(), "A", 1)) |
1204 | 0 | parameter._ipar.push_back(2); // hydrogen bond acceptor |
1205 | 0 | _ffvdwparams.push_back(parameter); |
1206 | 0 | } |
1207 | |
|
1208 | 0 | if (ifs) |
1209 | 0 | ifs.close(); |
1210 | |
|
1211 | 0 | return 0; |
1212 | 0 | } |
1213 | | |
1214 | | bool OBForceFieldMMFF94::ParseParamCharge(std::string &filename) |
1215 | 0 | { |
1216 | 0 | vector<string> vs; |
1217 | 0 | char buffer[80]; |
1218 | |
|
1219 | 0 | OBFFParameter parameter; |
1220 | | |
1221 | | // open data/mmffchg.par |
1222 | 0 | ifstream ifs; |
1223 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1224 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffchg.par", obError); |
1225 | 0 | return false; |
1226 | 0 | } |
1227 | | |
1228 | 0 | while (ifs.getline(buffer, 80)) { |
1229 | 0 | if (EQn(buffer, "*", 1)) continue; |
1230 | 0 | if (EQn(buffer, "$", 1)) continue; |
1231 | | |
1232 | 0 | tokenize(vs, buffer); |
1233 | |
|
1234 | 0 | parameter.clear(); |
1235 | 0 | parameter._ipar.push_back(atoi(vs[0].c_str())); // FF class |
1236 | 0 | parameter.a = atoi(vs[1].c_str()); |
1237 | 0 | parameter.b = atoi(vs[2].c_str()); |
1238 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // bci |
1239 | 0 | _ffchgparams.push_back(parameter); |
1240 | 0 | } |
1241 | |
|
1242 | 0 | if (ifs) |
1243 | 0 | ifs.close(); |
1244 | |
|
1245 | 0 | return 0; |
1246 | 0 | } |
1247 | | |
1248 | | bool OBForceFieldMMFF94::ParseParamPbci(std::string &filename) |
1249 | 0 | { |
1250 | 0 | vector<string> vs; |
1251 | 0 | char buffer[80]; |
1252 | |
|
1253 | 0 | OBFFParameter parameter; |
1254 | | |
1255 | | // open data/mmffpbci.par |
1256 | 0 | ifstream ifs; |
1257 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1258 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffpbci", obError); |
1259 | 0 | return false; |
1260 | 0 | } |
1261 | | |
1262 | 0 | while (ifs.getline(buffer, 80)) { |
1263 | 0 | if (EQn(buffer, "*", 1)) continue; |
1264 | 0 | if (EQn(buffer, "$", 1)) continue; |
1265 | | |
1266 | 0 | tokenize(vs, buffer); |
1267 | |
|
1268 | 0 | parameter.clear(); |
1269 | 0 | parameter.a = atoi(vs[1].c_str()); |
1270 | 0 | parameter._dpar.push_back(atof(vs[2].c_str())); // pbci |
1271 | 0 | parameter._dpar.push_back(atof(vs[3].c_str())); // fcadj |
1272 | 0 | _ffpbciparams.push_back(parameter); |
1273 | 0 | } |
1274 | |
|
1275 | 0 | if (ifs) |
1276 | 0 | ifs.close(); |
1277 | |
|
1278 | 0 | return 0; |
1279 | 0 | } |
1280 | | |
1281 | | bool OBForceFieldMMFF94::ParseParamProp(std::string &filename) |
1282 | 0 | { |
1283 | 0 | vector<string> vs; |
1284 | 0 | char buffer[80]; |
1285 | |
|
1286 | 0 | OBFFParameter parameter; |
1287 | | |
1288 | | // open data/mmffprop.par |
1289 | 0 | ifstream ifs; |
1290 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1291 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffprop.par", obError); |
1292 | 0 | return false; |
1293 | 0 | } |
1294 | | |
1295 | 0 | while (ifs.getline(buffer, 80)) { |
1296 | 0 | if (EQn(buffer, "*", 1)) continue; |
1297 | 0 | if (EQn(buffer, "$", 1)) continue; |
1298 | | |
1299 | 0 | tokenize(vs, buffer); |
1300 | |
|
1301 | 0 | parameter.clear(); |
1302 | 0 | parameter.a = atoi(vs[0].c_str()); // atom type |
1303 | 0 | parameter._ipar.push_back(atoi(vs[1].c_str())); // at.no |
1304 | 0 | parameter._ipar.push_back(atoi(vs[2].c_str())); // crd |
1305 | 0 | parameter._ipar.push_back(atoi(vs[3].c_str())); // val |
1306 | 0 | parameter._ipar.push_back(atoi(vs[4].c_str())); // pilp |
1307 | 0 | parameter._ipar.push_back(atoi(vs[5].c_str())); // mltb |
1308 | 0 | parameter._ipar.push_back(atoi(vs[6].c_str())); // arom |
1309 | 0 | parameter._ipar.push_back(atoi(vs[7].c_str())); // linh |
1310 | 0 | parameter._ipar.push_back(atoi(vs[8].c_str())); // sbmb |
1311 | |
|
1312 | 0 | if (parameter._ipar[3]) |
1313 | 0 | _ffpropPilp.SetBitOn(parameter.a); |
1314 | 0 | if (parameter._ipar[5]) |
1315 | 0 | _ffpropArom.SetBitOn(parameter.a); |
1316 | 0 | if (parameter._ipar[6]) |
1317 | 0 | _ffpropLin.SetBitOn(parameter.a); |
1318 | 0 | if (parameter._ipar[7]) |
1319 | 0 | _ffpropSbmb.SetBitOn(parameter.a); |
1320 | |
|
1321 | 0 | _ffpropparams.push_back(parameter); |
1322 | 0 | } |
1323 | |
|
1324 | 0 | if (ifs) |
1325 | 0 | ifs.close(); |
1326 | |
|
1327 | 0 | return 0; |
1328 | 0 | } |
1329 | | |
1330 | | bool OBForceFieldMMFF94::ParseParamDef(std::string &filename) |
1331 | 0 | { |
1332 | 0 | vector<string> vs; |
1333 | 0 | char buffer[80]; |
1334 | |
|
1335 | 0 | OBFFParameter parameter; |
1336 | | |
1337 | | // open data/mmffdef.par |
1338 | 0 | ifstream ifs; |
1339 | 0 | if (OpenDatafile(ifs, filename).length() == 0) { |
1340 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Cannot open mmffdef.par", obError); |
1341 | 0 | return false; |
1342 | 0 | } |
1343 | | |
1344 | 0 | while (ifs.getline(buffer, 80)) { |
1345 | 0 | if (EQn(buffer, "*", 1)) continue; |
1346 | 0 | if (EQn(buffer, "$", 1)) continue; |
1347 | | |
1348 | 0 | tokenize(vs, buffer); |
1349 | |
|
1350 | 0 | parameter.clear(); |
1351 | 0 | parameter._ipar.push_back(atoi(vs[1].c_str())); // level 1 |
1352 | 0 | parameter._ipar.push_back(atoi(vs[2].c_str())); // level 2 |
1353 | 0 | parameter._ipar.push_back(atoi(vs[3].c_str())); // level 3 |
1354 | 0 | parameter._ipar.push_back(atoi(vs[4].c_str())); // level 4 |
1355 | 0 | parameter._ipar.push_back(atoi(vs[5].c_str())); // level 5 |
1356 | 0 | _ffdefparams.push_back(parameter); |
1357 | 0 | } |
1358 | |
|
1359 | 0 | if (ifs) |
1360 | 0 | ifs.close(); |
1361 | |
|
1362 | 0 | return 0; |
1363 | 0 | } |
1364 | | |
1365 | | //////////////////////////////////////////////////////////////////////////////// |
1366 | | //////////////////////////////////////////////////////////////////////////////// |
1367 | | // |
1368 | | // Setup Functions |
1369 | | // |
1370 | | //////////////////////////////////////////////////////////////////////////////// |
1371 | | //////////////////////////////////////////////////////////////////////////////// |
1372 | | |
1373 | | // The MMFF94 article doesn't seem to include information about how |
1374 | | // aromaticity is perceived. This function was written by studying the |
1375 | | // MMFF_opti.log file, trail-and-error and using the MMFF94 validation |
1376 | | // set to check the results (If all atom types are assigned correctly, |
1377 | | // aromatic rings are probably detected correctly) |
1378 | | bool OBForceFieldMMFF94::PerceiveAromatic() |
1379 | 2.47k | { |
1380 | 2.47k | bool done = false; // not done actually.... |
1381 | 2.47k | OBAtom *ringatom; |
1382 | 2.47k | OBBond *ringbond; |
1383 | 2.47k | vector<OBRing*> vr; |
1384 | 2.47k | vr = _mol.GetSSSR(); |
1385 | | |
1386 | 2.47k | vector<OBRing*>::iterator ri; |
1387 | 2.47k | vector<int>::iterator rj; |
1388 | 2.47k | int n, index, ringsize, first_rj, prev_rj, pi_electrons, c60; |
1389 | 18.7k | for (ri = vr.begin();ri != vr.end();++ri) { // for each ring |
1390 | 16.2k | ringsize = (*ri)->Size(); |
1391 | | |
1392 | 16.2k | n = 1; |
1393 | 16.2k | pi_electrons = 0; |
1394 | 16.2k | c60 = 0; // we have a special case to get c60 right (all atom type 37) |
1395 | 80.4k | for(rj = (*ri)->_path.begin();rj != (*ri)->_path.end();++rj) { // for each ring atom |
1396 | 64.2k | index = *rj; |
1397 | 64.2k | ringatom = _mol.GetAtom(index); |
1398 | | |
1399 | | // is the bond to the previous ring atom double? |
1400 | 64.2k | if (n > 1) { |
1401 | 47.9k | ringbond = _mol.GetBond(prev_rj, index); |
1402 | 47.9k | if (!ringbond) { |
1403 | 0 | prev_rj = index; |
1404 | 0 | continue; |
1405 | 0 | } |
1406 | 47.9k | if (ringbond->GetBondOrder() == 2) { |
1407 | 4.91k | pi_electrons += 2; |
1408 | 4.91k | prev_rj = index; |
1409 | 4.91k | n++; |
1410 | 4.91k | continue; |
1411 | 4.91k | } |
1412 | 43.0k | prev_rj = index; |
1413 | 43.0k | } else { |
1414 | 16.2k | prev_rj = index; |
1415 | 16.2k | first_rj = index; |
1416 | 16.2k | } |
1417 | | |
1418 | | // does the current ring atom have a exocyclic double bond? |
1419 | 244k | FOR_NBORS_OF_ATOM (nbr, ringatom) { |
1420 | 244k | if ((*ri)->IsInRing(nbr->GetIdx())) |
1421 | 118k | continue; |
1422 | | |
1423 | 125k | if (!nbr->IsAromatic()) { |
1424 | 125k | if (ringatom->GetAtomicNum() == OBElements::Carbon && ringatom->IsInRingSize(5) |
1425 | 302 | && ringatom->IsInRingSize(6) && nbr->GetAtomicNum() == OBElements::Carbon && nbr->IsInRingSize(5) |
1426 | 3 | && nbr->IsInRingSize(6)) { |
1427 | 2 | c60++; |
1428 | 125k | } else { |
1429 | 125k | continue; |
1430 | 125k | } |
1431 | 125k | } |
1432 | | |
1433 | 540 | ringbond = _mol.GetBond(nbr->GetIdx(), index); |
1434 | 540 | if (!ringbond) { |
1435 | 0 | continue; |
1436 | 0 | } |
1437 | 540 | if (ringbond->GetBondOrder() == 2) |
1438 | 224 | pi_electrons++; |
1439 | 540 | } |
1440 | | |
1441 | | // is the atom N, O or S in 5 rings |
1442 | 59.3k | if (ringsize == 5 && |
1443 | 2.52k | ringatom->GetIdx() == (*ri)->GetRootAtom()) |
1444 | 439 | pi_electrons += 2; |
1445 | | |
1446 | 59.3k | n++; |
1447 | | |
1448 | 59.3k | } // for each ring atom |
1449 | | |
1450 | | // is the bond from the first to the last atom double? |
1451 | 16.2k | ringbond = _mol.GetBond(first_rj, index); |
1452 | 16.2k | if (ringbond) { |
1453 | 16.2k | if (ringbond->GetBondOrder() == 2) |
1454 | 1.28k | pi_electrons += 2; |
1455 | 16.2k | } |
1456 | | |
1457 | 16.2k | if (((pi_electrons == 6) && ((ringsize == 5) || (ringsize == 6))) |
1458 | 15.8k | || ((pi_electrons == 5) && (c60 == 5))) { |
1459 | | // mark ring atoms as aromatic |
1460 | 2.33k | for(rj = (*ri)->_path.begin();rj != (*ri)->_path.end();++rj) { |
1461 | 1.95k | if (!_mol.GetAtom(*rj)->IsAromatic()) |
1462 | 999 | done = true; |
1463 | 1.95k | _mol.GetAtom(*rj)->SetAromatic(); |
1464 | 1.95k | } |
1465 | | // mark all ring bonds as aromatic |
1466 | 378 | FOR_BONDS_OF_MOL (bond, _mol) |
1467 | 27.4k | if((*ri)->IsMember(&*bond)) |
1468 | 1.95k | bond->SetAromatic(); |
1469 | 378 | } |
1470 | 16.2k | } |
1471 | | |
1472 | 2.47k | return done; |
1473 | 2.47k | } |
1474 | | |
1475 | | // Symbolic atom typing is skipped |
1476 | | // |
1477 | | // atom typing is based on: |
1478 | | // MMFF94 I - Table III |
1479 | | // MMFF94 V - Table I |
1480 | | // |
1481 | | int OBForceFieldMMFF94::GetType(OBAtom *atom) |
1482 | 230k | { |
1483 | 230k | OBBond *bond; |
1484 | 230k | int oxygenCount, nitrogenCount, sulphurCount, doubleBondTo; |
1485 | | //////////////////////////////// |
1486 | | // Aromatic Atoms |
1487 | | //////////////////////////////// |
1488 | 230k | if (atom->IsAromatic()) { |
1489 | 1.03k | if (atom->IsInRingSize(5)) { |
1490 | 830 | bool IsAromatic = false; |
1491 | 830 | vector<OBAtom*> alphaPos, betaPos; |
1492 | 830 | vector<OBAtom*> alphaAtoms, betaAtoms; |
1493 | | |
1494 | 830 | if (atom->GetAtomicNum() == OBElements::Sulfur) { |
1495 | 61 | return 44; // Aromatic 5-ring sulfur with pi lone pair (STHI) |
1496 | 61 | } |
1497 | 769 | if (atom->GetAtomicNum() == OBElements::Oxygen) { |
1498 | 59 | return 59; // Aromatic 5-ring oxygen with pi lone pair (OFUR) |
1499 | 59 | } |
1500 | 710 | if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1501 | 962 | FOR_NBORS_OF_ATOM (nbr, atom) { |
1502 | 962 | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1503 | 6 | return 82; // N-oxide nitrogen in 5-ring alpha position, |
1504 | | // N-oxide nitrogen in 5-ring beta position, |
1505 | | // N-oxide nitrogen in other 5-ring position, |
1506 | | // (N5AX, N5BX, N5OX) |
1507 | 6 | } |
1508 | 962 | } |
1509 | 368 | } |
1510 | 1.85k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1511 | 1.85k | if (!((_mol.GetBond(atom, &*nbr))->IsAromatic()) || !nbr->IsInRingSize(5)) |
1512 | 429 | continue; |
1513 | | |
1514 | 1.43k | if (IsInSameRing(atom, &*nbr)) { |
1515 | 1.43k | alphaPos.push_back(&*nbr); |
1516 | 1.43k | } |
1517 | | |
1518 | 3.81k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
1519 | 3.81k | if (nbrNbr->GetIdx() == atom->GetIdx()) |
1520 | 1.43k | continue; |
1521 | 2.38k | if (!((_mol.GetBond(&*nbr, &*nbrNbr))->IsAromatic()) || !nbrNbr->IsInRingSize(5)) |
1522 | 868 | continue; |
1523 | | |
1524 | 1.51k | IsAromatic = true; |
1525 | | |
1526 | 1.51k | if (IsInSameRing(atom, &*nbrNbr)) { |
1527 | 1.43k | betaPos.push_back(&*nbrNbr); |
1528 | 1.43k | } |
1529 | 1.51k | } |
1530 | 1.43k | } |
1531 | | |
1532 | 704 | if (IsAromatic) { |
1533 | | |
1534 | | |
1535 | 2.13k | for (unsigned int i = 0; i < alphaPos.size(); i++) { |
1536 | 1.43k | if (alphaPos[i]->GetAtomicNum() == OBElements::Sulfur) { |
1537 | 87 | alphaAtoms.push_back(alphaPos[i]); |
1538 | 1.34k | } else if (alphaPos[i]->GetAtomicNum() == OBElements::Oxygen) { |
1539 | 77 | alphaAtoms.push_back(alphaPos[i]); |
1540 | 1.26k | } else if (alphaPos[i]->GetAtomicNum() == OBElements::Nitrogen && (alphaPos[i]->GetExplicitDegree() == 3)) { |
1541 | 240 | bool IsNOxide = false; |
1542 | 720 | FOR_NBORS_OF_ATOM (nbr, alphaPos[i]) { |
1543 | 720 | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1544 | 12 | IsNOxide = true; |
1545 | 12 | } |
1546 | 720 | } |
1547 | | |
1548 | 240 | if (!IsNOxide) { |
1549 | 228 | alphaAtoms.push_back(alphaPos[i]); |
1550 | 228 | } |
1551 | 240 | } |
1552 | 1.43k | } |
1553 | 2.13k | for (unsigned int i = 0; i < betaPos.size(); i++) { |
1554 | 1.43k | if (betaPos[i]->GetAtomicNum() == OBElements::Sulfur) { |
1555 | 82 | betaAtoms.push_back(betaPos[i]); |
1556 | 1.35k | } else if (betaPos[i]->GetAtomicNum() == OBElements::Oxygen) { |
1557 | 117 | betaAtoms.push_back(betaPos[i]); |
1558 | 1.23k | } else if (betaPos[i]->GetAtomicNum() == OBElements::Nitrogen && (betaPos[i]->GetExplicitDegree() == 3)) { |
1559 | 239 | bool IsNOxide = false; |
1560 | 717 | FOR_NBORS_OF_ATOM (nbr, betaPos[i]) { |
1561 | 717 | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1562 | 12 | IsNOxide = true; |
1563 | 12 | } |
1564 | 717 | } |
1565 | | |
1566 | 239 | if (!IsNOxide) { |
1567 | 227 | betaAtoms.push_back(betaPos[i]); |
1568 | 227 | } |
1569 | 239 | } |
1570 | 1.43k | } |
1571 | 703 | if (!betaAtoms.size()) { |
1572 | 376 | nitrogenCount = 0; |
1573 | 1.01k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1574 | 1.01k | if (nbr->GetAtomicNum() == OBElements::Nitrogen && (nbr->GetExplicitDegree() == 3)) { |
1575 | 122 | if ((nbr->GetExplicitValence() == 4) && nbr->IsAromatic()) { |
1576 | 17 | nitrogenCount++; |
1577 | 105 | } else if ((nbr->GetExplicitValence() == 3) && !nbr->IsAromatic()) { |
1578 | 11 | nitrogenCount++; |
1579 | 11 | } |
1580 | 122 | } |
1581 | 1.01k | } |
1582 | 376 | if (nitrogenCount >= 2) { |
1583 | 2 | return 80; // Aromatic carbon between N's in imidazolium (CIM+) |
1584 | 2 | } |
1585 | 376 | } |
1586 | 701 | if (!alphaAtoms.size() && !betaAtoms.size()) { |
1587 | 244 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1588 | 74 | bool c60 = true; // special case to ensure c60 is typed correctly -- Paolo Tosco |
1589 | 213 | FOR_NBORS_OF_ATOM (nbr, atom) { |
1590 | 213 | if (!(nbr->GetAtomicNum() == OBElements::Carbon && nbr->IsAromatic() && nbr->IsInRingSize(6))) |
1591 | 207 | c60 = false; |
1592 | 213 | } |
1593 | 74 | if (c60) |
1594 | 0 | return 37; // correct atom type for c in c60 (all atoms symmetric) |
1595 | | // there is no S:, O:, or N: |
1596 | | // this is the case for anions with only carbon and nitrogen in the ring |
1597 | 74 | return 78; // General carbon in 5-membered aromatic ring (C5) |
1598 | 170 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1599 | 123 | if (atom->GetExplicitDegree() == 3) { |
1600 | | // this is the N: atom |
1601 | 52 | return 39; // Aromatic 5 ring nitrogen with pi lone pair (NPYL) |
1602 | 71 | } else { |
1603 | | // again, no S:, O:, or N: |
1604 | 71 | return 76; // Nitrogen in 5-ring aromatic anion (N5M) |
1605 | 71 | } |
1606 | 123 | } |
1607 | 244 | } |
1608 | 504 | if (alphaAtoms.size() == 2) { |
1609 | 72 | if (atom->GetAtomicNum() == OBElements::Carbon && IsInSameRing(alphaAtoms[0], alphaAtoms[1])) { |
1610 | 28 | if (alphaAtoms[0]->GetAtomicNum() == OBElements::Nitrogen && alphaAtoms[1]->GetAtomicNum() == OBElements::Nitrogen) { |
1611 | 10 | if ((alphaAtoms[0]->GetExplicitDegree() == 3) && (alphaAtoms[1]->GetExplicitDegree() == 3)) { |
1612 | 10 | return 80; // Aromatic carbon between N's in imidazolium (CIM+) |
1613 | 10 | } |
1614 | 10 | } |
1615 | 28 | } |
1616 | 72 | } |
1617 | 494 | if (alphaAtoms.size() && !betaAtoms.size()) { |
1618 | 130 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1619 | 22 | return 63; // Aromatic 5-ring C, alpha to N:, O:, or S: (C5A) |
1620 | 108 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1621 | 67 | if (atom->GetExplicitDegree() == 3) { |
1622 | 31 | return 81; // Posivite nitrogen in 5-ring alpha position (N5A+) |
1623 | 36 | } else { |
1624 | 36 | return 65; // Aromatic 5-ring N, alpha to N:, O:, or S: (N5A) |
1625 | 36 | } |
1626 | 67 | } |
1627 | 130 | } |
1628 | 405 | if (!alphaAtoms.size() && betaAtoms.size()) { |
1629 | 139 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1630 | 44 | return 64; // Aromatic 5-ring C, beta to N:, O:, or S: (C5B) |
1631 | 95 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1632 | 54 | if (atom->GetExplicitDegree() == 3) { |
1633 | 15 | return 81; // Posivite nitrogen in 5-ring beta position (N5B+) |
1634 | 39 | } else { |
1635 | 39 | return 66; // Aromatic 5-ring N, beta to N:, O:, or S: (N5B) |
1636 | 39 | } |
1637 | 54 | } |
1638 | 139 | } |
1639 | 307 | if (alphaAtoms.size() && betaAtoms.size()) { |
1640 | 404 | for (unsigned int i = 0; i < alphaAtoms.size(); i++) { |
1641 | 529 | for (unsigned int j = 0; j < betaAtoms.size(); j++) { |
1642 | 303 | if (!IsInSameRing(alphaAtoms[i], betaAtoms[j])) { |
1643 | 6 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1644 | 1 | return 78; // General carbon in 5-membered aromatic ring (C5) |
1645 | 5 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1646 | 1 | return 79; // General nitrogen in 5-membered aromatic ring (N5) |
1647 | 1 | } |
1648 | 6 | } |
1649 | 303 | } |
1650 | 228 | } |
1651 | 293 | for (unsigned int i = 0; i < alphaAtoms.size(); i++) { |
1652 | 207 | if (alphaAtoms[i]->GetAtomicNum() == OBElements::Sulfur || alphaAtoms[i]->GetAtomicNum() == OBElements::Oxygen) { |
1653 | 110 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1654 | 26 | return 63; // Aromatic 5-ring C, alpha to N:, O:, or S: (C5A) |
1655 | 84 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1656 | 64 | return 65; // Aromatic 5-ring N, alpha to N:, O:, or S: (N5A) |
1657 | 64 | } |
1658 | 110 | } |
1659 | 207 | } |
1660 | 157 | for (unsigned int i = 0; i < betaAtoms.size(); i++) { |
1661 | 97 | if (betaAtoms[i]->GetAtomicNum() == OBElements::Sulfur || betaAtoms[i]->GetAtomicNum() == OBElements::Oxygen) { |
1662 | 53 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1663 | 2 | return 64; // Aromatic 5-ring C, beta to N:, O:, or S: (C5B) |
1664 | 51 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1665 | 24 | return 66; // Aromatic 5-ring N, beta to N:, O:, or S: (N5B) |
1666 | 24 | } |
1667 | 53 | } |
1668 | 97 | } |
1669 | | |
1670 | 60 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1671 | 2 | return 78; // General carbon in 5-membered aromatic ring (C5) |
1672 | 58 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1673 | 27 | return 79; // General nitrogen in 5-membered aromatic ring (N5) |
1674 | 27 | } |
1675 | 60 | } |
1676 | 307 | } |
1677 | 704 | } |
1678 | | |
1679 | 361 | if (atom->IsInRingSize(6)) { |
1680 | | |
1681 | 205 | if (atom->GetAtomicNum() == OBElements::Carbon) { |
1682 | 57 | return 37; // Aromatic carbon, e.g., in benzene (CB) |
1683 | 148 | } else if (atom->GetAtomicNum() == OBElements::Nitrogen) { |
1684 | 161 | FOR_NBORS_OF_ATOM (nbr, atom) { |
1685 | 161 | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1686 | 1 | return 69; // Pyridinium N-oxide nitrogen (NPOX) |
1687 | 1 | } |
1688 | 161 | } |
1689 | | |
1690 | 57 | if (atom->GetExplicitDegree() == 3) { |
1691 | 22 | return 58; // Aromatic nitrogen in pyridinium (NPD+) |
1692 | 35 | } else { |
1693 | 35 | return 38; // Aromatic nitrogen with sigma lone pair (NPYD) |
1694 | 35 | } |
1695 | 57 | } |
1696 | 205 | } |
1697 | 361 | } |
1698 | | |
1699 | | //////////////////////////////// |
1700 | | // Hydrogen |
1701 | | //////////////////////////////// |
1702 | 229k | if (atom->GetAtomicNum() == 1) { |
1703 | 39.0k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1704 | 32.8k | if (nbr->GetAtomicNum() == OBElements::Carbon) { |
1705 | 17.1k | return 5; // Hydrogen attatched to carbon (HC) |
1706 | 17.1k | } |
1707 | 15.6k | if (nbr->GetAtomicNum() == 14) { |
1708 | 249 | return 5; // Hydrogen attatched to silicon (HSI) |
1709 | 249 | } |
1710 | 15.4k | if (nbr->GetAtomicNum() == OBElements::Oxygen) { |
1711 | 1.87k | if (nbr->GetExplicitValence() == 3) { |
1712 | 166 | if (nbr->GetExplicitDegree() == 3) { |
1713 | 163 | return 50; // Hydrogen on oxonium oxygen (HO+) |
1714 | 163 | } else { |
1715 | 3 | return 52; // Hydrogen on oxenium oxygen (HO=+) |
1716 | 3 | } |
1717 | 166 | } |
1718 | | |
1719 | 1.70k | int hydrogenCount = 0; |
1720 | 4.22k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
1721 | 4.22k | if (nbrNbr->GetAtomicNum() == OBElements::Hydrogen) { |
1722 | 3.89k | hydrogenCount++; |
1723 | 3.89k | continue; |
1724 | 3.89k | } |
1725 | 331 | if (nbrNbr->GetAtomicNum() == OBElements::Carbon) { |
1726 | 156 | if (nbrNbr->IsAromatic()) { |
1727 | 6 | return 29; // phenol |
1728 | 6 | } |
1729 | | |
1730 | 581 | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
1731 | 581 | if (nbrNbrNbr->GetIdx() == nbr->GetIdx()) |
1732 | 146 | continue; |
1733 | | |
1734 | 435 | bond = _mol.GetBond(&*nbrNbr, &*nbrNbrNbr); |
1735 | 435 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1736 | 7 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Oxygen) { |
1737 | 1 | return 24; // Hydroxyl hydrogen in carboxylic acids (HOCO) |
1738 | 1 | } |
1739 | 6 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Carbon || nbrNbrNbr->GetAtomicNum() == OBElements::Nitrogen) { |
1740 | 3 | return 29; // Enolic or phenolic hydroxyl hydrogen, |
1741 | | // Hydroxyl hydrogen in HO-C=N moiety (HOCC, HOCN) |
1742 | 3 | } |
1743 | 6 | } |
1744 | 435 | } |
1745 | 150 | } |
1746 | 321 | if (nbrNbr->GetAtomicNum() == OBElements::Phosphorus) { |
1747 | 1 | return 24; // Hydroxyl hydrogen in H-O-P moiety (HOP) |
1748 | 1 | } |
1749 | 320 | if (nbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
1750 | 9 | return 33; // Hydrogen on oxygen attached to sulfur (HOS) |
1751 | 9 | } |
1752 | | |
1753 | 320 | } |
1754 | 1.68k | if (hydrogenCount == 2) { |
1755 | 1.48k | return 31; // Hydroxyl hydrogen in water (HOH) |
1756 | 1.48k | } |
1757 | | |
1758 | 206 | return 21; // Hydroxyl hydrogen in alcohols, Generic hydroxyl hydrogen (HOR, HO) |
1759 | 1.68k | } |
1760 | 13.5k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
1761 | 4.58k | switch (GetType(&*nbr)) { |
1762 | 6 | case 81: |
1763 | 6 | return 36; // Hydrogen on imidazolium nitrogen (HIM+) |
1764 | 6 | case 68: |
1765 | 6 | return 23; // Hydrogen on N in N-oxide (HNOX) |
1766 | 0 | case 67: |
1767 | 0 | return 23; // Hydrogen on N in N-oxide (HNOX) |
1768 | 91 | case 62: |
1769 | 91 | return 23; // Generic hydrogen on sp3 nitrogen, e.g., in amines (HNR) |
1770 | 1 | case 56: |
1771 | 1 | return 36; // Hydrogen on guanimdinium nitrogen (HGD+) |
1772 | 4 | case 55: |
1773 | 4 | return 36; // Hydrogen on amidinium nitrogen (HNN+) |
1774 | 4 | case 43: |
1775 | 4 | return 28; // Hydrogen on NSO, NSO2, or NSO3 nitrogen, Hydrogen on N triply bonded to C (HNSO, HNC%) |
1776 | 13 | case 39: |
1777 | 13 | return 23; // Hydrogen on nitrogen in pyrrole (HPYL) |
1778 | 3.76k | case 8: |
1779 | 3.76k | return 23; // Generic hydrogen on sp3 nitrogen, e.g., in amines, Hydrogen on nitrogen in ammonia (HNR, H3N) |
1780 | 4.58k | } |
1781 | | |
1782 | 695 | if (nbr->GetExplicitValence() == 4) { |
1783 | 271 | if (nbr->GetExplicitDegree() == 2) { |
1784 | 1 | return 28; // Hydrogen on N triply bonded to C (HNC%) |
1785 | 270 | } else { |
1786 | 270 | return 36; // Hydrogen on pyridinium nitrogen, Hydrogen on protonated imine nitrogen (HPD+, HNC+) |
1787 | 270 | } |
1788 | 271 | } |
1789 | | |
1790 | 424 | if (nbr->GetExplicitDegree() == 2) { |
1791 | 86 | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
1792 | 86 | if (nbrNbr->GetAtomicNum() == OBElements::Hydrogen) |
1793 | 3 | continue; |
1794 | | |
1795 | 83 | bond = _mol.GetBond(&*nbr, &*nbrNbr); |
1796 | 83 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1797 | 81 | if (nbrNbr->GetAtomicNum() == OBElements::Carbon || nbrNbr->GetAtomicNum() == OBElements::Nitrogen) { |
1798 | 79 | return 27; // Hydrogen on imine nitrogen, Hydrogen on azo nitrogen (HN=C, HN=N) |
1799 | 79 | } |
1800 | | |
1801 | 2 | return 28; // Generic hydrogen on sp2 nitrogen (HSP2) |
1802 | 81 | } |
1803 | 83 | } |
1804 | 83 | } |
1805 | | |
1806 | 804 | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
1807 | 804 | if (nbrNbr->GetAtomicNum() == OBElements::Hydrogen) |
1808 | 205 | continue; |
1809 | | |
1810 | 599 | if (nbrNbr->GetAtomicNum() == OBElements::Carbon) { |
1811 | 231 | if (nbrNbr->IsAromatic()) { |
1812 | 4 | return 28; // deloc. lp pair |
1813 | 4 | } |
1814 | | |
1815 | 646 | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
1816 | 646 | if (nbrNbrNbr->GetIdx() == nbr->GetIdx()) |
1817 | 219 | continue; |
1818 | | |
1819 | 427 | bond = _mol.GetBond(&*nbrNbr, &*nbrNbrNbr); |
1820 | 427 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1821 | 215 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Carbon || nbrNbrNbr->GetAtomicNum() == OBElements::Nitrogen || nbrNbrNbr->GetAtomicNum() == OBElements::Oxygen || nbrNbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
1822 | 45 | return 28; // Hydrogen on amide nitrogen, Hydrogen on thioamide nitrogen, |
1823 | | // Hydrogen on enamine nitrogen, Hydrogen in H-N-C=N moiety (HNCO, HNCS, HNCC, HNCN) |
1824 | 45 | } |
1825 | 215 | } |
1826 | 427 | } |
1827 | 227 | } |
1828 | 550 | if (nbrNbr->GetAtomicNum() == OBElements::Nitrogen) { |
1829 | 814 | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
1830 | 814 | if (nbrNbrNbr->GetIdx() == nbr->GetIdx()) |
1831 | 251 | continue; |
1832 | | |
1833 | 563 | bond = _mol.GetBond(&*nbrNbr, &*nbrNbrNbr); |
1834 | 563 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1835 | 88 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Carbon || nbrNbrNbr->GetAtomicNum() == OBElements::Nitrogen) { |
1836 | 87 | return 28; // Hydrogen in H-N-N=C moiety, Hydrogen in H-N-N=N moiety (HNNC, HNNN) |
1837 | 87 | } |
1838 | 88 | } |
1839 | 563 | } |
1840 | 319 | } |
1841 | 463 | if (nbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
1842 | 29 | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
1843 | 29 | if (nbrNbrNbr->GetIdx() == nbr->GetIdx()) |
1844 | 11 | continue; |
1845 | | |
1846 | 18 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Oxygen || (nbrNbrNbr->GetExplicitDegree() == 1)) { |
1847 | 12 | return 28; // Hydrogen on NSO, NSO2 or NSO3 nitrogen (HNSO) |
1848 | 12 | } |
1849 | 18 | } |
1850 | 16 | } |
1851 | 463 | } |
1852 | | |
1853 | 195 | return 23; // Generic hydrogen on sp3 nitrogen e.g., in amines, |
1854 | | // Hydrogen on nitrogen in pyrrole, Hydrogen in ammonia, |
1855 | | // Hydrogen on N in N-oxide (HNR, HPYL, H3N, HNOX) |
1856 | 343 | } |
1857 | 8.96k | if (nbr->GetAtomicNum() == OBElements::Sulfur || nbr->GetAtomicNum() == OBElements::Phosphorus) { |
1858 | 2.82k | return 71; // Hydrogen attached to sulfur, Hydrogen attached to >S= sulfur doubly bonded to N, |
1859 | | // Hydrogen attached to phosphorus (HS, HS=N, HP) |
1860 | 2.82k | } |
1861 | 8.96k | } |
1862 | 39.0k | } |
1863 | | |
1864 | | //////////////////////////////// |
1865 | | // Lithium |
1866 | | //////////////////////////////// |
1867 | 202k | if (atom->GetAtomicNum() == 3) { |
1868 | | // 0 neighbours |
1869 | 805 | if (atom->GetExplicitDegree() == 0) { |
1870 | 663 | return 92; // Lithium cation (LI+) |
1871 | 663 | } |
1872 | 805 | } |
1873 | | |
1874 | | //////////////////////////////// |
1875 | | // Carbon |
1876 | | //////////////////////////////// |
1877 | 202k | if (atom->GetAtomicNum() == 6) { |
1878 | | // 4 neighbours |
1879 | 24.3k | if (atom->GetExplicitDegree() == 4) { |
1880 | 6.52k | if (atom->IsInRingSize(3)) { |
1881 | 79 | return 22; // Aliphatic carbon in 3-membered ring (CR3R) |
1882 | 79 | } |
1883 | | |
1884 | 6.44k | if (atom->IsInRingSize(4)) { |
1885 | 70 | return 20; // Aliphatic carbon in 4-membered ring (CR4R) |
1886 | 70 | } |
1887 | | |
1888 | 6.37k | return 1; // Alkyl carbon (CR) |
1889 | 6.44k | } |
1890 | | // 3 neighbours |
1891 | 17.8k | if (atom->GetExplicitDegree() == 3) { |
1892 | 4.87k | int N2count = 0; |
1893 | 4.87k | int N3count = 0; |
1894 | 4.87k | int N3fcharge = 0; |
1895 | 4.87k | oxygenCount = sulphurCount = doubleBondTo = 0; |
1896 | | |
1897 | 14.6k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1898 | 14.6k | bond = _mol.GetBond(&*nbr, atom); |
1899 | 14.6k | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1900 | 3.99k | doubleBondTo = nbr->GetAtomicNum(); |
1901 | 3.99k | } |
1902 | | |
1903 | 14.6k | if (nbr->GetExplicitDegree() == 1) { |
1904 | 4.02k | if (nbr->GetAtomicNum() == OBElements::Oxygen) { |
1905 | 18 | oxygenCount++; |
1906 | 4.00k | } else if (nbr->GetAtomicNum() == OBElements::Sulfur) { |
1907 | 13 | sulphurCount++; |
1908 | 13 | } |
1909 | 10.5k | } else if (nbr->GetExplicitDegree() == 3) { |
1910 | 6.81k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
1911 | 826 | N3fcharge += nbr->GetFormalCharge(); |
1912 | 826 | N3count++; |
1913 | 826 | } |
1914 | 6.81k | } else if ((nbr->GetExplicitDegree() == 2) && !bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1915 | 1.01k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
1916 | 219 | N2count++; |
1917 | 219 | } |
1918 | 1.01k | } |
1919 | 14.6k | } |
1920 | 4.87k | if ((N3count >= 2) && (doubleBondTo == 7 || (!(doubleBondTo == 6) && atom->GetExplicitDegree() == 3 |
1921 | 243 | && N3fcharge == 1)) && !N2count && !oxygenCount && !sulphurCount) { |
1922 | | // N3==C--N3 |
1923 | 20 | return 57; // Guanidinium carbon, Carbon in +N=C-N: resonance structures (CGD+, CNN+) |
1924 | 20 | } |
1925 | 4.85k | if ((oxygenCount == 2) || (sulphurCount == 2)) { |
1926 | | // O1-?-C-?-O1 or S1-?-C-?-S1 |
1927 | 5 | return 41; // Carbon in carboxylate anion, Carbon in thiocarboxylate anion (CO2M, CS2M) |
1928 | 5 | } |
1929 | 4.84k | if (atom->IsInRingSize(4) && (doubleBondTo == 6)) { |
1930 | 81 | return 30; // Olefinic carbon in 4-membered ring (CR4E) |
1931 | 81 | } |
1932 | 4.76k | if ((doubleBondTo == 7) || (doubleBondTo == 8) || |
1933 | 4.46k | (doubleBondTo == 15) || (doubleBondTo == 16)) { |
1934 | | // C==N, C==O, C==P, C==S |
1935 | 938 | return 3; // Generic carbonyl carbon, Imine-type carbon, Guanidine carbon, |
1936 | | // Ketone or aldehyde carbonyl carbon, Amide carbonyl carbon, |
1937 | | // Carboxylic acid or ester carbonyl carbon, Carbamate carbonyl carbon, |
1938 | | // Carbonic acid or ester carbonyl carbon, Thioester carbonyl (double |
1939 | | // bonded to O or S), Thioamide carbon (double bonded to S), Carbon |
1940 | | // in >C=SO2, Sulfinyl carbon in >C=S=O, Thiocarboxylic acid or ester |
1941 | | // carbon, Carbon doubly bonded to P (C=O, C=N, CGD, C=OR, C=ON, COO, |
1942 | | // COON, COOO, C=OS, C=S, C=SN, CSO2, CS=O, CSS, C=P) |
1943 | 938 | } |
1944 | | |
1945 | 3.82k | return 2; // Vinylic Carbon, Generic sp2 carbon (C=C, CSP2) |
1946 | | |
1947 | 4.76k | } |
1948 | | // 2 neighbours |
1949 | 12.9k | if (atom->GetExplicitDegree() == 2) { |
1950 | 12.3k | return 4; // Acetylenic carbon, Allenic caron (CSP, =C=) |
1951 | 12.3k | } |
1952 | | // 1 neighbours |
1953 | 588 | if (atom->GetExplicitDegree() == 1) { |
1954 | 261 | return 60; // Isonitrile carbon (C%-) |
1955 | 261 | } |
1956 | 588 | } |
1957 | | |
1958 | | //////////////////////////////// |
1959 | | // Nitrogen |
1960 | | //////////////////////////////// |
1961 | 178k | if (atom->GetAtomicNum() == 7) { |
1962 | | // 4 neighbours |
1963 | 38.2k | if (atom->GetExplicitDegree() == 4) { |
1964 | 3.51k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1965 | 3.51k | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1966 | 20 | return 68; // sp3-hybridized N-oxide nitrogen (N3OX) |
1967 | 20 | } |
1968 | 3.51k | } |
1969 | | |
1970 | 865 | return 34; // Quaternary nitrogen (NR+) |
1971 | 885 | } |
1972 | | // 3 neighbours |
1973 | 37.4k | if (atom->GetExplicitDegree() == 3) { |
1974 | 9.02k | if (atom->GetExplicitValence() >= 4) { // > because we accept -N(=O)=O as a valid nitro group |
1975 | 573 | oxygenCount = nitrogenCount = doubleBondTo = 0; |
1976 | | |
1977 | 1.71k | FOR_NBORS_OF_ATOM (nbr, atom) { |
1978 | 1.71k | if (nbr->GetAtomicNum() == OBElements::Oxygen && (nbr->GetExplicitDegree() == 1)) { |
1979 | 16 | oxygenCount++; |
1980 | 16 | } |
1981 | 1.71k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
1982 | 543 | bond = _mol.GetBond(&*nbr, atom); |
1983 | 543 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1984 | 97 | doubleBondTo = 7; |
1985 | 97 | } |
1986 | 543 | } |
1987 | 1.71k | if (nbr->GetAtomicNum() == OBElements::Carbon) { |
1988 | 224 | bond = _mol.GetBond(&*nbr, atom); |
1989 | 224 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
1990 | 355 | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
1991 | 355 | if (nbrNbr->GetAtomicNum() == OBElements::Nitrogen && (nbrNbr->GetExplicitDegree() == 3)) { |
1992 | 161 | nitrogenCount++; |
1993 | 161 | } |
1994 | 355 | } |
1995 | 128 | } |
1996 | 224 | } |
1997 | 1.71k | } |
1998 | | |
1999 | 573 | if (oxygenCount == 1) { |
2000 | 14 | return 67; // sp2-hybridized N-oxide nitrogen (N2OX) |
2001 | 14 | } |
2002 | 559 | if (oxygenCount >= 2) { |
2003 | 1 | return 45; // Nitrogen in nitro group, Nitrogen in nitrate group (NO2, NO3) |
2004 | 1 | } |
2005 | | |
2006 | 558 | if (nitrogenCount == 1) { |
2007 | 89 | return 54; // Iminium nitrogen (N+=C) |
2008 | 89 | } |
2009 | 469 | if (nitrogenCount == 2) { |
2010 | 10 | return 55; // Either nitrogen in N+=C-N: (NCN+) |
2011 | 10 | } |
2012 | 459 | if (nitrogenCount == 3) { |
2013 | 12 | return 56; // Guanidinium nitrogen (NGD+) |
2014 | 12 | } |
2015 | | |
2016 | 447 | if (doubleBondTo == 7) { |
2017 | 75 | return 54; // Positivly charged nitrogen doubly bonded to nitrogen (N+=N) |
2018 | 75 | } |
2019 | 447 | } |
2020 | | |
2021 | 8.82k | if (atom->GetExplicitValence() == 3) { |
2022 | 8.44k | bool IsAmide = false; |
2023 | 8.44k | bool IsSulfonAmide = false; |
2024 | 8.44k | bool IsNNNorNNC = false; |
2025 | 8.44k | int tripleBondTo = 0; |
2026 | 8.44k | doubleBondTo = 0; |
2027 | | |
2028 | 25.3k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2029 | 25.3k | if (nbr->GetAtomicNum() == OBElements::Sulfur || nbr->GetAtomicNum() == OBElements::Phosphorus) { |
2030 | 742 | oxygenCount = 0; |
2031 | | |
2032 | 2.30k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2033 | 2.30k | if (nbrNbr->GetAtomicNum() == OBElements::Oxygen && (nbrNbr->GetExplicitDegree() == 1)) { |
2034 | 30 | oxygenCount++; |
2035 | 30 | } |
2036 | 2.30k | } |
2037 | 742 | if (oxygenCount >= 2) { |
2038 | 6 | IsSulfonAmide = true; |
2039 | | //return 43; // Sulfonamide nitrogen (NSO2, NSO3) |
2040 | 6 | } |
2041 | 742 | } |
2042 | 25.3k | } |
2043 | | |
2044 | 25.3k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2045 | 25.3k | if (nbr->GetAtomicNum() == OBElements::Carbon) { |
2046 | 3.85k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2047 | 3.85k | bond = _mol.GetBond(&*nbr, &*nbrNbr); |
2048 | 3.85k | if (!bond->IsAromatic() && bond->GetBondOrder() == 2 && (nbrNbr->GetAtomicNum() == OBElements::Oxygen || nbrNbr->GetAtomicNum() == OBElements::Sulfur)) { |
2049 | 30 | IsAmide = true; |
2050 | | //return 10; // Amide nitrogen, Thioamide nitrogen (NC=O, NC=S) |
2051 | 30 | } |
2052 | 3.85k | } |
2053 | 1.25k | } |
2054 | 25.3k | } |
2055 | | |
2056 | 25.2k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2057 | 25.2k | if (nbr->GetAtomicNum() == OBElements::Carbon) { |
2058 | 1.25k | int N2count = 0; |
2059 | 1.25k | int N3count = 0; |
2060 | 1.25k | oxygenCount = sulphurCount = 0; |
2061 | | |
2062 | 3.85k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2063 | 3.85k | bond = _mol.GetBond(&*nbr, &*nbrNbr); |
2064 | 3.85k | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2065 | 831 | doubleBondTo = nbrNbr->GetAtomicNum(); |
2066 | 831 | } |
2067 | 3.85k | if (bond->IsAromatic()) { |
2068 | 32 | if ((nbrNbr->GetAtomicNum() == 7) || (nbrNbr->GetAtomicNum() == 6)) { |
2069 | 26 | doubleBondTo = nbrNbr->GetAtomicNum(); |
2070 | 26 | } |
2071 | 32 | } |
2072 | 3.85k | if (!bond->IsAromatic() && bond->GetBondOrder() == 3) { |
2073 | 8 | tripleBondTo = nbrNbr->GetAtomicNum(); |
2074 | 8 | } |
2075 | 3.85k | if (nbrNbr->GetAtomicNum() == OBElements::Nitrogen && (nbrNbr->GetExplicitDegree() == 3)) { |
2076 | 2.10k | int nbrOxygen = 0; |
2077 | 6.30k | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
2078 | 6.30k | if (nbrNbrNbr->GetAtomicNum() == OBElements::Oxygen) { |
2079 | 46 | nbrOxygen++; |
2080 | 46 | } |
2081 | 6.30k | } |
2082 | 2.10k | if (nbrOxygen < 2) { |
2083 | 2.09k | N3count++; |
2084 | 2.09k | } |
2085 | 2.10k | } |
2086 | 3.85k | if (nbrNbr->GetAtomicNum() == OBElements::Nitrogen && (nbrNbr->GetExplicitDegree() == 2) && (bond->GetBondOrder() == 2 || bond->IsAromatic())) { |
2087 | 101 | N2count++; |
2088 | 101 | } |
2089 | 3.85k | if (nbrNbr->IsAromatic()) { |
2090 | 42 | if (nbrNbr->GetAtomicNum() == OBElements::Oxygen) { |
2091 | 1 | oxygenCount++; |
2092 | 1 | } |
2093 | 42 | if (nbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
2094 | 4 | sulphurCount++; |
2095 | 4 | } |
2096 | 42 | } |
2097 | 3.85k | } |
2098 | 1.25k | if (N3count == 3) { |
2099 | 30 | return 56; // Guanidinium nitrogen (NGD+) |
2100 | 30 | } |
2101 | | |
2102 | 1.22k | if (!IsAmide && !IsSulfonAmide && !oxygenCount && !sulphurCount && nbr->IsAromatic()) { |
2103 | 13 | return 40; |
2104 | 13 | } |
2105 | | |
2106 | 1.21k | if ((N3count == 2) && (doubleBondTo == 7) && !N2count) { |
2107 | 15 | return 55; // Either nitrogen in N+=C-N: (NCN+) |
2108 | 15 | } |
2109 | 1.21k | } |
2110 | | |
2111 | 25.2k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
2112 | 9.71k | nitrogenCount = 0; |
2113 | 27.3k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2114 | 27.3k | bond = _mol.GetBond(&*nbr, &*nbrNbr); |
2115 | 27.3k | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2116 | 1.29k | if (nbrNbr->GetAtomicNum() == OBElements::Carbon) { |
2117 | 128 | oxygenCount = sulphurCount = 0; |
2118 | 387 | FOR_NBORS_OF_ATOM (nbrNbrNbr, &*nbrNbr) { |
2119 | 387 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Oxygen) { |
2120 | 54 | oxygenCount++; |
2121 | 54 | } |
2122 | 387 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
2123 | 7 | sulphurCount++; |
2124 | 7 | } |
2125 | 387 | if (nbrNbrNbr->GetAtomicNum() == OBElements::Sulfur) { |
2126 | 7 | nitrogenCount++; |
2127 | 7 | } |
2128 | 387 | } |
2129 | 128 | if (!oxygenCount && !sulphurCount && (nitrogenCount == 1)) { |
2130 | 1 | bool bondToAromC = false; |
2131 | 3 | FOR_NBORS_OF_ATOM (nbr2, atom) { |
2132 | 3 | if (nbr2->IsAromatic() && nbr2->GetAtomicNum() == OBElements::Carbon && nbr2->IsInRingSize(6)) { |
2133 | 0 | bondToAromC = true; |
2134 | 0 | } |
2135 | 3 | } |
2136 | 1 | if (!bondToAromC) { |
2137 | 1 | IsNNNorNNC = true; |
2138 | 1 | } |
2139 | 1 | } |
2140 | 128 | } |
2141 | 1.29k | if (nbrNbr->GetAtomicNum() == OBElements::Nitrogen) { |
2142 | 825 | bool bondToAromC = false; |
2143 | 2.47k | FOR_NBORS_OF_ATOM (nbr2, atom) { |
2144 | 2.47k | if (nbr2->IsAromatic() && nbr2->GetAtomicNum() == OBElements::Carbon && nbr2->IsInRingSize(6)) { |
2145 | 3 | bondToAromC = true; |
2146 | 3 | } |
2147 | 2.47k | } |
2148 | 825 | if (!bondToAromC) { |
2149 | 822 | IsNNNorNNC = true; |
2150 | 822 | } |
2151 | 825 | } |
2152 | 1.29k | } |
2153 | 27.3k | } |
2154 | 9.71k | } |
2155 | 25.2k | } |
2156 | | |
2157 | 8.38k | if (IsSulfonAmide) { |
2158 | 6 | return 43; // Sulfonamide nitrogen (NSO2, NSO3) |
2159 | 6 | } |
2160 | 8.38k | if (IsAmide) { |
2161 | 27 | return 10; // Amide nitrogen, Thioamide nitrogen (NC=O, NC=S) |
2162 | 27 | } |
2163 | | |
2164 | 8.35k | if ((doubleBondTo == 6) || (doubleBondTo == 7) ||(doubleBondTo == 15) || (tripleBondTo == 6)) { |
2165 | 718 | return 40; // Enamine or aniline nitrogen (deloc. lp), Nitrogen in N-C=N with deloc. lp, |
2166 | | // Nitrogen in N-C=N with deloc. lp, Nitrogen attached to C-C triple bond |
2167 | | // (NC=C, NC=N, NC=P, NC%C) |
2168 | 718 | } |
2169 | 7.63k | if (tripleBondTo == 7) { |
2170 | 6 | return 43; // Nitrogen attached to cyano group (NC%N) |
2171 | 6 | } |
2172 | 7.63k | if (IsNNNorNNC) { |
2173 | 652 | return 10; // Nitrogen in N-N=C moiety with deloc. lp |
2174 | | // Nitrogen in N-N=N moiety with deloc. lp (NN=C, NN=N) |
2175 | 652 | } |
2176 | | |
2177 | 6.97k | return 8; // Amine nitrogen (NR) |
2178 | 7.63k | } |
2179 | 8.82k | } |
2180 | | // 2 neighbours |
2181 | 28.7k | if (atom->GetExplicitDegree() == 2) { |
2182 | 26.0k | if (atom->GetExplicitValence() >= 4) { |
2183 | 418 | bool isNbrCarbon = false; |
2184 | 418 | bool isBondTriple = false; |
2185 | 836 | FOR_NBORS_OF_ATOM (nbr, atom) { |
2186 | 836 | if (!isNbrCarbon) |
2187 | 830 | isNbrCarbon = nbr->GetAtomicNum() == OBElements::Carbon; |
2188 | 836 | bond = _mol.GetBond(&*nbr, atom); |
2189 | 836 | if (!isBondTriple) |
2190 | 807 | isBondTriple = !bond->IsAromatic() && bond->GetBondOrder() == 3; |
2191 | 836 | } |
2192 | 418 | if (isBondTriple && isNbrCarbon) |
2193 | 11 | return 61; // Isonitrile nitrogen (NR%) |
2194 | | |
2195 | 407 | return 53; // Central nitrogen in C=N=N or N=N=N (=N=) |
2196 | 418 | } |
2197 | | |
2198 | 25.6k | if (atom->GetExplicitValence() == 3) { |
2199 | 21.8k | doubleBondTo = 0; |
2200 | | |
2201 | 33.4k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2202 | 33.4k | bond = _mol.GetBond(&*nbr, atom); |
2203 | 33.4k | if (nbr->GetAtomicNum() == OBElements::Oxygen && !bond->IsAromatic() && bond->GetBondOrder() == 2 && (nbr->GetExplicitDegree() == 1)) { |
2204 | 6 | return 46; // Nitrogen in nitroso group (N=O) |
2205 | 6 | } |
2206 | 33.4k | if ((nbr->GetAtomicNum() == OBElements::Carbon || nbr->GetAtomicNum() == OBElements::Nitrogen) && !bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2207 | 20.4k | return 9; // Iminie nitrogen, Azo-group nitrogen (N=C, N=N) |
2208 | 20.4k | } |
2209 | 33.4k | } |
2210 | 2.83k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2211 | 2.83k | if (nbr->GetAtomicNum() == OBElements::Sulfur) { |
2212 | 560 | oxygenCount = 0; |
2213 | | |
2214 | 1.13k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2215 | 1.13k | if (nbrNbr->GetAtomicNum() == OBElements::Oxygen && (nbrNbr->GetExplicitDegree() == 1)) { |
2216 | 3 | oxygenCount++; |
2217 | 3 | } |
2218 | 1.13k | } |
2219 | 560 | if (oxygenCount >= 2) { |
2220 | 0 | return 43; // Sulfonamide nitrogen (NSO2, NSO3) |
2221 | 0 | } |
2222 | 560 | } |
2223 | 2.83k | } |
2224 | 1.41k | } |
2225 | | |
2226 | 5.17k | if (atom->GetExplicitValence() >= 2) { // Bug reported by Paolo Tosco |
2227 | 5.17k | oxygenCount = sulphurCount = 0; |
2228 | | |
2229 | 10.3k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2230 | 10.3k | if (nbr->GetAtomicNum() == OBElements::Sulfur) { |
2231 | 1.65k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2232 | 1.65k | if (nbrNbr->GetAtomicNum() == OBElements::Oxygen && (nbrNbr->GetExplicitDegree() == 1)) { |
2233 | 19 | oxygenCount++; |
2234 | 19 | } |
2235 | 1.65k | } |
2236 | 739 | if (oxygenCount == 1) { |
2237 | 17 | return 48; // Divalent nitrogen replacing monovalent O in SO2 group (NSO) |
2238 | 17 | } |
2239 | 739 | } |
2240 | 10.3k | } |
2241 | | |
2242 | 5.15k | return 62; // Anionic divalent nitrogen (NM) |
2243 | 5.17k | } |
2244 | 5.17k | } |
2245 | | // 1 neighbours |
2246 | 2.73k | if (atom->GetExplicitDegree() == 1) { |
2247 | 1.25k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2248 | 1.25k | bond = _mol.GetBond(&*nbr, atom); |
2249 | 1.25k | if (!bond->IsAromatic() && bond->GetBondOrder() == 3) { |
2250 | 78 | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2251 | 78 | if (atom != &*nbrNbr && !(nbr->GetAtomicNum() == OBElements::Nitrogen |
2252 | 9 | && nbrNbr->GetAtomicNum() == OBElements::Nitrogen && nbrNbr->GetExplicitDegree() == 2)) { |
2253 | 9 | return 42; // Triply bonded nitrogen (NSP) |
2254 | 9 | } |
2255 | 78 | } |
2256 | 69 | } |
2257 | 1.24k | if (nbr->GetAtomicNum() == OBElements::Nitrogen && (nbr->GetExplicitDegree() == 2)) { |
2258 | 62 | return 47; // Terminal nitrogen in azido group (NAZT) |
2259 | 62 | } |
2260 | 1.24k | } |
2261 | 1.25k | } |
2262 | 2.66k | return 8; // generic amine nitrogen |
2263 | 2.73k | } |
2264 | | |
2265 | | //////////////////////////////// |
2266 | | // Oxygen |
2267 | | //////////////////////////////// |
2268 | 139k | if (atom->GetAtomicNum() == 8) { |
2269 | | // 3 neighbours |
2270 | 7.51k | if (atom->GetExplicitDegree() == 3) { |
2271 | 399 | return 49; // Oxonium oxygen (O+) |
2272 | 399 | } |
2273 | | // 2 neighbours |
2274 | 7.11k | if (atom->GetExplicitDegree() == 2) { |
2275 | 2.84k | int hydrogenCount = 0; |
2276 | 5.69k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2277 | 5.69k | if (nbr->GetAtomicNum() == OBElements::Hydrogen) { |
2278 | 1.54k | hydrogenCount++; |
2279 | 1.54k | } |
2280 | 5.69k | } |
2281 | | |
2282 | 2.84k | if (hydrogenCount == 2) { |
2283 | | // H--O--H |
2284 | 741 | return 70; // Oxygen in water (OH2) |
2285 | 741 | } |
2286 | 2.10k | if (atom->GetExplicitValence() == 3) { |
2287 | 185 | return 51; // Oxenium oxygen (O=+) |
2288 | 185 | } |
2289 | | |
2290 | 1.92k | return 6; // Generic divalent oxygen, Ether oxygen, Carboxylic acid or ester oxygen, |
2291 | | // Enolic or phenolic oxygen, Oxygen in -O-C=N- moiety, Divalent oxygen in |
2292 | | // thioacid or ester, Divalent nitrate "ether" oxygen, Divalent oxygen in |
2293 | | // sulfate group, Divalent oxygen in sulfite group, One of two divalent |
2294 | | // oxygens attached to sulfur, Divalent oxygen in R(RO)S=O, Other divalent |
2295 | | // oxygen attached to sulfur, Divalent oxygen in phosphate group, Divalent |
2296 | | // oxygen in phosphite group, Divalent oxygen (one of two oxygens attached |
2297 | | // to P), Other divalent oxygen (-O-, OR, OC=O, OC=C, OC=N, OC=S, ONO2, |
2298 | | // ON=O, OSO3, OSO2, OSO, OS=O, -OS, OPO3, OPO2, OPO, -OP) |
2299 | | |
2300 | | // 59 ar |
2301 | 2.10k | } |
2302 | | // 1 neighbour |
2303 | 4.26k | if (atom->GetExplicitDegree() == 1) { |
2304 | 1.44k | oxygenCount = sulphurCount = 0; |
2305 | | |
2306 | 1.44k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2307 | 1.44k | bond = _mol.GetBond(&*nbr, atom); |
2308 | | |
2309 | 1.44k | if (nbr->GetAtomicNum() == OBElements::Carbon || nbr->GetAtomicNum() == OBElements::Nitrogen) { |
2310 | 383 | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2311 | 383 | if (nbrNbr->GetAtomicNum() == OBElements::Oxygen && (nbrNbr->GetExplicitDegree() == 1)) { |
2312 | 205 | oxygenCount++; |
2313 | 205 | } |
2314 | 383 | if (nbrNbr->GetAtomicNum() == OBElements::Sulfur && (nbrNbr->GetExplicitDegree() == 1)) { |
2315 | 16 | sulphurCount++; |
2316 | 16 | } |
2317 | 383 | } |
2318 | 129 | } |
2319 | | // O---H |
2320 | 1.44k | if (nbr->GetAtomicNum() == OBElements::Hydrogen) { |
2321 | 26 | return 35; |
2322 | 26 | } |
2323 | | // O-?-C |
2324 | 1.42k | if (nbr->GetAtomicNum() == OBElements::Carbon) { |
2325 | 66 | if (oxygenCount == 2) { |
2326 | | // O-?-C-?-O |
2327 | 20 | return 32; // Oxygen in carboxylate group (O2CM) |
2328 | 20 | } |
2329 | 46 | if (!bond->IsAromatic() && bond->GetBondOrder() == 1) { |
2330 | | // O--C |
2331 | 31 | return 35; // Oxide oxygen on sp3 carbon, Oxide oxygen on sp2 carbon (OM, OM2) |
2332 | 31 | } else { |
2333 | | // O==C |
2334 | 15 | return 7; // Generic carbonyl oxygen, Carbonyl oxygen in amides, |
2335 | | // Carbonyl oxygen in aldehydes and ketones, Carbonyl |
2336 | | // oxygen in acids or esters (O=C, O=CN, O=CR, O=CO) |
2337 | 15 | } |
2338 | 46 | } |
2339 | | // O-?-N |
2340 | 1.35k | if (nbr->GetAtomicNum() == OBElements::Nitrogen) { |
2341 | 63 | if (oxygenCount >= 2) { |
2342 | | // O-?-N-?-O |
2343 | 15 | return 32; // Oxygen in nitro group, Nitro-group oxygen in nitrate, |
2344 | | // Nitrate anion oxygen (O2N, O2NO, O3N) |
2345 | 15 | } |
2346 | 48 | if (!bond->IsAromatic() && bond->GetBondOrder() == 1) { |
2347 | 24 | if ((nbr->GetExplicitDegree() == 2) || (nbr->GetExplicitValence() == 3)) |
2348 | | // O(-)--N |
2349 | 7 | return 35; |
2350 | 17 | else |
2351 | | // O--N |
2352 | 17 | return 32; // Oxygen in N-oxides (ONX) |
2353 | 24 | } else { |
2354 | | // sometimes ONX bonds are labelled as double bonds |
2355 | | // (e.g. by MOE, noticed by Paolo Tosco) |
2356 | 24 | int ndab = 0; |
2357 | 56 | FOR_BONDS_OF_ATOM(bond2, &*nbr) { |
2358 | 56 | if (bond2->GetBondOrder() == 2 || bond2->GetBondOrder() == 5) |
2359 | 39 | ndab++; |
2360 | 56 | } |
2361 | 24 | if (ndab + nbr->GetExplicitDegree() == 5) |
2362 | | // O--N |
2363 | 13 | return 32; // Oxygen in N-oxides (ONX) |
2364 | 11 | else |
2365 | | // O==N |
2366 | 11 | return 7; // Nitroso oxygen (O=N) |
2367 | 24 | } |
2368 | 48 | } |
2369 | | // O-?-S |
2370 | 1.29k | if (nbr->GetAtomicNum() == OBElements::Sulfur) { |
2371 | 206 | if (sulphurCount == 1) { |
2372 | | // O1-?-S-?-S1 |
2373 | 0 | return 32; // Terminal oxygen in thiosulfinate anion (OSMS) |
2374 | 0 | } |
2375 | 206 | if (!bond->IsAromatic() && bond->GetBondOrder() == 1) { |
2376 | | // O--S |
2377 | 73 | return 32; // Single terminal oxygen on sulfur, One of 2 terminal O's on sulfur, |
2378 | | // One of 3 terminal O's on sulfur, Terminal O in sulfate anion, |
2379 | | // (O-S, O2S, O3S, O4S) |
2380 | 133 | } else { |
2381 | | // O==S |
2382 | | |
2383 | | // are all sulfur nbr atoms carbon? |
2384 | 133 | bool isSulfoxide = true; |
2385 | 133 | int oxygenBoundToSulfur = 0; |
2386 | 271 | FOR_NBORS_OF_ATOM (nbr2, &*nbr) { |
2387 | 271 | if (atom == &*nbr2) |
2388 | 133 | continue; |
2389 | | |
2390 | 138 | if (nbr2->GetAtomicNum() == OBElements::Oxygen) |
2391 | 61 | ++oxygenBoundToSulfur; |
2392 | 138 | } |
2393 | 271 | FOR_NBORS_OF_ATOM (nbr2, &*nbr) { |
2394 | 271 | if (atom == &*nbr2) |
2395 | 133 | continue; |
2396 | 138 | OBBond* bond = nbr->GetBond(&*nbr2); |
2397 | 138 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2 |
2398 | 59 | && nbr2->GetAtomicNum() == OBElements::Carbon && oxygenBoundToSulfur == 1) |
2399 | 0 | isSulfoxide = false; // O=S on sulfur doubly bonded to, e.g., C (O=S=) |
2400 | | |
2401 | 138 | if ((nbr2->GetAtomicNum() == OBElements::Oxygen && nbr2->GetExplicitDegree() == 1) |
2402 | 80 | || (nbr2->GetAtomicNum() == OBElements::Nitrogen && nbr2->GetExplicitDegree() == 2)) |
2403 | 64 | isSulfoxide = false; |
2404 | 138 | } |
2405 | | |
2406 | 133 | if (isSulfoxide) |
2407 | 80 | return 7; // Doubly bonded sulfoxide oxygen (O=S) |
2408 | 53 | else |
2409 | 53 | return 32; // (O2S, O2S=C, O3S, O4S) |
2410 | 133 | } |
2411 | 206 | } |
2412 | | |
2413 | 1.08k | return 32; // Oxygen in phosphine oxide, One of 2 terminal O's on sulfur, |
2414 | | // One of 3 terminal O's on sulfur, One of 4 terminal O's on sulfur, |
2415 | | // Oxygen in perchlorate anion (OP, O2P, O3P, O4P, O4Cl) |
2416 | 1.29k | } |
2417 | 1.44k | } |
2418 | 4.26k | } |
2419 | | |
2420 | | //////////////////////////////// |
2421 | | // Flourine |
2422 | | //////////////////////////////// |
2423 | 135k | if (atom->GetAtomicNum() == 9) { |
2424 | | // 1 neighbour |
2425 | 29.5k | if (atom->GetExplicitDegree() == 1) { |
2426 | 439 | return 11; // Fluorine (F) |
2427 | 439 | } |
2428 | | // 0 neighbours |
2429 | 29.0k | if (atom->GetExplicitDegree() == 0) { |
2430 | 141 | return 89; // Fluoride anion (F-) |
2431 | 141 | } |
2432 | 29.0k | } |
2433 | | |
2434 | | //////////////////////////////// |
2435 | | // Sodium |
2436 | | //////////////////////////////// |
2437 | 134k | if (atom->GetAtomicNum() == 11) { |
2438 | 208 | return 93; // Sodium cation (NA+) |
2439 | 208 | } |
2440 | | |
2441 | | //////////////////////////////// |
2442 | | // Magnesium |
2443 | | //////////////////////////////// |
2444 | 134k | if (atom->GetAtomicNum() == 12) { |
2445 | 263 | return 99; // Dipositive magnesium cation (MG+2) |
2446 | 263 | } |
2447 | | |
2448 | | //////////////////////////////// |
2449 | | // Silicon |
2450 | | //////////////////////////////// |
2451 | 134k | if (atom->GetAtomicNum() == 14) { |
2452 | 119 | return 19; // Silicon (SI) |
2453 | 119 | } |
2454 | | |
2455 | | //////////////////////////////// |
2456 | | // Phosphorus |
2457 | | //////////////////////////////// |
2458 | 134k | if (atom->GetAtomicNum() == 15) { |
2459 | 31.7k | if (atom->GetExplicitDegree() == 4) { |
2460 | 3.31k | return 25; // Phosphate group phosphorus, Phosphorus with 3 attached oxygens, |
2461 | | // Phosphorus with 2 attached oxygens, Phosphine oxide phosphorus, |
2462 | | // General tetracoordinate phosphorus (PO4, PO3, PO2, PO, PTET) |
2463 | 3.31k | } |
2464 | 28.4k | if (atom->GetExplicitDegree() == 3) { |
2465 | 3.78k | return 26; // Phosphorus in phosphines (P) |
2466 | 3.78k | } |
2467 | 24.7k | if (atom->GetExplicitDegree() == 2) { |
2468 | 17.1k | return 75; // Phosphorus doubly bonded to C (-P=C) |
2469 | 17.1k | } |
2470 | 24.7k | } |
2471 | | |
2472 | | //////////////////////////////// |
2473 | | // Sulfur |
2474 | | //////////////////////////////// |
2475 | 109k | if (atom->GetAtomicNum() == 16) { |
2476 | | // 4 neighbours |
2477 | 8.10k | if (atom->GetExplicitDegree() == 4) { |
2478 | 90 | return 18; // Sulfone sulfur, Sulfonamide sulfur, Sulfonate group sulfur, |
2479 | | // Sulfate group sulfur, Sulfur in nitrogen analog of sulfone |
2480 | | // (SO2, SO2N, SO3, SO4, SNO) |
2481 | 90 | } |
2482 | | // 3 neighbours |
2483 | 8.01k | if (atom->GetExplicitDegree() == 3) { |
2484 | 949 | oxygenCount = sulphurCount = doubleBondTo = 0; |
2485 | | |
2486 | 2.84k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2487 | 2.84k | bond = _mol.GetBond(&*nbr, atom); |
2488 | 2.84k | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2489 | 728 | if (nbr->GetAtomicNum() == 6) |
2490 | 304 | doubleBondTo = 6; |
2491 | 728 | } |
2492 | | |
2493 | 2.84k | if (nbr->GetExplicitDegree() == 1) { |
2494 | 410 | if (nbr->GetAtomicNum() == OBElements::Oxygen) { |
2495 | 36 | oxygenCount++; |
2496 | 374 | } else if (nbr->GetAtomicNum() == OBElements::Sulfur) { |
2497 | 15 | sulphurCount++; |
2498 | 15 | } |
2499 | 410 | } |
2500 | 2.84k | } |
2501 | | |
2502 | 949 | if (oxygenCount == 2) { |
2503 | 4 | if (doubleBondTo == 6) { |
2504 | 0 | return 18; // Sulfone sulfur, doubly bonded to carbon (=SO2) |
2505 | 0 | } |
2506 | 4 | return 73; // Sulfur in anionic sulfinate group (SO2M) |
2507 | 4 | } |
2508 | 945 | if (oxygenCount && sulphurCount) |
2509 | 2 | return 73; // Tricoordinate sulfur in anionic thiosulfinate group (SSOM) |
2510 | | |
2511 | | //if ((doubleBondTo == 6) || (doubleBondTo == 8)) |
2512 | 943 | return 17; // Sulfur doubly bonded to carbon, Sulfoxide sulfur (S=C, S=O) |
2513 | 945 | } |
2514 | | // 2 neighbours |
2515 | 7.06k | if (atom->GetExplicitDegree() == 2) { |
2516 | 5.27k | doubleBondTo = 0; |
2517 | | |
2518 | 10.5k | FOR_NBORS_OF_ATOM (nbr, atom) { |
2519 | 10.5k | if (nbr->GetAtomicNum() == OBElements::Oxygen) { |
2520 | 700 | bond = _mol.GetBond(&*nbr, atom); |
2521 | 700 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2522 | 58 | doubleBondTo = 8; |
2523 | 58 | } |
2524 | 700 | } |
2525 | 10.5k | } |
2526 | | |
2527 | 5.27k | if (doubleBondTo == 8) |
2528 | 42 | return 74; // Sulfinyl sulfur, e.g., in C=S=O (=S=O) |
2529 | | |
2530 | 5.23k | return 15; // Thiol, sulfide, or disulfide sulfor (S) |
2531 | 5.27k | } |
2532 | | // 1 neighbour |
2533 | 1.79k | if (atom->GetExplicitDegree() == 1) { |
2534 | 830 | sulphurCount = doubleBondTo = 0; |
2535 | | |
2536 | 830 | FOR_NBORS_OF_ATOM (nbr, atom) { |
2537 | 2.95k | FOR_NBORS_OF_ATOM (nbrNbr, &*nbr) { |
2538 | 2.95k | if (nbrNbr->GetAtomicNum() == OBElements::Sulfur && (nbrNbr->GetExplicitDegree() == 1)) { |
2539 | 1.14k | sulphurCount++; |
2540 | 1.14k | } |
2541 | 2.95k | } |
2542 | 830 | bond = _mol.GetBond(&*nbr, atom); |
2543 | 830 | if (!bond->IsAromatic() && bond->GetBondOrder() == 2) { |
2544 | 87 | doubleBondTo = nbr->GetAtomicNum(); |
2545 | 87 | } |
2546 | 830 | } |
2547 | | |
2548 | 830 | if ((doubleBondTo == 6) && (sulphurCount != 2)) { |
2549 | 12 | return 16; // Sulfur doubly bonded to carbon (S=C) |
2550 | 12 | } |
2551 | | |
2552 | 818 | return 72; // Terminal sulfur bonded to P, Anionic terminal sulfur, |
2553 | | // Terminal sulfur in thiosulfinate group (S-P, SM, SSMO) |
2554 | 830 | } |
2555 | | |
2556 | | // 44 ar |
2557 | 1.79k | } |
2558 | | |
2559 | | //////////////////////////////// |
2560 | | // Clorine |
2561 | | //////////////////////////////// |
2562 | 102k | if (atom->GetAtomicNum() == 17) { |
2563 | | // 4 neighbour |
2564 | 374 | if (atom->GetExplicitDegree() == 4) { |
2565 | 9 | oxygenCount = 0; |
2566 | | |
2567 | 36 | FOR_NBORS_OF_ATOM (nbr, atom) { |
2568 | 36 | if (nbr->GetAtomicNum() == OBElements::Oxygen) { |
2569 | 1 | oxygenCount++; |
2570 | 1 | } |
2571 | 36 | } |
2572 | 9 | if (oxygenCount == 4) |
2573 | 0 | return 77; // Perchlorate anion chlorine (CLO4) |
2574 | 9 | } |
2575 | | // 1 neighbour |
2576 | 374 | if (atom->GetExplicitDegree() == 1) { |
2577 | 184 | return 12; // Chlorine (CL) |
2578 | 184 | } |
2579 | | // 0 neighbours |
2580 | 190 | if (atom->GetExplicitDegree() == 0) { |
2581 | 61 | return 90; // Chloride anion (CL-) |
2582 | 61 | } |
2583 | 190 | } |
2584 | | |
2585 | | //////////////////////////////// |
2586 | | // Potasium |
2587 | | //////////////////////////////// |
2588 | 102k | if (atom->GetAtomicNum() == 19) { |
2589 | 506 | return 94; // Potasium cation (K+) |
2590 | 506 | } |
2591 | | |
2592 | | //////////////////////////////// |
2593 | | // Calcium |
2594 | | //////////////////////////////// |
2595 | 101k | if (atom->GetAtomicNum() == 20) { |
2596 | | // 0 neighbours |
2597 | 609 | if (atom->GetExplicitDegree() == 0) { |
2598 | 124 | return 96; // Dipositive calcium cation (CA+2) |
2599 | 124 | } |
2600 | 609 | } |
2601 | | |
2602 | | //////////////////////////////// |
2603 | | // Iron |
2604 | | //////////////////////////////// |
2605 | 101k | if (atom->GetAtomicNum() == 26) { |
2606 | 152 | if (atom->GetFormalCharge() == 2) |
2607 | 1 | return 87; // Dipositive iron (FE+2) |
2608 | 151 | else |
2609 | 151 | return 88; // Tripositive iron (FE+3) |
2610 | 152 | } |
2611 | | |
2612 | | //////////////////////////////// |
2613 | | // Copper |
2614 | | //////////////////////////////// |
2615 | 101k | if (atom->GetAtomicNum() == 29) { |
2616 | 169 | if (atom->GetFormalCharge() == 1) |
2617 | 10 | return 97; // Monopositive copper cation (CU+1) |
2618 | 159 | else |
2619 | 159 | return 98; // Dipositive copper cation (CU+2) |
2620 | 169 | } |
2621 | | |
2622 | | //////////////////////////////// |
2623 | | // Zinc |
2624 | | //////////////////////////////// |
2625 | 101k | if (atom->GetAtomicNum() == 30) { |
2626 | 169 | return 95; // Dipositive zinc cation (ZN+2) |
2627 | 169 | } |
2628 | | |
2629 | | //////////////////////////////// |
2630 | | // Bromine |
2631 | | //////////////////////////////// |
2632 | 101k | if (atom->GetAtomicNum() == 35) { |
2633 | | // 1 neighbour |
2634 | 171 | if (atom->GetExplicitDegree() == 1) { |
2635 | 60 | return 13; // Bromine (BR) |
2636 | 60 | } |
2637 | | // 0 neighbours |
2638 | 111 | if (atom->GetExplicitDegree() == 0) { |
2639 | 22 | return 91; // Bromide anion (BR-) |
2640 | 22 | } |
2641 | 111 | } |
2642 | | |
2643 | | //////////////////////////////// |
2644 | | // Iodine |
2645 | | //////////////////////////////// |
2646 | 101k | if (atom->GetAtomicNum() == 53) { |
2647 | | // 1 neighbour |
2648 | 2.99k | if (atom->GetExplicitDegree() == 1) { |
2649 | 257 | return 14; // Iodine (I) |
2650 | 257 | } |
2651 | 2.99k | } |
2652 | | |
2653 | | |
2654 | | |
2655 | 100k | return 0; |
2656 | 101k | } |
2657 | | |
2658 | | bool OBForceFieldMMFF94::SetTypes() |
2659 | 2.33k | { |
2660 | 2.33k | char type[4]; |
2661 | | |
2662 | 2.33k | _mol.SetAtomTypesPerceived(); |
2663 | | |
2664 | | // mark all atoms and bonds as non-aromatic |
2665 | 2.33k | _mol.SetAromaticPerceived(); |
2666 | 2.33k | FOR_BONDS_OF_MOL (bond, _mol) |
2667 | 182k | bond->SetAromatic(false); |
2668 | 2.33k | FOR_ATOMS_OF_MOL (atom, _mol) |
2669 | 225k | atom->SetAromatic(false); |
2670 | | |
2671 | | // It might be needed to run this function more than once... |
2672 | 2.33k | bool done = true; |
2673 | 4.80k | while (done) { |
2674 | 2.47k | done = PerceiveAromatic(); |
2675 | 2.47k | } |
2676 | | |
2677 | 225k | FOR_ATOMS_OF_MOL (atom, _mol) { |
2678 | 225k | snprintf(type, 3, "%d", GetType(&*atom)); |
2679 | 225k | atom->SetType(type); |
2680 | 225k | } |
2681 | | |
2682 | 2.33k | PrintTypes(); |
2683 | | |
2684 | 2.33k | return true; |
2685 | 2.33k | } |
2686 | | |
2687 | | bool OBForceFieldMMFF94::SetupCalculations() |
2688 | 2.33k | { |
2689 | 2.33k | OBFFParameter *parameter; |
2690 | 2.33k | OBAtom *a, *b, *c, *d; |
2691 | 2.33k | int type_a, type_b, type_c, type_d; |
2692 | 2.33k | bool found; |
2693 | 2.33k | int order; |
2694 | | |
2695 | 2.33k | IF_OBFF_LOGLVL_LOW |
2696 | 0 | OBFFLog("\nS E T T I N G U P C A L C U L A T I O N S\n\n"); |
2697 | | |
2698 | | // |
2699 | | // Bond Calculations |
2700 | | // |
2701 | | // no "step-down" procedure |
2702 | | // MMFF part V - page 625 (empirical rule) |
2703 | | // |
2704 | 2.33k | IF_OBFF_LOGLVL_LOW |
2705 | 0 | OBFFLog("SETTING UP BOND CALCULATIONS...\n"); |
2706 | | |
2707 | 2.33k | OBFFBondCalculationMMFF94 bondcalc; |
2708 | 2.33k | int bondtype; |
2709 | | |
2710 | 2.33k | _bondcalculations.clear(); |
2711 | | |
2712 | 2.33k | FOR_BONDS_OF_MOL(bond, _mol) { |
2713 | 1.87k | a = bond->GetBeginAtom(); |
2714 | 1.87k | b = bond->GetEndAtom(); |
2715 | | |
2716 | | // skip this bond if the atoms are ignored |
2717 | 1.87k | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) ) |
2718 | 0 | continue; |
2719 | | |
2720 | | // if there are any groups specified, check if the two bond atoms are in a single intraGroup |
2721 | 1.87k | if (HasGroups()) { |
2722 | 0 | bool validBond = false; |
2723 | 0 | for (unsigned int i=0; i < _intraGroup.size(); ++i) { |
2724 | 0 | if (_intraGroup[i].BitIsSet(a->GetIdx()) && _intraGroup[i].BitIsSet(b->GetIdx())) { |
2725 | 0 | validBond = true; |
2726 | 0 | break; |
2727 | 0 | } |
2728 | 0 | } |
2729 | 0 | if (!validBond) |
2730 | 0 | continue; |
2731 | 0 | } |
2732 | | |
2733 | 1.87k | bondtype = GetBondType(a, b); |
2734 | | |
2735 | 1.87k | parameter = GetTypedParameter2Atom(bondtype, atoi(a->GetType()), atoi(b->GetType()), _ffbondparams); // from mmffbond.par |
2736 | 1.87k | if (parameter == nullptr) { |
2737 | 1.87k | parameter = GetParameter2Atom(a->GetAtomicNum(), b->GetAtomicNum(), _ffbndkparams); // from mmffbndk.par - emperical rules |
2738 | 1.87k | if (parameter == nullptr) { |
2739 | 1.87k | IF_OBFF_LOGLVL_LOW { |
2740 | | // This should never happen |
2741 | 0 | snprintf(_logbuf, BUFF_SIZE, " COULD NOT FIND PARAMETERS FOR BOND %d-%d (IDX)...\n", a->GetIdx(), b->GetIdx()); |
2742 | 0 | OBFFLog(_logbuf); |
2743 | 0 | } |
2744 | 1.87k | return false; |
2745 | 1.87k | } else { |
2746 | 0 | IF_OBFF_LOGLVL_LOW { |
2747 | 0 | snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR BOND STRETCHING %d-%d (IDX)...\n", a->GetIdx(), b->GetIdx()); |
2748 | 0 | OBFFLog(_logbuf); |
2749 | 0 | } |
2750 | |
|
2751 | 0 | double rr, rr2, rr4, rr6; |
2752 | 0 | bondcalc.a = a; |
2753 | 0 | bondcalc.b = b; |
2754 | 0 | bondcalc.r0 = GetRuleBondLength(a, b); |
2755 | |
|
2756 | 0 | rr = parameter->_dpar[0] / bondcalc.r0; // parameter->_dpar[0] = r0-ref |
2757 | 0 | rr2 = rr * rr; |
2758 | 0 | rr4 = rr2 * rr2; |
2759 | 0 | rr6 = rr4 * rr2; |
2760 | |
|
2761 | 0 | bondcalc.kb = parameter->_dpar[1] * rr6; // parameter->_dpar[1] = kb-ref |
2762 | 0 | bondcalc.bt = bondtype; |
2763 | 0 | bondcalc.SetupPointers(); |
2764 | |
|
2765 | 0 | _bondcalculations.push_back(bondcalc); |
2766 | 0 | } |
2767 | 1.87k | } else { |
2768 | 0 | bondcalc.a = a; |
2769 | 0 | bondcalc.b = b; |
2770 | 0 | bondcalc.kb = parameter->_dpar[0]; |
2771 | 0 | bondcalc.r0 = parameter->_dpar[1]; |
2772 | 0 | bondcalc.bt = bondtype; |
2773 | 0 | bondcalc.SetupPointers(); |
2774 | |
|
2775 | 0 | _bondcalculations.push_back(bondcalc); |
2776 | 0 | } |
2777 | 1.87k | } |
2778 | | |
2779 | | // |
2780 | | // Angle Calculations |
2781 | | // |
2782 | | // MMFF part I - page 513 ("step-down" prodedure) |
2783 | | // MMFF part I - page 519 (reference 68 is actually a footnote) |
2784 | | // MMFF part V - page 627 (empirical rule) |
2785 | | // |
2786 | | // First try and find an exact match, if this fails, step down using the equivalences from mmffdef.par |
2787 | | // five-stage protocol: 1-1-1, 2-2-2, 3-2-3, 4-2-4, 5-2-5 |
2788 | | // If this fails, use empirical rules |
2789 | | // Since 1-1-1 = 2-2-2, we will only try 1-1-1 before going to 3-2-3 |
2790 | | // |
2791 | | // Stretch-Bend Calculations |
2792 | | // |
2793 | 457 | IF_OBFF_LOGLVL_LOW |
2794 | 0 | OBFFLog("SETTING UP ANGLE & STRETCH-BEND CALCULATIONS...\n"); |
2795 | | |
2796 | 457 | OBFFAngleCalculationMMFF94 anglecalc; |
2797 | 457 | OBFFStrBndCalculationMMFF94 strbndcalc; |
2798 | 457 | int angletype, strbndtype, bondtype1, bondtype2; |
2799 | | |
2800 | 457 | _anglecalculations.clear(); |
2801 | 457 | _strbndcalculations.clear(); |
2802 | | |
2803 | 457 | FOR_ANGLES_OF_MOL(angle, _mol) { |
2804 | 0 | b = _mol.GetAtom((*angle)[0] + 1); |
2805 | 0 | a = _mol.GetAtom((*angle)[1] + 1); |
2806 | 0 | c = _mol.GetAtom((*angle)[2] + 1); |
2807 | | // Cached AngleData can reference indices that no longer exist. |
2808 | 0 | if (a == nullptr || b == nullptr || c == nullptr) |
2809 | 0 | continue; |
2810 | | |
2811 | 0 | type_a = atoi(a->GetType()); |
2812 | 0 | type_b = atoi(b->GetType()); |
2813 | 0 | type_c = atoi(c->GetType()); |
2814 | | |
2815 | | // skip this angle if the atoms are ignored |
2816 | 0 | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) || _constraints.IsIgnored(c->GetIdx()) ) |
2817 | 0 | continue; |
2818 | | |
2819 | | // if there are any groups specified, check if the three angle atoms are in a single intraGroup |
2820 | 0 | if (HasGroups()) { |
2821 | 0 | bool validAngle = false; |
2822 | 0 | for (unsigned int i=0; i < _intraGroup.size(); ++i) { |
2823 | 0 | if (_intraGroup[i].BitIsSet(a->GetIdx()) && _intraGroup[i].BitIsSet(b->GetIdx()) && |
2824 | 0 | _intraGroup[i].BitIsSet(c->GetIdx())) { |
2825 | 0 | validAngle = true; |
2826 | 0 | break; |
2827 | 0 | } |
2828 | 0 | } |
2829 | 0 | if (!validAngle) |
2830 | 0 | continue; |
2831 | 0 | } |
2832 | | |
2833 | 0 | angletype = GetAngleType(a, b, c); |
2834 | 0 | strbndtype = GetStrBndType(a, b, c); |
2835 | 0 | bondtype1 = GetBondType(a, b); |
2836 | 0 | bondtype2 = GetBondType(b, c); |
2837 | |
|
2838 | 0 | if (HasLinSet(type_b)) { |
2839 | 0 | anglecalc.linear = true; |
2840 | 0 | } else { |
2841 | 0 | anglecalc.linear = false; |
2842 | 0 | } |
2843 | | |
2844 | | // try exact match |
2845 | 0 | parameter = GetTypedParameter3Atom(angletype, type_a, type_b, type_c, _ffangleparams); |
2846 | 0 | if (parameter == nullptr) // try 3-2-3 |
2847 | 0 | parameter = GetTypedParameter3Atom(angletype, EqLvl3(type_a), type_b, EqLvl3(type_c), _ffangleparams); |
2848 | 0 | if (parameter == nullptr) // try 4-2-4 |
2849 | 0 | parameter = GetTypedParameter3Atom(angletype, EqLvl4(type_a), type_b, EqLvl4(type_c), _ffangleparams); |
2850 | 0 | if (parameter == nullptr) // try 5-2-5 |
2851 | 0 | parameter = GetTypedParameter3Atom(angletype, EqLvl5(type_a), type_b, EqLvl5(type_c), _ffangleparams); |
2852 | |
|
2853 | 0 | if (parameter) { |
2854 | 0 | anglecalc.ka = parameter->_dpar[0]; |
2855 | 0 | anglecalc.theta0 = parameter->_dpar[1]; |
2856 | 0 | strbndcalc.theta0 = parameter->_dpar[1]; // ** |
2857 | 0 | } else { |
2858 | 0 | IF_OBFF_LOGLVL_LOW { |
2859 | 0 | snprintf(_logbuf, BUFF_SIZE, " USING DEFAULT ANGLE FOR %d-%d-%d (IDX)...\n", a->GetIdx(), b->GetIdx(), c->GetIdx()); |
2860 | 0 | snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR ANGLE BENDING %d-%d-%d (IDX)...\n", a->GetIdx(), b->GetIdx(), c->GetIdx()); |
2861 | 0 | OBFFLog(_logbuf); |
2862 | 0 | } |
2863 | |
|
2864 | 0 | anglecalc.ka = 0.0; |
2865 | 0 | anglecalc.theta0 = 120.0; |
2866 | |
|
2867 | 0 | if (GetCrd(type_b) == 4) |
2868 | 0 | anglecalc.theta0 = 109.45; |
2869 | |
|
2870 | 0 | if ((GetCrd(type_b) == 2) && b->GetAtomicNum() == OBElements::Oxygen) |
2871 | 0 | anglecalc.theta0 = 105.0; |
2872 | |
|
2873 | 0 | if (b->GetAtomicNum() > 10) |
2874 | 0 | anglecalc.theta0 = 95.0; |
2875 | |
|
2876 | 0 | if (HasLinSet(type_b)) |
2877 | 0 | anglecalc.theta0 = 180.0; |
2878 | |
|
2879 | 0 | if ((GetCrd(type_b) == 3) && (GetVal(type_b) == 3) && !GetMltb(type_b)) { |
2880 | 0 | if (b->GetAtomicNum() == OBElements::Nitrogen) { |
2881 | 0 | anglecalc.theta0 = 107.0; |
2882 | 0 | } else { |
2883 | 0 | anglecalc.theta0 = 92.0; |
2884 | 0 | } |
2885 | 0 | } |
2886 | |
|
2887 | 0 | if (a->IsInRingSize(3) && b->IsInRingSize(3) && c->IsInRingSize(3) && IsInSameRing(a, c)) |
2888 | 0 | anglecalc.theta0 = 60.0; |
2889 | |
|
2890 | 0 | if (a->IsInRingSize(4) && b->IsInRingSize(4) && c->IsInRingSize(4) && IsInSameRing(a, c)) |
2891 | 0 | anglecalc.theta0 = 90.0; |
2892 | |
|
2893 | 0 | strbndcalc.theta0 = anglecalc.theta0; // ** |
2894 | 0 | } |
2895 | | |
2896 | | // empirical rule for 0-b-0 and standard angles |
2897 | 0 | if (anglecalc.ka == 0.0) { |
2898 | 0 | IF_OBFF_LOGLVL_LOW { |
2899 | 0 | snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR ANGLE BENDING FORCE CONSTANT %d-%d-%d (IDX)...\n", a->GetIdx(), b->GetIdx(), c->GetIdx()); |
2900 | 0 | OBFFLog(_logbuf); |
2901 | 0 | } |
2902 | |
|
2903 | 0 | double beta, Za, Zc, Cb, r0ab, r0bc, theta, theta2, D, rr, rr2; |
2904 | 0 | Za = GetZParam(a); |
2905 | 0 | Cb = GetCParam(b); // Fixed typo -- PR#2741658 |
2906 | 0 | Zc = GetZParam(c); |
2907 | |
|
2908 | 0 | r0ab = GetBondLength(a, b); |
2909 | 0 | r0bc = GetBondLength(b, c); |
2910 | 0 | rr = r0ab + r0bc; |
2911 | 0 | rr2 = rr * rr; |
2912 | 0 | D = (r0ab - r0bc) / rr2; |
2913 | |
|
2914 | 0 | theta = anglecalc.theta0; |
2915 | 0 | theta2 = theta * theta; |
2916 | |
|
2917 | 0 | beta = 1.75; |
2918 | 0 | if (a->IsInRingSize(4) && b->IsInRingSize(4) && c->IsInRingSize(4) && IsInSameRing(a, c)) |
2919 | 0 | beta = 0.85 * beta; |
2920 | 0 | if (a->IsInRingSize(3) && b->IsInRingSize(3) && c->IsInRingSize(3) && IsInSameRing(a, c)) |
2921 | 0 | beta = 0.05 * beta; |
2922 | | |
2923 | | // Theta2 is in Degrees^2, but parameters are expecting radians |
2924 | | // PR#2741669 |
2925 | 0 | anglecalc.ka = (beta * Za * Cb * Zc * exp(-2 * D)) / (rr * theta2 * DEG_TO_RAD * DEG_TO_RAD); |
2926 | 0 | } |
2927 | |
|
2928 | 0 | anglecalc.a = a; |
2929 | 0 | anglecalc.b = b; |
2930 | 0 | anglecalc.c = c; |
2931 | 0 | anglecalc.at = angletype; |
2932 | |
|
2933 | 0 | anglecalc.SetupPointers(); |
2934 | 0 | _anglecalculations.push_back(anglecalc); |
2935 | |
|
2936 | 0 | if (anglecalc.linear) |
2937 | 0 | continue; |
2938 | | |
2939 | 0 | parameter = GetTypedParameter3Atom(strbndtype, type_a, type_b, type_c, _ffstrbndparams); |
2940 | 0 | if (parameter == nullptr) { |
2941 | 0 | int rowa, rowb, rowc; |
2942 | | |
2943 | | // This is not a real empirical rule... |
2944 | | //IF_OBFF_LOGLVL_LOW { |
2945 | | // snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR STRETCH-BENDING FORCE CONSTANT %d-%d-%d (IDX)...\n", a->GetIdx(), b->GetIdx(), c->GetIdx()); |
2946 | | // OBFFLog(_logbuf); |
2947 | | //} |
2948 | |
|
2949 | 0 | rowa = GetElementRow(a); |
2950 | 0 | rowb = GetElementRow(b); |
2951 | 0 | rowc = GetElementRow(c); |
2952 | |
|
2953 | 0 | parameter = GetParameter3Atom(rowa, rowb, rowc, _ffdfsbparams); |
2954 | |
|
2955 | 0 | if (parameter == nullptr) { |
2956 | | // This should never happen |
2957 | 0 | IF_OBFF_LOGLVL_LOW { |
2958 | 0 | snprintf(_logbuf, BUFF_SIZE, " COULD NOT FIND PARAMETERS FOR STRETCH-BEND %d-%d-%d (IDX)...\n", a->GetIdx(), b->GetIdx(), c->GetIdx()); |
2959 | 0 | OBFFLog(_logbuf); |
2960 | 0 | } |
2961 | 0 | return false; |
2962 | 0 | } |
2963 | | |
2964 | 0 | if (rowa == parameter->a) { |
2965 | 0 | strbndcalc.kbaABC = parameter->_dpar[0]; |
2966 | 0 | strbndcalc.kbaCBA = parameter->_dpar[1]; |
2967 | 0 | } else { |
2968 | 0 | strbndcalc.kbaABC = parameter->_dpar[1]; |
2969 | 0 | strbndcalc.kbaCBA = parameter->_dpar[0]; |
2970 | 0 | } |
2971 | 0 | } else { |
2972 | 0 | if (type_a == parameter->a) { |
2973 | 0 | strbndcalc.kbaABC = parameter->_dpar[0]; |
2974 | 0 | strbndcalc.kbaCBA = parameter->_dpar[1]; |
2975 | 0 | } else { |
2976 | 0 | strbndcalc.kbaABC = parameter->_dpar[1]; |
2977 | 0 | strbndcalc.kbaCBA = parameter->_dpar[0]; |
2978 | 0 | } |
2979 | 0 | } |
2980 | | |
2981 | 0 | strbndcalc.rab0 = GetBondLength(a, b); |
2982 | 0 | strbndcalc.rbc0 = GetBondLength(b ,c); |
2983 | 0 | strbndcalc.a = a; |
2984 | 0 | strbndcalc.b = b; |
2985 | 0 | strbndcalc.c = c; |
2986 | 0 | strbndcalc.sbt = strbndtype; |
2987 | 0 | strbndcalc.SetupPointers(); |
2988 | | // Set the pointers to addresses in the anglecalc, find the matching bondcalcs and do the same. |
2989 | | // This should improve performance by not calculating all this twice. We could do the same |
2990 | | // for torsion and angles since the bond lengths are calculated for bond stretching first. |
2991 | | //bool found_angle = false; |
2992 | | /* |
2993 | | for (unsigned int ai = 0; ai < _anglecalculations.size(); ++ai) { |
2994 | | if ( (_anglecalculations[ai].a->GetIdx() == a->GetIdx()) && |
2995 | | (_anglecalculations[ai].b->GetIdx() == b->GetIdx()) && |
2996 | | (_anglecalculations[ai].c->GetIdx() == c->GetIdx()) ) { |
2997 | | strbndcalc.theta = &(_anglecalculations[ai].theta); |
2998 | | strbndcalc.force_abc_a = _anglecalculations[ai].force_a; |
2999 | | strbndcalc.force_abc_b = _anglecalculations[ai].force_b; |
3000 | | strbndcalc.force_abc_c = _anglecalculations[ai].force_c; |
3001 | | found_angle = true; |
3002 | | break; |
3003 | | } else if ( (_anglecalculations[ai].a->GetIdx() == c->GetIdx()) && |
3004 | | (_anglecalculations[ai].b->GetIdx() == b->GetIdx()) && |
3005 | | (_anglecalculations[ai].c->GetIdx() == a->GetIdx()) ) { |
3006 | | strbndcalc.theta = &(_anglecalculations[ai].theta); |
3007 | | strbndcalc.force_abc_a = _anglecalculations[ai].force_c; |
3008 | | strbndcalc.force_abc_b = _anglecalculations[ai].force_b; |
3009 | | strbndcalc.force_abc_c = _anglecalculations[ai].force_a; |
3010 | | found_angle = true; |
3011 | | break; |
3012 | | } |
3013 | | } |
3014 | | */ |
3015 | | |
3016 | | /* |
3017 | | vector<OBFFAngleCalculationMMFF94>::iterator ai; |
3018 | | for (ai = _anglecalculations.begin(); ai != _anglecalculations.end(); ++ai) { |
3019 | | if ( (((*ai).a)->GetIdx() == a->GetIdx()) && (((*ai).b)->GetIdx() == b->GetIdx()) && (((*ai).c)->GetIdx() == c->GetIdx()) ) { |
3020 | | strbndcalc.theta = (*ai).theta; |
3021 | | cout << "theta prt = " << (*ai).theta << endl; |
3022 | | cout << "delta prt = " << &((*ai).delta) << endl; |
3023 | | cout << "GetThetaPointer = " << ai->GetThetaPointer() << endl; |
3024 | | strbndcalc.force_abc_a = (*ai).force_a; |
3025 | | strbndcalc.force_abc_b = (*ai).force_b; |
3026 | | strbndcalc.force_abc_c = (*ai).force_c; |
3027 | | found_angle = true; |
3028 | | break; |
3029 | | } else if ( (((*ai).a)->GetIdx() == c->GetIdx()) && (((*ai).b)->GetIdx() == b->GetIdx()) && (((*ai).c)->GetIdx() == a->GetIdx()) ) { |
3030 | | strbndcalc.theta = (*ai).theta; |
3031 | | strbndcalc.force_abc_a = (*ai).force_c; |
3032 | | strbndcalc.force_abc_b = (*ai).force_b; |
3033 | | strbndcalc.force_abc_c = (*ai).force_a; |
3034 | | found_angle = true; |
3035 | | break; |
3036 | | } |
3037 | | } |
3038 | | if (!found_angle) // didn't find matching angle, shouldn't happen, but continue to be safe |
3039 | | continue; |
3040 | | |
3041 | | |
3042 | | bool found_rab = false; |
3043 | | bool found_rbc = false; |
3044 | | vector<OBFFBondCalculationMMFF94>::iterator bi; |
3045 | | for (bi = _bondcalculations.begin(); bi != _bondcalculations.end(); ++bi) { |
3046 | | // find rab |
3047 | | if ( (((*bi).a)->GetIdx() == a->GetIdx()) && (((*bi).b)->GetIdx() == b->GetIdx()) ) { |
3048 | | strbndcalc.rab = &((*bi).rab); |
3049 | | strbndcalc.force_ab_a = (*bi).force_a; |
3050 | | strbndcalc.force_ab_b = (*bi).force_b; |
3051 | | found_rab = true; |
3052 | | } else if ( (((*bi).a)->GetIdx() == b->GetIdx()) && (((*bi).b)->GetIdx() == a->GetIdx()) ) { |
3053 | | strbndcalc.rab = &((*bi).rab); |
3054 | | strbndcalc.force_ab_a = (*bi).force_b; |
3055 | | strbndcalc.force_ab_b = (*bi).force_a; |
3056 | | found_rab = true; |
3057 | | } |
3058 | | // find rbc |
3059 | | if ( (((*bi).a)->GetIdx() == b->GetIdx()) && (((*bi).b)->GetIdx() == c->GetIdx()) ) { |
3060 | | strbndcalc.rbc = &(bondcalc.rab); |
3061 | | strbndcalc.force_ab_a = (*bi).force_a; |
3062 | | strbndcalc.force_ab_b = (*bi).force_b; |
3063 | | found_rbc = true; |
3064 | | } else if ( (((*bi).a)->GetIdx() == c->GetIdx()) && (((*bi).b)->GetIdx() == b->GetIdx()) ) { |
3065 | | strbndcalc.rbc = &(bondcalc.rab); |
3066 | | strbndcalc.force_ab_a = (*bi).force_b; |
3067 | | strbndcalc.force_ab_b = (*bi).force_a; |
3068 | | found_rbc = true; |
3069 | | } |
3070 | | |
3071 | | if (found_rab && found_rbc) |
3072 | | break; |
3073 | | } |
3074 | | if (!found_rab || !found_rbc) // didn't find matching bond, or atoms overlap |
3075 | | continue; |
3076 | | */ |
3077 | 0 | _strbndcalculations.push_back(strbndcalc); |
3078 | |
|
3079 | 0 | } |
3080 | | |
3081 | | // |
3082 | | // Torsion Calculations |
3083 | | // |
3084 | | // MMFF part I - page 513 ("step-down" prodedure) |
3085 | | // MMFF part I - page 519 (reference 68 is actually a footnote) |
3086 | | // MMFF part IV - page 631 (empirical rule) |
3087 | | // |
3088 | | // First try and find an exact match, if this fails, step down using the equivalences from mmffdef.par |
3089 | | // five-stage protocol: 1-1-1-1, 2-2-2-2, 3-2-2-5, 5-2-2-3, 5-2-2-5 |
3090 | | // If this fails, use empirical rules |
3091 | | // Since 1-1-1-1 = 2-2-2-2, we will only try 1-1-1-1 before going to 3-2-2-5 |
3092 | | // |
3093 | 457 | IF_OBFF_LOGLVL_LOW |
3094 | 0 | OBFFLog("SETTING UP TORSION CALCULATIONS...\n"); |
3095 | | |
3096 | 457 | OBFFTorsionCalculationMMFF94 torsioncalc; |
3097 | 457 | int torsiontype; |
3098 | | |
3099 | 457 | _torsioncalculations.clear(); |
3100 | | |
3101 | 457 | FOR_TORSIONS_OF_MOL(t, _mol) { |
3102 | 0 | a = _mol.GetAtom((*t)[0] + 1); |
3103 | 0 | b = _mol.GetAtom((*t)[1] + 1); |
3104 | 0 | c = _mol.GetAtom((*t)[2] + 1); |
3105 | 0 | d = _mol.GetAtom((*t)[3] + 1); |
3106 | | // Cached TorsionData can reference indices that no longer exist. |
3107 | 0 | if (a == nullptr || b == nullptr || c == nullptr || d == nullptr) |
3108 | 0 | continue; |
3109 | | |
3110 | 0 | type_a = atoi(a->GetType()); |
3111 | 0 | type_b = atoi(b->GetType()); |
3112 | 0 | type_c = atoi(c->GetType()); |
3113 | 0 | type_d = atoi(d->GetType()); |
3114 | | |
3115 | | // skip this torsion if the atoms are ignored |
3116 | 0 | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) || |
3117 | 0 | _constraints.IsIgnored(c->GetIdx()) || _constraints.IsIgnored(d->GetIdx()) ) |
3118 | 0 | continue; |
3119 | | |
3120 | | // if there are any groups specified, check if the four torsion atoms are in a single intraGroup |
3121 | 0 | if (HasGroups()) { |
3122 | 0 | bool validTorsion = false; |
3123 | 0 | for (unsigned int i=0; i < _intraGroup.size(); ++i) { |
3124 | 0 | if (_intraGroup[i].BitIsSet(a->GetIdx()) && _intraGroup[i].BitIsSet(b->GetIdx()) && |
3125 | 0 | _intraGroup[i].BitIsSet(c->GetIdx()) && _intraGroup[i].BitIsSet(d->GetIdx())) { |
3126 | 0 | validTorsion = true; |
3127 | 0 | break; |
3128 | 0 | } |
3129 | 0 | } |
3130 | 0 | if (!validTorsion) |
3131 | 0 | continue; |
3132 | 0 | } |
3133 | | |
3134 | 0 | torsiontype = GetTorsionType(a, b, c, d); |
3135 | | // CXT = MC*(J*MA**3 + K*MA**2 + I*MA + L) + TTijkl MC = 6, MA = 136 |
3136 | 0 | order = (type_c*2515456 + type_b*18496 + type_d*136 + type_a) |
3137 | 0 | - (type_b*2515456 + type_c*18496 + type_a*136 + type_d); |
3138 | |
|
3139 | 0 | if (order >= 0) { |
3140 | | // try exact match |
3141 | 0 | parameter = GetTypedParameter4Atom(torsiontype, type_a, type_b, type_c, type_d, _fftorsionparams); |
3142 | 0 | if (parameter == nullptr) // try 3-2-2-5 |
3143 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl3(type_a), type_b, type_c, EqLvl5(type_d), _fftorsionparams); |
3144 | 0 | if (parameter == nullptr) // try 5-2-2-3 |
3145 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl5(type_a), type_b, type_c, EqLvl3(type_d), _fftorsionparams); |
3146 | 0 | if (parameter == nullptr) // try 5-2-2-5 |
3147 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl5(type_a), type_b, type_c, EqLvl5(type_d), _fftorsionparams); |
3148 | 0 | } else { |
3149 | | // try exact match |
3150 | 0 | parameter = GetTypedParameter4Atom(torsiontype, type_d, type_c, type_b, type_a, _fftorsionparams); |
3151 | 0 | if (parameter == nullptr) // try 3-2-2-5 |
3152 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl3(type_d), type_c, type_b, EqLvl5(type_a), _fftorsionparams); |
3153 | 0 | if (parameter == nullptr) // try 5-2-2-3 |
3154 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl5(type_d), type_c, type_b, EqLvl3(type_a), _fftorsionparams); |
3155 | 0 | if (parameter == nullptr) // try 5-2-2-5 |
3156 | 0 | parameter = GetTypedParameter4Atom(torsiontype, EqLvl5(type_d), type_c, type_b, EqLvl5(type_a), _fftorsionparams); |
3157 | 0 | } |
3158 | |
|
3159 | 0 | if (parameter) { |
3160 | 0 | torsioncalc.v1 = parameter->_dpar[0]; |
3161 | 0 | torsioncalc.v2 = parameter->_dpar[1]; |
3162 | 0 | torsioncalc.v3 = parameter->_dpar[2]; |
3163 | 0 | } else { |
3164 | 0 | bool found_rule = false; |
3165 | | |
3166 | | //IF_OBFF_LOGLVL_LOW { |
3167 | | // snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR TORSION FORCE CONSTANT %d-%d-%d-%d (IDX)...\n", |
3168 | | // a->GetIdx(), b->GetIdx(), c->GetIdx(), d->GetIdx()); |
3169 | | // OBFFLog(_logbuf); |
3170 | | //} |
3171 | | |
3172 | | // rule (a) page 631 |
3173 | 0 | if (HasLinSet(type_b) || HasLinSet(type_c)) |
3174 | 0 | continue; |
3175 | | |
3176 | | // rule (b) page 631 |
3177 | 0 | OBBond *bc_bond = b->GetBond(c); |
3178 | 0 | if (bc_bond != nullptr && bc_bond->IsAromatic()) { |
3179 | 0 | double Ub, Uc, pi_bc, beta; |
3180 | 0 | Ub = GetUParam(b); |
3181 | 0 | Uc = GetUParam(c); |
3182 | |
|
3183 | 0 | if (!HasPilpSet(type_b) && !HasPilpSet(type_c)) |
3184 | 0 | pi_bc = 0.5; |
3185 | 0 | else |
3186 | 0 | pi_bc = 0.3; |
3187 | |
|
3188 | 0 | if (((GetVal(type_b) == 3) && (GetVal(type_c) == 4)) || |
3189 | 0 | ((GetVal(type_b) == 4) && (GetVal(type_c) == 3))) |
3190 | 0 | beta = 3.0; |
3191 | 0 | else |
3192 | 0 | beta = 6.0; |
3193 | |
|
3194 | 0 | torsioncalc.v1 = 0.0; |
3195 | 0 | torsioncalc.v2 = beta * pi_bc * sqrt(Ub * Uc); |
3196 | 0 | torsioncalc.v3 = 0.0; |
3197 | 0 | found_rule = true; |
3198 | 0 | } else { |
3199 | | // rule (c) page 631 |
3200 | 0 | double Ub, Uc, pi_bc, beta; |
3201 | 0 | Ub = GetUParam(b); |
3202 | 0 | Uc = GetUParam(c); |
3203 | 0 | OBBond *bond = a->GetBond(b); |
3204 | 0 | if (bond != nullptr && ((GetMltb(type_b) == 2) && (GetMltb(type_c) == 2)) && !bond->IsAromatic() && bond->GetBondOrder() == 2) |
3205 | 0 | pi_bc = 1.0; |
3206 | 0 | else |
3207 | 0 | pi_bc = 0.4; |
3208 | |
|
3209 | 0 | beta = 6.0; |
3210 | 0 | torsioncalc.v1 = 0.0; |
3211 | 0 | torsioncalc.v2 = beta * pi_bc * sqrt(Ub * Uc); |
3212 | 0 | torsioncalc.v3 = 0.0; |
3213 | 0 | found_rule = true; |
3214 | 0 | } |
3215 | | |
3216 | | // rule (d) page 632 |
3217 | 0 | if (!found_rule) |
3218 | 0 | if (((GetCrd(type_b) == 4) && (GetCrd(type_c) == 4))) { |
3219 | 0 | double Vb, Vc; |
3220 | 0 | Vb = GetVParam(b); |
3221 | 0 | Vc = GetVParam(c); |
3222 | |
|
3223 | 0 | torsioncalc.v1 = 0.0; |
3224 | 0 | torsioncalc.v2 = 0.0; |
3225 | 0 | torsioncalc.v3 = sqrt(Vb * Vc) / 9.0; |
3226 | 0 | found_rule = true; |
3227 | 0 | } |
3228 | | |
3229 | | // rule (e) page 632 |
3230 | 0 | if (!found_rule) |
3231 | 0 | if (((GetCrd(type_b) == 4) && (GetCrd(type_c) != 4))) { |
3232 | 0 | if (GetCrd(type_c) == 3) // case (1) |
3233 | 0 | if ((GetVal(type_c) == 4) || (GetVal(type_c) == 34) || (GetMltb(type_c) != 0)) |
3234 | 0 | continue; |
3235 | | |
3236 | 0 | if (GetCrd(type_c) == 2) // case (2) |
3237 | 0 | if ((GetVal(type_c) == 3) || (GetMltb(type_c) != 0)) |
3238 | 0 | continue; |
3239 | | |
3240 | | // case (3) saturated bonds -- see rule (h) |
3241 | 0 | } |
3242 | | |
3243 | | // rule (f) page 632 |
3244 | 0 | if (!found_rule) |
3245 | 0 | if (((GetCrd(type_b) != 4) && (GetCrd(type_c) == 4))) { |
3246 | 0 | if (GetCrd(type_b) == 3) // case (1) |
3247 | 0 | if ((GetVal(type_b) == 4) || (GetVal(type_b) == 34) || (GetMltb(type_b) != 0)) |
3248 | 0 | continue; |
3249 | | |
3250 | 0 | if (GetCrd(type_b) == 2) // case (2) |
3251 | 0 | if ((GetVal(type_b) == 3) || (GetMltb(type_b) != 0)) |
3252 | 0 | continue; |
3253 | | |
3254 | | // case (3) saturated bonds |
3255 | 0 | } |
3256 | | |
3257 | | // rule (g) page 632 |
3258 | 0 | if (!found_rule) { |
3259 | 0 | OBBond *bond = b->GetBond(c); |
3260 | 0 | if (bond != nullptr && !bond->IsAromatic() && bond->GetBondOrder() == 1 && ( |
3261 | 0 | (GetMltb(type_b) && GetMltb(type_c)) || |
3262 | 0 | (GetMltb(type_b) && HasPilpSet(type_c)) || |
3263 | 0 | (GetMltb(type_c) && HasPilpSet(type_b)))) { |
3264 | 0 | if (HasPilpSet(type_b) && HasPilpSet(type_c)) // case (1) |
3265 | 0 | continue; |
3266 | | |
3267 | 0 | double Ub, Uc, pi_bc, beta; |
3268 | 0 | Ub = GetUParam(b); |
3269 | 0 | Uc = GetUParam(c); |
3270 | 0 | beta = 6.0; |
3271 | |
|
3272 | 0 | if (HasPilpSet(type_b) && GetMltb(type_c)) { // case (2) |
3273 | 0 | if (GetMltb(type_c) == 1) |
3274 | 0 | pi_bc = 0.5; |
3275 | 0 | else if ((GetElementRow(b) == 1) && (GetElementRow(c) == 1)) |
3276 | 0 | pi_bc = 0.3; |
3277 | 0 | else |
3278 | 0 | pi_bc = 0.15; |
3279 | 0 | found_rule = true; |
3280 | 0 | } |
3281 | |
|
3282 | 0 | if (HasPilpSet(type_c) && GetMltb(type_b)) { // case (3) |
3283 | 0 | if (GetMltb(type_b) == 1) |
3284 | 0 | pi_bc = 0.5; |
3285 | 0 | else if ((GetElementRow(b) == 1) && (GetElementRow(c) == 1)) |
3286 | 0 | pi_bc = 0.3; |
3287 | 0 | else |
3288 | 0 | pi_bc = 0.15; |
3289 | 0 | found_rule = true; |
3290 | 0 | } |
3291 | |
|
3292 | 0 | if (!found_rule) |
3293 | 0 | if (((GetMltb(type_b) == 1) || (GetMltb(type_c) == 1)) && (b->GetAtomicNum() != OBElements::Carbon || c->GetAtomicNum() != OBElements::Carbon)) { |
3294 | 0 | pi_bc = 0.4; |
3295 | 0 | found_rule = true; |
3296 | 0 | } |
3297 | |
|
3298 | 0 | if (!found_rule) |
3299 | 0 | pi_bc = 0.15; |
3300 | |
|
3301 | 0 | torsioncalc.v1 = 0.0; |
3302 | 0 | torsioncalc.v2 = beta * pi_bc * sqrt(Ub * Uc); |
3303 | 0 | torsioncalc.v3 = 0.0; |
3304 | 0 | found_rule = true; |
3305 | 0 | } |
3306 | 0 | } |
3307 | | |
3308 | | // rule (h) page 632 |
3309 | 0 | if (!found_rule) { |
3310 | 0 | if ((b->GetAtomicNum() == OBElements::Oxygen || b->GetAtomicNum() == OBElements::Sulfur) && (c->GetAtomicNum() == OBElements::Oxygen || c->GetAtomicNum() == OBElements::Sulfur)) { |
3311 | 0 | double Wb, Wc; |
3312 | |
|
3313 | 0 | if (b->GetAtomicNum() == OBElements::Oxygen) { |
3314 | 0 | Wb = 2.0; |
3315 | 0 | } |
3316 | 0 | else { |
3317 | 0 | Wb = 8.0; |
3318 | 0 | } |
3319 | |
|
3320 | 0 | if (c->GetAtomicNum() == OBElements::Oxygen) { |
3321 | 0 | Wc = 2.0; |
3322 | 0 | } |
3323 | 0 | else { |
3324 | 0 | Wc = 8.0; |
3325 | 0 | } |
3326 | |
|
3327 | 0 | torsioncalc.v1 = 0.0; |
3328 | 0 | torsioncalc.v2 = -sqrt(Wb * Wc); |
3329 | 0 | torsioncalc.v3 = 0.0; |
3330 | 0 | } else { |
3331 | 0 | double Vb, Vc, Nbc; |
3332 | 0 | Vb = GetVParam(b); |
3333 | 0 | Vc = GetVParam(c); |
3334 | |
|
3335 | 0 | IF_OBFF_LOGLVL_LOW { |
3336 | 0 | snprintf(_logbuf, BUFF_SIZE, " USING EMPIRICAL RULE FOR TORSION FORCE CONSTANT %d-%d-%d-%d (IDX)...\n", |
3337 | 0 | a->GetIdx(), b->GetIdx(), c->GetIdx(), d->GetIdx()); |
3338 | 0 | OBFFLog(_logbuf); |
3339 | 0 | } |
3340 | |
|
3341 | 0 | Nbc = GetCrd(type_b) * GetCrd(type_c); |
3342 | |
|
3343 | 0 | torsioncalc.v1 = 0.0; |
3344 | 0 | torsioncalc.v2 = 0.0; |
3345 | 0 | torsioncalc.v3 = sqrt(Vb * Vc) / Nbc; |
3346 | 0 | } |
3347 | 0 | } |
3348 | 0 | } |
3349 | | |
3350 | 0 | torsioncalc.a = a; |
3351 | 0 | torsioncalc.b = b; |
3352 | 0 | torsioncalc.c = c; |
3353 | 0 | torsioncalc.d = d; |
3354 | 0 | torsioncalc.SetupPointers(); |
3355 | 0 | torsioncalc.tt = torsiontype; |
3356 | |
|
3357 | 0 | _torsioncalculations.push_back(torsioncalc); |
3358 | 0 | } |
3359 | | |
3360 | | // |
3361 | | // Out-Of-Plane Calculations |
3362 | | // |
3363 | 457 | IF_OBFF_LOGLVL_LOW |
3364 | 0 | OBFFLog("SETTING UP OOP CALCULATIONS...\n"); |
3365 | | |
3366 | 457 | OBFFOOPCalculationMMFF94 oopcalc; |
3367 | | |
3368 | 457 | _oopcalculations.clear(); |
3369 | | |
3370 | 10.2k | FOR_ATOMS_OF_MOL(atom, _mol) { |
3371 | 10.2k | b = (OBAtom*) &*atom; |
3372 | | |
3373 | 10.2k | found = false; |
3374 | | |
3375 | 10.2k | type_b = atoi(b->GetType()); |
3376 | | |
3377 | 10.2k | for (unsigned int idx=0; idx < _ffoopparams.size(); idx++) { |
3378 | 0 | if (type_b == _ffoopparams[idx].b) { |
3379 | 0 | a = nullptr; |
3380 | 0 | c = nullptr; |
3381 | 0 | d = nullptr; |
3382 | |
|
3383 | 0 | FOR_NBORS_OF_ATOM(nbr, b) { |
3384 | 0 | if (a ==nullptr) |
3385 | 0 | a = (OBAtom*) &*nbr; |
3386 | 0 | else if (c == nullptr) |
3387 | 0 | c = (OBAtom*) &*nbr; |
3388 | 0 | else |
3389 | 0 | d = (OBAtom*) &*nbr; |
3390 | 0 | } |
3391 | |
|
3392 | 0 | if (a == nullptr || c == nullptr || d == nullptr) |
3393 | 0 | break; |
3394 | | |
3395 | 0 | type_a = atoi(a->GetType()); |
3396 | 0 | type_c = atoi(c->GetType()); |
3397 | 0 | type_d = atoi(d->GetType()); |
3398 | | |
3399 | | // skip this oop if the atoms are ignored |
3400 | 0 | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) || |
3401 | 0 | _constraints.IsIgnored(c->GetIdx()) || _constraints.IsIgnored(d->GetIdx()) ) |
3402 | 0 | continue; |
3403 | | |
3404 | | // if there are any groups specified, check if the four oop atoms are in a single intraGroup |
3405 | 0 | if (HasGroups()) { |
3406 | 0 | bool validOOP = false; |
3407 | 0 | for (unsigned int i=0; i < _intraGroup.size(); ++i) { |
3408 | 0 | if (_intraGroup[i].BitIsSet(a->GetIdx()) && _intraGroup[i].BitIsSet(b->GetIdx()) && |
3409 | 0 | _intraGroup[i].BitIsSet(c->GetIdx()) && _intraGroup[i].BitIsSet(d->GetIdx())) { |
3410 | 0 | validOOP = true; |
3411 | 0 | break; |
3412 | 0 | } |
3413 | 0 | } |
3414 | 0 | if (!validOOP) |
3415 | 0 | continue; |
3416 | 0 | } |
3417 | | |
3418 | 0 | if (((type_a == _ffoopparams[idx].a) && (type_c == _ffoopparams[idx].c) && (type_d == _ffoopparams[idx].d)) || |
3419 | 0 | ((type_c == _ffoopparams[idx].a) && (type_a == _ffoopparams[idx].c) && (type_d == _ffoopparams[idx].d)) || |
3420 | 0 | ((type_c == _ffoopparams[idx].a) && (type_d == _ffoopparams[idx].c) && (type_a == _ffoopparams[idx].d)) || |
3421 | 0 | ((type_d == _ffoopparams[idx].a) && (type_c == _ffoopparams[idx].c) && (type_a == _ffoopparams[idx].d)) || |
3422 | 0 | ((type_a == _ffoopparams[idx].a) && (type_d == _ffoopparams[idx].c) && (type_c == _ffoopparams[idx].d)) || |
3423 | 0 | ((type_d == _ffoopparams[idx].a) && (type_a == _ffoopparams[idx].c) && (type_c == _ffoopparams[idx].d))) |
3424 | 0 | { |
3425 | 0 | found = true; |
3426 | |
|
3427 | 0 | oopcalc.koop = _ffoopparams[idx]._dpar[0]; |
3428 | | |
3429 | | // A-B-CD || C-B-AD PLANE = ABC |
3430 | 0 | oopcalc.a = a; |
3431 | 0 | oopcalc.b = b; |
3432 | 0 | oopcalc.c = c; |
3433 | 0 | oopcalc.d = d; |
3434 | |
|
3435 | 0 | oopcalc.SetupPointers(); |
3436 | 0 | _oopcalculations.push_back(oopcalc); |
3437 | | |
3438 | | // C-B-DA || D-B-CA PLANE BCD |
3439 | 0 | oopcalc.a = d; |
3440 | 0 | oopcalc.d = a; |
3441 | |
|
3442 | 0 | oopcalc.SetupPointers(); |
3443 | 0 | _oopcalculations.push_back(oopcalc); |
3444 | | |
3445 | | // A-B-DC || D-B-AC PLANE ABD |
3446 | 0 | oopcalc.a = a; |
3447 | 0 | oopcalc.c = d; |
3448 | 0 | oopcalc.d = c; |
3449 | |
|
3450 | 0 | oopcalc.SetupPointers(); |
3451 | 0 | _oopcalculations.push_back(oopcalc); |
3452 | 0 | } |
3453 | |
|
3454 | 0 | if ((_ffoopparams[idx].a == 0) && (_ffoopparams[idx].c == 0) && (_ffoopparams[idx].d == 0) && !found) // *-XX-*-* |
3455 | 0 | { |
3456 | 0 | oopcalc.koop = _ffoopparams[idx]._dpar[0]; |
3457 | | |
3458 | | // A-B-CD || C-B-AD PLANE = ABC |
3459 | 0 | oopcalc.a = a; |
3460 | 0 | oopcalc.b = b; |
3461 | 0 | oopcalc.c = c; |
3462 | 0 | oopcalc.d = d; |
3463 | |
|
3464 | 0 | oopcalc.SetupPointers(); |
3465 | 0 | _oopcalculations.push_back(oopcalc); |
3466 | | |
3467 | | // C-B-DA || D-B-CA PLANE BCD |
3468 | 0 | oopcalc.a = d; |
3469 | 0 | oopcalc.d = a; |
3470 | |
|
3471 | 0 | oopcalc.SetupPointers(); |
3472 | 0 | _oopcalculations.push_back(oopcalc); |
3473 | | |
3474 | | // A-B-DC || D-B-AC PLANE ABD |
3475 | 0 | oopcalc.a = a; |
3476 | 0 | oopcalc.c = d; |
3477 | 0 | oopcalc.d = c; |
3478 | |
|
3479 | 0 | oopcalc.SetupPointers(); |
3480 | 0 | _oopcalculations.push_back(oopcalc); |
3481 | 0 | } |
3482 | 0 | } |
3483 | 0 | } |
3484 | 10.2k | } |
3485 | | |
3486 | | // |
3487 | | // VDW Calculations |
3488 | | // |
3489 | 457 | IF_OBFF_LOGLVL_LOW |
3490 | 0 | OBFFLog("SETTING UP VAN DER WAALS CALCULATIONS...\n"); |
3491 | | |
3492 | 457 | OBFFVDWCalculationMMFF94 vdwcalc; |
3493 | | |
3494 | 457 | _vdwcalculations.clear(); |
3495 | | |
3496 | 457 | int pairIndex = -1; |
3497 | 457 | FOR_PAIRS_OF_MOL(p, _mol) { |
3498 | 100 | ++pairIndex; |
3499 | 100 | a = _mol.GetAtom((*p)[0]); |
3500 | 100 | b = _mol.GetAtom((*p)[1]); |
3501 | | |
3502 | | // skip this vdw if the atoms are ignored |
3503 | 100 | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) ) |
3504 | 0 | continue; |
3505 | | |
3506 | | // if there are any groups specified, check if the two atoms are in a single _interGroup or if |
3507 | | // two two atoms are in one of the _interGroups pairs. |
3508 | 100 | if (HasGroups()) { |
3509 | 0 | bool validVDW = false; |
3510 | 0 | for (unsigned int i=0; i < _interGroup.size(); ++i) { |
3511 | 0 | if (_interGroup[i].BitIsSet(a->GetIdx()) && _interGroup[i].BitIsSet(b->GetIdx())) { |
3512 | 0 | validVDW = true; |
3513 | 0 | break; |
3514 | 0 | } |
3515 | 0 | } |
3516 | 0 | if (!validVDW) { |
3517 | 0 | for (unsigned int i=0; i < _interGroups.size(); ++i) { |
3518 | 0 | if (_interGroups[i].first.BitIsSet(a->GetIdx()) && _interGroups[i].second.BitIsSet(b->GetIdx())) { |
3519 | 0 | validVDW = true; |
3520 | 0 | break; |
3521 | 0 | } |
3522 | 0 | if (_interGroups[i].first.BitIsSet(b->GetIdx()) && _interGroups[i].second.BitIsSet(a->GetIdx())) { |
3523 | 0 | validVDW = true; |
3524 | 0 | break; |
3525 | 0 | } |
3526 | 0 | } |
3527 | 0 | } |
3528 | |
|
3529 | 0 | if (!validVDW) |
3530 | 0 | continue; |
3531 | 0 | } |
3532 | | |
3533 | 100 | OBFFParameter *parameter_a, *parameter_b; |
3534 | 100 | parameter_a = GetParameter1Atom(atoi(a->GetType()), _ffvdwparams); |
3535 | 100 | parameter_b = GetParameter1Atom(atoi(b->GetType()), _ffvdwparams); |
3536 | 100 | if (parameter_a == nullptr || parameter_b == nullptr) { |
3537 | 100 | IF_OBFF_LOGLVL_LOW { |
3538 | 0 | snprintf(_logbuf, BUFF_SIZE, " COULD NOT FIND VAN DER WAALS PARAMETERS FOR %d-%d (IDX)...\n", a->GetIdx(), b->GetIdx()); |
3539 | 0 | OBFFLog(_logbuf); |
3540 | 0 | } |
3541 | | |
3542 | 100 | return false; |
3543 | 100 | } |
3544 | | |
3545 | 0 | vdwcalc.a = a; |
3546 | 0 | vdwcalc.alpha_a = parameter_a->_dpar[0]; |
3547 | 0 | vdwcalc.Na = parameter_a->_dpar[1]; |
3548 | 0 | vdwcalc.Aa = parameter_a->_dpar[2]; |
3549 | 0 | vdwcalc.Ga = parameter_a->_dpar[3]; |
3550 | 0 | vdwcalc.aDA = parameter_a->_ipar[0]; |
3551 | |
|
3552 | 0 | vdwcalc.b = b; |
3553 | 0 | vdwcalc.alpha_b = parameter_b->_dpar[0]; |
3554 | 0 | vdwcalc.Nb = parameter_b->_dpar[1]; |
3555 | 0 | vdwcalc.Ab = parameter_b->_dpar[2]; |
3556 | 0 | vdwcalc.Gb = parameter_b->_dpar[3]; |
3557 | 0 | vdwcalc.bDA = parameter_b->_ipar[0]; |
3558 | | |
3559 | | //these calculations only need to be done once for each pair, |
3560 | | //we do them now and save them for later use |
3561 | 0 | double R_AA, R_BB, R_AB6, g_AB, g_AB2; |
3562 | 0 | double R_AB2, R_AB4, /*R_AB7,*/ sqrt_a, sqrt_b; |
3563 | |
|
3564 | 0 | R_AA = vdwcalc.Aa * pow(vdwcalc.alpha_a, 0.25); |
3565 | 0 | R_BB = vdwcalc.Ab * pow(vdwcalc.alpha_b, 0.25); |
3566 | 0 | sqrt_a = sqrt(vdwcalc.alpha_a / vdwcalc.Na); |
3567 | 0 | sqrt_b = sqrt(vdwcalc.alpha_b / vdwcalc.Nb); |
3568 | |
|
3569 | 0 | if (vdwcalc.aDA == 1) { // hydrogen bond donor |
3570 | 0 | vdwcalc.R_AB = 0.5 * (R_AA + R_BB); |
3571 | 0 | R_AB2 = vdwcalc.R_AB * vdwcalc.R_AB; |
3572 | 0 | R_AB4 = R_AB2 * R_AB2; |
3573 | 0 | R_AB6 = R_AB4 * R_AB2; |
3574 | |
|
3575 | 0 | if (vdwcalc.bDA == 2) { // hydrogen bond acceptor |
3576 | 0 | vdwcalc.epsilon = 0.5 * (181.16 * vdwcalc.Ga * vdwcalc.Gb * vdwcalc.alpha_a * vdwcalc.alpha_b) / (sqrt_a + sqrt_b) * (1.0 / R_AB6); |
3577 | | // R_AB is scaled to 0.8 for D-A interactions. The value used in the calculation of epsilon is not scaled. |
3578 | 0 | vdwcalc.R_AB = 0.8 * vdwcalc.R_AB; |
3579 | 0 | } else |
3580 | 0 | vdwcalc.epsilon = (181.16 * vdwcalc.Ga * vdwcalc.Gb * vdwcalc.alpha_a * vdwcalc.alpha_b) / (sqrt_a + sqrt_b) * (1.0 / R_AB6); |
3581 | |
|
3582 | 0 | R_AB2 = vdwcalc.R_AB * vdwcalc.R_AB; |
3583 | 0 | R_AB4 = R_AB2 * R_AB2; |
3584 | 0 | R_AB6 = R_AB4 * R_AB2; |
3585 | 0 | vdwcalc.R_AB7 = R_AB6 * vdwcalc.R_AB; |
3586 | 0 | } else if (vdwcalc.bDA == 1) { // hydrogen bond donor |
3587 | 0 | vdwcalc.R_AB = 0.5 * (R_AA + R_BB); |
3588 | 0 | R_AB2 = vdwcalc.R_AB * vdwcalc.R_AB; |
3589 | 0 | R_AB4 = R_AB2 * R_AB2; |
3590 | 0 | R_AB6 = R_AB4 * R_AB2; |
3591 | |
|
3592 | 0 | if (vdwcalc.aDA == 2) { // hydrogen bond acceptor |
3593 | 0 | vdwcalc.epsilon = 0.5 * (181.16 * vdwcalc.Ga * vdwcalc.Gb * vdwcalc.alpha_a * vdwcalc.alpha_b) / (sqrt_a + sqrt_b) * (1.0 / R_AB6); |
3594 | | // R_AB is scaled to 0.8 for D-A interactions. The value used in the calculation of epsilon is not scaled. |
3595 | 0 | vdwcalc.R_AB = 0.8 * vdwcalc.R_AB; |
3596 | 0 | } else |
3597 | 0 | vdwcalc.epsilon = (181.16 * vdwcalc.Ga * vdwcalc.Gb * vdwcalc.alpha_a * vdwcalc.alpha_b) / (sqrt_a + sqrt_b) * (1.0 / R_AB6); |
3598 | |
|
3599 | 0 | R_AB2 = vdwcalc.R_AB * vdwcalc.R_AB; |
3600 | 0 | R_AB4 = R_AB2 * R_AB2; |
3601 | 0 | R_AB6 = R_AB4 * R_AB2; |
3602 | 0 | vdwcalc.R_AB7 = R_AB6 * vdwcalc.R_AB; |
3603 | 0 | } else { |
3604 | 0 | g_AB = (R_AA - R_BB) / ( R_AA + R_BB); |
3605 | 0 | g_AB2 = g_AB * g_AB; |
3606 | 0 | vdwcalc.R_AB = 0.5 * (R_AA + R_BB) * (1.0 + 0.2 * (1.0 - exp(-12.0 * g_AB2))); |
3607 | 0 | R_AB2 = vdwcalc.R_AB * vdwcalc.R_AB; |
3608 | 0 | R_AB4 = R_AB2 * R_AB2; |
3609 | 0 | R_AB6 = R_AB4 * R_AB2; |
3610 | 0 | vdwcalc.R_AB7 = R_AB6 * vdwcalc.R_AB; |
3611 | 0 | vdwcalc.epsilon = (181.16 * vdwcalc.Ga * vdwcalc.Gb * vdwcalc.alpha_a * vdwcalc.alpha_b) / (sqrt_a + sqrt_b) * (1.0 / R_AB6); |
3612 | 0 | } |
3613 | |
|
3614 | 0 | vdwcalc.pairIndex = pairIndex; |
3615 | 0 | vdwcalc.SetupPointers(); |
3616 | 0 | _vdwcalculations.push_back(vdwcalc); |
3617 | 0 | } |
3618 | | |
3619 | | // |
3620 | | // Electrostatic Calculations |
3621 | | // |
3622 | 357 | IF_OBFF_LOGLVL_LOW |
3623 | 0 | OBFFLog("SETTING UP ELECTROSTATIC CALCULATIONS...\n"); |
3624 | | |
3625 | 357 | OBFFElectrostaticCalculationMMFF94 elecalc; |
3626 | | |
3627 | 357 | _electrostaticcalculations.clear(); |
3628 | | |
3629 | 357 | pairIndex = -1; |
3630 | 357 | FOR_PAIRS_OF_MOL(p, _mol) { |
3631 | 0 | ++pairIndex; |
3632 | 0 | a = _mol.GetAtom((*p)[0]); |
3633 | 0 | b = _mol.GetAtom((*p)[1]); |
3634 | | |
3635 | | // skip this ele if the atoms are ignored |
3636 | 0 | if ( _constraints.IsIgnored(a->GetIdx()) || _constraints.IsIgnored(b->GetIdx()) ) |
3637 | 0 | continue; |
3638 | | |
3639 | | // if there are any groups specified, check if the two atoms are in a single _interGroup or if |
3640 | | // two two atoms are in one of the _interGroups pairs. |
3641 | 0 | if (HasGroups()) { |
3642 | 0 | bool validEle = false; |
3643 | 0 | for (unsigned int i=0; i < _interGroup.size(); ++i) { |
3644 | 0 | if (_interGroup[i].BitIsSet(a->GetIdx()) && _interGroup[i].BitIsSet(b->GetIdx())) { |
3645 | 0 | validEle = true; |
3646 | 0 | break; |
3647 | 0 | } |
3648 | 0 | } |
3649 | 0 | if (!validEle) { |
3650 | 0 | for (unsigned int i=0; i < _interGroups.size(); ++i) { |
3651 | 0 | if (_interGroups[i].first.BitIsSet(a->GetIdx()) && _interGroups[i].second.BitIsSet(b->GetIdx())) { |
3652 | 0 | validEle = true; |
3653 | 0 | break; |
3654 | 0 | } |
3655 | 0 | if (_interGroups[i].first.BitIsSet(b->GetIdx()) && _interGroups[i].second.BitIsSet(a->GetIdx())) { |
3656 | 0 | validEle = true; |
3657 | 0 | break; |
3658 | 0 | } |
3659 | 0 | } |
3660 | 0 | } |
3661 | |
|
3662 | 0 | if (!validEle) |
3663 | 0 | continue; |
3664 | 0 | } |
3665 | | |
3666 | 0 | elecalc.qq = 332.0716 * a->GetPartialCharge() * b->GetPartialCharge() / _epsilon; |
3667 | |
|
3668 | 0 | if (elecalc.qq) { |
3669 | 0 | elecalc.a = &*a; |
3670 | 0 | elecalc.b = &*b; |
3671 | | |
3672 | | // 1-4 scaling |
3673 | 0 | if (a->IsOneFour(b)) |
3674 | 0 | elecalc.qq *= 0.75; |
3675 | |
|
3676 | 0 | elecalc.pairIndex = pairIndex; |
3677 | 0 | elecalc.SetupPointers(); |
3678 | 0 | _electrostaticcalculations.push_back(elecalc); |
3679 | 0 | } |
3680 | 0 | } |
3681 | | |
3682 | 357 | return true; |
3683 | 457 | } |
3684 | | |
3685 | | bool OBForceFieldMMFF94::SetupPointers() |
3686 | 0 | { |
3687 | 0 | for (unsigned int i = 0; i < _bondcalculations.size(); ++i) |
3688 | 0 | _bondcalculations[i].SetupPointers(); |
3689 | 0 | for (unsigned int i = 0; i < _anglecalculations.size(); ++i) |
3690 | 0 | _anglecalculations[i].SetupPointers(); |
3691 | 0 | for (unsigned int i = 0; i < _strbndcalculations.size(); ++i) |
3692 | 0 | _strbndcalculations[i].SetupPointers(); |
3693 | 0 | for (unsigned int i = 0; i < _torsioncalculations.size(); ++i) |
3694 | 0 | _torsioncalculations[i].SetupPointers(); |
3695 | 0 | for (unsigned int i = 0; i < _oopcalculations.size(); ++i) |
3696 | 0 | _oopcalculations[i].SetupPointers(); |
3697 | 0 | for (unsigned int i = 0; i < _vdwcalculations.size(); ++i) |
3698 | 0 | _vdwcalculations[i].SetupPointers(); |
3699 | 0 | for (unsigned int i = 0; i < _electrostaticcalculations.size(); ++i) |
3700 | 0 | _electrostaticcalculations[i].SetupPointers(); |
3701 | |
|
3702 | 0 | return true; |
3703 | 0 | } |
3704 | | |
3705 | | |
3706 | | // we set the the formal charge with SetPartialCharge because formal charges |
3707 | | // in MMFF94 are not always and integer |
3708 | | bool OBForceFieldMMFF94::SetFormalCharges() |
3709 | 2.33k | { |
3710 | 2.33k | _mol.SetAutomaticPartialCharge(false); |
3711 | | |
3712 | 225k | FOR_ATOMS_OF_MOL (atom, _mol) { |
3713 | 225k | int type = atoi(atom->GetType()); |
3714 | 225k | atom->SetPartialCharge(0.0); |
3715 | | |
3716 | 225k | bool done = false; |
3717 | 225k | switch (type) { |
3718 | 577 | case 34: |
3719 | 976 | case 49: |
3720 | 1.16k | case 51: |
3721 | 1.31k | case 54: |
3722 | 1.33k | case 58: |
3723 | 2.00k | case 92: |
3724 | 2.20k | case 93: |
3725 | 2.71k | case 94: |
3726 | 2.72k | case 97: |
3727 | 2.72k | atom->SetPartialCharge(1.0); |
3728 | 2.72k | done = true; |
3729 | 2.72k | break; |
3730 | 64 | case 35: |
3731 | 5.13k | case 62: |
3732 | 5.27k | case 89: |
3733 | 5.33k | case 90: |
3734 | 5.35k | case 91: |
3735 | 5.35k | atom->SetPartialCharge(-1.0); |
3736 | 5.35k | done = true; |
3737 | 5.35k | break; |
3738 | 21 | case 55: |
3739 | 21 | atom->SetPartialCharge(0.5); |
3740 | 21 | done = true; |
3741 | 21 | break; |
3742 | 1 | case 87: |
3743 | 170 | case 95: |
3744 | 294 | case 96: |
3745 | 453 | case 98: |
3746 | 716 | case 99: |
3747 | 716 | atom->SetPartialCharge(2.0); |
3748 | 716 | done = true; |
3749 | 716 | break; |
3750 | 151 | case 88: |
3751 | 151 | atom->SetPartialCharge(3.0); |
3752 | 151 | done = true; |
3753 | 151 | break; |
3754 | | //case 98: |
3755 | | // atom->SetPartialCharge(3.0); |
3756 | 216k | default: |
3757 | 216k | break; |
3758 | 225k | } |
3759 | | |
3760 | 225k | if (done) |
3761 | 8.96k | continue; |
3762 | | |
3763 | 216k | if (type == 56) { |
3764 | 41 | int n_count = 0; |
3765 | 41 | int temp_type; |
3766 | 1.33k | FOR_ATOMS_OF_MOL (atom2, _mol) { |
3767 | 1.33k | temp_type = atoi(atom2->GetType()); |
3768 | 1.33k | if (temp_type == 56 || temp_type == 81) |
3769 | 165 | ++n_count; |
3770 | 1.33k | } |
3771 | 41 | atom->SetPartialCharge((double)((n_count + 1) / 3) / (double)n_count); |
3772 | 216k | } else if (type == 32) { |
3773 | 1.27k | int o_count = 0; |
3774 | 1.27k | bool sulfonamide = false; |
3775 | 1.27k | bool sulfone_s_c = false; |
3776 | 1.27k | int s_count = 0; |
3777 | | |
3778 | 1.27k | FOR_NBORS_OF_ATOM(nbr, &*atom) { |
3779 | 4.21k | FOR_NBORS_OF_ATOM(nbr2, &*nbr) { |
3780 | 4.21k | if (nbr2->GetAtomicNum() == OBElements::Oxygen && (nbr2->GetExplicitDegree() == 1)) |
3781 | 2.22k | o_count++; |
3782 | 4.21k | if (nbr2->GetAtomicNum() == OBElements::Sulfur && (nbr2->GetExplicitDegree() == 1)) |
3783 | 447 | s_count++; |
3784 | 4.21k | if (nbr2->GetAtomicNum() == OBElements::Nitrogen && !nbr2->IsAromatic()) |
3785 | 786 | sulfonamide = true; |
3786 | 4.21k | OBBond *bond = nbr->GetBond(&*nbr2); |
3787 | 4.21k | if (nbr2->GetAtomicNum() == OBElements::Carbon && !bond->IsAromatic() && bond->GetBondOrder() == 2) |
3788 | 9 | sulfone_s_c = true; |
3789 | 4.21k | } |
3790 | | |
3791 | 1.27k | if (nbr->GetAtomicNum() == OBElements::Carbon) |
3792 | 20 | atom->SetPartialCharge(-0.5); // O2CM |
3793 | | |
3794 | 1.27k | if (nbr->GetAtomicNum() == OBElements::Nitrogen && (o_count == 3)) |
3795 | 3 | atom->SetPartialCharge(-1.0 / o_count); // O3N |
3796 | | |
3797 | 1.27k | if (nbr->GetAtomicNum() == OBElements::Sulfur && !sulfonamide) { |
3798 | 99 | if (((o_count + s_count) == 2) && (nbr->GetExplicitDegree() == 3) |
3799 | 2 | && (nbr->GetExplicitValence() >= 3) && !sulfone_s_c) { |
3800 | 2 | atom->SetPartialCharge(-0.5); // O2S (sulfinate) |
3801 | 2 | } |
3802 | 97 | else if ((o_count + s_count) == 3) { |
3803 | 20 | atom->SetPartialCharge(-1.0 / 3.0); // O3S |
3804 | 20 | } |
3805 | 77 | else if ((o_count + s_count) == 4) { |
3806 | 12 | atom->SetPartialCharge(-0.5); // O4S |
3807 | 12 | } |
3808 | 99 | } |
3809 | | |
3810 | 1.27k | if (nbr->GetAtomicNum() == OBElements::Phosphorus) { |
3811 | 640 | if ((o_count + s_count) == 2) { |
3812 | 191 | atom->SetPartialCharge(-0.5); // O2P |
3813 | 191 | } |
3814 | 449 | else if ((o_count + s_count) == 3) { |
3815 | 245 | atom->SetPartialCharge(-2.0 / 3.0); // O3P |
3816 | 245 | } |
3817 | 204 | else if ((o_count + s_count) == 4) { |
3818 | 45 | atom->SetPartialCharge(-0.25); // O4P |
3819 | 45 | } |
3820 | 640 | } |
3821 | | |
3822 | 1.27k | if (atoi(nbr->GetType()) == 77) |
3823 | 0 | atom->SetPartialCharge(-0.25); // O4CL |
3824 | 1.27k | } |
3825 | 215k | } else if (type == 61) { |
3826 | 22 | FOR_BONDS_OF_ATOM(bond, &*atom) { |
3827 | 22 | OBAtom *nbr = bond->GetNbrAtom(&*atom); |
3828 | 22 | if (!bond->IsAromatic() && bond->GetBondOrder() == 3 && nbr->GetAtomicNum() == OBElements::Nitrogen) |
3829 | 1 | atom->SetPartialCharge(1.0); |
3830 | 22 | } |
3831 | 215k | } else if (type == 72) { |
3832 | 818 | int s_count = 0; |
3833 | | |
3834 | 818 | FOR_NBORS_OF_ATOM(nbr, &*atom) { |
3835 | 818 | if (nbr->GetAtomicNum() == OBElements::Sulfur) |
3836 | 88 | s_count++; |
3837 | | |
3838 | 818 | if (nbr->GetAtomicNum() == OBElements::Phosphorus || nbr->GetAtomicNum() == OBElements::Sulfur) { |
3839 | 455 | FOR_NBORS_OF_ATOM(nbr2, &*nbr) |
3840 | 1.98k | if ((nbr2->GetAtomicNum() == OBElements::Sulfur || nbr2->GetAtomicNum() == OBElements::Oxygen) && (nbr2->GetExplicitDegree() == 1) && (atom->GetIdx() != nbr2->GetIdx())) |
3841 | 709 | atom->SetPartialCharge(-0.5); |
3842 | 455 | } else |
3843 | 363 | atom->SetPartialCharge(-1.0); |
3844 | | |
3845 | 818 | if (nbr->GetAtomicNum() == OBElements::Carbon) |
3846 | 106 | FOR_NBORS_OF_ATOM(nbr2, &*nbr) |
3847 | 400 | if (nbr2->GetAtomicNum() == OBElements::Sulfur && (nbr2->GetExplicitDegree() == 1) && (atom->GetIdx() != nbr2->GetIdx())) |
3848 | 2 | atom->SetPartialCharge(-0.5); // SSMO |
3849 | | |
3850 | 818 | if (s_count >= 2) |
3851 | 0 | atom->SetPartialCharge(-0.5); // SSMO |
3852 | 818 | } |
3853 | 214k | } else if (type == 76) { |
3854 | 70 | vector<OBRing*> vr; |
3855 | 70 | vr = _mol.GetSSSR(); |
3856 | 70 | vector<OBRing*>::iterator ri; |
3857 | 70 | vector<int>::iterator rj; |
3858 | 70 | int n_count; |
3859 | | |
3860 | 429 | for (ri = vr.begin();ri != vr.end();++ri) { // for each ring |
3861 | 359 | n_count = 0; |
3862 | | |
3863 | 359 | if ((*ri)->IsAromatic() && (*ri)->IsMember(&*atom) && ((*ri)->Size() == 5)) { |
3864 | 420 | for(rj = (*ri)->_path.begin();rj != (*ri)->_path.end();++rj) // for each ring atom |
3865 | 350 | if (_mol.GetAtom(*rj)->GetAtomicNum() == OBElements::Nitrogen) |
3866 | 199 | n_count++; |
3867 | | |
3868 | 70 | if (n_count > 1) |
3869 | 59 | atom->SetPartialCharge(-1.0 / n_count); |
3870 | 70 | } |
3871 | 359 | } |
3872 | 214k | } else if (type == 81) { |
3873 | 40 | atom->SetPartialCharge(1.0); |
3874 | | |
3875 | 40 | vector<OBRing*> vr; |
3876 | 40 | vr = _mol.GetSSSR(); |
3877 | 40 | vector<OBRing*>::iterator ri; |
3878 | 40 | vector<int>::iterator rj; |
3879 | 254 | for (ri = vr.begin();ri != vr.end();++ri) // for each ring |
3880 | 214 | if ((*ri)->IsAromatic() && (*ri)->IsMember(&*atom) && ((*ri)->Size() == 5)) { |
3881 | 40 | int n_count = 0; |
3882 | 240 | for(rj = (*ri)->_path.begin();rj != (*ri)->_path.end();++rj) // for each ring atom |
3883 | 200 | if (_mol.GetAtom(*rj)->GetAtomicNum() == OBElements::Nitrogen && (_mol.GetAtom(*rj)->GetExplicitDegree() == 3)) |
3884 | 66 | n_count++; |
3885 | | |
3886 | 40 | if (n_count) // coverity defensive testing |
3887 | 40 | atom->SetPartialCharge(1.0 / n_count); // NIM+ |
3888 | | |
3889 | 40 | FOR_NBORS_OF_ATOM(nbr, &*atom) |
3890 | 120 | FOR_NBORS_OF_ATOM(nbr2, &*nbr) |
3891 | 308 | if (atoi(nbr2->GetType()) == 56) |
3892 | 2 | atom->SetPartialCharge(1.0 / 3.0); |
3893 | | |
3894 | 40 | FOR_NBORS_OF_ATOM(nbr, &*atom) |
3895 | 120 | FOR_NBORS_OF_ATOM(nbr2, &*nbr) |
3896 | 308 | if (atoi(nbr2->GetType()) == 55) |
3897 | 1 | atom->SetPartialCharge(1.0 / (1.0 + n_count)); |
3898 | 40 | } |
3899 | 40 | } |
3900 | | |
3901 | 216k | } |
3902 | | |
3903 | 2.33k | PrintFormalCharges(); |
3904 | | |
3905 | 2.33k | return true; |
3906 | 2.33k | } |
3907 | | |
3908 | | bool OBForceFieldMMFF94::SetPartialCharges() |
3909 | 2.33k | { |
3910 | 2.33k | vector<double> charges(_mol.NumAtoms()+1, 0); |
3911 | 2.33k | double M, Wab, factor, q0a, q0b, Pa, Pb; |
3912 | | |
3913 | 225k | FOR_ATOMS_OF_MOL (atom, _mol) { |
3914 | 225k | int type = atoi(atom->GetType()); |
3915 | | |
3916 | 225k | switch (type) { |
3917 | 1.27k | case 32: |
3918 | 1.34k | case 35: |
3919 | 2.16k | case 72: |
3920 | 2.16k | factor = 0.5; |
3921 | 2.16k | break; |
3922 | 5.06k | case 62: |
3923 | 5.13k | case 76: |
3924 | 5.13k | factor = 0.25; |
3925 | 5.13k | break; |
3926 | 218k | default: |
3927 | 218k | factor = 0.0; |
3928 | 218k | break; |
3929 | 225k | } |
3930 | | |
3931 | 225k | M = GetCrd(type); |
3932 | 225k | q0a = atom->GetPartialCharge(); |
3933 | | |
3934 | | // charge sharing |
3935 | 225k | if (!factor) |
3936 | 218k | FOR_NBORS_OF_ATOM (nbr, &*atom) |
3937 | 353k | if (nbr->GetPartialCharge() < 0.0) |
3938 | 8.58k | q0a += nbr->GetPartialCharge() / (2.0 * (double)(nbr->GetExplicitDegree())); |
3939 | | |
3940 | | // needed for SEYWUO, positive charge sharing? |
3941 | 225k | if (type == 62) |
3942 | 5.06k | FOR_NBORS_OF_ATOM (nbr, &*atom) |
3943 | 10.1k | if (nbr->GetPartialCharge() > 0.0) |
3944 | 769 | q0a -= nbr->GetPartialCharge() / 2.0; |
3945 | | |
3946 | 225k | q0b = 0.0; |
3947 | 225k | Wab = 0.0; |
3948 | 225k | Pa = Pb = 0.0; |
3949 | 365k | FOR_NBORS_OF_ATOM (nbr, &*atom) { |
3950 | 365k | int nbr_type = atoi(nbr->GetType()); |
3951 | | |
3952 | 365k | q0b += nbr->GetPartialCharge(); |
3953 | | |
3954 | 365k | bool bci_found = false; |
3955 | 365k | for (unsigned int idx=0; idx < _ffchgparams.size(); idx++) |
3956 | 0 | if (GetBondType(&*atom, &*nbr) == _ffchgparams[idx]._ipar[0]) { |
3957 | 0 | if ((type == _ffchgparams[idx].a) && (nbr_type == _ffchgparams[idx].b)) { |
3958 | 0 | Wab += -_ffchgparams[idx]._dpar[0]; |
3959 | 0 | bci_found = true; |
3960 | 0 | } else if ((type == _ffchgparams[idx].b) && (nbr_type == _ffchgparams[idx].a)) { |
3961 | 0 | Wab += _ffchgparams[idx]._dpar[0]; |
3962 | 0 | bci_found = true; |
3963 | 0 | } |
3964 | 0 | } |
3965 | | |
3966 | 365k | if (!bci_found) { |
3967 | 365k | for (unsigned int idx=0; idx < _ffpbciparams.size(); idx++) { |
3968 | 0 | if (type == _ffpbciparams[idx].a) |
3969 | 0 | Pa = _ffpbciparams[idx]._dpar[0]; |
3970 | 0 | if (nbr_type == _ffpbciparams[idx].a) |
3971 | 0 | Pb = _ffpbciparams[idx]._dpar[0]; |
3972 | 0 | } |
3973 | 365k | Wab += Pa - Pb; |
3974 | 365k | } |
3975 | 365k | } |
3976 | 225k | if (factor) |
3977 | 7.29k | charges[atom->GetIdx()] = (1.0 - M * factor) * q0a + factor * q0b + Wab; |
3978 | 218k | else |
3979 | 218k | charges[atom->GetIdx()] = q0a + Wab; |
3980 | 225k | } |
3981 | | |
3982 | 2.33k | FOR_ATOMS_OF_MOL (atom, _mol) |
3983 | 225k | atom->SetPartialCharge(charges[atom->GetIdx()]); |
3984 | | |
3985 | 2.33k | PrintPartialCharges(); |
3986 | | |
3987 | 2.33k | return true; |
3988 | 2.33k | } |
3989 | | |
3990 | | //////////////////////////////////////////////////////////////////////////////// |
3991 | | //////////////////////////////////////////////////////////////////////////////// |
3992 | | // |
3993 | | // Validation functions |
3994 | | // |
3995 | | //////////////////////////////////////////////////////////////////////////////// |
3996 | | //////////////////////////////////////////////////////////////////////////////// |
3997 | | |
3998 | | // used to validate the implementation |
3999 | | bool OBForceFieldMMFF94::Validate () |
4000 | 0 | { |
4001 | 0 | OBConversion conv; |
4002 | 0 | OBFormat *format_in = conv.FindFormat("mol2"); |
4003 | 0 | vector<string> vs; |
4004 | 0 | vector<int> types; |
4005 | 0 | vector<double> fcharges, pcharges; |
4006 | 0 | vector<double> bond_lengths; |
4007 | 0 | char buffer[150]; |
4008 | 0 | bool molfound, atomfound, bondfound, fchgfound, pchgfound; |
4009 | 0 | double etot, ebond, eangle, eoop, estbn, etor, evdw, eeq; |
4010 | 0 | double termcount; //1=bond, 2=angle, 3=strbnd, 4=torsion, 5=oop |
4011 | 0 | int n = 0; |
4012 | |
|
4013 | 0 | if (!format_in || !conv.SetInFormat(format_in)) { |
4014 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Could not set mol2 input format", obError); |
4015 | 0 | return false; |
4016 | 0 | } |
4017 | | |
4018 | 0 | ifstream ifs, ifs2; |
4019 | 0 | ofstream ofs; |
4020 | |
|
4021 | 0 | ifs.open("MMFF94_dative.mol2"); |
4022 | 0 | if (!ifs) { |
4023 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Could not open ./MMFF94_dative.mol2", obError); |
4024 | 0 | return false; |
4025 | 0 | } |
4026 | | |
4027 | 0 | ifs2.open("MMFF94_opti.log"); |
4028 | 0 | if (!ifs2) { |
4029 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Coulg not open ./MMFF_opti.log", obError); |
4030 | 0 | return false; |
4031 | 0 | } |
4032 | | |
4033 | 0 | ofs.open("MMFF94_openbabel.log"); |
4034 | 0 | if (!ofs) { |
4035 | 0 | obErrorLog.ThrowError(__FUNCTION__, "Coulg not open ./MMFF_openbabel.log", obError); |
4036 | 0 | return false; |
4037 | 0 | } |
4038 | | |
4039 | 0 | if (!_init) { |
4040 | 0 | ParseParamFile(); |
4041 | 0 | _init = true; |
4042 | 0 | } |
4043 | | |
4044 | |
|
4045 | 0 | SetLogFile(&ofs); |
4046 | 0 | SetLogLevel(OBFF_LOGLVL_HIGH); |
4047 | |
|
4048 | 0 | for (unsigned int c=1;; c++) { |
4049 | 0 | _mol.Clear(); |
4050 | 0 | types.clear(); |
4051 | 0 | fcharges.clear(); |
4052 | 0 | pcharges.clear(); |
4053 | 0 | bond_lengths.clear(); |
4054 | |
|
4055 | 0 | if (!conv.Read(&_mol, &ifs)) |
4056 | 0 | break; |
4057 | 0 | if (_mol.Empty()) |
4058 | 0 | break; |
4059 | | |
4060 | 0 | _ncoords = _mol.NumAtoms() * 3; |
4061 | 0 | _gradientPtr = new double[_ncoords]; |
4062 | |
|
4063 | 0 | SetTypes(); |
4064 | |
|
4065 | 0 | if ((c == 98) || (c == 692)) // CUDPAS & VUWXUG |
4066 | 0 | continue; |
4067 | | |
4068 | 0 | termcount = 0; |
4069 | 0 | molfound = false; |
4070 | 0 | atomfound = false; |
4071 | 0 | bondfound = false; |
4072 | 0 | fchgfound = false; |
4073 | 0 | pchgfound = false; |
4074 | |
|
4075 | 0 | while (ifs2.getline(buffer, 150)) { |
4076 | 0 | tokenize(vs, buffer); |
4077 | 0 | if (vs.size() == 0) { |
4078 | 0 | bondfound = false; |
4079 | 0 | continue; |
4080 | 0 | } |
4081 | | |
4082 | 0 | string str(buffer); |
4083 | 0 | if (string::npos != str.find(_mol.GetTitle(),0)) |
4084 | 0 | molfound = true; |
4085 | |
|
4086 | 0 | if (atomfound) { |
4087 | 0 | if (n) { |
4088 | 0 | types.push_back(atoi(vs[2].c_str())); |
4089 | 0 | types.push_back(atoi(vs[5].c_str())); |
4090 | 0 | types.push_back(atoi(vs[8].c_str())); |
4091 | 0 | types.push_back(atoi(vs[11].c_str())); |
4092 | 0 | } else { |
4093 | 0 | if (vs.size() > 2) |
4094 | 0 | types.push_back(atoi(vs[2].c_str())); |
4095 | 0 | if (vs.size() > 5) |
4096 | 0 | types.push_back(atoi(vs[5].c_str())); |
4097 | 0 | if (vs.size() > 8) |
4098 | 0 | types.push_back(atoi(vs[8].c_str())); |
4099 | |
|
4100 | 0 | atomfound = false; |
4101 | 0 | } |
4102 | 0 | n--; |
4103 | 0 | } |
4104 | |
|
4105 | 0 | if (fchgfound) { |
4106 | 0 | if (n) { |
4107 | 0 | fcharges.push_back(atof(vs[2].c_str())); |
4108 | 0 | fcharges.push_back(atof(vs[5].c_str())); |
4109 | 0 | fcharges.push_back(atof(vs[8].c_str())); |
4110 | 0 | fcharges.push_back(atof(vs[11].c_str())); |
4111 | 0 | } else { |
4112 | 0 | if (vs.size() > 2) |
4113 | 0 | fcharges.push_back(atof(vs[2].c_str())); |
4114 | 0 | if (vs.size() > 5) |
4115 | 0 | fcharges.push_back(atof(vs[5].c_str())); |
4116 | 0 | if (vs.size() > 8) |
4117 | 0 | fcharges.push_back(atof(vs[8].c_str())); |
4118 | |
|
4119 | 0 | fchgfound = false; |
4120 | 0 | } |
4121 | 0 | n--; |
4122 | 0 | } |
4123 | |
|
4124 | 0 | if (pchgfound) { |
4125 | 0 | if (n) { |
4126 | 0 | pcharges.push_back(atof(vs[2].c_str())); |
4127 | 0 | pcharges.push_back(atof(vs[5].c_str())); |
4128 | 0 | pcharges.push_back(atof(vs[8].c_str())); |
4129 | 0 | pcharges.push_back(atof(vs[11].c_str())); |
4130 | 0 | } else { |
4131 | 0 | if (vs.size() > 2) |
4132 | 0 | pcharges.push_back(atof(vs[2].c_str())); |
4133 | 0 | if (vs.size() > 5) |
4134 | 0 | pcharges.push_back(atof(vs[5].c_str())); |
4135 | 0 | if (vs.size() > 8) |
4136 | 0 | pcharges.push_back(atof(vs[8].c_str())); |
4137 | |
|
4138 | 0 | pchgfound = false; |
4139 | 0 | } |
4140 | 0 | n--; |
4141 | 0 | } |
4142 | |
|
4143 | 0 | if (molfound && EQn(buffer, " ATOM NAME TYPE", 16)) { |
4144 | 0 | atomfound = true; |
4145 | 0 | n = _mol.NumAtoms() / 4; |
4146 | 0 | } |
4147 | 0 | if (molfound && EQn(buffer, " ATOM FCHARGE", 17)) { |
4148 | 0 | fchgfound = true; |
4149 | 0 | n = _mol.NumAtoms() / 4; |
4150 | 0 | } |
4151 | 0 | if (molfound && EQn(buffer, " ATOM CHARGE", 17)) { |
4152 | 0 | pchgfound = true; |
4153 | 0 | n = _mol.NumAtoms() / 4; |
4154 | 0 | } |
4155 | |
|
4156 | 0 | if (bondfound) |
4157 | 0 | bond_lengths.push_back(atof(vs[7].c_str())); |
4158 | |
|
4159 | 0 | if (molfound) { |
4160 | 0 | if (EQn(buffer, " Total ENERGY", 13)) |
4161 | 0 | etot = atof(vs[3].c_str()); |
4162 | 0 | if (EQn(buffer, " Bond Stretching", 16)) |
4163 | 0 | ebond = atof(vs[2].c_str()); |
4164 | 0 | if (EQn(buffer, " Angle Bending", 14)) |
4165 | 0 | eangle = atof(vs[2].c_str()); |
4166 | 0 | if (EQn(buffer, " Out-of-Plane Bending", 21)) |
4167 | 0 | eoop = atof(vs[2].c_str()); |
4168 | 0 | if (EQn(buffer, " Stretch-Bend", 13)) |
4169 | 0 | estbn = atof(vs[1].c_str()); |
4170 | 0 | if (EQn(buffer, " Total Torsion", 18)) |
4171 | 0 | etor = atof(vs[2].c_str()); |
4172 | 0 | if (EQn(buffer, " Net vdW", 12)) |
4173 | 0 | evdw = atof(vs[2].c_str()); |
4174 | 0 | if (EQn(buffer, " Electrostatic", 14)) |
4175 | 0 | eeq = atof(vs[1].c_str()); |
4176 | 0 | if (EQn(buffer, " ---------------------", 22) && (termcount == 0)) { |
4177 | 0 | termcount++; |
4178 | 0 | bondfound = true; |
4179 | 0 | } |
4180 | 0 | if (EQn(buffer, " OPTIMOL> # read next", 22)) |
4181 | 0 | break; |
4182 | 0 | } |
4183 | | |
4184 | | |
4185 | |
|
4186 | 0 | } // while (getline) |
4187 | |
|
4188 | 0 | vector<int>::iterator i; |
4189 | 0 | vector<double>::iterator di; |
4190 | 0 | unsigned int ni; |
4191 | 0 | bool failed; |
4192 | |
|
4193 | 0 | cout << "--------------------------------------------------------------------------------" << endl; |
4194 | 0 | cout << " " << endl; |
4195 | 0 | cout << " VALIDATE MOLECULE " << c << ": " << _mol.GetTitle() << endl; |
4196 | 0 | cout << " " << endl; |
4197 | 0 | cout << "IDX HYB AROM OB_TYPE LOG_TYPE RESULT " << endl; |
4198 | 0 | cout << "---------------------------------------------- " << endl; |
4199 | |
|
4200 | 0 | ni = 1; |
4201 | 0 | failed = false; |
4202 | 0 | for (i = types.begin(); i != types.end();++i) { |
4203 | 0 | if (ni > _mol.NumAtoms()) |
4204 | 0 | continue; |
4205 | | |
4206 | 0 | if ( (atoi(_mol.GetAtom(ni)->GetType()) == 87) || |
4207 | 0 | (atoi(_mol.GetAtom(ni)->GetType()) == 97) |
4208 | 0 | ) continue; |
4209 | | |
4210 | 0 | if (atoi(_mol.GetAtom(ni)->GetType()) == (*i)) |
4211 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %3d %4d %3d %3d PASSED", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetHyb(), |
4212 | 0 | _mol.GetAtom(ni)->IsAromatic(), atoi(_mol.GetAtom(ni)->GetType()), *i); |
4213 | 0 | else { |
4214 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %3d %4d %3d %3d XXX FAILED XXX", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetHyb(), |
4215 | 0 | _mol.GetAtom(ni)->IsAromatic(), atoi(_mol.GetAtom(ni)->GetType()), *i); |
4216 | 0 | failed = true; |
4217 | 0 | } |
4218 | |
|
4219 | 0 | cout << _logbuf << endl; |
4220 | |
|
4221 | 0 | ni++; |
4222 | 0 | } |
4223 | |
|
4224 | 0 | if (failed) { |
4225 | 0 | cout << "Could not successfully assign atom types" << endl; |
4226 | 0 | return false; |
4227 | | //continue; |
4228 | 0 | } |
4229 | | |
4230 | 0 | SetFormalCharges(); |
4231 | 0 | cout << endl; |
4232 | 0 | cout << "IDX OB_FCARGE LOG_FCHARGE RESULT" << endl; |
4233 | 0 | cout << "----------------------------------------" << endl; |
4234 | |
|
4235 | 0 | ni = 1; |
4236 | 0 | for (di = fcharges.begin(); di != fcharges.end(); ++di) { |
4237 | 0 | if (ni > _mol.NumAtoms()) |
4238 | 0 | continue; |
4239 | | |
4240 | 0 | if ( (atoi(_mol.GetAtom(ni)->GetType()) == 87) || |
4241 | 0 | (atoi(_mol.GetAtom(ni)->GetType()) == 97) |
4242 | 0 | ) continue; |
4243 | | |
4244 | 0 | if (fabs((*di) - _mol.GetAtom(ni)->GetPartialCharge()) <= 0.001) |
4245 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %7.4f %7.4f PASSED", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetPartialCharge(), *di); |
4246 | 0 | else { |
4247 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %7.4f %7.4f XXX FAILED XXX", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetPartialCharge(), *di); |
4248 | 0 | failed = true; |
4249 | 0 | } |
4250 | |
|
4251 | 0 | cout << _logbuf << endl; |
4252 | |
|
4253 | 0 | ni++; |
4254 | 0 | } |
4255 | |
|
4256 | 0 | if (failed) { |
4257 | 0 | cout << "Could not successfully assign formal charges" << endl; |
4258 | | //return false; |
4259 | 0 | continue; |
4260 | 0 | } |
4261 | | |
4262 | 0 | SetPartialCharges(); |
4263 | 0 | cout << endl; |
4264 | 0 | cout << "IDX OB_PCARGE LOG_PCHARGE RESULT" << endl; |
4265 | 0 | cout << "----------------------------------------" << endl; |
4266 | |
|
4267 | 0 | ni = 1; |
4268 | 0 | for (di = pcharges.begin(); di != pcharges.end(); ++di) { |
4269 | 0 | if (ni > _mol.NumAtoms()) |
4270 | 0 | continue; |
4271 | | |
4272 | 0 | if ( (atoi(_mol.GetAtom(ni)->GetType()) == 87) || |
4273 | 0 | (atoi(_mol.GetAtom(ni)->GetType()) == 97) |
4274 | 0 | ) continue; |
4275 | | |
4276 | 0 | if (fabs((*di) - _mol.GetAtom(ni)->GetPartialCharge()) <= 0.001) |
4277 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %7.4f %7.4f PASSED", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetPartialCharge(), *di); |
4278 | 0 | else { |
4279 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d %7.4f %7.4f XXX FAILED XXX", _mol.GetAtom(ni)->GetIdx(), _mol.GetAtom(ni)->GetPartialCharge(), *di); |
4280 | 0 | failed = true; |
4281 | 0 | } |
4282 | |
|
4283 | 0 | cout << _logbuf << endl; |
4284 | |
|
4285 | 0 | ni++; |
4286 | 0 | } |
4287 | |
|
4288 | 0 | if (failed) { |
4289 | 0 | cout << "Could not successfully assign partial charges" << endl; |
4290 | | //return false; |
4291 | 0 | continue; |
4292 | 0 | } |
4293 | | |
4294 | | |
4295 | | |
4296 | 0 | if (!SetupCalculations()) { |
4297 | 0 | cout << "Could not setup calculations (missing parameters...)" << endl; |
4298 | 0 | return false; |
4299 | | //continue; |
4300 | 0 | } |
4301 | | |
4302 | 0 | double delta; |
4303 | 0 | cout << endl; |
4304 | 0 | cout << "TERM OB ENERGY LOG ENERGY DELTA" << endl; |
4305 | 0 | cout << "---------------------------------------------------------------" << endl; |
4306 | |
|
4307 | 0 | delta = (E_Bond() - ebond); |
4308 | 0 | snprintf(_logbuf, BUFF_SIZE, "Bond Stretching %11.5f %11.5f %11.5f", E_Bond(), ebond, delta); |
4309 | 0 | cout << _logbuf << endl; |
4310 | |
|
4311 | 0 | delta = (E_Angle() - eangle); |
4312 | 0 | snprintf(_logbuf, BUFF_SIZE, "Angle Bending %11.5f %11.5f %11.5f", E_Angle(), eangle, delta); |
4313 | 0 | cout << _logbuf << endl; |
4314 | |
|
4315 | 0 | delta = (E_StrBnd() - estbn); |
4316 | 0 | snprintf(_logbuf, BUFF_SIZE, "Stretch-Bending %11.5f %11.5f %11.5f", E_StrBnd(), estbn, delta); |
4317 | 0 | cout << _logbuf << endl; |
4318 | |
|
4319 | 0 | delta = (E_OOP() - eoop); |
4320 | 0 | snprintf(_logbuf, BUFF_SIZE, "Out-Of-Plane Bending %11.5f %11.5f %11.5f", E_OOP(), eoop, delta); |
4321 | 0 | cout << _logbuf << endl; |
4322 | |
|
4323 | 0 | delta = (E_Torsion() - etor); |
4324 | 0 | snprintf(_logbuf, BUFF_SIZE, "Torsional %11.5f %11.5f %11.5f", E_Torsion(), etor, delta); |
4325 | 0 | cout << _logbuf << endl; |
4326 | |
|
4327 | 0 | delta = (E_VDW() - evdw); |
4328 | 0 | snprintf(_logbuf, BUFF_SIZE, "Van der Waals %11.5f %11.5f %11.5f", E_VDW(), evdw, delta); |
4329 | 0 | cout << _logbuf << endl; |
4330 | |
|
4331 | 0 | delta = (E_Electrostatic() - eeq); |
4332 | 0 | snprintf(_logbuf, BUFF_SIZE, "Electrostatic %11.5f %11.5f %11.5f", E_Electrostatic(), eeq, delta); |
4333 | 0 | cout << _logbuf << endl; |
4334 | |
|
4335 | 0 | cout << endl; |
4336 | 0 | delta = (Energy() - etot); |
4337 | 0 | snprintf(_logbuf, BUFF_SIZE, "Total ENERGY %11.5f %11.5f %11.5f", Energy(), etot, delta); |
4338 | 0 | cout << _logbuf << endl; |
4339 | |
|
4340 | 0 | } // for (unsigned int c;; c++ ) |
4341 | | |
4342 | 0 | if (ifs) |
4343 | 0 | ifs.close(); |
4344 | 0 | if (ifs2) |
4345 | 0 | ifs2.close(); |
4346 | |
|
4347 | 0 | return true; |
4348 | 0 | } |
4349 | | |
4350 | | bool OBForceFieldMMFF94::ValidateGradients () |
4351 | 0 | { |
4352 | 0 | vector3 numgrad, anagrad, err; |
4353 | 0 | int coordIdx; |
4354 | |
|
4355 | 0 | bool passed = true; // set to false if any component fails |
4356 | |
|
4357 | 0 | cout << "----------------------------------------------------------------------------------------" << endl; |
4358 | 0 | cout << " " << endl; |
4359 | 0 | cout << " VALIDATE GRADIENTS : " << _mol.GetTitle() << endl; |
4360 | 0 | cout << " " << endl; |
4361 | 0 | cout << " " << endl; |
4362 | 0 | cout << "ATOM IDX NUMERICAL GRADIENT ANALYTICAL GRADIENT REL. ERROR (%) " << endl; |
4363 | 0 | cout << "----------------------------------------------------------------------------------------" << endl; |
4364 | | // "XX (000.000, 000.000, 000.000) (000.000, 000.000, 000.000) (00.00, 00.00, 00.00)" |
4365 | |
|
4366 | 0 | FOR_ATOMS_OF_MOL (a, _mol) { |
4367 | 0 | coordIdx = (a->GetIdx() - 1) * 3; |
4368 | | |
4369 | | // OBFF_ENERGY |
4370 | 0 | numgrad = NumericalDerivative(&*a, OBFF_ENERGY); |
4371 | 0 | Energy(); // compute |
4372 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4373 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4374 | |
|
4375 | 0 | snprintf(_logbuf, BUFF_SIZE, "%2d (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", a->GetIdx(), numgrad.x(), numgrad.y(), numgrad.z(), |
4376 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4377 | 0 | OBFFLog(_logbuf); |
4378 | | |
4379 | | // OBFF_EBOND |
4380 | 0 | numgrad = NumericalDerivative(&*a, OBFF_EBOND); |
4381 | 0 | ClearGradients(); |
4382 | 0 | E_Bond(); // compute |
4383 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4384 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4385 | |
|
4386 | 0 | snprintf(_logbuf, BUFF_SIZE, " bond (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4387 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4388 | 0 | OBFFLog(_logbuf); |
4389 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4390 | 0 | passed = false; |
4391 | | |
4392 | | // OBFF_EANGLE |
4393 | 0 | numgrad = NumericalDerivative(&*a, OBFF_EANGLE); |
4394 | 0 | ClearGradients(); |
4395 | 0 | E_Angle(); // compute |
4396 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4397 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4398 | |
|
4399 | 0 | snprintf(_logbuf, BUFF_SIZE, " angle (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4400 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4401 | 0 | OBFFLog(_logbuf); |
4402 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4403 | 0 | passed = false; |
4404 | | |
4405 | | // OBFF_ESTRBND |
4406 | 0 | numgrad = NumericalDerivative(&*a, OBFF_ESTRBND); |
4407 | 0 | ClearGradients(); |
4408 | 0 | E_StrBnd(); // compute |
4409 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4410 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4411 | |
|
4412 | 0 | snprintf(_logbuf, BUFF_SIZE, " strbnd (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4413 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4414 | 0 | OBFFLog(_logbuf); |
4415 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4416 | 0 | passed = false; |
4417 | | |
4418 | | // OBFF_ETORSION |
4419 | 0 | numgrad = NumericalDerivative(&*a, OBFF_ETORSION); |
4420 | 0 | ClearGradients(); |
4421 | 0 | E_Torsion(); // compute |
4422 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4423 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4424 | |
|
4425 | 0 | snprintf(_logbuf, BUFF_SIZE, " torsion (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4426 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4427 | 0 | OBFFLog(_logbuf); |
4428 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4429 | 0 | passed = false; |
4430 | | |
4431 | | // OBFF_EOOP |
4432 | 0 | numgrad = NumericalDerivative(&*a, OBFF_EOOP); |
4433 | 0 | ClearGradients(); |
4434 | 0 | E_OOP(); // compute |
4435 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4436 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4437 | |
|
4438 | 0 | snprintf(_logbuf, BUFF_SIZE, " oop (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4439 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4440 | 0 | OBFFLog(_logbuf); |
4441 | | // disable OOP gradient validation for now -- some small errors, but nothing major |
4442 | | // if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4443 | | // passed = false; |
4444 | | |
4445 | | // OBFF_EVDW |
4446 | 0 | numgrad = NumericalDerivative(&*a, OBFF_EVDW); |
4447 | 0 | ClearGradients(); |
4448 | 0 | E_VDW(); // compute |
4449 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4450 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4451 | |
|
4452 | 0 | snprintf(_logbuf, BUFF_SIZE, " vdw (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4453 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4454 | 0 | OBFFLog(_logbuf); |
4455 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4456 | 0 | passed = false; |
4457 | | |
4458 | | // OBFF_EELECTROSTATIC |
4459 | 0 | numgrad = NumericalDerivative(&*a, OBFF_EELECTROSTATIC); |
4460 | 0 | ClearGradients(); |
4461 | 0 | E_Electrostatic(); // compute |
4462 | 0 | anagrad.Set(_gradientPtr[coordIdx], _gradientPtr[coordIdx+1], _gradientPtr[coordIdx+2]); |
4463 | 0 | err = ValidateGradientError(numgrad, anagrad); |
4464 | |
|
4465 | 0 | snprintf(_logbuf, BUFF_SIZE, " electro (%7.3f, %7.3f, %7.3f) (%7.3f, %7.3f, %7.3f) (%5.2f, %5.2f, %5.2f)\n", numgrad.x(), numgrad.y(), numgrad.z(), |
4466 | 0 | anagrad.x(), anagrad.y(), anagrad.z(), err.x(), err.y(), err.z()); |
4467 | 0 | OBFFLog(_logbuf); |
4468 | 0 | if (err.x() > 5.0 || err.y() > 5.0 || err.z() > 5.0) |
4469 | 0 | passed = false; |
4470 | 0 | } |
4471 | |
|
4472 | 0 | return passed; // did we pass every single component? |
4473 | 0 | } |
4474 | | |
4475 | | //////////////////////////////////////////////////////////////////////////////// |
4476 | | //////////////////////////////////////////////////////////////////////////////// |
4477 | | // |
4478 | | // Calculate bond type, angle type, stretch-bend type, torsion type |
4479 | | // |
4480 | | //////////////////////////////////////////////////////////////////////////////// |
4481 | | //////////////////////////////////////////////////////////////////////////////// |
4482 | | |
4483 | | // |
4484 | | // MMFF part V - page 620 |
4485 | | // |
4486 | | // BTij is 1 when: |
4487 | | // a) single bond between atoms i and j, both i and j are not aromatic and both types have sbmb set in mmffprop.par, or |
4488 | | // b) bewtween two aromatic atoms, but the bond is not aromatic (e.g. connecting bond in biphenyl) |
4489 | | // |
4490 | | int OBForceFieldMMFF94::GetBondType(OBAtom* a, OBAtom* b) |
4491 | 1.87k | { |
4492 | 1.87k | OBBond *bond = _mol.GetBond(a, b); |
4493 | 1.87k | if (bond == nullptr) |
4494 | 0 | return 0; |
4495 | 1.87k | if (bond->GetBondOrder() != 1 || bond->IsAromatic()) |
4496 | 262 | return 0; |
4497 | | |
4498 | 1.61k | if (HasAromSet(atoi(a->GetType())) && HasAromSet(atoi(b->GetType()))) |
4499 | 0 | return 1; |
4500 | | |
4501 | 1.61k | if (HasSbmbSet(atoi(a->GetType())) && HasSbmbSet(atoi(b->GetType()))) |
4502 | 0 | return 1; |
4503 | | |
4504 | 1.61k | return 0; |
4505 | 1.61k | } |
4506 | | |
4507 | | int OBForceFieldMMFF94::GetAngleType(OBAtom* a, OBAtom* b, OBAtom *c) |
4508 | 0 | { |
4509 | 0 | int sumbondtypes; |
4510 | |
|
4511 | 0 | sumbondtypes = GetBondType(a,b) + GetBondType(b, c); |
4512 | |
|
4513 | 0 | if (a->IsInRingSize(3) && b->IsInRingSize(3) && c->IsInRingSize(3) && IsInSameRing(a, c)) |
4514 | 0 | switch (sumbondtypes) { |
4515 | 0 | case 0: |
4516 | 0 | return 3; |
4517 | 0 | case 1: |
4518 | 0 | return 5; |
4519 | 0 | case 2: |
4520 | 0 | return 6; |
4521 | 0 | } |
4522 | | |
4523 | 0 | if (a->IsInRingSize(4) && b->IsInRingSize(4) && c->IsInRingSize(4) && IsInSameRing(a, c)) |
4524 | 0 | switch (sumbondtypes) { |
4525 | 0 | case 0: |
4526 | 0 | return 4; |
4527 | 0 | case 1: |
4528 | 0 | return 7; |
4529 | 0 | case 2: |
4530 | 0 | return 8; |
4531 | 0 | } |
4532 | | |
4533 | 0 | return sumbondtypes; |
4534 | 0 | } |
4535 | | |
4536 | | int OBForceFieldMMFF94::GetStrBndType(OBAtom* a, OBAtom* b, OBAtom *c) |
4537 | 0 | { |
4538 | 0 | int btab, btbc, atabc; |
4539 | 0 | bool inverse; |
4540 | |
|
4541 | 0 | btab = GetBondType(a, b); |
4542 | 0 | btbc = GetBondType(b, c); |
4543 | 0 | atabc = GetAngleType(a, b, c); |
4544 | |
|
4545 | 0 | if (atoi(a->GetType()) <= atoi(c->GetType())) |
4546 | 0 | inverse = false; |
4547 | 0 | else |
4548 | 0 | inverse = true; |
4549 | |
|
4550 | 0 | switch (atabc) { |
4551 | 0 | case 0: |
4552 | 0 | return 0; |
4553 | | |
4554 | 0 | case 1: |
4555 | 0 | if (btab) { |
4556 | 0 | if (!inverse) { |
4557 | 0 | return 1; |
4558 | 0 | } else { |
4559 | 0 | return 2; |
4560 | 0 | } |
4561 | 0 | } |
4562 | 0 | if (btbc) { |
4563 | 0 | if (!inverse) { |
4564 | 0 | return 2; |
4565 | 0 | } else { |
4566 | 0 | return 1; |
4567 | 0 | } |
4568 | 0 | } |
4569 | | |
4570 | 0 | case 2: |
4571 | 0 | return 3; |
4572 | | |
4573 | 0 | case 3: |
4574 | 0 | return 5; |
4575 | | |
4576 | 0 | case 4: |
4577 | 0 | return 4; |
4578 | | |
4579 | 0 | case 5: |
4580 | 0 | if (btab) { |
4581 | 0 | if (!inverse) { |
4582 | 0 | return 6; |
4583 | 0 | } else { |
4584 | 0 | return 7; |
4585 | 0 | } |
4586 | 0 | } |
4587 | 0 | if (btbc) { |
4588 | 0 | if (!inverse) { |
4589 | 0 | return 7; |
4590 | 0 | } else { |
4591 | 0 | return 6; |
4592 | 0 | } |
4593 | 0 | } |
4594 | | |
4595 | 0 | case 6: |
4596 | 0 | return 8; |
4597 | | |
4598 | 0 | case 7: |
4599 | 0 | if (btab) { |
4600 | 0 | if (!inverse) { |
4601 | 0 | return 9; |
4602 | 0 | } else { |
4603 | 0 | return 10; |
4604 | 0 | } |
4605 | 0 | } |
4606 | 0 | if (btbc) { |
4607 | 0 | if (!inverse) { |
4608 | 0 | return 10; |
4609 | 0 | } else { |
4610 | 0 | return 9; |
4611 | 0 | } |
4612 | 0 | } |
4613 | | |
4614 | 0 | case 8: |
4615 | 0 | return 11; |
4616 | 0 | } |
4617 | | |
4618 | 0 | return 0; |
4619 | 0 | } |
4620 | | |
4621 | | // |
4622 | | // MMFF part IV - page 609 |
4623 | | // |
4624 | | // TTijkl = 1 when BTjk = 1 |
4625 | | // TTijkl = 2 when BTjk = 0 but BTij and/or BTkl = 1 |
4626 | | // TTijkl = 4 when i, j, k and l are all members of the same four-membered ring |
4627 | | // TTijkl = 5 when i, j, k and l are members of a five-membered ring and at least one is a sp3-hybridized carbon (MMFF atom type 1) |
4628 | | // |
4629 | | int OBForceFieldMMFF94::GetTorsionType(OBAtom* a, OBAtom* b, OBAtom *c, OBAtom *d) |
4630 | 0 | { |
4631 | 0 | int btab, btbc, btcd; |
4632 | |
|
4633 | 0 | btab = GetBondType(a, b); |
4634 | 0 | btbc = GetBondType(b, c); |
4635 | 0 | btcd = GetBondType(c, d); |
4636 | |
|
4637 | 0 | if (btbc == 1) |
4638 | 0 | return 1; |
4639 | | |
4640 | 0 | if (a->IsInRingSize(4) && b->IsInRingSize(4) && c->IsInRingSize(4) && d->IsInRingSize(4)) |
4641 | 0 | if (IsInSameRing(a,b) && IsInSameRing(b,c) && IsInSameRing(c,d)) |
4642 | 0 | return 4; |
4643 | | |
4644 | 0 | OBBond *bond = _mol.GetBond(b, c); |
4645 | 0 | if (bond != nullptr && bond->GetBondOrder() == 1 && !bond->IsAromatic()) { |
4646 | 0 | if (btab || btcd) |
4647 | 0 | return 2; |
4648 | | /* |
4649 | | unsigned int order1 = GetCXT(0, atoi(d->GetType()), atoi(c->GetType()), atoi(b->GetType()), atoi(a->GetType())); |
4650 | | unsigned int order2 = GetCXT(0, atoi(a->GetType()), atoi(b->GetType()), atoi(c->GetType()), atoi(d->GetType())); |
4651 | | |
4652 | | cout << "GetTorsionType(" << a->GetType() << ", " << b->GetType() << ", " << c->GetType() << ", " << d->GetType() << ")" << endl; |
4653 | | cout << " order1 = " << order1 << endl; |
4654 | | cout << " order2 = " << order2 << endl; |
4655 | | cout << " btab = " << btab << endl; |
4656 | | cout << " btbc = " << btbc << endl; |
4657 | | cout << " btcd = " << btcd << endl; |
4658 | | */ |
4659 | 0 | } |
4660 | | |
4661 | 0 | if (a->IsInRingSize(5) && b->IsInRingSize(5) && c->IsInRingSize(5) && d->IsInRingSize(5)) { |
4662 | 0 | vector<OBRing*> vr; |
4663 | 0 | vr = _mol.GetSSSR(); |
4664 | |
|
4665 | 0 | if( !((atoi(a->GetType()) == 1) || (atoi(b->GetType()) == 1) || (atoi(c->GetType()) == 1) || (atoi(d->GetType()) == 1)) ) |
4666 | 0 | return 0; |
4667 | | |
4668 | 0 | vector<OBRing*>::iterator ri; |
4669 | 0 | vector<int>::iterator rj; |
4670 | 0 | for (ri = vr.begin();ri != vr.end();++ri) { // for each ring |
4671 | 0 | if ((*ri)->IsAromatic()) |
4672 | 0 | continue; |
4673 | | |
4674 | 0 | if ((*ri)->Size() != 5) |
4675 | 0 | continue; |
4676 | | |
4677 | 0 | if (!(*ri)->IsMember(a) || !(*ri)->IsMember(b) || !(*ri)->IsMember(c) || !(*ri)->IsMember(d)) |
4678 | 0 | continue; |
4679 | | |
4680 | 0 | return 5; |
4681 | 0 | } |
4682 | 0 | } |
4683 | | |
4684 | | |
4685 | 0 | return 0; |
4686 | 0 | } |
4687 | | |
4688 | | // CXB = MC * (I * MA + J) + BTij |
4689 | | unsigned int OBForceFieldMMFF94::GetCXB(int type, int a, int b) |
4690 | 0 | { |
4691 | 0 | unsigned int cxb; |
4692 | 0 | cxb = 2 * (a * 136 + b) + type; |
4693 | 0 | return cxb; |
4694 | 0 | } |
4695 | | |
4696 | | // CXA = MC * (J * MA^2 + I * MA + K) + ATijk |
4697 | | unsigned int OBForceFieldMMFF94::GetCXA(int type, int a, int b, int c) |
4698 | 0 | { |
4699 | 0 | unsigned int cxa; |
4700 | 0 | cxa = 9 * (b * 18496 + a * 136 + c) + type; |
4701 | 0 | return cxa; |
4702 | 0 | } |
4703 | | |
4704 | | // CXS = MC * (J * MA^2 + I * MA + K) + STijk |
4705 | | unsigned int OBForceFieldMMFF94::GetCXS(int type, int a, int b, int c) |
4706 | 0 | { |
4707 | 0 | unsigned int cxs; |
4708 | 0 | cxs = 12 * (b * 18496 + a * 136 + c) + type; |
4709 | 0 | return cxs; |
4710 | 0 | } |
4711 | | |
4712 | | // CXO = J * MA^3 + I * MA^2 + K * MA + L |
4713 | | unsigned int OBForceFieldMMFF94::GetCXO(int a, int b, int c, int d) |
4714 | 0 | { |
4715 | 0 | unsigned int cxo; |
4716 | 0 | cxo = b * 2515456 + a * 18496 + c * 136 + d; |
4717 | 0 | return cxo; |
4718 | 0 | } |
4719 | | |
4720 | | // CXT = MC * (J * MA^3 + K * MA^2 + I * MA + L) + TTijkl |
4721 | | unsigned int OBForceFieldMMFF94::GetCXT(int type, int a, int b, int c, int d) |
4722 | 0 | { |
4723 | 0 | unsigned int cxt; |
4724 | 0 | cxt = 6 * (b * 2515456 + c * 18496 + a * 136 + d) + type; |
4725 | 0 | return cxt; |
4726 | 0 | } |
4727 | | |
4728 | | // CXQ = MC * (I * MA + J) + BTij |
4729 | | unsigned int OBForceFieldMMFF94::GetCXQ(int type, int a, int b) |
4730 | 0 | { |
4731 | 0 | unsigned int cxq; |
4732 | 0 | cxq = 2 * (a * 136 + b) + type; |
4733 | 0 | return cxq; |
4734 | 0 | } |
4735 | | |
4736 | | //////////////////////////////////////////////////////////////////////////////// |
4737 | | //////////////////////////////////////////////////////////////////////////////// |
4738 | | // |
4739 | | // Various tables & misc. functions |
4740 | | // |
4741 | | //////////////////////////////////////////////////////////////////////////////// |
4742 | | //////////////////////////////////////////////////////////////////////////////// |
4743 | | |
4744 | | // MMFF part V - TABLE I |
4745 | | bool OBForceFieldMMFF94::HasLinSet(int atomtype) |
4746 | 0 | { |
4747 | 0 | return _ffpropLin.BitIsSet(atomtype); |
4748 | 0 | } |
4749 | | |
4750 | | // MMFF part V - TABLE I |
4751 | | bool OBForceFieldMMFF94::HasPilpSet(int atomtype) |
4752 | 0 | { |
4753 | 0 | return _ffpropPilp.BitIsSet(atomtype); |
4754 | 0 | } |
4755 | | |
4756 | | // MMFF part V - TABLE I |
4757 | | bool OBForceFieldMMFF94::HasAromSet(int atomtype) |
4758 | 1.61k | { |
4759 | 1.61k | return _ffpropArom.BitIsSet(atomtype); |
4760 | 1.61k | } |
4761 | | |
4762 | | // MMFF part V - TABLE I |
4763 | | bool OBForceFieldMMFF94::HasSbmbSet(int atomtype) |
4764 | 1.61k | { |
4765 | 1.61k | return _ffpropSbmb.BitIsSet(atomtype); |
4766 | 1.61k | } |
4767 | | |
4768 | | // MMFF part V - TABLE I |
4769 | | int OBForceFieldMMFF94::GetCrd(int atomtype) |
4770 | 225k | { |
4771 | 225k | OBFFParameter *par; |
4772 | | |
4773 | 225k | par = GetParameter1Atom(atomtype, _ffpropparams); // from mmffprop.par |
4774 | 225k | if (par) |
4775 | 0 | return par->_ipar[1]; |
4776 | | |
4777 | 225k | return 0; |
4778 | 225k | } |
4779 | | |
4780 | | // MMFF part V - TABLE I |
4781 | | int OBForceFieldMMFF94::GetVal(int atomtype) |
4782 | 0 | { |
4783 | 0 | OBFFParameter *par; |
4784 | |
|
4785 | 0 | par = GetParameter1Atom(atomtype, _ffpropparams); // from mmffprop.par |
4786 | 0 | if (par) |
4787 | 0 | return par->_ipar[2]; |
4788 | | |
4789 | 0 | return 0; |
4790 | 0 | } |
4791 | | |
4792 | | // MMFF part V - TABLE I |
4793 | | int OBForceFieldMMFF94::GetMltb(int atomtype) |
4794 | 0 | { |
4795 | 0 | OBFFParameter *par; |
4796 | |
|
4797 | 0 | par = GetParameter1Atom(atomtype, _ffpropparams); // from mmffprop.par |
4798 | 0 | if (par) |
4799 | 0 | return par->_ipar[4]; |
4800 | | |
4801 | 0 | return 0; |
4802 | 0 | } |
4803 | | |
4804 | | // MMFF part I - TABLE IV |
4805 | | int OBForceFieldMMFF94::EqLvl2(int type) |
4806 | 0 | { |
4807 | 0 | for (unsigned int idx=0; idx < _ffdefparams.size(); idx++) |
4808 | 0 | if (_ffdefparams[idx]._ipar[0] == type) |
4809 | 0 | return _ffdefparams[idx]._ipar[1]; |
4810 | | |
4811 | 0 | return type; |
4812 | 0 | } |
4813 | | |
4814 | | // MMFF part I - TABLE IV |
4815 | | int OBForceFieldMMFF94::EqLvl3(int type) |
4816 | 0 | { |
4817 | 0 | for (unsigned int idx=0; idx < _ffdefparams.size(); idx++) |
4818 | 0 | if (_ffdefparams[idx]._ipar[0] == type) |
4819 | 0 | return _ffdefparams[idx]._ipar[2]; |
4820 | | |
4821 | 0 | return type; |
4822 | 0 | } |
4823 | | |
4824 | | // MMFF part I - TABLE IV |
4825 | | int OBForceFieldMMFF94::EqLvl4(int type) |
4826 | 0 | { |
4827 | 0 | for (unsigned int idx=0; idx < _ffdefparams.size(); idx++) |
4828 | 0 | if (_ffdefparams[idx]._ipar[0] == type) |
4829 | 0 | return _ffdefparams[idx]._ipar[3]; |
4830 | | |
4831 | 0 | return type; |
4832 | 0 | } |
4833 | | |
4834 | | // MMFF part I - TABLE IV |
4835 | | int OBForceFieldMMFF94::EqLvl5(int type) |
4836 | 0 | { |
4837 | 0 | for (unsigned int idx=0; idx < _ffdefparams.size(); idx++) |
4838 | 0 | if (_ffdefparams[idx]._ipar[0] == type) |
4839 | 0 | return _ffdefparams[idx]._ipar[4]; |
4840 | | |
4841 | 0 | return type; |
4842 | 0 | } |
4843 | | |
4844 | | // MMFF part V - TABLE VI |
4845 | | double OBForceFieldMMFF94::GetZParam(OBAtom* atom) |
4846 | 0 | { |
4847 | 0 | switch (atom->GetAtomicNum()) { |
4848 | 0 | case OBElements::Hydrogen: |
4849 | 0 | return 1.395; |
4850 | 0 | case OBElements::Carbon: |
4851 | 0 | return 2.494; |
4852 | 0 | case OBElements::Nitrogen: |
4853 | 0 | return 2.711; |
4854 | 0 | case OBElements::Oxygen: |
4855 | 0 | return 3.045; |
4856 | 0 | case OBElements::Fluorine: |
4857 | 0 | return 2.847; |
4858 | 0 | case OBElements::Silicon: |
4859 | 0 | return 2.350; |
4860 | 0 | case OBElements::Phosphorus: |
4861 | 0 | return 2.350; |
4862 | 0 | case OBElements::Sulfur: |
4863 | 0 | return 2.980; |
4864 | 0 | case OBElements::Chlorine: |
4865 | 0 | return 2.909; |
4866 | 0 | case OBElements::Bromine: |
4867 | 0 | return 3.017; |
4868 | 0 | case OBElements::Iodine: |
4869 | 0 | return 3.086; |
4870 | 0 | } |
4871 | | |
4872 | 0 | return 0.0; |
4873 | 0 | } |
4874 | | |
4875 | | // MMFF part V - TABLE VI |
4876 | | double OBForceFieldMMFF94::GetCParam(OBAtom* atom) |
4877 | 0 | { |
4878 | 0 | switch (atom->GetAtomicNum()) { |
4879 | 0 | case OBElements::Boron: |
4880 | 0 | return 0.704; |
4881 | 0 | case OBElements::Carbon: |
4882 | 0 | return 1.016; |
4883 | 0 | case OBElements::Nitrogen: |
4884 | 0 | return 1.113; |
4885 | 0 | case OBElements::Oxygen: |
4886 | 0 | return 1.337; |
4887 | 0 | case OBElements::Silicon: |
4888 | 0 | return 0.811; |
4889 | 0 | case OBElements::Phosphorus: |
4890 | 0 | return 1.068; |
4891 | 0 | case OBElements::Sulfur: |
4892 | 0 | return 1.249; |
4893 | 0 | case OBElements::Chlorine: |
4894 | 0 | return 1.078; |
4895 | 0 | case OBElements::Arsenic: |
4896 | 0 | return 0.825; |
4897 | 0 | } |
4898 | | |
4899 | 0 | return 0.0; |
4900 | 0 | } |
4901 | | |
4902 | | // MMFF part V - TABLE X |
4903 | | double OBForceFieldMMFF94::GetUParam(OBAtom* atom) |
4904 | 0 | { |
4905 | 0 | switch (atom->GetAtomicNum()) { |
4906 | 0 | case OBElements::Carbon: |
4907 | 0 | return 2.0; |
4908 | 0 | case OBElements::Nitrogen: |
4909 | 0 | return 2.0; |
4910 | 0 | case OBElements::Oxygen: |
4911 | 0 | return 2.0; |
4912 | 0 | case OBElements::Silicon: |
4913 | 0 | return 1.25; |
4914 | 0 | case OBElements::Phosphorus: |
4915 | 0 | return 1.25; |
4916 | 0 | case OBElements::Sulfur: |
4917 | 0 | return 1.25; |
4918 | 0 | } |
4919 | | |
4920 | 0 | return 0.0; |
4921 | 0 | } |
4922 | | |
4923 | | // MMFF part V - TABLE X |
4924 | | double OBForceFieldMMFF94::GetVParam(OBAtom* atom) |
4925 | 0 | { |
4926 | 0 | switch (atom->GetAtomicNum()) { |
4927 | 0 | case OBElements::Carbon: |
4928 | 0 | return 2.12; |
4929 | 0 | case OBElements::Nitrogen: |
4930 | 0 | return 1.5; |
4931 | 0 | case OBElements::Oxygen: |
4932 | 0 | return 0.2; |
4933 | 0 | case OBElements::Silicon: |
4934 | 0 | return 1.22; |
4935 | 0 | case OBElements::Phosphorus: |
4936 | 0 | return 2.4; |
4937 | 0 | case OBElements::Sulfur: |
4938 | 0 | return 0.49; |
4939 | 0 | } |
4940 | | |
4941 | 0 | return 0.0; |
4942 | 0 | } |
4943 | | |
4944 | | // R Blom and A Haaland, J. Mol. Struct., 128, 21-27 (1985) |
4945 | 0 | double OBForceFieldMMFF94::GetCovalentRadius(OBAtom* a) { |
4946 | |
|
4947 | 0 | switch (a->GetAtomicNum()) { |
4948 | 0 | case 1: |
4949 | 0 | return 0.33; // corrected value from MMFF part V |
4950 | 0 | case 5: |
4951 | 0 | return 0.81; |
4952 | 0 | case 6: |
4953 | 0 | return 0.77; // corrected value from MMFF part V |
4954 | 0 | case 7: |
4955 | 0 | return 0.73; |
4956 | 0 | case 8: |
4957 | 0 | return 0.72; |
4958 | 0 | case 9: |
4959 | 0 | return 0.74; |
4960 | 0 | case 13: |
4961 | 0 | return 1.22; |
4962 | 0 | case 14: |
4963 | 0 | return 1.15; |
4964 | 0 | case 15: |
4965 | 0 | return 1.09; |
4966 | 0 | case 16: |
4967 | 0 | return 1.03; |
4968 | 0 | case 17: |
4969 | 0 | return 1.01; |
4970 | 0 | case 31: |
4971 | 0 | return 1.19; |
4972 | 0 | case 32: |
4973 | 0 | return 1.20; |
4974 | 0 | case 33: |
4975 | 0 | return 1.20; |
4976 | 0 | case 34: |
4977 | 0 | return 1.16; |
4978 | 0 | case 35: |
4979 | 0 | return 1.15; |
4980 | 0 | case 44: |
4981 | 0 | return 1.46; |
4982 | 0 | case 50: |
4983 | 0 | return 1.40; |
4984 | 0 | case 51: |
4985 | 0 | return 1.41; |
4986 | 0 | case 52: |
4987 | 0 | return 1.35; |
4988 | 0 | case 53: |
4989 | 0 | return 1.33; |
4990 | 0 | case 81: |
4991 | 0 | return 1.51; |
4992 | 0 | case 82: |
4993 | 0 | return 1.53; |
4994 | 0 | case 83: |
4995 | 0 | return 1.55; |
4996 | 0 | default: |
4997 | 0 | return OBElements::GetCovalentRad(a->GetAtomicNum()); |
4998 | 0 | } |
4999 | 0 | } |
5000 | | |
5001 | | double OBForceFieldMMFF94::GetBondLength(OBAtom* a, OBAtom* b) |
5002 | 0 | { |
5003 | 0 | OBFFParameter *parameter; |
5004 | 0 | double rab; |
5005 | |
|
5006 | 0 | parameter = GetTypedParameter2Atom(GetBondType(a, b), atoi(a->GetType()), atoi(b->GetType()), _ffbondparams); |
5007 | 0 | if (parameter == nullptr) |
5008 | 0 | rab = GetRuleBondLength(a, b); |
5009 | 0 | else |
5010 | 0 | rab = parameter->_dpar[1]; |
5011 | |
|
5012 | 0 | return rab; |
5013 | 0 | } |
5014 | | |
5015 | | // MMFF part V - page 625 |
5016 | | double OBForceFieldMMFF94::GetRuleBondLength(OBAtom* a, OBAtom* b) |
5017 | 0 | { |
5018 | 0 | double r0ab, r0a, r0b, c, Xa, Xb; |
5019 | 0 | int Ha, Hb, BOab; |
5020 | 0 | r0a = GetCovalentRadius(a); |
5021 | 0 | r0b = GetCovalentRadius(b); |
5022 | 0 | Xa = OBElements::GetAllredRochowElectroNeg(a->GetAtomicNum()); |
5023 | 0 | Xb = OBElements::GetAllredRochowElectroNeg(b->GetAtomicNum()); |
5024 | | |
5025 | |
|
5026 | 0 | if (a->GetAtomicNum() == OBElements::Hydrogen) |
5027 | 0 | r0a = 0.33; |
5028 | 0 | if (b->GetAtomicNum() == OBElements::Hydrogen) |
5029 | 0 | r0b = 0.33; |
5030 | |
|
5031 | 0 | if (a->GetAtomicNum() == OBElements::Hydrogen || b->GetAtomicNum() == OBElements::Hydrogen) |
5032 | 0 | c = 0.050; |
5033 | 0 | else |
5034 | 0 | c = 0.085; |
5035 | |
|
5036 | 0 | if (GetMltb(atoi(a->GetType()) == 3)) |
5037 | 0 | Ha = 1; |
5038 | 0 | else if ((GetMltb(atoi(a->GetType())) == 1) || (GetMltb(atoi(a->GetType())) == 2)) |
5039 | 0 | Ha = 2; |
5040 | 0 | else |
5041 | 0 | Ha = 3; |
5042 | |
|
5043 | 0 | if (GetMltb(atoi(b->GetType()) == 3)) |
5044 | 0 | Hb = 1; |
5045 | 0 | else if ((GetMltb(atoi(b->GetType())) == 1) || (GetMltb(atoi(b->GetType())) == 2)) |
5046 | 0 | Hb = 2; |
5047 | 0 | else |
5048 | 0 | Hb = 3; |
5049 | |
|
5050 | 0 | OBBond *ab_bond = a->GetBond(b); |
5051 | 0 | BOab = (ab_bond != nullptr) ? ab_bond->GetBondOrder() : 1; |
5052 | 0 | if ((GetMltb(atoi(a->GetType())) == 1) && (GetMltb(atoi(b->GetType())) == 1)) |
5053 | 0 | BOab = 4; |
5054 | 0 | if ((GetMltb(atoi(a->GetType())) == 1) && (GetMltb(atoi(b->GetType())) == 2)) |
5055 | 0 | BOab = 5; |
5056 | 0 | if ((GetMltb(atoi(a->GetType())) == 2) && (GetMltb(atoi(b->GetType())) == 1)) |
5057 | 0 | BOab = 5; |
5058 | 0 | if (ab_bond != nullptr && ab_bond->IsAromatic()) { |
5059 | 0 | if (!HasPilpSet(atoi(a->GetType())) && !HasPilpSet(atoi(b->GetType()))) { |
5060 | 0 | BOab = 4; |
5061 | 0 | } else { |
5062 | 0 | BOab = 5; |
5063 | 0 | } |
5064 | 0 | } |
5065 | |
|
5066 | 0 | switch (BOab) { |
5067 | 0 | case 5: |
5068 | 0 | r0a -= 0.04; |
5069 | 0 | r0b -= 0.04; |
5070 | 0 | break; |
5071 | 0 | case 4: |
5072 | 0 | r0a -= 0.075; |
5073 | 0 | r0b -= 0.075; |
5074 | 0 | break; |
5075 | 0 | case 3: |
5076 | 0 | r0a -= 0.17; |
5077 | 0 | r0b -= 0.17; |
5078 | 0 | break; |
5079 | 0 | case 2: |
5080 | 0 | r0a -= 0.10; |
5081 | 0 | r0b -= 0.10; |
5082 | 0 | break; |
5083 | 0 | case 1: |
5084 | 0 | if (Ha == 1) |
5085 | 0 | r0a -= 0.08; |
5086 | 0 | if (Ha == 2) |
5087 | 0 | r0a -= 0.03; |
5088 | 0 | if (Hb == 1) |
5089 | 0 | r0b -= 0.08; |
5090 | 0 | if (Hb == 2) |
5091 | 0 | r0b -= 0.03; |
5092 | 0 | } |
5093 | | |
5094 | | /* |
5095 | | cout << "Ha=" << Ha << " Hb=" << Hb << " BOab=" << BOab << endl; |
5096 | | cout << "r0a=" << r0a << " Xa=" << Xa << endl; |
5097 | | cout << "r0b=" << r0b << " Xb=" << Xb << endl; |
5098 | | cout << "r0a + r0b=" << r0a +r0b << endl; |
5099 | | cout << "c=" << c << " |Xa-Xb|=" << fabs(Xa-Xb) << " |Xa-Xb|^1.4=" << pow(fabs(Xa-Xb), 1.4) << endl; |
5100 | | */ |
5101 | 0 | r0ab = r0a + r0b - c * pow(fabs(Xa - Xb), 1.4) - 0.008; |
5102 | |
|
5103 | 0 | return r0ab; |
5104 | 0 | } |
5105 | | |
5106 | | OBFFParameter* OBForceFieldMMFF94::GetParameter1Atom(int a, std::vector<OBFFParameter> ¶meter) |
5107 | 226k | { |
5108 | 226k | OBFFParameter *par; |
5109 | | |
5110 | 226k | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5111 | 0 | if (a == parameter[idx].a) { |
5112 | 0 | par = ¶meter[idx]; |
5113 | 0 | return par; |
5114 | 0 | } |
5115 | | |
5116 | 226k | return nullptr; |
5117 | 226k | } |
5118 | | |
5119 | | OBFFParameter* OBForceFieldMMFF94::GetParameter2Atom(int a, int b, std::vector<OBFFParameter> ¶meter) |
5120 | 1.87k | { |
5121 | 1.87k | OBFFParameter *par; |
5122 | | |
5123 | 1.87k | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5124 | 0 | if (((a == parameter[idx].a) && (b == parameter[idx].b)) || |
5125 | 0 | ((a == parameter[idx].b) && (b == parameter[idx].a))) |
5126 | 0 | { |
5127 | 0 | par = ¶meter[idx]; |
5128 | 0 | return par; |
5129 | 0 | } |
5130 | | |
5131 | 1.87k | return nullptr; |
5132 | 1.87k | } |
5133 | | |
5134 | | OBFFParameter* OBForceFieldMMFF94::GetParameter3Atom(int a, int b, int c, std::vector<OBFFParameter> ¶meter) |
5135 | 0 | { |
5136 | 0 | OBFFParameter *par; |
5137 | |
|
5138 | 0 | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5139 | 0 | if (((a == parameter[idx].a) && (b == parameter[idx].b) && (c == parameter[idx].c)) || |
5140 | 0 | ((a == parameter[idx].c) && (b == parameter[idx].b) && (c == parameter[idx].a))) |
5141 | 0 | { |
5142 | 0 | par = ¶meter[idx]; |
5143 | 0 | return par; |
5144 | 0 | } |
5145 | | |
5146 | 0 | return nullptr; |
5147 | 0 | } |
5148 | | |
5149 | | OBFFParameter* OBForceFieldMMFF94::GetTypedParameter2Atom(int ffclass, int a, int b, std::vector<OBFFParameter> ¶meter) |
5150 | 1.87k | { |
5151 | 1.87k | OBFFParameter *par; |
5152 | | |
5153 | 1.87k | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5154 | 0 | if (((a == parameter[idx].a) && (b == parameter[idx].b) && (ffclass == parameter[idx]._ipar[0])) || |
5155 | 0 | ((a == parameter[idx].b) && (b == parameter[idx].a) && (ffclass == parameter[idx]._ipar[0]))) |
5156 | 0 | { |
5157 | 0 | par = ¶meter[idx]; |
5158 | 0 | return par; |
5159 | 0 | } |
5160 | | |
5161 | 1.87k | return nullptr; |
5162 | 1.87k | } |
5163 | | |
5164 | | OBFFParameter* OBForceFieldMMFF94::GetTypedParameter3Atom(int ffclass, int a, int b, int c, std::vector<OBFFParameter> ¶meter) |
5165 | 0 | { |
5166 | 0 | OBFFParameter *par; |
5167 | |
|
5168 | 0 | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5169 | 0 | if (((a == parameter[idx].a) && (b == parameter[idx].b) && (c == parameter[idx].c) && (ffclass == parameter[idx]._ipar[0])) || |
5170 | 0 | ((a == parameter[idx].c) && (b == parameter[idx].b) && (c == parameter[idx].a) && (ffclass == parameter[idx]._ipar[0])) ) |
5171 | 0 | { |
5172 | 0 | par = ¶meter[idx]; |
5173 | 0 | return par; |
5174 | 0 | } |
5175 | | |
5176 | 0 | return nullptr; |
5177 | 0 | } |
5178 | | |
5179 | | OBFFParameter* OBForceFieldMMFF94::GetTypedParameter4Atom(int ffclass, int a, int b, int c, int d, std::vector<OBFFParameter> ¶meter) |
5180 | 0 | { |
5181 | 0 | OBFFParameter *par; |
5182 | |
|
5183 | 0 | for (unsigned int idx=0; idx < parameter.size(); idx++) |
5184 | 0 | if (((a == parameter[idx].a) && (b == parameter[idx].b) && (c == parameter[idx].c) && |
5185 | 0 | (d == parameter[idx].d) && (ffclass == parameter[idx]._ipar[0])) |
5186 | | /* || ((a == parameter[idx].d) && (b == parameter[idx].c) && (c == parameter[idx].b) && |
5187 | 0 | (d == parameter[idx].a) && (ffclass == parameter[idx]._ipar[0])) */ ) |
5188 | 0 | { |
5189 | 0 | par = ¶meter[idx]; |
5190 | 0 | return par; |
5191 | 0 | } |
5192 | | |
5193 | 0 | return nullptr; |
5194 | 0 | } |
5195 | | |
5196 | | } // end namespace OpenBabel |
5197 | | |
5198 | | //! \file forcefieldmmff94.cpp |
5199 | | //! \brief MMFF94 force field |