示例#1
0
void testGithub186(){
  BOOST_LOG(rdInfoLog) << "testing github issue 186: chiral S not written to ctab" << std::endl;
  std::string rdbase = getenv("RDBASE");
  rdbase += "/Code/GraphMol/FileParsers/test_data/";
  
  {
    std::string fName = rdbase + "github186.mol";
    RWMol *m = MolFileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==11);
    TEST_ASSERT(m->getNumBonds()==10);
    TEST_ASSERT(m->getAtomWithIdx(6)->getChiralTag()!=Atom::CHI_UNSPECIFIED &&
                m->getAtomWithIdx(6)->getChiralTag()!=Atom::CHI_OTHER
                );

    std::string mb=MolToMolBlock(*m);
    delete m;
    m = MolBlockToMol(mb);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==11);
    TEST_ASSERT(m->getNumBonds()==10);
    TEST_ASSERT(m->getAtomWithIdx(6)->getChiralTag()!=Atom::CHI_UNSPECIFIED &&
                m->getAtomWithIdx(6)->getChiralTag()!=Atom::CHI_OTHER
                );

    delete m;
  }
  
}
示例#2
0
void testGithub187(){
  BOOST_LOG(rdInfoLog) << "testing github issue 187: A not written to mol block" << std::endl;
  std::string rdbase = getenv("RDBASE");
  rdbase += "/Code/GraphMol/FileParsers/test_data/";
  
  {
    std::string fName = rdbase + "github187.mol";
    RWMol *m = MolFileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==1);
    TEST_ASSERT(m->getNumBonds()==0);
    TEST_ASSERT(m->getAtomWithIdx(0)->hasQuery());
    std::string mb=MolToMolBlock(*m);
    TEST_ASSERT(mb.find(" A   0")!=std::string::npos);

    // try the v3000 version:
    mb=MolToMolBlock(*m,true,-1,true,true);
    TEST_ASSERT(mb.find("V30 1 A 0")!=std::string::npos);
    
    delete m;
  }
  
  {
    std::string fName = rdbase + "github187.v3k.mol";
    RWMol *m = MolFileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==1);
    TEST_ASSERT(m->getNumBonds()==0);
    TEST_ASSERT(m->getAtomWithIdx(0)->hasQuery());
    std::string mb=MolToMolBlock(*m);
    TEST_ASSERT(mb.find(" A   0")!=std::string::npos);

    // try the v3000 version:
    mb=MolToMolBlock(*m,true,-1,true,true);
    TEST_ASSERT(mb.find("V30 1 A 0")!=std::string::npos);
    
    delete m;
  }

  {
    std::string fName = rdbase + "github187.2.mol";
    RWMol *m = MolFileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==1);
    TEST_ASSERT(m->getNumBonds()==0);
    TEST_ASSERT(m->getAtomWithIdx(0)->hasQuery());
    std::string mb=MolToMolBlock(*m);
    TEST_ASSERT(mb.find(" Q   0")!=std::string::npos);

    // try the v3000 version:
    mb=MolToMolBlock(*m,true,-1,true,true);
    TEST_ASSERT(mb.find("V30 1 \"NOT [C,H]\" 0")!=std::string::npos);
    
    delete m;
  }
  
  BOOST_LOG(rdInfoLog) << "done" << std::endl;
}
示例#3
0
void testV3000WriterDetails(){
  BOOST_LOG(rdInfoLog) << "testing details of v3000 writing" << std::endl;
  std::string rdbase = getenv("RDBASE");
  rdbase += "/Code/GraphMol/FileParsers/test_data/";
  {
    std::string fName = rdbase + "chebi_57262.v3k.mol";
    RWMol *m = MolFileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==22);
    TEST_ASSERT(m->getNumBonds()==21);
    TEST_ASSERT(m->getAtomWithIdx(18)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(18)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(18)->getIsotope()==1);
    TEST_ASSERT(m->getAtomWithIdx(21)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(21)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(21)->getIsotope()==2);

    std::string mb=MolToMolBlock(*m,true,-1,true,true);
    TEST_ASSERT(mb.find("MASS=1")!=std::string::npos);
    TEST_ASSERT(mb.find("MASS=2")!=std::string::npos);

    delete m;
    m = MolBlockToMol(mb);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==22);
    TEST_ASSERT(m->getNumBonds()==21);
    TEST_ASSERT(m->getAtomWithIdx(18)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(18)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(18)->getIsotope()==1);
    TEST_ASSERT(m->getAtomWithIdx(21)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(21)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(21)->getIsotope()==2);

    // repeat that one more time to make sure we're really solid:
    mb=MolToMolBlock(*m,true,-1,true,true);
    TEST_ASSERT(mb.find("MASS=1")!=std::string::npos);
    TEST_ASSERT(mb.find("MASS=2")!=std::string::npos);

    delete m;
    m = MolBlockToMol(mb);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==22);
    TEST_ASSERT(m->getNumBonds()==21);
    TEST_ASSERT(m->getAtomWithIdx(18)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(18)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(18)->getIsotope()==1);
    TEST_ASSERT(m->getAtomWithIdx(21)->getAtomicNum()==0);
    TEST_ASSERT(!m->getAtomWithIdx(21)->hasQuery());
    TEST_ASSERT(m->getAtomWithIdx(21)->getIsotope()==2);
    
    delete m;
  }
  
  BOOST_LOG(rdInfoLog) << "done" << std::endl;
}
void testGithubIssue429() 
{
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing github issue 429: fragmentOnSomeBonds() should update implicit H count on aromatic heteroatoms when addDummies is False"<< std::endl;

  {
    std::string smi = "c1cccn1CC1CC1";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms());
    unsigned int indices[]={4,5};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    std::vector<ROMOL_SPTR> frags;
    MolFragmenter::fragmentOnSomeBonds(*mol,bindices,frags,1,false);
    TEST_ASSERT(frags.size()==2);
    std::vector<std::vector<int> > fragMap;
    
    BOOST_FOREACH(ROMOL_SPTR romol,frags){
      RWMol *rwmol=(RWMol *)(romol.get());
      MolOps::sanitizeMol(*rwmol);
    }

    // we actually changed fragmentOnBonds(), check that too:
    RWMol *nmol=(RWMol *)MolFragmenter::fragmentOnBonds(*mol,bindices,false);
    MolOps::sanitizeMol(*nmol);
    delete nmol;

    delete mol;
  }
