public Point3d calcCenterOfRotation() { List<Integer> line = getLongestLayerLine(); // can't determine center of rotation if there are only 2 points // TODO does this ever happen?? if (line.size() < 3) { return subunits.getCentroid(); } Point3d centerOfRotation = new Point3d(); List<Point3d> centers = subunits.getOriginalCenters(); // calculate helix mid points for each set of 3 adjacent subunits for (int i = 0; i < line.size() - 2; i++) { Point3d p1 = new Point3d(centers.get(line.get(i))); Point3d p2 = new Point3d(centers.get(line.get(i + 1))); Point3d p3 = new Point3d(centers.get(line.get(i + 2))); transformationMatrix.transform(p1); transformationMatrix.transform(p2); transformationMatrix.transform(p3); centerOfRotation.add(getMidPoint(p1, p2, p3)); } // average over all midpoints to find best center of rotation centerOfRotation.scale(1 / (line.size() - 2)); // since helix is aligned along the y-axis, with an origin at y = 0, place the center of // rotation there centerOfRotation.y = 0; // transform center of rotation to the original coordinate frame reverseTransformationMatrix.transform(centerOfRotation); // System.out.println("center of rotation: " + centerOfRotation); return centerOfRotation; }
private void calcTransformationBySymmetryAxes() { Vector3d[] axisVectors = new Vector3d[2]; axisVectors[0] = new Vector3d(principalRotationVector); axisVectors[1] = new Vector3d(referenceVector); // y,z axis centered at the centroid of the subunits Vector3d[] referenceVectors = new Vector3d[2]; referenceVectors[0] = new Vector3d(Z_AXIS); referenceVectors[1] = new Vector3d(Y_AXIS); transformationMatrix = alignAxes(axisVectors, referenceVectors); // combine with translation Matrix4d combined = new Matrix4d(); combined.setIdentity(); Vector3d trans = new Vector3d(subunits.getCentroid()); trans.negate(); combined.setTranslation(trans); transformationMatrix.mul(combined); // for helical geometry, set a canonical view for the Z direction calcZDirection(); }
/* (non-Javadoc) * @see org.biojava.nbio.structure.quaternary.core.AxisAligner#getCentroid() */ @Override public Point3d getCentroid() { return new Point3d(subunits.getCentroid()); }