Skip to content

Commit

Permalink
Further adjustments to accommodate longer extended tetrahedrals
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed May 9, 2018
1 parent b2b9875 commit 675f056
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,21 @@ public List<IStereoElement> createAll() {
if (centers.elementType(w) == Stereocenters.Type.Tricoordinate) {
List<IBond> dbs = getCumulatedDbs(container.getBond(container.getAtom(w),
container.getAtom(v)));
if (dbs.size() == 2) {
if (dbs == null)
continue;
if (container.indexOf(dbs.get(0)) > container.indexOf(dbs.get(dbs.size() - 1)))
continue;
if ((dbs.size() & 0x1) == 0) {
IAtom focus = getShared(dbs.get(dbs.size() / 2),
dbs.get((dbs.size() / 2)-1));
// extended tetrahedral
IStereoElement element = createExtendedTetrahedral(v, centers);
IStereoElement element = createExtendedTetrahedral(container.indexOf(focus),
centers);
if (element != null) elements.add(element);
} else {
if (container.indexOf(dbs.get(0)) < container.indexOf(dbs.get(dbs.size() - 1))) {
// extended cis-trans
IStereoElement element = createExtendedCisTrans(dbs);
if (element != null) elements.add(element);
}
// extended cis-trans
IStereoElement element = createExtendedCisTrans(dbs);
if (element != null) elements.add(element);
}
break;
}
Expand Down Expand Up @@ -770,10 +775,6 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
int t0 = container.indexOf(terminals[0]);
int t1 = container.indexOf(terminals[1]);

// check the focus is cumulated
if (bondMap.get(v, t0).getOrder() != IBond.Order.DOUBLE
|| bondMap.get(v, t1).getOrder() != IBond.Order.DOUBLE) return null;

IAtom[] neighbors = new IAtom[4];
int[] elevation = new int[4];

Expand All @@ -784,23 +785,25 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
for (int w : graph[t0]) {
IBond bond = bondMap.get(t0, w);
if (w == v) continue;
if (bond.getOrder() != IBond.Order.SINGLE) return null;
if (bond.getOrder() != IBond.Order.SINGLE) continue;
if (isUnspecified(bond)) return null;
neighbors[n] = container.getAtom(w);
elevation[n] = elevationOf(terminals[0], bond);
n++;
}
if (n == 0)
return null;
n = 2;
for (int w : graph[t1]) {
IBond bond = bondMap.get(t1, w);
if (w == v) continue;
if (bond.getOrder() != IBond.Order.SINGLE) return null;
if (bond.getOrder() != IBond.Order.SINGLE) continue;
if (isUnspecified(bond)) return null;
neighbors[n] = container.getAtom(w);
elevation[n] = elevationOf(terminals[1], bond);
n++;
}

if (n == 2)
return null;
if (elevation[0] != 0 || elevation[1] != 0) {
if (elevation[2] != 0 || elevation[3] != 0) return null;
} else {
Expand Down Expand Up @@ -1200,10 +1203,6 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
int t0 = container.indexOf(terminals[0]);
int t1 = container.indexOf(terminals[1]);

// check the focus is cumulated
if (bondMap.get(v, t0).getOrder() != IBond.Order.DOUBLE
|| bondMap.get(v, t1).getOrder() != IBond.Order.DOUBLE) return null;

// check for kinked cumulated bond
if (!isColinear(focus, terminals))
return null;
Expand All @@ -1213,14 +1212,20 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters

int n = 0;
for (int w : graph[t0]) {
if (bondMap.get(t0, w).getOrder() != IBond.Order.SINGLE) continue;
if (bondMap.get(t0, w).getOrder() != IBond.Order.SINGLE)
continue;
neighbors[n++] = container.getAtom(w);
}
if (n == 0)
return null;
n = 2;
for (int w : graph[t1]) {
if (bondMap.get(t1, w).getOrder() != IBond.Order.SINGLE) continue;
if (bondMap.get(t1, w).getOrder() != IBond.Order.SINGLE)
continue;
neighbors[n++] = container.getAtom(w);
}
if (n == 2)
return null;

int parity = parity(neighbors);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,35 @@ private void setBondDisplay(IBond bond, IAtom focus, IBond.Stereo display) {
bond.setStereo(flip(display));
}

/**
* Find a bond between two possible atoms. For example beg1 - end or
* beg2 - end.
* @param beg1 begin 1
* @param beg2 begin 2
* @param end end
* @return the bond (or null if none)
*/
private IBond findBond(IAtom beg1, IAtom beg2, IAtom end) {
IBond bond = container.getBond(beg1, end);
if (bond != null)
return bond;
return container.getBond(beg2, end);
}

/**
* Sets a wedge bond, because wedges are relative we may need to flip
* the storage order on the bond.
*
* @param bond the bond
* @param end the expected end atom (fat end of wedge)
* @param style the wedge style
*/
private void setWedge(IBond bond, IAtom end, IBond.Stereo style) {
if (!bond.getEnd().equals(end))
bond.setAtoms(new IAtom[]{bond.getEnd(), bond.getBegin()});
bond.setStereo(style);
}

/**
* Assign non-planar labels (wedge/hatch) to the bonds of extended
* tetrahedral elements to correctly represent its stereochemistry.
Expand All @@ -414,18 +443,17 @@ private void label(final ExtendedTetrahedral element) {

IAtom[] terminals = element.findTerminalAtoms(container);

IAtom left = terminals[0];
IAtom left = terminals[0];
IAtom right = terminals[1];

// some bonds may be null if, this happens when an implicit atom
// is present and one or more 'atoms' is a terminal atom
bonds[0] = container.getBond(left, atoms[0]);
bonds[1] = container.getBond(left, atoms[1]);
bonds[2] = container.getBond(right, atoms[2]);
bonds[3] = container.getBond(right, atoms[3]);
for (int i = 0; i < 4; i++)
bonds[i] = findBond(left, right, atoms[i]);


// find the clockwise ordering (in the plane of the page) by sorting by
// polar corodinates
// polar coordinates
int[] rank = new int[4];
for (int i = 0; i < 4; i++)
rank[i] = i;
Expand Down Expand Up @@ -453,23 +481,15 @@ private void label(final ExtendedTetrahedral element) {
// we now check which side was more favourable and assign two labels
// to that side only
if (priority[0] + priority[1] < priority[2] + priority[3]) {
if (priority[0] < 5) {
bonds[0].setAtoms(new IAtom[]{left, atoms[0]});
bonds[0].setStereo(labels[0]);
}
if (priority[1] < 5) {
bonds[1].setAtoms(new IAtom[]{left, atoms[1]});
bonds[1].setStereo(labels[1]);
}
if (priority[0] < 5)
setWedge(bonds[0], atoms[0], labels[0]);
if (priority[1] < 5)
setWedge(bonds[1], atoms[1], labels[1]);
} else {
if (priority[2] < 5) {
bonds[2].setAtoms(new IAtom[]{right, atoms[2]});
bonds[2].setStereo(labels[2]);
}
if (priority[3] < 5) {
bonds[3].setAtoms(new IAtom[]{right, atoms[3]});
bonds[3].setStereo(labels[3]);
}
if (priority[2] < 5)
setWedge(bonds[2], atoms[2], labels[2]);
if (priority[3] < 5)
setWedge(bonds[3], atoms[3], labels[3]);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,26 @@ public void inconsistentStereoState() throws CDKException {
assertThat(wedgeCount, is(1));
}

@Test public void wedgeExtendedTetrahedral() throws CDKException {
final String smi = "C(=C=C=[C@@]=C=C=CC)C";
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = smipar.parseSmiles(smi);
StructureDiagramGenerator sdg = new StructureDiagramGenerator();
sdg.generateCoordinates(mol);
int wedgeCount = 0;
for (IBond bond : mol.bonds()) {
switch (bond.getStereo()) {
case UP:
case DOWN:
case UP_INVERTED:
case DOWN_INVERTED:
++wedgeCount;
break;
}
}
assertThat(wedgeCount, is(2));
}

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 675f056

Please sign in to comment.