示例#5
0
  const std::string GetMolFileQueryInfo(const RWMol &mol){
    std::stringstream ss;
    boost::dynamic_bitset<> listQs(mol.getNumAtoms());
    for(ROMol::ConstAtomIterator atomIt=mol.beginAtoms();
	atomIt!=mol.endAtoms();++atomIt){
      if(hasListQuery(*atomIt)) listQs.set((*atomIt)->getIdx());
    }    
    for(ROMol::ConstAtomIterator atomIt=mol.beginAtoms();
	atomIt!=mol.endAtoms();++atomIt){
      if(!listQs[(*atomIt)->getIdx()] && hasComplexQuery(*atomIt)){
	std::string sma=SmartsWrite::GetAtomSmarts(static_cast<const QueryAtom *>(*atomIt));
	ss<< "V  "<<std::setw(3)<<(*atomIt)->getIdx()+1<<" "<<sma<<std::endl;
      }
    }

    for(ROMol::ConstAtomIterator atomIt=mol.beginAtoms();
	atomIt!=mol.endAtoms();++atomIt){
      if(listQs[(*atomIt)->getIdx()]){
        INT_VECT vals;
        getListQueryVals((*atomIt)->getQuery(),vals);
        ss<<"M  ALS "<<std::setw(3)<<(*atomIt)->getIdx()+1<<" ";
        ss<<std::setw(2)<<vals.size();
        if((*atomIt)->getQuery()->getNegation()){
          ss<<" T";
        } else {
          ss<<" F";
        }
        BOOST_FOREACH(int val,vals){
          ss<<" "<<std::setw(3)<<std::left<<(PeriodicTable::getTable()->getElementSymbol(val));
        }
        ss<<"\n";
      }

    }
示例#6
0
文件: testMIF.cpp 项目: dfhahn/rdkit
void test3CubeFiles () {
  std::string path = getenv ("RDBASE");
  path += "/Code/GraphMol/MIF/test_data/";

  RWMol mol = *MolFileToMol(path + "HCl.mol", true, false);
  RealValueVect *data = new RealValueVect (0.0, 125);
  UniformRealValueGrid3D grd (5.0, 5.0, 5.0, 1.0, new Point3D (0.0, 0.0, 0.0),
                              data);
  for (unsigned int i = 0; i < grd.getSize (); i++) {
    grd.setVal (i, double (i / 10.0));
  }
  writeToCubeFile (grd, mol, path + "test3.cube");
  UniformRealValueGrid3D grd2;
  RWMol mol2 = *readFromCubeFile (grd2, path + "test3.cube");

  CHECK_INVARIANT(grd.getSize() == grd2.getSize(),
                  "I/O: grid sizes are not the same.");
  for (unsigned int i = 0; i < grd2.getSize (); i++) {
    CHECK_INVARIANT(feq(grd2.getVal(i), double(i / 10.0)),
                    "I/O: values in grid are not correct.");
  }
  CHECK_INVARIANT(grd.getNumX() == grd2.getNumX(), "I/O: grids are not the same.");
  CHECK_INVARIANT(grd.getNumY() == grd2.getNumY(), "I/O: grids are not the same.");
  CHECK_INVARIANT(grd.getNumZ() == grd2.getNumZ(), "I/O: grids are not the same.");
  CHECK_INVARIANT(feq(grd.getOffset().x, grd2.getOffset().x), "I/O: grids are not the same.");
  CHECK_INVARIANT(feq(grd.getSpacing(), grd2.getSpacing()), "I/O: grids are not the same.");
  CHECK_INVARIANT(grd.compareVectors(grd2), "I/O: grids are not the same.");
  CHECK_INVARIANT(grd.compareParams(grd2), "I/O: grids are not the same.");
  CHECK_INVARIANT(grd.compareGrids(grd2), "I/O: grids are not the same.");

  CHECK_INVARIANT(mol.getNumAtoms() == mol2.getNumAtoms(),
                  "I/O: number of atoms are not the same.");
  for (unsigned int i = 0; i < mol.getNumAtoms (); i++) {
    CHECK_INVARIANT(mol.getAtomWithIdx (i)->getAtomicNum ()
                    == mol2.getAtomWithIdx (i)->getAtomicNum (),
                    "I/O: atoms are not the same");
    CHECK_INVARIANT(feq (mol.getConformer ().getAtomPos (i).x,
                         mol2.getConformer ().getAtomPos (i).x),
                    "I/O: atom positions are not the same");
    CHECK_INVARIANT(feq (mol.getConformer ().getAtomPos (i).y,
                         mol2.getConformer ().getAtomPos (i).y),
                    "I/O: atom positions are not the same");
    CHECK_INVARIANT(feq (mol.getConformer ().getAtomPos (i).z,
                         mol2.getConformer ().getAtomPos (i).z),
                    "I/O: atom positions are not the same");
  }
}
示例#7
0
文件: testMIF.cpp 项目: dfhahn/rdkit
void test4Coulomb () {
  std::string path = getenv("RDBASE");
  path += "/Code/GraphMol/MIF/test_data/";

  RWMol mol = *MolFileToMol(path + "HCl.mol", true, false);

  computeGasteigerCharges(mol);

  std::vector<double> charges;
  std::vector<Point3D> pos;
  Conformer conf = mol.getConformer(0);
  for (int i = 0; i < mol.getNumAtoms(); ++i) {
    charges.push_back(mol.getAtomWithIdx (i)->getProp<double> ("_GasteigerCharge"));
    pos.push_back(conf.getAtomPos(i));
  }

  UniformRealValueGrid3D grd = *constructGrid(mol);
  UniformRealValueGrid3D grd2 = *constructGrid(mol);

  Coulomb coul(mol);

  calculateDescriptors<Coulomb>(grd, coul);
  calculateDescriptors<Coulomb>(grd2, Coulomb (charges, pos));

  CHECK_INVARIANT(grd.compareGrids(grd2),
                  "Coulomb: Different constructors do not yield the same descriptor.");
  CHECK_INVARIANT(feq (coul(0.0,0.0,0.0, 1000), 0.0),
                  "Coulomb: Potential between atoms wrong.(should be 0)");
  CHECK_INVARIANT(coul(2.0,0.0,0.0, 1000) < 0,
                  "Coulomb: Potential between positive charges not positive.");
  CHECK_INVARIANT(coul(-2.0,0.0,0.0, 1000) > 0,
                  "Coulomb: Potential between positive and negative charges not negative.");
  CHECK_INVARIANT(feq(coul(0.0,0.0,0.0, 0.1), 0.0),
                  "Coulomb: Small threshold dist does not give 0.");
                  
  calculateDescriptors<Coulomb>(grd, Coulomb(mol, 0, 1.0, true));
  for (unsigned int i = 0; i < grd.getSize(); i++) {
    CHECK_INVARIANT(grd.getVal (i) <= 0.0, "Coulomb: Absolute value field not negative");
  }

Coulomb coul1(mol, 0, -1.0, false, "_GasteigerCharge", 0.0, 0.01);
  CHECK_INVARIANT(coul1(-2.0, 0.0, 0.0, 1000) < 0, "Coulomb: Potential between negative charges not positive.");
  CHECK_INVARIANT(coul1(2.0, 0.0, 0.0, 1000) > 0, "Coulomb: Potential between positive and negative charges not negative.");

  Coulomb coul2 = Coulomb(mol, 0, -.5, false, "_GasteigerCharge", 0.0, 0.01);
  CHECK_INVARIANT(coul1(-2.0, 0.0, 0.0, 1000) < coul2 (-2.0, 0.0, 0.0, 1000),
                  "Coulomb: Higher probecharge does not result in stronger forces.");

  Coulomb coul3(mol, 0, 1.0, false, "_GasteigerCharge", 0.01, 1.0);
  CHECK_INVARIANT(coul3(0.0, 0.0, 0.0, 1000) > coul3(0.1, 0.0, 0.0, 1000),
                  "Coulomb: Softcore interaction wrong.");
  CHECK_INVARIANT(coul3(0.66, 0.0, 0.0, 1000) > coul3(0.68, 0.0, 0.0, 1000),
                  "Coulomb: Softcore interaction wrong.");
  CHECK_INVARIANT(coul3(0.70, 0.0, 0.0, 1000) > coul3(0.68, 0.0, 0.0, 1000),
                  "Coulomb: Softcore interaction wrong.");
  CHECK_INVARIANT(feq(coul3(0.0,0.0,0.0, 0.1), 0.0),
                  "Coulomb: Small threshold dist does not give 0.");

}
示例#8
0
文件: iotest.cpp 项目: giallu/rdkit
void test2() {
#ifdef SUPPORT_COMPRESSED_IO
  BOOST_LOG(rdInfoLog)
      << "testing writing to, then reading from compressed streams"
      << std::endl;

  std::string smiles = "C1CCCC1";
  std::string buff, molBlock;
  RWMol *m;
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(5));
  m->setProp(common_properties::_Name, "monkey");
  io::filtering_ostream outStrm;
  outStrm.push(io::gzip_compressor());
  outStrm.push(io::back_inserter(buff));
  TEST_ASSERT(outStrm.is_complete());

  molBlock = MolToMolBlock(*m);
  outStrm << molBlock;
  outStrm.reset();

  delete m;
  io::filtering_istream inStrm;
  inStrm.push(io::gzip_decompressor());
  inStrm.push(boost::make_iterator_range(buff));
  TEST_ASSERT(inStrm.is_complete());

  unsigned int lineNo = 0;
  m = MolDataStreamToMol(inStrm, lineNo);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(5));

  BOOST_LOG(rdInfoLog) << "done" << std::endl;
