bool GetDFFVector(OBMol &mol,vector<int> &dffv,OBBitVec &bv) { dffv.clear(); dffv.resize(mol.NumAtoms()); int dffcount,natom; OBBitVec used,curr,next; OBAtom *atom,*atom1; OBBond *bond; vector<OBAtom*>::iterator i; vector<OBBond*>::iterator j; next.Clear(); for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i)) { if (bv[atom->GetIdx()]) { dffv[atom->GetIdx()-1] = 0; continue; } dffcount = 0; used.Clear(); curr.Clear(); used.SetBitOn(atom->GetIdx()); curr.SetBitOn(atom->GetIdx()); while (!curr.IsEmpty() && (bv&curr).Empty()) { next.Clear(); for (natom = curr.NextBit(-1);natom != curr.EndBit();natom = curr.NextBit(natom)) { atom1 = mol.GetAtom(natom); for (bond = atom1->BeginBond(j);bond;bond = atom1->NextBond(j)) if (!used.BitIsOn(bond->GetNbrAtomIdx(atom1)) && !curr.BitIsOn(bond->GetNbrAtomIdx(atom1))) if (!(bond->GetNbrAtom(atom1))->IsHydrogen()) next.SetBitOn(bond->GetNbrAtomIdx(atom1)); } used |= next; curr = next; dffcount++; } dffv[atom->GetIdx()-1] = dffcount; } return(true); }
static void FindRings(OBMol &mol,vector<int> &path,OBBitVec &avisit, OBBitVec &bvisit, int natom,int depth ) { OBAtom *atom; OBBond *bond; vector<OBBond*>::iterator k; // don't return if all atoms are visited // (For example, some atoms are in multiple rings!) -GRH if (avisit[natom]) { int j = depth-1; bond=mol.GetBond(path[j--]); bond->SetInRing(); while( j >= 0 ) { bond=mol.GetBond(path[j--]); bond->SetInRing(); (bond->GetBeginAtom())->SetInRing(); (bond->GetEndAtom())->SetInRing(); if(bond->GetBeginAtomIdx()==static_cast<unsigned int>(natom) || bond-> GetEndAtomIdx()==static_cast<unsigned int>(natom)) break; } } else { avisit.SetBitOn(natom); atom = mol.GetAtom(natom); for(bond = atom->BeginBond(k);bond;bond=atom->NextBond(k)) if( !bvisit[bond->GetIdx()]) { path[depth] = bond->GetIdx(); bvisit.SetBitOn(bond->GetIdx()); FindRings(mol,path,avisit,bvisit,bond->GetNbrAtomIdx(atom), depth+1); } } }