Skip to content

Commit d6cad8b

Browse files
committed
Handle RXN files where the molecules end with $$$$ and not M END.
1 parent bac9397 commit d6cad8b

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,10 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
227227
try {
228228
for (int i = 1; i <= reactantCount; i++) {
229229
StringBuffer molFile = new StringBuffer();
230-
input.readLine(); // announceMDLFileLine
231230
String molFileLine = "";
231+
while (!input.readLine().startsWith("$MOL")) {
232+
// skip
233+
}
232234
do {
233235
molFileLine = input.readLine();
234236
molFile.append(molFileLine);
@@ -256,7 +258,9 @@ private IReaction readReaction(IChemObjectBuilder builder) throws CDKException {
256258
try {
257259
for (int i = 1; i <= productCount; i++) {
258260
StringBuffer molFile = new StringBuffer();
259-
input.readLine(); // String announceMDLFileLine =
261+
while (!input.readLine().startsWith("$MOL")) {
262+
// skip
263+
}
260264
String molFileLine = "";
261265
do {
262266
molFileLine = input.readLine();

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package org.openscience.cdk.io;
2424

2525
import java.io.InputStream;
26+
import java.io.StringReader;
2627
import java.util.Iterator;
2728

2829
import org.junit.Assert;
@@ -32,9 +33,11 @@
3233
import org.openscience.cdk.ChemModel;
3334
import org.openscience.cdk.Reaction;
3435
import org.openscience.cdk.interfaces.IAtomContainer;
36+
import org.openscience.cdk.interfaces.IChemObjectBuilder;
3537
import org.openscience.cdk.interfaces.IMapping;
3638
import org.openscience.cdk.interfaces.IReaction;
3739
import org.openscience.cdk.io.IChemObjectReader.Mode;
40+
import org.openscience.cdk.silent.SilentChemObjectBuilder;
3841
import org.openscience.cdk.tools.ILoggingTool;
3942
import org.openscience.cdk.tools.LoggingToolFactory;
4043

@@ -143,4 +146,36 @@ public void testAgentParts() throws Exception {
143146
assertThat(reaction.getAgents().getAtomContainerCount(), is(1));
144147
}
145148
}
149+
150+
@Test public void optionalSdfSeparator() throws Exception {
151+
String dummyRecord = "ethanol\n" +
152+
" Mrv1810 09251921392D \n" +
153+
"\n" +
154+
" 3 2 0 0 0 0 999 V2000\n" +
155+
" 1.9520 -1.1270 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" +
156+
" 1.2375 -0.7145 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0\n" +
157+
" 2.6664 -0.7145 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0\n" +
158+
" 1 2 1 0 0 0 0\n" +
159+
" 1 3 1 0 0 0 0\n" +
160+
"M END\n" +
161+
"$$$$\n";
162+
StringBuilder sb = new StringBuilder();
163+
sb.append("$RXN\n");
164+
sb.append("Test\n\n\n 2 1\n");
165+
sb.append("$MOL\n");
166+
sb.append(dummyRecord);
167+
sb.append("$MOL\n");
168+
sb.append(dummyRecord);
169+
sb.append("$MOL\n");
170+
sb.append(dummyRecord);
171+
172+
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
173+
try (MDLRXNV2000Reader reader = new MDLRXNV2000Reader(new StringReader(sb.toString()))) {
174+
IReaction rxn = reader.read(bldr.newInstance(IReaction.class));
175+
assertThat(rxn.getReactants().getAtomContainerCount(), is(2));
176+
assertThat(rxn.getProducts().getAtomContainerCount(), is(1));
177+
assertThat(rxn.getReactants().getAtomContainer(0).getAtomCount(), is(3));
178+
assertThat(rxn.getReactants().getAtomContainer(1).getAtomCount(), is(3));
179+
}
180+
}
146181
}

0 commit comments

Comments
 (0)