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 testSmilesWriter2() { { std::stringstream ss; SmilesWriter *writer = new SmilesWriter(&ss, " ","Name",false); RWMol *mol; mol = SmilesToMol("c1ccccc1"); //MolOps::Kekulize(*mol); writer->write(*mol); delete mol; mol = SmilesToMol("F[C@H](Cl)Br"); writer->write(*mol); delete mol; writer->flush(); TEST_ASSERT(ss.str()=="c1ccccc1 0\nFC(Cl)Br 1\n"); delete writer; } { std::stringstream ss; SmilesWriter *writer = new SmilesWriter(&ss, " ","Name",false,false,true); RWMol *mol; mol = SmilesToMol("c1ccccc1"); MolOps::Kekulize(*mol); writer->write(*mol); delete mol; mol = SmilesToMol("F[C@H](Cl)Br"); writer->write(*mol); delete mol; writer->flush(); TEST_ASSERT(ss.str()=="C1=CC=CC=C1 0\nF[C@H](Cl)Br 1\n"); delete writer; } }
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; } } }