void testIssue346() { BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl; BOOST_LOG(rdErrorLog) << "Test Issue346" << std::endl; std::string rdbase = getenv("RDBASE"); std::string fName = rdbase + "/Code/GraphMol/MolChemicalFeatures/test_data/featDef2.txt"; MolChemicalFeatureFactory *factory; MolChemicalFeatureDef::CollectionType::const_iterator featDefIt; MolChemicalFeatureDef::CollectionType::value_type featDef; std::ifstream inStream(fName.c_str()); TEST_ASSERT(inStream.is_open()); std::istream &instrm = static_cast<std::istream &>(inStream); factory = buildFeatureFactory(instrm); TEST_ASSERT(factory); TEST_ASSERT(factory->getNumFeatureDefs() == 2); featDefIt = factory->beginFeatureDefs(); featDef = *featDefIt; TEST_ASSERT(featDef->getFamily() == "HBondDonor"); featDefIt++; featDef = *featDefIt; TEST_ASSERT(featDefIt != factory->endFeatureDefs()); TEST_ASSERT(featDef->getFamily() == "HBondAcceptor"); featDefIt++; TEST_ASSERT(featDefIt == factory->endFeatureDefs()); delete (factory); BOOST_LOG(rdErrorLog) << " done" << std::endl; }
python::dict getFeatureDefs(const MolChemicalFeatureFactory &factory){ python::dict res; MolChemicalFeatureDef::CollectionType::const_iterator iter; for(iter=factory.beginFeatureDefs();iter!=factory.endFeatureDefs();++iter){ std::string key= (*iter)->getFamily()+"."+(*iter)->getType(); res[key]=(*iter)->getSmarts(); } return res; }
python::tuple getFeatureFamilies(const MolChemicalFeatureFactory &factory){ python::list res; MolChemicalFeatureDef::CollectionType::const_iterator iter; for(iter=factory.beginFeatureDefs();iter!=factory.endFeatureDefs();++iter){ std::string fam= (*iter)->getFamily(); if(res.count(fam)==0) res.append(fam); } return python::tuple(res); }
void testIssue347() { BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl; BOOST_LOG(rdErrorLog) << "Test Issue347" << std::endl; ROMol *testMol; MolChemicalFeatureFactory *factory; MolChemicalFeatureDef::CollectionType::const_iterator featDefIt; MolChemicalFeatureDef::CollectionType::value_type featDef; FeatSPtrList featSPtrs; boost::shared_ptr<MolChemicalFeature> featSPtr; std::string fdef; fdef = "DefineFeature CTriplet [C][C][C]\n" " Family LumpedHydrophobe\n" " Weights 1.0,1.0,1.0\n" "EndFeature\n" "DefineFeature CPair [C][C]\n" " Family LumpedHydrophobe\n" " Weights 1.0,1.0\n" "EndFeature\n"; factory = buildFeatureFactory(fdef); TEST_ASSERT(factory); TEST_ASSERT(factory->getNumFeatureDefs() == 2); featDefIt = factory->beginFeatureDefs(); featDef = *featDefIt; TEST_ASSERT(featDef->getFamily() == "LumpedHydrophobe"); featDefIt++; featDef = *featDefIt; TEST_ASSERT(featDef->getFamily() == "LumpedHydrophobe"); featDefIt++; TEST_ASSERT(featDefIt == factory->endFeatureDefs()); testMol = SmilesToMol("CCC"); TEST_ASSERT(testMol); featSPtrs = factory->getFeaturesForMol(*testMol); TEST_ASSERT(featSPtrs.size() == 1); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "LumpedHydrophobe"); TEST_ASSERT(featSPtr->getType() == "CTriplet"); delete factory; // now reverse the order and we should get two matches: fdef = "DefineFeature CPair [C][C]\n" " Family LumpedHydrophobe\n" " Weights 1.0,1.0\n" "EndFeature\n" "DefineFeature CTriplet [C][C][C]\n" " Family LumpedHydrophobe\n" " Weights 1.0,1.0,1.0\n" "EndFeature\n"; factory = buildFeatureFactory(fdef); TEST_ASSERT(factory); TEST_ASSERT(factory->getNumFeatureDefs() == 2); featDefIt = factory->beginFeatureDefs(); featDef = *featDefIt; TEST_ASSERT(featDef->getFamily() == "LumpedHydrophobe"); featDefIt++; featDef = *featDefIt; TEST_ASSERT(featDef->getFamily() == "LumpedHydrophobe"); featDefIt++; TEST_ASSERT(featDefIt == factory->endFeatureDefs()); featSPtrs = factory->getFeaturesForMol(*testMol); TEST_ASSERT(featSPtrs.size() == 3); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "LumpedHydrophobe"); TEST_ASSERT(featSPtr->getType() == "CPair"); featSPtr = *(++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "LumpedHydrophobe"); TEST_ASSERT(featSPtr->getType() == "CPair"); featSPtr = *(++++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "LumpedHydrophobe"); TEST_ASSERT(featSPtr->getType() == "CTriplet"); delete factory; delete testMol; BOOST_LOG(rdErrorLog) << " done" << std::endl; }
void test5() { BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl; BOOST_LOG(rdErrorLog) << "FeatureFactory testing." << std::endl; ROMol *testMol; MatchVectType mv; 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 HAcceptor1 [N,O]\n" " Family HBondAcceptor\n" " Weights 1.0\n" "EndFeature\n"; factory = buildFeatureFactory(inText); TEST_ASSERT(factory); TEST_ASSERT(factory->getNumFeatureDefs() == 2); testMol = SmilesToMol("COCN"); TEST_ASSERT(testMol); featDef = *factory->beginFeatureDefs(); TEST_ASSERT(SubstructMatch(*testMol, *featDef->getPattern(), mv)); BOOST_LOG(rdErrorLog) << "1" << std::endl; TEST_ASSERT(mv.size() == 1); TEST_ASSERT(mv[0].first == 0); TEST_ASSERT(mv[0].second == 3); featDef = *(++factory->beginFeatureDefs()); TEST_ASSERT(SubstructMatch(*testMol, *featDef->getPattern(), mv)); BOOST_LOG(rdErrorLog) << "2" << std::endl; TEST_ASSERT(mv.size() == 1); TEST_ASSERT(mv[0].first == 0); TEST_ASSERT(mv[0].second == 1 || mv[0].second == 3); // Test using the factory to find features: featSPtrs = factory->getFeaturesForMol(*testMol); BOOST_LOG(rdErrorLog) << "3" << std::endl; TEST_ASSERT(featSPtrs.size() == 3); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "HBondDonor"); TEST_ASSERT(featSPtr->getType() == "HDonor1"); featSPtr = *(++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "HBondAcceptor"); TEST_ASSERT(featSPtr->getType() == "HAcceptor1"); featSPtr = *(++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "HBondAcceptor"); TEST_ASSERT(featSPtr->getType() == "HAcceptor1"); // Test limiting stuff with includeOnly featSPtrs = factory->getFeaturesForMol(*testMol, "HBondAcceptor"); BOOST_LOG(rdErrorLog) << "4" << std::endl; TEST_ASSERT(featSPtrs.size() == 2); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "HBondAcceptor"); TEST_ASSERT(featSPtr->getType() == "HAcceptor1"); featSPtr = *(++featSPtrs.begin()); TEST_ASSERT(featSPtr->getFamily() == "HBondAcceptor"); TEST_ASSERT(featSPtr->getType() == "HAcceptor1"); featSPtrs = factory->getFeaturesForMol(*testMol, "HBondDonor"); BOOST_LOG(rdErrorLog) << "5" << std::endl; TEST_ASSERT(featSPtrs.size() == 1); featSPtr = *featSPtrs.begin(); TEST_ASSERT(featSPtr->getFamily() == "HBondDonor"); TEST_ASSERT(featSPtr->getType() == "HDonor1"); featSPtrs = factory->getFeaturesForMol(*testMol, "NotPresent"); BOOST_LOG(rdErrorLog) << "6" << std::endl; TEST_ASSERT(featSPtrs.size() == 0); delete testMol; delete factory; BOOST_LOG(rdErrorLog) << " done" << std::endl; }