1
/**********************************************************************
2
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc.
4
This program is free software; you can redistribute it and/or modify
5
it under the terms of the GNU General Public License as published by
6
the Free Software Foundation version 2 of the License.
8
This program is distributed in the hope that it will be useful,
9
but WITHOUT ANY WARRANTY; without even the implied warranty of
10
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
GNU General Public License for more details.
12
***********************************************************************/
19
extern OEAromaticTyper aromtyper;
21
// *******************************
22
// *** OEBond member functions ***
23
// *******************************
34
void OEBond::Set(int idx,OEAtom *begin,OEAtom *end,int order,int flags)
43
void OEBond::SetBO(int order)
49
if (_bgn) _bgn->SetAromatic();
50
if (_end) _end->SetAromatic();
55
void OEBond::SetLength(OEAtom *fixed, float length)
58
OEMol *mol = (OEMol*)fixed->GetParent();
59
Vector v1,v2,v3,v4,v5;
62
int a = fixed->GetIdx();
63
int b = GetNbrAtom(fixed)->GetIdx();
65
mol->FindChildren(children,a,b);
66
children.push_back(b);
68
v1 = GetNbrAtom(fixed)->GetVector();
69
v2 = fixed->GetVector();
76
for ( i = 0 ; i < children.size() ; i++ )
78
v1 = mol->GetAtom(children[i])->GetVector();
80
mol->GetAtom(children[i])->SetVector(v1);
82
idx = (children[i]-1) * 3;
90
bool OEBond::IsRotor()
92
return(_bgn->GetHvyValence() > 1 && _end->GetHvyValence() > 1 &&
93
_order == 1 && !IsInRing() && _bgn->GetHyb() != 1 &&
97
bool OEBond::IsAmide()
102
if (_bgn->GetAtomicNum() == 6 && _end->GetAtomicNum() == 7)
103
{a1 = (OEAtom*)_bgn; a2 = (OEAtom*)_end;}
105
if (_bgn->GetAtomicNum() == 7 && _end->GetAtomicNum() == 6)
106
{a1 = (OEAtom*)_end; a2 = (OEAtom*)_bgn;}
108
if (!a1 || !a2) return(false);
109
if (GetBO() != 1) return(false);
112
vector<OEBond*>::iterator i;
113
for (bond = a1->BeginBond(i);bond;bond = a1->NextBond(i))
114
if (bond->IsCarbonyl())
120
bool OEBond::IsPrimaryAmide()
125
if (_bgn->GetAtomicNum() == 6 && _end->GetAtomicNum() == 7)
126
{a1 = (OEAtom*)_bgn; a2 = (OEAtom*)_end;}
128
if (_bgn->GetAtomicNum() == 7 && _end->GetAtomicNum() == 6)
129
{a1 = (OEAtom*)_end; a2 = (OEAtom*)_bgn;}
131
if (!a1 || !a2) return(false);
132
if (GetBO() != 1) return(false);
135
vector<OEBond*>::iterator i;
136
for (bond = a1->BeginBond(i);bond;bond = a1->NextBond(i))
137
if (bond->IsCarbonyl())
138
if (a2->GetHvyValence() == 2)
145
bool OEBond::IsSecondaryAmide()
152
bool OEBond::IsEster()
157
if (_bgn->GetAtomicNum() == 6 && _end->GetAtomicNum() == 8)
158
{a1 = (OEAtom*)_bgn; a2 = (OEAtom*)_end;}
160
if (_bgn->GetAtomicNum() == 8 && _end->GetAtomicNum() == 6)
161
{a1 = (OEAtom*)_end; a2 = (OEAtom*)_bgn;}
163
if (!a1 || !a2) return(false);
164
if (GetBO() != 1) return(false);
167
vector<OEBond*>::iterator i;
168
for (bond = a1->BeginBond(i);bond;bond = a1->NextBond(i))
169
if (bond->IsCarbonyl())
176
bool OEBond::IsCarbonyl()
178
if (GetBO() != 2) return(false);
180
if ((_bgn->GetAtomicNum() == 6 && _end->GetAtomicNum() == 8) ||
181
(_bgn->GetAtomicNum() == 8 && _end->GetAtomicNum() == 6))
187
bool OEBond::IsSingle()
189
if (HasFlag(OE_AROMATIC_BOND)) return(false);
191
if (!((OEMol*)GetParent())->HasAromaticPerceived())
193
aromtyper.AssignAromaticFlags(*((OEMol*)GetParent()));
196
if ((this->GetBondOrder()==1) && !(HasFlag(OE_AROMATIC_BOND)))
202
bool OEBond::IsDouble()
204
if (HasFlag(OE_AROMATIC_BOND)) return(false);
206
if (!((OEMol*)GetParent())->HasAromaticPerceived())
208
aromtyper.AssignAromaticFlags(*((OEMol*)GetParent()));
211
if ((this->GetBondOrder()==2) && !(HasFlag(OE_AROMATIC_BOND)))
217
bool OEBond::IsAromatic() const
219
if (((OEBond*)this)->HasFlag(OE_AROMATIC_BOND)) return(true);
221
OEMol *mol = (OEMol*)((OEBond*)this)->GetParent();
222
if (!mol->HasAromaticPerceived())
224
aromtyper.AssignAromaticFlags(*mol);
225
if (((OEBond*)this)->HasFlag(OE_AROMATIC_BOND)) return(true);
231
void OEBond::SetKSingle()
233
_flags &= (~(OE_KSINGLE_BOND|OE_KDOUBLE_BOND|OE_KTRIPLE_BOND));
234
_flags |= OE_KSINGLE_BOND;
237
void OEBond::SetKDouble()
239
_flags &= (~(OE_KSINGLE_BOND|OE_KDOUBLE_BOND|OE_KTRIPLE_BOND));
240
_flags |= OE_KDOUBLE_BOND;
243
void OEBond::SetKTriple()
245
_flags &= (~(OE_KSINGLE_BOND|OE_KDOUBLE_BOND|OE_KTRIPLE_BOND));
246
_flags |= OE_KTRIPLE_BOND;
249
bool OEBond::IsKSingle()
251
if (_flags & OE_KSINGLE_BOND) return(true);
252
if (!((OEMol*)GetParent())->HasKekulePerceived())
253
((OEMol*)GetParent())->PerceiveKekuleBonds();
255
return((_flags & OE_KSINGLE_BOND) != 0) ? true : false;
258
bool OEBond::IsKDouble()
260
if (_flags & OE_KDOUBLE_BOND) return(true);
261
if (!((OEMol*)GetParent())->HasKekulePerceived())
262
((OEMol*)GetParent())->PerceiveKekuleBonds();
264
return((_flags & OE_KDOUBLE_BOND) != 0) ? true : false;
267
bool OEBond::IsKTriple()
269
if (_flags & OE_KTRIPLE_BOND) return(true);
270
if (!((OEMol*)GetParent())->HasKekulePerceived())
271
((OEMol*)GetParent())->PerceiveKekuleBonds();
273
return((_flags & OE_KTRIPLE_BOND) != 0) ? true : false;
276
bool OEBond::IsInRing() const
278
if (((OEBond*)this)->HasFlag(OE_RING_BOND)) return(true);
280
OEMol *mol = (OEMol*)((OEBond*)this)->GetParent();
281
if (!mol->HasRingAtomsAndBondsPerceived())
283
mol->FindRingAtomsAndBonds();
284
if (((OEBond*)this)->HasFlag(OE_RING_BOND)) return(true);
290
bool OEBond::IsClosure()
292
OEMol *mol = (OEMol*)GetParent();
293
if (!mol) return(false);
294
if (mol->HasClosureBondsPerceived()) return(HasFlag(OE_CLOSURE_BOND));
296
mol->SetClosureBondsPerceived();
300
OEBitVec uatoms,ubonds;
301
vector<OEAtom*> curr,next;
302
vector<OEAtom*>::iterator i;
303
vector<OEBond*>::iterator j;
305
uatoms.Resize(mol->NumAtoms()+1);
306
ubonds.Resize(mol->NumAtoms()+1);
308
for (;uatoms.CountBits() < (signed)mol->NumAtoms();)
311
for (atom = mol->BeginAtom(i);atom;atom = mol->NextAtom(i))
312
if (!uatoms[atom->GetIdx()])
314
uatoms |= atom->GetIdx();
315
curr.push_back(atom);
319
for (;!curr.empty();)
321
for (i = curr.begin();i != curr.end();i++)
322
for (nbr = (*i)->BeginNbrAtom(j);nbr;nbr = (*i)->NextNbrAtom(j))
323
if (!uatoms[nbr->GetIdx()])
325
uatoms |= nbr->GetIdx();
326
ubonds |= (*j)->GetIdx();
335
for (bond = mol->BeginBond(j);bond;bond = mol->NextBond(j))
336
if (!ubonds[bond->GetIdx()])
339
return(HasFlag(OE_CLOSURE_BOND));
342
float OEBond::GetEquibLength()
346
// CorrectedBondRad will always return a # now
347
// if (!CorrectedBondRad(GetBeginAtom(),rad1)) return(0.0);
348
// if (!CorrectedBondRad(GetEndAtom(),rad2)) return(0.0);
350
begin = GetBeginAtom();
352
length = etab.CorrectedBondRad(begin->GetAtomicNum(), begin->GetHyb())
353
+ etab.CorrectedBondRad(end->GetAtomicNum(), end->GetHyb());
355
if (IsAromatic()) length *= 0.93f;
356
else if (GetBO() == 2) length *= 0.91f;
357
else if (GetBO() == 3) length *= 0.87f;
361
float OEBond::GetLength()
365
begin = GetBeginAtom();
368
d2 = SQUARE(begin->GetX() - end->GetX());
369
d2 += SQUARE(begin->GetY() - end->GetY());
370
d2 += SQUARE(begin->GetZ() - end->GetZ());