Skip to content

Commit

Permalink
MDL reading and writing and stereo bond types
Browse files Browse the repository at this point in the history
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
mark_rynbeek authored and egonw committed Jan 29, 2010
1 parent da488c0 commit e335bbc
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/org/openscience/cdk/io/MDLWriter.java
Expand Up @@ -307,7 +307,13 @@ public void writeMolecule(IAtomContainer container) throws Exception {
case DOWN_INVERTED:
line += "6";
break;
default:
case UP_OR_DOWN:
line += "4";
break;
case E_OR_Z:
line += "3";
break;
default:
line += "0";
}
line += " 0 0 0 ";
Expand Down
84 changes: 84 additions & 0 deletions src/test/data/mdl/ChEBI_26120.mol
@@ -0,0 +1,84 @@

Marvin 03060821252D

40 39 0 0 0 0 999 V2000
4.6441 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.3585 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.9296 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
4.6441 -1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6.0730 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
3.2151 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6.7875 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
2.5006 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
7.5019 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7862 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
8.2164 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
7.5019 -1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.0717 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1.7862 -1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
8.9309 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
0.3572 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
9.6454 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.3572 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.3598 -0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.0717 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11.0743 0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.3598 -1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7862 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.5006 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7862 1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.2151 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-3.9296 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-4.6441 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-5.3585 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-4.6441 1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-6.0730 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-6.7875 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-7.5019 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-8.2164 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-7.5019 1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-8.9309 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-9.6454 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-10.3598 0.2062 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-11.0743 -0.2063 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
-10.3598 1.0312 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0 0 0 0
1 3 2 3 0 0 0
1 4 1 0 0 0 0
2 5 1 0 0 0 0
3 6 1 0 0 0 0
5 7 1 0 0 0 0
6 8 2 3 0 0 0
7 9 2 3 0 0 0
8 10 1 0 0 0 0
9 11 1 0 0 0 0
9 12 1 0 0 0 0
10 13 2 3 0 0 0
10 14 1 0 0 0 0
11 15 1 0 0 0 0
13 16 1 0 0 0 0
15 17 1 0 0 0 0
16 18 2 3 0 0 0
17 19 2 0 0 0 0
18 20 1 0 0 0 0
19 21 1 0 0 0 0
19 22 1 0 0 0 0
20 23 2 3 0 0 0
23 24 1 0 0 0 0
23 25 1 0 0 0 0
24 26 1 0 0 0 0
26 27 1 0 0 0 0
27 28 2 3 0 0 0
28 29 1 0 0 0 0
28 30 1 0 0 0 0
29 31 1 0 0 0 0
31 32 1 0 0 0 0
32 33 2 3 0 0 0
33 34 1 0 0 0 0
33 35 1 0 0 0 0
34 36 1 0 0 0 0
36 37 1 0 0 0 0
37 38 2 0 0 0 0
38 39 1 0 0 0 0
38 40 1 0 0 0 0
M END
11 changes: 11 additions & 0 deletions src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
Expand Up @@ -566,6 +566,17 @@ public class MDLV2000ReaderTest extends SimpleChemObjectReaderTest {
Assert.assertNull(atom.getPoint2d());
}
}

@Test public void testUndefinedStereo() throws Exception {
String filename = "data/mdl/ChEBI_26120.mol";
logger.info("Testing: " + filename);
InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename);
MDLV2000Reader reader = new MDLV2000Reader(ins, Mode.STRICT);
IMolecule mol = (IMolecule)reader.read(new NNMolecule());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(1).getStereo());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(6).getStereo());
Assert.assertEquals(IBond.Stereo.E_OR_Z,mol.getBond(7).getStereo());
}

/**
* Tests that the '0' read from the bond block for bond stereo
Expand Down
15 changes: 15 additions & 0 deletions src/test/org/openscience/cdk/io/MDLWriterTest.java
Expand Up @@ -45,6 +45,7 @@
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IMolecule;
import org.openscience.cdk.io.listener.PropertiesListener;
import org.openscience.cdk.templates.MoleculeFactory;

/**
* TestCase for the writer MDL mol files using one test file.
Expand Down Expand Up @@ -188,4 +189,18 @@ public class MDLWriterTest extends ChemObjectIOTest {
Assert.assertTrue(output.contains("1.0"));
Assert.assertTrue(output.contains("2.0"));
}

@Test public void testUndefinedStereo() throws Exception {
IMolecule mol = MoleculeFactory.makeAlphaPinene();
mol.getBond(0).setStereo(IBond.Stereo.UP_OR_DOWN);
mol.getBond(1).setStereo(IBond.Stereo.E_OR_Z);
StringWriter writer = new StringWriter();
MDLWriter mdlWriter = new MDLWriter(writer);
mdlWriter.write(mol);
String output = writer.toString();
Assert.assertTrue(output.indexOf("1 2 2 4 0 0 0")>-1);
Assert.assertTrue(output.indexOf("2 3 1 3 0 0 0")>-1);
}


}

0 comments on commit e335bbc

Please sign in to comment.