Esempio n. 1
0
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);
  }
Esempio n. 4
0
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;
}