From: Egon W. <eg...@us...> - 2005-06-28 08:32:33
|
Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/io In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18733 Modified Files: MDLWriter.java Log Message: Applied patch by Uli, so that writeMolecule() can be called repetively. Index: MDLWriter.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/io/MDLWriter.java,v retrieving revision 1.57 retrieving revision 1.58 diff -u -r1.57 -r1.58 --- MDLWriter.java 27 Jun 2005 10:53:23 -0000 1.57 +++ MDLWriter.java 28 Jun 2005 08:32:10 -0000 1.58 @@ -60,14 +60,6 @@ * writer.close(); * </pre> * - * <p>The <code>write(Molecule)</code> method cannot be used to write a MDL SDF - * file. Then you have to use code like this: - * <pre> - * MDLWriter writer = new MDLWriter(new FileWriter(new File("output.sdf"))); - * writer.write((SetOfMolecules)moleculeSet); - * writer.close(); - * </pre> - * * See {@cdk.cite DAL92}. * * @cdk.module io @@ -79,6 +71,7 @@ private BufferedWriter writer; private LoggingTool logger; private IsotopeFactory isotopeFactory = null; + private int moleculeNumber; public Map sdFields=null; /** @@ -128,6 +121,7 @@ throw new CDKException("Failed to initiate isotope factory: " + exception.getMessage()); } } + this.moleculeNumber = 1; } /** @@ -185,23 +179,10 @@ private void writeSetOfMolecules(SetOfMolecules som) { Molecule[] molecules = som.getMolecules(); - try - { - boolean[] isVisible=new boolean[molecules[0].getAtomCount()]; - for(int i=0;i<isVisible.length;i++){ - isVisible[i]=true; - } - writeMolecule(molecules[0], isVisible); - } - catch (Exception exc) - { - } - for (int i = 1; i <= som.getMoleculeCount() - 1; i++) + for (int i = 0; i < som.getMoleculeCount(); i++) { try { - writer.write("$$$$"); - writer.newLine(); boolean[] isVisible=new boolean[molecules[i].getAtomCount()]; for(int k=0;k<isVisible.length;k++){ isVisible[k]=true; @@ -240,7 +221,12 @@ public void writeMolecule(Molecule molecule, boolean[] isVisible) throws Exception { int Bonorder, stereo; String line = ""; - + // taking care of the $$$$ signs: + // we do not write such a sign at the end of the first molecule, thus we have to write on BEFORE the second molecule + if(moleculeNumber == 2) { + writer.write("$$$$"); + writer.newLine(); + } // write header block // lines get shortened to 80 chars, that's in the spec String title = (String)molecule.getProperty(CDKConstants.TITLE); @@ -397,6 +383,13 @@ writer.newLine(); } } + // taking care of the $$$$ signs: + // we write such a sign at the end of all except the first molecule + if(moleculeNumber != 1) { + writer.write("$$$$"); + writer.newLine(); + } + moleculeNumber++; writer.flush(); } |