Skip to content

Commit

Permalink
Avoid erroneous aromaticity due to abnormal valence.
Browse files Browse the repository at this point in the history
Change-Id: I4abbb2e203c07c2dbec27dfb0090d20e06e49a64
Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information
johnmay authored and egonw committed Feb 8, 2014
1 parent 1a3f3d3 commit d4255b3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/main/org/openscience/cdk/aromaticity/DaylightModel.java
Expand Up @@ -169,10 +169,13 @@ else if (nCyclicPiBonds[i] == 1) {
}

// a anion with a lone pair contributes 2 electrons - simplification
// here is we count the number free valence electrons
// here is we count the number free valence electrons but also
// check if the bonded valence is okay (i.e. not a radical)
else if (charge <= 0 && charge > -3) {
int v = valence(element, charge);
if (v - bondOrderSum[i] >= 2)
int bondedValence = bondOrderSum[i] + container.getAtom(i).getImplicitHydrogenCount();
if (!normal(element, charge, bondedValence))
electrons[i] = -1;
else if (valence(element, charge) - bondOrderSum[i] >= 2)
electrons[i] = 2;
else
electrons[i] = -1;
Expand Down Expand Up @@ -257,6 +260,39 @@ private static boolean aromaticElement(int element) {
return false;
}

/**
* The element (with only sigma bonds) has normal valence for the specified
* charge.
*
* @param element atomic number
* @param charge formal charge
* @param valence bonded electrons
* @return acceptable for this model
*/
private static boolean normal(int element, int charge, int valence) {
switch (element) {
case CARBON:
if (charge == -1 || charge == +1)
return valence == 3;
return charge == 0 && valence == 4;
case NITROGEN:
case PHOSPHORUS:
case ARSENIC:
if (charge == -1)
return valence == 2;
if (charge == +1)
return valence == 4;
return charge == 0 && valence == 3;
case OXYGEN:
case SULPHUR:
case SELENIUM:
if (charge == +1)
return valence == 3;
return charge == 0 && valence == 2;
}
return false;
}

/**
* Lookup of the number of valence electrons for the element at a given
* charge.
Expand Down
15 changes: 15 additions & 0 deletions src/test/org/openscience/cdk/aromaticity/DaylightModelTest.java
Expand Up @@ -181,6 +181,21 @@ public class DaylightModelTest {
-1, 0, 1, 1, 2, 1, 1);
}

@Test public void abnormalValence_carbon() throws Exception {
test(smiles("[C]1[C][C][C][C]1"),
-1, -1, -1, -1, -1);
}

@Test public void abnormalValence_nitrogen() throws Exception {
test(smiles("[N]1[N][N][N][N]1"),
-1, -1, -1, -1, -1);
}

@Test public void abnormalValence_phosphorus() throws Exception {
test(smiles("[P]1[P][P][P][P]1"),
-1, -1, -1, -1, -1);
}

static IAtomContainer addHydrogens(IAtomContainer container) throws CDKException {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(container);
CDKHydrogenAdder.getInstance(container.getBuilder()).addImplicitHydrogens(container);
Expand Down

0 comments on commit d4255b3

Please sign in to comment.