Skip to content

Commit 57679c9

Browse files
committed
bug fix if we read mol file containing a M ALS line with an AtomContainer
1 parent 03c7f3a commit 57679c9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,17 +520,26 @@ private IAtomContainer readAtomContainer(IAtomContainer molecule) throws CDKExce
520520
}
521521
}
522522

523-
// sanity check that we have a decent molecule, query bonds mean we
523+
// sanity check that we have a decent molecule, query bonds or query atoms mean we
524524
// don't have a hydrogen count for atoms and stereo perception isn't
525525
// currently possible
526526
if (!(outputContainer instanceof IQueryAtomContainer) && !isQuery &&
527527
addStereoElements.isSet() && hasX && hasY) {
528-
if (hasZ) { // has 3D coordinates
529-
outputContainer.setStereoElements(StereoElementFactory.using3DCoordinates(outputContainer)
530-
.createAll());
531-
} else if (!forceReadAs3DCoords.isSet()) { // has 2D coordinates (set as 2D coordinates)
532-
outputContainer.setStereoElements(StereoElementFactory.using2DCoordinates(outputContainer)
533-
.createAll());
528+
//ALS property could have changed an atom into a QueryAtom
529+
for(IAtom atom : outputContainer.atoms()){
530+
if (AtomRef.deref(atom) instanceof QueryAtom) {
531+
isQuery=true;
532+
break;
533+
}
534+
}
535+
if(!isQuery) {
536+
if (hasZ) { // has 3D coordinates
537+
outputContainer.setStereoElements(StereoElementFactory.using3DCoordinates(outputContainer)
538+
.createAll());
539+
} else if (!forceReadAs3DCoords.isSet()) { // has 2D coordinates (set as 2D coordinates)
540+
outputContainer.setStereoElements(StereoElementFactory.using2DCoordinates(outputContainer)
541+
.createAll());
542+
}
534543
}
535544
}
536545

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,4 +1886,14 @@ public void checkFuseBondWithFewerBondsThanAtoms() throws IOException, CDKExcept
18861886
assertThat(mol.getAtomCount(), is(108));
18871887
}
18881888
}
1889+
@Test
1890+
public void atomlistWithAtomContainer() throws Exception {
1891+
try (InputStream in = getClass().getResourceAsStream("query_notatomlist.mol");
1892+
MDLV2000Reader mdlr = new MDLV2000Reader(in)) {
1893+
1894+
IAtomContainer mol = mdlr.read(SilentChemObjectBuilder.getInstance().newAtomContainer());
1895+
IAtom deref = AtomRef.deref(mol.getAtom(0));
1896+
assertThat(deref, CoreMatchers.<IAtom>instanceOf(QueryAtom.class));
1897+
}
1898+
}
18891899
}

0 commit comments

Comments
 (0)