#else
  BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
#endif
}
示例#9
0
文件: Kekulize.cpp 项目: giallu/rdkit
void kekulizeFused(RWMol &mol, const VECT_INT_VECT &arings,
                   unsigned int maxBackTracks) {
  // get all the atoms in the ring system
  INT_VECT allAtms;
  Union(arings, allAtms);

  // get all the atoms that are candidates to receive a double bond
  // also mark atoms in the fused system that are not aromatic to begin with
  // as done. Mark all the bonds that are part of the aromatic system
  // to be single bonds
  INT_VECT done;
  INT_VECT questions;
  unsigned int nats = mol.getNumAtoms();
  unsigned int nbnds = mol.getNumBonds();
  boost::dynamic_bitset<> dBndCands(nats);
  boost::dynamic_bitset<> dBndAdds(nbnds);

  markDbondCands(mol, allAtms, dBndCands, questions, done);
#if 0
      std::cerr << "candidates: ";
      for(int i=0;i<nats;++i) std::cerr << dBndCands[i];
      std::cerr << std::endl;
#endif

  bool kekulized;
  kekulized =
      kekulizeWorker(mol, allAtms, dBndCands, dBndAdds, done, maxBackTracks);
  if (!kekulized && questions.size()) {
    // we failed, but there are some dummy atoms we can try permuting.
    kekulized = permuteDummiesAndKekulize(mol, allAtms, dBndCands, questions,
                                          maxBackTracks);
  }
  if (!kekulized) {
    // we exhausted all option (or crossed the allowed
    // number of backTracks) and we still need to backtrack
    // can't kekulize this thing
    std::ostringstream errout;
    errout << "Can't kekulize mol.";
    errout << "  Unkekulized atoms:";
    for (unsigned int i = 0; i < nats; ++i) {
      if (dBndCands[i]) errout << " " << i;
    }
    errout << std::endl;
    std::string msg = errout.str();
    BOOST_LOG(rdErrorLog) << msg << std::endl;
    throw MolSanitizeException(msg);
  }
}
示例#10
0
void test504() {
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing FMCS test504" << std::endl;
  std::cout << "\ntest504()\n";
  std::vector<ROMOL_SPTR> mols;
  const char* smi[] = {
      // TEST 504
      "C(CCNC(C1CC1[c:1]1[c:2]c(Cl)c(Cl)c[c:3]1)=O)CCN1CCC(NC(Nc2ccc(Cl)cc2)=O)"
      "C1 CHEMBL545864",  // - QUERY

      "FC(F)(F)c1cc(NC(N2CCCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)CC2)=O)ccc1Cl "
      "CHEMBL528228",
      "FC(F)(F)c1cc(NC(NC2CCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)C2)=O)ccc1Cl "
      "CHEMBL525875",
      "Fc1ccc(NC(N2CCCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)CC2)=O)cc1C(F)(F)F "
      "CHEMBL527277",
      "FC(F)(F)c1cc(NC(NC2CCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)CC2)=O)ccc1Cl "
      "CHEMBL537333",
      "Fc1ccc(NC(NC2CCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)C2)=O)cc1C(F)(F)F "
      "CHEMBL588077",
      "FC(F)(F)c1ccc(NC(NC2CCN(CCCCCNC(C3CC3c3cc(Cl)c(Cl)cc3)=O)C2)=O)cc1 "
      "CHEMBL525307",
      "Fc1ccc(NC(NC2CCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)CC2)=O)cc1C(F)(F)F "
      "CHEMBL581847",
      "FC(F)(F)c1ccc(NC(NC2CCN(CCCCCNC(C3CC3c3cc(Cl)c(Cl)cc3)=O)CC2)=O)cc1 "
      "CHEMBL579547",
      "N#Cc1cccc(NC(NC2CCN(CCCCCNC(C3CC3c3ccc(Cl)c(Cl)c3)=O)CC2)=O)c1 "
      "CHEMBL529994",
  };
  RWMol* qm = SmilesToMol(getSmilesOnly(smi[0]));
  unsigned nq = qm->getNumAtoms();
  for (size_t ai = 0; ai < nq; ai++) {
    Atom* atom = qm->getAtomWithIdx(ai);
    atom->setProp("molAtomMapNumber", (int)ai);
  }
  std::cout << "Query +MAP " << MolToSmiles(*qm) << "\n";
  mols.push_back(ROMOL_SPTR(qm));  // with RING INFO
  for (size_t i = 1; i < sizeof(smi) / sizeof(smi[0]); i++)
    mols.push_back(
        ROMOL_SPTR(SmilesToMol(getSmilesOnly(smi[i]))));  // with RING INFO
  t0 = nanoClock();
  MCSResult res = findMCS(mols);
  std::cout << "MCS: " << res.SmartsString << " " << res.NumAtoms << " atoms, "
            << res.NumBonds << " bonds\n";
  printTime();
  TEST_ASSERT(res.NumAtoms == 34 && res.NumBonds == 36);
  BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
}
示例#11
0
void testSFIssue1653802(){
  BOOST_LOG(rdErrorLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdErrorLog) << "    Testing SFIssue1653802." << std::endl;

  RWMol *mol;
  int needMore;
  ForceFields::ForceField *field;

  std::string pathName=getenv("RDBASE");
  pathName += "/Code/GraphMol/ForceFieldHelpers/UFF/test_data";

  mol = MolFileToMol(pathName+"/cyclobutadiene.mol",false);
  TEST_ASSERT(mol);
  MolOps::sanitizeMol(*mol);


  UFF::AtomicParamVect types;
  bool foundAll;
  boost::shared_array<boost::uint8_t> nbrMat;
  boost::tie(types,foundAll)=UFF::getAtomTypes(*mol);
  TEST_ASSERT(foundAll);
  TEST_ASSERT(types.size()==mol->getNumAtoms());
  field=new ForceFields::ForceField();
  UFF::Tools::addBonds(*mol,types,field);
  TEST_ASSERT(field->contribs().size()==8);

  nbrMat = UFF::Tools::buildNeighborMatrix(*mol);
  UFF::Tools::addAngles(*mol,types,field);
  TEST_ASSERT(field->contribs().size()==20);
  UFF::Tools::addTorsions(*mol,types,field);
  //std::cout << field->contribs().size() << std::endl;
  TEST_ASSERT(field->contribs().size()==36);
  UFF::Tools::addNonbonded(*mol,0,types,field,nbrMat);
  delete field;

  field = UFF::constructForceField(*mol);
  field->initialize();
  needMore = field->minimize(200,1e-6,1e-3);
  TEST_ASSERT(!needMore);
  
  delete mol;
  delete field;
  BOOST_LOG(rdErrorLog) << "  done" << std::endl;
}
示例#12
0
文件: Kekulize.cpp 项目: giallu/rdkit
bool permuteDummiesAndKekulize(RWMol &mol, const INT_VECT &allAtms,
                               boost::dynamic_bitset<> dBndCands,
                               INT_VECT &questions,
                               unsigned int maxBackTracks) {
  boost::dynamic_bitset<> atomsInPlay(mol.getNumAtoms());
  for (int allAtm : allAtms) {
    atomsInPlay[allAtm] = 1;
  }
  bool kekulized = false;
  QuestionEnumerator qEnum(questions);
  while (!kekulized && questions.size()) {
    boost::dynamic_bitset<> dBndAdds(mol.getNumBonds());
    INT_VECT done;
#if 1
    // reset the state: all aromatic bonds are remarked to single:
    for (RWMol::BondIterator bi = mol.beginBonds(); bi != mol.endBonds();
         ++bi) {
      if ((*bi)->getIsAromatic() && (*bi)->getBondType() != Bond::SINGLE &&
          atomsInPlay[(*bi)->getBeginAtomIdx()] &&
          atomsInPlay[(*bi)->getEndAtomIdx()]) {
        (*bi)->setBondType(Bond::SINGLE);
      }
    }
#endif
    // pick a new permutation of the questionable atoms:
    const INT_VECT &switchOff = qEnum.next();
    if (!switchOff.size()) break;
    boost::dynamic_bitset<> tCands = dBndCands;
    for (int it : switchOff) {
      tCands[it] = 0;
    }
#if 0
        std::cerr<<"permute: ";
        for (boost::dynamic_bitset<>::size_type i = 0; i < tCands.size(); ++i){
          std::cerr << tCands[i];
        }
        std::cerr<<std::endl;
#endif
    // try kekulizing again:
    kekulized =
        kekulizeWorker(mol, allAtms, tCands, dBndAdds, done, maxBackTracks);
  }
  return kekulized;
}
示例#13
0
void test1(){
#ifdef SUPPORT_COMPRESSED_IO
  BOOST_LOG(rdInfoLog) << "testing basic reading from compressed streams" << std::endl;

  std::string rdbase = getenv("RDBASE");
  std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/triazine.mol.gz";
  RWMol *m;
  
  io::filtering_istream inStrm;
  inStrm.push(io::gzip_decompressor());
  inStrm.push(io::file_source(fname2));
  TEST_ASSERT(inStrm.is_complete());
  unsigned int lineNo=0;
  m = MolDataStreamToMol(inStrm,lineNo);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(6));

  BOOST_LOG(rdInfoLog) << "done" << std::endl;
