/// <summary> Takes the given Z Matrix coordinates and converts them to cartesian coordinates. /// The first Atom end up in the origin, the second on on the x axis, and the third /// one in the XY plane. The rest is added by applying the Zmatrix distances, angles /// and dihedrals. /// /// </summary> /// <param name="distances"> Array of distance variables of the Z matrix /// </param> /// <param name="angles"> Array of angle variables of the Z matrix /// </param> /// <param name="dihedrals"> Array of distance variables of the Z matrix /// </param> /// <param name="first_atoms"> Array of atom ids of the first involed atom in distance, angle and dihedral /// </param> /// <param name="second_atoms"> Array of atom ids of the second involed atom in angle and dihedral /// </param> /// <param name="third_atoms"> Array of atom ids of the third involed atom in dihedral /// /// </param> /// <cdk.dictref> blue-obelisk:zmatrixCoordinatesIntoCartesianCoordinates </cdk.dictref> public static Point3d[] zmatrixToCartesian(double[] distances, int[] first_atoms, double[] angles, int[] second_atoms, double[] dihedrals, int[] third_atoms) { Point3d[] cartesianCoords = new Point3d[distances.Length]; for (int index = 0; index < distances.Length; index++) { if (index == 0) { cartesianCoords[index] = new Point3d(0d, 0d, 0d); } else if (index == 1) { cartesianCoords[index] = new Point3d(distances[1], 0d, 0d); } else if (index == 2) { cartesianCoords[index] = new Point3d((-System.Math.Cos((angles[2] / 180) * System.Math.PI)) * distances[2] + distances[1], System.Math.Sin((angles[2] / 180) * System.Math.PI) * distances[2], 0d); } else { Vector3d cd = new Vector3d(); cd.sub(cartesianCoords[third_atoms[index]], cartesianCoords[second_atoms[index]]); Vector3d bc = new Vector3d(); bc.sub(cartesianCoords[second_atoms[index]], cartesianCoords[first_atoms[index]]); Vector3d n1 = new Vector3d(); n1.cross(cd, bc); n1.normalize(); Vector3d n2 = rotate(n1, bc, dihedrals[index]); n2.normalize(); Vector3d ba = rotate(bc, n2, -angles[index]); ba.normalize(); Vector3d ban = new Vector3d(ba); ban.scale(distances[index]); Point3d result = new Point3d(); result.add(cartesianCoords[first_atoms[index]], ba); cartesianCoords[index] = result; } } return cartesianCoords; }
/// <summary> Inverts three cell axes. /// /// </summary> /// <returns> a 3x3 matrix with the three cartesian vectors representing /// the unit cell axes. The a axis is the first row. /// </returns> public static Vector3d[] calcInvertedAxes(Vector3d aAxis, Vector3d bAxis, Vector3d cAxis) { double det = aAxis.x * bAxis.y * cAxis.z - aAxis.x * bAxis.z * cAxis.y - aAxis.y * bAxis.x * cAxis.z + aAxis.y * bAxis.z * cAxis.x + aAxis.z * bAxis.x * cAxis.y - aAxis.z * bAxis.y * cAxis.x; Vector3d[] invaxes = new Vector3d[3]; invaxes[0] = new Vector3d(); invaxes[0].x = (bAxis.y * cAxis.z - bAxis.z * cAxis.y) / det; invaxes[0].y = (bAxis.z * cAxis.x - bAxis.x * cAxis.z) / det; invaxes[0].z = (bAxis.x * cAxis.y - bAxis.y * cAxis.x) / det; invaxes[1] = new Vector3d(); invaxes[1].x = (aAxis.z * cAxis.y - aAxis.y * cAxis.z) / det; invaxes[1].y = (aAxis.x * cAxis.z - aAxis.z * cAxis.x) / det; invaxes[1].z = (aAxis.y * cAxis.x - aAxis.x * cAxis.y) / det; invaxes[2] = new Vector3d(); invaxes[2].x = (aAxis.y * bAxis.z - aAxis.z * bAxis.y) / det; invaxes[2].y = (aAxis.z * bAxis.x - aAxis.x * bAxis.z) / det; invaxes[2].z = (aAxis.x * bAxis.y - aAxis.y * bAxis.x) / det; return invaxes; }
public virtual void endElement(CMLStack xpath, System.String uri, System.String name, System.String raw) { ////logger.debug("EndElement: ", name); System.String cData = currentChars; if ("bond".Equals(name)) { if (!stereoGiven) bondStereo.Add(""); if (bondStereo.Count > bondDictRefs.Count) bondDictRefs.Add(null); } else if ("atom".Equals(name)) { if (atomCounter > eltitles.Count) { eltitles.Add(null); } if (atomCounter > hCounts.Count) { /* while strictly undefined, assume zero implicit hydrogens when no number is given */ hCounts.Add("0"); } if (atomCounter > atomDictRefs.Count) { atomDictRefs.Add(null); } if (atomCounter > isotope.Count) { isotope.Add(null); } if (atomCounter > spinMultiplicities.Count) { spinMultiplicities.Add(null); } if (atomCounter > formalCharges.Count) { /* while strictly undefined, assume zero implicit hydrogens when no number is given */ formalCharges.Add("0"); } /* It may happen that not all atoms have associated 2D or 3D coordinates. accept that */ if (atomCounter > x2.Count && x2.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ x2.Add(null); y2.Add(null); } if (atomCounter > x3.Count && x3.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ x3.Add(null); y3.Add(null); z3.Add(null); } if (atomCounter > xfract.Count && xfract.Count != 0) { /* apparently, the previous atoms had atomic coordinates, add 'null' for this atom */ xfract.Add(null); yfract.Add(null); zfract.Add(null); } } else if ("molecule".Equals(name)) { storeData(); cdo.endObject("Molecule"); } else if ("crystal".Equals(name)) { if (crystalScalar > 0) { // convert unit cell parameters to cartesians Vector3d[] axes = CrystalGeometryTools.notionalToCartesian(unitcellparams[0], unitcellparams[1], unitcellparams[2], unitcellparams[3], unitcellparams[4], unitcellparams[5]); aAxis = axes[0]; bAxis = axes[1]; cAxis = axes[2]; cartesianAxesSet = true; cdo.startObject("a-axis"); cdo.setObjectProperty("a-axis", "x", aAxis.x.ToString()); cdo.setObjectProperty("a-axis", "y", aAxis.y.ToString()); cdo.setObjectProperty("a-axis", "z", aAxis.z.ToString()); cdo.endObject("a-axis"); cdo.startObject("b-axis"); cdo.setObjectProperty("b-axis", "x", bAxis.x.ToString()); cdo.setObjectProperty("b-axis", "y", bAxis.y.ToString()); cdo.setObjectProperty("b-axis", "z", bAxis.z.ToString()); cdo.endObject("b-axis"); cdo.startObject("c-axis"); cdo.setObjectProperty("c-axis", "x", cAxis.x.ToString()); cdo.setObjectProperty("c-axis", "y", cAxis.y.ToString()); cdo.setObjectProperty("c-axis", "z", cAxis.z.ToString()); cdo.endObject("c-axis"); } else { ////logger.error("Could not find crystal unit cell parameters"); } cdo.endObject("Crystal"); } else if ("list".Equals(name)) { cdo.endObject("SetOfMolecules"); } else if ("coordinate3".Equals(name)) { if (BUILTIN.Equals("xyz3")) { ////logger.debug("New coord3 xyz3 found: ", currentChars); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(currentChars); x3.Add(st.NextToken()); y3.Add(st.NextToken()); z3.Add(st.NextToken()); ////logger.debug("coord3 x3.length: ", x3.Count); ////logger.debug("coord3 y3.length: ", y3.Count); ////logger.debug("coord3 z3.length: ", z3.Count); } catch (System.Exception exception) { ////logger.error("CMLParsing error while setting coordinate3!"); ////logger.debug(exception); } } else { ////logger.warn("Unknown coordinate3 BUILTIN: " + BUILTIN); } } else if ("string".Equals(name)) { if (BUILTIN.Equals("elementType")) { ////logger.debug("Element: ", cData.Trim()); elsym.Add(cData); } else if (BUILTIN.Equals("atomRef")) { curRef++; ////logger.debug("Bond: ref #", curRef); if (curRef == 1) { bondARef1.Add(cData.Trim()); } else if (curRef == 2) { bondARef2.Add(cData.Trim()); } } else if (BUILTIN.Equals("order")) { ////logger.debug("Bond: order ", cData.Trim()); order.Add(cData.Trim()); } else if (BUILTIN.Equals("formalCharge")) { // NOTE: this combination is in violation of the CML DTD!!! ////logger.warn("formalCharge BUILTIN accepted but violating CML DTD"); ////logger.debug("Charge: ", cData.Trim()); System.String charge = cData.Trim(); if (charge.StartsWith("+") && charge.Length > 1) { charge = charge.Substring(1); } formalCharges.Add(charge); } } else if ("float".Equals(name)) { if (BUILTIN.Equals("x3")) { x3.Add(cData.Trim()); } else if (BUILTIN.Equals("y3")) { y3.Add(cData.Trim()); } else if (BUILTIN.Equals("z3")) { z3.Add(cData.Trim()); } else if (BUILTIN.Equals("x2")) { x2.Add(cData.Trim()); } else if (BUILTIN.Equals("y2")) { y2.Add(cData.Trim()); } else if (BUILTIN.Equals("order")) { // NOTE: this combination is in violation of the CML DTD!!! order.Add(cData.Trim()); } else if (BUILTIN.Equals("charge") || BUILTIN.Equals("partialCharge")) { partialCharges.Add(cData.Trim()); } } else if ("integer".Equals(name)) { if (BUILTIN.Equals("formalCharge")) { formalCharges.Add(cData.Trim()); } } else if ("coordinate2".Equals(name)) { if (BUILTIN.Equals("xy2")) { ////logger.debug("New coord2 xy2 found.", cData); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); x2.Add(st.NextToken()); y2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 175, 1); } } } else if ("stringArray".Equals(name)) { if (BUILTIN.Equals("id") || BUILTIN.Equals("atomId") || BUILTIN.Equals("atomID")) { // invalid according to CML1 DTD but found in OpenBabel 1.x output try { bool countAtoms = (atomCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countAtoms) { atomCounter++; } System.String token = st.NextToken(); ////logger.debug("StringArray (Token): ", token); elid.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 186, 1); } } else if (BUILTIN.Equals("elementType")) { try { bool countAtoms = (atomCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countAtoms) { atomCounter++; } elsym.Add(st.NextToken()); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("atomRefs")) { curRef++; ////logger.debug("New atomRefs found: ", curRef); try { bool countBonds = (bondCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countBonds) { bondCounter++; } System.String token = st.NextToken(); ////logger.debug("Token: ", token); if (curRef == 1) { bondARef1.Add(token); } else if (curRef == 2) { bondARef2.Add(token); } } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("atomRef")) { curRef++; ////logger.debug("New atomRef found: ", curRef); // this is CML1 stuff, we get things like: /* <bondArray> <stringArray builtin="atomRef">a2 a2 a2 a2 a3 a3 a4 a4 a5 a6 a7 a9</stringArray> <stringArray builtin="atomRef">a9 a11 a12 a13 a5 a4 a6 a9 a7 a8 a8 a10</stringArray> <stringArray builtin="order">1 1 1 1 2 1 2 1 1 1 2 2</stringArray> </bondArray> */ try { bool countBonds = (bondCounter == 0) ? true : false; SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { if (countBonds) { bondCounter++; } System.String token = st.NextToken(); ////logger.debug("Token: ", token); if (curRef == 1) { bondARef1.Add(token); } else if (curRef == 2) { bondARef2.Add(token); } } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } else if (BUILTIN.Equals("order")) { ////logger.debug("New bond order found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { System.String token = st.NextToken(); ////logger.debug("Token: ", token); order.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 194, 1); } } } else if ("integerArray".Equals(name)) { ////logger.debug("IntegerArray: builtin = ", BUILTIN); if (BUILTIN.Equals("formalCharge")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) { System.String token = st.NextToken(); ////logger.debug("Charge added: ", token); formalCharges.Add(token); } } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } } else if ("scalar".Equals(name)) { if (xpath.ToString().EndsWith("crystal/scalar/")) { ////logger.debug("Going to set a crystal parameter: " + crystalScalar, " to ", cData); try { unitcellparams[crystalScalar - 1] = System.Double.Parse(cData.Trim()); } catch (System.FormatException exception) { ////logger.error("Content must a float: " + cData); } } else { if (xpath.ToString().EndsWith("bond/scalar/")) { if (DICTREF.Equals("mdl:stereo")) { bondStereo.Add(cData.Trim()); stereoGiven = true; } } else { if (xpath.ToString().EndsWith("atom/scalar/")) { if (DICTREF.Equals("cdk:partialCharge")) { partialCharges.Add(cData.Trim()); } } else { if (xpath.ToString().EndsWith("molecule/scalar/")) { if (DICTREF.Equals("pdb:id")) { cdo.setObjectProperty("Molecule", DICTREF, cData); } } else { ////logger.warn("Ignoring scalar: " + xpath); } } } } } else if ("floatArray".Equals(name)) { if (BUILTIN.Equals("x3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) x3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } else if (BUILTIN.Equals("y3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) y3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 213, 1); } } else if (BUILTIN.Equals("z3")) { try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) z3.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 221, 1); } } else if (BUILTIN.Equals("x2")) { ////logger.debug("New floatArray found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) x2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 205, 1); } } else if (BUILTIN.Equals("y2")) { ////logger.debug("New floatArray found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) y2.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 454, 1); } } else if (BUILTIN.Equals("partialCharge")) { ////logger.debug("New floatArray with partial charges found."); try { SupportClass.Tokenizer st = new SupportClass.Tokenizer(cData); while (st.HasMoreTokens()) partialCharges.Add(st.NextToken()); } catch (System.Exception e) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" notify("CMLParsing error: " + e, SYSTEMID, 462, 1); } } } else if ("basic".Equals(name)) { // assuming this is the child element of <identifier> this.inchi = cData; } else if ("name".Equals(name)) { if (xpath.ToString().EndsWith("molecule/name/")) { cdo.setObjectProperty("Molecule", DICTREF, cData); } } else { ////logger.warn("Skipping element: " + name); } currentChars = ""; BUILTIN = ""; elementTitle = ""; }
/// <summary> Sets the value of this matrix to a scale and translation matrix; /// the translation is scaled by the scale factor and all of the /// matrix values are modified. /// </summary> /// <param name="v1">the translation amount /// </param> /// <param name="scale">the scale factor for the matrix /// </param> public void set_Renamed(Vector3d v1, double scale) { m00 = scale; m01 = 0.0; m02 = 0.0; m03 = scale * v1.x; m10 = 0.0; m11 = scale; m12 = 0.0; m13 = scale * v1.y; m20 = 0.0; m21 = 0.0; m22 = scale; m23 = scale * v1.z; m30 = 0.0; m31 = 0.0; m32 = 0.0; m33 = 1.0; }
/// <summary> Clean all data about read bonds.</summary> protected internal virtual void newCrystalData() { unitcellparams = new double[6]; cartesianAxesSet = false; crystalScalar = 0; aAxis = new Vector3d(); bAxis = new Vector3d(); cAxis = new Vector3d(); }
/// <summary> Copies the matrix values in the specified row into the vector parameter.</summary> /// <param name="row"> the matrix row /// </param> /// <param name="v"> the vector into which the matrix row values will be copied /// </param> public void getRow(int row, Vector3d v) { if (row == 0) { v.x = m00; v.y = m01; v.z = m02; } else if (row == 1) { v.x = m10; v.y = m11; v.z = m12; } else if (row == 2) { v.x = m20; v.y = m21; v.z = m22; } else { throw new Exception();//ArrayIndexOutOfBoundsException(VecMathI18N.getString("Matrix3d2")); } }
/// <summary> Sets the specified column of this matrix3d to the vector provided.</summary> /// <param name="column">the column number to be modified (zero indexed) /// </param> /// <param name="v">the replacement column /// </param> public void setColumn(int column, Vector3d v) { switch (column) { case 0: this.m00 = v.x; this.m10 = v.y; this.m20 = v.z; break; case 1: this.m01 = v.x; this.m11 = v.y; this.m21 = v.z; break; case 2: this.m02 = v.x; this.m12 = v.y; this.m22 = v.z; break; default: throw new Exception();//ArrayIndexOutOfBoundsException(VecMathI18N.getString("Matrix3d9")); } }
/// <cdk.dictref> blue-obelisk:convertCartesianIntoNotionalCoordinates </cdk.dictref> public static double[] cartesianToNotional(Vector3d aAxis, Vector3d bAxis, Vector3d cAxis) { double[] notionalCoords = new double[6]; notionalCoords[0] = aAxis.length(); notionalCoords[1] = bAxis.length(); notionalCoords[2] = cAxis.length(); notionalCoords[3] = bAxis.angle(cAxis) * 180.0 / System.Math.PI; notionalCoords[4] = aAxis.angle(cAxis) * 180.0 / System.Math.PI; notionalCoords[5] = aAxis.angle(bAxis) * 180.0 / System.Math.PI; return notionalCoords; }
/// <summary> Modifies the translational components of this matrix to the values of /// the Vector3d argument; the other values of this matrix are not modified. /// </summary> /// <param name="trans">the translational component /// </param> public void setTranslation(Vector3d trans) { m03 = trans.x; m13 = trans.y; m23 = trans.z; }
/// <summary> Performs an SVD normalization of this matrix to calculate the rotation /// as a 3x3 matrix, the translation, and the scale. None of the matrix values are modified. /// </summary> /// <param name="m1">The normalized matrix representing the rotation /// </param> /// <param name="t1">The translation component /// </param> /// <returns> The scale component of this transform /// </returns> public double get_Renamed(Matrix3f m1, Vector3d t1) { get_Renamed(t1); return SVD(m1); }
/// <summary> Retrieves the translational components of this matrix.</summary> /// <param name="trans">the vector that will receive the translational component /// </param> public void get_Renamed(Vector3d trans) { trans.x = m03; trans.y = m13; trans.z = m23; }
/// <summary> Constructs and initializes a Matrix4d from the rotation matrix, /// translation, and scale values; the scale is applied only to the /// rotational components of the matrix (upper 3x3) and not to the /// translational components. /// </summary> /// <param name="m1"> The rotation matrix representing the rotational components /// </param> /// <param name="t1"> The translational components of the matrix /// </param> /// <param name="s"> The scale value applied to the rotational components /// </param> public Matrix4d(Matrix3f m1, Vector3d t1, double s) { // why no set(Matrix3f, Vector3d, double) ? // set(Matrix3f, Vector3f, float) is there. // feel inconsistent. set_Renamed(m1); mulRotationScale(s); setTranslation(t1); m33 = 1.0; }
/// <summary> Constructs and initializes a Matrix4d from the rotation matrix, /// translation, and scale values; the scale is applied only to the /// rotational components of the matrix (upper 3x3) and not to the /// translational components. /// </summary> /// <param name="m1"> The rotation matrix representing the rotational components /// </param> /// <param name="t1"> The translational components of the matrix /// </param> /// <param name="s"> The scale value applied to the rotational components /// </param> public Matrix4d(Matrix3d m1, Vector3d t1, double s) { set_Renamed(m1, t1, s); }
/// <summary> Constructs and initializes a Matrix4d from the quaternion, /// translation, and scale values; the scale is applied only to the /// rotational components of the matrix (upper 3x3) and not to the /// translational components. /// </summary> /// <param name="q1"> The quaternion value representing the rotational component /// </param> /// <param name="t1"> The translational component of the matrix /// </param> /// <param name="s"> The scale value applied to the rotational components /// </param> public Matrix4d(Quat4f q1, Vector3d t1, double s) { set_Renamed(q1, t1, s); }
/// <summary> Transforms the normal parameter by this transform and places the value /// back into normal. The fourth element of the normal is assumed to be zero. /// </summary> /// <param name="normal">the input normal to be transformed. /// </param> public void transform(Vector3d normal) { transform(normal, normal); }
/// <summary> Transforms the normal parameter by this Matrix4d and places the value /// into normalOut. The fourth element of the normal is assumed to be zero. /// </summary> /// <param name="normal">the input normal to be transformed. /// </param> /// <param name="normalOut">the transformed normal /// </param> public void transform(Vector3d normal, Vector3d normalOut) { normalOut.set_Renamed(m00 * normal.x + m01 * normal.y + m02 * normal.z, m10 * normal.x + m11 * normal.y + m12 * normal.z, m20 * normal.x + m21 * normal.y + m22 * normal.z); }
/// <cdk.dictref> blue-obelisk:convertFractionIntoCartesianCoordinates </cdk.dictref> public static Point3d fractionalToCartesian(Vector3d aAxis, Vector3d bAxis, Vector3d cAxis, Point3d frac) { Point3d cart = new Point3d(); cart.x = frac.x * aAxis.x + frac.y * bAxis.x + frac.z * cAxis.x; cart.y = frac.x * aAxis.y + frac.y * bAxis.y + frac.z * cAxis.y; cart.z = frac.x * aAxis.z + frac.y * bAxis.z + frac.z * cAxis.z; return cart; }
/// <cdk.dictref> blue-obelisk:convertCartesianIntoFractionalCoordinates </cdk.dictref> public static Point3d cartesianToFractional(Vector3d aAxis, Vector3d bAxis, Vector3d cAxis, Point3d cartPoint) { Vector3d[] invaxis = calcInvertedAxes(aAxis, bAxis, cAxis); Point3d frac = new Point3d(); frac.x = invaxis[0].x * cartPoint.x + invaxis[0].y * cartPoint.y + invaxis[0].z * cartPoint.z; frac.y = invaxis[1].x * cartPoint.x + invaxis[1].y * cartPoint.y + invaxis[1].z * cartPoint.z; frac.z = invaxis[2].x * cartPoint.x + invaxis[2].y * cartPoint.y + invaxis[2].z * cartPoint.z; return frac; }
/// <summary> Calculates cartesian vectors for unit cell axes from axes lengths and angles /// between axes. /// /// <p>To calculate cartesian coordinates, it places the a axis on the x axes, /// the b axis in the xy plane, making an angle gamma with the a axis, and places /// the c axis to fullfil the remaining constraints. (See also /// <a href="http://server.ccl.net/cca/documents/molecular-modeling/node4.html">the /// CCL archive</a>.) /// /// </summary> /// <param name="alength"> length of the a axis /// </param> /// <param name="blength"> length of the b axis /// </param> /// <param name="clength"> length of the c axis /// </param> /// <param name="alpha"> angle between b and c axes in degrees /// </param> /// <param name="beta"> angle between a and c axes in degrees /// </param> /// <param name="gamma"> angle between a and b axes in degrees /// </param> /// <returns> an array of Vector3d objects with the three cartesian vectors representing /// the unit cell axes. /// /// </returns> /// <cdk.keyword> notional coordinates </cdk.keyword> /// <cdk.dictref> blue-obelisk:convertNotionalIntoCartesianCoordinates </cdk.dictref> public static Vector3d[] notionalToCartesian(double alength, double blength, double clength, double alpha, double beta, double gamma) { Vector3d[] axes = new Vector3d[3]; /* 1. align the a axis with x axis */ axes[0] = new Vector3d(); axes[0].x = alength; axes[0].y = 0.0; axes[0].z = 0.0; double toRadians = System.Math.PI / 180.0; /* some intermediate variables */ double cosalpha = System.Math.Cos(toRadians * alpha); double cosbeta = System.Math.Cos(toRadians * beta); double cosgamma = System.Math.Cos(toRadians * gamma); double singamma = System.Math.Sin(toRadians * gamma); /* 2. place the b is in xy plane making a angle gamma with a */ axes[1] = new Vector3d(); axes[1].x = blength * cosgamma; axes[1].y = blength * singamma; axes[1].z = 0.0; /* 3. now the c axis, with more complex maths */ axes[2] = new Vector3d(); double volume = alength * blength * clength * System.Math.Sqrt(1.0 - cosalpha * cosalpha - cosbeta * cosbeta - cosgamma * cosgamma + 2.0 * cosalpha * cosbeta * cosgamma); axes[2].x = clength * cosbeta; axes[2].y = clength * (cosalpha - cosbeta * cosgamma) / singamma; axes[2].z = volume / (alength * blength * singamma); return axes; }
/// <summary> Constructs and initializes a Vector3f from the specified Vector3d.</summary> /// <param name="v1">the Vector3d containing the initialization x y z data /// </param> public Vector3f(Vector3d v1):base(v1) { }
/// <summary> Constructs and initializes an AxisAngle4d from the specified /// axis and angle. /// </summary> /// <param name="axis">the axis /// </param> /// <param name="angle">the angle of rotation in radian /// /// </param> /// <since> Java 3D 1.2 /// </since> public AxisAngle4d(Vector3d axis, double angle) { this.x = axis.x; this.y = axis.y; this.z = axis.z; this.angle = angle; }
/// <summary> Sets the value of this matrix from the rotation expressed by the /// rotation matrix m1, the translation t1, and the scale s. The translation /// is not modified by the scale. /// </summary> /// <param name="m1">The rotation component /// </param> /// <param name="t1">The translation component /// </param> /// <param name="scale">The scale component /// </param> public void set_Renamed(Matrix3d m1, Vector3d t1, double scale) { setRotationScale(m1); mulRotationScale(scale); setTranslation(t1); m33 = 1.0; }
/// <summary> Initializes the unit cell axes to zero length.</summary> private void setZeroAxes() { aAxis = new Vector3d(0.0, 0.0, 0.0); bAxis = new Vector3d(0.0, 0.0, 0.0); cAxis = new Vector3d(0.0, 0.0, 0.0); }
/// <summary> Sets the value of this AxisAngle4d to the specified /// axis and angle. /// </summary> /// <param name="axis">the axis /// </param> /// <param name="angle">the angle of rotation in radians /// /// </param> /// <since> Java 3D 1.2 /// </since> public void set_Renamed(Vector3d axis, double angle) { this.x = axis.x; this.y = axis.y; this.z = axis.z; this.angle = angle; }
private IChemFile readChemFile(IChemFile file) { IChemSequence seq = file.Builder.newChemSequence(); IChemModel model = file.Builder.newChemModel(); ICrystal crystal = null; int lineNumber = 0; Vector3d a, b, c; try { System.String line = input.ReadLine(); while (input.Peek() != -1 && line != null) { //logger.debug((lineNumber++) + ": ", line); if (line.StartsWith("frame:")) { //logger.debug("found new frame"); model = file.Builder.newChemModel(); crystal = file.Builder.newCrystal(); // assume the file format is correct //logger.debug("reading spacegroup"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); crystal.SpaceGroup = line; //logger.debug("reading unit cell axes"); Vector3d axis = new Vector3d(); //logger.debug("parsing A: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.A = axis; axis = new Vector3d(); //logger.debug("parsing B: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.B = axis; axis = new Vector3d(); //logger.debug("parsing C: "); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.x = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.y = FortranFormat.atof(line); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); axis.z = FortranFormat.atof(line); crystal.C = axis; //logger.debug("Crystal: ", crystal); a = crystal.A; b = crystal.B; c = crystal.C; //logger.debug("Reading number of atoms"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); int atomsToRead = System.Int32.Parse(line); //logger.debug("Reading no molecules in assym unit cell"); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); int Z = System.Int32.Parse(line); crystal.Z = Z; System.String symbol; double charge; Point3d cart; for (int i = 1; i <= atomsToRead; i++) { cart = new Point3d(); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); symbol = line.Substring(0, (line.IndexOf(":")) - (0)); charge = System.Double.Parse(line.Substring(line.IndexOf(":") + 1)); line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.x = System.Double.Parse(line); // x line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.y = System.Double.Parse(line); // y line = input.ReadLine(); //logger.debug((lineNumber++) + ": ", line); cart.z = System.Double.Parse(line); // z IAtom atom = file.Builder.newAtom(symbol); atom.setCharge(charge); // convert cartesian coords to fractional Point3d frac = CrystalGeometryTools.cartesianToFractional(a, b, c, cart); atom.setFractionalPoint3d(frac); crystal.addAtom(atom); //logger.debug("Added atom: ", atom); } model.Crystal = crystal; seq.addChemModel(model); } else { //logger.debug("Format seems broken. Skipping these lines:"); while (!line.StartsWith("frame:") && input.Peek() != -1 && line != null) { line = input.ReadLine(); //logger.debug(lineNumber++ + ": ", line); } //logger.debug("Ok, resynched: found new frame"); } } file.addChemSequence(seq); } catch (System.Exception exception) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.String message = "Error while parsing CrystClust file: " + exception.Message; //logger.error(message); //logger.debug(exception); throw new CDKException(message, exception); } return file; }
/// <summary> Sets the value of this matrix from the rotation expressed by the /// quaternion q1, the translation t1, and the scale s. /// </summary> /// <param name="q1"> the rotation expressed as a quaternion /// </param> /// <param name="t1"> the translation /// </param> /// <param name="s"> the scale value /// </param> public void set_Renamed(Quat4d q1, Vector3d t1, double s) { set_Renamed(q1); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" mulRotationScale((float) s); m03 = (float) t1.x; m13 = (float) t1.y; m23 = (float) t1.z; }
/// <summary> Copies the matrix values in the specified column into the vector /// parameter. /// </summary> /// <param name="column"> the matrix column /// </param> /// <param name="v"> the vector into which the matrix row values will be copied /// </param> public void getColumn(int column, Vector3d v) { if (column == 0) { v.x = m00; v.y = m10; v.z = m20; } else if (column == 1) { v.x = m01; v.y = m11; v.z = m21; } else if (column == 2) { v.x = m02; v.y = m12; v.z = m22; } else { throw new Exception();//ArrayIndexOutOfBoundsException(VecMathI18N.getString("Matrix3d4")); } }
/// <summary> Sets the value of this matrix from the rotation expressed by the /// rotation matrix m1, the translation t1, and the scale s. The translation /// is not modified by the scale. /// </summary> /// <param name="m1">The rotation component /// </param> /// <param name="t1">The translation component /// </param> /// <param name="scale">The scale component /// </param> public void set_Renamed(Matrix3d m1, Vector3d t1, double scale) { setRotationScale(m1); //UPGRADE_WARNING: Data types in Visual C# might be different. Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'" mulRotationScale((float) scale); setTranslation(t1); m33 = 1.0f; }
private static double getAngle(IAtom atom1, IAtom atom2, IAtom atom3) { Vector3d centerAtom = new Vector3d(); centerAtom.x = atom1.X3d; centerAtom.y = atom1.Y3d; centerAtom.z = atom1.Z3d; Vector3d firstAtom = new Vector3d(); Vector3d secondAtom = new Vector3d(); firstAtom.x = atom2.X3d; firstAtom.y = atom2.Y3d; firstAtom.z = atom2.Z3d; secondAtom.x = atom3.X3d; secondAtom.y = atom3.Y3d; secondAtom.z = atom3.Z3d; firstAtom.sub(centerAtom); secondAtom.sub(centerAtom); return firstAtom.angle(secondAtom); }
/// <summary> Modifies the translational components of this matrix to the values of /// the Vector3d argument; the other values of this matrix are not modified. /// </summary> /// <param name="trans">the translational component /// </param> private void setTranslation(Vector3d trans) { m03 = (float) trans.x; m13 = (float) trans.y; m23 = (float) trans.z; }