Example #1
0
  ChemicalReaction * RxnMolToChemicalReaction(const ROMol &mol)
  {
	ChemicalReaction *rxn=new ChemicalReaction();

	MOL_SPTR_VECT fragments = MolOps::getMolFrags(mol);

	unsigned countFragments = 0;
	for(MOL_SPTR_VECT::iterator iter = fragments.begin();
		    iter != fragments.end(); ++iter, countFragments++){
	  int role = getRXNRoleOfMolecule(*iter->get());
      if(!testForSameRXNRoleOfAllMoleculeAtoms(*iter->get(), role)){
    	BOOST_LOG(rdWarningLog)<<">> Atoms within one molecule have different RXN roles.\n";
        continue;
      }
      switch(role){
      case 1:
    	rxn->addReactantTemplate(*iter);
        break;
      case 2:
    	rxn->addProductTemplate(*iter);
        break;
      case 3:
    	rxn->addAgentTemplate(*iter);
        break;
      default:
    	BOOST_LOG(rdWarningLog)<<">> Fragment "<< countFragments <<" not included in the reaction, atoms do not have a correct RXN role.\n";
      }
	}
    return rxn;    
  }
Example #2
0
void ReactionDemo() {
  // reaction smarts for a crude amide-bond formation definition:
  std::string sma = "[C:1](=[O:2])[OH].[N:3]>>[O:2]=[C:1][N:3]";
  // construct the reaction:
  ChemicalReaction *rxn = RxnSmartsToChemicalReaction(sma);
  // now initialize it and check for errors:
  rxn->initReactantMatchers();
  unsigned int nWarn, nError;
  rxn->validate(nWarn, nError);

  ROMol *mol;
  MOL_SPTR_VECT reacts;

  // build the list of reactants:
  ROMOL_SPTR react1(SmilesToMol("CC(=O)O"));
  ROMOL_SPTR react2(SmilesToMol("CCNCC1NC1"));
  reacts.push_back(react1);
  reacts.push_back(react2);

  // run the reaction, it returns a vector of vectors of product molecules:
  std::vector<MOL_SPTR_VECT> prods;
  prods = rxn->runReactants(reacts);

  // for each of the possible applications of the reaction to the reactants:
  for (unsigned int i = 0; i < prods.size(); ++i) {
    BOOST_LOG(rdInfoLog) << " product set: " << i << std::endl;
    // for each product of that application:
    for (unsigned int j = 0; j < prods[i].size(); ++j) {
      std::string psmiles = MolToSmiles(*prods[i][j], true);
      BOOST_LOG(rdInfoLog) << "   product : " << j << " " << psmiles
                           << std::endl;
    }
  }
}
Example #3
0
MOL_SPTR_VECT getReactantsFromRGroups(const std::vector<MOL_SPTR_VECT> &bbs,
                                      const RGROUPS &rgroups) {
  PRECONDITION(bbs.size() == rgroups.size(),
               "BBS and RGROUPS must have the same # reactants");
  MOL_SPTR_VECT result;
  result.reserve(bbs.size());
  for (size_t i = 0; i < bbs.size(); ++i) {
    result.push_back(bbs[i][rgroups[i]]);
  }
  return result;
}
Example #4
0
 RGroupDecompositionHelper(python::object cores,
                           const RGroupDecompositionParameters &params =
                               RGroupDecompositionParameters()) {
   python::extract<ROMol> isROMol(cores);
   if (isROMol.check()) {
     decomp = new RGroupDecomposition(isROMol(), params);
   } else {
     MOL_SPTR_VECT coreMols;
     python::stl_input_iterator<ROMOL_SPTR> iter(cores), end;
     while (iter != end) {
       if (!*iter) throw_value_error("reaction called with None reactants");
       coreMols.push_back(*iter);
       ++iter;
     }
     decomp = new RGroupDecomposition(coreMols, params);
   }
 }
MOL_SPTR_VECT generateOneProductSet(const ChemicalReaction& rxn,
                                    const MOL_SPTR_VECT& reactants,
                                    const std::vector<MatchVectType> &reactantsMatch)
{
    PRECONDITION(reactants.size() == reactantsMatch.size(),"vector size mismatch");

    // if any of the reactants have a conformer, we'll go ahead and
    // generate conformers for the products:
    bool doConfs=false;
    BOOST_FOREACH(ROMOL_SPTR reactant,reactants) {
        if(reactant->getNumConformers()) {
            doConfs=true;
            break;
        }
    }

    MOL_SPTR_VECT res;
    res.resize(rxn.getNumProductTemplates());
    unsigned int prodId=0;
    for(MOL_SPTR_VECT::const_iterator pTemplIt = rxn.beginProductTemplates();
            pTemplIt != rxn.endProductTemplates(); ++pTemplIt) {
        // copy product template and its properties to a new product RWMol
        RWMOL_SPTR product = initProduct(*pTemplIt);
        Conformer *conf = 0;
        if(doConfs) {
            conf = new Conformer();
            conf->set3D(false);
        }

        unsigned int reactantId = 0;
        for(MOL_SPTR_VECT::const_iterator iter = rxn.beginReactantTemplates();
                iter != rxn.endReactantTemplates(); ++iter, reactantId++) {
            addReactantAtomsAndBonds(rxn, product, reactants.at(reactantId),
                                     reactantsMatch.at(reactantId),
                                     *iter, conf);
        }

        if(doConfs) {
            product->addConformer(conf,true);
        }
        res[prodId] = product;
        ++prodId;
    }
    return res;
}
  MOL_SPTR_VECT readFuncGroups(std::istream &inStream,int nToRead) {
    MOL_SPTR_VECT funcGroups;
    funcGroups.clear();
    if (inStream.bad()) {
      throw BadFileException("Bad stream contents.");
    }
    const int MAX_LINE_LEN = 512;
    char inLine[MAX_LINE_LEN];
    std::string tmpstr;
    int nRead=0;
    while (!inStream.eof() && (nToRead<0 || nRead<nToRead)) {
      inStream.getline(inLine, MAX_LINE_LEN,'\n');
      tmpstr = inLine;
      // parse the molecule on this line (if there is one)
      ROMol *mol = getSmarts(tmpstr);
      if (mol) {
	funcGroups.push_back(ROMOL_SPTR(mol));
	nRead++;
      }
    }
    return funcGroups;
  }