Skip to content

Commit fdce829

Browse files
committed
Keep atomic number of alias elements in molfile.
1 parent 4254340 commit fdce829

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
MAYFIELD12221314372D
3+
4+
7 7 0 0 0 0 999 V2000
5+
7.8089 -1.3194 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
6+
7.0944 -1.7319 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
7+
7.0944 -2.5569 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
8+
7.8089 -2.9694 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
9+
8.5233 -2.5569 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
10+
8.5233 -1.7319 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
11+
7.8089 -0.4944 0.0000 N 0 0 0 0 0 0 0 0 0 0 0 0
12+
1 2 1 0 0 0 0
13+
2 3 2 0 0 0 0
14+
3 4 1 0 0 0 0
15+
4 5 2 0 0 0 0
16+
5 6 1 0 0 0 0
17+
1 6 2 0 0 0 0
18+
1 7 1 0 0 0 0
19+
A 7
20+
N1
21+
M END

storage/ctab/src/main/java/org/openscience/cdk/io/MDLV2000Reader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ static void label(final IAtomContainer container, final int index, final String
15851585
pseudoAtom.setLabel(label);
15861586
} else {
15871587
pseudoAtom.setSymbol(label);
1588-
pseudoAtom.setAtomicNumber(0);
1588+
pseudoAtom.setAtomicNumber(atom.getAtomicNumber());
15891589
pseudoAtom.setPoint2d(atom.getPoint2d());
15901590
pseudoAtom.setPoint3d(atom.getPoint3d());
15911591
pseudoAtom.setMassNumber(atom.getMassNumber());
@@ -1922,6 +1922,7 @@ private void readPropertiesSlow(BufferedReader input, IAtomContainer container,
19221922
}
19231923

19241924
IAtom newPseudoAtom = container.getBuilder().newInstance(IPseudoAtom.class, alias);
1925+
newPseudoAtom.setAtomicNumber(aliasAtom.getAtomicNumber());
19251926
if (aliasAtom.getPoint2d() != null) newPseudoAtom.setPoint2d(aliasAtom.getPoint2d());
19261927
if (aliasAtom.getPoint3d() != null) newPseudoAtom.setPoint3d(aliasAtom.getPoint3d());
19271928
AtomContainerManipulator.replaceAtomByAtom(container, aliasAtom, newPseudoAtom);

storage/ctab/src/test/java/org/openscience/cdk/io/MDLV2000ReaderTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ public void testRGroupHighAtomNumber() throws Exception {
10121012
IAtomContainer molecule = DefaultChemObjectBuilder.getInstance().newInstance(IAtomContainer.class);
10131013
reader.read(molecule);
10141014
reader.close();
1015-
Assert.assertEquals("R", molecule.getAtom(55).getSymbol());
1015+
IAtom atom = molecule.getAtom(55);
1016+
Assert.assertThat(atom, CoreMatchers.<IAtom>instanceOf(IPseudoAtom.class));
1017+
Assert.assertEquals("R", ((IPseudoAtom)atom).getLabel());
10161018
}
10171019

10181020
@Test
@@ -1370,6 +1372,17 @@ public void testAliasAfterRgroup() throws Exception {
13701372
assertThat(((IPseudoAtom) container.getAtom(7)).getLabel(), is("Protein"));
13711373
}
13721374

1375+
@Test
1376+
public void keepAtomicNumberOfAlias() throws Exception {
1377+
InputStream in = getClass().getResourceAsStream("/data/mdl/element-with-alias.mol");
1378+
MDLV2000Reader reader = new MDLV2000Reader(in);
1379+
IAtomContainer container = reader.read(new AtomContainer());
1380+
reader.close();
1381+
assertThat(container.getAtom(6), is(instanceOf(IPseudoAtom.class)));
1382+
assertThat(((IPseudoAtom) container.getAtom(6)).getLabel(), is("N1"));
1383+
assertThat(((IPseudoAtom) container.getAtom(6)).getAtomicNumber(), is(7));
1384+
}
1385+
13731386
@Test
13741387
public void v2000Version() throws Exception {
13751388
assertThat(MDLV2000Reader.CTabVersion.ofHeader(" 5 5 0 0 0 0 999 V2000"),

0 commit comments

Comments
 (0)