-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmolecule-ob.cpp
43 lines (31 loc) · 1005 Bytes
/
molecule-ob.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//
// All OpenBabel-dependent functionality is in this module. It's all molecule-related.
//
#include "molecule.h"
#include <openbabel/mol.h>
#include <openbabel/atom.h>
#include <openbabel/obconversion.h>
#include <openbabel/op.h>
using namespace OpenBabel;
Molecule* Molecule::createFromSMILES(const std::string &smiles, const std::string &opt) {
// convertor
OBConversion obConv;
obConv.SetInFormat("smi");
// molecule
OBMol obMol;
// read smiles
obConv.ReadString(&obMol, smiles);
// gen3D plugin
OBOp* pgen = OBOp::FindType("gen3D");
pgen->Do(&obMol, opt.c_str());
// our molecule
auto m = new Molecule("from smiles via babel");
// read molecule into out Molecule class
for (auto ita = obMol.BeginAtoms(); ita != obMol.EndAtoms(); ++ita) {
OBAtom *a = *ita;
m->add(Atom(Element(a->GetAtomicNum()), Vec3(a->GetX(), a->GetY(), a->GetZ())));
}
// rebuild bonds and return
m->detectBonds(); // TODO read bonds from OpenBabel structures
return m;
}