void test6() { BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl; BOOST_LOG(rdErrorLog) << "Feature Location testing." << std::endl; ROMol *testMol; Conformer *conf; std::string inText; FeatSPtrList featSPtrs; boost::shared_ptr<MolChemicalFeature> featSPtr; MolChemicalFeatureFactory *factory; MolChemicalFeatureDef::CollectionType::value_type featDef; inText = "DefineFeature HDonor1 [N,O;!H0]\n" " Family HBondDonor\n" " Weights 1.0\n" "EndFeature\n" "DefineFeature Carboxyl1 C(=O)[O;H1,-]\n" " Family ZnBinder\n" " Weights 1.0,1.0,1.0\n" "EndFeature\n"; factory = buildFeatureFactory(inText); TEST_ASSERT(factory); TEST_ASSERT(factory->getNumFeatureDefs() == 2); testMol = SmilesToMol("C(=O)O"); TEST_ASSERT(testMol); conf = new Conformer(3); testMol->addConformer(conf); conf->setAtomPos(0, RDGeom::Point3D(0, 0, 0.0)); conf->setAtomPos(1, RDGeom::Point3D(1.2, 0, 0.0)); conf->setAtomPos(2, RDGeom::Point3D(0, 1.5, 0.0)); featSPtrs = factory->getFeaturesForMol(*testMol); TEST_ASSERT(featSPtrs.size() == 2); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "HBondDonor"); TEST_ASSERT(featSPtr->getType() == "HDonor1"); TEST_ASSERT(feq(featSPtr->getPos().x, 0.0)); TEST_ASSERT(feq(featSPtr->getPos().y, 1.5)); TEST_ASSERT(feq(featSPtr->getPos().z, 0.0)); featSPtr = *(++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "ZnBinder"); TEST_ASSERT(featSPtr->getType() == "Carboxyl1"); TEST_ASSERT(feq(featSPtr->getPos().x, 0.4)); TEST_ASSERT(feq(featSPtr->getPos().y, 0.5)); TEST_ASSERT(feq(featSPtr->getPos().z, 0.0)); delete testMol; delete factory; BOOST_LOG(rdErrorLog) << " done" << std::endl; }
void test1Canonicalization() { ROMol *mol = SmilesToMol("C", 0, 1); Conformer *conf = new Conformer(1); conf->setAtomPos(0, RDGeom::Point3D(4.0, 5.0, 6.0)); int cid = mol->addConformer(conf, true); RDGeom::Point3D pt = computeCentroid(*conf); CHECK_INVARIANT(comparePts(pt, RDGeom::Point3D(4.0, 5.0, 6.0)), ""); RDGeom::Transform3D *trans = computeCanonicalTransform(*conf); transformConformer(*conf, *trans); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(0.0, 0.0, 0.0)), ""); conf->setAtomPos(0, RDGeom::Point3D(4.0, 5.0, 6.0)); canonicalizeConformer(*conf); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(0.0, 0.0, 0.0)), ""); delete mol; //delete conf; delete trans; // lets try two points now mol = SmilesToMol("CC", 0, 1); conf = new Conformer(2); conf->setAtomPos(0, RDGeom::Point3D(0.0, 0.0, 0.0)); conf->setAtomPos(1, RDGeom::Point3D(1.5, 0.0, 0.0)); cid = mol->addConformer(conf, true); trans = computeCanonicalTransform(*conf); canonicalizeConformer(*conf); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(-0.75, 0.0, 0.0)), ""); CHECK_INVARIANT(comparePts(conf->getAtomPos(1), RDGeom::Point3D(0.75, 0.0, 0.0)), ""); conf->setAtomPos(0, RDGeom::Point3D(0.0, 0.0, 0.0)); conf->setAtomPos(1, RDGeom::Point3D(0.0, 1.5, 0.0)); trans = computeCanonicalTransform(*conf); canonicalizeConformer(*conf); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(-0.75, 0.0, 0.0)), ""); CHECK_INVARIANT(comparePts(conf->getAtomPos(1), RDGeom::Point3D(0.75, 0.0, 0.0)), ""); delete mol; delete trans; mol = SmilesToMol("CC", 0, 1); conf = new Conformer(2); conf->setAtomPos(0, RDGeom::Point3D(0.0, 0.0, 0.0)); conf->setAtomPos(1, RDGeom::Point3D(1.5, 0.0, 0.0)); cid = mol->addConformer(conf, true); trans = computeCanonicalTransform(*conf); transformConformer(*conf, *trans); canonicalizeConformer(*conf); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(-0.75, 0.0, 0.0)), ""); CHECK_INVARIANT(comparePts(conf->getAtomPos(1), RDGeom::Point3D(0.75, 0.0, 0.0)), ""); delete mol; delete trans; mol = SmilesToMol("C1CC1", 0, 1); conf = new Conformer(3); conf->setAtomPos(0, RDGeom::Point3D(0.58, -0.66, -0.08)); conf->setAtomPos(1, RDGeom::Point3D(-0.88, -0.18, -0.04)); conf->setAtomPos(2, RDGeom::Point3D(.26, 0.82, 0.14)); cid = mol->addConformer(conf, true); //trans = computeCanonicalTransform(*conf); //transformConformer(*conf, *trans); canonicalizeConformer(*conf); CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(-0.6418, 0.6158, 0.0)), ""); CHECK_INVARIANT(comparePts(conf->getAtomPos(1), RDGeom::Point3D(-0.2029, -0.8602, 0.0)), ""); CHECK_INVARIANT(comparePts(conf->getAtomPos(2), RDGeom::Point3D(0.8447, 0.2445, 0.0)), ""); MolToMolFile(*mol, "junk.mol", 0); //CHECK_INVARIANT(comparePts(conf->getAtomPos(0), RDGeom::Point3D(-0.75, 0.0, 0.0)), ""); //CHECK_INVARIANT(comparePts(conf->getAtomPos(1), RDGeom::Point3D(0.75, 0.0, 0.0)), ""); delete mol; std::string rdbase = getenv("RDBASE"); std::string fname1 = rdbase + "/Code/GraphMol/MolTransforms/test_data/1oir.mol"; mol = MolFileToMol(fname1); std::string fname2 = rdbase + "/Code/GraphMol/MolTransforms/test_data/1oir_canon.mol"; ROMol *mol2 = MolFileToMol(fname2); Conformer &conf1 = mol->getConformer(0); canonicalizeConformer(conf1); Conformer &conf2 = mol2->getConformer(); unsigned int i, nats = mol->getNumAtoms(); for (i = 0; i < nats; ++i) { CHECK_INVARIANT(comparePts(conf1.getAtomPos(i), conf2.getAtomPos(i)), ""); } delete mol; delete mol2; }
ROMol *TDTMolSupplier::parseMol(std::string inLine) { PRECONDITION(dp_inStream, "no stream"); Utils::LocaleSwitcher ls; std::size_t startP = inLine.find("<"); std::size_t endP = inLine.find_last_of(">"); std::string smiles = inLine.substr(startP + 1, endP - startP - 1); ROMol *res = SmilesToMol(smiles, 0, df_sanitize); if (res && res->getNumAtoms() > 0) { // ----------- // Process the properties: d_line++; std::getline(*dp_inStream, inLine); while (!dp_inStream->eof() && inLine.find("|") != 0) { endP = inLine.find("<"); std::string propName = inLine.substr(0, endP); boost::trim_if(propName, boost::is_any_of(" \t")); startP = endP + 1; if (propName == common_properties::TWOD && d_confId2D >= 0) { std::string rest = inLine.substr(startP, inLine.size() - startP); std::vector<double> coords; TDTParseUtils::ParseNumberList(rest, coords, dp_inStream); Conformer *conf = new Conformer(res->getNumAtoms()); conf->setId(d_confId2D); conf->set3D(false); for (unsigned int atIdx = 0; atIdx < res->getNumAtoms(); atIdx++) { if (2 * atIdx + 1 < coords.size()) { conf->setAtomPos( atIdx, RDGeom::Point3D(coords[2 * atIdx], coords[2 * atIdx + 1], 0.0)); } else { // we're going to let this slide... but maybe we should do something // else? } } res->addConformer(conf, false); } else if (propName == "3D" && d_confId3D >= 0) { std::string rest = inLine.substr(startP, inLine.size() - startP); std::vector<double> coords; TDTParseUtils::ParseNumberList(rest, coords, dp_inStream); Conformer *conf = new Conformer(res->getNumAtoms()); conf->setId(d_confId3D); conf->set3D(true); for (unsigned int atIdx = 0; atIdx < res->getNumAtoms(); atIdx++) { if (3 * atIdx + 2 < coords.size()) { conf->setAtomPos( atIdx, RDGeom::Point3D(coords[3 * atIdx], coords[3 * atIdx + 1], coords[3 * atIdx + 2])); } else { // we're going to let this slide... but maybe we should do something // else? } } res->addConformer(conf, false); } else { endP = inLine.find_last_of(">"); if (endP == std::string::npos) { std::ostringstream errout; errout << "no end tag found for property" << propName; throw FileParseException(errout.str()); } else { std::string propVal = inLine.substr(startP, endP - startP); res->setProp(propName, propVal); if (propName == d_nameProp) res->setProp(common_properties::_Name, propVal); } } std::getline(*dp_inStream, inLine); } } return res; }