1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
|
// Created by Guillaume GODIN
// Copyright (C) 2012-2017 Greg Landrum
// @@ All Rights Reserved @@
//
// This file is part of the RDKit.
// The contents are covered by the terms of the BSD license
// which is included in the file license.txt, found at the root
// of the RDKit source tree.
//
#include <RDGeneral/test.h>
#include <RDGeneral/Invariant.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/FileParsers/MolSupplier.h>
#include <GraphMol/FileParsers/FileParsers.h>
#include <GraphMol/SmilesParse/SmilesWrite.h>
#include <RDGeneral/RDLog.h>
#include <vector>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <chrono> // for high_resolution_clock
#include <GraphMol/Descriptors/EEM.h>
void testEEM1() {
std::cout << "=>start test EEM\n";
std::string pathName = getenv("RDBASE");
std::string sdfName =
pathName + "/Code/GraphMol/Descriptors/test_data/setEEM1.sdf";
auto start = std::chrono::high_resolution_clock::now();
RDKit::SDMolSupplier reader(sdfName, true, false);
std::string fName =
pathName + "/Code/GraphMol/Descriptors/test_data/eem1.out";
std::ifstream instrm(fName.c_str());
std::string line;
std::vector<std::vector<std::string>> data;
while (std::getline(instrm, line)) {
std::string phrase;
std::vector<std::string> row;
std::stringstream ss(line);
while (std::getline(ss, phrase, ',')) {
row.push_back(phrase);
}
data.push_back(row);
}
int nDone = 0;
int errorMols = 0;
while (!reader.atEnd()) {
RDKit::ROMol *m = reader.next();
TEST_ASSERT(m);
std::string nm;
m->getProp("_Name", nm);
int errorAtoms = 0;
std::vector<std::string> myrow = data[nDone];
std::string inm = myrow[0];
TEST_ASSERT(inm == nm);
int confId = -1;
std::vector<double> charges;
RDKit::Descriptors::EEM(*m, charges, confId);
int numAtoms = m->getNumAtoms();
for (int i = 0; i < numAtoms; i++) {
double ref = atof(myrow[i + 2].c_str());
if (fabs(ref - charges[i]) >= 0.01) {
std::cout << inm << ","
<< "ref: " << ref << " ,val: " << charges[i]
<< "Symbol: " << m->getAtomWithIdx(i)->getSymbol() << "\n";
++errorAtoms;
}
// TEST_ASSERT(fabs(ref - charges[i]) < 0.01);
}
// if (nDone>1) {break;}
if (nDone % 100 == 0) {
std::cout << nDone << "\n";
}
if (errorAtoms > 0) {
std::cout << nDone << " " << inm << " " << errorAtoms << "\n";
++errorMols;
}
TEST_ASSERT(errorAtoms == 0);
delete m;
// break;
++nDone;
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "Errors:" << errorMols << "\n";
TEST_ASSERT(errorMols == 0);
BOOST_LOG(rdErrorLog) << "test on : " << nDone << " molecules done"
<< std::endl;
}
void testEEM2() {
std::cout << "=>start test EEM\n";
std::string pathName = getenv("RDBASE");
std::string sdfName =
pathName + "/Code/GraphMol/Descriptors/test_data/setEEM2.sdf";
auto start = std::chrono::high_resolution_clock::now();
RDKit::SDMolSupplier reader(sdfName, true, false);
std::string fName =
pathName + "/Code/GraphMol/Descriptors/test_data/eem2.out";
std::ifstream instrm(fName.c_str());
std::string line;
std::vector<std::vector<std::string>> data;
while (std::getline(instrm, line)) {
std::string phrase;
std::vector<std::string> row;
std::stringstream ss(line);
while (std::getline(ss, phrase, ',')) {
row.push_back(phrase);
}
data.push_back(row);
}
int nDone = 0;
int errorMols = 0;
while (!reader.atEnd()) {
RDKit::ROMol *m = reader.next();
TEST_ASSERT(m);
std::string nm;
m->getProp("_Name", nm);
int errorAtoms = 0;
std::vector<std::string> myrow = data[nDone];
std::string inm = myrow[0];
TEST_ASSERT(inm == nm);
int confId = -1;
std::vector<double> charges;
RDKit::Descriptors::EEM(*m, charges, confId);
int numAtoms = m->getNumAtoms();
for (int i = 0; i < numAtoms; i++) {
double ref = atof(myrow[i + 2].c_str());
if (fabs(ref - charges[i]) >= 0.01) {
std::cout << inm << ","
<< "ref: " << ref << " ,val: " << charges[i]
<< "Symbol: " << m->getAtomWithIdx(i)->getSymbol() << "\n";
++errorAtoms;
}
TEST_ASSERT(fabs(ref - charges[i]) < 0.01);
}
if (nDone % 100 == 0) {
std::cout << nDone << "\n";
}
if (errorAtoms > 0) {
std::cout << "id" << nDone << ", name:" << inm << "\n";
++errorMols;
std::cout << RDKit::MolToSmiles(*m) << "\n";
}
delete m;
++nDone;
}
auto finish = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed = finish - start;
std::cout << "Elapsed time: " << elapsed.count() << " s\n";
std::cout << "Errors Mols:" << errorMols << "\n";
BOOST_LOG(rdErrorLog) << "test on : " << nDone << " molecules done"
<< std::endl;
}
int main() {
RDLog::InitLogs();
testEEM1();
}
|