void alignMolConformers(ROMol &mol, const std::vector<unsigned int> *atomIds, const std::vector<unsigned int> *confIds, const RDNumeric::DoubleVector *weights, bool reflect, unsigned int maxIters, std::vector<double> *RMSlist) { if (mol.getNumConformers() == 0) { // nothing to be done ; return; } RDGeom::Point3DConstPtrVect refPoints, prbPoints; int cid = -1; if ((confIds != 0) && (confIds->size() > 0)) { cid = confIds->front(); } const Conformer &refCnf = mol.getConformer(cid); _fillAtomPositions(refPoints, refCnf, atomIds); // now loop throught the remaininf conformations and transform them RDGeom::Transform3D trans; double ssd; if (confIds == 0) { unsigned int i = 0; ROMol::ConformerIterator cnfi; // Conformer *conf; for (cnfi = mol.beginConformers(); cnfi != mol.endConformers(); cnfi++) { // conf = (*cnfi); i += 1; if (i == 1) { continue; } _fillAtomPositions(prbPoints, *(*cnfi), atomIds); ssd = RDNumeric::Alignments::AlignPoints(refPoints, prbPoints, trans, weights, reflect, maxIters); if (RMSlist) { ssd /= (prbPoints.size()); RMSlist->push_back(sqrt(ssd)); } MolTransforms::transformConformer(*(*cnfi), trans); } } else { std::vector<unsigned int>::const_iterator cai; unsigned int i = 0; for (cai = confIds->begin(); cai != confIds->end(); cai++) { i += 1; if (i == 1) { continue; } Conformer &conf = mol.getConformer(*cai); _fillAtomPositions(prbPoints, conf, atomIds); ssd = RDNumeric::Alignments::AlignPoints(refPoints, prbPoints, trans, weights, reflect, maxIters); if (RMSlist) { ssd /= (prbPoints.size()); RMSlist->push_back(sqrt(ssd)); } MolTransforms::transformConformer(conf, trans); } } }
std::string MolToTPLText(const ROMol &mol,std::string partialChargeProp,bool writeFirstConfTwice){ if(!mol.getNumConformers()){ BOOST_LOG(rdErrorLog)<<"Cannot write molecules with no conformers to TPL files\n"; return ""; } std::ostringstream res; std::string tempStr; res << "BioCAD format, all rights reserved"<<std::endl; res << "Output from RDKit"<<std::endl; if(!mol.hasProp("_Name")){ BOOST_LOG(rdWarningLog)<<"Molecule has no name; arbitrary name assigned.\n"; tempStr = "Unnamed molecule"; } else { mol.getProp("_Name",tempStr); } res << "NAME "<<tempStr<<std::endl; res << "PROP 7 1"<<std::endl; res << mol.getNumAtoms() << " " << mol.getNumBonds() << std::endl; ROMol::ConstConformerIterator confIt=mol.beginConformers(); // write the atoms: for(unsigned int i=0;i<mol.getNumAtoms();++i){ TPLWriter::writeAtom(mol,i,confIt,res,partialChargeProp); } // write the bonds: for(unsigned int i=0;i<mol.getNumBonds();++i){ TPLWriter::writeBond(mol,i,confIt,res); } // write the additional conformations: res << "CONFS "<< mol.getNumConformers()-1<<std::endl; if(!writeFirstConfTwice) ++confIt; while(confIt!=mol.endConformers()){ std::stringstream tmpStrm; std::string confName; tmpStrm<<"conformer_"<<(*confIt)->getId(); confName = tmpStrm.str(); res << "NAME " << confName << std::endl; for(unsigned int i=0;i<mol.getNumAtoms();++i){ const RDGeom::Point3D &pos=(*confIt)->getAtomPos(i); res << " " << 100.*pos.x << " " << 100.*pos.y << " " << 100.*pos.z << std::endl; } ++confIt; if(confIt!=mol.endConformers()){ res << std::endl; } } return res.str(); }
bool getMolAtomPoints(const ROMol &mol, std::vector<RDGeom::Point3D> &atomPoint, bool twod) { bool non_zero_z = false; atomPoint.resize(mol.getNumAtoms()); // take X,Y,Z coordinates of each atom if (0 != mol.getNumConformers()) for (RDKit::ROMol::ConstConformerIterator cnfi = mol.beginConformers(); cnfi != mol.endConformers(); cnfi++) { const Conformer &conf = **cnfi; // mol.getConformer(confId); if (twod || conf.is3D()) { for (unsigned i = 0; i < mol.getNumAtoms(); i++) { atomPoint[i] = conf.getAtomPos(i); if (fabs(atomPoint[i].z) >= 1.e-7) non_zero_z = true; } break; } } if (atomPoint.empty()) { // compute XYZ // TODO: // ???? .......... } return non_zero_z; }