示例#1
0
int main(int argc,char **argv)
{
   // Create a test molecule
   OpenBabel::OBMol mol;
   OpenBabel::OBAtom* a[5];
   a[0] = mol.NewAtom(); a[0]->SetAtomicNum(6);  a[0]->SetVector(-0.013,  1.086,  0.008);
   a[1] = mol.NewAtom(); a[1]->SetAtomicNum(1);  a[1]->SetVector( 0.002, -0.004,  0.002);
   a[2] = mol.NewAtom(); a[2]->SetAtomicNum(9);  a[2]->SetVector( 1.300,  1.570, -0.002);
   a[3] = mol.NewAtom(); a[3]->SetAtomicNum(35); a[3]->SetVector(-0.964,  1.737, -1.585);
   a[4] = mol.NewAtom(); a[4]->SetAtomicNum(17); a[4]->SetVector(-0.857,  1.667,  1.491);
   OpenBabel::OBBond* b;
   for (int i(1); i < 5; ++i)
   {
      b = mol.NewBond();
      b->SetBegin(a[0]); b->SetEnd(a[i]); b->SetBondOrder(1);
   }
   
   // Run the tests
   test01(&mol);
   test02(&mol);
   test03(&mol);
   test04(&mol);
   test05(&mol);
   test06(&mol);
   test07(&mol);
   test08(&mol);
   test09(&mol);
   
   // End
   return 0;
}
示例#2
0
Coordinate
_hDonCalcNormal(OpenBabel::OBAtom* a)
{
   int nbrBonds(0);
   Coordinate normal;

   std::vector<OpenBabel::OBBond*>::iterator bi;
   for (OpenBabel::OBBond* b = a->BeginBond(bi); b; b = a->NextBond(bi))
   {
      OpenBabel::OBAtom* aa = b->GetNbrAtom(a);
      if (aa->GetAtomicNum() == 1)
      {
         continue;
      }
      ++nbrBonds;
      normal.x += (aa->x() - a->x());
      normal.y += (aa->y() - a->y());
      normal.z += (aa->z() - a->z());
   }
   double length(sqrt(normal.x*normal.x + normal.y*normal.y + normal.z*normal.z));
   normal.x /= length;
   normal.y /= length;
   normal.z /= length;
  
   normal.x = -normal.x;
   normal.y = -normal.y;
   normal.z = -normal.z;
  
   normal.x += a->x();
   normal.y += a->y();
   normal.z += a->z();
  
   return normal;
}
示例#3
0
int spectrophoretest(int argc, char* argv[])
{
  int defaultchoice = 1;
  
  int choice = defaultchoice;

  if (argc > 1) {
    if(sscanf(argv[1], "%d", &choice) != 1) {
      printf("Couldn't parse that input as a number\n");
      return -1;
    }
  }

   // Create a test molecule
   OpenBabel::OBMol mol;
   OpenBabel::OBAtom* a[5];
   a[0] = mol.NewAtom(); a[0]->SetAtomicNum(6);  a[0]->SetVector(-0.013,  1.086,  0.008);
   a[1] = mol.NewAtom(); a[1]->SetAtomicNum(1);  a[1]->SetVector( 0.002, -0.004,  0.002);
   a[2] = mol.NewAtom(); a[2]->SetAtomicNum(9);  a[2]->SetVector( 1.300,  1.570, -0.002);
   a[3] = mol.NewAtom(); a[3]->SetAtomicNum(35); a[3]->SetVector(-0.964,  1.737, -1.585);
   a[4] = mol.NewAtom(); a[4]->SetAtomicNum(17); a[4]->SetVector(-0.857,  1.667,  1.491);
   OpenBabel::OBBond* b;
   for (int i(1); i < 5; ++i)
   {
      b = mol.NewBond();
      b->SetBegin(a[0]); b->SetEnd(a[i]); b->SetBondOrder(1);
   }
   
  switch(choice) {
  case 1:
    test01(&mol);
    test02(&mol);
    break;
  case 2:
    test03(&mol);
    test04(&mol);
    break;
  case 3:
    test05(&mol);
    test06(&mol);
    break;
  case 4:
    test07(&mol);
    test08(&mol);
    break;
  case 5:
    test09(&mol);
    break;
  default:
    std::cout << "Test number " << choice << " does not exist!\n";
    return -1;
  }

  return 0;
}
示例#4
0
  void StereoCenterItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  {
    Molecule *mol = molecule();
    
    painter->save();
    painter->setPen(Qt::green);

    if (!mol) {
      // not connected: default behaviour (draw connectable box)
      MolInputItem::paint(painter, option, widget);
      painter->restore();
      return;
    }

    const QList<Atom*> &atoms = mol->atoms();
    OpenBabel::OBMol *obmol = mol->OBMol();
    QPointF offset(-5.0, 5.0);

#ifdef OPENBABEL2_TRUNK
    // need to calculate symmetry first
    std::vector<unsigned int> symmetry_classes;
    OpenBabel::OBGraphSym graphsym(obmol);
    graphsym.GetSymmetry(symmetry_classes);

    //std::vector<unsigned long> atomIds = FindTetrahedralAtoms(obmol, symmetry_classes);
    std::vector<OpenBabel::StereogenicUnit> units = FindStereogenicUnits(obmol, symmetry_classes);
    
    for (unsigned int i = 0; i < units.size(); ++i) {
      if (units.at(i).type == OpenBabel::OBStereo::Tetrahedral) {
        OpenBabel::OBAtom *obatom = obmol->GetAtomById(units.at(i).id);
        painter->drawEllipse(mapFromItem(mol, atoms[obatom->GetIndex()]->pos()), 10, 10);
      } else 
      if (units.at(i).type == OpenBabel::OBStereo::CisTrans) {
        OpenBabel::OBBond *obbond = obmol->GetBondById(units.at(i).id);
        OpenBabel::OBAtom *obatom1 = obbond->GetBeginAtom();
        OpenBabel::OBAtom *obatom2 = obbond->GetEndAtom();
        painter->drawEllipse(mapFromItem(mol, atoms[obatom1->GetIndex()]->pos()), 10, 10);
        painter->drawEllipse(mapFromItem(mol, atoms[obatom2->GetIndex()]->pos()), 10, 10);
      } 
 
    }
#else
    using OpenBabel::OBMolAtomIter;
    FOR_ATOMS_OF_MOL(atom, obmol)
      if (atom->IsChiral())
        painter->drawEllipse(mapFromItem(mol, atoms[atom->GetIdx()-1]->pos()), 10, 10);
#endif

    // default behavious (draw the label())
    MolInputItem::paint(painter, option, widget);
    painter->restore();
  }
