Skip to content

Commit

Permalink
Some restructuring requiring to resolve failing unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed May 9, 2018
1 parent a58bdd5 commit 99e888a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import javax.vecmath.Vector2d;
import javax.vecmath.Vector3d;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
Expand Down Expand Up @@ -241,7 +240,8 @@ public List<IStereoElement> createAll() {
if (element != null) elements.add(element);
} else {
// extended cis-trans
IStereoElement element = createExtendedCisTrans(dbs);
IStereoElement element = createExtendedCisTrans(dbs,
centers);
if (element != null) elements.add(element);
}
break;
Expand Down Expand Up @@ -441,9 +441,11 @@ public List<IStereoElement> createAll() {
* </pre>
*
* @param bonds cumulated double bonds
* @param centers discovered stereocentres
* @return the extended cis/trans geometry if one could be created
*/
abstract ExtendedCisTrans createExtendedCisTrans(List<IBond> bonds);
abstract ExtendedCisTrans createExtendedCisTrans(List<IBond> bonds,
Stereocenters centers);

/**
* Indicate that stereochemistry drawn as a certain projection should be
Expand Down Expand Up @@ -775,6 +777,11 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
int t0 = container.indexOf(terminals[0]);
int t1 = container.indexOf(terminals[1]);

if (stereocenters.isSymmetryChecked() &&
(!stereocenters.isStereocenter(t0) ||
!stereocenters.isStereocenter(t1)))
return null;

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

Expand Down Expand Up @@ -817,8 +824,7 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
return new ExtendedTetrahedral(focus, neighbors, winding);
}

@Override
ExtendedCisTrans createExtendedCisTrans(List<IBond> dbs) {
ExtendedCisTrans createExtendedCisTrans(List<IBond> dbs, Stereocenters stereocenters) {

// only applies to odd-counts
if ((dbs.size() & 0x1) == 0)
Expand All @@ -834,6 +840,11 @@ ExtendedCisTrans createExtendedCisTrans(List<IBond> dbs) {
List<IBond> begBonds = container.getConnectedBondsList(begAtom);
List<IBond> endBonds = container.getConnectedBondsList(endAtom);

if (stereocenters.isSymmetryChecked() &&
(!stereocenters.isStereocenter(container.indexOf(begAtom)) ||
!stereocenters.isStereocenter(container.indexOf(endAtom))))
return null;

if (begBonds.size() < 2 || endBonds.size() < 2)
return null;

Expand Down Expand Up @@ -1235,7 +1246,8 @@ ExtendedTetrahedral createExtendedTetrahedral(int v, Stereocenters stereocenters
}

@Override
ExtendedCisTrans createExtendedCisTrans(List<IBond> dbs) {
ExtendedCisTrans createExtendedCisTrans(List<IBond> dbs,
Stereocenters centers) {

// only applies to odd-counts
if ((dbs.size() & 0x1) == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ public Type elementType(final int v) {
return elements[v].type;
}

boolean isSymmetryChecked() {
return checkSymmetry;
}

/**
* Is the atom be a stereocenter (i.e. True or Para).
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import com.google.common.collect.Iterables;
import org.junit.Test;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
Expand Down Expand Up @@ -224,7 +225,7 @@ public void e_hexa234triene() {
dbs.add(mol.getBond(0));
dbs.add(mol.getBond(1));
dbs.add(mol.getBond(2));
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs);
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs, Stereocenters.of(mol));
assertNotNull(element);
assertThat(element.getConfigOrder(), is(IStereoElement.OPPOSITE));
}
Expand Down Expand Up @@ -252,7 +253,7 @@ public void z_hexa234triene() {
dbs.add(mol.getBond(0));
dbs.add(mol.getBond(1));
dbs.add(mol.getBond(2));
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs);
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs, Stereocenters.of(mol));
assertNotNull(element);
assertThat(element.getConfigOrder(), is(IStereoElement.TOGETHER));
}
Expand Down Expand Up @@ -280,7 +281,7 @@ public void e_hexa234triene_3D() {
dbs.add(mol.getBond(0));
dbs.add(mol.getBond(1));
dbs.add(mol.getBond(2));
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs);
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs, Stereocenters.of(mol));
assertNotNull(element);
assertThat(element.getConfigOrder(), is(IStereoElement.OPPOSITE));
}
Expand Down Expand Up @@ -308,7 +309,7 @@ public void z_hexa234triene_3D() {
dbs.add(mol.getBond(0));
dbs.add(mol.getBond(1));
dbs.add(mol.getBond(2));
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs);
ExtendedCisTrans element = factory.createExtendedCisTrans(dbs, Stereocenters.of(mol));
assertNotNull(element);
assertThat(element.getConfigOrder(), is(IStereoElement.TOGETHER));
}
Expand Down

0 comments on commit 99e888a

Please sign in to comment.