/// <summary>************************************************************* /// see: /// Defining the Axis of a Helix /// Peter C Kahn /// Computers Chem. Vol 13, No 3, pp 185-189, 1989 /// /// Simple Methods for Computing the Least Squares Line /// in Three Dimensions /// Peter C Kahn /// Computers Chem. Vol 13, No 3, pp 191-195, 1989 /// ************************************************************** /// </summary> public virtual void calcCenter() { if (center == null) { int i = monomerIndex + monomerCount - 1; center = new Point3f(apolymer.getLeadPoint(i)); while (--i >= monomerIndex) center.add(apolymer.getLeadPoint(i)); center.scale(1f / monomerCount); // System.out.println("structure center is at :" + center); } }
public void calcLeadMidpointsAndWingVectors() { // System.out.println("Polymer.calcLeadMidpointsAndWingVectors"); int count = monomerCount; leadMidpoints = new Point3f[count + 1]; wingVectors = new Vector3f[count + 1]; bool _hasWingPoints = hasWingPoints(); Vector3f vectorA = new Vector3f(); Vector3f vectorB = new Vector3f(); Vector3f vectorC = new Vector3f(); Vector3f vectorD = new Vector3f(); Point3f leadPointPrev, leadPoint; leadMidpoints[0] = InitiatorPoint; leadPoint = getLeadPoint(0); Vector3f previousVectorD = null; for (int i = 1; i < count; ++i) { leadPointPrev = leadPoint; leadPoint = getLeadPoint(i); Point3f midpoint = new Point3f(leadPoint); midpoint.add(leadPointPrev); midpoint.scale(0.5f); leadMidpoints[i] = midpoint; if (_hasWingPoints) { vectorA.sub(leadPoint, leadPointPrev); vectorB.sub(leadPointPrev, getWingPoint(i - 1)); vectorC.cross(vectorA, vectorB); vectorD.cross(vectorA, vectorC); vectorD.normalize(); if (previousVectorD != null && previousVectorD.angle(vectorD) > System.Math.PI / 2) vectorD.scale(- 1); previousVectorD = wingVectors[i] = new Vector3f(vectorD); } } leadMidpoints[count] = TerminatorPoint; if (!_hasWingPoints) { if (count < 3) { wingVectors[1] = unitVectorX; } else { // auto-calculate wing vectors based upon lead atom positions only // seems to work like a charm! :-) Point3f next, current, prev; prev = leadMidpoints[0]; current = leadMidpoints[1]; Vector3f previousVectorC = null; for (int i = 1; i < count; ++i) { next = leadMidpoints[i + 1]; vectorA.sub(prev, current); vectorB.sub(next, current); vectorC.cross(vectorA, vectorB); vectorC.normalize(); if (previousVectorC != null && previousVectorC.angle(vectorC) > System.Math.PI / 2) vectorC.scale(- 1); previousVectorC = wingVectors[i] = new Vector3f(vectorC); prev = current; current = next; } } } wingVectors[0] = wingVectors[1]; wingVectors[count] = wingVectors[count - 1]; /* for (int i = 0; i < wingVectors.length; ++i) { if (wingVectors[i] == null) { System.out.println("que? wingVectors[" + i + "] == null?"); System.out.println("hasWingPoints=" + hasWingPoints + " wingVectors.length=" + wingVectors.length + " count=" + count); } else if (Float.isNaN(wingVectors[i].x)) { System.out.println("wingVectors[" + i + "]=" + wingVectors[i]); } } */ }
public Point3f findFractionalAdjustment() { Point3f pointMin = new Point3f(); Point3f pointMax = new Point3f(); calcAtomsMinMax(pointMin, pointMax); pointMin.add(pointMax); pointMin.scale(0.5f); Point3f fractionalCenter = pointMin; System.Console.Out.WriteLine("fractionalCenter=" + fractionalCenter); Point3f adjustment = pointMax; adjustment.set_Renamed((float) Math.Floor(fractionalCenter.x), (float) Math.Floor(fractionalCenter.y), (float) Math.Floor(fractionalCenter.z)); return adjustment; }
public virtual void getLeadMidPoint(int groupIndex, Point3f midPoint) { if (groupIndex == monomerCount) { --groupIndex; } else if (groupIndex > 0) { midPoint.set_Renamed(getLeadPoint(groupIndex)); midPoint.add(getLeadPoint(groupIndex - 1)); midPoint.scale(0.5f); return ; } midPoint.set_Renamed(getLeadPoint(groupIndex)); }