Skip to content

Commit

Permalink
Updated HIN reader to fix bug 2984581
Browse files Browse the repository at this point in the history
  • Loading branch information
rajarshi committed Apr 10, 2010
1 parent 38d5f8d commit f95c632
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 18 deletions.
35 changes: 21 additions & 14 deletions src/main/org/openscience/cdk/io/HINReader.java
Expand Up @@ -20,18 +20,6 @@
*/
package org.openscience.cdk.io;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

import javax.vecmath.Point3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand All @@ -48,6 +36,17 @@
import org.openscience.cdk.io.formats.HINFormat;
import org.openscience.cdk.io.formats.IResourceFormat;

import javax.vecmath.Point3d;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;

/**
* Reads an object from HIN formated input.
*
Expand Down Expand Up @@ -197,7 +196,7 @@ private IChemFile readChemFile(IChemFile file) {
// read data for current molecule
int atomSerial = 0;
while (true) {
if (line.indexOf("endmol ") >= 0) {
if (line == null || line.indexOf("endmol ") >= 0) {
break;
}
if (line.indexOf(';') == 0) continue; // comment line
Expand Down Expand Up @@ -257,7 +256,15 @@ private IChemFile readChemFile(IChemFile file) {
m.addBond(file.getBuilder().newBond(s, e, bo));
}
setOfMolecules.addMolecule(m);
line = input.readLine(); // read in the 'mol N'

// we may not get a 'mol N' immediately since
// the aromaticring keyword might be present
// and doesn't seem to be located within the molecule
// block
while (true) {
line = input.readLine();
if (line == null || line.indexOf("mol ") == 0) break;
}
}

// got all the molecule in the HIN file (hopefully!)
Expand Down
31 changes: 31 additions & 0 deletions src/test/data/hin/bug2984581.hin
@@ -0,0 +1,31 @@
forcefield mm+
sys 0 0 1
view 40 0.1471 55 15 0.5586844 -0.7573253 0.3381274 0.8112321 0.583803 -0.03280994 -0.172552 0.2926302 0.9405283 -1.5498 -0.69331 -55.277
seed 0
mol 1
atom 1 - C CA - -0.1921654 0.5444375 -0.480369 0.1121711 3 3 a 2 a 14 s
atom 2 - C CA - -0.07865381 1.48883 -1.507176 0.1121711 3 5 a 1 a 15 s
atom 3 - C CA - 0.1260283 0.9869497 0.8709679 0.1121711 3 1 a 4 a 7 s
atom 4 - C CA - -0.1945596 2.357387 1.141245 0.1121711 3 3 a 6 a 20 s
atom 5 - C CA - -0.1604924 2.854465 -1.227169 0.1121711 3 2 a 6 a 21 s
atom 6 - C CA - -0.08668089 3.281385 0.09564244 0.1121711 3 5 a 4 a 16 s
atom 7 - O O2 - -0.1584311 -0.06161446 1.767233 0.1121711 2 3 s 8 s
atom 8 - C CA - 0.09127665 -0.009773561 3.152164 0.1121711 3 13 a 7 s 9 a
atom 9 - C CA - -0.1865864 1.073688 4.026796 0.1121711 3 10 a 22 s 8 a
atom 10 - C CA - -0.1031656 0.8394372 5.407645 0.1121711 3 9 a 11 a 17 s
atom 11 - C CA - -0.153739 -0.452265 5.91707 0.1121711 3 10 a 12 a 18 s
atom 12 - C CA - -0.1025772 -1.539669 5.037201 0.1121711 3 11 a 13 a 19 s
atom 13 - C CA - -0.1454592 -1.331929 3.667263 0.1121711 3 12 a 8 a 23 s
atom 14 - Br BR - 0.07038784 -1.265702 -0.9827618 0.1121711 1 1 s
atom 15 - H H - 0.149111 1.15467 -2.557919 0.1121711 1 2 s
atom 16 - H H - 0.1373875 4.357067 0.3297046 0.1121711 1 6 s
atom 17 - H H - 0.1337775 1.701587 6.091895 0.1121711 1 10 s
atom 18 - H H - 0.1358719 -0.6226702 7.002957 0.1121711 1 11 s
atom 19 - H H - 0.1372966 -2.566783 5.432249 0.1121711 1 12 s
atom 20 - H H - 0.145665 2.75555 2.159567 0.1121711 1 4 s
atom 21 - H H - 0.1408581 3.583701 -2.04989 0.1121711 1 5 s
atom 22 - H H - 0.1395921 2.117928 3.702678 0.1121711 1 9 s
atom 23 - H H - 0.1552575 -2.176271 2.961693 0.1121711 1 13 s
endmol 1
aromaticring 6 1 1 1 3 1 4 1 6 1 5 1 2
aromaticring 6 1 8 1 13 1 12 1 11 1 10 1 9
21 changes: 17 additions & 4 deletions src/test/org/openscience/cdk/io/HINReaderTest.java
Expand Up @@ -27,20 +27,19 @@
* */
package org.openscience.cdk.io;

import java.io.InputStream;
import java.util.List;

import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemObject;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IChemFile;
import org.openscience.cdk.tools.LoggingTool;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

import java.io.InputStream;
import java.util.List;

/**
* TestCase for the reading HIN mol files using one test file.
*
Expand Down Expand Up @@ -139,4 +138,18 @@ public class HINReaderTest extends SimpleChemObjectReaderTest {
Assert.assertEquals(57, ac.getAtomCount());
Assert.assertEquals(59, ac.getBondCount());
}

/**
* @cdk.bug 2984581
* @throws Exception
*/
@Test public void testAromaticRingsLine() throws Exception {
String filename = "data/hin/bug2984581.hin";
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
ISimpleChemObjectReader reader = new HINReader(ins);
IChemFile content = (IChemFile) reader.read(new ChemFile());
List<IAtomContainer> cList = ChemFileManipulator.getAllAtomContainers(content);
Assert.assertEquals(1, cList.size());
IAtomContainer ac = cList.get(0);
}
}

0 comments on commit f95c632

Please sign in to comment.