/** * Parity computation for one side of a double bond in a geometric center. * The method needs the 3D coordinates of the double bond atoms (first 2 * arguments) and the coordinates of two substituents (one at each end). * * @param u an atom double bonded to v * @param v an atom double bonded to u * @param x an atom sigma bonded to u * @param w an atom sigma bonded to v * @return the parity of the atoms */ private int parity(Point3d u, Point3d v, Point3d x, Point3d w) { // create three vectors, v->u, v->w and u->x double[] vu = toVector(v, u); double[] vw = toVector(v, w); double[] ux = toVector(u, x); // normal vector (to compare against), the normal vector (n) looks like: // x n w // \ |/ // u = v double[] normal = crossProduct(vu, crossProduct(vu, vw)); // compare the dot products of v->w and u->x, if the signs are the same // they are both pointing the same direction. if a value is close to 0 // then it is at pi/2 radians (i.e. unspecified) however 3D coordinates // are generally discrete and do not normally represent on unspecified // stereo configurations so we don't check this int parity = (int) Math.signum(dot(normal, vw)) * (int) Math.signum(dot(normal, ux)); // invert sign, this then matches with Sp2 double bond parity return parity * -1; }