void SetSmiWriterProps(SmilesWriter &writer, python::object props) { // convert the python list to a STR_VECT STR_VECT propNames; PySequenceHolder<std::string> seq(props); for (unsigned int i = 0; i < seq.size(); i++) { propNames.push_back(seq[i]); } writer.setProps(propNames); }
void testSmilesWriterStrm() { std::string rdbase = getenv("RDBASE"); std::string fname = rdbase + "/Code/GraphMol/FileParsers/test_data/fewSmi.csv"; SmilesMolSupplier *nSup = new SmilesMolSupplier(fname, ",", 1, 0, false); std::string oname = rdbase + "/Code/GraphMol/FileParsers/test_data/outSmiles.csv"; std::ofstream *oStream=new std::ofstream(oname.c_str()); STR_VECT propNames; propNames.push_back(std::string("Column_2")); SmilesWriter *writer = new SmilesWriter(oStream, " "); writer->setProps(propNames); STR_VECT names; STR_VECT props; ROMol *mol = nSup->next(); while (mol) { std::string mname, pval; mol->getProp("_Name", mname); mol->getProp("Column_2", pval); names.push_back(mname); props.push_back(pval); writer->write(*mol); delete mol; try { mol = nSup->next(); } catch (FileParseException &) { break; } } writer->flush(); delete writer; delete nSup; // now read the molecules back in a check if we have the same properties etc nSup = new SmilesMolSupplier(oname); int i = 0; mol = nSup->next(); while (mol){ std::string mname, pval; mol->getProp("_Name", mname); mol->getProp("Column_2", pval); CHECK_INVARIANT(mname == names[i], ""); CHECK_INVARIANT(pval == props[i], ""); i++; delete mol; try { mol = nSup->next(); } catch (FileParseException &) { break; } } }
void testSmilesWriterClose() { std::string rdbase = getenv("RDBASE"); std::string fname = rdbase + "/Code/GraphMol/FileParsers/test_data/fewSmi.csv"; SmilesMolSupplier *nSup = new SmilesMolSupplier(fname, ",", 1, 0, false); std::string oname = rdbase + "/Code/GraphMol/FileParsers/test_data/outSmiles.csv"; STR_VECT propNames; propNames.push_back(std::string("Column_2")); SmilesWriter *writer = new SmilesWriter(oname," ",""); writer->setProps(propNames); STR_VECT props; ROMol *mol = nSup->next(); while (mol) { std::string mname, pval; mol->getProp("Column_2", pval); mol->setProp("_Name","bogus"); props.push_back(pval); writer->write(*mol); delete mol; try { mol = nSup->next(); } catch (FileParseException &) { break; } } writer->close(); delete nSup; // now read the molecules back in a check if we have the same properties etc nSup = new SmilesMolSupplier(oname,",",0,-1); int i = 0; mol = nSup->next(); while (mol){ std::string mname, pval; mol->getProp("_Name", mname); TEST_ASSERT(mname!="bogus"); mol->getProp("Column_2", pval); TEST_ASSERT(pval == props[i]); i++; delete mol; try { mol = nSup->next(); } catch (FileParseException &) { break; } } }