/src/openbabel/src/atom.cpp
Line | Count | Source |
1 | | /********************************************************************** |
2 | | atom.cpp - Handle OBAtom class. |
3 | | |
4 | | Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. |
5 | | Some portions Copyright (C) 2001-2008 by Geoffrey R. Hutchison |
6 | | Some portions Copyright (C) 2003 by Michael Banck |
7 | | |
8 | | This file is part of the Open Babel project. |
9 | | For more information, see <http://openbabel.org/> |
10 | | |
11 | | This program is free software; you can redistribute it and/or modify |
12 | | it under the terms of the GNU General Public License as published by |
13 | | the Free Software Foundation version 2 of the License. |
14 | | |
15 | | This program is distributed in the hope that it will be useful, |
16 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 | | GNU General Public License for more details. |
19 | | ***********************************************************************/ |
20 | | #include <openbabel/babelconfig.h> |
21 | | |
22 | | #include <openbabel/atom.h> |
23 | | #include <openbabel/bond.h> |
24 | | #include <openbabel/mol.h> |
25 | | #include <openbabel/obiter.h> |
26 | | #include <openbabel/generic.h> |
27 | | #include <openbabel/molchrg.h> |
28 | | #include <openbabel/ring.h> |
29 | | #include <openbabel/phmodel.h> |
30 | | #include <openbabel/builder.h> |
31 | | #include <openbabel/elements.h> |
32 | | #include <openbabel/chains.h> |
33 | | #include <openbabel/obutil.h> |
34 | | #include <openbabel/residue.h> |
35 | | #include <openbabel/chains.h> |
36 | | |
37 | | #include <openbabel/math/matrix3x3.h> |
38 | | |
39 | | #if !HAVE_STRNCASECMP |
40 | | extern "C" int strncasecmp(const char *s1, const char *s2, size_t n); |
41 | | #endif |
42 | | |
43 | | using namespace std; |
44 | | |
45 | | |
46 | | namespace OpenBabel |
47 | | { |
48 | | OB_EXTERN OBChainsParser chainsparser; |
49 | | /** \class OBAtom atom.h <openbabel/atom.h> |
50 | | \brief Atom class |
51 | | |
52 | | To understand the OBAtom class it is important to state a key |
53 | | decision on which the design was based. The OBAtom class not only |
54 | | holds data, but facilitates extraction of data perceived from both |
55 | | the atom and the molecule. This prevents the OBMol class from |
56 | | becoming overly large and complicated. |
57 | | |
58 | | A number of data extraction methods perform what is called |
59 | | <a href="http://en.wikipedia.org/wiki/Lazy_evaluation">`Lazy Evaluation,'</a> |
60 | | which is essentially on-the-fly evaluation. |
61 | | For example, when an atom is queried as to whether it is cyclic |
62 | | or what it's hybridization state is the information is perceived |
63 | | automatically. The perception of a particular trait is actually |
64 | | performed on the entire molecule the first time it is requested of |
65 | | an atom or bond, and stored for subsequent requests for the same |
66 | | trait of additional atoms or bonds.The OBAtom class is similar to |
67 | | OBMol and the whole of Open Babel in that data access and modification |
68 | | is done through Get and Set methods. |
69 | | |
70 | | The following code demonstrates how to print out the atom numbers, |
71 | | element numbers, and coordinates of a molecule: |
72 | | \code |
73 | | OBMol mol; |
74 | | |
75 | | FOR_ATOMS_OF_MOL(atom, mol) |
76 | | { |
77 | | cout << atom->GetIdx() << ` `; |
78 | | cout << atom->GetAtomicNum() << ` `; |
79 | | cout << atom->GetVector() << endl; |
80 | | } |
81 | | \endcode |
82 | | A number of the property member functions indicate that atoms |
83 | | have some knowledge of their covalently attached neighbor atoms. |
84 | | Bonding information is partly redundant within a molecule in |
85 | | that an OBMol has a complete list of bonds in a molecule, and |
86 | | an OBAtom has a list bonds of which it is a member. The following |
87 | | code demonstrates how an OBAtom uses its bond information to loop |
88 | | over atoms attached to itself: |
89 | | \code |
90 | | OBMol mol; |
91 | | OBAtom *atom; |
92 | | |
93 | | atom = mol.GetAtom(1); |
94 | | FOR_NBORS_OF_ATOM(nbr, atom) |
95 | | { |
96 | | cout << "atom #" << atom->GetIdx() << " is attached to atom #" |
97 | | << nbr->GetIdx() << endl; |
98 | | } |
99 | | \endcode |
100 | | |
101 | | should produce an output like |
102 | | \code |
103 | | atom #1 is attached to atom #2 |
104 | | \endcode |
105 | | */ |
106 | | |
107 | | extern THREAD_LOCAL OBAromaticTyper aromtyper; |
108 | | extern THREAD_LOCAL OBAtomTyper atomtyper; |
109 | | extern THREAD_LOCAL OBPhModel phmodel; |
110 | | OB_EXTERN OBTypeTable ttab; |
111 | | |
112 | | // |
113 | | // OBAtom member functions |
114 | | // |
115 | | |
116 | | OBAtom::OBAtom() |
117 | 148M | { |
118 | 148M | _parent = nullptr; |
119 | 148M | Clear(); |
120 | 148M | } |
121 | | |
122 | | OBAtom::~OBAtom() |
123 | 148M | { |
124 | 148M | if (_residue != nullptr) |
125 | 426 | { |
126 | 426 | _residue->RemoveAtom(this); |
127 | 426 | } |
128 | | /* |
129 | | if (!_vdata.empty()) |
130 | | { |
131 | | vector<OBGenericData*>::iterator m; |
132 | | for (m = _vdata.begin();m != _vdata.end();++m) |
133 | | delete *m; |
134 | | _vdata.clear(); |
135 | | } |
136 | | */ |
137 | 148M | } |
138 | | |
139 | | bool OBAtom::Clear() |
140 | 149M | { |
141 | 149M | _c = nullptr; |
142 | 149M | _cidx = 0; |
143 | 149M | _flags=0; |
144 | 149M | _idx = 0; |
145 | 149M | _hyb = 0; |
146 | 149M | _ele = (char)0; |
147 | 149M | _isotope = 0; |
148 | 149M | _spinmultiplicity=0; // CM 18 Sept 2003 |
149 | 149M | _imph = 0; |
150 | 149M | _fcharge = 0; |
151 | 149M | _type[0] = '\0'; |
152 | 149M | _pcharge = 0.0; |
153 | 149M | _vbond.clear(); |
154 | 149M | _vbond.reserve(4); |
155 | 149M | _residue = nullptr; |
156 | 149M | _id = NoId; |
157 | | |
158 | 149M | return(OBBase::Clear()); |
159 | 149M | } |
160 | | |
161 | | OBAtom &OBAtom::operator=(OBAtom &src) |
162 | | //copy atom information |
163 | | //bond info is not copied here as ptrs may be invalid |
164 | 22.3M | { |
165 | 22.3M | if (this != &src) { |
166 | 22.3M | _idx = src.GetIdx(); |
167 | 22.3M | Duplicate(&src); |
168 | 22.3M | } |
169 | 22.3M | return(*this); |
170 | 22.3M | } |
171 | | |
172 | | void OBAtom::Duplicate(OBAtom *src) |
173 | 22.3M | { |
174 | 22.3M | if (!src) |
175 | 0 | return; |
176 | | |
177 | 22.3M | _hyb = src->_hyb; |
178 | 22.3M | _ele = src->_ele; |
179 | 22.3M | _imph = src->_imph; |
180 | 22.3M | _isotope = src->_isotope; |
181 | 22.3M | _fcharge = src->_fcharge; |
182 | 22.3M | _spinmultiplicity = src->_spinmultiplicity; |
183 | 22.3M | strncpy(_type,src->_type, sizeof(_type) - 1); |
184 | 22.3M | _type[sizeof(_type) - 1] = '\0'; |
185 | 22.3M | _pcharge = src->_pcharge; |
186 | 22.3M | _v = src->GetVector(); |
187 | 22.3M | _flags = src->_flags; |
188 | 22.3M | _residue = nullptr; |
189 | 22.3M | _id = src->_id; |
190 | | |
191 | 22.3M | _vdata.clear(); |
192 | | //Copy all the OBGenericData, providing the new atom |
193 | 22.3M | vector<OBGenericData*>::iterator itr; |
194 | 24.8M | for(itr=src->BeginData();itr!=src->EndData();++itr) |
195 | 2.45M | { |
196 | 2.45M | OBGenericData* pCopiedData = (*itr)->Clone(this); |
197 | 2.45M | SetData(pCopiedData); |
198 | 2.45M | } |
199 | 22.3M | } |
200 | | |
201 | | bool OBAtom::IsConnected(OBAtom *a1) |
202 | 253M | { |
203 | 253M | OBBondIterator i; |
204 | 253M | OBBond *bond; |
205 | | |
206 | 1.36G | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
207 | 1.11G | if (bond->GetBeginAtom() == a1 || bond->GetEndAtom() == a1) |
208 | 12.7M | return(true); |
209 | | |
210 | 240M | return(false); |
211 | 253M | } |
212 | | |
213 | | bool OBAtom::IsOneThree(OBAtom *a1) |
214 | 100 | { |
215 | 100 | OBAtom *atom1,*atom2; |
216 | 100 | OBBond *bond1,*bond2; |
217 | 100 | OBBondIterator i,j; |
218 | 100 | atom1 = this; |
219 | 100 | atom2 = a1; |
220 | | |
221 | 100 | for (bond1 = atom1->BeginBond(i);bond1;bond1 = atom1->NextBond(i)) |
222 | 0 | for (bond2 = atom2->BeginBond(j);bond2;bond2 = atom2->NextBond(j)) |
223 | 0 | if (bond1->GetNbrAtom(atom1) == bond2->GetNbrAtom(atom2)) |
224 | 0 | return(true); |
225 | | |
226 | 100 | return(false); |
227 | 100 | } |
228 | | |
229 | | bool OBAtom::IsOneFour(OBAtom *a1) |
230 | 0 | { |
231 | 0 | OBAtom *atom1,*atom2; |
232 | 0 | OBBond *bond1,*bond2; |
233 | 0 | OBBondIterator i,j; |
234 | 0 | atom1 = this; |
235 | 0 | atom2 = a1; |
236 | |
|
237 | 0 | for (bond1 = atom1->BeginBond(i);bond1;bond1 = atom1->NextBond(i)) |
238 | 0 | for (bond2 = atom2->BeginBond(j);bond2;bond2 = atom2->NextBond(j)) |
239 | 0 | if ((bond1->GetNbrAtom(atom1))->IsConnected(bond2->GetNbrAtom(atom2))) |
240 | 0 | return(true); |
241 | | |
242 | 0 | return(false); |
243 | 0 | } |
244 | | |
245 | | bool OBAtom::IsAxial() |
246 | 0 | { |
247 | 0 | double tor; |
248 | 0 | OBAtom *a,*b,*c; |
249 | 0 | OBBondIterator i,j,k; |
250 | |
|
251 | 0 | for (a = BeginNbrAtom(i);a;a = NextNbrAtom(i)) |
252 | 0 | if (a->GetHyb() == 3 && a->IsInRing() && !(*i)->IsInRing()) |
253 | 0 | for (b = a->BeginNbrAtom(j);b;b = a->NextNbrAtom(j)) |
254 | 0 | if (b != this && b->IsInRing() && b->GetHyb() == 3) |
255 | 0 | for (c = b->BeginNbrAtom(k);c;c = b->NextNbrAtom(k)) |
256 | 0 | if (c != a && c->IsInRing()) |
257 | 0 | { |
258 | 0 | tor = fabs(((OBMol*)GetParent())->GetTorsion(this,a,b,c)); |
259 | 0 | return(tor > 55.0 && tor < 75.0); |
260 | 0 | } |
261 | | |
262 | 0 | return(false); |
263 | 0 | } |
264 | | |
265 | | /** This can be sketched as follows |
266 | | \code |
267 | | '*' |
268 | | \ |
269 | | a=b |
270 | | \endcode |
271 | | where a and b are the 'apha' and 'beta' atoms, respectively and '*' |
272 | | indicates the current atom. |
273 | | **/ |
274 | | bool OBAtom::HasAlphaBetaUnsat(bool includePandS) |
275 | 0 | { |
276 | 0 | OBAtom *a1,*a2; |
277 | 0 | OBBondIterator i,j; |
278 | |
|
279 | 0 | for (a1 = BeginNbrAtom(i);a1;a1 = NextNbrAtom(i)) |
280 | 0 | if (includePandS || (a1->GetAtomicNum() != OBElements::Phosphorus && a1->GetAtomicNum() != OBElements::Sulfur)) |
281 | 0 | for (a2 = a1->BeginNbrAtom(j);a2;a2 = a1->NextNbrAtom(j)) |
282 | 0 | if (a2 != this && ((*j)->GetBondOrder() == 2 || (*j)->GetBondOrder() == 3 || (*j)->GetBondOrder() == 5)) |
283 | 0 | return(true); |
284 | | |
285 | 0 | return(false); |
286 | 0 | } |
287 | | |
288 | | bool OBAtom::HasBondOfOrder(unsigned int order) |
289 | 769k | { |
290 | 769k | OBBond *bond; |
291 | 769k | OBBondIterator i; |
292 | 2.95M | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
293 | 2.50M | if (bond->GetBondOrder() == order) |
294 | 321k | return(true); |
295 | | |
296 | 447k | return(false); |
297 | 769k | } |
298 | | |
299 | | int OBAtom::CountBondsOfOrder(unsigned int order) |
300 | 0 | { |
301 | 0 | int count = 0; |
302 | 0 | OBBond *bond; |
303 | 0 | OBBondIterator i; |
304 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
305 | 0 | if (bond->GetBondOrder() == order) |
306 | 0 | count++; |
307 | |
|
308 | 0 | return(count); |
309 | 0 | } |
310 | | |
311 | | int OBAtom::HighestBondOrder() |
312 | 0 | { |
313 | 0 | unsigned int highest = 0; |
314 | 0 | OBBond *bond; |
315 | 0 | OBBondIterator i; |
316 | 0 | for(bond = BeginBond(i); bond; bond = NextBond(i)) |
317 | 0 | if(bond->GetBondOrder() > highest) |
318 | 0 | highest = bond->GetBondOrder(); |
319 | |
|
320 | 0 | return(highest); |
321 | 0 | } |
322 | | |
323 | | bool OBAtom::HasNonSingleBond() |
324 | 37.2k | { |
325 | 37.2k | OBBond *bond; |
326 | 37.2k | OBBondIterator i; |
327 | 72.9k | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
328 | 40.3k | if (bond->GetBondOrder() != 1) |
329 | 4.65k | return(true); |
330 | | |
331 | 32.6k | return(false); |
332 | 37.2k | } |
333 | | |
334 | | bool OBAtom::IsPolarHydrogen() |
335 | 0 | { |
336 | 0 | if (GetAtomicNum() != OBElements::Hydrogen) |
337 | 0 | return(false); |
338 | | |
339 | 0 | OBAtom *atom; |
340 | 0 | OBBond *bond; |
341 | 0 | OBBondIterator i; |
342 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
343 | 0 | { |
344 | 0 | atom = bond->GetNbrAtom(this); |
345 | 0 | if (atom->GetAtomicNum() == 7) |
346 | 0 | return(true); |
347 | 0 | if (atom->GetAtomicNum() == 8) |
348 | 0 | return(true); |
349 | 0 | if (atom->GetAtomicNum() == 15) |
350 | 0 | return(true); |
351 | 0 | if (atom->GetAtomicNum() == 16) |
352 | 0 | return(true); |
353 | 0 | } |
354 | | |
355 | 0 | return(false); |
356 | 0 | } |
357 | | |
358 | | bool OBAtom::IsNonPolarHydrogen() |
359 | 0 | { |
360 | 0 | if (GetAtomicNum() != OBElements::Hydrogen) |
361 | 0 | return(false); |
362 | | |
363 | 0 | OBAtom *atom; |
364 | 0 | OBBond *bond; |
365 | 0 | OBBondIterator i; |
366 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
367 | 0 | { |
368 | 0 | atom = bond->GetNbrAtom(this); |
369 | 0 | if (atom->GetAtomicNum() == 6) |
370 | 0 | return(true); |
371 | 0 | } |
372 | | |
373 | 0 | return(false); |
374 | 0 | } |
375 | | |
376 | | vector3 &OBAtom::GetVector() |
377 | 1.87G | { |
378 | 1.87G | if (!_c) |
379 | 1.83G | return(_v); |
380 | | |
381 | 39.1M | _v.Set((*_c)[_cidx],(*_c)[_cidx+1],(*_c)[_cidx+2]); |
382 | 39.1M | return(_v); |
383 | 1.87G | } |
384 | | |
385 | | const vector3 &OBAtom::GetVector() const |
386 | 0 | { |
387 | 0 | if (!_c) |
388 | 0 | return(_v); |
389 | | |
390 | 0 | _v.Set((*_c)[_cidx],(*_c)[_cidx+1],(*_c)[_cidx+2]); |
391 | 0 | return(_v); |
392 | 0 | } |
393 | | |
394 | | void OBAtom::SetVector() |
395 | 1.70G | { |
396 | | // obAssert(_c); |
397 | 1.70G | if (_c) |
398 | 1.70G | _v.Set((*_c)[_cidx],(*_c)[_cidx+1],(*_c)[_cidx+2]); |
399 | 1.70G | } |
400 | | |
401 | | void OBAtom::SetVector(const vector3 &v) |
402 | 1.61M | { |
403 | 1.61M | if (!_c) |
404 | 347k | _v = v; |
405 | 1.26M | else |
406 | 1.26M | { |
407 | 1.26M | (*_c)[_cidx ] = v.x(); |
408 | 1.26M | (*_c)[_cidx+1] = v.y(); |
409 | 1.26M | (*_c)[_cidx+2] = v.z(); |
410 | 1.26M | } |
411 | 1.61M | } |
412 | | |
413 | | void OBAtom::SetVector(const double v_x,const double v_y,const double v_z) |
414 | 1.52M | { |
415 | 1.52M | if (!_c) |
416 | 1.52M | _v.Set(v_x,v_y,v_z); |
417 | 0 | else |
418 | 0 | { |
419 | 0 | (*_c)[_cidx ] = v_x; |
420 | 0 | (*_c)[_cidx+1] = v_y; |
421 | 0 | (*_c)[_cidx+2] = v_z; |
422 | 0 | } |
423 | 1.52M | } |
424 | | |
425 | | void OBAtom::SetType(const char *type) |
426 | 12.7M | { |
427 | 12.7M | strncpy(_type,type, sizeof(_type) - 1); |
428 | 12.7M | _type[sizeof(_type) - 1] = '\0'; |
429 | 12.7M | if (_ele == 1 && type[0] == 'D') |
430 | 456 | _isotope = 2; |
431 | 12.7M | } |
432 | | |
433 | | void OBAtom::SetType(const string &type) |
434 | 16.9k | { |
435 | 16.9k | strncpy(_type,type.c_str(), sizeof(_type) - 1); |
436 | 16.9k | _type[sizeof(_type) - 1] = '\0'; |
437 | 16.9k | if (_ele == 1 && type[0] == 'D') |
438 | 0 | _isotope = 2; |
439 | 16.9k | } |
440 | | |
441 | | void OBAtom::SetIsotope(unsigned int iso) |
442 | 488k | { |
443 | 488k | _isotope = iso; |
444 | 488k | } |
445 | | |
446 | | OBResidue *OBAtom::GetResidue() |
447 | 1.74M | { |
448 | 1.74M | OBMol *mol = this->GetParent(); |
449 | 1.74M | if (!mol->HasChainsPerceived()) |
450 | 0 | chainsparser.PerceiveChains(*mol); |
451 | | |
452 | 1.74M | return _residue; |
453 | 1.74M | } |
454 | | |
455 | | double OBAtom::GetAtomicMass() const |
456 | 433k | { |
457 | 433k | if (_isotope == 0) |
458 | 407k | return OBElements::GetMass(_ele); |
459 | 26.3k | else |
460 | 26.3k | return OBElements::GetExactMass(_ele, _isotope); |
461 | 433k | } |
462 | | |
463 | | double OBAtom::GetExactMass() const |
464 | 433k | { |
465 | 433k | return OBElements::GetExactMass(_ele, _isotope); |
466 | 433k | } |
467 | | |
468 | | char *OBAtom::GetType() |
469 | 888k | { |
470 | 888k | OBMol *mol = (OBMol*)GetParent(); |
471 | 888k | if (mol) |
472 | 888k | if (!mol->HasAtomTypesPerceived()) |
473 | 194 | atomtyper.AssignTypes(*((OBMol*)GetParent())); |
474 | | |
475 | 888k | if (strlen(_type) == 0) // Somehow we still don't have a type! |
476 | 4.67k | { |
477 | 4.67k | char num[6]; |
478 | 4.67k | string fromType = ttab.GetFromType(); // save previous types |
479 | 4.67k | string toType = ttab.GetToType(); |
480 | | |
481 | 4.67k | ttab.SetFromType("ATN"); |
482 | 4.67k | ttab.SetToType("INT"); |
483 | 4.67k | snprintf(num, 6, "%d", GetAtomicNum()); |
484 | 4.67k | ttab.Translate(_type, num); |
485 | | |
486 | 4.67k | ttab.SetFromType(fromType.c_str()); |
487 | 4.67k | ttab.SetToType(toType.c_str()); |
488 | 4.67k | } |
489 | 888k | if (_ele == 1 && _isotope == 2) |
490 | 596 | snprintf(_type, 6, "%s", "D"); |
491 | | |
492 | 888k | return(_type); |
493 | 888k | } |
494 | | |
495 | | unsigned int OBAtom::GetHyb() const |
496 | 33.1M | { |
497 | | //hybridization is assigned when atoms are typed |
498 | 33.1M | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
499 | 33.1M | if (mol && !mol->HasHybridizationPerceived()) |
500 | 302k | atomtyper.AssignHyb(*mol); |
501 | | |
502 | 33.1M | return(_hyb); |
503 | 33.1M | } |
504 | | |
505 | | |
506 | | unsigned int OBAtom::GetHvyDegree() const |
507 | 775k | { |
508 | 775k | unsigned int count=0; |
509 | | |
510 | 775k | OBBond *bond; |
511 | 775k | OBBondIterator i; |
512 | 2.47M | for (bond = ((OBAtom*)this)->BeginBond(i); bond; bond = ((OBAtom*)this)->NextBond(i)) |
513 | 1.69M | if (bond->GetNbrAtom((OBAtom*)this)->GetAtomicNum() != OBElements::Hydrogen) |
514 | 1.27M | count++; |
515 | | |
516 | 775k | return(count); |
517 | 775k | } |
518 | | |
519 | | unsigned int OBAtom::GetHeteroDegree() const |
520 | 0 | { |
521 | 0 | unsigned int count=0; |
522 | 0 | OBBond *bond; |
523 | 0 | OBBondIterator i; |
524 | 0 | for (bond = ((OBAtom*)this)->BeginBond(i);bond;bond = ((OBAtom*)this)->NextBond(i)) |
525 | 0 | if (bond->GetNbrAtom((OBAtom*)this)->IsHeteroatom()) |
526 | 0 | count++; |
527 | |
|
528 | 0 | return((unsigned int)count); |
529 | 0 | } |
530 | | |
531 | | double OBAtom::GetPartialCharge() |
532 | 994k | { |
533 | 994k | if (!GetParent()) |
534 | 0 | return(_pcharge); |
535 | 994k | if (!((OBMol*)GetParent())->AutomaticPartialCharge()) |
536 | 964k | return(_pcharge); |
537 | | |
538 | 29.8k | if (!((OBMol*)GetParent())->HasPartialChargesPerceived()) |
539 | 1.05k | { |
540 | | //seed partial charges are set in the atom typing procedure |
541 | 1.05k | OBAtom *atom; |
542 | 1.05k | OBMol *mol = (OBMol*)GetParent(); |
543 | 1.05k | vector<OBAtom*>::iterator i; |
544 | 130k | for (atom = mol->BeginAtom(i); atom; atom = mol->NextAtom(i)) |
545 | 129k | atom->SetPartialCharge(0.0); |
546 | | |
547 | 1.05k | phmodel.AssignSeedPartialCharge(*((OBMol*)GetParent())); |
548 | 1.05k | OBGastChrg gc; |
549 | 1.05k | gc.AssignPartialCharges(*((OBMol*)GetParent())); |
550 | 1.05k | } |
551 | | |
552 | 29.8k | return(_pcharge); |
553 | 994k | } |
554 | | |
555 | | //! Returns true if nitrogen is part of an amide |
556 | | bool OBAtom::IsAmideNitrogen() |
557 | 0 | { |
558 | 0 | if (GetAtomicNum() != OBElements::Nitrogen) |
559 | 0 | return(false); |
560 | | |
561 | 0 | OBAtom *nbratom,*atom; |
562 | 0 | OBBond *abbond,*bond; |
563 | |
|
564 | 0 | OBBondIterator i,j; |
565 | 0 | atom = this; |
566 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
567 | 0 | { |
568 | 0 | nbratom = bond->GetNbrAtom(atom); |
569 | 0 | for (abbond = nbratom->BeginBond(j);abbond;abbond = nbratom->NextBond(j)) |
570 | 0 | if (abbond->GetBondOrder() == 2 && |
571 | 0 | (((abbond->GetNbrAtom(nbratom))->GetAtomicNum() == 8) || |
572 | 0 | ((abbond->GetNbrAtom(nbratom))->GetAtomicNum() == 16))) |
573 | 0 | return(true); |
574 | 0 | } |
575 | | |
576 | 0 | return(false); |
577 | 0 | } |
578 | | |
579 | | bool OBAtom::IsAromaticNOxide() |
580 | 0 | { |
581 | 0 | if (GetAtomicNum() != OBElements::Nitrogen || !IsAromatic()) |
582 | 0 | return(false); |
583 | | |
584 | 0 | OBAtom *atom; |
585 | 0 | OBBondIterator i; |
586 | |
|
587 | 0 | for (atom = BeginNbrAtom(i);atom;atom = NextNbrAtom(i)) |
588 | 0 | if (atom->GetAtomicNum() == OBElements::Oxygen && !(*i)->IsInRing() && (*i)->GetBondOrder() == 2) |
589 | 0 | return(true); |
590 | | |
591 | 0 | return(false); |
592 | 0 | } |
593 | | |
594 | | bool OBAtom::IsCarboxylOxygen() |
595 | 496k | { |
596 | 496k | if (GetAtomicNum() != OBElements::Oxygen) |
597 | 484k | return(false); |
598 | 12.0k | if (GetHvyDegree() != 1) |
599 | 7.13k | return(false); |
600 | | |
601 | 4.95k | OBAtom *atom; |
602 | 4.95k | OBBond *bond; |
603 | 4.95k | OBBondIterator i; |
604 | | |
605 | 4.95k | atom = nullptr; |
606 | 8.92k | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
607 | 4.95k | if ((bond->GetNbrAtom(this))->GetAtomicNum() == OBElements::Carbon) |
608 | 992 | { |
609 | 992 | atom = bond->GetNbrAtom(this); |
610 | 992 | break; |
611 | 992 | } |
612 | 4.95k | if (!atom) |
613 | 3.96k | return(false); |
614 | 992 | if (!(atom->CountFreeOxygens() == 2) |
615 | 919 | && !(atom->CountFreeOxygens() == 1 && atom->CountFreeSulfurs() == 1)) |
616 | 905 | return(false); |
617 | | |
618 | | //atom is connected to a carbon that has a total |
619 | | //of 2 attached free oxygens or 1 free oxygen and 1 free sulfur |
620 | 87 | return(true); |
621 | 992 | } |
622 | | |
623 | | bool OBAtom::IsPhosphateOxygen() |
624 | 0 | { |
625 | 0 | if (GetAtomicNum() != OBElements::Oxygen) |
626 | 0 | return(false); |
627 | 0 | if (GetHvyDegree() != 1) |
628 | 0 | return(false); |
629 | 0 | OBAtom *atom; |
630 | 0 | OBBond *bond; |
631 | 0 | OBBondIterator i; |
632 | |
|
633 | 0 | atom = nullptr; |
634 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
635 | 0 | if ((bond->GetNbrAtom(this))->GetAtomicNum() == OBElements::Phosphorus) |
636 | 0 | { |
637 | 0 | atom = bond->GetNbrAtom(this); |
638 | 0 | break; |
639 | 0 | } |
640 | 0 | if (!atom) |
641 | 0 | return(false); |
642 | 0 | if (atom->CountFreeOxygens() > 2) |
643 | 0 | return(true); |
644 | | |
645 | | //atom is connected to a carbon that has a total |
646 | | //of 2 attached free oxygens |
647 | 0 | return(false); |
648 | 0 | } |
649 | | |
650 | | bool OBAtom::IsSulfateOxygen() |
651 | 0 | { |
652 | 0 | if (GetAtomicNum() != OBElements::Oxygen) |
653 | 0 | return(false); |
654 | 0 | if (GetHvyDegree() != 1) |
655 | 0 | return(false); |
656 | | |
657 | 0 | OBAtom *atom; |
658 | 0 | OBBond *bond; |
659 | 0 | OBBondIterator i; |
660 | |
|
661 | 0 | atom = nullptr; |
662 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
663 | 0 | if ((bond->GetNbrAtom(this))->GetAtomicNum() == OBElements::Sulfur) |
664 | 0 | { |
665 | 0 | atom = bond->GetNbrAtom(this); |
666 | 0 | break; |
667 | 0 | } |
668 | 0 | if (!atom) |
669 | 0 | return(false); |
670 | 0 | if (atom->CountFreeOxygens() < 3) |
671 | 0 | return(false); |
672 | | |
673 | | //atom is connected to a carbon that has a total |
674 | | //of 2 attached free oxygens |
675 | 0 | return(true); |
676 | 0 | } |
677 | | |
678 | | // Helper function for IsHBondAcceptor |
679 | | static bool IsSulfoneOxygen(OBAtom* atm) |
680 | | // Stefano Forli |
681 | | //atom is connected to a sulfur that has a total |
682 | | //of 2 attached free oxygens, and it's not a sulfonamide |
683 | | //e.g. C-SO2-C |
684 | | // Is this atom an oxygen in a sulfone(R1 - SO2 - R2) group ? |
685 | 0 | { |
686 | 0 | if (atm->GetAtomicNum() != OBElements::Oxygen) |
687 | 0 | return(false); |
688 | 0 | if (atm->GetHvyDegree() != 1){ |
689 | | //cerr << "sulfone> O valence is not 1\n"; |
690 | 0 | return(false); |
691 | 0 | } |
692 | | |
693 | 0 | OBAtom *nbr = nullptr; |
694 | 0 | OBBond *bond1,*bond2; |
695 | 0 | OBBondIterator i,j; |
696 | | |
697 | | // searching for attached sulfur |
698 | 0 | for (bond1 = atm->BeginBond(i); bond1; bond1 = atm->NextBond(i)) |
699 | 0 | if ((bond1->GetNbrAtom(atm))->GetAtomicNum() == OBElements::Sulfur) |
700 | 0 | { nbr = bond1->GetNbrAtom(atm); |
701 | 0 | break; } |
702 | 0 | if (!nbr){ |
703 | | //cerr << "sulfone> atom null\n" ; |
704 | 0 | return(false); } |
705 | | |
706 | | // check for sulfate |
707 | | //cerr << "sulfone> If we're here... " << atom->GetAtomicNum() <<"\n" << atom->GetAtomicNum() == OBElements::Sulfur << "\n"; |
708 | | //cerr << "sulfone> number of free oxygens:" << atom->CountFreeOxygens() << "\n"; |
709 | 0 | if (nbr->CountFreeOxygens() != 2){ |
710 | | //cerr << "sulfone> count of free oxygens not 2" << atom->CountFreeOxygens() << '\n' ; |
711 | 0 | return(false); } |
712 | | |
713 | | // check for sulfonamide |
714 | 0 | for (bond2 = nbr->BeginBond(j);bond2;bond2 = nbr->NextBond(j)){ |
715 | | //cerr<<"NEIGH: " << (bond2->GetNbrAtom(atom))->GetAtomicNum()<<"\n"; |
716 | 0 | if ((bond2->GetNbrAtom(nbr))->GetAtomicNum() == OBElements::Nitrogen){ |
717 | | //cerr << "sulfone> sulfonamide null\n" ; |
718 | 0 | return(false);}} |
719 | | //cerr << "sulfone> none of the above\n"; |
720 | 0 | return(true); // true sulfone |
721 | 0 | } |
722 | | |
723 | | |
724 | | |
725 | | |
726 | | |
727 | | bool OBAtom::IsNitroOxygen() |
728 | 0 | { |
729 | 0 | if (GetAtomicNum() != OBElements::Oxygen) |
730 | 0 | return(false); |
731 | 0 | if (GetHvyDegree() != 1) |
732 | 0 | return(false); |
733 | | |
734 | 0 | OBAtom *atom; |
735 | 0 | OBBond *bond; |
736 | 0 | OBBondIterator i; |
737 | |
|
738 | 0 | atom = nullptr; |
739 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) |
740 | 0 | if ((bond->GetNbrAtom(this))->GetAtomicNum() == OBElements::Nitrogen) |
741 | 0 | { |
742 | 0 | atom = bond->GetNbrAtom(this); |
743 | 0 | break; |
744 | 0 | } |
745 | 0 | if (!atom) |
746 | 0 | return(false); |
747 | 0 | if (atom->CountFreeOxygens() != 2) |
748 | 0 | return(false); |
749 | | |
750 | | //atom is connected to a nitrogen that has a total |
751 | | //of 2 attached free oxygens |
752 | 0 | return(true); |
753 | 0 | } |
754 | | |
755 | | bool OBAtom::IsHeteroatom() |
756 | 0 | { |
757 | 0 | switch(GetAtomicNum()) |
758 | 0 | { |
759 | 0 | case 7: |
760 | 0 | case 8: |
761 | 0 | case 15: |
762 | 0 | case 16: |
763 | 0 | case 33: |
764 | 0 | case 34: |
765 | 0 | case 51: |
766 | 0 | case 52: |
767 | 0 | case 83: |
768 | 0 | case 84: |
769 | 0 | return(true); |
770 | 0 | } |
771 | 0 | return(false); |
772 | 0 | } |
773 | | |
774 | | bool OBAtom::IsAromatic() const |
775 | 280M | { |
776 | 280M | OBMol *mol = ((OBAtom*)this)->GetParent(); |
777 | 280M | if (!mol->HasAromaticPerceived()) |
778 | 17.0k | aromtyper.AssignAromaticFlags(*mol); |
779 | | |
780 | 280M | if (((OBAtom*)this)->HasFlag(OB_AROMATIC_ATOM)) |
781 | 128M | return true; |
782 | | |
783 | 151M | return false; |
784 | 280M | } |
785 | | |
786 | | bool OBAtom::IsInRing() const |
787 | 390M | { |
788 | 390M | OBMol *mol = ((OBAtom*)this)->GetParent(); |
789 | 390M | if (!mol->HasRingAtomsAndBondsPerceived()) |
790 | 7.58k | mol->FindRingAtomsAndBonds(); |
791 | | |
792 | 390M | if (((OBAtom*)this)->HasFlag(OB_RING_ATOM)) |
793 | 62.1M | return true; |
794 | | |
795 | 328M | return false; |
796 | 390M | } |
797 | | |
798 | | //! @todo |
799 | | bool OBAtom::IsChiral() |
800 | 0 | { |
801 | 0 | OBMol *mol = (OBMol*) GetParent(); |
802 | 0 | OBStereoFacade stereoFacade(mol); |
803 | 0 | return stereoFacade.HasTetrahedralStereo(_id); |
804 | 0 | } |
805 | | |
806 | | bool OBAtom::IsPeriodic() const |
807 | 1.90M | { |
808 | 1.90M | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
809 | 1.90M | if (mol == nullptr) |
810 | 0 | return false; |
811 | 1.90M | return mol->IsPeriodic(); |
812 | 1.90M | } |
813 | | |
814 | | bool OBAtom::IsInRingSize(int size) const |
815 | 2.49M | { |
816 | 2.49M | vector<OBRing*> rlist; |
817 | 2.49M | vector<OBRing*>::iterator i; |
818 | | |
819 | 2.49M | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
820 | 2.49M | if (!mol->HasSSSRPerceived()) |
821 | 170 | mol->FindSSSR(); |
822 | | |
823 | 2.49M | if (!((OBAtom*)this)->HasFlag(OB_RING_ATOM)) |
824 | 1.48M | return(false); |
825 | | |
826 | 1.00M | rlist = mol->GetSSSR(); |
827 | 34.8M | for (i = rlist.begin();i != rlist.end();++i) |
828 | 34.1M | if ((*i)->IsInRing(GetIdx()) && static_cast<int>((*i)->Size()) == size) |
829 | 345k | return(true); |
830 | | |
831 | 658k | return(false); |
832 | 1.00M | } |
833 | | |
834 | | unsigned int OBAtom::MemberOfRingCount() const |
835 | 503k | { |
836 | 503k | vector<OBRing*> rlist; |
837 | 503k | vector<OBRing*>::iterator i; |
838 | 503k | unsigned int count=0; |
839 | | |
840 | 503k | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
841 | | |
842 | 503k | if (!mol->HasSSSRPerceived()) |
843 | 42 | mol->FindSSSR(); |
844 | | |
845 | 503k | if (!((OBAtom*)this)->IsInRing()) |
846 | 289k | return(0); |
847 | | |
848 | 213k | rlist = mol->GetSSSR(); |
849 | | |
850 | 3.00M | for (i = rlist.begin();i != rlist.end();++i) |
851 | 2.79M | if ((*i)->IsInRing(GetIdx())) |
852 | 13.0k | count++; |
853 | | |
854 | 213k | return((unsigned int)count); |
855 | 503k | } |
856 | | |
857 | | unsigned int OBAtom::MemberOfRingSize() const |
858 | 0 | { |
859 | 0 | vector<OBRing*> rlist; |
860 | 0 | vector<OBRing*>::iterator i; |
861 | |
|
862 | 0 | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
863 | |
|
864 | 0 | if (!mol->HasSSSRPerceived()) |
865 | 0 | mol->FindSSSR(); |
866 | |
|
867 | 0 | if (!((OBAtom*)this)->IsInRing()) |
868 | 0 | return(0); |
869 | | |
870 | 0 | rlist = mol->GetSSSR(); |
871 | |
|
872 | 0 | for (i = rlist.begin();i != rlist.end();++i) |
873 | 0 | if ((*i)->IsInRing(GetIdx())) |
874 | 0 | return((*i)->Size()); |
875 | | |
876 | 0 | return(0); |
877 | 0 | } |
878 | | |
879 | | unsigned int OBAtom::CountRingBonds() const |
880 | 13.5k | { |
881 | 13.5k | unsigned int count = 0; |
882 | 13.5k | OBBond *bond; |
883 | 13.5k | OBBondIterator i; |
884 | | |
885 | 13.5k | for (bond = ((OBAtom*)this)->BeginBond(i); |
886 | 40.5k | bond; |
887 | 26.9k | bond = ((OBAtom*)this)->NextBond(i)) |
888 | 26.9k | { |
889 | 26.9k | if (bond->IsInRing()) |
890 | 13.2k | count++; |
891 | 26.9k | } |
892 | 13.5k | return count; |
893 | 13.5k | } |
894 | | |
895 | | double OBAtom::SmallestBondAngle() |
896 | 419k | { |
897 | 419k | OBAtom *b, *c; |
898 | 419k | vector3 v1, v2; |
899 | 419k | double degrees, minDegrees; |
900 | | // vector<OBAtom*>::iterator i; |
901 | 419k | OBBondIterator j,k; |
902 | | |
903 | 419k | minDegrees = 360.0; |
904 | | |
905 | 1.19M | for (b = BeginNbrAtom(j); b; b = NextNbrAtom(j)) |
906 | 779k | { |
907 | 779k | k = j; |
908 | 2.10M | for (c = NextNbrAtom(k); c; c = NextNbrAtom(k)) |
909 | 1.32M | { |
910 | 1.32M | degrees = b->GetAngle((OBAtom*)this, c); |
911 | 1.32M | if (degrees < minDegrees) |
912 | 86.9k | minDegrees = degrees; |
913 | 1.32M | } |
914 | 779k | } |
915 | 419k | return minDegrees; |
916 | 419k | } |
917 | | |
918 | | double OBAtom::AverageBondAngle() |
919 | 538k | { |
920 | 538k | OBAtom *b, *c; |
921 | 538k | vector3 v1, v2; |
922 | 538k | double degrees, avgDegrees; |
923 | | // vector<OBAtom*>::iterator i; |
924 | 538k | OBBondIterator j,k; |
925 | 538k | int n=0; |
926 | | |
927 | 538k | avgDegrees = 0.0; |
928 | | |
929 | 879k | for (b = BeginNbrAtom(j); b; b = NextNbrAtom(j)) |
930 | 340k | { |
931 | 340k | k = j; |
932 | 919k | for (c = NextNbrAtom(k); c; c = NextNbrAtom(k)) |
933 | 578k | { |
934 | 578k | degrees = b->GetAngle((OBAtom*)this, c); |
935 | 578k | avgDegrees += degrees; |
936 | 578k | n++; |
937 | 578k | } |
938 | 340k | } |
939 | | |
940 | 538k | if (n >=1) |
941 | 75.3k | avgDegrees /= n; |
942 | | |
943 | 538k | return avgDegrees; |
944 | 538k | } |
945 | | |
946 | | unsigned int OBAtom::CountFreeOxygens() const |
947 | 4.66k | { |
948 | 4.66k | unsigned int count = 0; |
949 | 4.66k | OBAtom *atom; |
950 | 4.66k | OBBond *bond; |
951 | 4.66k | OBBondIterator i; |
952 | | |
953 | 17.2k | for (bond = ((OBAtom*)this)->BeginBond(i);bond;bond = ((OBAtom*)this)->NextBond(i)) |
954 | 12.6k | { |
955 | 12.6k | atom = bond->GetNbrAtom((OBAtom*)this); |
956 | 12.6k | if (atom->GetAtomicNum() == OBElements::Oxygen && atom->GetHvyDegree() == 1) |
957 | 2.36k | count++; |
958 | 12.6k | } |
959 | | |
960 | 4.66k | return(count); |
961 | 4.66k | } |
962 | | |
963 | | unsigned int OBAtom::CountFreeSulfurs() const |
964 | 839 | { |
965 | 839 | unsigned int count = 0; |
966 | 839 | OBAtom *atom; |
967 | 839 | OBBond *bond; |
968 | 839 | OBBondIterator i; |
969 | | |
970 | 3.11k | for (bond = ((OBAtom*)this)->BeginBond(i);bond;bond = ((OBAtom*)this)->NextBond(i)) |
971 | 2.27k | { |
972 | 2.27k | atom = bond->GetNbrAtom((OBAtom*)this); |
973 | 2.27k | if (atom->GetAtomicNum() == OBElements::Sulfur && atom->GetHvyDegree() == 1) |
974 | 20 | count++; |
975 | 2.27k | } |
976 | | |
977 | 839 | return(count); |
978 | 839 | } |
979 | | |
980 | | unsigned int OBAtom::GetExplicitValence() const |
981 | 42.7M | { |
982 | 42.7M | unsigned int bosum = 0; |
983 | | |
984 | 42.7M | OBBondIterator i; |
985 | 692M | for (OBBond *bond = ((OBAtom*)this)->BeginBond(i); bond; bond = ((OBAtom*)this)->NextBond(i)) |
986 | 649M | bosum += bond->GetBondOrder(); |
987 | | |
988 | 42.7M | return bosum; |
989 | 42.7M | } |
990 | | |
991 | | unsigned int OBAtom::GetTotalValence() const |
992 | 955k | { |
993 | 955k | return GetExplicitValence() + _imph; |
994 | 955k | } |
995 | | |
996 | | unsigned int OBAtom::ExplicitHydrogenCount(bool ExcludeIsotopes) const |
997 | 43.6M | { |
998 | | //If ExcludeIsotopes is true, H atoms with _isotope!=0 are not included. |
999 | | //This excludes D, T and H when _isotope exlicitly set to 1 rather than the default 0. |
1000 | 43.6M | int numH=0; |
1001 | 43.6M | OBAtom *atom; |
1002 | 43.6M | OBBondIterator i; |
1003 | 321M | for (atom = ((OBAtom*)this)->BeginNbrAtom(i);atom;atom = ((OBAtom*)this)->NextNbrAtom(i)) |
1004 | 277M | if (atom->GetAtomicNum() == OBElements::Hydrogen && !(ExcludeIsotopes && atom->GetIsotope()!=0)) |
1005 | 3.82M | numH++; |
1006 | | |
1007 | 43.6M | return(numH); |
1008 | 43.6M | } |
1009 | | |
1010 | | /** |
1011 | | * The returned values count whole lone pairs, so the acid count is the number of |
1012 | | * electron pairs desired and the base count is the number of electron pairs |
1013 | | * available. |
1014 | | * |
1015 | | @verbatim |
1016 | | Algorithm from: |
1017 | | Clark, A. M. Accurate Specification of Molecular Structures: The Case for |
1018 | | Zero-Order Bonds and Explicit Hydrogen Counting. Journal of Chemical Information |
1019 | | and Modeling, 51, 3149-3157 (2011). http://pubs.acs.org/doi/abs/10.1021/ci200488k |
1020 | | @endverbatim |
1021 | | */ |
1022 | | pair<int, int> OBAtom::LewisAcidBaseCounts() const |
1023 | 0 | { |
1024 | | // TODO: Is this data stored elsewhere? |
1025 | | // The number of valence electrons in a free atom |
1026 | 0 | const int VALENCE[113] = {0,1,2,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,10, |
1027 | 0 | 11,12,3,4,5,6,7,8,1,2,3,4,5,6,7,8,9,10,11,12,3,4,5,6,7,8,1,2, |
1028 | 0 | 4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,5,6,7,8,9,10,11,12,3,4,5,6,7, |
1029 | 0 | 8,1,1,4,4,4,4,4,4,4,4,4,4,4,4,4,4,3,4,5,6,7,8,9,10,11,12}; |
1030 | | // The number of electrons required to make up a full valence shell |
1031 | 0 | const int SHELL[113] = {0,2,2,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,18,18,18,18,18,18, |
1032 | 0 | 18,18,18,18,8,8,8,8,8,8,8,8,18,18,18,18,18,18,18,18,18,18,8, |
1033 | 0 | 8,8,8,8,8,8,8,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18, |
1034 | 0 | 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,8,8,18,18,18,18, |
1035 | 0 | 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18}; |
1036 | |
|
1037 | 0 | pair<int, int> counts; |
1038 | 0 | int N = GetAtomicNum(); |
1039 | 0 | if (N == 0 || N > 112) { |
1040 | 0 | counts.first = 0; |
1041 | 0 | counts.second = 0; |
1042 | 0 | } else { |
1043 | 0 | int S = SHELL[N]; |
1044 | 0 | int V = VALENCE[N]; |
1045 | 0 | int C = GetFormalCharge(); |
1046 | 0 | int B = GetTotalValence(); |
1047 | | // TODO: Do we actually want to divide by 2 here? (counting pairs instead of single) |
1048 | 0 | counts.first = (S - V - B + C) / 2; // Acid: Number of electrons pairs desired |
1049 | 0 | counts.second = (V - B - C) / 2; // Base: Number of electrons pairs available |
1050 | 0 | } |
1051 | 0 | return counts; |
1052 | 0 | } |
1053 | | |
1054 | | bool OBAtom::DeleteBond(OBBond *bond) |
1055 | 8.81M | { |
1056 | 8.81M | OBBondIterator i; |
1057 | 48.9M | for (i = _vbond.begin();i != _vbond.end();++i) |
1058 | 48.9M | if ((OBBond*)bond == *i) |
1059 | 8.81M | { |
1060 | 8.81M | _vbond.erase(i); |
1061 | 8.81M | return(true); |
1062 | 8.81M | } |
1063 | 0 | return(false); |
1064 | 8.81M | } |
1065 | | |
1066 | | bool OBAtom::MatchesSMARTS(const char *pattern) |
1067 | 0 | { |
1068 | 0 | OBMol *mol = (OBMol*)((OBAtom*)this)->GetParent(); |
1069 | 0 | vector<vector<int> > mlist; |
1070 | 0 | vector<vector<int> >::iterator l; |
1071 | |
|
1072 | 0 | OBSmartsPattern test; |
1073 | 0 | test.Init(pattern); |
1074 | 0 | if (test.Match(*mol)) |
1075 | 0 | { |
1076 | 0 | mlist = test.GetUMapList(); |
1077 | 0 | for (l = mlist.begin(); l != mlist.end(); ++l) |
1078 | 0 | if (GetIdx() == mol->GetAtom((*l)[0])->GetIdx()) |
1079 | 0 | return true; |
1080 | 0 | } |
1081 | 0 | return false; |
1082 | 0 | } |
1083 | | |
1084 | | OBBond *OBAtom::BeginBond(OBBondIterator &i) |
1085 | 643M | { |
1086 | 643M | i = _vbond.begin(); |
1087 | 643M | return i == _vbond.end() ? nullptr : (OBBond*)*i; |
1088 | 643M | } |
1089 | | |
1090 | | OBBond *OBAtom::NextBond(OBBondIterator &i) |
1091 | 2.76G | { |
1092 | 2.76G | i++; |
1093 | 2.76G | return i == _vbond.end() ? nullptr : (OBBond*)*i; |
1094 | 2.76G | } |
1095 | | |
1096 | | OBAtom *OBAtom::BeginNbrAtom(OBBondIterator &i) |
1097 | 633M | { |
1098 | 633M | i = _vbond.begin(); |
1099 | 633M | return i != _vbond.end() ? ((OBBond*) *i)->GetNbrAtom(this) : nullptr; |
1100 | 633M | } |
1101 | | |
1102 | | OBAtom *OBAtom::NextNbrAtom(OBBondIterator &i) |
1103 | 8.36G | { |
1104 | 8.36G | i++; |
1105 | 8.36G | return i != _vbond.end() ? ((OBBond*) *i)->GetNbrAtom(this) : nullptr; |
1106 | 8.36G | } |
1107 | | |
1108 | | double OBAtom::GetDistance(OBAtom *b) |
1109 | 617 | { |
1110 | 617 | if (!IsPeriodic()) |
1111 | 617 | { |
1112 | 617 | return(( this->GetVector() - b->GetVector() ).length()); |
1113 | 617 | } |
1114 | 0 | else |
1115 | 0 | { |
1116 | 0 | OBUnitCell *box = (OBUnitCell*)GetParent()->GetData(OBGenericDataType::UnitCell); |
1117 | 0 | return (box->MinimumImageCartesian(this->GetVector() - b->GetVector())).length(); |
1118 | 0 | } |
1119 | 617 | } |
1120 | | |
1121 | | double OBAtom::GetDistance(int b) |
1122 | 0 | { |
1123 | 0 | OBMol *mol = (OBMol*)GetParent(); |
1124 | 0 | return( this->GetDistance(mol->GetAtom(b)) ); |
1125 | 0 | } |
1126 | | |
1127 | | double OBAtom::GetDistance(vector3 *v) |
1128 | 0 | { |
1129 | 0 | return(( this->GetVector() - *v ).length()); |
1130 | 0 | } |
1131 | | |
1132 | | double OBAtom::GetAngle(OBAtom *b, OBAtom *c) |
1133 | 1.90M | { |
1134 | 1.90M | vector3 v1,v2; |
1135 | | |
1136 | 1.90M | v1 = this->GetVector() - b->GetVector(); |
1137 | 1.90M | v2 = c->GetVector() - b->GetVector(); |
1138 | 1.90M | if (IsPeriodic()) |
1139 | 0 | { |
1140 | 0 | OBUnitCell *box = (OBUnitCell*)GetParent()->GetData(OBGenericDataType::UnitCell); |
1141 | 0 | v1 = box->MinimumImageCartesian(v1); |
1142 | 0 | v2 = box->MinimumImageCartesian(v2); |
1143 | 0 | } |
1144 | | |
1145 | 1.90M | if (fabs(v1.length()) < 1.0e-3 |
1146 | 1.90M | || fabs(v2.length()) < 1.0e-3) { |
1147 | 242 | return(0.0); |
1148 | 242 | } |
1149 | | |
1150 | 1.90M | return(vectorAngle(v1, v2)); |
1151 | 1.90M | } |
1152 | | |
1153 | | double OBAtom::GetAngle(int b, int c) |
1154 | 0 | { |
1155 | 0 | OBMol *mol = (OBMol*)GetParent(); |
1156 | 0 | return(this->GetAngle(mol->GetAtom(b), mol->GetAtom(c))); |
1157 | 0 | } |
1158 | | |
1159 | | bool OBAtom::GetNewBondVector(vector3 &v,double length) |
1160 | 12.7k | { |
1161 | 12.7k | v = OBBuilder::GetNewBondVector(this, length); |
1162 | 12.7k | return(true); |
1163 | 12.7k | } |
1164 | | |
1165 | | //! \return a "corrected" bonding radius based on the hybridization. |
1166 | | //! Scales the covalent radius by 0.95 for sp2 and 0.90 for sp hybrids |
1167 | | static double CorrectedBondRad(unsigned int elem, unsigned int hyb) |
1168 | 0 | { |
1169 | 0 | double rad = OBElements::GetCovalentRad(elem); |
1170 | 0 | switch (hyb) { |
1171 | 0 | case 2: |
1172 | 0 | return rad * 0.95; |
1173 | 0 | case 1: |
1174 | 0 | return rad * 0.90; |
1175 | 0 | default: |
1176 | 0 | return rad; |
1177 | 0 | } |
1178 | 0 | } |
1179 | | |
1180 | | bool OBAtom::HtoMethyl() |
1181 | 0 | { |
1182 | 0 | if (GetAtomicNum() != OBElements::Hydrogen) |
1183 | 0 | return(false); |
1184 | | |
1185 | 0 | obErrorLog.ThrowError(__FUNCTION__, |
1186 | 0 | "Ran OpenBabel::HtoMethyl", obAuditMsg); |
1187 | |
|
1188 | 0 | OBMol *mol = (OBMol*)GetParent(); |
1189 | |
|
1190 | 0 | mol->BeginModify(); |
1191 | |
|
1192 | 0 | SetAtomicNum(6); |
1193 | 0 | SetType("C3"); |
1194 | 0 | SetHyb(3); |
1195 | |
|
1196 | 0 | OBAtom *atom; |
1197 | 0 | OBBond *bond; |
1198 | 0 | OBBondIterator i; |
1199 | 0 | atom = BeginNbrAtom(i); |
1200 | 0 | bond = (OBBond *)*i; |
1201 | 0 | if (!atom) |
1202 | 0 | { |
1203 | 0 | mol->EndModify(); |
1204 | 0 | return(false); |
1205 | 0 | } |
1206 | | |
1207 | 0 | double br1,br2; |
1208 | 0 | br1 = CorrectedBondRad(6,3); |
1209 | 0 | br2 = CorrectedBondRad(atom->GetAtomicNum(),atom->GetHyb()); |
1210 | 0 | bond->SetLength(atom,br1+br2); |
1211 | |
|
1212 | 0 | OBAtom *hatom; |
1213 | 0 | br2 = CorrectedBondRad(1,0); |
1214 | 0 | vector3 v; |
1215 | |
|
1216 | 0 | for (int j = 0;j < 3;++j) |
1217 | 0 | { |
1218 | 0 | hatom = mol->NewAtom(); |
1219 | 0 | hatom->SetAtomicNum(1); |
1220 | 0 | hatom->SetType("H"); |
1221 | |
|
1222 | 0 | GetNewBondVector(v,br1+br2); |
1223 | 0 | hatom->SetVector(v); |
1224 | 0 | mol->AddBond(GetIdx(),mol->NumAtoms(),1); |
1225 | 0 | } |
1226 | |
|
1227 | 0 | mol->EndModify(); |
1228 | 0 | return(true); |
1229 | 0 | } |
1230 | | |
1231 | | static void ApplyRotMatToBond(OBMol &mol,matrix3x3 &m,OBAtom *a1,OBAtom *a2) |
1232 | 0 | { |
1233 | 0 | vector<int> children; |
1234 | 0 | mol.FindChildren(children,a1->GetIdx(),a2->GetIdx()); |
1235 | 0 | children.push_back(a2->GetIdx()); |
1236 | |
|
1237 | 0 | vector3 v; |
1238 | 0 | vector<int>::iterator i; |
1239 | 0 | for (i = children.begin();i != children.end();++i) |
1240 | 0 | { |
1241 | 0 | v = mol.GetAtom(*i)->GetVector(); |
1242 | 0 | v -= a1->GetVector(); |
1243 | 0 | v *= m; |
1244 | 0 | v += a1->GetVector(); |
1245 | 0 | mol.GetAtom(*i)->SetVector(v); |
1246 | 0 | } |
1247 | |
|
1248 | 0 | } |
1249 | | |
1250 | | //! \deprecated This will be removed in future versions of Open Babel |
1251 | | OB_DEPRECATED bool OBAtom::SetHybAndGeom(int hyb) |
1252 | 0 | { |
1253 | 0 | obErrorLog.ThrowError(__FUNCTION__, |
1254 | 0 | "Ran OpenBabel::SetHybridizationAndGeometry", |
1255 | 0 | obAuditMsg); |
1256 | | |
1257 | | //if (hyb == GetHyb()) return(true); |
1258 | 0 | if (GetAtomicNum() == 1) |
1259 | 0 | return(false); |
1260 | 0 | if (hyb == 0 && GetHvyDegree() > 1) |
1261 | 0 | return(false); |
1262 | 0 | if (hyb == 1 && GetHvyDegree() > 2) |
1263 | 0 | return(false); |
1264 | 0 | if (hyb == 2 && GetHvyDegree() > 3) |
1265 | 0 | return(false); |
1266 | 0 | if (hyb == 3 && GetHvyDegree() > 4) |
1267 | 0 | return(false); |
1268 | | |
1269 | 0 | OBMol *mol = (OBMol*)GetParent(); |
1270 | |
|
1271 | 0 | OBAtom *nbr; |
1272 | 0 | vector<OBAtom*> delatm; |
1273 | 0 | OBBondIterator i; |
1274 | |
|
1275 | 0 | for (nbr = BeginNbrAtom(i);nbr;nbr = NextNbrAtom(i)) |
1276 | 0 | if (nbr->GetAtomicNum() == OBElements::Hydrogen) |
1277 | 0 | delatm.push_back(nbr); |
1278 | | |
1279 | | //delete attached hydrogens |
1280 | 0 | mol->IncrementMod(); |
1281 | 0 | vector<OBAtom*>::iterator j; |
1282 | 0 | for (j = delatm.begin();j != delatm.end();++j) |
1283 | 0 | mol->DeleteAtom(*j); |
1284 | 0 | mol->DecrementMod(); |
1285 | |
|
1286 | 0 | double targetAngle; |
1287 | 0 | if (hyb == 3) |
1288 | 0 | targetAngle = 109.5; |
1289 | 0 | else if (hyb == 2) |
1290 | 0 | targetAngle = 120.0; |
1291 | 0 | else if (hyb == 1) |
1292 | 0 | targetAngle = 180.0; |
1293 | 0 | else |
1294 | 0 | targetAngle = 0.0; |
1295 | |
|
1296 | 0 | if (IsInRing()) |
1297 | 0 | targetAngle = 180.0 - (360.0 / MemberOfRingSize()); |
1298 | | |
1299 | | //adjust attached acyclic bond lengths |
1300 | 0 | double br1,br2, length; |
1301 | 0 | br1 = CorrectedBondRad(GetAtomicNum(),hyb); |
1302 | 0 | for (nbr = BeginNbrAtom(i);nbr;nbr = NextNbrAtom(i)) |
1303 | 0 | if (!(*i)->IsInRing()) |
1304 | 0 | { |
1305 | 0 | br2 = CorrectedBondRad(nbr->GetAtomicNum(),nbr->GetHyb()); |
1306 | 0 | length = br1 + br2; |
1307 | 0 | if ((*i)->IsAromatic()) |
1308 | 0 | length *= 0.93; |
1309 | 0 | else if ((*i)->GetBondOrder() == 2) |
1310 | 0 | length *= 0.91; |
1311 | 0 | else if ((*i)->GetBondOrder() == 3) |
1312 | 0 | length *= 0.87; |
1313 | 0 | ((OBBond*) *i)->SetLength(this, length); |
1314 | 0 | } |
1315 | |
|
1316 | 0 | if (GetExplicitDegree() > 1) |
1317 | 0 | { |
1318 | 0 | double angle; |
1319 | 0 | matrix3x3 m; |
1320 | 0 | vector3 v1,v2,v3,v4,n,s; |
1321 | 0 | OBAtom *r1,*r2,*r3,*a1,*a2,*a3,*a4; |
1322 | 0 | r1 = r2 = r3 = a1 = a2 = a3 = a4 = nullptr; |
1323 | | |
1324 | | //find ring atoms first |
1325 | 0 | for (nbr = BeginNbrAtom(i);nbr;nbr = NextNbrAtom(i)) |
1326 | 0 | if ((*i)->IsInRing()) { |
1327 | 0 | if (!r1) { |
1328 | 0 | r1 = nbr; |
1329 | 0 | } |
1330 | 0 | else if (!r2) { |
1331 | 0 | r2 = nbr; |
1332 | 0 | } |
1333 | 0 | else if (!r3) { |
1334 | 0 | r3 = nbr; |
1335 | 0 | } |
1336 | 0 | } |
1337 | | |
1338 | | //find non-ring atoms |
1339 | 0 | for (nbr = BeginNbrAtom(i);nbr;nbr = NextNbrAtom(i)) |
1340 | 0 | if (!(*i)->IsInRing()) { |
1341 | 0 | if (!a1) { |
1342 | 0 | a1 = nbr; |
1343 | 0 | } |
1344 | 0 | else if (!a2) { |
1345 | 0 | a2 = nbr; |
1346 | 0 | } |
1347 | 0 | else if (!a3) { |
1348 | 0 | a3 = nbr; |
1349 | 0 | } |
1350 | 0 | else if (!a4) { |
1351 | 0 | a4 = nbr; |
1352 | 0 | } |
1353 | 0 | } |
1354 | | |
1355 | | //adjust geometries of heavy atoms according to hybridization |
1356 | 0 | if (hyb == 1) |
1357 | 0 | { |
1358 | 0 | if (a2) |
1359 | 0 | { |
1360 | 0 | v1 = a1->GetVector()-GetVector(); |
1361 | 0 | v1.normalize(); |
1362 | 0 | v2 = a2->GetVector()-GetVector(); |
1363 | 0 | v2.normalize(); |
1364 | 0 | n = cross(v1,v2); |
1365 | 0 | angle = vectorAngle(v1,v2)-targetAngle; |
1366 | 0 | m.RotAboutAxisByAngle(n,-angle); |
1367 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1368 | 0 | } |
1369 | 0 | } |
1370 | 0 | else if (hyb == 2) |
1371 | 0 | { |
1372 | 0 | if (r1 && r2 && a1) |
1373 | 0 | { |
1374 | 0 | v1 = r1->GetVector()-GetVector(); |
1375 | 0 | v1.normalize(); |
1376 | 0 | v2 = r2->GetVector()-GetVector(); |
1377 | 0 | v2.normalize(); |
1378 | 0 | v3 = a1->GetVector()-GetVector(); |
1379 | 0 | s = v1+v2; |
1380 | 0 | s.normalize(); |
1381 | 0 | s *= -1.0; |
1382 | 0 | n = cross(s,v3); |
1383 | 0 | angle = vectorAngle(s,v3); |
1384 | 0 | m.RotAboutAxisByAngle(n,angle); |
1385 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1386 | 0 | } |
1387 | 0 | else |
1388 | 0 | { |
1389 | 0 | if (a2) |
1390 | 0 | { |
1391 | 0 | v1 = a1->GetVector()-GetVector(); |
1392 | 0 | v1.normalize(); |
1393 | 0 | v2 = a2->GetVector()-GetVector(); |
1394 | 0 | v2.normalize(); |
1395 | 0 | n = cross(v1,v2); |
1396 | 0 | angle = vectorAngle(v1,v2)-targetAngle; |
1397 | 0 | m.RotAboutAxisByAngle(n,-angle); |
1398 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1399 | 0 | } |
1400 | 0 | if (a3) |
1401 | 0 | { |
1402 | 0 | v1 = a1->GetVector()-GetVector(); |
1403 | 0 | v1.normalize(); |
1404 | 0 | v2 = a2->GetVector()-GetVector(); |
1405 | 0 | v2.normalize(); |
1406 | 0 | v3 = a3->GetVector()-GetVector(); |
1407 | 0 | s = v1+v2; |
1408 | 0 | s.normalize(); |
1409 | 0 | s *= -1.0; |
1410 | 0 | n = cross(s,v3); |
1411 | 0 | angle = vectorAngle(s,v3); |
1412 | 0 | m.RotAboutAxisByAngle(n,angle); |
1413 | 0 | ApplyRotMatToBond(*mol,m,this,a3); |
1414 | 0 | } |
1415 | 0 | } |
1416 | 0 | } |
1417 | 0 | else if (hyb == 3) |
1418 | 0 | { |
1419 | 0 | if (r1 && r2 && r3 && a1) |
1420 | 0 | { |
1421 | 0 | v1 = r1->GetVector()-GetVector(); |
1422 | 0 | v1.normalize(); |
1423 | 0 | v2 = r2->GetVector()-GetVector(); |
1424 | 0 | v2.normalize(); |
1425 | 0 | v3 = r3->GetVector()-GetVector(); |
1426 | 0 | v3.normalize(); |
1427 | 0 | v4 = a1->GetVector()-GetVector(); |
1428 | 0 | s = v1 + v2 + v3; |
1429 | 0 | s *= -1.0; |
1430 | 0 | s.normalize(); |
1431 | 0 | n = cross(s,v4); |
1432 | 0 | angle = vectorAngle(s,v4); |
1433 | 0 | m.RotAboutAxisByAngle(n,angle); |
1434 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1435 | 0 | } |
1436 | 0 | else if (r1 && r2 && !r3 && a1) |
1437 | 0 | { |
1438 | 0 | v1 = r1->GetVector()-GetVector(); |
1439 | 0 | v1.normalize(); |
1440 | 0 | v2 = r2->GetVector()-GetVector(); |
1441 | 0 | v2.normalize(); |
1442 | 0 | v3 = a1->GetVector()-GetVector(); |
1443 | 0 | s = v1+v2; |
1444 | 0 | s *= -1.0; |
1445 | 0 | s.normalize(); |
1446 | 0 | n = cross(v1,v2); |
1447 | 0 | n.normalize(); |
1448 | 0 | #ifndef ONE_OVER_SQRT3 |
1449 | 0 | #define ONE_OVER_SQRT3 0.57735026918962576451 |
1450 | 0 | #endif //SQRT_TWO_THIRDS |
1451 | 0 | #ifndef SQRT_TWO_THIRDS |
1452 | 0 | #define SQRT_TWO_THIRDS 0.81649658092772603272 |
1453 | 0 | #endif //ONE_OVER_SQRT3 |
1454 | 0 | s *= ONE_OVER_SQRT3; //1/sqrt(3) |
1455 | 0 | n *= SQRT_TWO_THIRDS; //sqrt(2/3) |
1456 | 0 | s += n; |
1457 | 0 | s.normalize(); |
1458 | 0 | n = cross(s,v3); |
1459 | 0 | angle = vectorAngle(s,v3); |
1460 | 0 | m.RotAboutAxisByAngle(n,angle); |
1461 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1462 | |
|
1463 | 0 | if (a2) |
1464 | 0 | { |
1465 | 0 | v1 = r1->GetVector()-GetVector(); |
1466 | 0 | v1.normalize(); |
1467 | 0 | v2 = r2->GetVector()-GetVector(); |
1468 | 0 | v2.normalize(); |
1469 | 0 | v3 = a1->GetVector()-GetVector(); |
1470 | 0 | v3.normalize(); |
1471 | 0 | v4 = a2->GetVector()-GetVector(); |
1472 | 0 | s = v1 + v2 + v3; |
1473 | 0 | s *= -1.0; |
1474 | 0 | s.normalize(); |
1475 | 0 | n = cross(s,v4); |
1476 | 0 | angle = vectorAngle(s,v4); |
1477 | 0 | m.RotAboutAxisByAngle(n,angle); |
1478 | 0 | ApplyRotMatToBond(*mol,m,this,a2); |
1479 | 0 | } |
1480 | 0 | } |
1481 | 0 | else |
1482 | 0 | { |
1483 | 0 | if (a2) |
1484 | 0 | { |
1485 | 0 | v1 = a1->GetVector()-GetVector(); |
1486 | 0 | v1.normalize(); |
1487 | 0 | v2 = a2->GetVector()-GetVector(); |
1488 | 0 | v2.normalize(); |
1489 | 0 | n = cross(v1,v2); |
1490 | 0 | angle = vectorAngle(v1,v2)-targetAngle; |
1491 | 0 | m.RotAboutAxisByAngle(n,-angle); |
1492 | 0 | ApplyRotMatToBond(*mol,m,this,a1); |
1493 | 0 | } |
1494 | 0 | if (a3) |
1495 | 0 | { |
1496 | 0 | v1 = a1->GetVector()-GetVector(); |
1497 | 0 | v1.normalize(); |
1498 | 0 | v2 = a2->GetVector()-GetVector(); |
1499 | 0 | v2.normalize(); |
1500 | 0 | v3 = a3->GetVector()-GetVector(); |
1501 | 0 | s = v1+v2; |
1502 | 0 | s *= -1.0; |
1503 | 0 | s.normalize(); |
1504 | 0 | n = cross(v1,v2); |
1505 | 0 | n.normalize(); |
1506 | 0 | s *= ONE_OVER_SQRT3; //1/sqrt(3) |
1507 | 0 | n *= SQRT_TWO_THIRDS; //sqrt(2/3) |
1508 | 0 | s += n; |
1509 | 0 | s.normalize(); |
1510 | 0 | n = cross(s,v3); |
1511 | 0 | angle = vectorAngle(s,v3); |
1512 | 0 | m.RotAboutAxisByAngle(n,angle); |
1513 | 0 | ApplyRotMatToBond(*mol,m,this,a3); |
1514 | 0 | } |
1515 | 0 | } |
1516 | 0 | } |
1517 | 0 | } |
1518 | | |
1519 | | //add hydrogens back to atom |
1520 | 0 | int impval=1; |
1521 | 0 | switch (GetAtomicNum()) |
1522 | 0 | { |
1523 | 0 | case 6: |
1524 | 0 | if (hyb == 3) |
1525 | 0 | impval = 4; |
1526 | 0 | if (hyb == 2) |
1527 | 0 | impval = 3; |
1528 | 0 | if (hyb == 1) |
1529 | 0 | impval = 2; |
1530 | 0 | break; |
1531 | 0 | case 7: |
1532 | 0 | if (hyb == 3) |
1533 | 0 | impval = 3; |
1534 | 0 | if (hyb == 2) |
1535 | 0 | impval = 2; |
1536 | 0 | if (hyb == 1) |
1537 | 0 | impval = 1; |
1538 | 0 | break; |
1539 | 0 | case 8: |
1540 | 0 | if (hyb == 3) |
1541 | 0 | impval = 2; |
1542 | 0 | if (hyb == 2) |
1543 | 0 | impval = 2; |
1544 | 0 | if (hyb == 1) |
1545 | 0 | impval = 2; |
1546 | 0 | break; |
1547 | 0 | case 16: |
1548 | 0 | if (hyb == 3) |
1549 | 0 | impval = 2; |
1550 | 0 | if (hyb == 2) |
1551 | 0 | impval = 2; |
1552 | 0 | if (hyb == 1) |
1553 | 0 | impval = 0; |
1554 | 0 | break; |
1555 | 0 | case 15: |
1556 | 0 | if (hyb == 3) |
1557 | 0 | impval = 4; |
1558 | 0 | if (hyb == 2) |
1559 | 0 | impval = 3; |
1560 | 0 | if (hyb == 1) |
1561 | 0 | impval = 2; |
1562 | 0 | break; |
1563 | 0 | default: |
1564 | 0 | impval = 1; |
1565 | 0 | } |
1566 | | |
1567 | 0 | int hcount = impval-GetHvyDegree(); |
1568 | 0 | if (hcount) |
1569 | 0 | { |
1570 | 0 | int k; |
1571 | 0 | vector3 v; |
1572 | 0 | OBAtom *atom; |
1573 | 0 | double brsum = CorrectedBondRad(1,0)+ |
1574 | 0 | CorrectedBondRad(GetAtomicNum(),GetHyb()); |
1575 | 0 | SetHyb(hyb); |
1576 | |
|
1577 | 0 | mol->BeginModify(); |
1578 | 0 | for (k = 0;k < hcount;++k) |
1579 | 0 | { |
1580 | 0 | GetNewBondVector(v,brsum); |
1581 | 0 | atom = mol->NewAtom(); |
1582 | 0 | atom->SetAtomicNum(1); |
1583 | 0 | atom->SetType("H"); |
1584 | 0 | atom->SetVector(v); |
1585 | 0 | mol->AddBond(atom->GetIdx(),GetIdx(),1); |
1586 | 0 | } |
1587 | 0 | mol->EndModify(); |
1588 | 0 | } |
1589 | | |
1590 | |
|
1591 | 0 | return(true); |
1592 | 0 | } |
1593 | | |
1594 | | OBBond *OBAtom::GetBond(OBAtom *nbr) |
1595 | 3.75M | { |
1596 | 3.75M | OBBond *bond; |
1597 | 3.75M | vector<OBBond *>::iterator i; |
1598 | 22.2M | for (bond = BeginBond(i) ; bond ; bond = NextBond(i)) |
1599 | 22.2M | if (bond->GetNbrAtom(this) == nbr) |
1600 | 3.75M | return bond; |
1601 | 0 | return nullptr; |
1602 | 3.75M | } |
1603 | | |
1604 | | /*Now in OBBase |
1605 | | // OBGenericData methods |
1606 | | bool OBAtom::HasData(string &s) |
1607 | | //returns true if the generic attribute/value pair exists |
1608 | | { |
1609 | | if (_vdata.empty()) |
1610 | | return(false); |
1611 | | |
1612 | | vector<OBGenericData*>::iterator i; |
1613 | | |
1614 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1615 | | if ((*i)->GetAttribute() == s) |
1616 | | return(true); |
1617 | | |
1618 | | return(false); |
1619 | | } |
1620 | | |
1621 | | bool OBAtom::HasData(const char *s) |
1622 | | //returns true if the generic attribute/value pair exists |
1623 | | { |
1624 | | if (_vdata.empty()) |
1625 | | return(false); |
1626 | | |
1627 | | vector<OBGenericData*>::iterator i; |
1628 | | |
1629 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1630 | | if ((*i)->GetAttribute() == s) |
1631 | | return(true); |
1632 | | |
1633 | | return(false); |
1634 | | } |
1635 | | |
1636 | | bool OBAtom::HasData(unsigned int dt) |
1637 | | //returns true if the generic attribute/value pair exists |
1638 | | { |
1639 | | if (_vdata.empty()) |
1640 | | return(false); |
1641 | | |
1642 | | vector<OBGenericData*>::iterator i; |
1643 | | |
1644 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1645 | | if ((*i)->GetDataType() == dt) |
1646 | | return(true); |
1647 | | |
1648 | | return(false); |
1649 | | } |
1650 | | |
1651 | | OBGenericData *OBAtom::GetData(string &s) |
1652 | | //returns the value given an attribute |
1653 | | { |
1654 | | vector<OBGenericData*>::iterator i; |
1655 | | |
1656 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1657 | | if ((*i)->GetAttribute() == s) |
1658 | | return(*i); |
1659 | | |
1660 | | return(NULL); |
1661 | | } |
1662 | | |
1663 | | OBGenericData *OBAtom::GetData(const char *s) |
1664 | | //returns the value given an attribute |
1665 | | { |
1666 | | vector<OBGenericData*>::iterator i; |
1667 | | |
1668 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1669 | | if ((*i)->GetAttribute() == s) |
1670 | | return(*i); |
1671 | | |
1672 | | return(NULL); |
1673 | | } |
1674 | | |
1675 | | OBGenericData *OBAtom::GetData(unsigned int dt) |
1676 | | { |
1677 | | vector<OBGenericData*>::iterator i; |
1678 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1679 | | if ((*i)->GetDataType() == dt) |
1680 | | return(*i); |
1681 | | return(NULL); |
1682 | | } |
1683 | | |
1684 | | void OBAtom::DeleteData(unsigned int dt) |
1685 | | { |
1686 | | vector<OBGenericData*> vdata; |
1687 | | vector<OBGenericData*>::iterator i; |
1688 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1689 | | if ((*i)->GetDataType() == dt) |
1690 | | delete *i; |
1691 | | else |
1692 | | vdata.push_back(*i); |
1693 | | _vdata = vdata; |
1694 | | } |
1695 | | |
1696 | | void OBAtom::DeleteData(vector<OBGenericData*> &vg) |
1697 | | { |
1698 | | vector<OBGenericData*> vdata; |
1699 | | vector<OBGenericData*>::iterator i,j; |
1700 | | |
1701 | | bool del; |
1702 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1703 | | { |
1704 | | del = false; |
1705 | | for (j = vg.begin();j != vg.end();++j) |
1706 | | if (*i == *j) |
1707 | | { |
1708 | | del = true; |
1709 | | break; |
1710 | | } |
1711 | | if (del) |
1712 | | delete *i; |
1713 | | else |
1714 | | vdata.push_back(*i); |
1715 | | } |
1716 | | _vdata = vdata; |
1717 | | } |
1718 | | |
1719 | | void OBAtom::DeleteData(OBGenericData *gd) |
1720 | | { |
1721 | | vector<OBGenericData*>::iterator i; |
1722 | | for (i = _vdata.begin();i != _vdata.end();++i) |
1723 | | if (*i == gd) |
1724 | | { |
1725 | | delete *i; |
1726 | | _vdata.erase(i); |
1727 | | } |
1728 | | |
1729 | | } |
1730 | | */ |
1731 | | |
1732 | | bool OBAtom::IsHbondAcceptorSimple() |
1733 | 0 | { |
1734 | | // Changes from Liu Zhiguo |
1735 | 0 | if (_ele == 8 || _ele == 9) |
1736 | 0 | return true; |
1737 | 0 | if (_ele == 7) { |
1738 | | // N+ ions and sp2 hybrid N with 3 valences should not be Hbond acceptors |
1739 | 0 | if (!((GetExplicitDegree() == 4 && GetHyb() == 3) |
1740 | 0 | || (GetExplicitDegree() == 3 && GetHyb() == 2))) |
1741 | 0 | return true; |
1742 | 0 | } |
1743 | | // Changes from Paolo Tosco |
1744 | 0 | if (_ele == 16 && GetFormalCharge() == -1) |
1745 | 0 | return true; |
1746 | 0 | return false; |
1747 | 0 | } |
1748 | | |
1749 | | // new function, Stefano Forli |
1750 | | // Incorporate ideas and data from Kubyni and others. |
1751 | | // [1] Kubinyi, H. "Changing paradigms in drug discovery. |
1752 | | // "SPECIAL PUBLICATION-ROYAL SOCIETY OF CHEMISTRY 304.1 (2006): 219-232. |
1753 | | // |
1754 | | // [2] Kingsbury, Charles A. "Why are the Nitro and Sulfone |
1755 | | // Groups Poor Hydrogen Bonders?." (2015). |
1756 | | // |
1757 | | // [3] Per Restorp, Orion B. Berryman, Aaron C. Sather, Dariush Ajami |
1758 | | // and Julius Rebek Jr., Chem. Commun., 2009, 5692 DOI: 10.1039/b914171e |
1759 | | // |
1760 | | // [4] Dunitz, Taylor. "Organic fluorine hardly ever accepts |
1761 | | // hydrogen bonds." Chemistry-A European Journal 3.1 (1997): 83-92. |
1762 | | // |
1763 | | // This function has a finer grain than the original |
1764 | | // implementation, checking also the neighbor atoms. |
1765 | | // Accordingly to these rules, the function will return: |
1766 | | // |
1767 | | // aliph-O-aliph ether -> true [1] |
1768 | | // hydroxy O-sp3 -> true [1] |
1769 | | // aro-O-aliph ether -> true [1] |
1770 | | // ester O-sp2 -> true [1] |
1771 | | // sulfate O (R-SO3) -> true [2] |
1772 | | // sulfoxyde O (R-SO-R) -> true [2] |
1773 | | // organoboron-F (R-BF3) -> true [3] |
1774 | | // ester O-sp3 -> false [1] |
1775 | | // sulfone (R1-SO2-R2 ) -> false [2] |
1776 | | // aro-O-aro -> false [1] |
1777 | | // aromatic O -> false [1] |
1778 | | // O-nitro -> false [2] |
1779 | | // organic F (R-F) -> false [4] |
1780 | | // |
1781 | 0 | bool OBAtom::IsHbondAcceptor() { |
1782 | 0 | if (_ele == 8) { |
1783 | | // oxygen; this should likely be a separate function |
1784 | | // something like IsHbondAcceptorOxygen() |
1785 | 0 | unsigned int aroCount = 0; |
1786 | |
|
1787 | 0 | OBBond *bond; |
1788 | 0 | OBBondIterator i; |
1789 | 0 | if (IsNitroOxygen()){ // maybe could be a bool option in the function? |
1790 | 0 | return (false); |
1791 | 0 | } |
1792 | 0 | if (IsAromatic()){ // aromatic oxygen (furan) (NO) |
1793 | 0 | return(false); |
1794 | 0 | } |
1795 | 0 | if (IsSulfoneOxygen(this)){ // sulfone (NO) |
1796 | 0 | return(false); |
1797 | 0 | } |
1798 | 0 | FOR_NBORS_OF_ATOM(nbr, this){ |
1799 | 0 | if (nbr->IsAromatic()){ |
1800 | 0 | aroCount += 1; |
1801 | 0 | if (aroCount == 2){ // aromatic ether (aro-O-aro) (NO) |
1802 | 0 | return(false); |
1803 | 0 | } |
1804 | 0 | } |
1805 | 0 | else { |
1806 | 0 | if (nbr->GetAtomicNum() == OBElements::Hydrogen) { // hydroxyl (YES) |
1807 | 0 | return(true); |
1808 | 0 | } |
1809 | 0 | else { |
1810 | 0 | bond = nbr->GetBond(this); |
1811 | 0 | if ( (bond->IsEster()) && (!(IsCarboxylOxygen()))) |
1812 | 0 | return(false); |
1813 | 0 | } |
1814 | 0 | } |
1815 | 0 | } |
1816 | 0 | return(true); // any other oxygen |
1817 | 0 | } // oxygen END |
1818 | | // fluorine |
1819 | 0 | if (_ele == 9 ) { |
1820 | 0 | OBBondIterator i; |
1821 | | // organic fluorine (NO) |
1822 | 0 | for (OBAtom* nbr = BeginNbrAtom(i);nbr;nbr=NextNbrAtom(i)) |
1823 | 0 | if (nbr->GetAtomicNum() == 6) |
1824 | 0 | return (false); |
1825 | 0 | else |
1826 | 0 | return (true); |
1827 | 0 | }; |
1828 | 0 | if (_ele == 7) { |
1829 | | // N+ ions and sp2 hybrid N with 3 valences should not be Hbond acceptors |
1830 | 0 | if (!((GetExplicitDegree() == 4 && GetHyb() == 3) |
1831 | 0 | || (GetExplicitDegree() == 3 && GetHyb() == 2))) |
1832 | 0 | return true; |
1833 | 0 | }; |
1834 | | // Changes from Paolo Tosco |
1835 | 0 | if (_ele == 16 && GetFormalCharge() == -1){ |
1836 | 0 | return (true); } |
1837 | | // everything else |
1838 | 0 | return (false); |
1839 | 0 | } |
1840 | | |
1841 | | bool OBAtom::IsHbondDonor() |
1842 | 0 | { |
1843 | | // return MatchesSMARTS("[$([#8,#7H,#9;!H0])]"); |
1844 | 0 | if (!(_ele == 7 || _ele == 8 || _ele == 9)) |
1845 | 0 | return false; |
1846 | | |
1847 | 0 | OBAtom *nbr; |
1848 | 0 | OBBondIterator i; |
1849 | 0 | for (nbr = BeginNbrAtom(i);nbr;nbr = NextNbrAtom(i)) |
1850 | 0 | if (nbr->GetAtomicNum() == OBElements::Hydrogen) |
1851 | 0 | return true; |
1852 | | |
1853 | 0 | return false; |
1854 | 0 | } |
1855 | | |
1856 | | bool OBAtom::IsHbondDonorH() |
1857 | 0 | { |
1858 | 0 | if (GetAtomicNum() != OBElements::Hydrogen) return(false); |
1859 | | |
1860 | | // Recursive definition -- this atom is an H atom |
1861 | | // are any neighbors HbondDonors? |
1862 | | |
1863 | 0 | OBAtom *atom; |
1864 | 0 | OBBond *bond; |
1865 | 0 | OBBondIterator i; |
1866 | 0 | for (bond = BeginBond(i);bond;bond = NextBond(i)) { |
1867 | 0 | atom = bond->GetNbrAtom(this); |
1868 | 0 | if (atom->IsHbondDonor()) return(true); |
1869 | 0 | } |
1870 | | |
1871 | 0 | return(false); |
1872 | 0 | } |
1873 | | |
1874 | | bool OBAtom::IsMetal() |
1875 | 0 | { |
1876 | 0 | const unsigned NMETALS = 78; |
1877 | 0 | const int metals[NMETALS] = { |
1878 | 0 | 3,4,11,12,13,19,20,21,22,23,24,25,26,27,28,29, |
1879 | 0 | 30,31,37,38,39,40,41,42,43,44,45,46,47,48,49,50,55,56,57,58,59,60,61,62,63, |
1880 | 0 | 64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,87,88,89,90,91, |
1881 | 0 | 92,93,94,95,96,97,98,99,100,101,102,103}; |
1882 | 0 | return std::find(metals, metals+78, GetAtomicNum())!=metals+78; |
1883 | 0 | } |
1884 | | |
1885 | | } // end namespace OpenBabel |
1886 | | |
1887 | | //! \file atom.cpp |
1888 | | //! \brief Handle OBAtom class |