Example #1
0
struct reaccs_molecule_t *molToReaccs(const ROMol &mol) {
  std::string molB = MolToMolBlock(mol, true);
  Utils::LocaleSwitcher ls;
  struct reaccs_molecule_t *res = MolStr2Mol((char *)molB.c_str());
  POSTCONDITION(res, "could not build a molecule");
  return res;
}
Example #2
0
  //! returns an RXN block for a reaction
  std::string ChemicalReactionToRxnBlock(const ChemicalReaction &rxn, bool separateAgents){
    std::ostringstream res;
    res<<"$RXN\n\n      RDKit\n\n";
    if(separateAgents){
      res<<std::setw(3)<<rxn.getNumReactantTemplates()
    	 <<std::setw(3)<<rxn.getNumProductTemplates()
         <<std::setw(3)<<rxn.getNumAgentTemplates()<<"\n";
    }
    else{
      res<<std::setw(3)<<(rxn.getNumReactantTemplates()+rxn.getNumAgentTemplates())
    	 <<std::setw(3)<<rxn.getNumProductTemplates()<<"\n";
    }

    for(MOL_SPTR_VECT::const_iterator iter=rxn.beginReactantTemplates();
	iter != rxn.endReactantTemplates();++iter){
      // to write the mol block, we need ring information:
      MolOps::findSSSR(**iter);
      res<<"$MOL\n";
      res << MolToMolBlock(**iter,true,-1,false);
    }
    if(!separateAgents){
      for(MOL_SPTR_VECT::const_iterator iter=rxn.beginAgentTemplates();
          iter != rxn.endAgentTemplates();++iter){
        // to write the mol block, we need ring information:
        MolOps::findSSSR(**iter);
        res<<"$MOL\n";
        res << MolToMolBlock(**iter,true,-1,false);
      }
    }
    for(MOL_SPTR_VECT::const_iterator iter=rxn.beginProductTemplates();
	iter != rxn.endProductTemplates();++iter){
      // to write the mol block, we need ring information:
      MolOps::findSSSR(**iter);
      res<<"$MOL\n";
      res << MolToMolBlock(**iter,true,-1,false);
    }
    if(separateAgents){
      for(MOL_SPTR_VECT::const_iterator iter=rxn.beginAgentTemplates();
          iter != rxn.endAgentTemplates();++iter){
        // to write the mol block, we need ring information:
        MolOps::findSSSR(**iter);
        res<<"$MOL\n";
        res << MolToMolBlock(**iter,true,-1,false);
      }
    }
    return res.str();
  };
Example #3
0
  void SDWriter::write(const ROMol &mol, int confId) {
    PRECONDITION(dp_ostream,"no output stream");

    // write the molecule 
    (*dp_ostream) << MolToMolBlock(mol, true, confId, df_kekulize, df_forceV3000);

    // now write the properties
    STR_VECT_CI pi;
    if (d_props.size() > 0) {
      // check if we have any properties the user specified to write out
      // in which loop over them and write them out
      for (pi = d_props.begin(); pi != d_props.end(); pi++) {
	if (mol.hasProp(*pi)) {
	  writeProperty(mol, (*pi));
	}
      }
    }
    else {
      // if use did not specify any properties, write all non computed properties
      // out to the file
      STR_VECT properties = mol.getPropList();
      STR_VECT compLst;
      if (mol.hasProp(detail::computedPropName)) {
	mol.getProp(detail::computedPropName, compLst);
      }
      STR_VECT_CI pi;
      for (pi = properties.begin(); pi != properties.end(); pi++) {

	// ignore any of the following properties
	if ( ((*pi) == detail::computedPropName) || 
	     ((*pi) == "_Name") ||
	     ((*pi) == "_MolFileInfo") ||
	     ((*pi) == "_MolFileComments") ||
             ((*pi) == "_MolFileChiralFlag")) {
	  continue;
	}

	// check if this property is not computed
	if (std::find(compLst.begin(), compLst.end(), (*pi)) == compLst.end()) {
	  writeProperty(mol, (*pi));
	}
      }
    }
    // add the $$$$ that marks the end of a molecule
    (*dp_ostream) << "$$$$\n";

    ++d_molid;
  }