示例#5
0
void
Fingerprint::_getFragments(std::vector<int> levels, std::vector<int>curfrag, 
int level, OpenBabel::OBAtom* patom, OpenBabel::OBBond* pbond)
{
   const int MaxFragSize = 7;
   int bo(0);
   if (pbond) bo = pbond->IsAromatic() ? 5 : pbond->GetBondOrder();

   curfrag.push_back(bo);
   curfrag.push_back(patom->GetAtomicNum());
   levels[patom->GetIdx()] = level;

   std::vector<OpenBabel::OBBond*>::iterator i;
   OpenBabel::OBBond* pnewbond;
   for (pnewbond = patom->BeginBond(i); pnewbond; pnewbond = patom->NextBond(i))
   {
      if (pnewbond == pbond)
      {
         continue;
      }
      OpenBabel::OBAtom* pnxtat = pnewbond->GetNbrAtom(patom);
      int atlevel = levels[pnxtat->GetIdx()];
      if (atlevel)
      {
         if (atlevel == 1)
         {
            curfrag[0] = bo;
            _ringset.insert(curfrag);
         }
      }
      else
      {
         if (level < MaxFragSize)
         {
            _getFragments(levels, curfrag, level + 1, pnxtat, pnewbond);
         }
      }
   }
   
   if ((curfrag[0] == 0) &&
      ((level > 1) || (patom->GetAtomicNum() > 8) || (patom->GetAtomicNum() < 6)))
   {
      _fragset.insert(curfrag);
   }
}
    //--
    // [rad] generate path and ident for bond
    void RelationBond::GetPathAndIdentBond(const std::string& refMoleculeId, std::string& refPath, std::string& refIdent)
    {
				
				refPath = m_vecSatisfiedClasses.front()->GetPrefix() + ":" + m_vecSatisfiedClasses.front()->GetName();

				std::stringstream ssConv;
				OpenBabel::OBBond* pBond = m_pBond;

				OpenBabel::OBAtom* pAtomStart = pBond->GetBeginAtom();
				OpenBabel::OBAtom* pAtomEnd = pBond->GetEndAtom();


				ssConv << m_vecSatisfiedClasses.front()->GetName() << "_" << refMoleculeId << "_" <<
					pAtomStart->GetIdx() << "_"	<< pAtomEnd->GetIdx();

				refIdent = "";
				ssConv >> refIdent;
    }
