Skip to content

Commit

Permalink
Merge pull request #300 from cdk/patch/wedgebondpriority
Browse files Browse the repository at this point in the history
Slight tweak to assign wedge bonds.
  • Loading branch information
egonw committed Apr 20, 2017
2 parents 385c145 + c0db57f commit c05eac4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Expand Up @@ -36,7 +36,6 @@
import org.openscience.cdk.ringsearch.RingSearch;
import org.openscience.cdk.stereo.ExtendedTetrahedral;
import org.openscience.cdk.tools.LoggingToolFactory;
import uk.ac.ebi.beam.Bond;

import javax.vecmath.Point2d;
import java.util.ArrayList;
Expand Down Expand Up @@ -338,7 +337,8 @@ private void label(final ITetrahedralChirality element) {
}

// set the label for the highest priority and available bond
IBond.Stereo firstlabel = null;
IBond.Stereo firstlabel = null;
boolean assignTwoLabels = assignTwoLabels(bonds, labels);
for (int v : priority(atomToIndex.get(focus), atoms, n)) {
IBond bond = bonds[v];
if (bond.getStereo() != NONE || bond.getOrder() != SINGLE)
Expand All @@ -349,7 +349,7 @@ private void label(final ITetrahedralChirality element) {
bond.setStereo(labels[v]);
firstlabel = labels[v];
// don't assign a second label when there are only three ligands
if (labels.length == 3)
if (!assignTwoLabels)
break;
}
// second label
Expand All @@ -365,6 +365,19 @@ else if (labels[v] != firstlabel) {
throw new IllegalArgumentException("could not assign non-planar (up/down) labels");
}

private boolean assignTwoLabels(IBond[] bonds, IBond.Stereo[] labels) {
return labels.length == 4 && countRingBonds(bonds) != 3;
}

private int countRingBonds(IBond[] bonds) {
int rbonds = 0;
for (IBond bond : bonds) {
if (bond != null && bond.isInRing())
rbonds++;
}
return rbonds;
}

/**
* Obtain the parity of a value x. The parity is -1 if the value is odd or
* +1 if the value is even.
Expand Down
Expand Up @@ -33,6 +33,8 @@
import org.openscience.cdk.interfaces.ITetrahedralChirality;
import org.openscience.cdk.silent.Atom;
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.stereo.DoubleBondStereochemistry;
import org.openscience.cdk.stereo.ExtendedTetrahedral;
import org.openscience.cdk.stereo.TetrahedralChirality;
Expand Down Expand Up @@ -595,6 +597,22 @@ public void unspecifiedMarkedOnDifferentLigands() {
assertThat(wavyCount, is(1));
}

/**
* {@code SMILES: O=C4C=C2[C@]([C@@]1([H])CC[C@@]3([C@@]([H])(O)CC[C@@]3([H])[C@]1([H])CC2)C)(C)CC4}
*/
@Test
public void testosterone() throws CDKException {
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = smipar.parseSmiles("O=C4C=C2[C@]([C@@]1([H])CC[C@@]3([C@@]([H])(O)CC[C@@]3([H])[C@]1([H])CC2)C)(C)CC4");
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.generateCoordinates(mol);
int wedgeCount = 0;
for (IBond bond : mol.bonds())
if (bond.getStereo() == IBond.Stereo.UP || bond.getStereo() == IBond.Stereo.DOWN)
wedgeCount++;
assertThat(wedgeCount, is(7));
}

static IAtom atom(String symbol, int hCount, double x, double y) {
IAtom a = new Atom(symbol);
a.setImplicitHydrogenCount(hCount);
Expand Down

0 comments on commit c05eac4

Please sign in to comment.