mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-03 21:44:30 +08:00
first pass, using google style
This commit is contained in:
@@ -30,22 +30,24 @@
|
||||
#include <string>
|
||||
|
||||
using namespace RDKit;
|
||||
namespace io=boost::iostreams;
|
||||
namespace io = boost::iostreams;
|
||||
|
||||
void test1(){
|
||||
void test1() {
|
||||
#ifdef SUPPORT_COMPRESSED_IO
|
||||
BOOST_LOG(rdInfoLog) << "testing basic reading from compressed streams" << std::endl;
|
||||
BOOST_LOG(rdInfoLog) << "testing basic reading from compressed streams"
|
||||
<< std::endl;
|
||||
|
||||
std::string rdbase = getenv("RDBASE");
|
||||
std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/triazine.mol.gz";
|
||||
std::string fname2 =
|
||||
rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/triazine.mol.gz";
|
||||
RWMol *m;
|
||||
|
||||
|
||||
io::filtering_istream inStrm;
|
||||
inStrm.push(io::gzip_decompressor());
|
||||
inStrm.push(io::file_source(fname2));
|
||||
TEST_ASSERT(inStrm.is_complete());
|
||||
unsigned int lineNo=0;
|
||||
m = MolDataStreamToMol(inStrm,lineNo);
|
||||
unsigned int lineNo = 0;
|
||||
m = MolDataStreamToMol(inStrm, lineNo);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
|
||||
@@ -55,17 +57,19 @@ void test1(){
|
||||
#endif
|
||||
}
|
||||
|
||||
void test2(){
|
||||
void test2() {
|
||||
#ifdef SUPPORT_COMPRESSED_IO
|
||||
BOOST_LOG(rdInfoLog) << "testing writing to, then reading from compressed streams" << std::endl;
|
||||
BOOST_LOG(rdInfoLog)
|
||||
<< "testing writing to, then reading from compressed streams"
|
||||
<< std::endl;
|
||||
|
||||
std::string smiles="C1CCCC1";
|
||||
std::string buff,molBlock;
|
||||
std::string smiles = "C1CCCC1";
|
||||
std::string buff, molBlock;
|
||||
RWMol *m;
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
m->setProp(common_properties::_Name,"monkey");
|
||||
m->setProp(common_properties::_Name, "monkey");
|
||||
io::filtering_ostream outStrm;
|
||||
outStrm.push(io::gzip_compressor());
|
||||
outStrm.push(io::back_inserter(buff));
|
||||
@@ -74,15 +78,15 @@ void test2(){
|
||||
molBlock = MolToMolBlock(*m);
|
||||
outStrm << molBlock;
|
||||
outStrm.reset();
|
||||
|
||||
|
||||
delete m;
|
||||
io::filtering_istream inStrm;
|
||||
inStrm.push(io::gzip_decompressor());
|
||||
inStrm.push(boost::make_iterator_range(buff));
|
||||
TEST_ASSERT(inStrm.is_complete());
|
||||
|
||||
unsigned int lineNo=0;
|
||||
m = MolDataStreamToMol(inStrm,lineNo);
|
||||
unsigned int lineNo = 0;
|
||||
m = MolDataStreamToMol(inStrm, lineNo);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
|
||||
@@ -92,112 +96,115 @@ void test2(){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void test3(){
|
||||
void test3() {
|
||||
#ifdef SUPPORT_COMPRESSED_IO
|
||||
BOOST_LOG(rdInfoLog) << "testing writing pickles to a file then reading them back" << std::endl;
|
||||
BOOST_LOG(rdInfoLog)
|
||||
<< "testing writing pickles to a file then reading them back"
|
||||
<< std::endl;
|
||||
std::string rdbase = getenv("RDBASE");
|
||||
std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/mols.rdb";
|
||||
|
||||
std::string smiles,buff;
|
||||
std::string smiles, buff;
|
||||
RWMol *m;
|
||||
|
||||
std::vector<unsigned int> filePs;
|
||||
io::filtering_ostream outStrm;
|
||||
outStrm.push(io::file_sink(fname2,std::ios_base::out|std::ios_base::binary));
|
||||
outStrm.push(
|
||||
io::file_sink(fname2, std::ios_base::out | std::ios_base::binary));
|
||||
TEST_ASSERT(outStrm.is_complete());
|
||||
|
||||
smiles="C1CCC1";
|
||||
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="C1CCC1";
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(0);
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="C1CCCC1";
|
||||
|
||||
smiles = "C1CCCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="c1ccccc1";
|
||||
|
||||
smiles = "c1ccccc1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="c1ccccc1CC(=O)O";
|
||||
|
||||
smiles = "c1ccccc1CC(=O)O";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
outStrm.flush();
|
||||
outStrm.reset();
|
||||
|
||||
|
||||
io::filtering_istream inStrm;
|
||||
inStrm.push(io::file_source(fname2,std::ios_base::in|std::ios_base::binary));
|
||||
inStrm.push(
|
||||
io::file_source(fname2, std::ios_base::in | std::ios_base::binary));
|
||||
TEST_ASSERT(inStrm.is_complete());
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
delete m;
|
||||
|
||||
|
||||
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
||||
#else
|
||||
BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void test4(){
|
||||
void test4() {
|
||||
#ifdef SUPPORT_COMPRESSED_IO
|
||||
BOOST_LOG(rdInfoLog) << "testing writing pickles to a single compressed file then reading them back" << std::endl;
|
||||
BOOST_LOG(rdInfoLog) << "testing writing pickles to a single compressed file "
|
||||
"then reading them back" << std::endl;
|
||||
std::string rdbase = getenv("RDBASE");
|
||||
std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/mols.rdz";
|
||||
|
||||
@@ -206,197 +213,196 @@ void test4(){
|
||||
|
||||
io::filtering_ostream outStrm;
|
||||
outStrm.push(io::gzip_compressor());
|
||||
outStrm.push(io::file_sink(fname2,std::ios_base::out|std::ios_base::binary));
|
||||
outStrm.push(
|
||||
io::file_sink(fname2, std::ios_base::out | std::ios_base::binary));
|
||||
TEST_ASSERT(outStrm.is_complete());
|
||||
|
||||
smiles="C1CCC1";
|
||||
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="C1CCC1";
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="C1CCCC1";
|
||||
|
||||
smiles = "C1CCCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="c1ccccc1";
|
||||
|
||||
smiles = "c1ccccc1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
smiles="c1ccccc1CC(=O)O";
|
||||
|
||||
smiles = "c1ccccc1CC(=O)O";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
MolPickler::pickleMol(*m,outStrm);
|
||||
MolPickler::pickleMol(*m, outStrm);
|
||||
delete m;
|
||||
|
||||
io::flush(outStrm);
|
||||
outStrm.pop();
|
||||
|
||||
|
||||
io::filtering_istream inStrm;
|
||||
inStrm.push(io::gzip_decompressor());
|
||||
inStrm.push(io::file_source(fname2,std::ios_base::in|std::ios_base::binary));
|
||||
inStrm.push(
|
||||
io::file_source(fname2, std::ios_base::in | std::ios_base::binary));
|
||||
TEST_ASSERT(inStrm.is_complete());
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
delete m;
|
||||
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(inStrm,*m);
|
||||
MolPickler::molFromPickle(inStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
delete m;
|
||||
|
||||
|
||||
BOOST_LOG(rdInfoLog) << "done" << std::endl;
|
||||
#else
|
||||
BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
|
||||
#endif
|
||||
}
|
||||
|
||||
void test5(){
|
||||
void test5() {
|
||||
#ifdef SUPPORT_COMPRESSED_IO
|
||||
BOOST_LOG(rdInfoLog) << "testing writing compressed pickles to a single file then reading them back" << std::endl;
|
||||
BOOST_LOG(rdInfoLog) << "testing writing compressed pickles to a single file "
|
||||
"then reading them back" << std::endl;
|
||||
std::string rdbase = getenv("RDBASE");
|
||||
std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/tmp.rdz";
|
||||
|
||||
std::string smiles,buff;
|
||||
std::string smiles, buff;
|
||||
RWMol *m;
|
||||
std::vector<unsigned int> filePs;
|
||||
|
||||
io::filtering_ostream outStrm;
|
||||
outStrm.push(io::file_sink(fname2,std::ios_base::out|std::ios_base::binary));
|
||||
outStrm.push(
|
||||
io::file_sink(fname2, std::ios_base::out | std::ios_base::binary));
|
||||
TEST_ASSERT(outStrm.is_complete());
|
||||
|
||||
smiles="C1CCC1";
|
||||
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
|
||||
|
||||
io::filtering_ostream *tmpStrm;
|
||||
tmpStrm=new io::filtering_ostream();
|
||||
tmpStrm = new io::filtering_ostream();
|
||||
tmpStrm->push(io::gzip_compressor());
|
||||
tmpStrm->push(io::back_inserter(buff));
|
||||
|
||||
|
||||
|
||||
filePs.push_back(0);
|
||||
MolPickler::pickleMol(*m,*tmpStrm);
|
||||
MolPickler::pickleMol(*m, *tmpStrm);
|
||||
delete m;
|
||||
tmpStrm->reset();
|
||||
|
||||
outStrm<<buff.size();
|
||||
outStrm<<buff;
|
||||
std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
|
||||
buff="";
|
||||
outStrm << buff.size();
|
||||
outStrm << buff;
|
||||
std::cerr << "sz: " << buff.size() << " " << outStrm.tellp() << std::endl;
|
||||
buff = "";
|
||||
tmpStrm->push(io::gzip_compressor());
|
||||
tmpStrm->push(io::back_inserter(buff));
|
||||
|
||||
smiles="C1CCC1";
|
||||
|
||||
smiles = "C1CCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,*tmpStrm);
|
||||
MolPickler::pickleMol(*m, *tmpStrm);
|
||||
delete m;
|
||||
tmpStrm->reset();
|
||||
outStrm<<buff.size();
|
||||
outStrm<<buff;
|
||||
std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
|
||||
buff="";
|
||||
outStrm << buff.size();
|
||||
outStrm << buff;
|
||||
std::cerr << "sz: " << buff.size() << " " << outStrm.tellp() << std::endl;
|
||||
buff = "";
|
||||
tmpStrm->push(io::gzip_compressor());
|
||||
tmpStrm->push(io::back_inserter(buff));
|
||||
|
||||
smiles="C1CCCC1";
|
||||
smiles = "C1CCCC1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,*tmpStrm);
|
||||
MolPickler::pickleMol(*m, *tmpStrm);
|
||||
delete m;
|
||||
tmpStrm->reset();
|
||||
outStrm<<buff.size();
|
||||
outStrm<<buff;
|
||||
std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
|
||||
buff="";
|
||||
outStrm << buff.size();
|
||||
outStrm << buff;
|
||||
std::cerr << "sz: " << buff.size() << " " << outStrm.tellp() << std::endl;
|
||||
buff = "";
|
||||
tmpStrm->push(io::gzip_compressor());
|
||||
tmpStrm->push(io::back_inserter(buff));
|
||||
|
||||
|
||||
smiles="c1ccccc1";
|
||||
smiles = "c1ccccc1";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,*tmpStrm);
|
||||
MolPickler::pickleMol(*m, *tmpStrm);
|
||||
delete m;
|
||||
tmpStrm->reset();
|
||||
outStrm<<buff.size();
|
||||
outStrm<<buff;
|
||||
std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
|
||||
buff="";
|
||||
outStrm << buff.size();
|
||||
outStrm << buff;
|
||||
std::cerr << "sz: " << buff.size() << " " << outStrm.tellp() << std::endl;
|
||||
buff = "";
|
||||
tmpStrm->push(io::gzip_compressor());
|
||||
tmpStrm->push(io::back_inserter(buff));
|
||||
|
||||
smiles="c1ccccc1CC(=O)O";
|
||||
|
||||
smiles = "c1ccccc1CC(=O)O";
|
||||
m = SmilesToMol(smiles);
|
||||
TEST_ASSERT(m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
RDDepict::compute2DCoords(*m);
|
||||
filePs.push_back(outStrm.tellp());
|
||||
MolPickler::pickleMol(*m,*tmpStrm);
|
||||
MolPickler::pickleMol(*m, *tmpStrm);
|
||||
delete m;
|
||||
tmpStrm->reset();
|
||||
outStrm<<buff.size();
|
||||
outStrm<<buff;
|
||||
std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
|
||||
outStrm << buff.size();
|
||||
outStrm << buff;
|
||||
std::cerr << "sz: " << buff.size() << " " << outStrm.tellp() << std::endl;
|
||||
|
||||
delete tmpStrm;
|
||||
io::flush(outStrm);
|
||||
@@ -406,80 +412,81 @@ void test5(){
|
||||
io::filtering_istream inStrm;
|
||||
unsigned int sz;
|
||||
char *charArr;
|
||||
|
||||
inStrm.push(io::file_source(fname2,std::ios_base::in|std::ios_base::binary));
|
||||
|
||||
inStrm.push(
|
||||
io::file_source(fname2, std::ios_base::in | std::ios_base::binary));
|
||||
TEST_ASSERT(inStrm.is_complete());
|
||||
|
||||
inStrm>>sz;
|
||||
inStrm >> sz;
|
||||
charArr = new char[sz];
|
||||
inStrm.read(charArr,sz);
|
||||
inStrm.read(charArr, sz);
|
||||
buff = "";
|
||||
buff.append(charArr,sz);
|
||||
buff.append(charArr, sz);
|
||||
tmpIStrm.push(io::gzip_decompressor());
|
||||
tmpIStrm.push(boost::make_iterator_range(buff));
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(tmpIStrm,*m);
|
||||
MolPickler::molFromPickle(tmpIStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
inStrm>>sz;
|
||||
delete [] charArr;
|
||||
inStrm >> sz;
|
||||
delete[] charArr;
|
||||
charArr = new char[sz];
|
||||
inStrm.read(charArr,sz);
|
||||
inStrm.read(charArr, sz);
|
||||
buff = "";
|
||||
buff.append(charArr,sz);
|
||||
buff.append(charArr, sz);
|
||||
tmpIStrm.reset();
|
||||
tmpIStrm.push(io::gzip_decompressor());
|
||||
tmpIStrm.push(boost::make_iterator_range(buff));
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(tmpIStrm,*m);
|
||||
MolPickler::molFromPickle(tmpIStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(4));
|
||||
delete m;
|
||||
|
||||
inStrm>>sz;
|
||||
delete [] charArr;
|
||||
inStrm >> sz;
|
||||
delete[] charArr;
|
||||
charArr = new char[sz];
|
||||
inStrm.read(charArr,sz);
|
||||
inStrm.read(charArr, sz);
|
||||
buff = "";
|
||||
buff.append(charArr,sz);
|
||||
buff.append(charArr, sz);
|
||||
tmpIStrm.reset();
|
||||
tmpIStrm.push(io::gzip_decompressor());
|
||||
tmpIStrm.push(boost::make_iterator_range(buff));
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(tmpIStrm,*m);
|
||||
MolPickler::molFromPickle(tmpIStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(5));
|
||||
delete m;
|
||||
|
||||
inStrm>>sz;
|
||||
delete [] charArr;
|
||||
inStrm >> sz;
|
||||
delete[] charArr;
|
||||
charArr = new char[sz];
|
||||
inStrm.read(charArr,sz);
|
||||
inStrm.read(charArr, sz);
|
||||
buff = "";
|
||||
buff.append(charArr,sz);
|
||||
buff.append(charArr, sz);
|
||||
tmpIStrm.reset();
|
||||
tmpIStrm.push(io::gzip_decompressor());
|
||||
tmpIStrm.push(boost::make_iterator_range(buff));
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(tmpIStrm,*m);
|
||||
MolPickler::molFromPickle(tmpIStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(6));
|
||||
delete m;
|
||||
|
||||
inStrm>>sz;
|
||||
delete [] charArr;
|
||||
inStrm >> sz;
|
||||
delete[] charArr;
|
||||
charArr = new char[sz];
|
||||
inStrm.read(charArr,sz);
|
||||
inStrm.read(charArr, sz);
|
||||
buff = "";
|
||||
buff.append(charArr,sz);
|
||||
buff.append(charArr, sz);
|
||||
tmpIStrm.reset();
|
||||
tmpIStrm.push(io::gzip_decompressor());
|
||||
tmpIStrm.push(boost::make_iterator_range(buff));
|
||||
m = new RWMol();
|
||||
TEST_ASSERT(m);
|
||||
MolPickler::molFromPickle(tmpIStrm,*m);
|
||||
MolPickler::molFromPickle(tmpIStrm, *m);
|
||||
TEST_ASSERT(m->getNumAtoms(9));
|
||||
delete m;
|
||||
|
||||
@@ -489,8 +496,7 @@ void test5(){
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,char *argv[]){
|
||||
int main(int argc, char *argv[]) {
|
||||
RDLog::InitLogs();
|
||||
#if 1
|
||||
test1();
|
||||
|
||||
@@ -17,25 +17,24 @@
|
||||
|
||||
using namespace RDKit;
|
||||
|
||||
|
||||
void runMol(ROMol *mol,int checkEvery=10,bool verbose=true){
|
||||
void runMol(ROMol *mol, int checkEvery = 10, bool verbose = true) {
|
||||
ForceFields::ForceField *field;
|
||||
|
||||
std::cout << MolToMolBlock(*mol) << "$$$$" << std::endl;
|
||||
|
||||
try{
|
||||
field=UFF::constructForceField(*mol,2.5);
|
||||
try {
|
||||
field = UFF::constructForceField(*mol, 2.5);
|
||||
} catch (...) {
|
||||
field=0;
|
||||
field = 0;
|
||||
}
|
||||
if(field){
|
||||
if (field) {
|
||||
field->initialize();
|
||||
int needMore=1;
|
||||
int nPasses=0;
|
||||
while(needMore){
|
||||
int needMore = 1;
|
||||
int nPasses = 0;
|
||||
while (needMore) {
|
||||
#if 1
|
||||
needMore = field->minimize(checkEvery);
|
||||
if(verbose) std::cerr << "\t" << ++nPasses << std::endl;
|
||||
if (verbose) std::cerr << "\t" << ++nPasses << std::endl;
|
||||
#else
|
||||
needMore = field->minimize(1);
|
||||
std::cout << MolToMolBlock(mol) << "$$$$" << std::endl;
|
||||
@@ -46,63 +45,60 @@ void runMol(ROMol *mol,int checkEvery=10,bool verbose=true){
|
||||
} else {
|
||||
std::cerr << "failed";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void runMolFile(std::string fileName,int checkEvery=10){
|
||||
RWMol *mol=MolFileToMol(fileName,false);
|
||||
void runMolFile(std::string fileName, int checkEvery = 10) {
|
||||
RWMol *mol = MolFileToMol(fileName, false);
|
||||
TEST_ASSERT(mol);
|
||||
MolOps::sanitizeMol(*mol);
|
||||
|
||||
ROMol *mol2=MolOps::addHs(*mol,false,true);
|
||||
ROMol *mol2 = MolOps::addHs(*mol, false, true);
|
||||
|
||||
runMol(mol2,checkEvery);
|
||||
runMol(mol2, checkEvery);
|
||||
|
||||
delete mol;
|
||||
delete mol2;
|
||||
}
|
||||
|
||||
void runSDFile(std::string fileName,int checkEvery=10){
|
||||
SDMolSupplier suppl(fileName,false);
|
||||
|
||||
void runSDFile(std::string fileName, int checkEvery = 10) {
|
||||
SDMolSupplier suppl(fileName, false);
|
||||
|
||||
RWMol *mol;
|
||||
|
||||
mol = (RWMol *)suppl.next();
|
||||
while(mol){
|
||||
while (mol) {
|
||||
std::string name;
|
||||
mol->getProp(common_properties::_Name,name);
|
||||
mol->getProp(common_properties::_Name, name);
|
||||
std::cerr << "Mol: " << name << std::endl;
|
||||
try{
|
||||
try {
|
||||
MolOps::sanitizeMol(*mol);
|
||||
} catch (...) {
|
||||
std::cerr << " sanitization failed" << std::endl;
|
||||
delete mol;
|
||||
mol = 0;
|
||||
}
|
||||
if(mol){
|
||||
ROMol *mol2=MolOps::addHs(*mol,false,true);
|
||||
if (mol) {
|
||||
ROMol *mol2 = MolOps::addHs(*mol, false, true);
|
||||
delete mol;
|
||||
runMol(mol2,checkEvery,false);
|
||||
runMol(mol2, checkEvery, false);
|
||||
delete mol2;
|
||||
}
|
||||
mol = (RWMol *)suppl.next();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
//
|
||||
//-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||
int main(int argc,char *argv[]){
|
||||
PRECONDITION(argc>1,"bad arguments");
|
||||
std::string fileName=argv[1];
|
||||
int checkEvery=10;
|
||||
std::cerr << ">" << fileName<< " " << fileName.find(".sdf") << std::endl;
|
||||
if(fileName.find(".sdf")==std::string::npos){
|
||||
runMolFile(fileName,checkEvery);
|
||||
int main(int argc, char *argv[]) {
|
||||
PRECONDITION(argc > 1, "bad arguments");
|
||||
std::string fileName = argv[1];
|
||||
int checkEvery = 10;
|
||||
std::cerr << ">" << fileName << " " << fileName.find(".sdf") << std::endl;
|
||||
if (fileName.find(".sdf") == std::string::npos) {
|
||||
runMolFile(fileName, checkEvery);
|
||||
} else {
|
||||
runSDFile(fileName,checkEvery);
|
||||
runSDFile(fileName, checkEvery);
|
||||
}
|
||||
|
||||
std::cerr << "done" << std::endl;
|
||||
|
||||
@@ -10,30 +10,30 @@
|
||||
#include <GraphMol/RDKitBase.h>
|
||||
|
||||
namespace TemplateEnum {
|
||||
using namespace RDKit;
|
||||
using namespace RDKit;
|
||||
|
||||
class EnumException : public std::exception {
|
||||
public :
|
||||
EnumException(const char *msg) : _msg(msg) {};
|
||||
EnumException(const std::string msg) : _msg(msg) {};
|
||||
const char *message () const { return _msg.c_str(); };
|
||||
~EnumException () throw () {};
|
||||
private :
|
||||
std::string _msg;
|
||||
};
|
||||
class EnumException : public std::exception {
|
||||
public:
|
||||
EnumException(const char *msg) : _msg(msg){};
|
||||
EnumException(const std::string msg) : _msg(msg){};
|
||||
const char *message() const { return _msg.c_str(); };
|
||||
~EnumException() throw(){};
|
||||
|
||||
void orientSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molAttachIdx,int sidechainAttachIdx);
|
||||
private:
|
||||
std::string _msg;
|
||||
};
|
||||
|
||||
typedef std::vector< RWMOL_SPTR_VECT > VECT_RWMOL_SPTR_VECT;
|
||||
void markAttachmentPoints(RWMOL_SPTR *mol,char frontMarker='X');
|
||||
void markAttachmentPoints(RWMol *mol,char frontMarker='X');
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains,char frontMarker='Y');
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *mol,VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains=true);
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainName);
|
||||
void orientSidechain(RWMol *mol, RWMol *sidechain, int molAttachIdx,
|
||||
int sidechainAttachIdx);
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
typedef std::vector<RWMOL_SPTR_VECT> VECT_RWMOL_SPTR_VECT;
|
||||
void markAttachmentPoints(RWMOL_SPTR *mol, char frontMarker = 'X');
|
||||
void markAttachmentPoints(RWMol *mol, char frontMarker = 'X');
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains, char frontMarker = 'Y');
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *mol, VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains = true);
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainName);
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
#endif
|
||||
|
||||
|
||||
@@ -7,401 +7,404 @@
|
||||
#include <Geometry/Transform3D.h>
|
||||
#include <GraphMol/MolTransforms/MolTransforms.h>
|
||||
#include <GraphMol/FileParsers/FileParsers.h>
|
||||
#define FEQ(_a_,_b_) (fabs((_a_)-(_b_))<1e-4)
|
||||
#define FEQ(_a_, _b_) (fabs((_a_) - (_b_)) < 1e-4)
|
||||
|
||||
namespace TemplateEnum {
|
||||
using namespace RDKit;
|
||||
using namespace RDKit;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// transforms a sidechain so that it is oriented better for attachment
|
||||
// to a molecule
|
||||
//
|
||||
// Arguments:
|
||||
// mol: core molecule
|
||||
// sidechain: sidechain to attach.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void orientSidechain(RWMol *mol, RWMol *sidechain, int molAttachIdx,
|
||||
int sidechainAttachIdx) {
|
||||
PRECONDITION(mol, "bad molecule");
|
||||
PRECONDITION(sidechain, "bad molecule");
|
||||
|
||||
// ---------
|
||||
// start by getting our 4 atoms
|
||||
// ---------
|
||||
Conformer &molConf = mol->getConformer();
|
||||
Conformer &sidechainConf = sidechain->getConformer();
|
||||
Atom *molConnAtom, *molAttachAtom;
|
||||
Atom *chainConnAtom, *chainAttachAtom;
|
||||
molAttachAtom = mol->getAtomWithIdx(molAttachIdx);
|
||||
chainAttachAtom = sidechain->getAtomWithIdx(sidechainAttachIdx);
|
||||
PRECONDITION(molAttachAtom->getDegree() == 1,
|
||||
"attachment points must be degree 1");
|
||||
PRECONDITION(chainAttachAtom->getDegree() == 1,
|
||||
"attachment points must be degree 1");
|
||||
RWMol::ADJ_ITER nbrIdx, endNbrs;
|
||||
boost::tie(nbrIdx, endNbrs) = mol->getAtomNeighbors(molAttachAtom);
|
||||
molConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
boost::tie(nbrIdx, endNbrs) = sidechain->getAtomNeighbors(chainAttachAtom);
|
||||
chainConnAtom = sidechain->getAtomWithIdx(*nbrIdx);
|
||||
|
||||
//-----------------------------------------
|
||||
// Notation:
|
||||
// Pmc: molecule connection point (the atom that will be
|
||||
// removed from the molecule).
|
||||
// Pma: molecule attachment point (the atom to which we'll form
|
||||
// the bond).
|
||||
// Psc: sidechain connection point
|
||||
// Psa: sidechain attachment point
|
||||
// Vm: Pmc-Pma (molecular attachment vector)
|
||||
// Vs: Psc-Psa (sidechain attachment vector)
|
||||
//
|
||||
// transforms a sidechain so that it is oriented better for attachment
|
||||
// to a molecule
|
||||
//
|
||||
// Arguments:
|
||||
// mol: core molecule
|
||||
// sidechain: sidechain to attach.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void orientSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molAttachIdx,int sidechainAttachIdx){
|
||||
PRECONDITION(mol,"bad molecule");
|
||||
PRECONDITION(sidechain,"bad molecule");
|
||||
//-----------------------------------------
|
||||
RDGeom::Transform3D sidechainTform, templateTform, tmpTform;
|
||||
|
||||
// ---------
|
||||
// start by getting our 4 atoms
|
||||
// ---------
|
||||
Conformer &molConf=mol->getConformer();
|
||||
Conformer &sidechainConf=sidechain->getConformer();
|
||||
Atom *molConnAtom,*molAttachAtom;
|
||||
Atom *chainConnAtom,*chainAttachAtom;
|
||||
molAttachAtom = mol->getAtomWithIdx(molAttachIdx);
|
||||
chainAttachAtom = sidechain->getAtomWithIdx(sidechainAttachIdx);
|
||||
PRECONDITION(molAttachAtom->getDegree()==1,"attachment points must be degree 1");
|
||||
PRECONDITION(chainAttachAtom->getDegree()==1,"attachment points must be degree 1");
|
||||
RWMol::ADJ_ITER nbrIdx,endNbrs;
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(molAttachAtom);
|
||||
molConnAtom=mol->getAtomWithIdx(*nbrIdx);
|
||||
boost::tie(nbrIdx,endNbrs) = sidechain->getAtomNeighbors(chainAttachAtom);
|
||||
chainConnAtom=sidechain->getAtomWithIdx(*nbrIdx);
|
||||
RDGeom::Point3D Vm, Um, Pmc, Pma;
|
||||
RDGeom::Point3D Vs, Us, Psc, Psa;
|
||||
Pmc = molConf.getAtomPos(molConnAtom->getIdx());
|
||||
Pma = molConf.getAtomPos(molAttachAtom->getIdx());
|
||||
std::cerr << "p=array([" << Pma.x << "," << Pma.y << "," << Pma.z << "])"
|
||||
<< std::endl;
|
||||
Psc = sidechainConf.getAtomPos(chainConnAtom->getIdx());
|
||||
Psa = sidechainConf.getAtomPos(chainAttachAtom->getIdx());
|
||||
|
||||
templateTform.setToIdentity();
|
||||
Vm = Pmc - Pma;
|
||||
// note the opposite direction here:
|
||||
Vs = Psa - Psc;
|
||||
Um = Vm;
|
||||
Um.normalize();
|
||||
std::cerr << "Um=array([" << Um.x << "," << Um.y << "," << Um.z << "])"
|
||||
<< std::endl;
|
||||
Us = Vs;
|
||||
Us.normalize();
|
||||
std::cerr << "Us=array([" << Us.x << "," << Us.y << "," << Us.z << "])"
|
||||
<< std::endl;
|
||||
// translate Psc -> Pma
|
||||
// RDGeom::Point3D headTrans = Pma-Psc;
|
||||
|
||||
templateTform.setToIdentity();
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Pma);
|
||||
templateTform *= tmpTform;
|
||||
|
||||
double sinT, cosT;
|
||||
cosT = Us.dotProduct(Um);
|
||||
if (cosT > 1.0) cosT = 1.0;
|
||||
if (fabs(cosT) < 1.0) {
|
||||
tmpTform.setToIdentity();
|
||||
sinT = sqrt(1.0 - cosT * cosT);
|
||||
RDGeom::Point3D rotnAxis = Us.crossProduct(Um);
|
||||
rotnAxis.normalize();
|
||||
std::cerr << "ax=array([" << rotnAxis.x << "," << rotnAxis.y << ","
|
||||
<< rotnAxis.z << "])" << std::endl;
|
||||
tmpTform.SetRotation(cosT, sinT, rotnAxis);
|
||||
templateTform *= tmpTform;
|
||||
} else if (cosT == 1.0) {
|
||||
RDGeom::Point3D normal(1, 0, 0);
|
||||
if (fabs(Us.dotProduct(normal)) == 1.0) {
|
||||
normal = RDGeom::Point3D(0, 1, 0);
|
||||
}
|
||||
RDGeom::Point3D rotnAxis = Us.crossProduct(normal);
|
||||
templateTform.SetRotation(-1, 0, rotnAxis);
|
||||
}
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Psc * -1.0);
|
||||
templateTform *= tmpTform;
|
||||
|
||||
// ---------
|
||||
// transform the atomic positions in the sidechain:
|
||||
// ---------
|
||||
MolTransforms::transformMolsAtoms(sidechain, templateTform);
|
||||
|
||||
// that's it!
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// attaches a sidechain fragment to a molecule.
|
||||
//
|
||||
// Arguments:
|
||||
// mol: molecule to be modified
|
||||
// sidechain: sidechain to attach. The sidechain is copied in.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
// bondType: type of the bond to form between the atoms
|
||||
//
|
||||
// The connector atoms are *NOT* part of the final molecule, they
|
||||
// merely serve to establish where things connect.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void molAddSidechain(RWMol *mol, RWMol *sidechain, int molConnectorIdx,
|
||||
int sidechainConnectorIdx, Bond::BondType bondType) {
|
||||
PRECONDITION(mol, "bad molecule provided");
|
||||
PRECONDITION(sidechain, "bad sidechain provided");
|
||||
int origNumAtoms = mol->getNumAtoms();
|
||||
mol->insertMol(*sidechain);
|
||||
|
||||
// get pointers to the two connectors (these are the atoms
|
||||
// we'll end up removing)
|
||||
Atom *molConnAtom, *sidechainConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(molConnectorIdx);
|
||||
sidechainConnAtom = mol->getAtomWithIdx(sidechainConnectorIdx + origNumAtoms);
|
||||
|
||||
// now use those pointers to get the atoms which will remain
|
||||
// (we're going to connect these) and remove the original
|
||||
// connection points from the molecule
|
||||
Atom *tmpAtom;
|
||||
RWMol::ADJ_ITER nbrIdx, endNbrs;
|
||||
boost::tie(nbrIdx, endNbrs) = mol->getAtomNeighbors(molConnAtom);
|
||||
|
||||
// we are assuming that the first neighbor is the correct one.
|
||||
// Really we should be able to assume that there is only a single
|
||||
// attachment point.
|
||||
tmpAtom = molConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
// repeat that process for the sidechain:
|
||||
boost::tie(nbrIdx, endNbrs) = mol->getAtomNeighbors(sidechainConnAtom);
|
||||
tmpAtom = sidechainConnAtom;
|
||||
sidechainConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
|
||||
// finally connect the remaining atoms:
|
||||
mol->addBond(molConnAtom, sidechainConnAtom, bondType);
|
||||
}
|
||||
|
||||
// used as a starting point for connection bookmarks
|
||||
const int CONNECT_BOOKMARK_START = 0x23424223;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Loop through all the atoms and bookmark the attachment points
|
||||
//
|
||||
// attachment points are assumed to have one of these properties:
|
||||
// - common_properties::molFileAlias (set by the mol file parser)
|
||||
// - common_properties::dummyLabel (set by the SMILES parser)
|
||||
// frontMarker is the "recognition character" to be used to pick
|
||||
// valid labels. e.g. if the frontMarker is 'X', a label beginning
|
||||
// with 'Y' will not be marked.
|
||||
//
|
||||
// In addition to bookmarking the attachment points, we also set
|
||||
// the common_properties::maxAttachIdx property, which holds an integer with
|
||||
// the
|
||||
// maximum attachment bookmark index. This is used in the
|
||||
// enumeration to prevent us from having to scan through all the
|
||||
// molecule's bookmarks
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void markAttachmentPoints(RWMOL_SPTR mol, char frontMarker) {
|
||||
markAttachmentPoints(mol.get(), frontMarker);
|
||||
}
|
||||
void markAttachmentPoints(RWMol *mol, char frontMarker) {
|
||||
PRECONDITION(mol, "bad molecule");
|
||||
|
||||
RWMol::AtomIterator atomIt;
|
||||
int maxAttachIdx = 0;
|
||||
|
||||
// scan through the atoms and mark those that have aliases
|
||||
// (these might be attachment points)
|
||||
for (atomIt = mol->beginAtoms(); atomIt != mol->endAtoms(); atomIt++) {
|
||||
// start by finding possible attachment point properties:
|
||||
std::string attachLabel = "";
|
||||
if ((*atomIt)->hasProp(common_properties::molFileAlias)) {
|
||||
(*atomIt)->getProp(common_properties::molFileAlias, attachLabel);
|
||||
} else if ((*atomIt)->hasProp(common_properties::dummyLabel)) {
|
||||
(*atomIt)->getProp(common_properties::dummyLabel, attachLabel);
|
||||
}
|
||||
|
||||
// if we got one and it starts with the appropriate front
|
||||
// marker, proceed:
|
||||
if (attachLabel != "" && attachLabel[0] == frontMarker) {
|
||||
// to avoid trouble later, we guarantee that the attachment
|
||||
// point has degree 1 (one bond to it).
|
||||
if ((*atomIt)->getDegree() > 1)
|
||||
throw EnumException("More than one bond to an attachment point.");
|
||||
|
||||
int offset = CONNECT_BOOKMARK_START;
|
||||
if (attachLabel.length() > 1) {
|
||||
if (attachLabel[1] >= 'a' && attachLabel[1] <= 'z') {
|
||||
offset += (int)attachLabel[1] - (int)'a';
|
||||
}
|
||||
}
|
||||
mol->setAtomBookmark(*atomIt, offset);
|
||||
if (offset > maxAttachIdx) maxAttachIdx = offset;
|
||||
}
|
||||
}
|
||||
if (maxAttachIdx) {
|
||||
mol->setProp(common_properties::maxAttachIdx, maxAttachIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// loops through the sidechain molecules and calls
|
||||
// _markAttachmentPoints()_ on each.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains, char frontMarker) {
|
||||
PRECONDITION(sidechains, "bad sidechain list");
|
||||
RWMOL_SPTR_VECT::iterator mpvI;
|
||||
for (mpvI = sidechains->begin(); mpvI != sidechains->end(); mpvI++) {
|
||||
markAttachmentPoints(*mpvI, frontMarker);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Enumerates the library around a template and returns the result.
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *templateMol,
|
||||
VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains) {
|
||||
PRECONDITION(templateMol, "bad molecule");
|
||||
RWMOL_SPTR_VECT res, tmp;
|
||||
res.push_back(RWMOL_SPTR(new RWMol(*templateMol)));
|
||||
|
||||
// if there's no attachment point on the molecule or no
|
||||
// sidechains, return now:
|
||||
if (!templateMol->hasProp(common_properties::maxAttachIdx) ||
|
||||
sidechains.size() == 0)
|
||||
return res;
|
||||
|
||||
int maxIdx;
|
||||
templateMol->getProp(common_properties::maxAttachIdx, maxIdx);
|
||||
|
||||
tmp.clear();
|
||||
// loop over the sidechains and attach them
|
||||
for (unsigned int i = 0; i < sidechains.size(); i++) {
|
||||
int tgtMark = CONNECT_BOOKMARK_START + i;
|
||||
// here's another boundary condition
|
||||
if (tgtMark > maxIdx) break;
|
||||
|
||||
/// loop over all atoms with the appropriate mark
|
||||
// This means that if a mol has two attachment points with the
|
||||
// same name (e.g. two Xa's) they'll always have the same
|
||||
// sidechain attached to them. This is a feature.
|
||||
RWMOL_SPTR_VECT::iterator sidechainIt;
|
||||
for (sidechainIt = sidechains[i].begin();
|
||||
sidechainIt != sidechains[i].end(); sidechainIt++) {
|
||||
// we've got our sidechain, find the atom it attaches from
|
||||
if ((*sidechainIt)->hasAtomBookmark(CONNECT_BOOKMARK_START)) {
|
||||
//
|
||||
// NOTE: If there's more than one marked atom in the sidechain,
|
||||
/// we'll only use the first for the moment.
|
||||
//
|
||||
int sidechainAtomIdx = (*sidechainIt)
|
||||
->getAtomWithBookmark(CONNECT_BOOKMARK_START)
|
||||
->getIdx();
|
||||
|
||||
// now add the sidechain to each molecule
|
||||
RWMOL_SPTR_VECT::iterator templMolIt;
|
||||
// loop over all the mols we've generated to this point
|
||||
for (templMolIt = res.begin(); templMolIt != res.end(); templMolIt++) {
|
||||
RWMol *templ = new RWMol(**templMolIt);
|
||||
std::string name, tmpStr;
|
||||
if (templ->hasProp(common_properties::_Name)) {
|
||||
templ->getProp(common_properties::_Name, tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
while (templ->hasAtomBookmark(tgtMark)) {
|
||||
// this is the atom we'll be replacing in the template
|
||||
Atom *at = templ->getAtomWithBookmark(tgtMark);
|
||||
|
||||
// copy and transform the sidechain:
|
||||
RWMol *sidechain;
|
||||
if (orientSidechains) {
|
||||
sidechain = new RWMol(*(sidechainIt->get()));
|
||||
orientSidechain(templ, sidechain, at->getIdx(), sidechainAtomIdx);
|
||||
} else {
|
||||
sidechain = sidechainIt->get();
|
||||
}
|
||||
// FIX: need to use the actual bond order here:
|
||||
molAddSidechain(templ, sidechain, at->getIdx(), sidechainAtomIdx,
|
||||
Bond::SINGLE);
|
||||
if (sidechain->hasProp(common_properties::_Name)) {
|
||||
sidechain->getProp(common_properties::_Name, tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
templ->clearAtomBookmark(tgtMark, at);
|
||||
if (orientSidechains) {
|
||||
delete sidechain;
|
||||
}
|
||||
}
|
||||
// std::cout << templ << "> " << MolToSmiles(*templ) << std::endl;
|
||||
if (name != "") templ->setProp(common_properties::_Name, name);
|
||||
tmp.push_back(RWMOL_SPTR(templ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------
|
||||
// Notation:
|
||||
// Pmc: molecule connection point (the atom that will be
|
||||
// removed from the molecule).
|
||||
// Pma: molecule attachment point (the atom to which we'll form
|
||||
// the bond).
|
||||
// Psc: sidechain connection point
|
||||
// Psa: sidechain attachment point
|
||||
// Vm: Pmc-Pma (molecular attachment vector)
|
||||
// Vs: Psc-Psa (sidechain attachment vector)
|
||||
//
|
||||
//-----------------------------------------
|
||||
RDGeom::Transform3D sidechainTform,templateTform,tmpTform;
|
||||
|
||||
RDGeom::Point3D Vm,Um,Pmc,Pma;
|
||||
RDGeom::Point3D Vs,Us,Psc,Psa;
|
||||
Pmc = molConf.getAtomPos(molConnAtom->getIdx());
|
||||
Pma = molConf.getAtomPos(molAttachAtom->getIdx());
|
||||
std::cerr << "p=array(["<<Pma.x<<","<<Pma.y<<","<<Pma.z<<"])" << std::endl;
|
||||
Psc = sidechainConf.getAtomPos(chainConnAtom->getIdx());
|
||||
Psa = sidechainConf.getAtomPos(chainAttachAtom->getIdx());
|
||||
|
||||
templateTform.setToIdentity();
|
||||
Vm = Pmc - Pma;
|
||||
// note the opposite direction here:
|
||||
Vs = Psa - Psc;
|
||||
Um = Vm;
|
||||
Um.normalize();
|
||||
std::cerr << "Um=array(["<<Um.x<<","<<Um.y<<","<<Um.z<<"])" << std::endl;
|
||||
Us = Vs;
|
||||
Us.normalize();
|
||||
std::cerr << "Us=array(["<<Us.x<<","<<Us.y<<","<<Us.z<<"])" << std::endl;
|
||||
// translate Psc -> Pma
|
||||
//RDGeom::Point3D headTrans = Pma-Psc;
|
||||
|
||||
templateTform.setToIdentity();
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Pma);
|
||||
templateTform *= tmpTform;
|
||||
|
||||
double sinT,cosT;
|
||||
cosT = Us.dotProduct(Um);
|
||||
if(cosT>1.0) cosT = 1.0;
|
||||
if(fabs(cosT)<1.0){
|
||||
tmpTform.setToIdentity();
|
||||
sinT = sqrt(1.0-cosT*cosT);
|
||||
RDGeom::Point3D rotnAxis=Us.crossProduct(Um);
|
||||
rotnAxis.normalize();
|
||||
std::cerr << "ax=array(["<<rotnAxis.x<<","<<rotnAxis.y<<","<<rotnAxis.z<<"])" << std::endl;
|
||||
tmpTform.SetRotation(cosT,sinT,rotnAxis);
|
||||
templateTform *= tmpTform;
|
||||
} else if(cosT==1.0){
|
||||
RDGeom::Point3D normal(1,0,0);
|
||||
if(fabs(Us.dotProduct(normal))==1.0){
|
||||
normal = RDGeom::Point3D(0,1,0);
|
||||
}
|
||||
RDGeom::Point3D rotnAxis=Us.crossProduct(normal);
|
||||
templateTform.SetRotation(-1,0,rotnAxis);
|
||||
}
|
||||
|
||||
tmpTform.setToIdentity();
|
||||
tmpTform.SetTranslation(Psc*-1.0);
|
||||
templateTform *= tmpTform;
|
||||
|
||||
// ---------
|
||||
// transform the atomic positions in the sidechain:
|
||||
// ---------
|
||||
MolTransforms::transformMolsAtoms(sidechain,templateTform);
|
||||
|
||||
|
||||
// that's it!
|
||||
}
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// attaches a sidechain fragment to a molecule.
|
||||
//
|
||||
// Arguments:
|
||||
// mol: molecule to be modified
|
||||
// sidechain: sidechain to attach. The sidechain is copied in.
|
||||
// molConnectorIdx: the index of the attachment point atom in the
|
||||
// molecule.
|
||||
// sidechainConnectorIdx: the index of the attachment point atom
|
||||
// in the sidechain.
|
||||
// bondType: type of the bond to form between the atoms
|
||||
//
|
||||
// The connector atoms are *NOT* part of the final molecule, they
|
||||
// merely serve to establish where things connect.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void molAddSidechain(RWMol *mol,RWMol *sidechain,
|
||||
int molConnectorIdx,int sidechainConnectorIdx,
|
||||
Bond::BondType bondType){
|
||||
PRECONDITION(mol,"bad molecule provided");
|
||||
PRECONDITION(sidechain,"bad sidechain provided");
|
||||
int origNumAtoms=mol->getNumAtoms();
|
||||
mol->insertMol(*sidechain);
|
||||
|
||||
// get pointers to the two connectors (these are the atoms
|
||||
// we'll end up removing)
|
||||
Atom *molConnAtom,*sidechainConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(molConnectorIdx);
|
||||
sidechainConnAtom = mol->getAtomWithIdx(sidechainConnectorIdx+origNumAtoms);
|
||||
|
||||
// now use those pointers to get the atoms which will remain
|
||||
// (we're going to connect these) and remove the original
|
||||
// connection points from the molecule
|
||||
Atom *tmpAtom;
|
||||
RWMol::ADJ_ITER nbrIdx,endNbrs;
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(molConnAtom);
|
||||
|
||||
// we are assuming that the first neighbor is the correct one.
|
||||
// Really we should be able to assume that there is only a single
|
||||
// attachment point.
|
||||
tmpAtom = molConnAtom;
|
||||
molConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
// repeat that process for the sidechain:
|
||||
boost::tie(nbrIdx,endNbrs) = mol->getAtomNeighbors(sidechainConnAtom);
|
||||
tmpAtom = sidechainConnAtom;
|
||||
sidechainConnAtom = mol->getAtomWithIdx(*nbrIdx);
|
||||
mol->removeAtom(tmpAtom);
|
||||
|
||||
// finally connect the remaining atoms:
|
||||
mol->addBond(molConnAtom,sidechainConnAtom,bondType);
|
||||
}
|
||||
|
||||
|
||||
// used as a starting point for connection bookmarks
|
||||
const int CONNECT_BOOKMARK_START=0x23424223;
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Loop through all the atoms and bookmark the attachment points
|
||||
//
|
||||
// attachment points are assumed to have one of these properties:
|
||||
// - common_properties::molFileAlias (set by the mol file parser)
|
||||
// - common_properties::dummyLabel (set by the SMILES parser)
|
||||
// frontMarker is the "recognition character" to be used to pick
|
||||
// valid labels. e.g. if the frontMarker is 'X', a label beginning
|
||||
// with 'Y' will not be marked.
|
||||
//
|
||||
// In addition to bookmarking the attachment points, we also set
|
||||
// the common_properties::maxAttachIdx property, which holds an integer with the
|
||||
// maximum attachment bookmark index. This is used in the
|
||||
// enumeration to prevent us from having to scan through all the
|
||||
// molecule's bookmarks
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void markAttachmentPoints(RWMOL_SPTR mol,char frontMarker){
|
||||
markAttachmentPoints(mol.get(),frontMarker);
|
||||
}
|
||||
void markAttachmentPoints(RWMol *mol,char frontMarker){
|
||||
PRECONDITION(mol,"bad molecule");
|
||||
|
||||
RWMol::AtomIterator atomIt;
|
||||
int maxAttachIdx=0;
|
||||
|
||||
// scan through the atoms and mark those that have aliases
|
||||
// (these might be attachment points)
|
||||
for(atomIt=mol->beginAtoms();atomIt!=mol->endAtoms();atomIt++){
|
||||
// start by finding possible attachment point properties:
|
||||
std::string attachLabel="";
|
||||
if((*atomIt)->hasProp(common_properties::molFileAlias)){
|
||||
(*atomIt)->getProp(common_properties::molFileAlias,attachLabel);
|
||||
} else if((*atomIt)->hasProp(common_properties::dummyLabel)){
|
||||
(*atomIt)->getProp(common_properties::dummyLabel,attachLabel);
|
||||
}
|
||||
|
||||
// if we got one and it starts with the appropriate front
|
||||
// marker, proceed:
|
||||
if(attachLabel!="" && attachLabel[0]==frontMarker ){
|
||||
// to avoid trouble later, we guarantee that the attachment
|
||||
// point has degree 1 (one bond to it).
|
||||
if((*atomIt)->getDegree()>1)
|
||||
throw EnumException("More than one bond to an attachment point.");
|
||||
|
||||
int offset = CONNECT_BOOKMARK_START;
|
||||
if(attachLabel.length()>1){
|
||||
if(attachLabel[1]>='a' && attachLabel[1]<='z'){
|
||||
offset += (int)attachLabel[1] - (int)'a';
|
||||
}
|
||||
}
|
||||
mol->setAtomBookmark(*atomIt,offset);
|
||||
if(offset>maxAttachIdx) maxAttachIdx=offset;
|
||||
}
|
||||
}
|
||||
if(maxAttachIdx){
|
||||
mol->setProp(common_properties::maxAttachIdx,maxAttachIdx);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// loops through the sidechain molecules and calls
|
||||
// _markAttachmentPoints()_ on each.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
void prepareSidechains(RWMOL_SPTR_VECT *sidechains,char frontMarker){
|
||||
PRECONDITION(sidechains,"bad sidechain list");
|
||||
RWMOL_SPTR_VECT::iterator mpvI;
|
||||
for(mpvI=sidechains->begin();mpvI!=sidechains->end();mpvI++){
|
||||
markAttachmentPoints(*mpvI,frontMarker);
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Enumerates the library around a template and returns the result.
|
||||
//
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumerateLibrary(RWMol *templateMol,
|
||||
VECT_RWMOL_SPTR_VECT &sidechains,
|
||||
bool orientSidechains){
|
||||
PRECONDITION(templateMol,"bad molecule");
|
||||
RWMOL_SPTR_VECT res,tmp;
|
||||
res.push_back(RWMOL_SPTR(new RWMol(*templateMol)));
|
||||
|
||||
// if there's no attachment point on the molecule or no
|
||||
// sidechains, return now:
|
||||
if(!templateMol->hasProp(common_properties::maxAttachIdx) || sidechains.size()==0 )
|
||||
return res;
|
||||
|
||||
int maxIdx;
|
||||
templateMol->getProp(common_properties::maxAttachIdx,maxIdx);
|
||||
|
||||
tmp.clear();
|
||||
// loop over the sidechains and attach them
|
||||
for(unsigned int i=0;i<sidechains.size();i++){
|
||||
int tgtMark=CONNECT_BOOKMARK_START+i;
|
||||
// here's another boundary condition
|
||||
if(tgtMark>maxIdx) break;
|
||||
|
||||
/// loop over all atoms with the appropriate mark
|
||||
// This means that if a mol has two attachment points with the
|
||||
// same name (e.g. two Xa's) they'll always have the same
|
||||
// sidechain attached to them. This is a feature.
|
||||
RWMOL_SPTR_VECT::iterator sidechainIt;
|
||||
for(sidechainIt=sidechains[i].begin();
|
||||
sidechainIt!=sidechains[i].end();
|
||||
sidechainIt++){
|
||||
// we've got our sidechain, find the atom it attaches from
|
||||
if( (*sidechainIt)->hasAtomBookmark(CONNECT_BOOKMARK_START) ){
|
||||
//
|
||||
// NOTE: If there's more than one marked atom in the sidechain,
|
||||
/// we'll only use the first for the moment.
|
||||
//
|
||||
int sidechainAtomIdx = (*sidechainIt)->getAtomWithBookmark(CONNECT_BOOKMARK_START)->getIdx();
|
||||
|
||||
// now add the sidechain to each molecule
|
||||
RWMOL_SPTR_VECT::iterator templMolIt;
|
||||
// loop over all the mols we've generated to this point
|
||||
for(templMolIt=res.begin();templMolIt!=res.end();templMolIt++){
|
||||
RWMol *templ = new RWMol(**templMolIt);
|
||||
std::string name,tmpStr;
|
||||
if(templ->hasProp(common_properties::_Name)){
|
||||
templ->getProp(common_properties::_Name,tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
while(templ->hasAtomBookmark(tgtMark)){
|
||||
// this is the atom we'll be replacing in the template
|
||||
Atom *at = templ->getAtomWithBookmark(tgtMark);
|
||||
|
||||
// copy and transform the sidechain:
|
||||
RWMol *sidechain;
|
||||
if(orientSidechains){
|
||||
sidechain = new RWMol(*(sidechainIt->get()));
|
||||
orientSidechain(templ,sidechain,
|
||||
at->getIdx(),sidechainAtomIdx);
|
||||
} else {
|
||||
sidechain = sidechainIt->get();
|
||||
}
|
||||
// FIX: need to use the actual bond order here:
|
||||
molAddSidechain(templ,sidechain,
|
||||
at->getIdx(),sidechainAtomIdx,
|
||||
Bond::SINGLE);
|
||||
if(sidechain->hasProp(common_properties::_Name)){
|
||||
sidechain->getProp(common_properties::_Name,tmpStr);
|
||||
name = name + " " + tmpStr;
|
||||
}
|
||||
templ->clearAtomBookmark(tgtMark,at);
|
||||
if(orientSidechains){
|
||||
delete sidechain;
|
||||
}
|
||||
}
|
||||
//std::cout << templ << "> " << MolToSmiles(*templ) << std::endl;
|
||||
if(name != "") templ->setProp(common_properties::_Name,name);
|
||||
tmp.push_back(RWMOL_SPTR(templ));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// if we just made any molecules, free up the memory used by the
|
||||
// existing result set and move the molecules we just generated
|
||||
// over
|
||||
if(tmp.size()){
|
||||
// if we just made any molecules, free up the memory used by the
|
||||
// existing result set and move the molecules we just generated
|
||||
// over
|
||||
if (tmp.size()) {
|
||||
#if 0
|
||||
RWMOL_SPTR_VECT::iterator tmpMolIt;
|
||||
for(tmpMolIt=res.begin();tmpMolIt!=res.end();tmpMolIt++){
|
||||
delete *tmpMolIt;
|
||||
}
|
||||
#endif
|
||||
res = tmp;
|
||||
tmp.clear();
|
||||
}
|
||||
res = tmp;
|
||||
tmp.clear();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
//
|
||||
// Reads a template and library of sidechains from input files.
|
||||
// the template file should be a mol file and the sidechain files
|
||||
// SD files
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainNames) {
|
||||
PRECONDITION(templateName, "bad template file name passed in");
|
||||
|
||||
// build and mark the template molecule
|
||||
RWMol *templ = MolFileToMol(templateName, false);
|
||||
if (!templ) throw EnumException("could not construct template molecule");
|
||||
markAttachmentPoints(templ, 'X');
|
||||
|
||||
// now build and mark each set of sidechains:
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
VECT_RWMOL_SPTR_VECT allSidechains;
|
||||
for (std::vector<const char *>::const_iterator i = sidechainNames.begin();
|
||||
i != sidechainNames.end(); i++) {
|
||||
sidechains = SDFileToMols(*i, false);
|
||||
if (!sidechains.size()) {
|
||||
std::string err = "no sidechains read from file: ";
|
||||
err += *i;
|
||||
throw EnumException(err.c_str());
|
||||
}
|
||||
prepareSidechains(&sidechains, 'X');
|
||||
allSidechains.push_back(sidechains);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// enumerate the library:
|
||||
RWMOL_SPTR_VECT library = enumerateLibrary(templ, allSidechains);
|
||||
|
||||
//--------------------------
|
||||
//
|
||||
// Reads a template and library of sidechains from input files.
|
||||
// the template file should be a mol file and the sidechain files
|
||||
// SD files
|
||||
// Clean up the molecules and sidechains we constructed along the
|
||||
// way.
|
||||
//
|
||||
// ------------------------------------------------------------------
|
||||
RWMOL_SPTR_VECT enumFromFiles(const char *templateName,
|
||||
std::vector<const char *> &sidechainNames){
|
||||
PRECONDITION(templateName,"bad template file name passed in");
|
||||
|
||||
// build and mark the template molecule
|
||||
RWMol *templ = MolFileToMol(templateName,false);
|
||||
if(!templ) throw EnumException("could not construct template molecule");
|
||||
markAttachmentPoints(templ,'X');
|
||||
|
||||
// now build and mark each set of sidechains:
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
VECT_RWMOL_SPTR_VECT allSidechains;
|
||||
for(std::vector<const char*>::const_iterator i=sidechainNames.begin();
|
||||
i!=sidechainNames.end();i++){
|
||||
sidechains = SDFileToMols(*i,false);
|
||||
if(!sidechains.size()){
|
||||
std::string err="no sidechains read from file: ";
|
||||
err += *i;
|
||||
throw EnumException(err.c_str());
|
||||
}
|
||||
prepareSidechains(&sidechains,'X');
|
||||
allSidechains.push_back(sidechains);
|
||||
}
|
||||
|
||||
// enumerate the library:
|
||||
RWMOL_SPTR_VECT library=enumerateLibrary(templ,allSidechains);
|
||||
|
||||
|
||||
//--------------------------
|
||||
//
|
||||
// Clean up the molecules and sidechains we constructed along the
|
||||
// way.
|
||||
//
|
||||
//--------------------------
|
||||
delete templ;
|
||||
//--------------------------
|
||||
delete templ;
|
||||
#if 0
|
||||
VECT_RWMOL_SPTR_VECT::iterator vmpvI;
|
||||
for(vmpvI=allSidechains.begin();vmpvI!=allSidechains.end();vmpvI++){
|
||||
@@ -412,10 +415,9 @@ namespace TemplateEnum {
|
||||
vmpvI->clear();
|
||||
}
|
||||
#endif
|
||||
allSidechains.clear();
|
||||
allSidechains.clear();
|
||||
|
||||
return library;
|
||||
}
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
return library;
|
||||
}
|
||||
|
||||
} // end of TemplateEnum namespace
|
||||
|
||||
@@ -13,273 +13,326 @@ using namespace TemplateEnum;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
bool feq(RDGeom::Point3D p1,RDGeom::Point3D p2,double tol=1e-4){
|
||||
return feq(p1.x,p2.x,tol)&&feq(p1.y,p2.y,tol)&&feq(p1.z,p2.z,tol);
|
||||
bool feq(RDGeom::Point3D p1, RDGeom::Point3D p2, double tol = 1e-4) {
|
||||
return feq(p1.x, p2.x, tol) && feq(p1.y, p2.y, tol) && feq(p1.z, p2.z, tol);
|
||||
}
|
||||
|
||||
void test1(){
|
||||
void test1() {
|
||||
// single attachment point, small list
|
||||
std::cout << " ----------> Test1 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
std::vector<const char *> fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.1.mol",fileNames);
|
||||
library = enumFromFiles("template.1.mol", fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==2,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library.size() == 2, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 10, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 11, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void test2(){
|
||||
void test2() {
|
||||
// single attachment point, larger list
|
||||
std::cout << " ----------> Test2 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
std::vector<const char *> fileNames;
|
||||
fileNames.push_back("esters.sdf");
|
||||
fileNames.push_back("esters.sdf");
|
||||
library = enumFromFiles("template.1.mol",fileNames);
|
||||
library = enumFromFiles("template.1.mol", fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==6,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library.size() == 6, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 10, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 11, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 12, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 12, "");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms() == 13, "");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms() == 13, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test3(){
|
||||
void test3() {
|
||||
// two attachment points, small list
|
||||
std::cout << " ----------> Test3 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
std::vector<const char *> fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.mol",fileNames);
|
||||
library = enumFromFiles("template.mol", fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==15,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==15,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==16,"");
|
||||
CHECK_INVARIANT(library.size() == 4, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 14, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 15, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 15, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 16, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test4(){
|
||||
void test4() {
|
||||
// test templates that have repeated attachment points
|
||||
std::cout << " ----------> Test4 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
std::vector<const char *>fileNames;
|
||||
std::vector<const char *> fileNames;
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
fileNames.push_back("esters.2.sdf");
|
||||
library = enumFromFiles("template.2.mol",fileNames);
|
||||
library = enumFromFiles("template.2.mol", fileNames);
|
||||
|
||||
CHECK_INVARIANT(library.size()==2,"");
|
||||
CHECK_INVARIANT(library.size() == 2, "");
|
||||
library[0]->debugMol(std::cout);
|
||||
std::cout << "smi0: " << MolToSmiles(*library[0],0) << std::endl;
|
||||
std::cout << "smi1: " << MolToSmiles(*library[1],0) << std::endl;
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==16,"");
|
||||
|
||||
std::cout << "smi0: " << MolToSmiles(*library[0], 0) << std::endl;
|
||||
std::cout << "smi1: " << MolToSmiles(*library[1], 0) << std::endl;
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 14, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 16, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test5(){
|
||||
void test5() {
|
||||
// test working from SMILES
|
||||
std::cout << " ----------> Test5 " << std::endl;
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC",0,0);
|
||||
CHECK_INVARIANT(m1,"");
|
||||
markAttachmentPoints(m1,'X');
|
||||
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC", 0, 0);
|
||||
CHECK_INVARIANT(m1, "");
|
||||
markAttachmentPoints(m1, 'X');
|
||||
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)C",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)CCC",0,0)));
|
||||
prepareSidechains(&sidechains,'X');
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)", 0, 0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)C", 0, 0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("[X]OC(=O)CCC", 0, 0)));
|
||||
prepareSidechains(&sidechains, 'X');
|
||||
|
||||
VECT_RWMOL_SPTR_VECT allSideChains;
|
||||
allSideChains.push_back(sidechains);
|
||||
allSideChains.push_back(sidechains);
|
||||
|
||||
RWMOL_SPTR_VECT library;
|
||||
library = enumerateLibrary(m1,allSideChains,false);
|
||||
library = enumerateLibrary(m1, allSideChains, false);
|
||||
|
||||
CHECK_INVARIANT(library.size()==9,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==10,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==11,"");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms()==12,"");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[6]->getNumAtoms()==13,"");
|
||||
CHECK_INVARIANT(library[7]->getNumAtoms()==14,"");
|
||||
CHECK_INVARIANT(library[8]->getNumAtoms()==16,"");
|
||||
CHECK_INVARIANT(library.size() == 9, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 10, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 11, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 13, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 11, "");
|
||||
CHECK_INVARIANT(library[4]->getNumAtoms() == 12, "");
|
||||
CHECK_INVARIANT(library[5]->getNumAtoms() == 14, "");
|
||||
CHECK_INVARIANT(library[6]->getNumAtoms() == 13, "");
|
||||
CHECK_INVARIANT(library[7]->getNumAtoms() == 14, "");
|
||||
CHECK_INVARIANT(library[8]->getNumAtoms() == 16, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test6(){
|
||||
void test6() {
|
||||
// test working from SMILES with no matches
|
||||
std::cout << " ----------> Test6 " << std::endl;
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC",0,0);
|
||||
CHECK_INVARIANT(m1,"");
|
||||
markAttachmentPoints(m1,'X');
|
||||
|
||||
RWMol *m1 = SmilesToMol("[Xa]CC([Xb])CC", 0, 0);
|
||||
CHECK_INVARIANT(m1, "");
|
||||
markAttachmentPoints(m1, 'X');
|
||||
|
||||
RWMOL_SPTR_VECT sidechains;
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)C",0,0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)CCC",0,0)));
|
||||
prepareSidechains(&sidechains,'X');
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)", 0, 0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)C", 0, 0)));
|
||||
sidechains.push_back(RWMOL_SPTR(SmilesToMol("OC(=O)CCC", 0, 0)));
|
||||
prepareSidechains(&sidechains, 'X');
|
||||
|
||||
VECT_RWMOL_SPTR_VECT allSideChains;
|
||||
allSideChains.push_back(sidechains);
|
||||
allSideChains.push_back(sidechains);
|
||||
|
||||
RWMOL_SPTR_VECT library;
|
||||
library = enumerateLibrary(m1,allSideChains,false);
|
||||
library = enumerateLibrary(m1, allSideChains, false);
|
||||
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==6,"");
|
||||
CHECK_INVARIANT(library.size() == 1, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 6, "");
|
||||
|
||||
library.clear();
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
void test7(){
|
||||
void test7() {
|
||||
// test transforms
|
||||
std::cout << " ----------> Test7 " << std::endl;
|
||||
RWMOL_SPTR_VECT library;
|
||||
RWMOL_SPTR mol;
|
||||
Atom *at1,*at2;
|
||||
Atom *at1, *at2;
|
||||
int i;
|
||||
std::vector<const char *>fileNames;
|
||||
std::vector<const char *> fileNames;
|
||||
fileNames.push_back("Ts.1.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
library = enumFromFiles("box.1.mol", fileNames);
|
||||
CHECK_INVARIANT(library.size() == 1, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 8, "");
|
||||
mol = library[0];
|
||||
at1=mol->getAtomWithIdx(0);
|
||||
at2=mol->getAtomWithIdx(4);
|
||||
CHECK_INVARIANT(feq(mol->getConformer().getAtomPos(at1->getIdx()).x,mol->getConformer().getAtomPos(at2->getIdx()).x),"");
|
||||
CHECK_INVARIANT(mol->getConformer().getAtomPos(at1->getIdx()).y-mol->getConformer().getAtomPos(at2->getIdx()).y==-1.0,"");
|
||||
at1 = mol->getAtomWithIdx(0);
|
||||
at2 = mol->getAtomWithIdx(4);
|
||||
CHECK_INVARIANT(feq(mol->getConformer().getAtomPos(at1->getIdx()).x,
|
||||
mol->getConformer().getAtomPos(at2->getIdx()).x),
|
||||
"");
|
||||
CHECK_INVARIANT(mol->getConformer().getAtomPos(at1->getIdx()).y -
|
||||
mol->getConformer().getAtomPos(at2->getIdx()).y ==
|
||||
-1.0,
|
||||
"");
|
||||
library.clear();
|
||||
|
||||
// try another orientation of the sidechain molecule:
|
||||
fileNames.clear();
|
||||
fileNames.push_back("Ts.4.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==1,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
library = enumFromFiles("box.1.mol", fileNames);
|
||||
CHECK_INVARIANT(library.size() == 1, "");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 8, "");
|
||||
mol = library[0];
|
||||
std::cout << MolToMolBlock(*mol);
|
||||
std::cout << std::endl;
|
||||
|
||||
at1=mol->getAtomWithIdx(0);
|
||||
at2=mol->getAtomWithIdx(7);
|
||||
TEST_ASSERT(feq(mol->getConformer().getAtomPos(7),RDGeom::Point3D(-.5,2.5,0.0)));
|
||||
at1 = mol->getAtomWithIdx(0);
|
||||
at2 = mol->getAtomWithIdx(7);
|
||||
TEST_ASSERT(
|
||||
feq(mol->getConformer().getAtomPos(7), RDGeom::Point3D(-.5, 2.5, 0.0)));
|
||||
library.clear();
|
||||
|
||||
|
||||
// now use an SD file that has the same molecule in different
|
||||
// orientations as sidechains:
|
||||
fileNames.clear();
|
||||
fileNames.push_back("Ts.sdf");
|
||||
library = enumFromFiles("box.1.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
library = enumFromFiles("box.1.mol", fileNames);
|
||||
CHECK_INVARIANT(library.size() == 4, "");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 8, "");
|
||||
|
||||
for(i=0;i<library.size();i++){
|
||||
for (i = 0; i < library.size(); i++) {
|
||||
std::cout << "------ Mol: " << i << "------" << std::endl;
|
||||
mol = library[i];
|
||||
std::cout << MolToMolBlock(*mol);
|
||||
std::cout << std::endl;
|
||||
}
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[1]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[1]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[1]->getConformer().getAtomPos(i).z),"");
|
||||
for (i = 0; i < library[0]->getNumAtoms(); i++) {
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[1]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[1]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[1]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[2]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[2]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[2]->getConformer().getAtomPos(i).z),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[2]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[2]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[2]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i),library[3]->getConformer().getAtomPos(i)),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i),
|
||||
library[3]->getConformer().getAtomPos(i)),
|
||||
"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
// move the attachment point on the template. This should
|
||||
// make no difference.
|
||||
library = enumFromFiles("box.1a.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
library = enumFromFiles("box.1a.mol", fileNames);
|
||||
CHECK_INVARIANT(library.size() == 4, "");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==8,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 8, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 8, "");
|
||||
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[1]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[1]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[1]->getConformer().getAtomPos(i).z),"");
|
||||
for (i = 0; i < library[0]->getNumAtoms(); i++) {
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[1]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[1]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[1]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[2]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[2]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[2]->getConformer().getAtomPos(i).z),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[2]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[2]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[2]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
//std::cout << i << "\t" << library[0]->getConformer().getAtomPos(i) << std::endl;
|
||||
//std::cout << "\t" << library[3]->getConformer().getAtomPos(i) << std::endl;
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[3]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[3]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[3]->getConformer().getAtomPos(i).z),"");
|
||||
// std::cout << i << "\t" << library[0]->getConformer().getAtomPos(i) <<
|
||||
// std::endl;
|
||||
// std::cout << "\t" << library[3]->getConformer().getAtomPos(i) <<
|
||||
// std::endl;
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[3]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[3]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[3]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
// move the attachment point on the template. This should
|
||||
// make no difference.
|
||||
library = enumFromFiles("box.mol",fileNames);
|
||||
CHECK_INVARIANT(library.size()==4,"");
|
||||
library = enumFromFiles("box.mol", fileNames);
|
||||
CHECK_INVARIANT(library.size() == 4, "");
|
||||
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms()==20,"");
|
||||
CHECK_INVARIANT(library[0]->getNumAtoms() == 20, "");
|
||||
CHECK_INVARIANT(library[1]->getNumAtoms() == 20, "");
|
||||
CHECK_INVARIANT(library[2]->getNumAtoms() == 20, "");
|
||||
CHECK_INVARIANT(library[3]->getNumAtoms() == 20, "");
|
||||
|
||||
for(i=0;i<library[0]->getNumAtoms();i++){
|
||||
for (i = 0; i < library[0]->getNumAtoms(); i++) {
|
||||
at1 = library[0]->getAtomWithIdx(i);
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[1]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[1]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[1]->getConformer().getAtomPos(i).z),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[1]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[1]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[1]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[2]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[2]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[2]->getConformer().getAtomPos(i).z),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[2]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[2]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[2]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,library[3]->getConformer().getAtomPos(i).x),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,library[3]->getConformer().getAtomPos(i).y),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,library[3]->getConformer().getAtomPos(i).z),"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).x,
|
||||
library[3]->getConformer().getAtomPos(i).x),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).y,
|
||||
library[3]->getConformer().getAtomPos(i).y),
|
||||
"");
|
||||
CHECK_INVARIANT(feq(library[0]->getConformer().getAtomPos(i).z,
|
||||
library[3]->getConformer().getAtomPos(i).z),
|
||||
"");
|
||||
}
|
||||
library.clear();
|
||||
|
||||
|
||||
|
||||
std::cout << " <---------- Done " << std::endl;
|
||||
}
|
||||
|
||||
@@ -414,15 +467,15 @@ void testCoords(){
|
||||
}
|
||||
|
||||
#endif
|
||||
int main(){
|
||||
int main() {
|
||||
#if 1
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
//test4();
|
||||
// test4();
|
||||
test5();
|
||||
test6();
|
||||
#endif
|
||||
test7();
|
||||
//testCoords();
|
||||
// testCoords();
|
||||
}
|
||||
|
||||
@@ -11,32 +11,32 @@ using namespace TemplateEnum;
|
||||
|
||||
#include <math.h>
|
||||
|
||||
bool feq(double v1,double v2,double tol=1e-4){
|
||||
return fabs(v1-v2)<=tol;
|
||||
bool feq(double v1, double v2, double tol = 1e-4) {
|
||||
return fabs(v1 - v2) <= tol;
|
||||
}
|
||||
bool feq(RDGeom::Point3D p1,RDGeom::Point3D p2,double tol=1e-4){
|
||||
return feq(p1.x,p2.x,tol)&&feq(p1.y,p2.y,tol)&&feq(p1.z,p2.z,tol);
|
||||
bool feq(RDGeom::Point3D p1, RDGeom::Point3D p2, double tol = 1e-4) {
|
||||
return feq(p1.x, p2.x, tol) && feq(p1.y, p2.y, tol) && feq(p1.z, p2.z, tol);
|
||||
}
|
||||
|
||||
|
||||
int main(int argc,const char *argv[]){
|
||||
if(argc<3){
|
||||
std::cerr << " Usage: simple.exe <template.mol> [attach1.sdf, attach2.sdf, ...]" << std::endl;
|
||||
int main(int argc, const char *argv[]) {
|
||||
if (argc < 3) {
|
||||
std::cerr
|
||||
<< " Usage: simple.exe <template.mol> [attach1.sdf, attach2.sdf, ...]"
|
||||
<< std::endl;
|
||||
exit(-1);
|
||||
}
|
||||
std::vector<const char *>fileNames;
|
||||
for(int i=2;i<argc;i++){
|
||||
fileNames.push_back( argv[i] );
|
||||
std::vector<const char *> fileNames;
|
||||
for (int i = 2; i < argc; i++) {
|
||||
fileNames.push_back(argv[i]);
|
||||
}
|
||||
RWMOL_SPTR_VECT library=enumFromFiles(argv[1],fileNames);
|
||||
RWMOL_SPTR_VECT library = enumFromFiles(argv[1], fileNames);
|
||||
|
||||
std::cerr << "Created: " << library.size() << " compounds." << std::endl;
|
||||
for(int i=0;i<library.size();i++){
|
||||
for (int i = 0; i < library.size(); i++) {
|
||||
RWMOL_SPTR mol = library[i];
|
||||
std::cout << MolToMolBlock(mol.get(),false);
|
||||
std::cout << MolToMolBlock(mol.get(), false);
|
||||
std::cout << "$$$$" << std::endl;
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef __gen_IRDKit_h__
|
||||
#define __gen_IRDKit_h__
|
||||
|
||||
|
||||
#ifndef __gen_nsISupports_h__
|
||||
#include "nsISupports.h"
|
||||
#endif
|
||||
@@ -18,13 +17,15 @@
|
||||
/* starting interface: IRDMolecule */
|
||||
#define IRDMOLECULE_IID_STR "2fd55049-0125-48be-88e6-270b1b83a8a8"
|
||||
|
||||
#define IRDMOLECULE_IID \
|
||||
{0x2fd55049, 0x0125, 0x48be, \
|
||||
{ 0x88, 0xe6, 0x27, 0x0b, 0x1b, 0x83, 0xa8, 0xa8 }}
|
||||
#define IRDMOLECULE_IID \
|
||||
{ \
|
||||
0x2fd55049, 0x0125, 0x48be, { \
|
||||
0x88, 0xe6, 0x27, 0x0b, 0x1b, 0x83, 0xa8, 0xa8 \
|
||||
} \
|
||||
}
|
||||
|
||||
class NS_NO_VTABLE IRDMolecule : public nsISupports {
|
||||
public:
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(IRDMOLECULE_IID)
|
||||
|
||||
/* double GetMW (); */
|
||||
@@ -47,38 +48,56 @@ class NS_NO_VTABLE IRDMolecule : public nsISupports {
|
||||
|
||||
/* void Generate3DCoords (); */
|
||||
NS_IMETHOD Generate3DCoords(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
/* Use this macro when declaring classes that implement this interface. */
|
||||
#define NS_DECL_IRDMOLECULE \
|
||||
NS_IMETHOD GetMW(double *_retval); \
|
||||
NS_IMETHOD GetSmiles(char **_retval); \
|
||||
NS_IMETHOD GetMolBlock(char **_retval); \
|
||||
#define NS_DECL_IRDMOLECULE \
|
||||
NS_IMETHOD GetMW(double *_retval); \
|
||||
NS_IMETHOD GetSmiles(char **_retval); \
|
||||
NS_IMETHOD GetMolBlock(char **_retval); \
|
||||
NS_IMETHOD GetSmartsMatchCount(const char *smarts, PRUint32 *_retval); \
|
||||
NS_IMETHOD LogP(double *_retval); \
|
||||
NS_IMETHOD MR(double *_retval); \
|
||||
NS_IMETHOD Generate3DCoords(void);
|
||||
NS_IMETHOD LogP(double *_retval); \
|
||||
NS_IMETHOD MR(double *_retval); \
|
||||
NS_IMETHOD Generate3DCoords(void);
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||
#define NS_FORWARD_IRDMOLECULE(_to) \
|
||||
NS_IMETHOD GetMW(double *_retval) { return _to GetMW(_retval); } \
|
||||
NS_IMETHOD GetSmiles(char **_retval) { return _to GetSmiles(_retval); } \
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object. */
|
||||
#define NS_FORWARD_IRDMOLECULE(_to) \
|
||||
NS_IMETHOD GetMW(double *_retval) { return _to GetMW(_retval); } \
|
||||
NS_IMETHOD GetSmiles(char **_retval) { return _to GetSmiles(_retval); } \
|
||||
NS_IMETHOD GetMolBlock(char **_retval) { return _to GetMolBlock(_retval); } \
|
||||
NS_IMETHOD GetSmartsMatchCount(const char *smarts, PRUint32 *_retval) { return _to GetSmartsMatchCount(smarts, _retval); } \
|
||||
NS_IMETHOD LogP(double *_retval) { return _to LogP(_retval); } \
|
||||
NS_IMETHOD MR(double *_retval) { return _to MR(_retval); } \
|
||||
NS_IMETHOD Generate3DCoords(void) { return _to Generate3DCoords(); }
|
||||
NS_IMETHOD GetSmartsMatchCount(const char *smarts, PRUint32 *_retval) { \
|
||||
return _to GetSmartsMatchCount(smarts, _retval); \
|
||||
} \
|
||||
NS_IMETHOD LogP(double *_retval) { return _to LogP(_retval); } \
|
||||
NS_IMETHOD MR(double *_retval) { return _to MR(_retval); } \
|
||||
NS_IMETHOD Generate3DCoords(void) { return _to Generate3DCoords(); }
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDMOLECULE(_to) \
|
||||
NS_IMETHOD GetMW(double *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMW(_retval); } \
|
||||
NS_IMETHOD GetSmiles(char **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSmiles(_retval); } \
|
||||
NS_IMETHOD GetMolBlock(char **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetMolBlock(_retval); } \
|
||||
NS_IMETHOD GetSmartsMatchCount(const char *smarts, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->GetSmartsMatchCount(smarts, _retval); } \
|
||||
NS_IMETHOD LogP(double *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->LogP(_retval); } \
|
||||
NS_IMETHOD MR(double *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->MR(_retval); } \
|
||||
NS_IMETHOD Generate3DCoords(void) { return !_to ? NS_ERROR_NULL_POINTER : _to->Generate3DCoords(); }
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDMOLECULE(_to) \
|
||||
NS_IMETHOD GetMW(double *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->GetMW(_retval); \
|
||||
} \
|
||||
NS_IMETHOD GetSmiles(char **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->GetSmiles(_retval); \
|
||||
} \
|
||||
NS_IMETHOD GetMolBlock(char **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->GetMolBlock(_retval); \
|
||||
} \
|
||||
NS_IMETHOD GetSmartsMatchCount(const char *smarts, PRUint32 *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER \
|
||||
: _to->GetSmartsMatchCount(smarts, _retval); \
|
||||
} \
|
||||
NS_IMETHOD LogP(double *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->LogP(_retval); \
|
||||
} \
|
||||
NS_IMETHOD MR(double *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->MR(_retval); \
|
||||
} \
|
||||
NS_IMETHOD Generate3DCoords(void) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->Generate3DCoords(); \
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Use the code below as a template for the implementation class for this interface. */
|
||||
@@ -157,17 +176,18 @@ NS_IMETHODIMP _MYCLASS_::Generate3DCoords()
|
||||
/* End of implementation class template. */
|
||||
#endif
|
||||
|
||||
|
||||
/* starting interface: IRDMolSupplier */
|
||||
#define IRDMOLSUPPLIER_IID_STR "056a8da1-7820-41d7-b254-5ef7dd1693ce"
|
||||
|
||||
#define IRDMOLSUPPLIER_IID \
|
||||
{0x056a8da1, 0x7820, 0x41d7, \
|
||||
{ 0xb2, 0x54, 0x5e, 0xf7, 0xdd, 0x16, 0x93, 0xce }}
|
||||
#define IRDMOLSUPPLIER_IID \
|
||||
{ \
|
||||
0x056a8da1, 0x7820, 0x41d7, { \
|
||||
0xb2, 0x54, 0x5e, 0xf7, 0xdd, 0x16, 0x93, 0xce \
|
||||
} \
|
||||
}
|
||||
|
||||
class NS_NO_VTABLE IRDMolSupplier : public nsISupports {
|
||||
public:
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(IRDMOLSUPPLIER_IID)
|
||||
|
||||
/* boolean atEnd (); */
|
||||
@@ -175,23 +195,28 @@ class NS_NO_VTABLE IRDMolSupplier : public nsISupports {
|
||||
|
||||
/* IRDMolecule next (); */
|
||||
NS_IMETHOD Next(IRDMolecule **_retval) = 0;
|
||||
|
||||
};
|
||||
|
||||
/* Use this macro when declaring classes that implement this interface. */
|
||||
#define NS_DECL_IRDMOLSUPPLIER \
|
||||
#define NS_DECL_IRDMOLSUPPLIER \
|
||||
NS_IMETHOD AtEnd(PRBool *_retval); \
|
||||
NS_IMETHOD Next(IRDMolecule **_retval);
|
||||
NS_IMETHOD Next(IRDMolecule **_retval);
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||
#define NS_FORWARD_IRDMOLSUPPLIER(_to) \
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object. */
|
||||
#define NS_FORWARD_IRDMOLSUPPLIER(_to) \
|
||||
NS_IMETHOD AtEnd(PRBool *_retval) { return _to AtEnd(_retval); } \
|
||||
NS_IMETHOD Next(IRDMolecule **_retval) { return _to Next(_retval); }
|
||||
NS_IMETHOD Next(IRDMolecule **_retval) { return _to Next(_retval); }
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDMOLSUPPLIER(_to) \
|
||||
NS_IMETHOD AtEnd(PRBool *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->AtEnd(_retval); } \
|
||||
NS_IMETHOD Next(IRDMolecule **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Next(_retval); }
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDMOLSUPPLIER(_to) \
|
||||
NS_IMETHOD AtEnd(PRBool *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->AtEnd(_retval); \
|
||||
} \
|
||||
NS_IMETHOD Next(IRDMolecule **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->Next(_retval); \
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Use the code below as a template for the implementation class for this interface. */
|
||||
@@ -240,17 +265,18 @@ NS_IMETHODIMP _MYCLASS_::Next(IRDMolecule **_retval)
|
||||
/* End of implementation class template. */
|
||||
#endif
|
||||
|
||||
|
||||
/* starting interface: IRDKit */
|
||||
#define IRDKIT_IID_STR "bfb9acf3-9349-47ec-8984-f6f8e2f02f65"
|
||||
|
||||
#define IRDKIT_IID \
|
||||
{0xbfb9acf3, 0x9349, 0x47ec, \
|
||||
{ 0x89, 0x84, 0xf6, 0xf8, 0xe2, 0xf0, 0x2f, 0x65 }}
|
||||
#define IRDKIT_IID \
|
||||
{ \
|
||||
0xbfb9acf3, 0x9349, 0x47ec, { \
|
||||
0x89, 0x84, 0xf6, 0xf8, 0xe2, 0xf0, 0x2f, 0x65 \
|
||||
} \
|
||||
}
|
||||
|
||||
class NS_NO_VTABLE IRDKit : public nsISupports {
|
||||
public:
|
||||
|
||||
public:
|
||||
NS_DEFINE_STATIC_IID_ACCESSOR(IRDKIT_IID)
|
||||
|
||||
/* unsigned long strlen (in string arg); */
|
||||
@@ -263,30 +289,52 @@ class NS_NO_VTABLE IRDKit : public nsISupports {
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval) = 0;
|
||||
|
||||
/* IRDMolSupplier SupplierFromSDFile (in string fileName); */
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval) = 0;
|
||||
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName,
|
||||
IRDMolSupplier **_retval) = 0;
|
||||
};
|
||||
|
||||
/* Use this macro when declaring classes that implement this interface. */
|
||||
#define NS_DECL_IRDKIT \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval); \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval); \
|
||||
#define NS_DECL_IRDKIT \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval); \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval); \
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval); \
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval);
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval);
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object. */
|
||||
#define NS_FORWARD_IRDKIT(_to) \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval) { return _to Strlen(arg, _retval); } \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval) { return _to MolFromSmiles(smiles, _retval); } \
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval) { return _to MolFromMolBlock(molBlock, _retval); } \
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval) { return _to SupplierFromSDFile(fileName, _retval); }
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object. */
|
||||
#define NS_FORWARD_IRDKIT(_to) \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval) { \
|
||||
return _to Strlen(arg, _retval); \
|
||||
} \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval) { \
|
||||
return _to MolFromSmiles(smiles, _retval); \
|
||||
} \
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval) { \
|
||||
return _to MolFromMolBlock(molBlock, _retval); \
|
||||
} \
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, \
|
||||
IRDMolSupplier **_retval) { \
|
||||
return _to SupplierFromSDFile(fileName, _retval); \
|
||||
}
|
||||
|
||||
/* Use this macro to declare functions that forward the behavior of this interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDKIT(_to) \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->Strlen(arg, _retval); } \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->MolFromSmiles(smiles, _retval); } \
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->MolFromMolBlock(molBlock, _retval); } \
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval) { return !_to ? NS_ERROR_NULL_POINTER : _to->SupplierFromSDFile(fileName, _retval); }
|
||||
/* Use this macro to declare functions that forward the behavior of this
|
||||
* interface to another object in a safe way. */
|
||||
#define NS_FORWARD_SAFE_IRDKIT(_to) \
|
||||
NS_IMETHOD Strlen(const char *arg, PRUint32 *_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->Strlen(arg, _retval); \
|
||||
} \
|
||||
NS_IMETHOD MolFromSmiles(const char *smiles, IRDMolecule **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER : _to->MolFromSmiles(smiles, _retval); \
|
||||
} \
|
||||
NS_IMETHOD MolFromMolBlock(const char *molBlock, IRDMolecule **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER \
|
||||
: _to->MolFromMolBlock(molBlock, _retval); \
|
||||
} \
|
||||
NS_IMETHOD SupplierFromSDFile(const char *fileName, \
|
||||
IRDMolSupplier **_retval) { \
|
||||
return !_to ? NS_ERROR_NULL_POINTER \
|
||||
: _to->SupplierFromSDFile(fileName, _retval); \
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* Use the code below as a template for the implementation class for this interface. */
|
||||
@@ -347,5 +395,4 @@ NS_IMETHODIMP _MYCLASS_::SupplierFromSDFile(const char *fileName, IRDMolSupplier
|
||||
/* End of implementation class template. */
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* __gen_IRDKit_h__ */
|
||||
|
||||
@@ -8,27 +8,14 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(RDKitImpl);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(RDMolecule);
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR(RDMolSupplier);
|
||||
|
||||
static const nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "RDKit Interface",
|
||||
IRDKIT_IID,
|
||||
"@rationaldiscovery.com/RDKit/base",
|
||||
RDKitImplConstructor
|
||||
},
|
||||
{ "RDKit Molecule Interface",
|
||||
IRDMOLECULE_IID,
|
||||
"@rationaldiscovery.com/RDKit/molecule",
|
||||
RDMoleculeConstructor
|
||||
},
|
||||
{ "RDKit Molecule Supplier Interface",
|
||||
IRDMOLSUPPLIER_IID,
|
||||
"@rationaldiscovery.com/RDKit/molsupplier",
|
||||
RDMolSupplierConstructor
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
static const nsModuleComponentInfo components[] = {
|
||||
{"RDKit Interface", IRDKIT_IID, "@rationaldiscovery.com/RDKit/base",
|
||||
RDKitImplConstructor},
|
||||
{"RDKit Molecule Interface", IRDMOLECULE_IID,
|
||||
"@rationaldiscovery.com/RDKit/molecule", RDMoleculeConstructor},
|
||||
{"RDKit Molecule Supplier Interface", IRDMOLSUPPLIER_IID,
|
||||
"@rationaldiscovery.com/RDKit/molsupplier", RDMolSupplierConstructor},
|
||||
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE(nsRDKitModule, components);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -10,34 +10,26 @@
|
||||
/* Implementation file */
|
||||
NS_IMPL_ISUPPORTS1(RDKitImpl, IRDKit)
|
||||
|
||||
RDKitImpl::RDKitImpl()
|
||||
{
|
||||
/* member initializers and constructor code */
|
||||
}
|
||||
RDKitImpl::RDKitImpl() { /* member initializers and constructor code */ }
|
||||
|
||||
|
||||
RDKitImpl::~RDKitImpl()
|
||||
{
|
||||
/* destructor code */
|
||||
}
|
||||
RDKitImpl::~RDKitImpl() { /* destructor code */ }
|
||||
|
||||
/* unsigned long strlen (in string arg); */
|
||||
NS_IMETHODIMP RDKitImpl::Strlen(const char *arg, PRUint32 *_retval)
|
||||
{
|
||||
NS_IMETHODIMP RDKitImpl::Strlen(const char *arg, PRUint32 *_retval) {
|
||||
std::string text(arg);
|
||||
*_retval = text.size();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* IRDMolecule MolFromSmiles (in string smiles); */
|
||||
NS_IMETHODIMP RDKitImpl::MolFromSmiles(const char *smiles, IRDMolecule **_retval)
|
||||
{
|
||||
NS_IMETHODIMP RDKitImpl::MolFromSmiles(const char *smiles,
|
||||
IRDMolecule **_retval) {
|
||||
std::string smi(smiles);
|
||||
RDKit::ROMol *roMol = RDKit::SmilesToMol(smiles);
|
||||
if(!roMol) return NS_ERROR_FAILURE;
|
||||
if (!roMol) return NS_ERROR_FAILURE;
|
||||
|
||||
RDMolecule *mol = new RDMolecule(roMol);
|
||||
if(!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*_retval = static_cast<IRDMolecule *>(mol);
|
||||
|
||||
// FIX: does this leak?
|
||||
@@ -47,13 +39,13 @@ NS_IMETHODIMP RDKitImpl::MolFromSmiles(const char *smiles, IRDMolecule **_retval
|
||||
}
|
||||
|
||||
/* IRDMolecule MolFromMolBlock (in string molBlock); */
|
||||
NS_IMETHODIMP RDKitImpl::MolFromMolBlock(const char *molBlock, IRDMolecule **_retval)
|
||||
{
|
||||
NS_IMETHODIMP RDKitImpl::MolFromMolBlock(const char *molBlock,
|
||||
IRDMolecule **_retval) {
|
||||
RDKit::ROMol *roMol = RDKit::MolBlockToMol(std::string(molBlock));
|
||||
if(!roMol) return NS_ERROR_FAILURE;
|
||||
if (!roMol) return NS_ERROR_FAILURE;
|
||||
|
||||
RDMolecule *mol = new RDMolecule(roMol);
|
||||
if(!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*_retval = static_cast<IRDMolecule *>(mol);
|
||||
|
||||
// FIX: does this leak?
|
||||
@@ -62,14 +54,14 @@ NS_IMETHODIMP RDKitImpl::MolFromMolBlock(const char *molBlock, IRDMolecule **_re
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* IRDMolSupplier SupplierFromSDFile (in string fileName); */
|
||||
NS_IMETHODIMP RDKitImpl::SupplierFromSDFile(const char *fileName, IRDMolSupplier **_retval)
|
||||
{
|
||||
/* IRDMolSupplier SupplierFromSDFile (in string fileName); */
|
||||
NS_IMETHODIMP RDKitImpl::SupplierFromSDFile(const char *fileName,
|
||||
IRDMolSupplier **_retval) {
|
||||
RDKit::MolSupplier *sdSuppl = new RDKit::SDMolSupplier(std::string(fileName));
|
||||
if(!sdSuppl) return NS_ERROR_FAILURE;
|
||||
if (!sdSuppl) return NS_ERROR_FAILURE;
|
||||
|
||||
RDMolSupplier *suppl = new RDMolSupplier(sdSuppl);
|
||||
if(!suppl) return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!suppl) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*_retval = static_cast<IRDMolSupplier *>(suppl);
|
||||
|
||||
// FIX: does this leak?
|
||||
@@ -77,4 +69,3 @@ NS_IMETHODIMP RDKitImpl::SupplierFromSDFile(const char *fileName, IRDMolSupplier
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,18 +3,17 @@
|
||||
#include "IRDKit.h"
|
||||
|
||||
/* Header file */
|
||||
class RDKitImpl : public IRDKit
|
||||
{
|
||||
public:
|
||||
class RDKitImpl : public IRDKit {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IRDKIT
|
||||
|
||||
RDKitImpl();
|
||||
|
||||
private:
|
||||
private:
|
||||
~RDKitImpl();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/* additional members */
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -14,107 +14,100 @@
|
||||
|
||||
NS_IMPL_ISUPPORTS1(RDMolecule, IRDMolecule)
|
||||
|
||||
RDMolecule::~RDMolecule()
|
||||
{
|
||||
if(this->dp_mol){
|
||||
RDMolecule::~RDMolecule() {
|
||||
if (this->dp_mol) {
|
||||
delete dp_mol;
|
||||
dp_mol=0;
|
||||
}
|
||||
|
||||
dp_mol = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* double GetMW (); */
|
||||
NS_IMETHODIMP RDMolecule::GetMW(double *_retval)
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
RDKit::PeriodicTable *pt=RDKit::PeriodicTable::getTable();
|
||||
*_retval=0.0;
|
||||
for(RDKit::ROMol::AtomIterator atIt=dp_mol->beginAtoms();
|
||||
atIt!=dp_mol->endAtoms();atIt++){
|
||||
*_retval += (*atIt)->getMass()+(*atIt)->getNumImplicitHs()*pt->getAtomicWeight(1);
|
||||
NS_IMETHODIMP RDMolecule::GetMW(double *_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
RDKit::PeriodicTable *pt = RDKit::PeriodicTable::getTable();
|
||||
*_retval = 0.0;
|
||||
for (RDKit::ROMol::AtomIterator atIt = dp_mol->beginAtoms();
|
||||
atIt != dp_mol->endAtoms(); atIt++) {
|
||||
*_retval += (*atIt)->getMass() +
|
||||
(*atIt)->getNumImplicitHs() * pt->getAtomicWeight(1);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string GetSmiles (); */
|
||||
NS_IMETHODIMP RDMolecule::GetSmiles(char **_retval)
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
std::string smi=RDKit::MolToSmiles(*dp_mol);
|
||||
*_retval=(char *)nsMemory::Clone(smi.c_str(),sizeof(char)*(smi.size()+1));
|
||||
NS_IMETHODIMP RDMolecule::GetSmiles(char **_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
std::string smi = RDKit::MolToSmiles(*dp_mol);
|
||||
*_retval =
|
||||
(char *)nsMemory::Clone(smi.c_str(), sizeof(char) * (smi.size() + 1));
|
||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* unsigned long GetSmartsMatchCount (in string smarts); */
|
||||
NS_IMETHODIMP RDMolecule::GetSmartsMatchCount(const char *smarts, PRUint32 *_retval)
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
RDKit::ROMol *patt=RDKit::SmartsToMol(std::string(smarts));
|
||||
if(!patt) return NS_ERROR_FAILURE;
|
||||
NS_IMETHODIMP RDMolecule::GetSmartsMatchCount(const char *smarts,
|
||||
PRUint32 *_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
RDKit::ROMol *patt = RDKit::SmartsToMol(std::string(smarts));
|
||||
if (!patt) return NS_ERROR_FAILURE;
|
||||
|
||||
std::vector<RDKit::MatchVectType> matches;
|
||||
int res=RDKit::SubstructMatch(dp_mol,patt,matches);
|
||||
int res = RDKit::SubstructMatch(dp_mol, patt, matches);
|
||||
*_retval = res;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* double LogP (); */
|
||||
NS_IMETHODIMP RDMolecule::LogP(double *_retval)
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
NS_IMETHODIMP RDMolecule::LogP(double *_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
double logp;
|
||||
if(dp_mol->hasProp(common_properties::_CrippenLogP)) {
|
||||
dp_mol->getProp(common_properties::_CrippenLogP,logp);
|
||||
if (dp_mol->hasProp(common_properties::_CrippenLogP)) {
|
||||
dp_mol->getProp(common_properties::_CrippenLogP, logp);
|
||||
} else {
|
||||
double mr;
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(dp_mol,logp,mr);
|
||||
dp_mol->setProp(common_properties::_CrippenLogP,logp,true);
|
||||
dp_mol->setProp(common_properties::_CrippenMR,mr,true);
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(dp_mol, logp, mr);
|
||||
dp_mol->setProp(common_properties::_CrippenLogP, logp, true);
|
||||
dp_mol->setProp(common_properties::_CrippenMR, mr, true);
|
||||
}
|
||||
*_retval=logp;
|
||||
*_retval = logp;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* double MR (); */
|
||||
NS_IMETHODIMP RDMolecule::MR(double *_retval)
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
NS_IMETHODIMP RDMolecule::MR(double *_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
double mr;
|
||||
if(dp_mol->hasProp(common_properties::_CrippenMR)) {
|
||||
dp_mol->getProp(common_properties::_CrippenMR,mr);
|
||||
if (dp_mol->hasProp(common_properties::_CrippenMR)) {
|
||||
dp_mol->getProp(common_properties::_CrippenMR, mr);
|
||||
} else {
|
||||
double logp;
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(dp_mol,logp,mr);
|
||||
dp_mol->setProp(common_properties::_CrippenLogP,logp,true);
|
||||
dp_mol->setProp(common_properties::_CrippenMR,mr,true);
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(dp_mol, logp, mr);
|
||||
dp_mol->setProp(common_properties::_CrippenLogP, logp, true);
|
||||
dp_mol->setProp(common_properties::_CrippenMR, mr, true);
|
||||
}
|
||||
*_retval=mr;
|
||||
*_retval = mr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* string GetMolBlock (); */
|
||||
NS_IMETHODIMP RDMolecule::GetMolBlock(char **_retval)
|
||||
{
|
||||
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
std::string molB=RDKit::MolToMolBlock(dp_mol);
|
||||
*_retval=(char *)nsMemory::Clone(molB.c_str(),sizeof(char)*(molB.size()+1));
|
||||
NS_IMETHODIMP RDMolecule::GetMolBlock(char **_retval) {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
std::string molB = RDKit::MolToMolBlock(dp_mol);
|
||||
*_retval =
|
||||
(char *)nsMemory::Clone(molB.c_str(), sizeof(char) * (molB.size() + 1));
|
||||
return *_retval ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
/* void Generate3DCoords (); */
|
||||
NS_IMETHODIMP RDMolecule::Generate3DCoords()
|
||||
{
|
||||
if(!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
bool embedded=RDKit::DGeomHelpers::EmbedMolecule(*dp_mol);
|
||||
if(!embedded) return NS_ERROR_FAILURE;
|
||||
|
||||
ForceFields::ForceField *ff=RDKit::UFF::constructForceField(dp_mol);
|
||||
if(!ff) return NS_ERROR_FAILURE;
|
||||
NS_IMETHODIMP RDMolecule::Generate3DCoords() {
|
||||
if (!dp_mol) return NS_ERROR_NOT_INITIALIZED;
|
||||
bool embedded = RDKit::DGeomHelpers::EmbedMolecule(*dp_mol);
|
||||
if (!embedded) return NS_ERROR_FAILURE;
|
||||
|
||||
ForceFields::ForceField *ff = RDKit::UFF::constructForceField(dp_mol);
|
||||
if (!ff) return NS_ERROR_FAILURE;
|
||||
ff->initialize();
|
||||
int needsMore=ff->minimize();
|
||||
int needsMore = ff->minimize();
|
||||
delete ff;
|
||||
if(needsMore) return NS_ERROR_FAILURE;
|
||||
if (needsMore) return NS_ERROR_FAILURE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
#include "IRDKit.h"
|
||||
|
||||
namespace RDKit {
|
||||
class ROMol;
|
||||
class ROMol;
|
||||
}
|
||||
|
||||
class RDMolecule : public IRDMolecule
|
||||
{
|
||||
public:
|
||||
class RDMolecule : public IRDMolecule {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IRDMOLECULE
|
||||
|
||||
RDMolecule() : dp_mol(0) {};
|
||||
RDMolecule(RDKit::ROMol *mol) : dp_mol(mol) {};
|
||||
RDMolecule() : dp_mol(0){};
|
||||
RDMolecule(RDKit::ROMol *mol) : dp_mol(mol){};
|
||||
RDKit::ROMol *dp_mol;
|
||||
private:
|
||||
|
||||
private:
|
||||
~RDMolecule();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/* additional members */
|
||||
};
|
||||
|
||||
|
||||
@@ -7,33 +7,29 @@
|
||||
|
||||
NS_IMPL_ISUPPORTS1(RDMolSupplier, IRDMolSupplier)
|
||||
|
||||
RDMolSupplier::~RDMolSupplier()
|
||||
{
|
||||
if(this->dp_suppl){
|
||||
RDMolSupplier::~RDMolSupplier() {
|
||||
if (this->dp_suppl) {
|
||||
delete dp_suppl;
|
||||
dp_suppl=0;
|
||||
}
|
||||
|
||||
dp_suppl = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* boolean atEnd (); */
|
||||
NS_IMETHODIMP RDMolSupplier::AtEnd(PRBool *_retval)
|
||||
{
|
||||
if(!dp_suppl) return NS_ERROR_NOT_INITIALIZED;
|
||||
*_retval=dp_suppl->atEnd();
|
||||
NS_IMETHODIMP RDMolSupplier::AtEnd(PRBool *_retval) {
|
||||
if (!dp_suppl) return NS_ERROR_NOT_INITIALIZED;
|
||||
*_retval = dp_suppl->atEnd();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* IRDMolecule next (); */
|
||||
NS_IMETHODIMP RDMolSupplier::Next(IRDMolecule **_retval)
|
||||
{
|
||||
if(!dp_suppl) return NS_ERROR_NOT_INITIALIZED;
|
||||
if(dp_suppl->atEnd()) return NS_BASE_STREAM_CLOSED;
|
||||
RDKit::ROMol *roMol=dp_suppl->next();
|
||||
if(!roMol) return NS_ERROR_UNEXPECTED;
|
||||
NS_IMETHODIMP RDMolSupplier::Next(IRDMolecule **_retval) {
|
||||
if (!dp_suppl) return NS_ERROR_NOT_INITIALIZED;
|
||||
if (dp_suppl->atEnd()) return NS_BASE_STREAM_CLOSED;
|
||||
RDKit::ROMol *roMol = dp_suppl->next();
|
||||
if (!roMol) return NS_ERROR_UNEXPECTED;
|
||||
|
||||
RDMolecule *mol = new RDMolecule(roMol);
|
||||
if(!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
if (!mol) return NS_ERROR_OUT_OF_MEMORY;
|
||||
*_retval = static_cast<IRDMolecule *>(mol);
|
||||
|
||||
// FIX: does this leak?
|
||||
|
||||
@@ -3,23 +3,23 @@
|
||||
#include "IRDKit.h"
|
||||
|
||||
namespace RDKit {
|
||||
class ROMol;
|
||||
class MolSupplier;
|
||||
class ROMol;
|
||||
class MolSupplier;
|
||||
}
|
||||
|
||||
class RDMolSupplier : public IRDMolSupplier
|
||||
{
|
||||
public:
|
||||
class RDMolSupplier : public IRDMolSupplier {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IRDMOLSUPPLIER
|
||||
|
||||
RDMolSupplier() : dp_suppl(0) {};
|
||||
RDMolSupplier(RDKit::MolSupplier *suppl) : dp_suppl(suppl) {};
|
||||
RDMolSupplier() : dp_suppl(0){};
|
||||
RDMolSupplier(RDKit::MolSupplier *suppl) : dp_suppl(suppl){};
|
||||
RDKit::MolSupplier *dp_suppl;
|
||||
private:
|
||||
|
||||
private:
|
||||
~RDMolSupplier();
|
||||
|
||||
protected:
|
||||
protected:
|
||||
/* additional members */
|
||||
};
|
||||
|
||||
|
||||
@@ -22,180 +22,180 @@
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
using namespace RDKit;
|
||||
|
||||
std::string MolToSVG(const ROMol &mol){
|
||||
std::vector<int> drawing=RDKit::Drawing::MolToDrawing(mol);
|
||||
std::string svg=RDKit::Drawing::DrawingToSVG(drawing);
|
||||
std::string MolToSVG(const ROMol &mol) {
|
||||
std::vector<int> drawing = RDKit::Drawing::MolToDrawing(mol);
|
||||
std::string svg = RDKit::Drawing::DrawingToSVG(drawing);
|
||||
return svg;
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_CAIRO
|
||||
void MolToCairo(const ROMol &mol,cairo_t *cr,int width,int height){
|
||||
PRECONDITION(cr,"no context");
|
||||
PRECONDITION(width>0 && height>0,"bad dimensions");
|
||||
std::vector<int> drawing=RDKit::Drawing::MolToDrawing(mol);
|
||||
RDKit::Drawing::DrawingToCairo(drawing,cr,width,height);
|
||||
void MolToCairo(const ROMol &mol, cairo_t *cr, int width, int height) {
|
||||
PRECONDITION(cr, "no context");
|
||||
PRECONDITION(width > 0 && height > 0, "bad dimensions");
|
||||
std::vector<int> drawing = RDKit::Drawing::MolToDrawing(mol);
|
||||
RDKit::Drawing::DrawingToCairo(drawing, cr, width, height);
|
||||
}
|
||||
#endif
|
||||
|
||||
void DrawDemo(){
|
||||
|
||||
void DrawDemo() {
|
||||
#if 1
|
||||
{
|
||||
RWMol *mol=SmilesToMol("c1c(C#N)cccc1C~C2CC2");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol = SmilesToMol("c1c(C#N)cccc1C~C2CC2");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol =
|
||||
SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah3.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCCCCCC(CCCCCCCCCCC(CCCCCCCCC)(CCCCCCCCCC)CCCCCC)CCCCCCCCCCCCCCCCCCCCCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol = SmilesToMol(
|
||||
"[Mg]c1c(C#N)cc(C(=O)NCCCCCC(CCCCCCCCCCC(CCCCCCCCC)(CCCCCCCCCC)CCCCCC)"
|
||||
"CCCCCCCCCCCCCCCCCCCCCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah4.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("BrO");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol = SmilesToMol("BrO");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah2.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("BrC(O)(Cl)N");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol = SmilesToMol("BrC(O)(Cl)N");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah5.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[14NH2+]=[14NH2+]");
|
||||
std::string svg=MolToSVG(*mol);
|
||||
RWMol *mol = SmilesToMol("[14NH2+]=[14NH2+]");
|
||||
std::string svg = MolToSVG(*mol);
|
||||
std::ofstream ostr("blah6.svg");
|
||||
ostr<<svg<<std::endl;
|
||||
ostr << svg << std::endl;
|
||||
delete mol;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
#ifdef USE_CAIRO
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
RWMol *mol =
|
||||
SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 200, 200);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,200,200);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 200, 200);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 200, 200);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol1.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol1.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("c1c[12cH]ccn1");
|
||||
RWMol *mol = SmilesToMol("c1c[12cH]ccn1");
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol2.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol2.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("Nc1ccc(cc1)S(=O)(=O)c1ccc(N)cc1");
|
||||
RWMol *mol = SmilesToMol("Nc1ccc(cc1)S(=O)(=O)c1ccc(N)cc1");
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol3.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol3.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("Nccc(CCO)n",0,false);
|
||||
RWMol *mol = SmilesToMol("Nccc(CCO)n", 0, false);
|
||||
mol->updatePropertyCache();
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol4.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol4.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("N~ccc(CCO)n",0,false);
|
||||
RWMol *mol = SmilesToMol("N~ccc(CCO)n", 0, false);
|
||||
mol->updatePropertyCache();
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol5.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol5.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("BrO",0,false);
|
||||
RWMol *mol = SmilesToMol("BrO", 0, false);
|
||||
mol->updatePropertyCache();
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol6.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol6.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[Mg]c1c(C#N)cc(C(=O)NCCCCCC(CCCCCCCCCCC(CCCCCCCCC)(CCCCCCCCCC)CCCCCC)CCCCCCCCCCCCCCCCCCCCCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
RWMol *mol = SmilesToMol(
|
||||
"[Mg]c1c(C#N)cc(C(=O)NCCCCCC(CCCCCCCCCCC(CCCCCCCCC)(CCCCCCCCCC)CCCCCC)"
|
||||
"CCCCCCCCCCCCCCCCCCCCCc2sc([NH3+])c([NH3+])c2)cc1");
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol7.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol7.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
{
|
||||
RWMol *mol=SmilesToMol("[NH3+][NH3+]",0,false);
|
||||
RWMol *mol = SmilesToMol("[NH3+][NH3+]", 0, false);
|
||||
mol->updatePropertyCache();
|
||||
cairo_surface_t *surface =
|
||||
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create (surface);
|
||||
MolToCairo(*mol,cr,300,300);
|
||||
cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 300, 300);
|
||||
cairo_t *cr = cairo_create(surface);
|
||||
MolToCairo(*mol, cr, 300, 300);
|
||||
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_write_to_png (surface, "mol8.png");
|
||||
cairo_surface_destroy (surface);
|
||||
cairo_destroy(cr);
|
||||
cairo_surface_write_to_png(surface, "mol8.png");
|
||||
cairo_surface_destroy(surface);
|
||||
delete mol;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
RDLog::InitLogs();
|
||||
DrawDemo();
|
||||
}
|
||||
|
||||
@@ -30,218 +30,217 @@
|
||||
|
||||
using namespace RDKit;
|
||||
|
||||
void BuildSimpleMolecule(){
|
||||
void BuildSimpleMolecule() {
|
||||
// build the molecule: C/C=C\C
|
||||
RWMol *mol=new RWMol();
|
||||
RWMol *mol = new RWMol();
|
||||
|
||||
// add atoms and bonds:
|
||||
mol->addAtom(new Atom(6)); // atom 0
|
||||
mol->addAtom(new Atom(6)); // atom 1
|
||||
mol->addAtom(new Atom(6)); // atom 2
|
||||
mol->addAtom(new Atom(6)); // atom 3
|
||||
mol->addBond(0,1,Bond::SINGLE); // bond 0
|
||||
mol->addBond(1,2,Bond::DOUBLE); // bond 1
|
||||
mol->addBond(2,3,Bond::SINGLE); // bond 2
|
||||
mol->addAtom(new Atom(6)); // atom 0
|
||||
mol->addAtom(new Atom(6)); // atom 1
|
||||
mol->addAtom(new Atom(6)); // atom 2
|
||||
mol->addAtom(new Atom(6)); // atom 3
|
||||
mol->addBond(0, 1, Bond::SINGLE); // bond 0
|
||||
mol->addBond(1, 2, Bond::DOUBLE); // bond 1
|
||||
mol->addBond(2, 3, Bond::SINGLE); // bond 2
|
||||
// setup the stereochem:
|
||||
mol->getBondWithIdx(0)->setBondDir(Bond::ENDUPRIGHT);
|
||||
mol->getBondWithIdx(2)->setBondDir(Bond::ENDDOWNRIGHT);
|
||||
|
||||
|
||||
// do the chemistry perception:
|
||||
RDKit::MolOps::sanitizeMol(*mol);
|
||||
|
||||
// Get the canonical SMILES, include stereochemistry:
|
||||
std::string smiles;
|
||||
smiles = MolToSmiles(*(static_cast<ROMol *>(mol)),true);
|
||||
BOOST_LOG(rdInfoLog)<<" sample 1 SMILES: " <<smiles<<std::endl;
|
||||
smiles = MolToSmiles(*(static_cast<ROMol *>(mol)), true);
|
||||
BOOST_LOG(rdInfoLog) << " sample 1 SMILES: " << smiles << std::endl;
|
||||
}
|
||||
|
||||
void WorkWithRingInfo(){
|
||||
void WorkWithRingInfo() {
|
||||
// use a more complicated molecule to demonstrate querying about
|
||||
// ring information
|
||||
ROMol *mol=SmilesToMol("OC1CCC2C1CCCC2");
|
||||
ROMol *mol = SmilesToMol("OC1CCC2C1CCCC2");
|
||||
// the molecule from SmilesToMol is already sanitized, so we don't
|
||||
// need to worry about that.
|
||||
|
||||
// work with ring information
|
||||
RingInfo *ringInfo = mol->getRingInfo();
|
||||
|
||||
TEST_ASSERT(ringInfo->numRings()==2);
|
||||
TEST_ASSERT(ringInfo->numRings() == 2);
|
||||
|
||||
// can ask how many rings an atom is in:
|
||||
TEST_ASSERT(ringInfo->numAtomRings(0)==0);
|
||||
TEST_ASSERT(ringInfo->numAtomRings(1)==1);
|
||||
TEST_ASSERT(ringInfo->numAtomRings(4)==2);
|
||||
TEST_ASSERT(ringInfo->numAtomRings(0) == 0);
|
||||
TEST_ASSERT(ringInfo->numAtomRings(1) == 1);
|
||||
TEST_ASSERT(ringInfo->numAtomRings(4) == 2);
|
||||
// same with bonds:
|
||||
TEST_ASSERT(ringInfo->numBondRings(0)==0);
|
||||
TEST_ASSERT(ringInfo->numBondRings(1)==1);
|
||||
TEST_ASSERT(ringInfo->numBondRings(0) == 0);
|
||||
TEST_ASSERT(ringInfo->numBondRings(1) == 1);
|
||||
|
||||
// can check if an atom is in a ring of a particular size:
|
||||
TEST_ASSERT(!ringInfo->isAtomInRingOfSize(0,5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(1,5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(4,5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(4,6));
|
||||
TEST_ASSERT(!ringInfo->isAtomInRingOfSize(0, 5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(1, 5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(4, 5));
|
||||
TEST_ASSERT(ringInfo->isAtomInRingOfSize(4, 6));
|
||||
// same with bonds:
|
||||
TEST_ASSERT(!ringInfo->isBondInRingOfSize(0,5));
|
||||
TEST_ASSERT(ringInfo->isBondInRingOfSize(1,5));
|
||||
TEST_ASSERT(!ringInfo->isBondInRingOfSize(0, 5));
|
||||
TEST_ASSERT(ringInfo->isBondInRingOfSize(1, 5));
|
||||
|
||||
// can also get the full list of rings as atom indices:
|
||||
VECT_INT_VECT atomRings; // VECT_INT_VECT is vector< vector<int> >
|
||||
atomRings=ringInfo->atomRings();
|
||||
TEST_ASSERT(atomRings.size()==2);
|
||||
TEST_ASSERT(atomRings[0].size()==5);
|
||||
TEST_ASSERT(atomRings[1].size()==6);
|
||||
VECT_INT_VECT atomRings; // VECT_INT_VECT is vector< vector<int> >
|
||||
atomRings = ringInfo->atomRings();
|
||||
TEST_ASSERT(atomRings.size() == 2);
|
||||
TEST_ASSERT(atomRings[0].size() == 5);
|
||||
TEST_ASSERT(atomRings[1].size() == 6);
|
||||
// this sort is just here for test/demo purposes:
|
||||
std::sort(atomRings[0].begin(),atomRings[0].end());
|
||||
TEST_ASSERT(atomRings[0][0]==1);
|
||||
TEST_ASSERT(atomRings[0][1]==2);
|
||||
TEST_ASSERT(atomRings[0][2]==3);
|
||||
TEST_ASSERT(atomRings[0][3]==4);
|
||||
TEST_ASSERT(atomRings[0][4]==5);
|
||||
std::sort(atomRings[0].begin(), atomRings[0].end());
|
||||
TEST_ASSERT(atomRings[0][0] == 1);
|
||||
TEST_ASSERT(atomRings[0][1] == 2);
|
||||
TEST_ASSERT(atomRings[0][2] == 3);
|
||||
TEST_ASSERT(atomRings[0][3] == 4);
|
||||
TEST_ASSERT(atomRings[0][4] == 5);
|
||||
// same with bonds:
|
||||
VECT_INT_VECT bondRings; // VECT_INT_VECT is vector< vector<int> >
|
||||
bondRings=ringInfo->bondRings();
|
||||
TEST_ASSERT(bondRings.size()==2);
|
||||
TEST_ASSERT(bondRings[0].size()==5);
|
||||
TEST_ASSERT(bondRings[1].size()==6);
|
||||
VECT_INT_VECT bondRings; // VECT_INT_VECT is vector< vector<int> >
|
||||
bondRings = ringInfo->bondRings();
|
||||
TEST_ASSERT(bondRings.size() == 2);
|
||||
TEST_ASSERT(bondRings[0].size() == 5);
|
||||
TEST_ASSERT(bondRings[1].size() == 6);
|
||||
// the same trick played above with the contents of each ring
|
||||
// can be played, but we won't
|
||||
|
||||
// count the number of rings of size 5:
|
||||
unsigned int nRingsSize5=0;
|
||||
for(VECT_INT_VECT_CI ringIt=atomRings.begin();
|
||||
ringIt!=atomRings.end();++ringIt){
|
||||
if(ringIt->size()==5) nRingsSize5++;
|
||||
unsigned int nRingsSize5 = 0;
|
||||
for (VECT_INT_VECT_CI ringIt = atomRings.begin(); ringIt != atomRings.end();
|
||||
++ringIt) {
|
||||
if (ringIt->size() == 5) nRingsSize5++;
|
||||
}
|
||||
TEST_ASSERT(nRingsSize5==1);
|
||||
TEST_ASSERT(nRingsSize5 == 1);
|
||||
delete mol;
|
||||
|
||||
// count the number of atoms in 5-rings where all the atoms
|
||||
// are aromatic:
|
||||
mol=SmilesToMol("C1CC2=C(C1)C1=C(NC3=C1C=CC=C3)C=C2");
|
||||
mol = SmilesToMol("C1CC2=C(C1)C1=C(NC3=C1C=CC=C3)C=C2");
|
||||
ringInfo = mol->getRingInfo();
|
||||
atomRings=ringInfo->atomRings();
|
||||
atomRings = ringInfo->atomRings();
|
||||
|
||||
unsigned int nMatchingAtoms=0;
|
||||
for(VECT_INT_VECT_CI ringIt=atomRings.begin();
|
||||
ringIt!=atomRings.end();++ringIt){
|
||||
if(ringIt->size()!=5){
|
||||
unsigned int nMatchingAtoms = 0;
|
||||
for (VECT_INT_VECT_CI ringIt = atomRings.begin(); ringIt != atomRings.end();
|
||||
++ringIt) {
|
||||
if (ringIt->size() != 5) {
|
||||
continue;
|
||||
}
|
||||
bool isAromatic=true;
|
||||
for(INT_VECT_CI atomIt=ringIt->begin();
|
||||
atomIt!=ringIt->end();++atomIt){
|
||||
if(!mol->getAtomWithIdx(*atomIt)->getIsAromatic()){
|
||||
isAromatic=false;
|
||||
bool isAromatic = true;
|
||||
for (INT_VECT_CI atomIt = ringIt->begin(); atomIt != ringIt->end();
|
||||
++atomIt) {
|
||||
if (!mol->getAtomWithIdx(*atomIt)->getIsAromatic()) {
|
||||
isAromatic = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isAromatic){
|
||||
nMatchingAtoms+=5;
|
||||
if (isAromatic) {
|
||||
nMatchingAtoms += 5;
|
||||
}
|
||||
}
|
||||
TEST_ASSERT(nMatchingAtoms==5);
|
||||
TEST_ASSERT(nMatchingAtoms == 5);
|
||||
delete mol;
|
||||
|
||||
// count the number of rings where all the bonds
|
||||
// are aromatic.
|
||||
mol=SmilesToMol("c1cccc2c1CCCC2");
|
||||
mol = SmilesToMol("c1cccc2c1CCCC2");
|
||||
ringInfo = mol->getRingInfo();
|
||||
bondRings=ringInfo->bondRings();
|
||||
|
||||
unsigned int nAromaticRings=0;
|
||||
for(VECT_INT_VECT_CI ringIt=bondRings.begin();
|
||||
ringIt!=bondRings.end();++ringIt){
|
||||
bool isAromatic=true;
|
||||
for(INT_VECT_CI bondIt=ringIt->begin();
|
||||
bondIt!=ringIt->end();++bondIt){
|
||||
if(!mol->getBondWithIdx(*bondIt)->getIsAromatic()){
|
||||
isAromatic=false;
|
||||
bondRings = ringInfo->bondRings();
|
||||
|
||||
unsigned int nAromaticRings = 0;
|
||||
for (VECT_INT_VECT_CI ringIt = bondRings.begin(); ringIt != bondRings.end();
|
||||
++ringIt) {
|
||||
bool isAromatic = true;
|
||||
for (INT_VECT_CI bondIt = ringIt->begin(); bondIt != ringIt->end();
|
||||
++bondIt) {
|
||||
if (!mol->getBondWithIdx(*bondIt)->getIsAromatic()) {
|
||||
isAromatic = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(isAromatic) nAromaticRings++;
|
||||
if (isAromatic) nAromaticRings++;
|
||||
}
|
||||
TEST_ASSERT(nAromaticRings==1);
|
||||
TEST_ASSERT(nAromaticRings == 1);
|
||||
delete mol;
|
||||
}
|
||||
|
||||
void WorkWithSmarts(){
|
||||
void WorkWithSmarts() {
|
||||
// demonstrate the use of substructure searching
|
||||
ROMol *mol=SmilesToMol("ClCC=CCC");
|
||||
ROMol *mol = SmilesToMol("ClCC=CCC");
|
||||
// a simple SMARTS pattern for rotatable bonds:
|
||||
ROMol *pattern=SmartsToMol("[!$(*#*)&!D1]-&!@[!$(*#*)&!D1]");
|
||||
ROMol *pattern = SmartsToMol("[!$(*#*)&!D1]-&!@[!$(*#*)&!D1]");
|
||||
|
||||
std::vector<MatchVectType> matches;
|
||||
unsigned int nMatches;
|
||||
nMatches=SubstructMatch(*mol,*pattern,matches);
|
||||
TEST_ASSERT(nMatches==2);
|
||||
TEST_ASSERT(matches.size()==2); // <- there are two rotatable bonds
|
||||
nMatches = SubstructMatch(*mol, *pattern, matches);
|
||||
TEST_ASSERT(nMatches == 2);
|
||||
TEST_ASSERT(matches.size() == 2); // <- there are two rotatable bonds
|
||||
|
||||
// a MatchVect is a vector of std::pairs with (patternIdx, molIdx):
|
||||
TEST_ASSERT(matches[0].size()==2);
|
||||
TEST_ASSERT(matches[0][0].first==0);
|
||||
TEST_ASSERT(matches[0][0].second==1);
|
||||
TEST_ASSERT(matches[0][1].first==1);
|
||||
TEST_ASSERT(matches[0][1].second==2);
|
||||
TEST_ASSERT(matches[0].size() == 2);
|
||||
TEST_ASSERT(matches[0][0].first == 0);
|
||||
TEST_ASSERT(matches[0][0].second == 1);
|
||||
TEST_ASSERT(matches[0][1].first == 1);
|
||||
TEST_ASSERT(matches[0][1].second == 2);
|
||||
|
||||
delete pattern;
|
||||
delete mol;
|
||||
}
|
||||
|
||||
void DepictDemo(){
|
||||
void DepictDemo() {
|
||||
// demonstrate the use of the depiction-generation code2D coordinates:
|
||||
ROMol *mol=SmilesToMol("ClCC=CCC");
|
||||
ROMol *mol = SmilesToMol("ClCC=CCC");
|
||||
|
||||
// generate the 2D coordinates:
|
||||
RDDepict::compute2DCoords(*mol);
|
||||
|
||||
// generate a mol block (could also go to a file):
|
||||
std::string molBlock=MolToMolBlock(*mol);
|
||||
BOOST_LOG(rdInfoLog)<<molBlock;
|
||||
std::string molBlock = MolToMolBlock(*mol);
|
||||
BOOST_LOG(rdInfoLog) << molBlock;
|
||||
|
||||
delete mol;
|
||||
}
|
||||
|
||||
|
||||
void CleanupMolecule(){
|
||||
void CleanupMolecule() {
|
||||
// an example of doing some cleaning up of a molecule before
|
||||
// calling the sanitizeMol function()
|
||||
|
||||
|
||||
// build: C1CC1C(:O):O
|
||||
RWMol *mol=new RWMol();
|
||||
RWMol *mol = new RWMol();
|
||||
|
||||
// add atoms and bonds:
|
||||
mol->addAtom(new Atom(6)); // atom 0
|
||||
mol->addAtom(new Atom(6)); // atom 1
|
||||
mol->addAtom(new Atom(6)); // atom 2
|
||||
mol->addAtom(new Atom(6)); // atom 3
|
||||
mol->addAtom(new Atom(8)); // atom 4
|
||||
mol->addAtom(new Atom(8)); // atom 5
|
||||
mol->addBond(3,4,Bond::AROMATIC); // bond 0
|
||||
mol->addBond(3,5,Bond::AROMATIC); // bond 1
|
||||
mol->addBond(3,2,Bond::SINGLE); // bond 2
|
||||
mol->addBond(2,1,Bond::SINGLE); // bond 3
|
||||
mol->addBond(1,0,Bond::SINGLE); // bond 4
|
||||
mol->addBond(0,2,Bond::SINGLE); // bond 5
|
||||
mol->addAtom(new Atom(6)); // atom 0
|
||||
mol->addAtom(new Atom(6)); // atom 1
|
||||
mol->addAtom(new Atom(6)); // atom 2
|
||||
mol->addAtom(new Atom(6)); // atom 3
|
||||
mol->addAtom(new Atom(8)); // atom 4
|
||||
mol->addAtom(new Atom(8)); // atom 5
|
||||
mol->addBond(3, 4, Bond::AROMATIC); // bond 0
|
||||
mol->addBond(3, 5, Bond::AROMATIC); // bond 1
|
||||
mol->addBond(3, 2, Bond::SINGLE); // bond 2
|
||||
mol->addBond(2, 1, Bond::SINGLE); // bond 3
|
||||
mol->addBond(1, 0, Bond::SINGLE); // bond 4
|
||||
mol->addBond(0, 2, Bond::SINGLE); // bond 5
|
||||
|
||||
// instead of calling sanitize mol, which would generate an error,
|
||||
// we'll perceive the rings, then take care of aromatic bonds
|
||||
// that aren't in a ring, then sanitize:
|
||||
MolOps::findSSSR(*mol);
|
||||
for(ROMol::BondIterator bondIt=mol->beginBonds();
|
||||
bondIt!=mol->endBonds();++bondIt){
|
||||
if( ((*bondIt)->getIsAromatic() ||
|
||||
(*bondIt)->getBondType()==Bond::AROMATIC)
|
||||
&& !mol->getRingInfo()->numBondRings((*bondIt)->getIdx()) ){
|
||||
for (ROMol::BondIterator bondIt = mol->beginBonds();
|
||||
bondIt != mol->endBonds(); ++bondIt) {
|
||||
if (((*bondIt)->getIsAromatic() ||
|
||||
(*bondIt)->getBondType() == Bond::AROMATIC) &&
|
||||
!mol->getRingInfo()->numBondRings((*bondIt)->getIdx())) {
|
||||
// remove the aromatic flag on the bond:
|
||||
(*bondIt)->setIsAromatic(false);
|
||||
// and cleanup its attached atoms as well (they were
|
||||
// also marked aromatic when the bond was added)
|
||||
(*bondIt)->getBeginAtom()->setIsAromatic(false);
|
||||
(*bondIt)->getEndAtom()->setIsAromatic(false);
|
||||
|
||||
|
||||
// NOTE: this isn't really reasonable:
|
||||
(*bondIt)->setBondType(Bond::SINGLE);
|
||||
(*bondIt)->setBondType(Bond::SINGLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,20 +249,20 @@ void CleanupMolecule(){
|
||||
|
||||
// Get the canonical SMILES, include stereochemistry:
|
||||
std::string smiles;
|
||||
smiles = MolToSmiles(*(static_cast<ROMol *>(mol)),true);
|
||||
BOOST_LOG(rdInfoLog)<<" fixed SMILES: " <<smiles<<std::endl;
|
||||
smiles = MolToSmiles(*(static_cast<ROMol *>(mol)), true);
|
||||
BOOST_LOG(rdInfoLog) << " fixed SMILES: " << smiles << std::endl;
|
||||
}
|
||||
|
||||
void ReactionDemo(){
|
||||
void ReactionDemo() {
|
||||
// reaction smarts for a crude amide-bond formation definition:
|
||||
std::string sma="[C:1](=[O:2])[OH].[N:3]>>[O:2]=[C:1][N:3]";
|
||||
std::string sma = "[C:1](=[O:2])[OH].[N:3]>>[O:2]=[C:1][N:3]";
|
||||
// construct the reaction:
|
||||
ChemicalReaction *rxn = RxnSmartsToChemicalReaction(sma);
|
||||
ChemicalReaction *rxn = RxnSmartsToChemicalReaction(sma);
|
||||
// now initialize it and check for errors:
|
||||
rxn->initReactantMatchers();
|
||||
unsigned int nWarn,nError;
|
||||
rxn->validate(nWarn,nError);
|
||||
|
||||
unsigned int nWarn, nError;
|
||||
rxn->validate(nWarn, nError);
|
||||
|
||||
ROMol *mol;
|
||||
MOL_SPTR_VECT reacts;
|
||||
|
||||
@@ -278,20 +277,18 @@ void ReactionDemo(){
|
||||
prods = rxn->runReactants(reacts);
|
||||
|
||||
// for each of the possible applications of the reaction to the reactants:
|
||||
for(unsigned int i=0;i<prods.size();++i){
|
||||
BOOST_LOG(rdInfoLog)<<" product set: " <<i<<std::endl;
|
||||
for (unsigned int i = 0; i < prods.size(); ++i) {
|
||||
BOOST_LOG(rdInfoLog) << " product set: " << i << std::endl;
|
||||
// for each product of that application:
|
||||
for(unsigned int j=0;j<prods[i].size();++j){
|
||||
std::string psmiles=MolToSmiles(*prods[i][j],true);
|
||||
BOOST_LOG(rdInfoLog)<<" product : " <<j<<" "<<psmiles<<std::endl;
|
||||
}
|
||||
for (unsigned int j = 0; j < prods[i].size(); ++j) {
|
||||
std::string psmiles = MolToSmiles(*prods[i][j], true);
|
||||
BOOST_LOG(rdInfoLog) << " product : " << j << " " << psmiles
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
RDLog::InitLogs();
|
||||
BuildSimpleMolecule();
|
||||
WorkWithRingInfo();
|
||||
|
||||
@@ -24,61 +24,58 @@
|
||||
|
||||
namespace mpi = boost::mpi;
|
||||
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
mpi::environment env(argc, argv);
|
||||
mpi::communicator world;
|
||||
|
||||
// construct the data:
|
||||
std::vector<std::string> data;
|
||||
if (world.rank() == 0) {
|
||||
for(unsigned int i=0;i<100;++i){
|
||||
std::string txt(i+1,'C');
|
||||
for (unsigned int i = 0; i < 100; ++i) {
|
||||
std::string txt(i + 1, 'C');
|
||||
data.push_back(txt);
|
||||
}
|
||||
}
|
||||
|
||||
// broadcast it:
|
||||
broadcast(world,data,0);
|
||||
broadcast(world, data, 0);
|
||||
|
||||
// process it:
|
||||
std::vector<unsigned int> res;
|
||||
std::vector<std::vector<unsigned int> > allRes;
|
||||
// start by finding our chunk:
|
||||
unsigned int nProcs=world.size();
|
||||
unsigned int chunkSize=data.size() / nProcs;
|
||||
unsigned int extraBits=data.size() % nProcs;
|
||||
unsigned int nProcs = world.size();
|
||||
unsigned int chunkSize = data.size() / nProcs;
|
||||
unsigned int extraBits = data.size() % nProcs;
|
||||
|
||||
// handle extra bits on the root node:
|
||||
if( world.rank() == 0 ){
|
||||
for(unsigned int i=0;i<extraBits;++i){
|
||||
const std::string &elem=data[i];
|
||||
if (world.rank() == 0) {
|
||||
for (unsigned int i = 0; i < extraBits; ++i) {
|
||||
const std::string &elem = data[i];
|
||||
res.push_back(elem.length());
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int pos=extraBits+world.rank()*chunkSize;
|
||||
for(unsigned int i=0;i<chunkSize;++i){
|
||||
const std::string &elem=data[pos++];
|
||||
|
||||
unsigned int pos = extraBits + world.rank() * chunkSize;
|
||||
for (unsigned int i = 0; i < chunkSize; ++i) {
|
||||
const std::string &elem = data[pos++];
|
||||
res.push_back(elem.length());
|
||||
}
|
||||
|
||||
if( world.rank() == 0 ){
|
||||
gather(world,res,allRes,0);
|
||||
if (world.rank() == 0) {
|
||||
gather(world, res, allRes, 0);
|
||||
} else {
|
||||
gather(world,res,0);
|
||||
gather(world, res, 0);
|
||||
}
|
||||
|
||||
// reporting:
|
||||
if(world.rank()==0){
|
||||
for(unsigned int i=0;i<static_cast<unsigned int>(world.size());++i){
|
||||
std::cout<<"results from process "<<i<<": ";
|
||||
std::copy(allRes[i].begin(),allRes[i].end(),std::ostream_iterator<int,char>(std::cout, " "));
|
||||
std::cout<<std::endl;
|
||||
if (world.rank() == 0) {
|
||||
for (unsigned int i = 0; i < static_cast<unsigned int>(world.size()); ++i) {
|
||||
std::cout << "results from process " << i << ": ";
|
||||
std::copy(allRes[i].begin(), allRes[i].end(),
|
||||
std::ostream_iterator<int, char>(std::cout, " "));
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,80 +24,79 @@
|
||||
|
||||
namespace mpi = boost::mpi;
|
||||
|
||||
void broadcastMols(mpi::communicator &world,std::vector<RDKit::ROMOL_SPTR> &mols){
|
||||
void broadcastMols(mpi::communicator &world,
|
||||
std::vector<RDKit::ROMOL_SPTR> &mols) {
|
||||
std::vector<std::string> data;
|
||||
if (world.rank() == 0) {
|
||||
data.reserve(mols.size());
|
||||
BOOST_FOREACH( const RDKit::ROMOL_SPTR &ptr, mols ) {
|
||||
BOOST_FOREACH (const RDKit::ROMOL_SPTR &ptr, mols) {
|
||||
std::string pickle;
|
||||
RDKit::MolPickler::pickleMol(*ptr,pickle);
|
||||
RDKit::MolPickler::pickleMol(*ptr, pickle);
|
||||
data.push_back(pickle);
|
||||
}
|
||||
}
|
||||
broadcast(world,data,0);
|
||||
broadcast(world, data, 0);
|
||||
if (world.rank() != 0) {
|
||||
mols.reserve(data.size());
|
||||
BOOST_FOREACH( const std::string &pickle, data ) {
|
||||
RDKit::ROMol *mol=new RDKit::ROMol;
|
||||
RDKit::MolPickler::molFromPickle(pickle,mol);
|
||||
BOOST_FOREACH (const std::string &pickle, data) {
|
||||
RDKit::ROMol *mol = new RDKit::ROMol;
|
||||
RDKit::MolPickler::molFromPickle(pickle, mol);
|
||||
mols.push_back(RDKit::ROMOL_SPTR(mol));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
int main(int argc, char *argv[]) {
|
||||
mpi::environment env(argc, argv);
|
||||
mpi::communicator world;
|
||||
|
||||
// construct the data:
|
||||
std::vector<RDKit::ROMOL_SPTR> data;
|
||||
if (world.rank() == 0) {
|
||||
for(unsigned int i=0;i<100;++i){
|
||||
std::string txt(i+1,'C');
|
||||
RDKit::ROMol *m=RDKit::SmilesToMol(txt);
|
||||
for (unsigned int i = 0; i < 100; ++i) {
|
||||
std::string txt(i + 1, 'C');
|
||||
RDKit::ROMol *m = RDKit::SmilesToMol(txt);
|
||||
data.push_back(RDKit::ROMOL_SPTR(m));
|
||||
}
|
||||
}
|
||||
|
||||
// broadcast it:
|
||||
broadcastMols(world,data);
|
||||
broadcastMols(world, data);
|
||||
|
||||
// process it:
|
||||
std::vector<unsigned int> res;
|
||||
std::vector<std::vector<unsigned int> > allRes;
|
||||
// start by finding our chunk:
|
||||
unsigned int nProcs=world.size();
|
||||
unsigned int chunkSize=data.size() / nProcs;
|
||||
unsigned int extraBits=data.size() % nProcs;
|
||||
unsigned int nProcs = world.size();
|
||||
unsigned int chunkSize = data.size() / nProcs;
|
||||
unsigned int extraBits = data.size() % nProcs;
|
||||
|
||||
// handle extra bits on the root node:
|
||||
if( world.rank() == 0 ){
|
||||
for(unsigned int i=0;i<extraBits;++i){
|
||||
if (world.rank() == 0) {
|
||||
for (unsigned int i = 0; i < extraBits; ++i) {
|
||||
res.push_back(data[i]->getNumAtoms());
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int pos=extraBits+world.rank()*chunkSize;
|
||||
for(unsigned int i=0;i<chunkSize;++i){
|
||||
|
||||
unsigned int pos = extraBits + world.rank() * chunkSize;
|
||||
for (unsigned int i = 0; i < chunkSize; ++i) {
|
||||
res.push_back(data[pos++]->getNumAtoms());
|
||||
}
|
||||
|
||||
if( world.rank() == 0 ){
|
||||
gather(world,res,allRes,0);
|
||||
if (world.rank() == 0) {
|
||||
gather(world, res, allRes, 0);
|
||||
} else {
|
||||
gather(world,res,0);
|
||||
gather(world, res, 0);
|
||||
}
|
||||
|
||||
// reporting:
|
||||
if(world.rank()==0){
|
||||
for(unsigned int i=0;i<static_cast<unsigned int>(world.size());++i){
|
||||
std::cout<<"results from process "<<i<<": ";
|
||||
std::copy(allRes[i].begin(),allRes[i].end(),std::ostream_iterator<int,char>(std::cout, " "));
|
||||
std::cout<<std::endl;
|
||||
if (world.rank() == 0) {
|
||||
for (unsigned int i = 0; i < static_cast<unsigned int>(world.size()); ++i) {
|
||||
std::cout << "results from process " << i << ": ";
|
||||
std::copy(allRes[i].begin(), allRes[i].end(),
|
||||
std::ostream_iterator<int, char>(std::cout, " "));
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,25 +2,23 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifndef CLASSA_H
|
||||
#define CLASSA_H
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
class classA {
|
||||
public:
|
||||
classA() {
|
||||
setProp("useless", 10);
|
||||
};
|
||||
classA() { setProp("useless", 10); };
|
||||
~classA() {}
|
||||
|
||||
|
||||
void printA() const {
|
||||
if (hasProp("useless")) {
|
||||
std::cout << "has useless\n";
|
||||
@@ -31,9 +29,7 @@ class classA {
|
||||
return (dp_props.find(key) != dp_props.end());
|
||||
}
|
||||
|
||||
void setProp(const std::string &key, int val) {
|
||||
dp_props[key] = val;
|
||||
}
|
||||
void setProp(const std::string &key, int val) { dp_props[key] = val; }
|
||||
|
||||
private:
|
||||
std::map<std::string, int> dp_props;
|
||||
|
||||
@@ -7,24 +7,22 @@
|
||||
#define CLASSC_H
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
typedef std::pair<std::string, int> STR_INT;
|
||||
typedef std::vector<STR_INT> PAIR_VECT;
|
||||
|
||||
class classC {
|
||||
|
||||
public:
|
||||
classC() {
|
||||
setProp("useless", 10);
|
||||
};
|
||||
classC() { setProp("useless", 10); };
|
||||
~classC() {}
|
||||
|
||||
|
||||
void printC() const {
|
||||
if (hasProp("useless")) {
|
||||
std::cout << "has useless\n";
|
||||
@@ -38,7 +36,7 @@ class classC {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void setProp(const std::string &key, int val) {
|
||||
@@ -48,7 +46,6 @@ class classC {
|
||||
|
||||
private:
|
||||
PAIR_VECT dp_props;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,13 +4,9 @@
|
||||
#include <DataStructs/ExplicitBitVect.h>
|
||||
namespace python = boost::python;
|
||||
|
||||
void testCrossA(classA *A) {
|
||||
A->printA();
|
||||
};
|
||||
void testCrossA(classA *A) { A->printA(); };
|
||||
|
||||
void testCrossC(classC *C) {
|
||||
C->printC();
|
||||
};
|
||||
void testCrossC(classC *C) { C->printC(); };
|
||||
|
||||
classC *getClassC() {
|
||||
classC *nc = new classC();
|
||||
@@ -18,12 +14,11 @@ classC *getClassC() {
|
||||
}
|
||||
|
||||
ExplicitBitVect *getEBV() {
|
||||
ExplicitBitVect *ebv = new ExplicitBitVect(20);
|
||||
ExplicitBitVect *ebv = new ExplicitBitVect(20);
|
||||
return ebv;
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleB)
|
||||
{
|
||||
BOOST_PYTHON_MODULE(moduleB) {
|
||||
python::def("testCrossA", testCrossA);
|
||||
python::def("testCrossC", testCrossC);
|
||||
python::def("GetClassC", getClassC,
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
namespace python = boost::python;
|
||||
@@ -14,17 +15,10 @@ namespace python = boost::python;
|
||||
struct A_wrapper {
|
||||
static void wrap() {
|
||||
python::class_<classA>("classA", python::init<>())
|
||||
.def("printA", &classA::printA)
|
||||
;
|
||||
.def("printA", &classA::printA);
|
||||
};
|
||||
};
|
||||
|
||||
void wrap_classA() {
|
||||
A_wrapper::wrap();
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleA)
|
||||
{
|
||||
wrap_classA();
|
||||
}
|
||||
void wrap_classA() { A_wrapper::wrap(); }
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleA) { wrap_classA(); }
|
||||
|
||||
@@ -1,31 +1,24 @@
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
#include "classC.h"
|
||||
#include <boost/python.hpp>
|
||||
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
struct C_wrapper {
|
||||
static void wrap() {
|
||||
python::class_<classC>("classC", python::init<>())
|
||||
.def("printC", &classC::printC)
|
||||
;
|
||||
.def("printC", &classC::printC);
|
||||
};
|
||||
};
|
||||
|
||||
void wrap_classC() {
|
||||
C_wrapper::wrap();
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleC)
|
||||
{
|
||||
wrap_classC();
|
||||
}
|
||||
void wrap_classC() { C_wrapper::wrap(); }
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleC) { wrap_classC(); }
|
||||
|
||||
@@ -7,21 +7,19 @@
|
||||
#include <iostream>
|
||||
#include <Invariant/Invariant.h>
|
||||
|
||||
int idx=0;
|
||||
int idx = 0;
|
||||
|
||||
class Contained {
|
||||
public:
|
||||
public:
|
||||
Contained() : _idx(idx) {
|
||||
std::cout << "Contained CTOR:" << _idx << std::endl;
|
||||
idx++;
|
||||
}
|
||||
~Contained() {
|
||||
std::cout << "Contained DTOR:" << _idx << std::endl;
|
||||
}
|
||||
Contained( const Contained &other) : _idx(other._idx) {
|
||||
~Contained() { std::cout << "Contained DTOR:" << _idx << std::endl; }
|
||||
Contained(const Contained &other) : _idx(other._idx) {
|
||||
std::cout << "Contained Copy CTOR:" << _idx << std::endl;
|
||||
}
|
||||
Contained &operator=( const Contained &other) {
|
||||
Contained &operator=(const Contained &other) {
|
||||
_idx = other._idx;
|
||||
std::cout << "Contained Assign:" << _idx << std::endl;
|
||||
return *this;
|
||||
@@ -29,171 +27,168 @@ public:
|
||||
int _idx;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct larger_of {
|
||||
T operator()(T arg1, T arg2) { return arg1 > arg2 ? arg1 : arg2; };
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct larger_of {
|
||||
T operator()(T arg1,T arg2) { return arg1>arg2 ? arg1 : arg2; };
|
||||
struct charptr_functor {
|
||||
bool operator()(const char *s1, const char *s2) const {
|
||||
return strcmp(s1, s2) < 0;
|
||||
};
|
||||
|
||||
|
||||
struct charptr_functor {
|
||||
bool operator()(const char* s1, const char* s2) const
|
||||
{
|
||||
return strcmp(s1, s2) < 0;
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
class Dict {
|
||||
public:
|
||||
typedef std::map<const char *,boost::any,charptr_functor> DataType;
|
||||
Dict() {_data.clear();};
|
||||
Dict(const Dict &other) { _data = other._data; };
|
||||
Dict &operator=(const Dict &other) {
|
||||
_data = other._data;
|
||||
return *this;
|
||||
};
|
||||
|
||||
bool hasVal(const char *what) const {
|
||||
//DataType::const_iterator i;
|
||||
//std::cerr << "\t\tpre: ";
|
||||
//for(i=_data.begin();i!=_data.end();i++){
|
||||
//std::cerr << (*i).first << " ";
|
||||
//}
|
||||
//std::cerr << std::endl;
|
||||
//std::cerr << "\thasVal: " << what << ": " << _data.count(what) << std::endl;
|
||||
//std::cerr << "\t\tpost: ";
|
||||
//for(i=_data.begin();i!=_data.end();i++){
|
||||
//std::cerr << (*i).first << " ";
|
||||
//}
|
||||
//std::cerr << std::endl;
|
||||
return _data.count(what);
|
||||
};
|
||||
bool hasVal(const std::string &what) const {
|
||||
return hasVal(what.c_str());
|
||||
};
|
||||
|
||||
//
|
||||
// We're going to try and be somewhat crafty about this getVal stuff to make these
|
||||
// containers a little bit more generic. The normal behavior here is that the
|
||||
// value being queried must be directly castable to type T. We'll robustify a
|
||||
// little bit by trying that and, if the cast fails, attempting a couple of
|
||||
// other casts, which will then be lexically cast to type T.
|
||||
//
|
||||
template <typename T>
|
||||
void getVal(const char *what,T &res) const {
|
||||
PRECONDITION(hasVal(what),"getVal called on non-existent key");
|
||||
const boost::any &val = _data.find(what)->second;
|
||||
res = boost::any_cast<T>(val);
|
||||
};
|
||||
|
||||
void getVal(const char *what,std::string &res) const {
|
||||
PRECONDITION(hasVal(what),"getVal called on non-existent key");
|
||||
const boost::any &val = _data.find(what)->second;
|
||||
try{
|
||||
res = boost::any_cast<std::string>(val);
|
||||
} catch (const boost::bad_any_cast &) {
|
||||
if(val.type()==typeid(int)){
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<int>(val));
|
||||
} else if(val.type()==typeid(long)){
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<long>(val));
|
||||
} else if(val.type()==typeid(float)){
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<float>(val));
|
||||
} else if(val.type()==typeid(double)){
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<double>(val));
|
||||
} else if(val.type()==typeid(const char *)){
|
||||
res = std::string(boost::any_cast<const char *>(val));
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename T>
|
||||
void getVal(const std::string &what,T &res) const { getVal(what.c_str(),res); };
|
||||
|
||||
template <typename T>
|
||||
void setVal(const char *what,T &val){
|
||||
_data[what] = boost::any(val);
|
||||
};
|
||||
template <typename T>
|
||||
void setVal(const std::string &what,T &val) { setVal(what.c_str(),val); };
|
||||
|
||||
void clearVal(const char *what) { _data.erase(what); };
|
||||
|
||||
void reset() { _data.clear(); };
|
||||
|
||||
private:
|
||||
DataType _data;
|
||||
|
||||
public:
|
||||
typedef std::map<const char *, boost::any, charptr_functor> DataType;
|
||||
Dict() { _data.clear(); };
|
||||
Dict(const Dict &other) { _data = other._data; };
|
||||
Dict &operator=(const Dict &other) {
|
||||
_data = other._data;
|
||||
return *this;
|
||||
};
|
||||
|
||||
bool hasVal(const char *what) const {
|
||||
// DataType::const_iterator i;
|
||||
// std::cerr << "\t\tpre: ";
|
||||
// for(i=_data.begin();i!=_data.end();i++){
|
||||
// std::cerr << (*i).first << " ";
|
||||
//}
|
||||
// std::cerr << std::endl;
|
||||
// std::cerr << "\thasVal: " << what << ": " << _data.count(what) <<
|
||||
// std::endl;
|
||||
// std::cerr << "\t\tpost: ";
|
||||
// for(i=_data.begin();i!=_data.end();i++){
|
||||
// std::cerr << (*i).first << " ";
|
||||
//}
|
||||
// std::cerr << std::endl;
|
||||
return _data.count(what);
|
||||
};
|
||||
bool hasVal(const std::string &what) const { return hasVal(what.c_str()); };
|
||||
|
||||
void test1(){
|
||||
//
|
||||
// We're going to try and be somewhat crafty about this getVal stuff to make
|
||||
// these
|
||||
// containers a little bit more generic. The normal behavior here is that
|
||||
// the
|
||||
// value being queried must be directly castable to type T. We'll robustify
|
||||
// a
|
||||
// little bit by trying that and, if the cast fails, attempting a couple of
|
||||
// other casts, which will then be lexically cast to type T.
|
||||
//
|
||||
template <typename T>
|
||||
void getVal(const char *what, T &res) const {
|
||||
PRECONDITION(hasVal(what), "getVal called on non-existent key");
|
||||
const boost::any &val = _data.find(what)->second;
|
||||
res = boost::any_cast<T>(val);
|
||||
};
|
||||
|
||||
void getVal(const char *what, std::string &res) const {
|
||||
PRECONDITION(hasVal(what), "getVal called on non-existent key");
|
||||
const boost::any &val = _data.find(what)->second;
|
||||
try {
|
||||
res = boost::any_cast<std::string>(val);
|
||||
} catch (const boost::bad_any_cast &) {
|
||||
if (val.type() == typeid(int)) {
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<int>(val));
|
||||
} else if (val.type() == typeid(long)) {
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<long>(val));
|
||||
} else if (val.type() == typeid(float)) {
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<float>(val));
|
||||
} else if (val.type() == typeid(double)) {
|
||||
res = boost::lexical_cast<std::string>(boost::any_cast<double>(val));
|
||||
} else if (val.type() == typeid(const char *)) {
|
||||
res = std::string(boost::any_cast<const char *>(val));
|
||||
} else {
|
||||
throw;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void getVal(const std::string &what, T &res) const {
|
||||
getVal(what.c_str(), res);
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void setVal(const char *what, T &val) {
|
||||
_data[what] = boost::any(val);
|
||||
};
|
||||
template <typename T>
|
||||
void setVal(const std::string &what, T &val) {
|
||||
setVal(what.c_str(), val);
|
||||
};
|
||||
|
||||
void clearVal(const char *what) { _data.erase(what); };
|
||||
|
||||
void reset() { _data.clear(); };
|
||||
|
||||
private:
|
||||
DataType _data;
|
||||
};
|
||||
|
||||
void test1() {
|
||||
// basic containers
|
||||
std::cout << "----------- TEST1 -----------" << std::endl;
|
||||
|
||||
Contained c;
|
||||
TEST_ASSERT(c._idx==0);
|
||||
TEST_ASSERT(c._idx == 0);
|
||||
Contained d(c);
|
||||
TEST_ASSERT(d._idx==0);
|
||||
TEST_ASSERT(d._idx == 0);
|
||||
Contained e;
|
||||
TEST_ASSERT(e._idx==1);
|
||||
TEST_ASSERT(e._idx == 1);
|
||||
std::cout << "assign" << std::endl;
|
||||
e=c;
|
||||
TEST_ASSERT(e._idx==0);
|
||||
e = c;
|
||||
TEST_ASSERT(e._idx == 0);
|
||||
|
||||
|
||||
std::cout <<" Done" << std::endl;
|
||||
std::cout << " Done" << std::endl;
|
||||
}
|
||||
|
||||
void test2(){
|
||||
void test2() {
|
||||
// shared pointers with containers
|
||||
std::cout << "----------- TEST2 -----------" << std::endl;
|
||||
|
||||
typedef boost::shared_ptr<Contained> CONT_SPTR;
|
||||
CONT_SPTR s_d(new Contained());
|
||||
TEST_ASSERT(s_d.use_count()==1);
|
||||
CONT_SPTR s_e=s_d;
|
||||
TEST_ASSERT(s_e.use_count()==2);
|
||||
TEST_ASSERT(s_d.use_count() == 1);
|
||||
CONT_SPTR s_e = s_d;
|
||||
TEST_ASSERT(s_e.use_count() == 2);
|
||||
s_d.reset();
|
||||
TEST_ASSERT(s_e.use_count()==1);
|
||||
TEST_ASSERT(s_e.use_count() == 1);
|
||||
s_e.reset();
|
||||
|
||||
std::cout <<" Done" << std::endl;
|
||||
std::cout << " Done" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void test3(){
|
||||
void test3() {
|
||||
// basic dict stuff
|
||||
std::cout << "----------- TEST3 -----------" << std::endl;
|
||||
|
||||
Dict dict;
|
||||
TEST_ASSERT(!dict.hasVal("foo"));
|
||||
|
||||
int tmp=4;
|
||||
dict.setVal("foo",tmp);
|
||||
int tmp = 4;
|
||||
dict.setVal("foo", tmp);
|
||||
TEST_ASSERT(dict.hasVal("foo"));
|
||||
tmp=0;
|
||||
dict.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp==4);
|
||||
tmp = 0;
|
||||
dict.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp == 4);
|
||||
|
||||
Dict d2(dict);
|
||||
TEST_ASSERT(d2.hasVal("foo"));
|
||||
d2.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp==4);
|
||||
d2.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp == 4);
|
||||
|
||||
Dict d3;
|
||||
d3=d2;
|
||||
d3 = d2;
|
||||
TEST_ASSERT(d3.hasVal("foo"));
|
||||
d3.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp==4);
|
||||
|
||||
std::cout <<" Done" << std::endl;
|
||||
d3.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp == 4);
|
||||
|
||||
std::cout << " Done" << std::endl;
|
||||
}
|
||||
|
||||
void test4(){
|
||||
void test4() {
|
||||
// dict containing Contained objects
|
||||
std::cout << "----------- TEST4 -----------" << std::endl;
|
||||
|
||||
@@ -201,33 +196,31 @@ void test4(){
|
||||
TEST_ASSERT(!dict.hasVal("foo"));
|
||||
|
||||
Contained tmp;
|
||||
int hold=tmp._idx;
|
||||
int hold = tmp._idx;
|
||||
std::cout << " set" << std::endl;
|
||||
dict.setVal("foo",tmp);
|
||||
dict.setVal("foo", tmp);
|
||||
std::cout << " query" << std::endl;
|
||||
TEST_ASSERT(dict.hasVal("foo"));
|
||||
std::cout << " get" << std::endl;
|
||||
dict.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp._idx==hold);
|
||||
dict.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp._idx == hold);
|
||||
|
||||
std::cout << " copy" << std::endl;
|
||||
Dict d2(dict);
|
||||
TEST_ASSERT(d2.hasVal("foo"));
|
||||
d2.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp._idx==hold);
|
||||
|
||||
d2.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp._idx == hold);
|
||||
|
||||
Dict d3;
|
||||
d3=d2;
|
||||
d3 = d2;
|
||||
TEST_ASSERT(d3.hasVal("foo"));
|
||||
d3.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp._idx==hold);
|
||||
d3.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp._idx == hold);
|
||||
|
||||
|
||||
std::cout <<" Done" << std::endl;
|
||||
std::cout << " Done" << std::endl;
|
||||
}
|
||||
|
||||
void test5(){
|
||||
void test5() {
|
||||
// dict containing sptrs to Contained objects
|
||||
std::cout << "----------- TEST5 -----------" << std::endl;
|
||||
typedef boost::shared_ptr<Contained> CONT_SPTR;
|
||||
@@ -236,38 +229,34 @@ void test5(){
|
||||
TEST_ASSERT(!dict.hasVal("foo"));
|
||||
|
||||
CONT_SPTR tmp(new Contained());
|
||||
int hold=tmp->_idx;
|
||||
int hold = tmp->_idx;
|
||||
std::cout << " set" << std::endl;
|
||||
dict.setVal("foo",tmp);
|
||||
dict.setVal("foo", tmp);
|
||||
std::cout << " query" << std::endl;
|
||||
TEST_ASSERT(dict.hasVal("foo"));
|
||||
std::cout << " get" << std::endl;
|
||||
dict.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp->_idx==hold);
|
||||
dict.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp->_idx == hold);
|
||||
|
||||
std::cout << " copy" << std::endl;
|
||||
Dict d2(dict);
|
||||
TEST_ASSERT(d2.hasVal("foo"));
|
||||
d2.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp->_idx==hold);
|
||||
|
||||
d2.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp->_idx == hold);
|
||||
|
||||
Dict d3;
|
||||
d3=d2;
|
||||
d3 = d2;
|
||||
TEST_ASSERT(d3.hasVal("foo"));
|
||||
d3.getVal("foo",tmp);
|
||||
TEST_ASSERT(tmp->_idx==hold);
|
||||
d3.getVal("foo", tmp);
|
||||
TEST_ASSERT(tmp->_idx == hold);
|
||||
|
||||
|
||||
std::cout <<" Done" << std::endl;
|
||||
std::cout << " Done" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
int main() {
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
|
||||
}
|
||||
|
||||
@@ -2,25 +2,23 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
|
||||
#ifndef CLASSA_H
|
||||
#define CLASSA_H
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
class classA {
|
||||
public:
|
||||
classA() {
|
||||
setProp("useless", 10);
|
||||
};
|
||||
classA() { setProp("useless", 10); };
|
||||
~classA() {}
|
||||
|
||||
|
||||
void printA() const {
|
||||
if (hasProp("useless")) {
|
||||
std::cout << "has useless\n";
|
||||
@@ -31,9 +29,7 @@ class classA {
|
||||
return (dp_props.find(key) != dp_props.end());
|
||||
}
|
||||
|
||||
void setProp(const std::string &key, int val) {
|
||||
dp_props[key] = val;
|
||||
}
|
||||
void setProp(const std::string &key, int val) { dp_props[key] = val; }
|
||||
|
||||
private:
|
||||
std::map<std::string, int> dp_props;
|
||||
|
||||
@@ -7,24 +7,22 @@
|
||||
#define CLASSC_H
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
typedef std::pair<std::string, int> STR_INT;
|
||||
typedef std::vector<STR_INT> PAIR_VECT;
|
||||
|
||||
class classC {
|
||||
|
||||
public:
|
||||
classC() {
|
||||
setProp("useless", 10);
|
||||
};
|
||||
classC() { setProp("useless", 10); };
|
||||
~classC() {}
|
||||
|
||||
|
||||
void printC() const {
|
||||
if (hasProp("useless")) {
|
||||
std::cout << "has useless\n";
|
||||
@@ -38,7 +36,7 @@ class classC {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void setProp(const std::string &key, int val) {
|
||||
@@ -48,7 +46,6 @@ class classC {
|
||||
|
||||
private:
|
||||
PAIR_VECT dp_props;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,18 +4,11 @@
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
void testCrossA(classA *A) {
|
||||
A->printA();
|
||||
};
|
||||
void testCrossA(classA *A) { A->printA(); };
|
||||
|
||||
void testCrossC(classC *C) {
|
||||
C->printC();
|
||||
};
|
||||
void testCrossC(classC *C) { C->printC(); };
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleB)
|
||||
{
|
||||
BOOST_PYTHON_MODULE(moduleB) {
|
||||
python::def("testCrossA", testCrossA);
|
||||
python::def("testCrossC", testCrossC);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
namespace python = boost::python;
|
||||
@@ -14,17 +15,10 @@ namespace python = boost::python;
|
||||
struct A_wrapper {
|
||||
static void wrap() {
|
||||
python::class_<classA>("classA", python::init<>())
|
||||
.def("printA", &classA::printA)
|
||||
;
|
||||
.def("printA", &classA::printA);
|
||||
};
|
||||
};
|
||||
|
||||
void wrap_classA() {
|
||||
A_wrapper::wrap();
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleA)
|
||||
{
|
||||
wrap_classA();
|
||||
}
|
||||
void wrap_classA() { A_wrapper::wrap(); }
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleA) { wrap_classA(); }
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
#include <boost/python.hpp>
|
||||
|
||||
#ifdef WIN32
|
||||
#pragma warning (disable: 4786) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4788) // warning: long & complicated stl warning
|
||||
#pragma warning (disable: 4660)
|
||||
#pragma warning (disable: 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning (disable: 4305) // warning: truncation from 'const double' to 'const float'
|
||||
#pragma warning(disable : 4786) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4788) // warning: long & complicated stl warning
|
||||
#pragma warning(disable : 4660)
|
||||
#pragma warning(disable : 4275) // warning: non dll-interface class used as...
|
||||
#pragma warning(disable : 4305) // warning: truncation from 'const double' to
|
||||
// 'const float'
|
||||
#endif
|
||||
|
||||
namespace python = boost::python;
|
||||
@@ -14,17 +15,10 @@ namespace python = boost::python;
|
||||
struct C_wrapper {
|
||||
static void wrap() {
|
||||
python::class_<classC>("classC", python::init<>())
|
||||
.def("printC", &classC::printC)
|
||||
;
|
||||
.def("printC", &classC::printC);
|
||||
};
|
||||
};
|
||||
|
||||
void wrap_classC() {
|
||||
C_wrapper::wrap();
|
||||
}
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleC)
|
||||
{
|
||||
wrap_classC();
|
||||
}
|
||||
void wrap_classC() { C_wrapper::wrap(); }
|
||||
|
||||
BOOST_PYTHON_MODULE(moduleC) { wrap_classC(); }
|
||||
|
||||
@@ -6,10 +6,6 @@
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE(moda)
|
||||
{
|
||||
python::class_<ClassA>("ClassA")
|
||||
.def("Get4",&ClassA::get4)
|
||||
;
|
||||
|
||||
BOOST_PYTHON_MODULE(moda) {
|
||||
python::class_<ClassA>("ClassA").def("Get4", &ClassA::get4);
|
||||
}
|
||||
|
||||
@@ -6,13 +6,10 @@
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
BOOST_PYTHON_MODULE(modb)
|
||||
{
|
||||
python::class_<ClassB>("ClassB")
|
||||
.def("Get3",&ClassB::get3)
|
||||
.def("ReturnOther",&ClassB::returnOther,
|
||||
python::return_value_policy<python::manage_new_object>())
|
||||
.def("AcceptOther",&ClassB::acceptOther)
|
||||
;
|
||||
|
||||
BOOST_PYTHON_MODULE(modb) {
|
||||
python::class_<ClassB>("ClassB")
|
||||
.def("Get3", &ClassB::get3)
|
||||
.def("ReturnOther", &ClassB::returnOther,
|
||||
python::return_value_policy<python::manage_new_object>())
|
||||
.def("AcceptOther", &ClassB::acceptOther);
|
||||
}
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
|
||||
#include <boost/python.hpp>
|
||||
|
||||
|
||||
class ClassA{
|
||||
public:
|
||||
class ClassA {
|
||||
public:
|
||||
int get4() { return 4; };
|
||||
};
|
||||
|
||||
class ClassB{
|
||||
public:
|
||||
class ClassB {
|
||||
public:
|
||||
ClassA *returnOther() { return new ClassA; };
|
||||
int get3() { return 3; };
|
||||
int acceptOther(ClassA *other) { return other->get4();};
|
||||
int acceptOther(ClassA *other) { return other->get4(); };
|
||||
};
|
||||
|
||||
@@ -7,16 +7,14 @@
|
||||
#define PY_ARRAY_UNIQUE_SYMBOL RD_array_API
|
||||
#include "numpy/oldnumeric.h"
|
||||
|
||||
|
||||
namespace python = boost::python;
|
||||
|
||||
double GetFirstElement(python::numeric::array &x){
|
||||
double GetFirstElement(python::numeric::array &x) {
|
||||
PyArrayObject *ptr = (PyArrayObject *)x.ptr();
|
||||
void* data = ptr->data;
|
||||
double res=0.0;
|
||||
void *data = ptr->data;
|
||||
double res = 0.0;
|
||||
|
||||
switch(ptr->descr->type_num)
|
||||
{
|
||||
switch (ptr->descr->type_num) {
|
||||
case PyArray_DOUBLE:
|
||||
res = ((double *)data)[0];
|
||||
break;
|
||||
@@ -29,14 +27,8 @@ double GetFirstElement(python::numeric::array &x){
|
||||
case PyArray_INT:
|
||||
res = (double)((int *)data)[0];
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(linalg)
|
||||
{
|
||||
python::def("GetFirstElement",GetFirstElement);
|
||||
|
||||
}
|
||||
BOOST_PYTHON_MODULE(linalg) { python::def("GetFirstElement", GetFirstElement); }
|
||||
|
||||
@@ -5,18 +5,16 @@
|
||||
#include <boost/python.hpp>
|
||||
namespace python = boost::python;
|
||||
|
||||
|
||||
// ------
|
||||
//
|
||||
// This one is relatively easy:
|
||||
// expose a function with a default argument
|
||||
//
|
||||
// ------
|
||||
int func2(int v1,int plus=3);
|
||||
int func2(int v1,int plus) {return v1+plus;};
|
||||
int func2(int v1, int plus = 3);
|
||||
int func2(int v1, int plus) { return v1 + plus; };
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, func2, 1, 2)
|
||||
|
||||
|
||||
// ------
|
||||
//
|
||||
// More complex:
|
||||
@@ -24,25 +22,21 @@ BOOST_PYTHON_FUNCTION_OVERLOADS(f2_overloads, func2, 1, 2)
|
||||
//
|
||||
// ------
|
||||
template <typename T>
|
||||
T func(T v1,int plus=3);
|
||||
T func(T v1, int plus = 3);
|
||||
|
||||
template <typename T>
|
||||
T func(T v1,int plus) {
|
||||
return v1+plus;
|
||||
T func(T v1, int plus) {
|
||||
return v1 + plus;
|
||||
}
|
||||
|
||||
int (*f1_int)(int,int=3)=func; // gotta love that syntax!
|
||||
int (*f1_int)(int, int = 3) = func; // gotta love that syntax!
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(f1_int_overloads, f1_int, 1, 2)
|
||||
float (*f1_float)(float,int=3)=func;
|
||||
float (*f1_float)(float, int = 3) = func;
|
||||
BOOST_PYTHON_FUNCTION_OVERLOADS(f1_float_overloads, f1_float, 1, 2)
|
||||
|
||||
BOOST_PYTHON_MODULE(overloads) {
|
||||
python::def("f2", func2, f2_overloads(python::args("v1", "plus")));
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(overloads)
|
||||
{
|
||||
python::def("f2",func2,f2_overloads(python::args("v1","plus")));
|
||||
|
||||
python::def("f1",f1_int,f1_int_overloads(python::args("v1","plus")));
|
||||
python::def("f1",f1_float,f1_float_overloads(python::args("v1","plus")));
|
||||
|
||||
python::def("f1", f1_int, f1_int_overloads(python::args("v1", "plus")));
|
||||
python::def("f1", f1_float, f1_float_overloads(python::args("v1", "plus")));
|
||||
}
|
||||
|
||||
@@ -6,29 +6,22 @@
|
||||
#include <boost/python/detail/api_placeholder.hpp>
|
||||
namespace python = boost::python;
|
||||
|
||||
|
||||
|
||||
// ----------
|
||||
//
|
||||
// In both cases here, the restriction on the object passed in is
|
||||
// solely that it support the functions used.
|
||||
//
|
||||
// ----------
|
||||
int seq_len(python::object seq){
|
||||
return python::len(seq);
|
||||
}
|
||||
int seq_len(python::object seq) { return python::len(seq); }
|
||||
|
||||
int sum_first2(python::object seq){
|
||||
int sum_first2(python::object seq) {
|
||||
int sum;
|
||||
sum = python::extract<int>(seq[0]) + python::extract<int>(seq[1]);
|
||||
|
||||
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(python_objs)
|
||||
{
|
||||
python::def("seq_len",seq_len);
|
||||
python::def("sum_first2",sum_first2);
|
||||
BOOST_PYTHON_MODULE(python_objs) {
|
||||
python::def("seq_len", seq_len);
|
||||
python::def("sum_first2", sum_first2);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
|
||||
#include <boost/python.hpp>
|
||||
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
|
||||
#include <boost/python/detail/api_placeholder.hpp>
|
||||
@@ -14,90 +13,68 @@
|
||||
namespace python = boost::python;
|
||||
|
||||
class DemoKlass {
|
||||
public:
|
||||
explicit DemoKlass(int v) : val_(v) {};
|
||||
public:
|
||||
explicit DemoKlass(int v) : val_(v){};
|
||||
int getVal() const { return val_; };
|
||||
private:
|
||||
|
||||
private:
|
||||
int val_;
|
||||
};
|
||||
typedef boost::shared_ptr<DemoKlass> DemoKlassSPtr;
|
||||
typedef std::vector<DemoKlass*> DemoKlassPtrVect;
|
||||
typedef std::vector<DemoKlass *> DemoKlassPtrVect;
|
||||
typedef std::vector<DemoKlassSPtr> DemoKlassSPtrVect;
|
||||
|
||||
DemoKlass *buildPtr(int v) {
|
||||
return new DemoKlass(v);
|
||||
}
|
||||
DemoKlassSPtr buildSPtr(int v) {
|
||||
return DemoKlassSPtr(new DemoKlass(v));
|
||||
}
|
||||
DemoKlass *buildPtr(int v) { return new DemoKlass(v); }
|
||||
DemoKlassSPtr buildSPtr(int v) { return DemoKlassSPtr(new DemoKlass(v)); }
|
||||
|
||||
DemoKlassPtrVect buildPtrVector(unsigned int sz){
|
||||
DemoKlassPtrVect buildPtrVector(unsigned int sz) {
|
||||
DemoKlassPtrVect res;
|
||||
for(unsigned int i=0;i<sz;i++){
|
||||
for (unsigned int i = 0; i < sz; i++) {
|
||||
res.push_back(new DemoKlass(i));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
DemoKlassSPtrVect buildSPtrVector(unsigned int sz){
|
||||
DemoKlassSPtrVect buildSPtrVector(unsigned int sz) {
|
||||
DemoKlassSPtrVect res;
|
||||
for(unsigned int i=0;i<sz;i++){
|
||||
for (unsigned int i = 0; i < sz; i++) {
|
||||
res.push_back(DemoKlassSPtr(new DemoKlass(i)));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
class DemoContainer {
|
||||
public:
|
||||
public:
|
||||
typedef DemoKlassSPtrVect::iterator iterator;
|
||||
typedef DemoKlassSPtrVect::const_iterator const_iterator;
|
||||
explicit DemoContainer(unsigned int sz) {
|
||||
vect_ = buildSPtrVector(sz);
|
||||
}
|
||||
iterator begin() {
|
||||
return vect_.begin();
|
||||
}
|
||||
iterator end() {
|
||||
return vect_.end();
|
||||
}
|
||||
const_iterator begin() const {
|
||||
return vect_.begin();
|
||||
}
|
||||
const_iterator end() const {
|
||||
return vect_.end();
|
||||
}
|
||||
explicit DemoContainer(unsigned int sz) { vect_ = buildSPtrVector(sz); }
|
||||
iterator begin() { return vect_.begin(); }
|
||||
iterator end() { return vect_.end(); }
|
||||
const_iterator begin() const { return vect_.begin(); }
|
||||
const_iterator end() const { return vect_.end(); }
|
||||
|
||||
private:
|
||||
private:
|
||||
DemoKlassSPtrVect vect_;
|
||||
};
|
||||
|
||||
BOOST_PYTHON_MODULE(SPtrTestModule) {
|
||||
python::class_<DemoKlass, DemoKlassSPtr>("DemoKlass", "demo class",
|
||||
python::init<int>())
|
||||
.def("GetVal", &DemoKlass::getVal);
|
||||
|
||||
|
||||
BOOST_PYTHON_MODULE(SPtrTestModule)
|
||||
{
|
||||
python::class_<DemoKlass,DemoKlassSPtr >("DemoKlass","demo class",python::init<int>())
|
||||
.def("GetVal",&DemoKlass::getVal)
|
||||
;
|
||||
|
||||
python::def("buildPtr",buildPtr,python::return_value_policy<python::manage_new_object>());
|
||||
python::def("buildSPtr",buildSPtr);
|
||||
|
||||
python::def("buildPtr", buildPtr,
|
||||
python::return_value_policy<python::manage_new_object>());
|
||||
python::def("buildSPtr", buildSPtr);
|
||||
|
||||
python::class_<DemoKlassPtrVect>("DemoKlassPtrVec")
|
||||
.def(python::vector_indexing_suite<DemoKlassPtrVect>())
|
||||
;
|
||||
python::def("buildPtrVector",buildPtrVector);
|
||||
.def(python::vector_indexing_suite<DemoKlassPtrVect>());
|
||||
python::def("buildPtrVector", buildPtrVector);
|
||||
|
||||
python::class_<DemoKlassSPtrVect>("DemoKlassSPtrVec")
|
||||
.def(python::vector_indexing_suite<DemoKlassSPtrVect,true>())
|
||||
;
|
||||
python::def("buildSPtrVector",buildSPtrVector);
|
||||
|
||||
|
||||
python::class_<DemoContainer>("DemoContainer","demo container",python::init<unsigned int>())
|
||||
.def("__iter__",python::iterator<DemoContainer>())
|
||||
;
|
||||
|
||||
.def(python::vector_indexing_suite<DemoKlassSPtrVect, true>());
|
||||
python::def("buildSPtrVector", buildSPtrVector);
|
||||
|
||||
python::class_<DemoContainer>("DemoContainer", "demo container",
|
||||
python::init<unsigned int>())
|
||||
.def("__iter__", python::iterator<DemoContainer>());
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// $Id$
|
||||
//
|
||||
//
|
||||
// Copyright (C) 2007,2008 Greg Landrum
|
||||
//
|
||||
// @@ All Rights Reserved @@
|
||||
@@ -24,56 +24,54 @@ SQLITE_EXTENSION_INIT1
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
std::string stringFromTextArg(sqlite3_value *arg){
|
||||
const unsigned char *text=sqlite3_value_text(arg);
|
||||
int nBytes=sqlite3_value_bytes(arg);
|
||||
std::string res((const char *)text,nBytes);
|
||||
std::string stringFromTextArg(sqlite3_value *arg) {
|
||||
const unsigned char *text = sqlite3_value_text(arg);
|
||||
int nBytes = sqlite3_value_bytes(arg);
|
||||
std::string res((const char *)text, nBytes);
|
||||
return res;
|
||||
}
|
||||
|
||||
std::string stringFromBlobArg(sqlite3_value *arg){
|
||||
const void *blob=sqlite3_value_blob(arg);
|
||||
int nBytes=sqlite3_value_bytes(arg);
|
||||
std::string res((const char *)blob,nBytes);
|
||||
std::string stringFromBlobArg(sqlite3_value *arg) {
|
||||
const void *blob = sqlite3_value_blob(arg);
|
||||
int nBytes = sqlite3_value_bytes(arg);
|
||||
std::string res((const char *)blob, nBytes);
|
||||
return res;
|
||||
}
|
||||
|
||||
RDKit::ROMol *molFromBlobArg(sqlite3_value *arg){
|
||||
std::string pkl=stringFromBlobArg(arg);
|
||||
RDKit::ROMol *molFromBlobArg(sqlite3_value *arg) {
|
||||
std::string pkl = stringFromBlobArg(arg);
|
||||
RDKit::ROMol *m;
|
||||
try{
|
||||
try {
|
||||
m = new RDKit::ROMol(pkl);
|
||||
} catch (RDKit::MolPicklerException &){
|
||||
m=0;
|
||||
} catch (RDKit::MolPicklerException &) {
|
||||
m = 0;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
||||
|
||||
ExplicitBitVect *ebvFromBlobArg(sqlite3_value *arg){
|
||||
std::string pkl=stringFromBlobArg(arg);
|
||||
ExplicitBitVect *ebvFromBlobArg(sqlite3_value *arg) {
|
||||
std::string pkl = stringFromBlobArg(arg);
|
||||
ExplicitBitVect *ebv;
|
||||
try{
|
||||
try {
|
||||
ebv = new ExplicitBitVect(pkl);
|
||||
} catch (ValueErrorException &){
|
||||
ebv=0;
|
||||
} catch (ValueErrorException &) {
|
||||
ebv = 0;
|
||||
}
|
||||
return ebv;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
RDKit::SparseIntVect<T> *sivFromBlobArg(sqlite3_value *arg){
|
||||
std::string pkl=stringFromBlobArg(arg);
|
||||
RDKit::SparseIntVect<T> *sivFromBlobArg(sqlite3_value *arg) {
|
||||
std::string pkl = stringFromBlobArg(arg);
|
||||
RDKit::SparseIntVect<T> *siv;
|
||||
try{
|
||||
try {
|
||||
siv = new RDKit::SparseIntVect<T>(pkl);
|
||||
} catch (ValueErrorException &){
|
||||
siv=0;
|
||||
} catch (ValueErrorException &) {
|
||||
siv = 0;
|
||||
}
|
||||
return siv;
|
||||
}
|
||||
|
||||
|
||||
/* ---------------------------------
|
||||
|
||||
Benchmarking results.
|
||||
@@ -82,263 +80,249 @@ RDKit::SparseIntVect<T> *sivFromBlobArg(sqlite3_value *arg){
|
||||
|
||||
Simple access: select count(*) from molecules where length(molpkl)>40;
|
||||
0.3s
|
||||
depickle : select count(*) from molecules where rdk_molNumAtoms(molpkl)>40;
|
||||
depickle : select count(*) from molecules where
|
||||
rdk_molNumAtoms(molpkl)>40;
|
||||
11.3s
|
||||
|
||||
substruct1 : select count(*) from molecules where
|
||||
|
||||
substruct1 : select count(*) from molecules where
|
||||
rdk_molHasSubstruct(molpkl,'c1ncncn1');
|
||||
18.0s
|
||||
|
||||
substruct2 : select count(*) from molecules where
|
||||
substruct2 : select count(*) from molecules where
|
||||
rdk_molHasSubstruct(molpkl,'[#6;r10]');
|
||||
15.8
|
||||
|
||||
3 Oct 2007:
|
||||
depickle : select count(*) from molecules where rdk_molNumAtoms(molpkl)>40;
|
||||
depickle : select count(*) from molecules where
|
||||
rdk_molNumAtoms(molpkl)>40;
|
||||
9.4s
|
||||
mw : select count(*) from molecules where rdk_molAMW(molpkl)<200;
|
||||
9.7s
|
||||
|
||||
|
||||
|
||||
|
||||
--------------------------------- */
|
||||
|
||||
|
||||
static void numAtomsFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(m){
|
||||
int res=m->getNumAtoms();
|
||||
static void numAtomsFunc(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (m) {
|
||||
int res = m->getNumAtoms();
|
||||
delete m;
|
||||
sqlite3_result_int(context, res);
|
||||
} else {
|
||||
std::string errorMsg="BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
std::string errorMsg = "BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
}
|
||||
}
|
||||
|
||||
static void molWtFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(m){
|
||||
double res=RDKit::Descriptors::CalcAMW(*m);
|
||||
static void molWtFunc(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (m) {
|
||||
double res = RDKit::Descriptors::CalcAMW(*m);
|
||||
delete m;
|
||||
sqlite3_result_double(context, res);
|
||||
} else {
|
||||
std::string errorMsg="BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
std::string errorMsg = "BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
}
|
||||
}
|
||||
|
||||
static void molLogPFunc(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(m){
|
||||
double res,tmp;
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(*m,res,tmp);
|
||||
static void molLogPFunc(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (m) {
|
||||
double res, tmp;
|
||||
RDKit::Descriptors::CalcCrippenDescriptors(*m, res, tmp);
|
||||
delete m;
|
||||
sqlite3_result_double(context, res);
|
||||
} else {
|
||||
std::string errorMsg="BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
std::string errorMsg = "BLOB could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
}
|
||||
}
|
||||
|
||||
static void smilesToBlob(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
std::string smiles=stringFromTextArg(argv[0]);
|
||||
RDKit::ROMol *m=0;
|
||||
try{
|
||||
m=RDKit::SmilesToMol(smiles);
|
||||
} catch(RDKit::MolSanitizeException &){
|
||||
m=0;
|
||||
static void smilesToBlob(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
std::string smiles = stringFromTextArg(argv[0]);
|
||||
RDKit::ROMol *m = 0;
|
||||
try {
|
||||
m = RDKit::SmilesToMol(smiles);
|
||||
} catch (RDKit::MolSanitizeException &) {
|
||||
m = 0;
|
||||
}
|
||||
if(m){
|
||||
if (m) {
|
||||
std::string text;
|
||||
RDKit::MolPickler::pickleMol(*m,text);
|
||||
RDKit::MolPickler::pickleMol(*m, text);
|
||||
delete m;
|
||||
sqlite3_result_blob(context, text.c_str(), text.length(), SQLITE_TRANSIENT );
|
||||
sqlite3_result_blob(context, text.c_str(), text.length(), SQLITE_TRANSIENT);
|
||||
} else {
|
||||
std::string errorMsg="SMILES could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
std::string errorMsg = "SMILES could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
}
|
||||
}
|
||||
|
||||
static void molHasSubstruct(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(!m){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
static void molHasSubstruct(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (!m) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string smarts=stringFromTextArg(argv[1]);
|
||||
std::string smarts = stringFromTextArg(argv[1]);
|
||||
|
||||
std::map<std::string,boost::any> &molMap=
|
||||
*static_cast<std::map<std::string,boost::any> *>(sqlite3_user_data(context));
|
||||
RDKit::ROMol *patt=0;
|
||||
if(molMap.find(smarts)!=molMap.end()){
|
||||
patt=boost::any_cast<RDKit::ROMOL_SPTR>(molMap[smarts]).get();
|
||||
std::map<std::string, boost::any> &molMap =
|
||||
*static_cast<std::map<std::string, boost::any> *>(
|
||||
sqlite3_user_data(context));
|
||||
RDKit::ROMol *patt = 0;
|
||||
if (molMap.find(smarts) != molMap.end()) {
|
||||
patt = boost::any_cast<RDKit::ROMOL_SPTR>(molMap[smarts]).get();
|
||||
} else {
|
||||
patt=static_cast<RDKit::ROMol *>(RDKit::SmartsToMol(smarts));
|
||||
molMap[smarts]=boost::any(RDKit::ROMOL_SPTR(patt));
|
||||
patt = static_cast<RDKit::ROMol *>(RDKit::SmartsToMol(smarts));
|
||||
molMap[smarts] = boost::any(RDKit::ROMOL_SPTR(patt));
|
||||
}
|
||||
if(!patt){
|
||||
std::string errorMsg="SMARTS (argument 2) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
if (!patt) {
|
||||
std::string errorMsg =
|
||||
"SMARTS (argument 2) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
RDKit::MatchVectType match;
|
||||
int res=RDKit::SubstructMatch(*m,*patt,match,true,false,true);
|
||||
int res = RDKit::SubstructMatch(*m, *patt, match, true, false, true);
|
||||
delete m;
|
||||
sqlite3_result_int(context, res);
|
||||
}
|
||||
|
||||
static void molSubstructCount(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(!m){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
static void molSubstructCount(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (!m) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
|
||||
std::string smarts=stringFromTextArg(argv[1]);
|
||||
std::string smarts = stringFromTextArg(argv[1]);
|
||||
|
||||
std::map<std::string,boost::any> &molMap=
|
||||
*static_cast<std::map<std::string,boost::any> *>(sqlite3_user_data(context));
|
||||
RDKit::ROMol *patt=0;
|
||||
if(molMap.find(smarts)!=molMap.end()){
|
||||
patt=boost::any_cast<RDKit::ROMOL_SPTR>(molMap[smarts]).get();
|
||||
std::map<std::string, boost::any> &molMap =
|
||||
*static_cast<std::map<std::string, boost::any> *>(
|
||||
sqlite3_user_data(context));
|
||||
RDKit::ROMol *patt = 0;
|
||||
if (molMap.find(smarts) != molMap.end()) {
|
||||
patt = boost::any_cast<RDKit::ROMOL_SPTR>(molMap[smarts]).get();
|
||||
} else {
|
||||
patt=static_cast<RDKit::ROMol *>(RDKit::SmartsToMol(smarts));
|
||||
molMap[smarts]=boost::any(RDKit::ROMOL_SPTR(patt));
|
||||
patt = static_cast<RDKit::ROMol *>(RDKit::SmartsToMol(smarts));
|
||||
molMap[smarts] = boost::any(RDKit::ROMOL_SPTR(patt));
|
||||
}
|
||||
if(!patt){
|
||||
std::string errorMsg="SMARTS (argument 2) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
if (!patt) {
|
||||
std::string errorMsg =
|
||||
"SMARTS (argument 2) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
std::vector<RDKit::MatchVectType> matches;
|
||||
int res=RDKit::SubstructMatch(*m,*patt,matches,true,true,false);
|
||||
int res = RDKit::SubstructMatch(*m, *patt, matches, true, true, false);
|
||||
delete m;
|
||||
sqlite3_result_int(context, res);
|
||||
}
|
||||
|
||||
static void blobToRDKitFingerprint(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(!m){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
static void blobToRDKitFingerprint(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (!m) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
ExplicitBitVect *fp=RDKit::DaylightFingerprintMol(*m,1,7,2048,4,true,0.3,128);
|
||||
std::string text=fp->toString();
|
||||
ExplicitBitVect *fp =
|
||||
RDKit::DaylightFingerprintMol(*m, 1, 7, 2048, 4, true, 0.3, 128);
|
||||
std::string text = fp->toString();
|
||||
delete fp;
|
||||
delete m;
|
||||
sqlite3_result_text(context, text.c_str(), text.length(), SQLITE_TRANSIENT );
|
||||
sqlite3_result_text(context, text.c_str(), text.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
static void blobToAtomPairFingerprint(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
RDKit::ROMol *m=molFromBlobArg(argv[0]);
|
||||
if(!m){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
static void blobToAtomPairFingerprint(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
RDKit::ROMol *m = molFromBlobArg(argv[0]);
|
||||
if (!m) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into a molecule";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
RDKit::SparseIntVect<int> *fp=RDKit::Descriptors::AtomPairs::getAtomPairFingerprint(*m);
|
||||
std::string text=fp->toString();
|
||||
RDKit::SparseIntVect<int> *fp =
|
||||
RDKit::Descriptors::AtomPairs::getAtomPairFingerprint(*m);
|
||||
std::string text = fp->toString();
|
||||
delete fp;
|
||||
delete m;
|
||||
sqlite3_result_text(context, text.c_str(), text.length(), SQLITE_TRANSIENT );
|
||||
sqlite3_result_text(context, text.c_str(), text.length(), SQLITE_TRANSIENT);
|
||||
}
|
||||
|
||||
static void bvTanimotoSim(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
ExplicitBitVect *bv1=ebvFromBlobArg(argv[0]);
|
||||
if(!bv1){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into a bit vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
static void bvTanimotoSim(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
ExplicitBitVect *bv1 = ebvFromBlobArg(argv[0]);
|
||||
if (!bv1) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into a bit vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
ExplicitBitVect *bv2=ebvFromBlobArg(argv[1]);
|
||||
if(!bv2){
|
||||
ExplicitBitVect *bv2 = ebvFromBlobArg(argv[1]);
|
||||
if (!bv2) {
|
||||
delete bv1;
|
||||
std::string errorMsg="BLOB (argument 2) could not be converted into a bit vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 2) could not be converted into a bit vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
double res=SimilarityWrapper(*bv1,*bv2,TanimotoSimilarity);
|
||||
double res = SimilarityWrapper(*bv1, *bv2, TanimotoSimilarity);
|
||||
delete bv1;
|
||||
delete bv2;
|
||||
sqlite3_result_double(context, res);
|
||||
}
|
||||
static void ucvTanimotoSim(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
static void ucvTanimotoSim(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
// table from Andrew Dalke:
|
||||
static const unsigned int popCounts[] = {
|
||||
0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
|
||||
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
||||
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
||||
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
||||
1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
|
||||
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
||||
2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
|
||||
3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
|
||||
0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5,
|
||||
3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
|
||||
4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8,
|
||||
};
|
||||
const unsigned char *t1=(const unsigned char *)sqlite3_value_blob(argv[0]);
|
||||
int nB1=sqlite3_value_bytes(argv[0]);
|
||||
const unsigned char *t2=(const unsigned char *)sqlite3_value_blob(argv[1]);
|
||||
int nB2=sqlite3_value_bytes(argv[1]);
|
||||
if(nB1!=nB2){
|
||||
std::string errorMsg="bit vectors not ths same length";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
const unsigned char *t1 = (const unsigned char *)sqlite3_value_blob(argv[0]);
|
||||
int nB1 = sqlite3_value_bytes(argv[0]);
|
||||
const unsigned char *t2 = (const unsigned char *)sqlite3_value_blob(argv[1]);
|
||||
int nB2 = sqlite3_value_bytes(argv[1]);
|
||||
if (nB1 != nB2) {
|
||||
std::string errorMsg = "bit vectors not ths same length";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
unsigned int x=0,y=0,z=0;
|
||||
for(unsigned int i=0;i<(unsigned int)nB1;++i){
|
||||
y+= popCounts[*t1];
|
||||
z+= popCounts[*t2];
|
||||
x+= popCounts[(*t1)&(*t2)];
|
||||
unsigned int x = 0, y = 0, z = 0;
|
||||
for (unsigned int i = 0; i < (unsigned int)nB1; ++i) {
|
||||
y += popCounts[*t1];
|
||||
z += popCounts[*t2];
|
||||
x += popCounts[(*t1) & (*t2)];
|
||||
++t1;
|
||||
++t2;
|
||||
}
|
||||
double res=0;
|
||||
if(y+z-x>0){
|
||||
res=double(x) / (y+z-x);
|
||||
double res = 0;
|
||||
if (y + z - x > 0) {
|
||||
res = double(x) / (y + z - x);
|
||||
}
|
||||
sqlite3_result_double(context, res);
|
||||
}
|
||||
@@ -370,131 +354,133 @@ static void sivDiceSim(
|
||||
}
|
||||
#else
|
||||
// faster, just parse the format directly
|
||||
static void sivDiceSim(
|
||||
sqlite3_context *context,
|
||||
int argc,
|
||||
sqlite3_value **argv
|
||||
){
|
||||
const unsigned char *t1=(const unsigned char *)sqlite3_value_blob(argv[0]);
|
||||
int nB1=sqlite3_value_bytes(argv[0]);
|
||||
const unsigned char *t2=(const unsigned char *)sqlite3_value_blob(argv[1]);
|
||||
int nB2=sqlite3_value_bytes(argv[1]);
|
||||
static void sivDiceSim(sqlite3_context *context, int argc,
|
||||
sqlite3_value **argv) {
|
||||
const unsigned char *t1 = (const unsigned char *)sqlite3_value_blob(argv[0]);
|
||||
int nB1 = sqlite3_value_bytes(argv[0]);
|
||||
const unsigned char *t2 = (const unsigned char *)sqlite3_value_blob(argv[1]);
|
||||
int nB2 = sqlite3_value_bytes(argv[1]);
|
||||
|
||||
// check the version flags:
|
||||
boost::uint32_t tmp;
|
||||
tmp = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
if(tmp!=ci_SPARSEINTVECT_VERSION){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into an int vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
if (tmp != ci_SPARSEINTVECT_VERSION) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into an int vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
tmp = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
if(tmp!=ci_SPARSEINTVECT_VERSION){
|
||||
std::string errorMsg="BLOB (argument 2) could not be converted into an int vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
if (tmp != ci_SPARSEINTVECT_VERSION) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 2) could not be converted into an int vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
|
||||
// check the element size:
|
||||
tmp = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
if(tmp!=sizeof(boost::uint32_t)){
|
||||
std::string errorMsg="BLOB (argument 1) could not be converted into an uint32_t vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
if (tmp != sizeof(boost::uint32_t)) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 1) could not be converted into an uint32_t vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
tmp = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
if(tmp!=sizeof(boost::uint32_t)){
|
||||
std::string errorMsg="BLOB (argument 2) could not be converted into an uint32_t vector";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
if (tmp != sizeof(boost::uint32_t)) {
|
||||
std::string errorMsg =
|
||||
"BLOB (argument 2) could not be converted into an uint32_t vector";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
|
||||
double res=0.;
|
||||
|
||||
double res = 0.;
|
||||
// start reading:
|
||||
boost::uint32_t len1,len2;
|
||||
boost::uint32_t len1, len2;
|
||||
len1 = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
len2 = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
if(len1!=len2){
|
||||
std::string errorMsg="attempt to compare fingerprints of different length";
|
||||
sqlite3_result_error(context,errorMsg.c_str(),errorMsg.length());
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
if (len1 != len2) {
|
||||
std::string errorMsg =
|
||||
"attempt to compare fingerprints of different length";
|
||||
sqlite3_result_error(context, errorMsg.c_str(), errorMsg.length());
|
||||
return;
|
||||
}
|
||||
|
||||
boost::uint32_t nElem1,nElem2;
|
||||
boost::uint32_t nElem1, nElem2;
|
||||
nElem1 = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
nElem2 = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
|
||||
if(!nElem1 || !nElem2){
|
||||
res=0.0;
|
||||
if (!nElem1 || !nElem2) {
|
||||
res = 0.0;
|
||||
sqlite3_result_double(context, res);
|
||||
}
|
||||
|
||||
double v1Sum=0,v2Sum=0,numer=0;
|
||||
boost::uint32_t idx1=0;
|
||||
double v1Sum = 0, v2Sum = 0, numer = 0;
|
||||
boost::uint32_t idx1 = 0;
|
||||
boost::int32_t v1;
|
||||
boost::uint32_t idx2=0;
|
||||
boost::uint32_t idx2 = 0;
|
||||
boost::int32_t v2;
|
||||
idx1 = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
v1 = *(reinterpret_cast<const boost::int32_t *>(t1));
|
||||
t1+=sizeof(boost::int32_t);
|
||||
t1 += sizeof(boost::int32_t);
|
||||
nElem1--;
|
||||
v1Sum += v1;
|
||||
|
||||
idx2 = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
v2 = *(reinterpret_cast<const boost::int32_t *>(t2));
|
||||
t2+=sizeof(boost::int32_t);
|
||||
t2 += sizeof(boost::int32_t);
|
||||
nElem2--;
|
||||
v2Sum += v2;
|
||||
|
||||
while(1){
|
||||
while(nElem2 && idx2<idx1){
|
||||
while (1) {
|
||||
while (nElem2 && idx2 < idx1) {
|
||||
idx2 = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
v2 = *(reinterpret_cast<const boost::int32_t *>(t2));
|
||||
t2+=sizeof(boost::int32_t);
|
||||
t2 += sizeof(boost::int32_t);
|
||||
nElem2--;
|
||||
v2Sum += v2;
|
||||
}
|
||||
if(idx2==idx1 ){
|
||||
//std::cerr<<" --- "<<idx1<<" "<<v1<<" - "<<idx2<<" "<<v2<<std::endl;
|
||||
numer += std::min(v1,v2);
|
||||
if (idx2 == idx1) {
|
||||
// std::cerr<<" --- "<<idx1<<" "<<v1<<" - "<<idx2<<" "<<v2<<std::endl;
|
||||
numer += std::min(v1, v2);
|
||||
}
|
||||
if(nElem1){
|
||||
if (nElem1) {
|
||||
idx1 = *(reinterpret_cast<const boost::uint32_t *>(t1));
|
||||
t1+=sizeof(boost::uint32_t);
|
||||
t1 += sizeof(boost::uint32_t);
|
||||
v1 = *(reinterpret_cast<const boost::int32_t *>(t1));
|
||||
t1+=sizeof(boost::int32_t);
|
||||
t1 += sizeof(boost::int32_t);
|
||||
nElem1--;
|
||||
v1Sum += v1;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
while(nElem2){
|
||||
while (nElem2) {
|
||||
idx2 = *(reinterpret_cast<const boost::uint32_t *>(t2));
|
||||
t2+=sizeof(boost::uint32_t);
|
||||
t2 += sizeof(boost::uint32_t);
|
||||
v2 = *(reinterpret_cast<const boost::int32_t *>(t2));
|
||||
t2+=sizeof(boost::int32_t);
|
||||
t2 += sizeof(boost::int32_t);
|
||||
nElem2--;
|
||||
v2Sum += v2;
|
||||
}
|
||||
double denom=v1Sum+v2Sum;
|
||||
if(fabs(denom)<1e-6){
|
||||
res=0.0;
|
||||
double denom = v1Sum + v2Sum;
|
||||
if (fabs(denom) < 1e-6) {
|
||||
res = 0.0;
|
||||
} else {
|
||||
res = 2.*numer/denom;
|
||||
res = 2. * numer / denom;
|
||||
}
|
||||
//std::cerr<<" "<<v1Sum<<" "<<v2Sum<<" "<<numer<<" "<<res<<std::endl;
|
||||
// std::cerr<<" "<<v1Sum<<" "<<v2Sum<<" "<<numer<<" "<<res<<std::endl;
|
||||
sqlite3_result_double(context, res);
|
||||
}
|
||||
#endif
|
||||
@@ -504,34 +490,33 @@ static void sivDiceSim(
|
||||
** modules here. This is usually the only exported symbol in
|
||||
** the shared library.
|
||||
*/
|
||||
extern "C" int sqlite3_extension_init(
|
||||
sqlite3 *db,
|
||||
char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi
|
||||
){
|
||||
extern "C" int sqlite3_extension_init(sqlite3 *db, char **pzErrMsg,
|
||||
const sqlite3_api_routines *pApi) {
|
||||
SQLITE_EXTENSION_INIT2(pApi);
|
||||
std::map<std::string,boost::any> *molMap=new std::map<std::string,boost::any>();
|
||||
sqlite3_create_function(db, "rdk_molNumAtoms", 1, SQLITE_ANY, 0, numAtomsFunc, 0, 0);
|
||||
std::map<std::string, boost::any> *molMap =
|
||||
new std::map<std::string, boost::any>();
|
||||
sqlite3_create_function(db, "rdk_molNumAtoms", 1, SQLITE_ANY, 0, numAtomsFunc,
|
||||
0, 0);
|
||||
sqlite3_create_function(db, "rdk_molAMW", 1, SQLITE_ANY, 0, molWtFunc, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_smilesToBlob", 1, SQLITE_ANY, 0, smilesToBlob, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_smilesToBlob", 1, SQLITE_ANY, 0,
|
||||
smilesToBlob, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_molToRDKitFP", 1, SQLITE_ANY, 0,
|
||||
blobToRDKitFingerprint, 0, 0);
|
||||
blobToRDKitFingerprint, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_bvTanimotoSim", 2, SQLITE_ANY, 0,
|
||||
bvTanimotoSim, 0, 0);
|
||||
bvTanimotoSim, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_ucvTanimotoSim", 2, SQLITE_ANY, 0,
|
||||
ucvTanimotoSim, 0, 0);
|
||||
ucvTanimotoSim, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_molToAtomPairFP", 1, SQLITE_ANY, 0,
|
||||
blobToAtomPairFingerprint, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_sivDiceSim", 2, SQLITE_ANY, 0,
|
||||
sivDiceSim, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_sivDiceSim2", 2, SQLITE_ANY, 0,
|
||||
sivDiceSim2, 0, 0);
|
||||
blobToAtomPairFingerprint, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_sivDiceSim", 2, SQLITE_ANY, 0, sivDiceSim, 0,
|
||||
0);
|
||||
sqlite3_create_function(db, "rdk_sivDiceSim2", 2, SQLITE_ANY, 0, sivDiceSim2,
|
||||
0, 0);
|
||||
sqlite3_create_function(db, "rdk_molHasSubstruct", 2, SQLITE_ANY,
|
||||
static_cast<void *>(molMap),
|
||||
molHasSubstruct, 0, 0);
|
||||
static_cast<void *>(molMap), molHasSubstruct, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_molSubstructCount", 2, SQLITE_ANY,
|
||||
static_cast<void *>(molMap),
|
||||
molSubstructCount, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_molLogP", 1, SQLITE_ANY, 0, molLogPFunc, 0, 0);
|
||||
static_cast<void *>(molMap), molSubstructCount, 0, 0);
|
||||
sqlite3_create_function(db, "rdk_molLogP", 1, SQLITE_ANY, 0, molLogPFunc, 0,
|
||||
0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user