From df81c1deb934379453339965f3564ef5f2671a58 Mon Sep 17 00:00:00 2001 From: John May Date: Wed, 1 Feb 2012 12:04:57 +0000 Subject: [PATCH] Added ability to read atom parity from Mol files (inc. junit test). --- .../openscience/cdk/io/MDLV2000Reader.java | 5 +++++ src/test/data/mdl/mol_testAtomParity.mol | 16 ++++++++++++++ .../cdk/io/MDLV2000ReaderTest.java | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 src/test/data/mdl/mol_testAtomParity.mol diff --git a/src/main/org/openscience/cdk/io/MDLV2000Reader.java b/src/main/org/openscience/cdk/io/MDLV2000Reader.java index 742c28d2964..aca7cc9e723 100644 --- a/src/main/org/openscience/cdk/io/MDLV2000Reader.java +++ b/src/main/org/openscience/cdk/io/MDLV2000Reader.java @@ -524,6 +524,11 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce logger.error("Cannot set mass difference for a non-element!"); } + + // set the stereo partiy + Integer parity = line.length() > 41 ? Character.digit(line.charAt(41), 10) : 0; + atom.setStereoParity(parity); + if (line.length() >= 51) { String valenceString = removeNonDigits(line.substring(48,51)); logger.debug("Valence: ", valenceString); diff --git a/src/test/data/mdl/mol_testAtomParity.mol b/src/test/data/mdl/mol_testAtomParity.mol new file mode 100644 index 00000000000..ddd066de81f --- /dev/null +++ b/src/test/data/mdl/mol_testAtomParity.mol @@ -0,0 +1,16 @@ + + Mrv0541 01311217092D + + 6 5 0 0 0 0 999 V2000 + -1.1749 0.1436 0.0000 C 0 0 1 0 0 0 0 0 0 0 0 0 + -0.7624 0.8581 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + -0.7624 -0.5709 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0 + -1.1749 1.5726 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + 0.0626 0.8581 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0 + -1.9999 0.1436 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0 + 1 2 1 0 0 0 0 + 1 3 1 1 0 0 0 + 2 4 2 0 0 0 0 + 2 5 1 0 0 0 0 + 1 6 1 0 0 0 0 +M END diff --git a/src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java b/src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java index 0dbf0ee32fe..fc398a4c865 100644 --- a/src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java +++ b/src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java @@ -956,4 +956,25 @@ public void testPseudoAtomLabels() throws Exception { Assert.assertEquals("Gln", pa.getLabel()); } + @Test + public void testAtomParity() throws CDKException{ + + InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/mol_testAtomParity.mol"); + MDLV2000Reader reader = new MDLV2000Reader(in); + IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class); + reader.read(molecule); + + boolean chiralCentre = false; + IAtom[] atoms = AtomContainerManipulator.getAtomArray(molecule); + for (IAtom atom : atoms) { + Integer parity = atom.getStereoParity(); + if(parity == 1){ + chiralCentre = true; + } + } + + Assert.assertTrue(chiralCentre); + + } + }