示例#1
0
void runSDFile(std::string fileName,int checkEvery=10){
  SDMolSupplier suppl(fileName,false);
  
  RWMol *mol;

  mol = (RWMol *)suppl.next();
  while(mol){
    std::string name;
    mol->getProp("_Name",name);
    std::cerr << "Mol: " << name << std::endl;
    try{
      MolOps::sanitizeMol(*mol);
    } catch (...) {
      std::cerr << " sanitization failed" << std::endl;
      delete mol;
      mol = 0;
    }
    if(mol){
      ROMol *mol2=MolOps::addHs(*mol,false,true);
      delete mol;
      runMol(mol2,checkEvery,false);
      delete mol2;
    }
    mol = (RWMol *)suppl.next();

  }

}
示例#2
0
int main(int argc, char *argv[]) {
  RDLog::InitLogs();
  std::string fname;
  if (argc > 1) {
    fname = argv[1];
  } else {
    BOOST_LOG(rdErrorLog) << "Pass in the list of smiles\n";
  }

  std::ifstream inStream(fname.c_str());
  const int MAX_LINE_LEN = 256;
  char inLine[MAX_LINE_LEN];
  std::string tmpstr;
  std::string smi;
  inStream.getline(inLine, MAX_LINE_LEN, '\n');
  tmpstr = inLine;
  // MolOps molop;
  while (tmpstr.size() > 0) {
    getSmiles(tmpstr, smi);
    RWMol *m = SmilesToMol(smi, 0, 0);

    try {
      // testKekule(*m);

      MolOps::sanitizeMol(*m);

      int nar;
      m->getProp(common_properties::numArom, nar);
      BOOST_LOG(rdInfoLog) << nar << "\n";

      // MolOps::setHybridization(*m);
      delete m;
    } catch (MolSanitizeException) {
      BOOST_LOG(rdErrorLog) << smi << "\n";
      delete m;
    }
    inStream.getline(inLine, MAX_LINE_LEN, '\n');
    tmpstr = inLine;
  }
  return 1;
}
  // ------------------------------------------------------------------
  //
  // Enumerates the library around a template and returns the result.
  //
  //
  // ------------------------------------------------------------------
  RWMOL_SPTR_VECT enumerateLibrary(RWMol *templateMol,
				   VECT_RWMOL_SPTR_VECT &sidechains,
				   bool orientSidechains){
    PRECONDITION(templateMol,"bad molecule");
    RWMOL_SPTR_VECT res,tmp;
    res.push_back(RWMOL_SPTR(new RWMol(*templateMol)));

    // if there's no attachment point on the molecule or no
    // sidechains, return now: 
    if(!templateMol->hasProp(common_properties::maxAttachIdx) || sidechains.size()==0 )
      return res;

    int maxIdx;
    templateMol->getProp(common_properties::maxAttachIdx,maxIdx);

    tmp.clear();
    // loop over the sidechains and attach them
    for(unsigned int i=0;i<sidechains.size();i++){
      int tgtMark=CONNECT_BOOKMARK_START+i;
      // here's another boundary condition
      if(tgtMark>maxIdx) break;

      /// loop over all atoms with the appropriate mark
      //  This means that if a mol has two attachment points with the
      //  same name (e.g. two Xa's) they'll always have the same
      //  sidechain attached to them.  This is a feature.
      RWMOL_SPTR_VECT::iterator sidechainIt;
      for(sidechainIt=sidechains[i].begin();
	  sidechainIt!=sidechains[i].end();
	  sidechainIt++){
	// we've got our sidechain, find the atom it attaches from
	if( (*sidechainIt)->hasAtomBookmark(CONNECT_BOOKMARK_START) ){
	  //
	  // NOTE: If there's more than one marked atom in the sidechain,
	  ///      we'll only use the first for the moment.
	  //
	  int sidechainAtomIdx = (*sidechainIt)->getAtomWithBookmark(CONNECT_BOOKMARK_START)->getIdx();
	
	  // now add the sidechain to each molecule
	  RWMOL_SPTR_VECT::iterator templMolIt;
	  // loop over all the mols we've generated to this point
	  for(templMolIt=res.begin();templMolIt!=res.end();templMolIt++){
	    RWMol *templ =  new RWMol(**templMolIt);
	    std::string name,tmpStr;
	    if(templ->hasProp(common_properties::_Name)){
	      templ->getProp(common_properties::_Name,tmpStr);
	      name = name + " " + tmpStr;
	    }
	    while(templ->hasAtomBookmark(tgtMark)){
	      // this is the atom we'll be replacing in the template
	      Atom *at = templ->getAtomWithBookmark(tgtMark);

	      // copy and transform the sidechain:
	      RWMol *sidechain;
	      if(orientSidechains){
		sidechain = new RWMol(*(sidechainIt->get()));
		orientSidechain(templ,sidechain,
				at->getIdx(),sidechainAtomIdx);
	      } else {
		sidechain = sidechainIt->get();
	      }
	      // FIX: need to use the actual bond order here:
	      molAddSidechain(templ,sidechain,
			      at->getIdx(),sidechainAtomIdx,
			      Bond::SINGLE);
	      if(sidechain->hasProp(common_properties::_Name)){
		sidechain->getProp(common_properties::_Name,tmpStr);
		name = name + " " + tmpStr;
	      }
	      templ->clearAtomBookmark(tgtMark,at);
	      if(orientSidechains){
		delete sidechain;
	      }
	    }
	    //std::cout << templ << "> " << MolToSmiles(*templ) << std::endl;
	    if(name != "") templ->setProp(common_properties::_Name,name);
	    tmp.push_back(RWMOL_SPTR(templ));
	  }
	}
      }

      //
      // if we just made any molecules, free up the memory used by the
      // existing result set and move the molecules we just generated
      // over
      if(tmp.size()){
#if 0      
	RWMOL_SPTR_VECT::iterator tmpMolIt;
	for(tmpMolIt=res.begin();tmpMolIt!=res.end();tmpMolIt++){
	  delete *tmpMolIt;
	}
#endif
	res = tmp;
	tmp.clear();
      }
    }
    return res;
  }