Skip to content

Commit

Permalink
Additional guard against trying to write molecules in an inconsistent…
Browse files Browse the repository at this point in the history
… state.
  • Loading branch information
johnmay committed Nov 9, 2016
1 parent b5ff6c4 commit 974b385
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,11 @@ static Edge toBeamEdge(IBond b, int flavour, Map<IAtom, Integer> 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?");

Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand Down

0 comments on commit 974b385

Please sign in to comment.