Beispiel #1
0
void
FilterCores::Calculate(OpenBabel::OBMol* mol)
{
   // Any rings?
   OpenBabel::OBAtom* atom;
   std::vector<OpenBabel::OBAtom*>::iterator i;
   bool rings(false);
   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();
   
      // Iteratively remove all endstanding atoms until none are left
      OpenBabel::OBAtom* atom;
      std::vector<OpenBabel::OBAtom*>::iterator i;
      bool endstanding(true);
      while (endstanding && m.NumAtoms())
      {
         endstanding = false;
         for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
         {
            if (atom->GetValence() < 2)
            {
               if (m.DeleteAtom(atom))
               {
                  endstanding = true;
                  break;
               }
            }
         }
      }

      if (m.NumAtoms()) _result = 1;
      else _result = 0;
   }
   else
   {
      _result = 0;
   }
   
   if ((_minLimit && (_result < _min)) || (_maxLimit && (_result > _max)))
   {
      _passed = false;
   }
   else
   {
      _passed = true;
   }  
}
Beispiel #2
0
unsigned int
Schuffenhauer::CalculateHeteroAtoms(OpenBabel::OBMol& mol, OpenBabel::OBRing* ring, int a = 0)
{
   	unsigned int n(0);
   	OpenBabel::OBAtom* atom;
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	for (atom = mol.BeginAtom(avi); atom; atom = mol.NextAtom(avi))
   	{
      	if (ring->IsMember(atom) && (atom->GetAtomicNum() == a))
      	{
         	++n;
      	}
      	if (!a && ring->IsMember(atom))
      	{
         	if ((atom->GetAtomicNum() == 7) ||
				(atom->GetAtomicNum() == 8) ||
				(atom->GetAtomicNum() == 16))
         	{
            	++n;
         	}
      	}
   	}
   	return n;
}
void
FilterBridgeFraction::Calculate(OpenBabel::OBMol* mol)
{
   // Are there rings?
   OpenBabel::OBAtom* atom;
   std::vector<OpenBabel::OBAtom*>::iterator i;
   bool rings(false);
   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();
      unsigned int natoms(m.NumAtoms());
      if (!natoms)
      {
         _result = 0.0;
         _passed = false;
         return;
      }
   
      // Iteratively remove all endstanding atoms until none are left
      OpenBabel::OBAtom* atom;
      std::vector<OpenBabel::OBAtom*>::iterator i;
      bool endstanding(true);
      while (endstanding && m.NumAtoms())
      {
         endstanding = false;
         for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
         {
            if (atom->GetValence() < 2)
            {
               if (m.DeleteAtom(atom))
               {
                  endstanding = true;
                  break;
               }
            }
         }
      }

      // Now remove all ring atoms
      rings = true;
      while (rings && m.NumAtoms())
      {
         rings = false;
         for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
         {
            if (atom->IsInRing())
            {
               if (m.DeleteAtom(atom))
               {
                  rings = true;
                  break;
               }
            }
         }
      }
   
      _result = (double) m.NumAtoms() / (double) natoms;
   }
   else
   {
      _result = 0.0;
   }
   
   if ((_minLimit && (_result < _min)) || (_maxLimit && (_result > _max)))
   {
      _passed = false;
   }
   else
   {
      _passed = true;
   }
}
void
FilterAtomsInSmallestBridge::Calculate(OpenBabel::OBMol* mol)
{
   // Are there rings?
   OpenBabel::OBAtom* atom;
   std::vector<OpenBabel::OBAtom*>::iterator i;
   bool rings(false);
   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();
   
      // Iteratively remove all endstanding atoms until none are left
      OpenBabel::OBAtom* atom;
      std::vector<OpenBabel::OBAtom*>::iterator i;
      bool endstanding(true);
      while (endstanding && m.NumAtoms())
      {
         endstanding = false;
         for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
         {
            if (atom->GetValence() < 2)
            {
               if (m.DeleteAtom(atom))
               {
                  endstanding = true;
                  break;
               }
            }
         }
      }

      // Now remove all ring atoms
      rings = true;
      while (rings && m.NumAtoms())
      {
         rings = false;
         for (atom = m.BeginAtom(i); atom; atom = m.NextAtom(i))
         {
            if (atom->IsInRing())
            {
               if (m.DeleteAtom(atom))
               {
                  rings = true;
                  break;
               }
            }
         }
      }
   
      // Separate into fragments
      if (m.NumAtoms())
      {
         std::vector<std::vector<int> > bridges;
         m.ContigFragList(bridges);
         _result = bridges[0].size();
         for (unsigned int i(1); i < bridges.size(); ++i)
         {
            if (bridges[i].size() < _result) _result = bridges[i].size();
         }
      }

      if ((_minLimit && (_result < _min)) || (_maxLimit && (_result > _max)))
      {
         _passed = false;
      }  
      else
      {
         _passed = true;
      }
   }
   else
   {
      _result = 0;
      _passed = true;
   }
}
Beispiel #5
0
OpenBabel::OBMol
Schuffenhauer::Rule_11(OpenBabel::OBMol& oldMol)
{
   	// Return if the molecule contains an acyclic linker
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	OpenBabel::OBAtom* atom;
   	for (atom = oldMol.BeginAtom(avi); atom; atom = oldMol.NextAtom(avi))
   	{
      	if (!atom->IsInRing() && atom->GetValence() >= 2)
      	{
         	return oldMol;
      	}
   	}
   
   	// Make sure we are dealing with a mixed aromatic/nonaromatic system
   	bool notaromatic(false);
   	bool aromatic(false);
   	for (atom = oldMol.BeginAtom(avi); atom; atom = oldMol.NextAtom(avi))
   	{
      	if (atom->IsAromatic())
      	{
         	aromatic = true;
      	}
      	else
      	{
         	notaromatic = true;
      	}
   	}
   	if (aromatic && notaromatic)
   	{
      	std::vector<OpenBabel::OBRing*> allrings(oldMol.GetSSSR());
     	if (allrings.size() <= _ringsToBeRetained)
      	{
         	return oldMol;
      	}
      
      	std::vector<OpenBabel::OBMol> mols;
      	std::vector<unsigned int> aromaticRings;
      	for (unsigned int i(0); i < allrings.size(); ++i)
      	{
         	if (allrings[i]->IsAromatic())
         	{
            	mols.push_back(oldMol);
            	aromaticRings.push_back(i);
         	}
      	}
   
      	std::vector<OpenBabel::OBMol> validMols;
      	for (unsigned int i(0); i < aromaticRings.size(); ++i)
      	{
         	mols[i] = RemoveRing(mols[i], allrings, aromaticRings[i]);
         	if (!mols[i].Empty())
         	{
            	validMols.push_back(mols[i]);
         	}
      	}

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

   	return oldMol;
}
Beispiel #6
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;
}
Beispiel #7
0
OpenBabel::OBMol
Schuffenhauer::Rule_6(OpenBabel::OBMol& oldMol)
{
   	std::vector<OpenBabel::OBRing*> allrings(oldMol.GetSSSR());
   	if (allrings.size() <= _ringsToBeRetained)
   	{
      	return oldMol;
   	}
   
   	std::vector<OpenBabel::OBMol> mols;
   	std::vector<int> rings;
   	int size;
   	for (unsigned int i(0); i < allrings.size(); ++i)
   	{
      	size = allrings[i]->Size();
      	if ((size == 3) || (size == 5) || (size == 6))
      	{
         	mols.push_back(oldMol);
         	rings.push_back(i);
      	}
   	}
	if (mols.empty())
	{
		return oldMol;
	}

	// Only focus on ringsystems with more than one ring
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	OpenBabel::OBAtom* atom;
	std::vector<int> fusedRings;
	for (unsigned int i(0); i < rings.size(); ++i)
	{
   		for (atom = oldMol.BeginAtom(avi); atom; atom = oldMol.NextAtom(avi))
		{
			if (allrings[rings[i]]->IsMember(atom) && (atom->MemberOfRingCount() > 1))
			{
				fusedRings.push_back(rings[i]);
				break;
			}
		}
	} 
	if (fusedRings.empty())
	{
		return oldMol;
	}
  
   	std::vector<OpenBabel::OBMol> validMols;
   	for (unsigned int i(0); i < fusedRings.size(); ++i)
   	{
      	mols[i] = RemoveRing(mols[i], allrings, fusedRings[i]);
      	if (!mols[i].Empty())
      	{
         	validMols.push_back(mols[i]);
      	}
   	}

 	if (validMols.size() == 1)
   	{
      	return validMols[0];
   	}
   	return oldMol;
}
Beispiel #8
0
OpenBabel::OBMol
Schuffenhauer::Rule_4(OpenBabel::OBMol& oldMol)
{
   	std::vector<OpenBabel::OBRing*> allrings(oldMol.GetSSSR());
   	if (allrings.size() <= _ringsToBeRetained)
   	{
      	return oldMol;
   	}

	// Only focus on ringsystems with more than one ring
   	std::vector<OpenBabel::OBAtom*>::iterator avi;
   	std::vector<OpenBabel::OBMol> mols;
   	OpenBabel::OBAtom* atom;
	std::vector<int> fusedRings;
	for (unsigned int i(0); i < allrings.size(); ++i)
	{
   		for (atom = oldMol.BeginAtom(avi); atom; atom = oldMol.NextAtom(avi))
		{
			if (allrings[i]->IsMember(atom) && (atom->MemberOfRingCount() > 1))
			{
				fusedRings.push_back(i);
		     	mols.push_back(oldMol);
				break;
			}
		}
	}
	if (fusedRings.empty())
	{
		return oldMol;
	}
  
   	std::vector<OpenBabel::OBMol> validMols;
   	for (unsigned int i(0); i < fusedRings.size(); ++i)
   	{
     	mols[i] = RemoveRing(mols[i], allrings, fusedRings[i]);
      	if (!mols[i].Empty())
      	{
         	validMols.push_back(mols[i]);
      	}
   	}
    	if (validMols.empty())
   	{
		return oldMol;
	}
    
	int delta;
	int absdelta;
	std::vector<int> score;
	for (unsigned int i(0); i < validMols.size(); ++i)
	{
		delta = CalculateDelta(validMols[i]);
		absdelta = abs(delta);
		score.push_back(1000 * absdelta + delta);
	}
	int maximum = score[0];
	for (unsigned int i(1); i < validMols.size(); ++i)
	{
		if (score[i] > maximum)
		{
			maximum = score[i];
		}
	}
	unsigned int oldMolecules = validMols.size();
	std::vector<OpenBabel::OBMol> remainingMols;
	for (unsigned int i(0); i < validMols.size(); ++i)
	{
		if (score[i] == maximum)
		{
			remainingMols.push_back(validMols[i]);
		}
	}
	if (remainingMols.size() == 1)
	{
		return remainingMols[0];
    }
   
   	return oldMol;
}
Beispiel #9
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;
   }
}