#else
  BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
#endif
}
示例#14
0
void test18() {
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing FMCS test18" << std::endl;
  std::cout << "\ntest18()\n";
  std::vector<ROMOL_SPTR> mols;
  const char* smi[] = {
      // TEST 18
      "Cc1nc(CN(C(C)c2ncccc2)CCCCN)ccc1 CHEMBL1682991",  //-- QUERY
      "Cc1ccc(CN(C(C)c2ccccn2)CCCCN)nc1 CHEMBL1682990",
      "Cc1cccnc1CN(C(C)c1ccccn1)CCCCN CHEMBL1682998",
      "CC(N(CCCCN)Cc1c(N)cccn1)c1ccccn1 CHEMBL1682987",
      "Cc1cc(C)c(CN(C(C)c2ccccn2)CCCCN)nc1 CHEMBL1682992",
      "Cc1cc(C(C)N(CCCCN)Cc2c(C)cccn2)ncc1 CHEMBL1682993",
      "Cc1nc(C(C)N(CCCCN)Cc2nc3c([nH]2)cccc3)ccc1 CHEMBL1682878",
      "CC(c1ncccc1)N(CCCCN)Cc1nc2c([nH]1)cccc2 CHEMBL1682867",
      "CC(N(CCCCN)Cc1c(C(C)(C)C)cccn1)c1ccccn1 CHEMBL1682989",
      "CC(N(CCCCN)Cc1c(C(F)(F)F)cccn1)c1ccccn1 CHEMBL1682988",
      //# 18 .  20 20 0.04 sec. Python MCS: CC(c1ccccn1)N(CCCCN)Ccnccc
  };
  RWMol* qm = SmilesToMol(getSmilesOnly(smi[0]));
  unsigned nq = qm->getNumAtoms();
  for (size_t ai = 0; ai < nq; ai++) {
    Atom* atom = qm->getAtomWithIdx(ai);
    atom->setProp("molAtomMapNumber", (int)ai);
  }
  std::cout << "Query +MAP " << MolToSmiles(*qm) << "\n";
  mols.push_back(ROMOL_SPTR(qm));  // with RING INFO
  for (size_t i = 1; i < sizeof(smi) / sizeof(smi[0]); i++)
    mols.push_back(
        ROMOL_SPTR(SmilesToMol(getSmilesOnly(smi[i]))));  // with RING INFO
  t0 = nanoClock();
  MCSResult res = findMCS(mols);
  std::cout << "MCS: " << res.SmartsString << " " << res.NumAtoms << " atoms, "
            << res.NumBonds << " bonds\n";
  printTime();
  TEST_ASSERT(res.NumAtoms == 21 && res.NumBonds == 21);
  BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
}
示例#15
0
void testGeneral(std::string rdbase){

  BOOST_LOG(rdInfoLog) << "---------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "-- testing general mol2 file parsing --" << std::endl;
  BOOST_LOG(rdInfoLog) << "---------------------------------------" << std::endl;

  {
    bool ok=false;
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/nonExistFile.mol2";
    try{
      RWMol *m = Mol2FileToMol(fName);
      delete m;
    } catch(const BadFileException &e){
      ok=true;
    }
    TEST_ASSERT(ok);
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/pyrazole_pyridine.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==5);

    // this was sf.net issue 2727976:
    TEST_ASSERT(m->getNumConformers()==1);
    TEST_ASSERT(m->getConformer().is3D());
    TEST_ASSERT(feq(m->getConformer().getAtomPos(0).x,1.5019));
    TEST_ASSERT(feq(m->getConformer().getAtomPos(0).y,1.0435));
    TEST_ASSERT(feq(m->getConformer().getAtomPos(0).z,0.0000));

    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/benzene.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==6);
    delete m;
  }
  {
    bool ok=false;
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/mol_noatoms.mol2";
    try {
      RWMol *m = Mol2FileToMol(fName);
      delete m;
    } catch(const FileParseException &e){
      ok=true;
    }
    TEST_ASSERT(ok);
  }
  {
    bool ok=false;
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/mol_nomol.mol2";
    try {
      RWMol *m = Mol2FileToMol(fName);
      delete m;
    } catch(const FileParseException &e){
      ok=true;
    }
    TEST_ASSERT(ok);
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/lonePairMol.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms()==5 && m->getNumBonds()==4);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/symmetricGuanidine.mol2";
    RWMol *m = Mol2FileToMol(fName,false);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(1)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==1);
    delete m;
  }

  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/highlySymmetricGuanidine.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(4)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(12)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(20)->getFormalCharge()==1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/Noxide.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(9)->getFormalCharge()==-1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/Noxide.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(9)->getFormalCharge()==-1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/fusedRing.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);


    TEST_ASSERT(m->getAtomWithIdx(0)->getFormalCharge()==0);
    TEST_ASSERT(m->getAtomWithIdx(5)->getFormalCharge()==0);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==0);
    TEST_ASSERT(m->getAtomWithIdx(13)->getFormalCharge()==0);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/pyridiniumPhenyl.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(5)->getFormalCharge()==1);
    TEST_ASSERT(m->getAtomWithIdx(6)->getFormalCharge()==0);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/sulfonAmide.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(1)->getFormalCharge()==0);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/chargedAmidineRWH.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(6)->getFormalCharge()==1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/chargedAmidineEC.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(3)->getFormalCharge()==1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/chargedAmidine.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(9)->getFormalCharge()==1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/dbtranslateCharged.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==1);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/dbtranslateUncharged.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(8)->getFormalCharge()==0);
    delete m;
  }
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/dbtranslateUnchargedRing.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getAtomWithIdx(2)->getFormalCharge()==0);
    delete m;
  }


