Your SlideShare is downloading. ×
Open Babel 2.3 Quick Reference
Open Babel 2.3 Quick Reference
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Open Babel 2.3 Quick Reference


Published on

1 Like
  • Be the first to comment

No Downloads
Total Views
On Slideshare
From Embeds
Number of Embeds
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

No notes for slide


  • 1. // Automatic format perception // Molecular formula Open Babel 2.3 std::ifstream ifs(filename); OBConversion conv; (std::string) mol.GetFormula(); C++ API OBFormat* inFormat = conv.FormatFromExt(filename); OBFormat* outFormat = conv.SetFormat("SDF"); // Conformations (int) mol.NumConformers(); if (inFormat && outFormat) Quick reference guide { conv.SetInAndOutFormats(inFormat, outFormat); // Smallest set of smallest rings (std::vector<OBRing*>) mol.GetSSSR(); } // Hydrogen manipulations (bool) mol.DeleteHydrogens(); // All H (bool) mol.AddPolarHydrogens(); // Polar H Namespace
 (bool) mol.AddHydrogens(); // All H // Generic data using namespace OpenBabel; #include <openbabel/obiter.h> std::vector<OBGenericData*>::iterator k; #include <openbabel/mol.h> std::vector<OBGenericData*> vdata = mol.GetData(); for (k = vdata.begin(); k != vdata.end(); ++k) using namespace OpenBabel; if ((*k)->GetDataType() == OBGenericDataType::PairData) Reading
 OBMol mol; { std::cout << "> <" << (*k)->GetAttribute(); OBAtom* atom; std::cout << ">" << std::endl; #include <openbabel/mol.h> OBAtom* nbrAtom; std::cout << ((OBPairData*)(*k))->GetValue(); #include <openbabel/obconversion.h> OBBond* bond; std::cout << std::endl; } int main(int argc, char **argv) // Looping over all atoms { double exactMass(0.0); // Remove all but the largest fragments OBMol mol; FOR_ATOMS_OF_MOL(atom, mol) (bool) mol.StripSalts(0); { // Read from standard input and write to exactMass += atom->GetExactMass(); // Clear molecule for re-use // standard output } (bool) mol.Clear(); OBConversion conv(&std::cin, &std::cout); // Looping over all bonds // Input format is sd-file, output format unsigned int totalBondOrder(0); // is canonical smiles if (conv.SetInAndOutFormats("sdf", "can")) FOR_BONDS_OF_MOL(bond, mol) { Atoms
 { totalBondOrder += bond->GetBondOrder(); if (conv.Read(&mol)) } #include <openbabel/atom.h> { // Looping over all neighbor atoms of given atom // Print number of atoms unsigned int nAtoms(0); OBAtom atom; std::cerr << "Molecule has: " << FOR_NBORS_OF_ATOM(nbrAtom, atom) ++nAtoms; mol.NumAtoms() << " atoms.n"; // Properties } (int) atom.GetFormalCharge(); conv->Write(&mol); (unsigned int) atom.GetAtomicNum(); } mol.Clear(); Element
 (double) atom.GetAtomicMass(); return 0; // Explicit and maximum expected connections } #include <openbabel/data.h> (unsigned int) atom.GetValence(); (unsigned int) atom.GetImplicitValence(); OBElementTable etab; // Non-hydrogen connections Conversion
 (char*) (int) etab.GetSymbol(6); etab.GetAtomicNum("C"); (unsigned int) atom.GetHvyValence(); (double) etab.GetVdwRad(7); // Implicit and explicit hydrogens #include <openbabel/obconversion.h> (double) etab.GetCovalentRad(8); (unsigned int) atom.ImplicitHydrogenCount(); #include <openbabel/mol.h> (double) etab.GetMass(1); (unsigned int) atom.ExplicitHydrogenCount(); // Create molecule from SMILES string // Is atom in ring of size 6? std::string SmilesString("c1ccccc1"); (bool) atom.IsInRing() && atom.IsInRingSize(6); OBMol mol; stringstream ss(SmilesString) Molecules
 // Size of smallest ring that contains the atom OBConversion conv(&ss); (unsigned int) atom.MemberOfRingSize(); if (conv.SetInFormat("smi") && conv.Read(&mol)) #include <openbabel/mol.h> { /* ... */ } #include <openbabel/generic.h> // Number of rings that contain the atom (unsigned int) atom.MemberOfRingCount(); // Conversion without manipulation OBMol mol; OBConversion conv(&is, &os); if (conv.SetInAndOutFormats("SMI", "MOL")) // Number of atoms and bonds { // Option "h" adds explicit hydrogens (unsigned (unsigned int) mol.NumAtoms(); // All atoms int) mol.NumHvyAtoms(); // Non-H atoms Bonds
 conv.AddOption("h", OBConversion::GENOPTIONS); (unsigned int) mol.NumBonds(); // All bonds conv.Convert(); #include <openbabel/bond.h> } // Molecular weight with implicit hydrogens #include <openbabel/atom.h> (double) mol.GetMolWt(true);

  • 2. OBBond bond; // Set calculation parameters spec.SetResolution(3.0); Energy
 // Properties spec.SetAccuracy(AngStepSize20); (unsigned int) bond.GetBondOrder(); spec.SetStereo(NoStereoSpecificProbes); #include <openbabel/forcefield.h> (bool) bond.IsPrimaryAmide(); // and 2 and 3... spec.SetNormalization(NormalizationTowardsZeroMean); #include <openbabel/mol.h> (bool) bond.IsSingle(); // and 2 and 3... (bool) bond.IsRotor(); // Calculate and print OBMol mol; std::vector<double> sphore; /* ... */ // Flanking atoms sphore = spec.GetSpectrophore(&mol); (OBAtom*) bond.GetBeginAtom(); for (int i(0); i < sphore.size(); ++i) // Select the MMFF94 forcefield (OBAtom*) bond.GetEndAtom(); { OBForceField* pFF; OBAtom* atom; (OBAtom*) bond.GetNbrAtom(atom); std::cout << sphore[i] << "t"; pFF = OBForceField::FindForceField("MMFF94"); } if (!pFF) exit(1); // Is bond in ring? std::cout << std::endl; (bool) bond.IsInRing(); // Set the logfile pFF->SetLogFile(&std::cerr); Stereochemistry
 // Assign atom types, parameters, ... Substructure
 pFF->Setup(mol); #include <openbabel/mol.h> // Calculate the energy #include <openbabel/parsmart.h> #include <openbabel/obconversion.h> pFF->Energy(); #include <openbabel/mol.h> #include <openbabel/stereo/tetrahedral.h> #include <openbabel/atom.h> // Perform maximum 1000 steps of minimization OBMol mol; pFF->ConjugateGradients(1000); OBMol mol; OBConversion conv; OBAtom* atom; conv.SetInFormat("smi"); /* ... */ conv.ReadString(&mol, "C[C@H](Cl)Br"); // Create a SMARTS pattern of a phenyl ring // Stereofacade object OBSmartsPattern sp; OBStereoFacade facade(&mol); Open
 sp.Init("c1ccccc1"); (unsigned int) facade.NumTetrahedralStereo(); (unsigned int) facade.NumCisTransStereo(); This documentation is part of the Open Babel project. For more information, // Properties of the substructure (unsigned int) facade.SquarePlanarStereo(); see Open Babel is free software; you can redistribute if (sp.IsValid()) it and/or modify it under the terms of the GNU General Public License as { // Loop over all atoms to check if stereocenter published by the Free Software Foundation version 2 of the License. Open std::cout << sp.NumAtoms(); FOR_ATOMS_OF_MOL(atom, mol) Babel is distributed in the hope that it will be useful, but without any std::cout << sp.NumBonds(); { std::cout << sp.GetSmarts(); std::cout << atom->GetId() << ": "; warranty; without even the implied warranty of merchantability or fitness for } if (facade.HasTetrahedralStereo(atom->GetId())) a particular purpose. See the GNU General Public License for more details. std::cout << ": stereo"; // Matching else (bool) sp.Match(mol, true); // Single matching std::cout << ": no stereo"; Spectrophore™ (bool) sp.Match(mol, false); // Complete matching std::cout << std::endl; } Spectrophore™ is a trademark of Silicos NV and the technology is part of // Substructure mapping the Open Babel project. std::vector<std::vector<int> > mapListA; mapListA = sp.GetMapList(); // Non-unique matches std::vector<std::vector<int> > mapListU; Rings
 mapListU = sp.GetUMapList(); // Unique matches for (int m(0); m < mapListU.size(); ++m) Silicos is a fee-for-service company empowering open source chemo- { #include <openbabel/mol.h> informatics virtual screening technologies for the discovery of novel lead std::cout << "Unique match " << m << std::endl; #include <openbabel/ring.h> compounds and database characterization. Silicos fully endorses the for (int a(0); a < mapListU[m].size(); ++a) #include <openbabel/math/vector3.h> concept of open innovation and open source software development, and { provides its clients with a wide variety of computational chemistry-based atom = mol.GetAtom(mapListU[m][a]); OBMol mol; lead discovery services, including Open Babel support, training and code std::cout << atom->GetAtomicNum() << std::endl; /* ... */ } development. Please visit for more details. } // Get the smallest-set-of-smallest-rings std::vector<OBRing*> rings = mol.GetSSSR(); vector3 center; vector3 normal_up; Spectrophores™
 vector3 normal_down; for (int i(0); i < rings.size(); ++i) Copyright © 2010 Silicos NV { Silicos NV #include <openbabel/obspectrophore.h> (bool) rings[i].IsAromatic(); #include <openbabel/mol.h> (int) rings[i].Size(); Wetenschapspark 7, (bool) rings[i].findCenterAndNormal(center, B-3590 Diepenbeek OBMol mol; normal_up, Belgium /* ... */ normal_down); } // Create a Spectrophore object OBSpectrophore spec;