Last active
July 13, 2018 12:52
-
-
Save n-yoshikawa/55b99f5ca2c44c65857e55bd479f4352 to your computer and use it in GitHub Desktop.
Builder test codes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sstream> | |
#include <openbabel/mol.h> | |
#include <openbabel/obconversion.h> | |
#include <openbabel/builder.h> | |
#include <openbabel/math/align.h> | |
using namespace std; | |
using namespace OpenBabel; | |
int main(int argc, char **argv) { | |
if (argc != 3) { | |
cerr << "Usage: " << argv[0] << "<target> <reference>" << endl; | |
exit(EXIT_FAILURE); | |
} | |
OBMol mol1, mol2; | |
OBConversion conv; | |
ifstream ifs1, ifs2; | |
string s, s1, s2; | |
stringstream ss; | |
for(int i = 1; i <= 2; ++i) { | |
OBFormat *inFormat = conv.FormatFromExt(argv[i]); | |
if(inFormat==NULL || !conv.SetInFormat(inFormat)) { | |
cerr << " Cannot read file format for " << argv[i] << endl; | |
exit(EXIT_FAILURE); | |
} | |
} | |
ifs1.open(argv[1]); | |
ifs2.open(argv[2]); | |
conv.SetOutFormat("can"); | |
if (!ifs1 || !ifs2 ) { | |
cerr << "Cannot read input file" << endl; | |
exit(EXIT_FAILURE); | |
} | |
while(ifs1.peek() != EOF && ifs1.good() && ifs2.peek() != EOF && ifs2.good()) { | |
conv.Read(&mol1, &ifs1); | |
conv.Read(&mol2, &ifs2); | |
s1 = conv.WriteString(&mol1, true); | |
s2 = conv.WriteString(&mol2, true); | |
ss.str(s1); | |
ss >> s; | |
OBAlign aln(mol1, mol2); | |
aln.Align(); | |
cout << s << "," << aln.GetRMSD() << endl; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <openbabel/mol.h> | |
#include <openbabel/obconversion.h> | |
#include <openbabel/builder.h> | |
using namespace std; | |
using namespace OpenBabel; | |
int main(int argc, char **argv) { | |
OBMol mol; | |
OBBuilder builder; | |
ifstream ifs; | |
OBConversion conv; | |
conv.SetOutFormat("SDF"); | |
for (int i=1; i < argc; i++) { | |
OBFormat *inFormat = conv.FormatFromExt(argv[i]); | |
if(inFormat==NULL || !conv.SetInFormat(inFormat)) | |
{ | |
cerr << " Cannot read file format for " << argv[i] << endl; | |
continue; // try next file | |
} | |
ifs.open(argv[i]); | |
if (!ifs) { | |
cerr << "Cannot read input file: " << argv[i] << endl; | |
continue; | |
} | |
while(ifs.peek() != EOF && ifs.good()) { | |
conv.Read(&mol, &ifs); | |
builder.Build(mol); | |
mol.AddHydrogens(); | |
conv.Write(&mol, &cout); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment