//! Parse a text stream in MDL rxn format into a ChemicalReaction ChemicalReaction *RxnDataStreamToChemicalReaction(std::istream &inStream, unsigned int &line) { std::string tempStr; // header line line++; tempStr = getLine(inStream); if (inStream.eof()) { throw ChemicalReactionParserException("premature EOF hit."); } if (tempStr.substr(0, 4) != "$RXN") { throw ChemicalReactionParserException("$RXN header not found"); } int version = 2000; if (tempStr.size() >= 10 && tempStr.substr(5, 5) == "V3000") version = 3000; ChemicalReaction *res = nullptr; try { if (version == 2000) { ParseV2000RxnBlock(inStream, line, res); } else { ParseV3000RxnBlock(inStream, line, res); } } catch (ChemicalReactionParserException &e) { // catch our exceptions and throw them back after cleanup delete res; res = nullptr; throw e; } // convert atoms to queries: for (MOL_SPTR_VECT::const_iterator iter = res->beginReactantTemplates(); iter != res->endReactantTemplates(); ++iter) { // to write the mol block, we need ring information: for (ROMol::AtomIterator atomIt = (*iter)->beginAtoms(); atomIt != (*iter)->endAtoms(); ++atomIt) { FileParserUtils::replaceAtomWithQueryAtom((RWMol *)iter->get(), (*atomIt)); } } for (MOL_SPTR_VECT::const_iterator iter = res->beginProductTemplates(); iter != res->endProductTemplates(); ++iter) { // to write the mol block, we need ring information: for (ROMol::AtomIterator atomIt = (*iter)->beginAtoms(); atomIt != (*iter)->endAtoms(); ++atomIt) { FileParserUtils::replaceAtomWithQueryAtom((RWMol *)iter->get(), (*atomIt)); } } updateProductsStereochem(res); // RXN-based reactions do not have implicit properties res->setImplicitPropertiesFlag(false); return res; };
FragCatParams::FragCatParams(const FragCatParams &other) { d_funcGroups.clear(); // copy consttructor d_typeStr = other.getTypeStr(); d_lowerFragLen = other.getLowerFragLength(); d_upperFragLen = other.getUpperFragLength(); d_tolerance = other.getTolerance(); // std::cout << "In param copier\n"; const MOL_SPTR_VECT &ofgrps = other.getFuncGroups(); // const MOL_PTR_VECT &ofgrps = other.getFuncGroups(); MOL_SPTR_VECT::const_iterator fgi; // MOL_PTR_VECT_CI fgi; for (fgi = ofgrps.begin(); fgi != ofgrps.end(); fgi++) { ROMol *nmol = new ROMol(*(fgi->get())); // ROMol *nmol = new ROMol(*(*fgi)); d_funcGroups.push_back(ROMOL_SPTR(nmol)); // d_funcGroups.push_back(nmol); } }
void ReactionPickler::_pickle(const ChemicalReaction *rxn, std::ostream &ss) { PRECONDITION(rxn, "empty reaction"); uint32_t tmpInt; tmpInt = static_cast<int32_t>(rxn->getNumReactantTemplates()); streamWrite(ss, tmpInt); tmpInt = static_cast<int32_t>(rxn->getNumProductTemplates()); streamWrite(ss, tmpInt); tmpInt = static_cast<int32_t>(rxn->getNumAgentTemplates()); streamWrite(ss, tmpInt); uint32_t flag = 0; if (rxn->getImplicitPropertiesFlag()) flag |= 0x1; if (rxn->df_needsInit) flag |= 0x2; streamWrite(ss, flag); // ------------------- // // Write Reactants // // ------------------- streamWrite(ss, BEGINREACTANTS); for (MOL_SPTR_VECT::const_iterator tmpl = rxn->beginReactantTemplates(); tmpl != rxn->endReactantTemplates(); ++tmpl) { MolPickler::pickleMol(tmpl->get(), ss); } streamWrite(ss, ENDREACTANTS); streamWrite(ss, BEGINPRODUCTS); for (MOL_SPTR_VECT::const_iterator tmpl = rxn->beginProductTemplates(); tmpl != rxn->endProductTemplates(); ++tmpl) { MolPickler::pickleMol(tmpl->get(), ss, PicklerOps::AllProps); } streamWrite(ss, ENDPRODUCTS); if (rxn->getNumAgentTemplates()) { streamWrite(ss, BEGINAGENTS); for (MOL_SPTR_VECT::const_iterator tmpl = rxn->beginAgentTemplates(); tmpl != rxn->endAgentTemplates(); ++tmpl) { MolPickler::pickleMol(tmpl->get(), ss); } streamWrite(ss, ENDAGENTS); } streamWrite(ss, ENDREACTION); } // end of _pickle
MatchVectType findFuncGroupsOnMol(const ROMol &mol, const FragCatParams *params, INT_VECT &fgBonds) { PRECONDITION(params,"bad params"); fgBonds.clear(); std::pair<int, int> amat; MatchVectType aidFgrps; std::vector<MatchVectType> fgpMatches; std::vector<MatchVectType>::const_iterator mati; MatchVectType::const_iterator mi; int aid; //const ROMol *fgrp; INT_VECT_CI bi; aidFgrps.clear(); int fid = 0; const MOL_SPTR_VECT &fgrps = params->getFuncGroups(); MOL_SPTR_VECT::const_iterator fgci; for (fgci = fgrps.begin(); fgci != fgrps.end(); fgci++) { const ROMol *fgrp = fgci->get(); std::string fname; (*fgci)->getProp(common_properties::_Name, fname); //std::cout << "Groups number: " << fname << "\n"; //(*fgci)->debugMol(std::cout); //mol->debugMol(std::cout); // match this functional group onto the molecule SubstructMatch(mol, *fgrp, fgpMatches); // loop over all the matches we get for this fgroup for (mati = fgpMatches.begin(); mati != fgpMatches.end(); mati++) { //FIX: we will assume that the first atom in fgrp is always the connection // atom amat = mati->front(); aid = amat.second; //FIX: is this correct - the second entry in the pair is the atom ID from mol // grab the list of atom Ids from mol that match the functional group INT_VECT bondIds, maids; for (mi = mati->begin(); mi != mati->end(); mi++) { maids.push_back(mi->second); } // create a list of bond IDs from these atom ID // these are the bond in mol that are part of portion that matches the // functional group bondIds = Subgraphs::bondListFromAtomList(mol, maids); // now check if all these bonds have been covered as part of larger // functional group that was dealt with earlier // FIX: obviously we assume here that the function groups in params // come in decreasing order of size. bool allDone = true; for (bi = bondIds.begin(); bi != bondIds.end(); bi++) { if (std::find(fgBonds.begin(), fgBonds.end(), (*bi)) == fgBonds.end()) { allDone = false; fgBonds.push_back(*bi); } } if (!allDone) { // this functional group mapping onto mol is not part of a larger func // group mapping so record it aidFgrps.push_back(std::pair<int, int>(aid, fid)); } } fid++; } return aidFgrps; }