#if 0  
  {
    std::string fName = rdbase + "/Code/GraphMol/FileParsers/test_data/Sulfonate.mol2";
    RWMol *m = Mol2FileToMol(fName);
    TEST_ASSERT(m);
    BOOST_LOG(rdInfoLog) <<MolToSmiles(*m)<<std::endl;
    delete m;
  }
#endif

  BOOST_LOG(rdInfoLog) << "------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "-- DONE general mol2 file parsing --" << std::endl;
  BOOST_LOG(rdInfoLog) << "------------------------------------" << std::endl;

}
示例#16
0
void test5(){
#ifdef SUPPORT_COMPRESSED_IO
  BOOST_LOG(rdInfoLog) << "testing writing compressed pickles to a single file then reading them back" << std::endl;
  std::string rdbase = getenv("RDBASE");
  std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/tmp.rdz";

  std::string smiles,buff;
  RWMol *m;
  std::vector<unsigned int> filePs;

  io::filtering_ostream outStrm;
  outStrm.push(io::file_sink(fname2,std::ios_base::out|std::ios_base::binary));
  TEST_ASSERT(outStrm.is_complete());
  
  smiles="C1CCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(4));


  io::filtering_ostream *tmpStrm;
  tmpStrm=new io::filtering_ostream();
  tmpStrm->push(io::gzip_compressor());
  tmpStrm->push(io::back_inserter(buff));
  
  
  filePs.push_back(0);
  MolPickler::pickleMol(*m,*tmpStrm);
  delete m;
  tmpStrm->reset();

  outStrm<<buff.size();
  outStrm<<buff;
  std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
  buff="";
  tmpStrm->push(io::gzip_compressor());
  tmpStrm->push(io::back_inserter(buff));
  
  smiles="C1CCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(4));
  RDDepict::compute2DCoords(*m);

  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,*tmpStrm);
  delete m;
  tmpStrm->reset();
  outStrm<<buff.size();
  outStrm<<buff;
  std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
  buff="";
  tmpStrm->push(io::gzip_compressor());
  tmpStrm->push(io::back_inserter(buff));

  smiles="C1CCCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(5));
  RDDepict::compute2DCoords(*m);

  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,*tmpStrm);
  delete m;
  tmpStrm->reset();
  outStrm<<buff.size();
  outStrm<<buff;
  std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
  buff="";
  tmpStrm->push(io::gzip_compressor());
  tmpStrm->push(io::back_inserter(buff));


  smiles="c1ccccc1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(6));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,*tmpStrm);
  delete m;
  tmpStrm->reset();
  outStrm<<buff.size();
  outStrm<<buff;
  std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;
  buff="";
  tmpStrm->push(io::gzip_compressor());
  tmpStrm->push(io::back_inserter(buff));
  
  smiles="c1ccccc1CC(=O)O";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(9));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,*tmpStrm);
  delete m;
  tmpStrm->reset();
  outStrm<<buff.size();
  outStrm<<buff;
  std::cerr<<"sz: " <<buff.size()<<" "<<outStrm.tellp() <<std::endl;

  delete tmpStrm;
  io::flush(outStrm);
  outStrm.pop();

  io::filtering_istream tmpIStrm;
  io::filtering_istream inStrm;
  unsigned int sz;
  char *charArr;
  
  inStrm.push(io::file_source(fname2,std::ios_base::in|std::ios_base::binary));
  TEST_ASSERT(inStrm.is_complete());

  inStrm>>sz;
  charArr = new char[sz];
  inStrm.read(charArr,sz);
  buff = "";
  buff.append(charArr,sz);
  tmpIStrm.push(io::gzip_decompressor());
  tmpIStrm.push(boost::make_iterator_range(buff));
  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(tmpIStrm,*m);
  TEST_ASSERT(m->getNumAtoms(4));
  delete m;

  inStrm>>sz;
  delete [] charArr;
  charArr = new char[sz];
  inStrm.read(charArr,sz);
  buff = "";
  buff.append(charArr,sz);
  tmpIStrm.reset();
  tmpIStrm.push(io::gzip_decompressor());
  tmpIStrm.push(boost::make_iterator_range(buff));
  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(tmpIStrm,*m);
  TEST_ASSERT(m->getNumAtoms(4));
  delete m;

  inStrm>>sz;
  delete [] charArr;
  charArr = new char[sz];
  inStrm.read(charArr,sz);
  buff = "";
  buff.append(charArr,sz);
  tmpIStrm.reset();
  tmpIStrm.push(io::gzip_decompressor());
  tmpIStrm.push(boost::make_iterator_range(buff));
  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(tmpIStrm,*m);
  TEST_ASSERT(m->getNumAtoms(5));
  delete m;

  inStrm>>sz;
  delete [] charArr;
  charArr = new char[sz];
  inStrm.read(charArr,sz);
  buff = "";
  buff.append(charArr,sz);
  tmpIStrm.reset();
  tmpIStrm.push(io::gzip_decompressor());
  tmpIStrm.push(boost::make_iterator_range(buff));
  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(tmpIStrm,*m);
  TEST_ASSERT(m->getNumAtoms(6));
  delete m;

  inStrm>>sz;
  delete [] charArr;
  charArr = new char[sz];
  inStrm.read(charArr,sz);
  buff = "";
  buff.append(charArr,sz);
  tmpIStrm.reset();
  tmpIStrm.push(io::gzip_decompressor());
  tmpIStrm.push(boost::make_iterator_range(buff));
  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(tmpIStrm,*m);
  TEST_ASSERT(m->getNumAtoms(9));
  delete m;

  BOOST_LOG(rdInfoLog) << "done" << std::endl;
