Loading...
Searching...
No Matches
obconformersearch_default.cpp
#include <openbabel/obconversion.h>
#include <openbabel/mol.h>
#include <openbabel/shared_ptr.h>
#include <openbabel/conformersearch.h>
#include <iostream>
using namespace OpenBabel;
// Helper function to read molecule from file
shared_ptr<OBMol> GetMol(const std::string &filename)
{
// Create the OBMol object.
shared_ptr<OBMol> mol(new OBMol);
// Create the OBConversion object.
OBConversion conv;
OBFormat *format = conv.FormatFromExt(filename.c_str());
if (!format || !conv.SetInFormat(format)) {
std::cout << "Could not find input format for file " << filename << std::endl;
return mol;
}
// Open the file.
std::ifstream ifs(filename.c_str());
if (!ifs) {
std::cout << "Could not open " << filename << " for reading." << std::endl;
return mol;
}
// Read the molecule.
if (!conv.Read(mol.get(), &ifs)) {
std::cout << "Could not read molecule from file " << filename << std::endl;
return mol;
}
return mol;
}
int main(int argc, char **argv)
{
if (argc < 2) {
std::cout << "Usage: " << argv[0] << " <filename>" << std::endl;
return 1;
}
// Read the file
shared_ptr<OBMol> mol = GetMol(argv[1]);
// Create the OBConformerSearch object
OBConformerSearch cs;
// Setup
std::cout << "Setting up conformer searching..." << std::endl
<< " conformers: 30" << std::endl
<< " children: 5" << std::endl
<< " mutability: 5" << std::endl
<< " convergence: 25" << std::endl;
cs.Setup(*mol.get(),
30, // numConformers
5, // numChildren
5, // mutability
25); // convergence
// Perform searching
cs.Search();
// Print the rotor keys
RotorKeys keys = cs.GetRotorKeys();
for (RotorKeys::iterator key = keys.begin(); key != keys.end(); ++key) {
for (unsigned int i = 1; i < key->size(); ++i)
std::cout << key->at(i) << " ";
std::cout << std::endl;
}
// Get the conformers
cs.GetConformers(*mol.get());
std::cout << mol->NumConformers() << std::endl;
OBConversion conv;
conv.SetOutFormat("sdf");
for (unsigned int c = 0; c < mol->NumConformers(); ++c) {
mol->SetConformer(c);
conv.Write(mol.get(), &std::cerr);
}
}
OpenBabel::OBConformerSearch
Conformer searching using genetic algorithm. See ConformerSearching.
Definition conformersearch.h:269
OpenBabel::OBConformerSearch::Setup
bool Setup(const OBMol &mol, int numConformers=30, int numChildren=5, int mutability=5, int convergence=25)
Definition conformersearch.cpp:332
OpenBabel::OBConformerSearch::GetConformers
void GetConformers(OBMol &mol)
Definition conformersearch.cpp:695
OpenBabel::OBConformerSearch::GetRotorKeys
const RotorKeys & GetRotorKeys() const
Definition conformersearch.h:349
OpenBabel::OBConformerSearch::Search
void Search()
Definition conformersearch.cpp:587
OpenBabel::OBConversion
Class to convert from one format to another.
Definition obconversion.h:60
OpenBabel::OBConversion::Read
bool Read(OBBase *pOb, std::istream *pin=nullptr)
Reads an object of a class derived from OBBase into pOb.
Definition obconversion.cpp:830
OpenBabel::OBConversion::FormatFromExt
static OBFormat * FormatFromExt(const char *filename)
Searches registered formats for an ID the same as the file extension.
Definition obconversion.cpp:808
OpenBabel::OBConversion::SetOutFormat
bool SetOutFormat(const char *outID, bool isgzip=false)
Sets the output format from an id e.g. CML.
Definition obconversion.cpp:449
OpenBabel::OBConversion::Write
bool Write(OBBase *pOb, std::ostream *pout=nullptr)
Outputs an object of a class derived from OBBase.
Definition obconversion.cpp:896
OpenBabel::OBConversion::SetInFormat
bool SetInFormat(const char *inID, bool isgzip=false)
Sets the input format from an id e.g. CML.
Definition obconversion.cpp:440
OpenBabel::OBFormat
Base class for file formats.
Definition format.h:45
OpenBabel::OBMol
Molecule Class.
Definition mol.h:121
conformersearch.h
Conformer searching using genetic algorithm.
mol.h
Handle molecules. Declarations of OBMol, OBAtom, OBBond, OBResidue. (the main header for Open Babel).
OpenBabel
Global namespace for all Open Babel code.
Definition alias.h:23
OpenBabel::RotorKeys
std::vector< RotorKey > RotorKeys
Definition conformersearch.h:31
obconversion.h
Handle file conversions. Declaration of OBFormat, OBConversion.
shared_ptr.h
Shared pointer.