示例#7
0
unsigned int
Schuffenhauer::CalculateAcyclicBonds(OpenBabel::OBMol& mol)
{
   	unsigned int nbonds(0);
   	OpenBabel::OBAtom* nbratom[2];
   	OpenBabel::OBBond* bond;
   	std::vector<OpenBabel::OBBond*>::iterator bvi;
   	for (bond = mol.BeginBond(bvi); bond; bond = mol.NextBond(bvi))
   	{
      	nbratom[0] = bond->GetBeginAtom();
      	nbratom[1] = bond->GetEndAtom();
		if (nbratom[0] && nbratom[1])
		{
      		if (!bond->IsInRing() && 
				(nbratom[0]->GetValence() > 1) && 
				(nbratom[1]->GetValence() > 1))
      		{
         		++nbonds;
      		}
		}
   	}
   	return nbonds;
}
示例#8
0
bool
Schuffenhauer::HasLinkerToHeteroAtom(OpenBabel::OBMol& mol, OpenBabel::OBRing* ring)
{
   	std::vector<OpenBabel::OBBond*>::iterator bvi;
   	OpenBabel::OBBond* bond;
   	OpenBabel::OBAtom* nbrAtom[2];
   	for (bond = mol.BeginBond(bvi); bond; bond = mol.NextBond(bvi))
   	{
      	nbrAtom[0] = bond->GetBeginAtom();
      	nbrAtom[1] = bond->GetEndAtom();
      	if
		(
			// Neighbours are real
			nbrAtom[0] &&
			nbrAtom[1] &&
			
			// Bond should be acyclic
			!bond->IsInRing() &&
			
			// Both atoms have to be ring atoms
			nbrAtom[0]->IsInRing() && 
			nbrAtom[1]->IsInRing() && 
			
			// At least one of the atoms should be hetero
			(nbrAtom[0]->IsHeteroatom() || nbrAtom[1]->IsHeteroatom()) &&
			
			// One of the atoms, but not both, should be part of this ring	
			((ring->IsMember(nbrAtom[0]) && !ring->IsMember(nbrAtom[1])) ||
			(ring->IsMember(nbrAtom[1]) && !ring->IsMember(nbrAtom[0])))
		)
		{
         	return true;
     	}
   	}
   	return false;
}
示例#9
0
bool
Oprea_1::CalculateScaffold(const OpenBabel::OBMol& mol, Options* o)
{
	OpenBabel::OBMol m(mol);
	OpenBabel::OBAtom* atom;
	OpenBabel::OBAtom* nbrAtom[2];
	OpenBabel::OBBondIterator bi;
	std::vector<OpenBabel::OBAtom*>::iterator avi;
	OpenBabel::OBBond* bond;
	std::vector<OpenBabel::OBBond*>::iterator bvi;
	bool removed(true);
	while (removed)
	{
		removed = false;
		for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
		{
			if (IsEndStanding(atom, false, false))
			{
				m.DeleteAtom(atom);
				removed = true;
				break;
			}
		}
	}

	// Make all atoms as neutral C and all bond orders equal to 1
 	m.BeginModify();
	for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
	{
		atom->SetAtomicNum(6);
		atom->SetFormalCharge(0);
	}
	for (bond = m.BeginBond(bvi); bond; bond = m.NextBond(bvi))
	{
		bond->SetBondOrder(1);
	}
	m.EndModify();
   
   	// Transform all neighbouring linker atoms into a single bond
   	removed = true;
   	while (removed)
   	{
		removed = false;
		for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
		{
			if (!atom->IsInRing() && (atom->GetValence() == 2))
			{
		        nbrAtom[0] = atom->BeginNbrAtom(bi);
		        nbrAtom[1] = atom->NextNbrAtom(bi);
				if (nbrAtom[0] && nbrAtom[1])
				{
					m.BeginModify();
		        	m.AddBond(nbrAtom[0]->GetIdx(), nbrAtom[1]->GetIdx(), 1);
		        	m.DeleteAtom(atom);
		      		m.EndModify();
					removed = true;
					break;
				}
			}
		}
   	}

   	// Shrink all rings to their minimum size
   	removed = true;
   	while (removed)
   	{
      	removed = false;
      	for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
      	{
         	if ((atom->MemberOfRingSize() > 3) &&
				(atom->GetValence() == 2))
         	{
            	nbrAtom[0] = atom->BeginNbrAtom(bi);
            	nbrAtom[1] = atom->NextNbrAtom(bi);
				if (nbrAtom[0] && nbrAtom[1])
				{
            		m.BeginModify();
            		m.AddBond(nbrAtom[0]->GetIdx(), nbrAtom[1]->GetIdx(), 1);
            		m.DeleteAtom(atom);
            		m.EndModify();
            		removed = true;
            		break;
				}
         	}
      	}
   	}
   
   	if (!m.Empty())
	{
 		_smiles = _mol2can.WriteString(&m, true);
	}
   	else
   	{
      	_smiles = "-";
      	return false;
   	}
   	return true;
}
示例#10
0
bool
Oprea_2::CalculateScaffold(const OpenBabel::OBMol& mol, Options* o)
{
   	OpenBabel::OBMol m(mol);

   	// Tag all HBD
   	std::vector<bool> hbd(m.NumAtoms() + 1);
   	for (OpenBabel::OBMolAtomIter atom(m); atom; ++atom)
   	{    
		if (atom->MatchesSMARTS("[NH,NH2,NH3,OH,nH]"))
      	{
         	hbd[atom->GetIdx()] = true;
      	}
      	else
      	{
         	hbd[atom->GetIdx()] = false;
      	}
   	}
   
   	// Tag all HBA
   	std::vector<bool> hba(m.NumAtoms() + 1);
   	for (OpenBabel::OBMolAtomIter atom(m); atom; ++atom)
   	{   
 		if (!atom->IsAmideNitrogen() &&        // No amide nitrogen
			!atom->IsAromatic() &&             // Not aromatic
			(atom->GetFormalCharge() <= 0) &&    // No + charge
			atom->MatchesSMARTS("[NH0]"))        // No hydrogens
      	{
         	hba[atom->GetIdx()] = true;
      	}
      	else
		if (atom->IsNitrogen() &&              // Nitrogen
          	atom->IsAromatic() &&              // Aromatic
			atom->MatchesSMARTS("[nH0]") && 	   // No hydrogens
         	(atom->GetHvyValence() <= 2) &&    // Maximal two non-H atoms connected
         	(atom->GetFormalCharge() <= 0))    // No + charge
      	{     
         	hba[atom->GetIdx()] = true;
      	}
      	else
      	if (atom->IsOxygen() &&                // Oxygen
         	(atom->GetFormalCharge() <= 0))    // No + charge
      	{
         	hba[atom->GetIdx()] = true;
     	}
      	else
      	{
          	hba[atom->GetIdx()] = false;
      	}
   	}
   
   	// Mark the C(=O) or S(=O) also as HBA
   	for (OpenBabel::OBMolAtomIter atom(m); atom; ++atom)
   	{   
		if (atom->MatchesSMARTS("C=O"))
		{
         	hba[atom->GetIdx()] = true;
		}
		else
		if (atom->MatchesSMARTS("S=O"))
		{
         	hba[atom->GetIdx()] = true;
		} 
	}

   	// Make all atoms as neutral C, N (HBD), or O (HBA)
   	m.BeginModify();
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	OpenBabel::OBAtom* atom;
   	for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
   	{
      	if (hba[atom->GetIdx()])
		{
			atom->SetAtomicNum(8);
		}
      	else
		if (hbd[atom->GetIdx()])
		{
			atom->SetAtomicNum(7);
		}
      	else
		{
			atom->SetAtomicNum(6);
		}
      	atom->SetFormalCharge(0);
   	}
   	m.EndModify();

	// Remove all endstanding atoms
   	OpenBabel::OBBondIterator bi;
  	OpenBabel::OBBond* bond;
   	std::vector<OpenBabel::OBBond*>::iterator bvi;
    bool removed(true);
   	while (removed)
   	{
      	removed = false;
      	for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
      	{
         	if (IsEndStanding(atom, false, false))
         	{
	         	m.DeleteAtom(atom);
            	removed = true;
				break;
         	}
      	}
   	}
   
   	// Set all bond orders equal to 1
   	m.BeginModify();
   	for (bond = m.BeginBond(bvi); bond; bond = m.NextBond(bvi))
   	{
      	bond->SetBondOrder(1);
   	}
   	m.EndModify();

   	// Transform all neighbouring linker atoms into a single bond
   	removed = true; 
	OpenBabel::OBAtom* nbrAtom[2];
   	while (removed)
   	{
		removed = false;
		for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
		{
			if (!atom->IsInRing() && (atom->GetValence() == 2))
			{
				m.BeginModify();
		        nbrAtom[0] = atom->BeginNbrAtom(bi);
		        nbrAtom[1] = atom->NextNbrAtom(bi);
				if (nbrAtom[0] && nbrAtom[1])
				{
		        	m.AddBond(nbrAtom[0]->GetIdx(), nbrAtom[1]->GetIdx(), 1);
		        	m.DeleteAtom(atom);
		      		m.EndModify();
					removed = true;
					break;
				}
			}
		}
   	}

   	// Shrink all rings to their minimum size
   	removed = true;
   	while (removed)
   	{
      	removed = false;
      	for (atom = m.BeginAtom(avi); atom; atom = m.NextAtom(avi))
      	{
         	if ((atom->MemberOfRingSize() > 3) && (atom->GetValence() == 2))
         	{
            	nbrAtom[0] = atom->BeginNbrAtom(bi);
            	nbrAtom[1] = atom->NextNbrAtom(bi);
				if (nbrAtom[0] && nbrAtom[1])
				{
            		if (nbrAtom[0]->GetAtomicNum() == atom->GetAtomicNum())
            		{
               			m.BeginModify();
               			m.AddBond(nbrAtom[0]->GetIdx(), nbrAtom[1]->GetIdx(), 1);
               			m.DeleteAtom(atom);
               			m.EndModify();
               			removed = true;
               			break;
            		}
            		else
					if (nbrAtom[1]->GetAtomicNum() == atom->GetAtomicNum())
            		{
               			m.BeginModify();
               			m.AddBond(nbrAtom[0]->GetIdx(), nbrAtom[1]->GetIdx(), 1);
               			m.DeleteAtom(atom);
               			m.EndModify();
               			removed = true;
               			break;
					}
            	}
         	}
      	}
   	}

   	if (!m.Empty())
	{
		_smiles = _mol2can.WriteString(&m, true);
	}
   	else
   	{
      	_smiles = "-";
      	return false;
   	}
   	return true;
}
示例#11
0
OpenBabel::OBMol
Schuffenhauer::RemoveRing(OpenBabel::OBMol& oldMol, 
std::vector<OpenBabel::OBRing*>& rings, unsigned int ringIdx)
{
	OpenBabel::OBMol newMol(oldMol);

	// Make list of the ring bonds
	std::set<OpenBabel::OBBond*> ringBonds;
	OpenBabel::OBBond* bond;
	std::vector<OpenBabel::OBBond*>::iterator bvi;
	for (bond = newMol.BeginBond(bvi); bond; bond = newMol.NextBond(bvi))
	{
		if (rings[ringIdx]->IsMember(bond))
		{
			ringBonds.insert(bond);
		}
	}
	
	// Make list of delocalizable bonds (aromatic, single and flanked by two double bonds)
	std::set<OpenBabel::OBBond*> delocalizableBonds;
	std::set<OpenBabel::OBBond*>::iterator bli;
	OpenBabel::OBBondIterator bi;
	OpenBabel::OBAtom* atom;
	OpenBabel::OBBond* nbrBond;
	unsigned int n;
	for (bli = ringBonds.begin(); bli != ringBonds.end(); ++bli)
	{
		bond = *bli;
		if ((bond->GetBondOrder() == 1) && 
			bond->IsAromatic())
		{
			n = 0;
			atom = bond->GetBeginAtom();
			for (nbrBond = atom->BeginBond(bi); nbrBond; nbrBond = atom->NextBond(bi))
			{
				if ((nbrBond != bond) && 
					ringBonds.count(nbrBond) && 
					(nbrBond->GetBondOrder() == 2))
				{
					++n;
				}
			}
			atom = bond->GetEndAtom();
			for (nbrBond = atom->BeginBond(bi); nbrBond; nbrBond = atom->NextBond(bi))
			{
				if ((nbrBond != bond) && 
					ringBonds.count(nbrBond) &&
					(nbrBond->GetBondOrder() == 2))
				{
					++n;
				}
			}
		}
		if (n == 2)
		{
			delocalizableBonds.insert(bond);
		}
	}
	
	// Make list of bonds which form the fusion with other rings
	std::set<OpenBabel::OBBond*> fusionBonds;
	for (bli = ringBonds.begin(); bli != ringBonds.end(); ++bli)
	{
		bond = *bli;
		for (unsigned int i(0); i < rings.size(); ++i)
		{
			if (i != ringIdx)
			{
				if (rings[i]->IsMember(bond))
				{
					fusionBonds.insert(bond);
				}
			}
		}
	}
   
	// Make list of bonds which are the fusion between aromatic and non-aromatic
	std::set<OpenBabel::OBBond*> aromaticNonaromaticFusionBonds;
	if (rings[ringIdx]->IsAromatic())
	{
		for (bli = fusionBonds.begin(); bli != fusionBonds.end(); ++bli)
		{
			bond = *bli;
			for (unsigned int i(0); i < rings.size(); ++i)
			{
				if (i != ringIdx)
				{
					if (rings[i]->IsMember(bond) && 
						!rings[i]->IsAromatic())
					{
						aromaticNonaromaticFusionBonds.insert(bond);
					}
				}
			}
		}
	}
   
	// Make list of bonds which are the fusion between aromatic and aromatic
	std::set<OpenBabel::OBBond*> aromaticAromaticFusionBonds;
	if (rings[ringIdx]->IsAromatic())
	{
		for (bli = fusionBonds.begin(); bli != fusionBonds.end(); ++bli)
		{
			bond = *bli;
			for (unsigned int i(0); i < rings.size(); ++i)
			{
				if (i != ringIdx)
				{
					if (rings[i]->IsMember(bond) &&
						rings[i]->IsAromatic())
					{
						aromaticAromaticFusionBonds.insert(bond);
					}
				}
 			}
		}
	}

	// Remove ring
	std::set<OpenBabel::OBBond*> bondsToBeDeleted;  
	std::set<OpenBabel::OBAtom*> atomsToBeDeleted;  
	OpenBabel::OBAtom* nbrAtom[2];
	for (bli = ringBonds.begin(); bli != ringBonds.end(); ++bli)
	{
		bond = *bli;
		if (fusionBonds.count(bond))
		{
			continue;
		}
		else
		{
			bondsToBeDeleted.insert(bond);
			nbrAtom[0] = bond->GetBeginAtom();
			nbrAtom[1] = bond->GetEndAtom();
			if (nbrAtom[0] && nbrAtom[1])
			{
				if (nbrAtom[0]->MemberOfRingCount() == 1)
				{
					atomsToBeDeleted.insert(nbrAtom[0]);
				}
				if (nbrAtom[1]->MemberOfRingCount() == 1)
				{
					atomsToBeDeleted.insert(nbrAtom[1]);
				}
			}
		}
	}
	newMol.BeginModify();
	for (bli = bondsToBeDeleted.begin(); bli != bondsToBeDeleted.end(); ++bli)
	{
		newMol.DeleteBond(*bli);
	}
	newMol.EndModify();
	newMol.BeginModify();
	std::set<OpenBabel::OBAtom*>::iterator ali;
	for (ali = atomsToBeDeleted.begin(); ali != atomsToBeDeleted.end(); ++ali)
	{
		newMol.DeleteAtom(*ali);
	}
	newMol.EndModify();
	
	// Correct the bond orders of the ex-fusion bond(s)
	newMol.BeginModify();
	for (bond = newMol.BeginBond(bvi); bond; bond = newMol.NextBond(bvi))
	{
		if (aromaticNonaromaticFusionBonds.count(bond))
		{
			bond->SetBondOrder(2);
		} 
		else
		if (aromaticAromaticFusionBonds.count(bond) && 
			delocalizableBonds.count(bond))
		{
			bond->SetBondOrder(2);
		} 
 	}
	newMol.EndModify();
   
	// Remove single atoms that originate from exocyclic bonds at ring
	(void) RemoveSidechains(&newMol);
	
	// Check if there are atoms with valences that are not allowed
	std::vector<OpenBabel::OBAtom*>::iterator avi;
	for (atom = newMol.BeginAtom(avi); atom; atom = newMol.NextAtom(avi))
	{
		if (atom->IsCarbon() &&
			(atom->BOSum() > 4))
		{
			newMol.Clear();
			break;
		}
		else
		if (atom->IsNitrogen() &&
			(atom->BOSum() > 3))
		{
			newMol.Clear();
			break;
		}
		else
		if (atom->IsOxygen() &&
			(atom->BOSum() > 2))
		{
			newMol.Clear();
			break;
		}
	}
	
	// Check if there are no discontinuous fragments
	if (newMol.Separate().size() > 1)
	{
		newMol.Clear();
	}
	
	return newMol;
}
示例#12
0
OpenBabel::OBMol
Schuffenhauer::Rule_7(OpenBabel::OBMol& oldMol)
{
   	std::vector<OpenBabel::OBRing*> allrings(oldMol.GetSSSR());
   	if (allrings.size() <= _ringsToBeRetained)
   	{
      	return oldMol;
   	}

   	// Are all atoms and bonds aromatic?
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	OpenBabel::OBAtom* atom;
   	for (atom = oldMol.BeginAtom(avi); atom; atom = oldMol.NextAtom(avi))
   	{
      	if (!atom->IsAromatic())
      	{
         	return oldMol;
      	}
   	}
   	std::vector<OpenBabel::OBBond*>::iterator bvi;
   	OpenBabel::OBBond* bond;
   	for (bond = oldMol.BeginBond(bvi); bond; bond = oldMol.NextBond(bvi))
   	{
      	if (!bond->IsAromatic())
      	{
         	return oldMol;
      	}
   	}

   	std::vector<OpenBabel::OBMol> mols;
   	for (unsigned int i(0); i < allrings.size(); ++i)
   	{
      	mols.push_back(oldMol);
   	}
   
   	std::vector<OpenBabel::OBMol> validMols;
   	for (unsigned int i(0); i < mols.size(); ++i)
   	{
      	mols[i] = RemoveRing(mols[i], allrings, i);
      	if (!mols[i].Empty())
      	{
         	// Has aromaticity been broken?
         	bool broken(false);
         	for (atom = mols[i].BeginAtom(avi); atom; atom = mols[i].NextAtom(avi))
         	{
            	if (atom->IsInRing() && !atom->IsAromatic())
            	{
               		broken = true;
               		break;
            	}
         	}
         	if (!broken)
         	{
            	validMols.push_back(mols[i]);
         	}
      	}
   	}

	if (validMols.size() == 1)
   	{
      	return validMols[0];
   	}

   	return oldMol;
}
示例#13
0
void
FilterRingsystems::Calculate(OpenBabel::OBMol* mol)
{
   // Are there rings?
   bool rings(false);
   OpenBabel::OBAtom* atom;
   std::vector<OpenBabel::OBAtom*>::iterator i;
   for (atom = mol->BeginAtom(i); atom; atom = mol->NextAtom(i))
   {
      if (atom->IsInRing())
      {
         rings = true;
         break;
      }
   }
   
   if (rings)
   {
      // Make workcopy of original mol
      OpenBabel::OBMol m = *mol; m.DeleteHydrogens();
   
      // Remove all atoms that are not part of ring
      std::vector<OpenBabel::OBAtom*> nonRingAtoms;
      nonRingAtoms.clear();
      for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
      {
         if (!atom->IsInRing()) nonRingAtoms.push_back(atom);
      }
      for (unsigned int i(0); i < nonRingAtoms.size(); ++i)
      {
         m.DeleteAtom(nonRingAtoms[i]);
      }
      
      // Remove all bonds that are not part of a ring
      std::vector<OpenBabel::OBBond*> nonRingBonds;
      nonRingBonds.clear();
      OpenBabel::OBBond* bond;
      std::vector<OpenBabel::OBBond*>::iterator j;
      for (bond = m.BeginBond(j); bond; bond = m.NextBond(j))
      {
         if (!bond->IsInRing()) nonRingBonds.push_back(bond);
      }
      for (unsigned int i(0); i < nonRingBonds.size(); ++i)
      {
         m.DeleteBond(nonRingBonds[i]);
      }
      
      // Count ringsystems
      std::vector<std::vector< int > > ringsystems;
      m.ContigFragList(ringsystems);
      _result = ringsystems.size();

   }
   else
   {
      _result = 0;
   }
   
   if ((_minLimit && (_result < _min)) || (_maxLimit && (_result > _max)))
   {
      _passed = false;
   }
   else
   {
      _passed = true;
   }
}