OBMolPairIter::OBMolPairIter(OBMol &mol) { _parent = &mol; bool foundPair = false; OBAtom *a = _parent->BeginAtom(_i); if (!a) return; OBAtom *b = _parent->BeginAtom(_j); while (!foundPair) { b = _parent->NextAtom(_j); if (!b) { a = _parent->NextAtom(_i); if (!a) return; b = _parent->BeginAtom(_j); } if (a->GetIdx() >= b->GetIdx()) continue; if (a->IsConnected(b)) continue; if (a->IsOneThree(b)) continue; foundPair = true; } _pair.clear(); _pair.push_back(a->GetIdx()); _pair.push_back(b->GetIdx()); }
bool OBCisTransStereo::IsOnSameAtom(unsigned long id1, unsigned long id2) const { const OBMol *mol = GetMolecule(); if (!mol) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : No valid molecule set", obError); return false; } OBAtom *begin = mol->GetAtomById(m_cfg.begin); if (!begin) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Begin reference id is not valid.", obError); return false; } OBAtom *end = mol->GetAtomById(m_cfg.end); if (!end) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : End reference id is not valid.", obError); return false; } OBAtom *a = mol->GetAtomById(id1); OBAtom *b = mol->GetAtomById(id2); if (a && b) { // both on begin atom? if (a->IsConnected(begin) && b->IsConnected(begin)) return true; // both on end atom? if (a->IsConnected(end) && b->IsConnected(end)) return true; return false; } else { if (a) { // b atom not found, could be a deleted hydrogen... if (a->IsConnected(begin)) { // a is connected to begin. if this is the atom missing a hydrogen, return false if (begin->GetValence() == 2) return true; // check if the end atom really is missing an atom if (end->GetValence() != 2) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : id2 is not valid and is not a missing hydrogen.", obError); return false; } // inform user we are treating id2 as deleted hydrogen obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id2 doesn't exist anymore, must be a (deleted) hydrogen.", obInfo); } else if (a->IsConnected(end)) { // a is connected to end. again, if this is the atom missing a hydrogen, return false if (end->GetValence() == 2) return true; // check if the begin atom really is missing an atom if (begin->GetValence() != 2) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : id2 is not valid and is not a missing hydrogen.", obError); return true; } // inform user we are treating id2 as deleted hydrogen obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id2 doesn't exist, must be a (deleted) hydrogen.", obInfo); } else { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id1 isn't connected to the begin or end atom.", obError); return true; } } else if (b) { // a atom not found, could be a deleted hydrogen... if (b->IsConnected(begin)) { // b is connected to begin. if this is the atom missing a hydrogen, return false if (begin->GetValence() == 2) return true; // check if the end atom really is missing an atom if (end->GetValence() != 2) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : id1 is not valid and is not a missing hydrogen.", obError); return true; } // inform user we are treating id1 as deleted hydrogen obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id1 doesn't exist, must be a (deleted) hydrogen.", obInfo); } else if (b->IsConnected(end)) { // a is connected to end. again, if this is the atom missing a hydrogen, return false if (end->GetValence() == 2) return true; // check if the begin atom really is missing an atom if (begin->GetValence() != 2) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : id1 is not valid and is not a missing hydrogen.", obError); return true; } // inform user we are treating id2 as deleted hydrogen obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id1 doesn't exist, must be a (deleted) hydrogen.", obInfo); } else { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atom with id1 isn't connected to the begin or end atom.", obError); return true; } } else { OBAtom *c = 0, *d = 0; // no a & b, check the remaining ids which will reveal same info for (int i = 0; i < 4; ++i) { if ((m_cfg.refs.at(i) == id1) || (m_cfg.refs.at(i) == id2)) continue; if (!c) { c = mol->GetAtomById(m_cfg.refs.at(i)); } else { d = mol->GetAtomById(m_cfg.refs.at(i)); } } if (!c || !d) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : invalid stereochemistry!", obError); return true; } if ((begin->GetValence() != 2) || (end->GetValence() != 2)) { obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : invalid stereochemistry!", obError); return true; } obErrorLog.ThrowError(__FUNCTION__, "OBCisTransStereo::IsOnSameAtom : Atoms with id1 & id2 don't exist, must be a (deleted) hydrogens.", obInfo); return IsOnSameAtom(c->GetId(), d->GetId()); } } return false; }