#else
  BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
#endif
}
void testFragmentOnSomeBonds() 
{
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing fragmentOnSomeBonds"<< std::endl;

  {
    std::string smi = "OCCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms());
    unsigned int indices[]={0,2,4};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    std::vector<ROMOL_SPTR> frags;
    MolFragmenter::fragmentOnSomeBonds(*mol,bindices,frags,2);
    TEST_ASSERT(frags.size()==3);
    std::vector<std::vector<int> > fragMap;

    TEST_ASSERT(MolOps::getMolFrags(*frags[0],fragMap)==3);
    TEST_ASSERT(fragMap.size()==3);
    TEST_ASSERT(fragMap[0].size()==2);
    TEST_ASSERT(fragMap[1].size()==4);
    TEST_ASSERT(fragMap[2].size()==4);

    TEST_ASSERT(MolOps::getMolFrags(*frags[1],fragMap)==3);
    TEST_ASSERT(fragMap.size()==3);
    TEST_ASSERT(fragMap[0].size()==2);
    TEST_ASSERT(fragMap[1].size()==6);
    TEST_ASSERT(fragMap[2].size()==2);

    TEST_ASSERT(MolOps::getMolFrags(*frags[2],fragMap)==3);
    TEST_ASSERT(fragMap.size()==3);
    TEST_ASSERT(fragMap[0].size()==4);
    TEST_ASSERT(fragMap[1].size()==4);
    TEST_ASSERT(fragMap[2].size()==2);
    
    delete mol;
  }


  {
    std::string smi = "OCCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms());
    unsigned int indices[]={0,2,4};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    std::vector<ROMOL_SPTR> frags;
    std::vector<std::vector<unsigned int> > cpa;
    MolFragmenter::fragmentOnSomeBonds(*mol,bindices,frags,2,false,NULL,NULL,&cpa);
    TEST_ASSERT(frags.size()==3);
    TEST_ASSERT(cpa.size()==3);
    TEST_ASSERT(cpa[0].size()==mol->getNumAtoms());
    TEST_ASSERT(cpa[1].size()==mol->getNumAtoms());
    TEST_ASSERT(cpa[2].size()==mol->getNumAtoms());

    
    delete mol;
  }


  BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
}
void testFragmentOnBRICSBonds() 
{
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing fragmentOnBRICSBonds"<< std::endl;

  {
    std::string smi = "c1ccccc1OC";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==8);
    TEST_ASSERT(mol->getBondBetweenAtoms(5,6));
    TEST_ASSERT(mol->getBondBetweenAtoms(6,7));

    std::vector<MolFragmenter::FragmenterBondType> fbts;
    MolFragmenter::constructBRICSBondTypes(fbts);
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,fbts);
    TEST_ASSERT(nmol);
    
    TEST_ASSERT(nmol->getNumAtoms()==10);
    TEST_ASSERT(!nmol->getBondBetweenAtoms(5,6));
    TEST_ASSERT(nmol->getBondBetweenAtoms(6,7));

    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[3*]OC.[16*]c1ccccc1");

    TEST_ASSERT(nmol->getAtomWithIdx(8)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(8)->getIsotope()==3);
    TEST_ASSERT(nmol->getBondBetweenAtoms(6,8));
    TEST_ASSERT(nmol->getAtomWithIdx(9)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(9)->getIsotope()==16);
    TEST_ASSERT(nmol->getBondBetweenAtoms(5,9));
    
    delete mol;
    delete nmol;
  }

  {
    std::string smi = "c1ccccc1";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==6);

    std::vector<MolFragmenter::FragmenterBondType> fbts;
    MolFragmenter::constructBRICSBondTypes(fbts);
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,fbts);
    TEST_ASSERT(nmol);

    
    TEST_ASSERT(nmol->getNumAtoms()==6);

    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="c1ccccc1");
    
    delete mol;
    delete nmol;
  }

  {
    std::string smi = "OC(C)=CC";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);

    std::vector<MolFragmenter::FragmenterBondType> fbts;
    MolFragmenter::constructBRICSBondTypes(fbts);
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,fbts);
    TEST_ASSERT(nmol);

    
    TEST_ASSERT(nmol->getNumAtoms()==7);

    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[7*]=CC.[7*]=C(C)O");
    
    delete mol;
    delete nmol;
  }

  {
    std::string smi = "c1ccccc1OC";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==8);
    ROMol *nmol=MolFragmenter::fragmentOnBRICSBonds(*mol);
    TEST_ASSERT(nmol);
    TEST_ASSERT(nmol->getNumAtoms()==10);
    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[3*]OC.[16*]c1ccccc1");
    
    delete mol;
    delete nmol;
  }
  {
    std::string smi = "OC(C)=CC";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);

    ROMol *nmol=MolFragmenter::fragmentOnBRICSBonds(*mol);
    TEST_ASSERT(nmol);

    
    TEST_ASSERT(nmol->getNumAtoms()==7);
    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[7*]=CC.[7*]=C(C)O");
    
    delete mol;
    delete nmol;
  }

  {
    std::string smi = "CCCOCCC(=O)c1ccccc1";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==14);

    ROMol *nmol=MolFragmenter::fragmentOnBRICSBonds(*mol);
    TEST_ASSERT(nmol);
    
    TEST_ASSERT(nmol->getNumAtoms()==20);
    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[3*]O[3*].[4*]CCC.[4*]CCC([6*])=O.[16*]c1ccccc1");
    MolOps::sanitizeMol(static_cast<RWMol &>(*nmol));
    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="[3*]O[3*].[4*]CCC.[4*]CCC([6*])=O.[16*]c1ccccc1");
    
    delete mol;
    delete nmol;
  }

  {
    std::string smi = "Cl.CC(=O)O[C@]1(c2ccccc2)CCN(C)[C@H]2CCCC[C@@H]21";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==22);
    ROMol *nmol=MolFragmenter::fragmentOnBRICSBonds(*mol);
    TEST_ASSERT(nmol);
    
    TEST_ASSERT(nmol->getNumAtoms()==28);
    smi = MolToSmiles(*nmol,true);
    //std::cerr<<smi<<std::endl;
    TEST_ASSERT(smi=="Cl.[1*]C(C)=O.[3*]O[3*].[15*]C1([15*])CCN(C)[C@H]2CCCC[C@@H]21.[16*]c1ccccc1");
    MolOps::sanitizeMol(static_cast<RWMol &>(*nmol));
    smi = MolToSmiles(*nmol,true);
    TEST_ASSERT(smi=="Cl.[1*]C(C)=O.[3*]O[3*].[15*]C1([15*])CCN(C)[C@H]2CCCC[C@@H]21.[16*]c1ccccc1");
    
    delete mol;
    delete nmol;
  }

  BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
}
void testFragmentOnBonds() 
{
  BOOST_LOG(rdInfoLog) << "-------------------------------------" << std::endl;
  BOOST_LOG(rdInfoLog) << "Testing fragmentOnBonds"<< std::endl;

  {
    std::string smi = "OCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);
    unsigned int indices[]={0,3};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,bindices,false);
    TEST_ASSERT(nmol);
    TEST_ASSERT(nmol->getNumAtoms()==5);
    delete mol;
    delete nmol;
  }
  {
    std::string smi = "OCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);
    unsigned int indices[]={0,1};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    std::vector<unsigned int> cutsPerAtom(mol->getNumAtoms());
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,bindices,false,0,0,&cutsPerAtom);
    TEST_ASSERT(nmol);
    TEST_ASSERT(nmol->getNumAtoms()==5);
    TEST_ASSERT(cutsPerAtom[0]==1);
    TEST_ASSERT(cutsPerAtom[1]==2);
    TEST_ASSERT(cutsPerAtom[2]==1);
    TEST_ASSERT(cutsPerAtom[3]==0);
    delete mol;
    delete nmol;
  }
  {
    std::string smi = "OCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);
    TEST_ASSERT(mol->getBondBetweenAtoms(0,1));
    TEST_ASSERT(mol->getBondBetweenAtoms(3,4));
    unsigned int indices[]={0,3};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,bindices);
    TEST_ASSERT(nmol);
    TEST_ASSERT(nmol->getNumAtoms()==9);
    TEST_ASSERT(!nmol->getBondBetweenAtoms(0,1));
    TEST_ASSERT(!nmol->getBondBetweenAtoms(3,4));
    TEST_ASSERT(nmol->getAtomWithIdx(5)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(5)->getIsotope()==0);
    TEST_ASSERT(nmol->getBondBetweenAtoms(1,5));
    TEST_ASSERT(nmol->getAtomWithIdx(6)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(6)->getIsotope()==1);
    TEST_ASSERT(nmol->getBondBetweenAtoms(0,6));
    
    TEST_ASSERT(nmol->getAtomWithIdx(7)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(7)->getIsotope()==3);
    TEST_ASSERT(nmol->getBondBetweenAtoms(4,7));
    TEST_ASSERT(nmol->getAtomWithIdx(8)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(8)->getIsotope()==4);
    TEST_ASSERT(nmol->getBondBetweenAtoms(3,8));
    delete mol;
    delete nmol;
  }
  {
    std::string smi = "OCCCN";
    RWMol *mol = SmilesToMol(smi);
    TEST_ASSERT(mol);
    TEST_ASSERT(mol->getNumAtoms()==5);
    TEST_ASSERT(mol->getBondBetweenAtoms(0,1));
    TEST_ASSERT(mol->getBondBetweenAtoms(3,4));
    unsigned int indices[]={0,3};
    std::vector<unsigned int> bindices(indices,indices+(sizeof(indices)/sizeof(indices[0])));
    std::vector< std::pair<unsigned int,unsigned int> > dummyLabels(2);
    dummyLabels[0] =std::make_pair(10,11);
    dummyLabels[1] =std::make_pair(100,110);
    ROMol *nmol=MolFragmenter::fragmentOnBonds(*mol,bindices,true,&dummyLabels);
    TEST_ASSERT(nmol);
    TEST_ASSERT(nmol->getNumAtoms()==9);
    TEST_ASSERT(!nmol->getBondBetweenAtoms(0,1));
    TEST_ASSERT(!nmol->getBondBetweenAtoms(3,4));
    TEST_ASSERT(nmol->getAtomWithIdx(5)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(5)->getIsotope()==10);
    TEST_ASSERT(nmol->getBondBetweenAtoms(1,5));
    TEST_ASSERT(nmol->getAtomWithIdx(6)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(6)->getIsotope()==11);
    TEST_ASSERT(nmol->getBondBetweenAtoms(0,6));
    
    TEST_ASSERT(nmol->getAtomWithIdx(7)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(7)->getIsotope()==100);
    TEST_ASSERT(nmol->getBondBetweenAtoms(4,7));
    TEST_ASSERT(nmol->getAtomWithIdx(8)->getAtomicNum()==0);
    TEST_ASSERT(nmol->getAtomWithIdx(8)->getIsotope()==110);
    TEST_ASSERT(nmol->getBondBetweenAtoms(3,8));
    delete mol;
    delete nmol;
  }

  
  BOOST_LOG(rdInfoLog) << "\tdone" << std::endl;
}
示例#20
0
int setAromaticity(RWMol &mol) {
  // FIX: we will assume for now that if the input molecule came
  // with aromaticity information it is correct and we will not
  // touch it. Loop through the atoms and check if any atom has
  // arom stuff set.  We may want check this more carefully later
  // and start from scratch if necessary
  ROMol::AtomIterator ai;
  for (ai = mol.beginAtoms(); ai != mol.endAtoms(); ai++) {
    if ((*ai)->getIsAromatic()) {
      // found aromatic info
      return -1;
    }
  }

  // first find the all the simple rings in the molecule
  VECT_INT_VECT srings;
  if (mol.getRingInfo()->isInitialized()) {
    srings = mol.getRingInfo()->atomRings();
  } else {
    MolOps::symmetrizeSSSR(mol, srings);
  }

  int narom = 0;
  // loop over all the atoms in the rings that can be candidates
  // for aromaticity
  // Atoms are candidates if
  //   - it is part of ring
  //   - has one or more electron to donate or has empty p-orbitals
  int natoms = mol.getNumAtoms();
  boost::dynamic_bitset<> acands(natoms);
  boost::dynamic_bitset<> aseen(natoms);
  VECT_EDON_TYPE edon(natoms);

  VECT_INT_VECT cRings;  // holder for rings that are candidates for aromaticity
  for (VECT_INT_VECT_I vivi = srings.begin(); vivi != srings.end(); ++vivi) {
    bool allAromatic = true;
    for (INT_VECT_I ivi = (*vivi).begin(); ivi != (*vivi).end(); ++ivi) {
      if (aseen[*ivi]) {
        if (!acands[*ivi]) allAromatic = false;
        continue;
      }
      aseen[*ivi] = 1;
      Atom *at = mol.getAtomWithIdx(*ivi);

      // now that the atom is part of ring check if it can donate
      // electron or has empty orbitals. Record the donor type
      // information in 'edon' - we will need it when we get to
      // the Huckel rule later
      edon[*ivi] = getAtomDonorTypeArom(at);
      acands[*ivi] = isAtomCandForArom(at, edon[*ivi]);
      if (!acands[*ivi]) allAromatic = false;
    }
    if (allAromatic) {
      cRings.push_back((*vivi));
    }
  }

  // first convert all rings to bonds ids
  VECT_INT_VECT brings;
  RingUtils::convertToBonds(cRings, brings, mol);

  // make the neighbor map for the rings
  // i.e. a ring is a neighbor a another candidate ring if
  // shares at least one bond
  // useful to figure out fused systems
  INT_INT_VECT_MAP neighMap;
  RingUtils::makeRingNeighborMap(brings, neighMap, maxFusedAromaticRingSize);

  // now loop over all the candidate rings and check the
  // huckel rule - of course paying attention to fused systems.
  INT_VECT doneRs;
  int curr = 0;
  int cnrs = rdcast<int>(cRings.size());
  boost::dynamic_bitset<> fusDone(cnrs);
  INT_VECT fused;
  while (curr < cnrs) {
    fused.resize(0);
    RingUtils::pickFusedRings(curr, neighMap, fused, fusDone);
    applyHuckelToFused(mol, cRings, brings, fused, edon, neighMap, narom, 6);

    int rix;
    for (rix = 0; rix < cnrs; rix++) {
      if (!fusDone[rix]) {
        curr = rix;
        break;
      }
    }
    if (rix == cnrs) {
      break;
    }
  }

  mol.setProp(common_properties::numArom, narom, true);

  return narom;
}
示例#21
0
文件: test1.cpp 项目: ASKCOS/rdkit
void testGithub336() {
  BOOST_LOG(rdInfoLog) << "testing github issue 336: bad canonical smiles for "
                          "conjugated double bonds" << std::endl;
  // some tests around dealing with bad mol blocks
  {
    std::string pathName = getenv("RDBASE");
    pathName += "/External/AvalonTools/test_data/";
    std::ifstream ins((pathName + "EZ_test.2.sdf").c_str());
    std::string mb((std::istreambuf_iterator<char>(ins)),
                   std::istreambuf_iterator<char>());
    ROMol *m = MolBlockToMol(mb);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms() == 17);

    std::string smi1 = AvalonTools::getCanonSmiles(mb, false);
    std::string smi2 = AvalonTools::getCanonSmiles(*m);
    std::cerr << "smi1: " << smi1 << std::endl;
    std::cerr << "smi2: " << smi2 << std::endl;
    TEST_ASSERT(smi1 == smi2);
    delete m;
  }

  {
    std::string pathName = getenv("RDBASE");
    pathName += "/External/AvalonTools/test_data/";
    std::ifstream ins((pathName + "heterocycle.mol").c_str());
    std::string mb((std::istreambuf_iterator<char>(ins)),
                   std::istreambuf_iterator<char>());
    RWMol *m = MolBlockToMol(mb, false);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms() == 6);
    m->updatePropertyCache();
    MolOps::cleanUp(*m);
    MolOps::setAromaticity(*m);

    std::string smi1 = AvalonTools::getCanonSmiles(mb, false);
    std::string smi2 = AvalonTools::getCanonSmiles(*m);
    std::cerr << "smi1: " << smi1 << std::endl;
    std::cerr << "smi2: " << smi2 << std::endl;
    TEST_ASSERT(smi1 == smi2);
    TEST_ASSERT(smi1 == "CC1C=NNC=1");
    delete m;
  }

  {
    std::string pathName = getenv("RDBASE");
    pathName += "/External/AvalonTools/test_data/";
    std::ifstream ins((pathName + "heterocycle2.mol").c_str());
    std::string mb((std::istreambuf_iterator<char>(ins)),
                   std::istreambuf_iterator<char>());
    RWMol *m = MolBlockToMol(mb, false);
    TEST_ASSERT(m);
    TEST_ASSERT(m->getNumAtoms() == 11);
    m->updatePropertyCache();
    MolOps::cleanUp(*m);
    MolOps::setAromaticity(*m);

    std::string smi1 = AvalonTools::getCanonSmiles(mb, false);
    std::string smi2 = AvalonTools::getCanonSmiles(*m);
    std::cerr << "smi1: " << smi1 << std::endl;
    std::cerr << "smi2: " << smi2 << std::endl;
    TEST_ASSERT(smi1 == smi2);
    TEST_ASSERT(smi1 == "CN2C=CC1=CC(=O)NC=C12");
    delete m;
  }

  BOOST_LOG(rdInfoLog) << "done" << std::endl;
}
示例#22
0
void test3(){
#ifdef SUPPORT_COMPRESSED_IO
  BOOST_LOG(rdInfoLog) << "testing writing pickles to a file then reading them back" << std::endl;
  std::string rdbase = getenv("RDBASE");
  std::string fname2 = rdbase + "/Code/Demos/RDKit/BinaryIO/test_data/mols.rdb";

  std::string smiles,buff;
  RWMol *m;

  std::vector<unsigned int> filePs;
  io::filtering_ostream outStrm;
  outStrm.push(io::file_sink(fname2,std::ios_base::out|std::ios_base::binary));
  TEST_ASSERT(outStrm.is_complete());
  
  smiles="C1CCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(4));
  
  MolPickler::pickleMol(*m,outStrm);
  delete m;

  smiles="C1CCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(4));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(0);
  MolPickler::pickleMol(*m,outStrm);
  delete m;
  
  smiles="C1CCCC1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(5));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,outStrm);
  delete m;
  
  smiles="c1ccccc1";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(6));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,outStrm);
  delete m;
  
  smiles="c1ccccc1CC(=O)O";
  m = SmilesToMol(smiles);
  TEST_ASSERT(m);
  TEST_ASSERT(m->getNumAtoms(9));
  RDDepict::compute2DCoords(*m);
  filePs.push_back(outStrm.tellp());
  MolPickler::pickleMol(*m,outStrm);
  delete m;

  outStrm.flush();
  outStrm.reset();
  
  io::filtering_istream inStrm;
  inStrm.push(io::file_source(fname2,std::ios_base::in|std::ios_base::binary));
  TEST_ASSERT(inStrm.is_complete());

  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(inStrm,*m);
  TEST_ASSERT(m->getNumAtoms(4));
  delete m;

  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(inStrm,*m);
  TEST_ASSERT(m->getNumAtoms(4));
  delete m;

  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(inStrm,*m);
  TEST_ASSERT(m->getNumAtoms(5));
  delete m;

  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(inStrm,*m);
  TEST_ASSERT(m->getNumAtoms(6));
  delete m;

  m = new RWMol();
  TEST_ASSERT(m);
  MolPickler::molFromPickle(inStrm,*m);
  TEST_ASSERT(m->getNumAtoms(9));
  delete m;


  BOOST_LOG(rdInfoLog) << "done" << std::endl;
#else
  BOOST_LOG(rdInfoLog) << "Compressed IO disabled; test skipped" << std::endl;
#endif
}