-
Notifications
You must be signed in to change notification settings - Fork 5
/
obgen.cpp
189 lines (144 loc) · 4.81 KB
/
obgen.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*
* This file is part of esynth.
*
* esynth is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* esynth is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with esynth. If not, see <http://www.gnu.org/licenses/>.
*/
/**********************************************************************
Adopted this source code from obgen to use NOT as a stand-alone,
but as source code directly linked to the synthetic chemsitry project.
C. Alvin 6-20-2014
***********************************************************************/
/**********************************************************************
obgen.cpp - test program for SMILES 3D coordinate generation
- using systematic rotor search
Copyright (C) 2006 Tim Vandermeersch
Some portions Copyright (C) 2006 Geoffrey R. Hutchison
This file is part of the Open Babel project.
For more information, see <http://openbabel.org/>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation version 2 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
#include <sstream>
#include <iostream>
#include <openbabel/babelconfig.h>
#include <openbabel/base.h>
#include <openbabel/mol.h>
#include <openbabel/obconversion.h>
#include <openbabel/forcefield.h>
#include <openbabel/builder.h>
#include "obgen.h"
//
// A lightweight set of classes that ensures all information thrown to the streami
// is never buffered, nor retained.
//
class NullBuffer : public std::streambuf
{
public:
int overflow(int c) { return c; }
};
class NullStream : public std::ostream
{
public:
NullStream() : std::ostream(&m_sb) {}
private:
NullBuffer m_sb;
};
//
// Original OBGEN: Generate rough 3D coordinates for SMILES (or other 0D files).
//
/*
void OBGen::obgen(std::string& smiMol)
{
OpenBabel::OBConversion conv;
conv.SetInFormat("SMI");
OpenBabel::OBMol smiOBMol;
conv.ReadString(&smiOBMol, smiMol);
return obgen(smiOBMol);
}
*/
//
// Modified OBGEN: Minimizes SteepestDescent and WeightedRotorSearch steps.
//
bool OBGen::fast_obgen(OpenBabel::OBMol* mol)
{
std::string ff = "MMFF94";
OpenBabel::OBForceField* pFF = OpenBabel::OBForceField::FindForceField(ff);
if (!pFF)
{
std::cerr << "obgen: could not find forcefield '" << ff << "'." << std::endl;
return false;
}
NullStream null_stream;
pFF->SetLogFile(&null_stream);
pFF->SetLogLevel(OBFF_LOGLVL_LOW);
OpenBabel::OBBuilder builder;
builder.Build(*mol);
// hydrogens must be added before Setup(mol) is called
mol->AddHydrogens(false, true);
if (!pFF->Setup(*mol))
{
std::cerr << "obgen: could not setup force field." << std::endl;
return false;
}
pFF->SteepestDescent(1, 1.0e-4);
pFF->WeightedRotorSearch(250, 1);
pFF->SteepestDescent(1, 1.0e-6);
pFF->UpdateCoordinates(*mol);
return true;
}
//
// Original OBGEN: Generate rough 3D coordinates for SMILES (or other 0D files).
//
bool OBGen::obgen(OpenBabel::OBMol* mol)
{
std::string ff = "MMFF94";
OpenBabel::OBForceField* pFF = OpenBabel::OBForceField::FindForceField(ff);
if (!pFF)
{
std::cerr << "obgen: could not find forcefield '" << ff << "'." << std::endl;
return false;
}
NullStream null_stream;
pFF->SetLogFile(&null_stream);
pFF->SetLogLevel(OBFF_LOGLVL_LOW);
OpenBabel::OBBuilder builder;
builder.Build(*mol);
// hydrogens must be added before Setup(mol) is called
mol->AddHydrogens(false, true);
if (!pFF->Setup(*mol))
{
std::cerr << "obgen: could not setup force field." << std::endl;
return false;
}
pFF->SteepestDescent(500, 1.0e-4);
pFF->WeightedRotorSearch(250, 50);
pFF->SteepestDescent(500, 1.0e-6);
pFF->UpdateCoordinates(*mol);
return true;
//
// Write the molecule to a string in SDF format.
//
/*
OpenBabel::OBConversion conv;
conv.SetOutFormat("SDF");
std::ostringstream oss;
conv.Write(&mol, &oss);
return oss.str();
*/
}