diff --git a/storage/smiles/src/main/java/org/openscience/cdk/smiles/CDKToBeam.java b/storage/smiles/src/main/java/org/openscience/cdk/smiles/CDKToBeam.java index 0fd8fd7f70..b419d94e5a 100644 --- a/storage/smiles/src/main/java/org/openscience/cdk/smiles/CDKToBeam.java +++ b/storage/smiles/src/main/java/org/openscience/cdk/smiles/CDKToBeam.java @@ -248,7 +248,11 @@ static Edge toBeamEdge(IBond b, int flavour, Map indices) throws */ private static Bond toBeamEdgeLabel(IBond b, int flavour) throws CDKException { - if (SmiFlavor.isSet(flavour, SmiFlavor.UseAromaticSymbols) && b.getFlag(CDKConstants.ISAROMATIC)) return Bond.AROMATIC; + if (SmiFlavor.isSet(flavour, SmiFlavor.UseAromaticSymbols) && b.isAromatic()) { + if (!b.getAtom(0).isAromatic() || !b.getAtom(1).isAromatic()) + throw new IllegalStateException("Aromatic bond connects non-aromatic atomic atoms"); + return Bond.AROMATIC; + } if (b.getOrder() == null) throw new CDKException("A bond had undefined order, possible query bond?"); @@ -264,7 +268,7 @@ private static Bond toBeamEdgeLabel(IBond b, int flavour) throws CDKException { case QUADRUPLE: return Bond.QUADRUPLE; default: - if (!SmiFlavor.isSet(flavour, SmiFlavor.UseAromaticSymbols) && b.getFlag(CDKConstants.ISAROMATIC)) + if (!SmiFlavor.isSet(flavour, SmiFlavor.UseAromaticSymbols) && b.isAromatic()) throw new CDKException("Cannot write Kekulé SMILES output due to aromatic bond with unset bond order - molecule should be Kekulized"); throw new CDKException("Unsupported bond order: " + order); } diff --git a/storage/smiles/src/test/java/org/openscience/cdk/smiles/SmilesGeneratorTest.java b/storage/smiles/src/test/java/org/openscience/cdk/smiles/SmilesGeneratorTest.java index 29139b040d..d0046c95a6 100644 --- a/storage/smiles/src/test/java/org/openscience/cdk/smiles/SmilesGeneratorTest.java +++ b/storage/smiles/src/test/java/org/openscience/cdk/smiles/SmilesGeneratorTest.java @@ -1228,6 +1228,16 @@ public void assignDbStereo() throws Exception { assertThat(smigen.create(r2), is(smigen.create(r3))); } + @Test(expected = IllegalStateException.class) + public void inconsistentAromaticState() throws Exception { + SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance()); + IAtomContainer mol = smipar.parseSmiles("c1ccccc1"); + for (IAtom atom : mol.atoms()) + atom.setIsAromatic(false); + SmilesGenerator smigen = new SmilesGenerator(SmiFlavor.UseAromaticSymbols); + smigen.create(mol); + } + static ITetrahedralChirality anticlockwise(IAtomContainer container, int central, int a1, int a2, int a3, int a4) { return new TetrahedralChirality(container.getAtom(central), new IAtom[]{container.getAtom(a1), container.getAtom(a2), container.getAtom(a3), container.getAtom(a4)},