Hi, I am trying to convert small CSV file (SMILES and associated property) as SD File using CDK 1.2.0.
I am using parseSmiles -> StructureDiagramGenerator -> setSdFields -> MDLWriter sequence. Am getting following error: (1) cannot find symbol in class org.openscience.cdk.io.MDLWriter.mw.setSdFields(map); (2) When I comment mw.setSdFields(map) line, I get the structure (no SD tag) printed out with following null pointer Exception Reason: null java.lang.NullPointerException at java.io.Reader.<init>(Reader.java:61) at java.io.InputStreamReader.<init>(InputStreamReader.java:55) at org.openscience.cdk.layout.TemplateHandler.loadTemplates(TemplateHandler.java:98) at org.openscience.cdk.layout.TemplateHandler.<init>(TemplateHandler.java:83) at org.openscience.cdk.layout.StructureDiagramGenerator.setMolecule(StructureDiagramGenerator.java:131) at org.openscience.cdk.layout.StructureDiagramGenerator.setMolecule(StructureDiagramGenerator.java:221) at Smile2Str.GetStr(csv2sdf.java:47) at csv2sdf.main(csv2sdf.java:102) Attached is code and data file Any help will be appreciated. Thanks om Bioinformatics Center University of Pune Pune-411007 India
//-----------------------------------------------------------// // Code written based on CDK for CSV to SDF file conversion // // ompan...@gmail.com // // date: 28/05/09 // // ----------------------------------------------------------// import org.openscience.cdk.*; import org.openscience.cdk.interfaces.IChemObject; import org.openscience.cdk.interfaces.IChemObjectBuilder; import org.openscience.cdk.interfaces.IAtomContainer; import org.openscience.cdk.interfaces.IMolecule; import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector; import org.openscience.cdk.layout.StructureDiagramGenerator; import org.openscience.cdk.tools.manipulator.AtomContainerManipulator; import org.openscience.cdk.exception.CDKException; import org.openscience.cdk.io.MDLWriter; import org.openscience.cdk.io.iterator.*; import org.openscience.cdk.smiles.*; import java.io.*; import java.util.*; import java.lang.*; import java.util.HashMap; import java.util.regex.*; import java.io.StringWriter; import java.io.FileWriter; import java.io.File; import java.sql.*; class Smile2Str { IMolecule mol = null; HashMap<String, Object> map = new HashMap<String, Object>(); //private HashMap sd_tags = new HashMap(); public void GetStr (String smi, int ID, double MIC) // constructor { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); StructureDiagramGenerator sdg = new StructureDiagramGenerator(); StringWriter w = new StringWriter(); try { mol = sp.parseSmiles(smi); CDKHueckelAromaticityDetector.detectAromaticity(mol); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); try { sdg.setMolecule(mol); sdg.generateCoordinates(); mol = sdg.getMolecule(); //mol.setProperty("NIAID", ID); map.put("NIAID", ID); try { MDLWriter mw = new MDLWriter(w); mw.setSdFields(map); mw.writeMolecule(mol); mw.close(); } catch (Exception e) {System.out.println(e.toString());} System.out.println(w.toString()); } catch (Exception exc) { exc.printStackTrace();} } catch (CDKException cdke) { cdke.printStackTrace();} } // method } // class class csv2sdf { public static void main(String[] args) throws CDKException { int i, j, k=0; String [] myArr = null; String strLine; int NIAID = 0; double MIC = 0.00; String SMILES; String colname; //Read File Line By Line try { FileInputStream fstream = new FileInputStream("NIAID.csv"); //FileWriter w1 = new FileWriter (new File ("molecule.sdf")) ; Smile2Str smi2str = new Smile2Str (); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); strLine = br.readLine(); if (strLine != null) { System.out.println ("Col name:" +strLine); while ((strLine = br.readLine()) != null) { // "NIAID ID","MIC original","MIC original unit","MIC (uM)","TB dataset ID","Smiles" // 180691,0.000003,"uM",0.000003,2767,"o1c2c(nc1C)c(OC(=O)COC)c1c(cccc1)c2OC(=O)COC" strLine=strLine.replaceAll("\n",""); myArr = strLine.split (","); NIAID=Integer.valueOf(myArr[0]); MIC=Double.valueOf(myArr[3]); SMILES=myArr[5]; SMILES=SMILES.replaceAll("\"", ""); // remove the quotes from SMILES smi2str.GetStr(SMILES, NIAID, MIC); //System.out.println (SMILES + NIAID + MIC); } } //Close the input stream in.close(); } catch (Exception fe){System.err.println("Error: " + fe.getMessage());} } }//class
"NIAID ID","MIC original","MIC original unit","MIC (uM)","TB dataset ID","Smiles" 180691,0.000003,"uM",0.000003,2767,"o1c2c(nc1C)c(OC(=O)COC)c1c(cccc1)c2OC(=O)COC" 180690,0.000010,"uM",0.000010,2766,"o1c2c(nc1-c1ccccc1)C(=O)c1c(cccc1)C2=O" 180689,0.000010,"uM",0.000010,2765,"o1c2c(nc1C)C(=O)c1c(cccc1)C2=O" 180692,0.000020,"uM",0.000020,2768,"s1c2c(nc1C)C(=O)c1c(cccc1)C2=O" 185726,0.000100,"ug/ml",0.000113,2807,"O1c2c3c4c(c([O-])c2C)c([O-])c(NC(=O)/C(=C/C=C\C(C)C(O)C(C)C(O)C(C)C(OC(=O)C)C(C)C(OC)\C=C/OC1(C)C3=O)/C)c(N1CC[NH+](CC1)Cc1ccc(cc1)C)c4O" 2516,0.000100,"ug/ml",0.000119,28,"O1c2c3c4c(c([O-])c2C)c([O-])c(NC(=O)/C(=C/C=C\C(C)C(O)C(C)C(O)C(C)C(OC(=O)C)C(C)C(OC)\C=C/OC1(C)C3=O)/C)c(N1CC[NH+](CC1)CC(C)C)c4O" 113916,0.000100,"ug/ml",0.000124,2317,"s1cccc1\C=N/c1c2NC(=O)/C(=C\C=C\C(C)C(O)C(C)C(O)C(C)C(OC(=O)C)C(C)C(OC)\C=C/OC3(Oc4c(c(c(c([O-])c4C)c2[O-])c1O)C3=O)C)/C" 113800,0.000150,"ug/ml",0.000174,2248,"O1c2c3c4c(c([O-])c2C)C(=O)C(NC(=O)/C(=C/C=C\C(C)C(O)C(C)C(O)C(C)C(OC(=O)C)C(C)C(OC)\C=C/OC1(C)C3=O)/C)=C1NC2(N=C14)CC[NH+](CC2)CCC(C)C" 185729,0.000300,"ug/ml",0.000326,2810,"O1c2c3c4c(c([O-])c2C)c([O-])c(NC(=O)/C(=C/C=C\C(C)C(O)C(C)C(O)C(C)C(OC(=O)C)C(C)C(OC)\C=C/OC1(C)C3=O)/C)c(N1CC[NH+](CC1)Cc1c2c(ccc1)cccc2)c4O"
------------------------------------------------------------------------------ Register Now for Creativity and Technology (CaT), June 3rd, NYC. CaT is a gathering of tech-side developers & brand creativity professionals. Meet the minds behind Google Creative Lab, Visual Complexity, Processing, & iPhoneDevCamp as they present alongside digital heavyweights like Barbarian Group, R/GA, & Big Spaceship. http://p.sf.net/sfu/creativitycat-com
_______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user