Beispiel #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;
 }
Beispiel #3
0
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;
}
  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);
  }
MolChemicalFeatureFactory *buildFeatureFactory(std::istream &inStream) {
  MolChemicalFeatureFactory *res = nullptr;
  MolChemicalFeatureDef::CollectionType featDefs;

  if (parseFeatureData(inStream, featDefs) == 0) {
    // everything parsed ok
    res = new MolChemicalFeatureFactory();
    // std::copy(featDefs.begin(),featDefs.end(),res->beginFeatureDefs());
    for (MolChemicalFeatureDef::CollectionType::const_iterator ci =
             featDefs.begin();
         ci != featDefs.end(); ci++) {
      res->addFeatureDef(*ci);
    }
  }

  return res;
}
Beispiel #6
0
void testGithub252() {
  BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdErrorLog) << "Testing Github Issue #252: crash when calling "
                           "getPos() with no conformer."
                        << std::endl;
  BOOST_LOG(rdErrorLog) << "     expect a precondition failure message below"
                        << std::endl;

  ROMol *testMol;
  MolChemicalFeatureFactory *factory;
  FeatSPtrList featSPtrs;
  boost::shared_ptr<MolChemicalFeature> featSPtr;

  std::string 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);
  testMol = SmilesToMol("CCC");
  TEST_ASSERT(testMol);
  featSPtrs = factory->getFeaturesForMol(*testMol);
  TEST_ASSERT(featSPtrs.size() == 1);
  featSPtr = *featSPtrs.begin();
  TEST_ASSERT(featSPtr->getFamily() == "LumpedHydrophobe");
  bool ok = false;
  try {
    featSPtr->getPos();
  } catch (const Invar::Invariant &) {
    ok = true;
  }

  delete factory;
  delete testMol;

  TEST_ASSERT(ok);
  BOOST_LOG(rdErrorLog) << "   Done" << std::endl;
}
FeatSPtr getMolFeature(const MolChemicalFeatureFactory &factory,
                       const ROMol &mol, int idx, std::string includeOnly = "",
                       bool recompute = true) {
  static FeatSPtrList feats;
  if (recompute) {
    feats = factory.getFeaturesForMol(mol, includeOnly.c_str());
  }
  if (idx < 0 || idx >= static_cast<int>(feats.size())) {
    throw IndexErrorException(idx);
  }

  FeatSPtrList_I fi = feats.begin();
  for (int i = 0; i < idx; ++i) {
    ++fi;
  }
  return (*fi);
}
Beispiel #8
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;
}
Beispiel #9
0
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;
}
int getNumMolFeatures(const MolChemicalFeatureFactory &factory,
                      const ROMol &mol, std::string includeOnly = "") {
  FeatSPtrList feats = factory.getFeaturesForMol(mol, includeOnly.c_str());
  return feats.size();
}