void prepareMolForDrawing(RWMol &mol, bool kekulize, bool addChiralHs, bool wedgeBonds, bool forceCoords) { if (kekulize) { MolOps::Kekulize(mol, false); // kekulize, but keep the aromatic flags! } if (addChiralHs) { std::vector<unsigned int> chiralAts; for (RWMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms(); ++atIt) { if ((*atIt)->getChiralTag() == Atom::CHI_TETRAHEDRAL_CCW || (*atIt)->getChiralTag() == Atom::CHI_TETRAHEDRAL_CW) { chiralAts.push_back((*atIt)->getIdx()); } } if (chiralAts.size()) { bool addCoords = false; if (!forceCoords && mol.getNumConformers()) addCoords = true; MolOps::addHs(mol, false, addCoords, &chiralAts); } } if (forceCoords || !mol.getNumConformers()) { RDDepict::compute2DCoords(mol); } if (wedgeBonds) { WedgeMolBonds(mol, &mol.getConformer()); } }
void prepareMolForDrawing(RWMol &mol, bool kekulize, bool addChiralHs, bool wedgeBonds, bool forceCoords) { if (kekulize) { MolOps::Kekulize(mol, false); // kekulize, but keep the aromatic flags! } if (addChiralHs) { std::vector<unsigned int> chiralAts; for (RWMol::AtomIterator atIt = mol.beginAtoms(); atIt != mol.endAtoms(); ++atIt) { if (isAtomCandForChiralH(mol, *atIt)) { chiralAts.push_back((*atIt)->getIdx()); } } if (chiralAts.size()) { bool addCoords = false; if (!forceCoords && mol.getNumConformers()) addCoords = true; MolOps::addHs(mol, false, addCoords, &chiralAts); } } if (forceCoords || !mol.getNumConformers()) { // compute 2D coordinates in a standard orientation: const bool canonOrient = true; RDDepict::compute2DCoords(mol, NULL, canonOrient); } if (wedgeBonds) { WedgeMolBonds(mol, &mol.getConformer()); } }
void test2() { BOOST_LOG(rdInfoLog) << "testing coordinate generation" << std::endl; #if 1 { RWMol *m = SmilesToMol("c1cccnc1"); TEST_ASSERT(m); unsigned int confId = AvalonTools::set2DCoords(*m); TEST_ASSERT(m->getNumConformers() == 1); TEST_ASSERT(confId == 0); delete m; } #endif { std::string molb = AvalonTools::set2DCoords("c1cccnc1", true); TEST_ASSERT(molb != ""); } BOOST_LOG(rdInfoLog) << "done" << std::endl; }
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; }