Skip to content

Commit

Permalink
Fixed bugged when reading MDL V2000 files. If the atom number of a ps…
Browse files Browse the repository at this point in the history
…eudo atom was greater then 9 it would not be read correctly

Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
John May authored and rajarshi committed Oct 2, 2011
1 parent 3ce93a5 commit fd90ed5
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/org/openscience/cdk/io/MDLV2000Reader.java
Expand Up @@ -713,11 +713,11 @@ private IMolecule readMolecule(IMolecule molecule) throws CDKException {
int charge = Integer.parseInt(token.trim());
molecule.getAtom(atomNumber - 1).setFormalCharge(charge);
}
} else if (line.matches("^A \\d+")) {
} else if (line.matches("A\\s{1,4}\\d+")) {
// Reads the pseudo atom property from the mol file

// The atom number of the to replaced atom
int aliasAtomNumber = Integer.parseInt(line.replaceFirst("^A ", "")) - RGroupCounter;
int aliasAtomNumber = Integer.parseInt(line.replaceFirst("A\\s{1,4}", "")) - RGroupCounter;
line = input.readLine(); linecount++;
String[] aliasArray = line.split("\\\\");
// name of the alias atom like R1 odr R2 etc.
Expand Down
121 changes: 121 additions & 0 deletions src/test/data/mdl/brenda_molfile_rgroup.mol
@@ -0,0 +1,121 @@

ACD/Labs06030910512D

56 58 0 0 1 0 0 0 0 0 3 V2000
10.4106 -7.9647 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
9.2793 -7.2805 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
33.6229 -6.7877 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
6.9846 -7.2411 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
5.8211 -7.8858 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
33.6229 -8.9166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
32.3304 -6.4076 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
32.3304 -5.1911 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
33.2427 -10.1331 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
31.8742 -10.1331 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
33.6229 -4.7349 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
34.3832 -5.7233 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
32.5585 -8.1563 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
31.4940 -8.9166 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
31.2659 -4.5068 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
31.2659 -7.0158 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
31.1139 -11.1215 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
30.2775 -5.1151 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
30.3536 -8.5365 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
30.2775 -6.4076 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
29.8213 -7.3200 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
33.9270 -11.1975 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
31.2659 -3.2143 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
29.9734 -11.8058 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
28.8329 -11.1215 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
29.9734 -13.0983 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
29.3652 -10.6653 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
28.6809 -8.0042 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
27.4644 -7.3200 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
28.6809 -9.2968 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
27.9966 -6.8638 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
26.3999 -8.0042 0.0000 P 0 0 0 0 0 0 0 0 0 0 0 0
25.2595 -7.3200 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
26.3999 -9.2968 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
25.7157 -6.8638 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
12.7144 -8.0042 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
13.8548 -7.3200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
14.9953 -8.0042 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
16.1358 -7.3200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
17.2762 -8.0042 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
18.4167 -7.3200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
19.5571 -8.0042 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
20.6976 -7.3200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
21.8381 -8.0042 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
22.9025 -7.3200 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
24.0430 -8.0042 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
23.5868 -6.1795 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
22.5984 -6.0274 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
21.8381 -9.2968 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
20.6976 -6.0274 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
16.1358 -6.0274 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
11.5739 -7.3200 0.0000 S 0 0 0 0 0 0 0 0 0 0 0 0
8.1250 -7.9254 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10.3879 -9.2846 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
8.1023 -9.2453 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
4.6812 -7.2007 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6 3 1 1 0 0 0
7 3 1 0 0 0 0
12 3 1 0 0 0 0
9 6 1 0 0 0 0
13 6 1 0 0 0 0
8 7 2 0 0 0 0
16 7 1 0 0 0 0
15 8 1 0 0 0 0
11 8 1 0 0 0 0
10 9 1 0 0 0 0
9 22 1 6 0 0 0
10 17 1 6 0 0 0
14 10 1 0 0 0 0
12 11 2 0 0 0 0
14 13 1 0 0 0 0
14 19 1 1 0 0 0
23 15 1 0 0 0 0
18 15 2 0 0 0 0
20 16 2 0 0 0 0
24 17 1 0 0 0 0
20 18 1 0 0 0 0
21 19 1 0 0 0 0
28 21 1 0 0 0 0
25 24 1 0 0 0 0
26 24 2 0 0 0 0
27 24 1 0 0 0 0
29 28 1 0 0 0 0
30 28 2 0 0 0 0
31 28 1 0 0 0 0
32 29 1 0 0 0 0
33 32 1 0 0 0 0
34 32 2 0 0 0 0
35 32 1 0 0 0 0
46 33 1 0 0 0 0
37 36 1 0 0 0 0
52 36 1 0 0 0 0
38 37 1 0 0 0 0
39 38 1 0 0 0 0
40 39 1 0 0 0 0
51 39 2 0 0 0 0
41 40 1 0 0 0 0
42 41 1 0 0 0 0
43 42 1 0 0 0 0
44 43 1 0 0 0 0
50 43 2 0 0 0 0
45 44 1 0 0 0 0
49 44 1 0 0 0 0
46 45 1 0 0 0 0
47 45 1 0 0 0 0
48 45 1 0 0 0 0
2 1 1 0 0 0 0
54 1 2 0 0 0 0
53 2 1 0 0 0 0
4 53 1 0 0 0 0
53 55 1 6 0 0 0
5 4 1 0 0 0 0
52 1 1 0 0 0 0
5 56 1 0 0 0 0
A 56
R
M END
10 changes: 10 additions & 0 deletions src/test/org/openscience/cdk/io/MDLV2000ReaderTest.java
Expand Up @@ -877,4 +877,14 @@ public void testDeuterium() throws Exception {
Assert.assertEquals(1, tritiumCount);
}

/**
* Test that R-groups at higher atom numbers (>9) are read correctly
*/
@Test public void testRGroupHighAtomNumber() throws Exception {
InputStream in = ClassLoader.getSystemResourceAsStream("data/mdl/brenda_molfile_rgroup.mol");
MDLV2000Reader reader = new MDLV2000Reader(in);
IMolecule molecule = DefaultChemObjectBuilder.getInstance().newInstance(IMolecule.class);
reader.read(molecule);
Assert.assertEquals("R", molecule.getAtom(55).getSymbol() );
}
}

0 comments on commit fd90ed5

Please sign in to comment.