Permalink
Browse files

geometric parity configuration for 2D/3D tetrahedral stereo centres f…

…or hash code

Signed-off-by: Egon Willighagen <egonw@users.sourceforge.net>
  • Loading branch information...
johnmay authored and egonw committed Feb 11, 2013
1 parent 920ad3e commit 20332b69186dbb552f927451223b990924447a4b
View
@@ -48,6 +48,17 @@
</bibtex:article>
</bibtex:entry>
<bibtex:entry id="Cieplak2001">
<bibtex:article>
<bibtex:author>Cieplak, T and Wisniewski J. L.</bibtex:author>
<bibtex:title>A New Effective Algorithm for the Unambiguous Identification of the Stereochemical Characteristics of Compounds During Their Registration in Databases</bibtex:title>
<bibtex:journal>Molecules</bibtex:journal>
<bibtex:year>2001</bibtex:year>
<bibtex:volume>6</bibtex:volume>
<bibtex:pages>915-926</bibtex:pages>
</bibtex:article>
</bibtex:entry>
<bibtex:entry id="Moreau1980">
<bibtex:article>
<bibtex:author>Moreau G. and Broto P.</bibtex:author>
@@ -0,0 +1 @@
vecmath*.jar
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2013. John May <jwmay@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U
*/
package org.openscience.cdk.hash.stereo.parity;
/**
* Describes the geometric parity of a stereo configuration.
*
* @author John May
* @cdk.module hash
*/
public interface GeometricParity {
/**
* Calculate the geometric parity.
*
* @return -1 odd, +1 even and 0 none
*/
public int parity();
}
@@ -0,0 +1,108 @@
/*
* Copyright (c) 2013. John May <jwmay@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U
*/
package org.openscience.cdk.hash.stereo.parity;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import javax.vecmath.Point2d;
/**
* Geometric parity for 2D tetrahedral geometry. This class requires four 2D
* coordinates and their elevations. The 2D coordinates correspond to the four
* ligands of a tetrahedral atom and the elevation as to whether they are
* attached via a wedge/hatch bonds. Wedge bonds come out of the plane (+ve) and
* hatch bonds go into the plane (-ve), these elevations are specified with a
* (+1) and (-1) respectively. If a tetrahedral atom has an implicit hydrogen
* (only 3 ligands) the forth coordinate should be that of the atom at the
* centre with no elevation {@cdk.cite Cieplak2001}.
*
* @author John May
* @cdk.module hash
* @see <a href="http://www.mdpi.org/molecules/papers/61100915/61100915.htm">Cieplak,
* T and Wisniewski, J.L. 2001</a>
*/
@TestClass("org.openscience.cdk.hash.stereo.parity.Tetrahedral2DParityTest")
public final class Tetrahedral2DParity implements GeometricParity {
/* four coordinates */
private final Point2d[] coordinates;
/* where the coordinates are with respect to the plane (-1,0,+1) */
private final int[] elevations;
/**
* Create a new geometric parity for 2D tetrahedral geometry by specifying
* the coordinates and the elevations.
*
* @param coordinates non-null, 4 2D coordinates
* @param elevations non-null, 4 elevations (-1,0,+1)
* @throws IllegalArgumentException if the number of coordinates/elevations
* was not exactly 4
*/
@TestMethod("testConstruction_InvalidCoords,testConstruction_InvalidElev")
public Tetrahedral2DParity(Point2d[] coordinates, int[] elevations) {
if (coordinates.length != 4 || elevations.length != 4)
throw new IllegalArgumentException("4 coordinates/elevations expected");
this.coordinates = coordinates;
this.elevations = elevations;
}
/**
* @inheritDoc
*/
@TestMethod("testParity_Four_NNND,testParity_Four_NNNU," +
"testParity_Four_NNNN,testParity_Four_UUUN," +
"testParity_Four_DDDN,testParity_Four_UUUU," +
"testParity_Four_DDDD,testParity_Three_UNN," +
"testParity_Three_DNN,testParity_Three_UUU," +
"testParity_Three_DDD")
@Override public int parity() {
double x1 = coordinates[0].x;
double x2 = coordinates[1].x;
double x3 = coordinates[2].x;
double x4 = coordinates[3].x;
double y1 = coordinates[0].y;
double y2 = coordinates[1].y;
double y3 = coordinates[2].y;
double y4 = coordinates[3].y;
double det = (elevations[0] * det(x2, y2, x3, y3, x4, y4)) -
(elevations[1] * det(x1, y1, x3, y3, x4, y4)) +
(elevations[2] * det(x1, y1, x2, y2, x4, y4)) -
(elevations[3] * det(x1, y1, x2, y2, x3, y3));
return (int) Math.signum(det);
}
// 3x3 determinant helper for a constant third column
private static double det(double xa, double ya, double xb, double yb, double xc, double yc) {
return (xa - xc) * (yb - yc) - (ya - yc) * (xb - xc);
}
}
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2013. John May <jwmay@users.sf.net>
*
* Contact: cdk-devel@lists.sourceforge.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2.1
* of the License, or (at your option) any later version.
* All we ask is that proper credit is given for our work, which includes
* - but is not limited to - adding the above copyright notice to the beginning
* of your source code files, and to any copyright notice that you may distribute
* with programs based on this work.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 U
*/
package org.openscience.cdk.hash.stereo.parity;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import javax.vecmath.Point3d;
/**
* Geometric parity for 3D tetrahedral geometry. This class requires four 3D
* coordinates. The 3D coordinates correspond to the four ligands of a
* tetrahedral atom. If a tetrahedral atom has an implicit hydrogen (only 3
* ligands) the forth coordinate should be that of the atom at the centre
* {@cdk.cite Cieplak2001}.
*
* @author John May
* @cdk.module hash
* @see <a href="http://www.mdpi.org/molecules/papers/61100915/61100915.htm">Cieplak,
* T and Wisniewski, J.L. 2001</a>
*/
@TestClass("org.openscience.cdk.hash.stereo.parity.Tetrahedral3DParityTest")
public class Tetrahedral3DParity implements GeometricParity {
/* array of four 3D coordinates */
private final Point3d[] coordinates;
/**
* Create a new geometric parity for 3D tetrahedral geometry by specifying
* the coordinates.
*
* @param coordinates non-null, 4 3D coordinates
* @throws IllegalArgumentException if the number of coordinates was not 4
*/
@TestMethod("testConstruction_Empty")
public Tetrahedral3DParity(Point3d[] coordinates) {
if (coordinates.length != 4)
throw new IllegalArgumentException("4 coordinates expected");
this.coordinates = coordinates;
}
/**
* @inheritDoc
*/
@TestMethod("testParity_Three_Clockwise,testParity_Three_Anticlockwise," +
"testParity_Four_Clockwise,testParity_Four_Anticlockwise")
@Override public int parity() {
double x1 = coordinates[0].x;
double x2 = coordinates[1].x;
double x3 = coordinates[2].x;
double x4 = coordinates[3].x;
double y1 = coordinates[0].y;
double y2 = coordinates[1].y;
double y3 = coordinates[2].y;
double y4 = coordinates[3].y;
double z1 = coordinates[0].z;
double z2 = coordinates[1].z;
double z3 = coordinates[2].z;
double z4 = coordinates[3].z;
double det = (z1 * det(x2, y2, x3, y3, x4, y4)) -
(z2 * det(x1, y1, x3, y3, x4, y4)) +
(z3 * det(x1, y1, x2, y2, x4, y4)) -
(z4 * det(x1, y1, x2, y2, x3, y3));
return (int) Math.signum(det);
}
// 3x3 determinant helper for a constant third column
private static double det(double xa, double ya, double xb, double yb, double xc, double yc) {
return (xa - xc) * (yb - yc) - (ya - yc) * (xb - xc);
}
}
Oops, something went wrong.

0 comments on commit 20332b6

Please sign in to comment.