// Automatic format perception // Molecular formula std::ifstream ifs(filename); (std::string) mol.GetFormula(); Open Babel 2.3 OBConversion conv; OBFormat* inFormat = conv.FormatFromExt(filename); // Conformations ++ API OBFormat* outFormat = conv.SetFormat("SDF"); (int) mol.NumConformers(); if (inFormat && outFormat) Quick reference guide { // Smallest set of smallest rings conv.SetInAndOutFormats(inFormat, outFormat); (std::vector) mol.GetSSSR(); } // Hydrogen manipulations (bool) mol.DeleteHydrogens(); // All H (bool) mol.AddPolarHydrogens(); // Polar H (bool) mol.AddHydrogens(); // All H Namespace Looping over atoms and bonds // Generic data using namespace OpenBabel; #include std::vector::iterator k; #include std::vector vdata = mol.GetData(); for (k = vdata.begin(); k != vdata.end(); ++k) using namespace OpenBabel; if ((*k)->GetDataType() == OBGenericDataType::PairData) { Reading and writing OBMol mol; std::cout << "> <" << (*k)->GetAttribute(); OBAtom* atom; std::cout << ">" << std::endl; #include OBAtom* nbrAtom; std::cout << ((OBPairData*)(*k))->GetValue(); #include 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 FOR_BONDS_OF_MOL(bond, mol) if (conv.SetInAndOutFormats("sdf", "can")) { Atoms { totalBondOrder += bond->GetBondOrder(); if (conv.Read(&mol)) } #include { // 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(); (double) atom.GetAtomicMass(); } Element table return 0; // Explicit and maximum expected connections } #include (unsigned int) atom.GetValence(); (unsigned int) atom.GetImplicitValence(); OBElementTable etab; // Non-hydrogen connections (char*) etab.GetSymbol(6); (unsigned int) atom.GetHvyValence(); Conversion (int) etab.GetAtomicNum("C"); (double) etab.GetVdwRad(7); // Implicit and explicit hydrogens #include (double) etab.GetCovalentRad(8); (unsigned int) atom.ImplicitHydrogenCount(); #include (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 { /* ... */ } #include // 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 { (unsigned int) mol.NumAtoms(); // All atoms // Option "h" adds explicit hydrogens (unsigned int) mol.NumHvyAtoms(); // Non-H atoms Bonds conv.AddOption("h", OBConversion::GENOPTIONS); (unsigned int) mol.NumBonds(); // All bonds conv.Convert(); #include } // Molecular weight with implicit hydrogens #include (double) mol.GetMolWt(true);

www.silicos.com www.silicos.com www.silicos.com OBBond bond; // Set calculation parameters spec.SetResolution(3.0); Energy calculations // Properties spec.SetAccuracy(AngStepSize20); (unsigned int) bond.GetBondOrder(); spec.SetStereo(NoStereoSpecificProbes); #include (bool) bond.IsPrimaryAmide(); // and 2 and 3... spec.SetNormalization(NormalizationTowardsZeroMean); #include (bool) bond.IsSingle(); // and 2 and 3... (bool) bond.IsRotor(); // Calculate and print OBMol mol; std::vector 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 search pFF->Setup(mol);

#include // Calculate the energy #include #include pFF->Energy(); #include #include #include // 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 Babel 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 www.openbabel.org. Open Babel is free ; 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 > mapListA; mapListA = sp.GetMapList(); // Non-unique matches std::vector > mapListU; Silicos NV mapListU = sp.GetUMapList(); // Unique matches Rings for (int m(0); m < mapListU.size(); ++m) Silicos is a fee-for-service company empowering open source chemo- { #include informatics virtual screening technologies for the discovery of novel lead std::cout << "Unique match " << m << std::endl; #include compounds and database characterization. Silicos fully endorses the for (int a(0); a < mapListU[m].size(); ++a) #include concept of open innovation and open source software development, and { provides its clients with a wide variety of -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 www.silicos.com for more details. } // Get the smallest-set-of-smallest-rings std::vector rings = mol.GetSSSR(); vector3 center; vector3 normal_up; Spectrophores™ vector3 normal_down; Copyright © 2010 Silicos NV for (int i(0); i < rings.size(); ++i) { Silicos NV #include (bool) rings[i].IsAromatic(); #include (int) rings[i].Size(); Wetenschapspark 7, (bool) rings[i].findCenterAndNormal(center, B-3590 Diepenbeek OBMol mol; normal_up, Belgium /* ... */ normal_down); } www.silicos.com // Create a Spectrophore object www.openbabel.org OBSpectrophore spec;

www.silicos.com www.silicos.com