## cdk-commits

 [Cdk-commits] CVS: cdk/src/org/openscience/cdk/geometry CrystalGeometryTools.java,1.1,1.2 GeometryTools.java,1.5,1.6 From: Egon Willighagen - 2002-11-27 13:49:55 ```Update of /cvsroot/cdk/cdk/src/org/openscience/cdk/geometry In directory sc8-pr-cvs1:/tmp/cvs-serv28143/src/org/openscience/cdk/geometry Modified Files: CrystalGeometryTools.java GeometryTools.java Log Message: Two getCentreOfMass() methods added. More code moved from ShelXReader to CrystalGeometryTools. Index: CrystalGeometryTools.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/geometry/CrystalGeometryTools.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -r1.1 -r1.2 *** CrystalGeometryTools.java 27 Nov 2002 10:59:00 -0000 1.1 --- CrystalGeometryTools.java 27 Nov 2002 13:49:51 -0000 1.2 *************** *** 83,93 **** * @keyword notional coordinates */ ! public static double[][] calculateCartesianVectors(double alength, double blength, ! double clength, double alpha, ! double beta, double gamma) { double[][] axes = new double[3][3]; /* 1. align the a axis with x axis */ ! axes[0][0] = a; // ax axes[0][1] = 0.0; // ay axes[0][2] = 0.0; // az --- 83,93 ---- * @keyword notional coordinates */ ! public static double[][] notionalToCartesian(double alength, double blength, ! double clength, double alpha, ! double beta, double gamma) { double[][] axes = new double[3][3]; /* 1. align the a axis with x axis */ ! axes[0][0] = alength; // ax axes[0][1] = 0.0; // ay axes[0][2] = 0.0; // az *************** *** 102,120 **** /* 2. place the b is in xy plane making a angle gamma with a */ ! axes[1][0] = b*cosgamma; // bx ! axes[1][1] = b*singamma; // by axes[1][2] = 0.0; // bz /* 3. now the c axis, * source: http://server.ccl.net/cca/documents/molecular-modeling/node4.html */ ! double V = a * b * c * Math.sqrt(1.0 - cosalpha*cosalpha - cosbeta*cosbeta - cosgamma*cosgamma + 2.0*cosalpha*cosbeta*cosgamma); ! axes[2][0] = c*cosbeta; // cx ! axes[2][1] = c*(cosalpha - // cy cosbeta*cosgamma)/singamma; ! axes[2][2] = V/(a*b*singamma); // cz return axes; --- 102,121 ---- /* 2. place the b is in xy plane making a angle gamma with a */ ! axes[1][0] = blength*cosgamma; // bx ! axes[1][1] = blength*singamma; // by axes[1][2] = 0.0; // bz /* 3. now the c axis, * source: http://server.ccl.net/cca/documents/molecular-modeling/node4.html */ ! double V = alength * blength * clength * Math.sqrt(1.0 - cosalpha*cosalpha - cosbeta*cosbeta - cosgamma*cosgamma + 2.0*cosalpha*cosbeta*cosgamma); ! axes[2][0] = clength*cosbeta; // cx ! axes[2][1] = clength*(cosalpha- // cy cosbeta*cosgamma)/singamma; ! axes[2][2] = V/(alength*blength ! *singamma); // cz return axes; Index: GeometryTools.java =================================================================== RCS file: /cvsroot/cdk/cdk/src/org/openscience/cdk/geometry/GeometryTools.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -r1.5 -r1.6 *** GeometryTools.java 5 Oct 2002 14:48:46 -0000 1.5 --- GeometryTools.java 27 Nov 2002 13:49:51 -0000 1.6 *************** *** 1,3 **** ! /* \$RCSfile\$ * \$Author\$ * \$Date\$ --- 1,3 ---- ! /* \$RCSfile\$ * \$Author\$ * \$Date\$ *************** *** 226,229 **** --- 226,282 ---- } + /** + * Calculates the center of mass for the Atoms in the + * AtomContainer for the 2D coordinates. + * + * @param ac AtomContainer for which the center of mass is calculated + * + * @keyword center of mass + */ + public static Point2d get2DCentreOfMass(AtomContainer ac) { + double x = 0.0; + double y = 0.0; + + double totalmass = 0.0; + + AtomEnumeration atoms = ac.atoms(); + while (atoms.hasMoreElements()) { + Atom a = (Atom)atoms.nextElement(); + double mass = a.getExactMass(); + totalmass += mass; + x += mass*a.getX2D(); + y += mass*a.getY2D(); + } + + return new Point2d(x/totalmass, y/totalmass); + } + + /** + * Calculates the center of mass for the Atoms in the + * AtomContainer for the 2D coordinates. + * + * @param ac AtomContainer for which the center of mass is calculated + * + * @keyword center of mass + */ + public static Point3d get3DCentreOfMass(AtomContainer ac) { + double x = 0.0; + double y = 0.0; + double z = 0.0; + + double totalmass = 0.0; + + AtomEnumeration atoms = ac.atoms(); + while (atoms.hasMoreElements()) { + Atom a = (Atom)atoms.nextElement(); + double mass = a.getExactMass(); + totalmass += mass; + x += mass*a.getX3D(); + y += mass*a.getY3D(); + z += mass*a.getZ3D(); + } + + return new Point3d(x/totalmass, y/totalmass, z/totalmass); + } public static double getAngle(double xDiff, double yDiff) ```