/// <summary> Constructs an Atom from a String containing an element symbol. /// /// </summary> /// <param name="elementSymbol"> The String describing the element for the Atom /// </param> public Atom(System.String elementSymbol) : base(elementSymbol) { this.fractionalPoint3d = null; this.point3d = null; this.point2d = null; }
/// <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; }
/// <deprecated> /// </deprecated> public static Point3d fractionalToCartesian(double[] aAxis, double[] bAxis, double[] cAxis, Point3d fracPoint) { double[] frac = new double[3]; frac[0] = fracPoint.x; frac[1] = fracPoint.y; frac[2] = fracPoint.z; double[] cart = fractionalToCartesian(aAxis, bAxis, cAxis, frac); return new Point3d(cart[0], cart[1], cart[2]); }
/// <summary> Constructs an Atom from an Element and a Point3d. /// /// </summary> /// <param name="elementSymbol"> The symbol of the atom /// </param> /// <param name="point3d"> The 3D coordinates of the atom /// </param> public Atom(System.String elementSymbol, javax.vecmath.Point3d point3d) : this(elementSymbol) { this.point3d = point3d; }
/// <summary> /// Sets a point specifying the location of this /// atom in 3D space. /// /// </summary> /// <param name="point3d"> A point in a 3-dimensional space /// /// </param> /// <seealso cref="getPoint3d"> /// </seealso> public virtual void setPoint3d(javax.vecmath.Point3d point3d) { this.point3d = point3d; notifyChanged(); }
/// <summary> Rotates a 3D point about a specified line segment by a specified angle. /// /// The code is based on code available <a href="http://astronomy.swin.edu.au/~pbourke/geometry/rotate/source.c">here</a>. /// Positive angles are anticlockwise looking down the axis towards the origin. /// Assume right hand coordinate system. /// /// </summary> /// <param name="atom">The atom to rotate /// </param> /// <param name="p1"> The first point of the line segment /// </param> /// <param name="p2"> The second point of the line segment /// </param> /// <param name="angle"> The angle to rotate by (in degrees) /// </param> public static void rotate(IAtom atom, Point3d p1, Point3d p2, double angle) { double costheta, sintheta; Point3d r = new Point3d(); r.x = p2.x - p1.x; r.y = p2.y - p1.y; r.z = p2.z - p1.z; normalize(r); angle = angle * System.Math.PI / 180.0; costheta = System.Math.Cos(angle); sintheta = System.Math.Sin(angle); Point3d p = atom.getPoint3d(); p.x -= p1.x; p.y -= p1.y; p.z -= p1.z; Point3d q = new Point3d(0, 0, 0); q.x += (costheta + (1 - costheta) * r.x * r.x) * p.x; q.x += ((1 - costheta) * r.x * r.y - r.z * sintheta) * p.y; q.x += ((1 - costheta) * r.x * r.z + r.y * sintheta) * p.z; q.y += ((1 - costheta) * r.x * r.y + r.z * sintheta) * p.x; q.y += (costheta + (1 - costheta) * r.y * r.y) * p.y; q.y += ((1 - costheta) * r.y * r.z - r.x * sintheta) * p.z; q.z += ((1 - costheta) * r.x * r.z - r.y * sintheta) * p.x; q.z += ((1 - costheta) * r.y * r.z + r.x * sintheta) * p.y; q.z += (costheta + (1 - costheta) * r.z * r.z) * p.z; q.x += p1.x; q.y += p1.y; q.z += p1.z; atom.setPoint3d(q); }
public virtual IAtom newAtom(String elementSymbol, Point3d point3d) { return new Atom(elementSymbol, point3d); }
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> Returns the distance between this point and point p1.</summary> /// <param name="p1">the other point /// </param> /// <returns> the distance /// </returns> public double distance(Point3d p1) { double dx, dy, dz; dx = this.x - p1.x; dy = this.y - p1.y; dz = this.z - p1.z; return System.Math.Sqrt(dx * dx + dy * dy + dz * dz); }
/// <summary> Transforms the point parameter with this Matrix4d and /// places the result back into point. The fourth element of the /// point input paramter is assumed to be one. /// </summary> /// <param name="point">the input point to be transformed. /// </param> public void transform(Point3d point) { transform(point, point); }
/// <summary> Transforms the point parameter with this Matrix4d and places the result /// into pointOut. The fourth element of the point input paramter is assumed /// to be one. /// </summary> /// <param name="point">the input point to be transformed. /// </param> /// <param name="pointOut">the transformed point /// </param> public void transform(Point3d point, Point3d pointOut) { pointOut.set_Renamed(m00 * point.x + m01 * point.y + m02 * point.z + m03, m10 * point.x + m11 * point.y + m12 * point.z + m13, m20 * point.x + m21 * point.y + m22 * point.z + m23); }
/// <summary> Sets a point specifying the location of this /// atom in a Crystal unit cell. /// /// </summary> /// <param name="point3d"> A point in a 3d fractional unit cell space /// /// </param> /// <seealso cref="getFractionalPoint3d"> /// </seealso> /// <seealso cref="org.openscience.cdk.Crystal"> /// </seealso> public virtual void setFractionalPoint3d(javax.vecmath.Point3d point3d) { this.fractionalPoint3d = point3d; notifyChanged(); }
/// <summary> /// Sets a point specifying the location of this /// atom in 3D space. /// /// </summary> /// <param name="point3d"> A point in a 3-dimensional space /// /// </param> /// <seealso cref="getPoint3d"> /// </seealso> public virtual void setPoint3d(javax.vecmath.Point3d point3d) { this.point3d = point3d; notifyChanged(); }
/// <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> Computes the L-1 (Manhattan) distance between this point and /// point p1. The L-1 distance is equal to: /// abs(x1-x2) + abs(y1-y2) + abs(z1-z2). /// </summary> /// <param name="p1">the other point /// </param> /// <returns> the L-1 distance /// </returns> public double distanceL1(Point3d p1) { return System.Math.Abs(this.x - p1.x) + System.Math.Abs(this.y - p1.y) + System.Math.Abs(this.z - p1.z); }
private void processAtomLoopBlock(System.String firstLine) { int atomLabel = -1; // -1 means not found in this block int atomSymbol = -1; int atomFractX = -1; int atomFractY = -1; int atomFractZ = -1; int atomRealX = -1; int atomRealY = -1; int atomRealZ = -1; System.String line = firstLine.Trim(); int headerCount = 0; bool hasParsableInformation = false; while (line != null && line[0] == '_') { headerCount++; if (line.Equals("_atom_site_label") || line.Equals("_atom_site_label_atom_id")) { atomLabel = headerCount; hasParsableInformation = true; //logger.info("label found in col: " + atomLabel); } else if (line.StartsWith("_atom_site_fract_x")) { atomFractX = headerCount; hasParsableInformation = true; //logger.info("frac x found in col: " + atomFractX); } else if (line.StartsWith("_atom_site_fract_y")) { atomFractY = headerCount; hasParsableInformation = true; //logger.info("frac y found in col: " + atomFractY); } else if (line.StartsWith("_atom_site_fract_z")) { atomFractZ = headerCount; hasParsableInformation = true; //logger.info("frac z found in col: " + atomFractZ); } else if (line.Equals("_atom_site.Cartn_x")) { atomRealX = headerCount; hasParsableInformation = true; //logger.info("cart x found in col: " + atomRealX); } else if (line.Equals("_atom_site.Cartn_y")) { atomRealY = headerCount; hasParsableInformation = true; //logger.info("cart y found in col: " + atomRealY); } else if (line.Equals("_atom_site.Cartn_z")) { atomRealZ = headerCount; hasParsableInformation = true; //logger.info("cart z found in col: " + atomRealZ); } else if (line.Equals("_atom_site.type_symbol")) { atomSymbol = headerCount; hasParsableInformation = true; //logger.info("type_symbol found in col: " + atomSymbol); } else { //logger.warn("Ignoring atom loop block field: " + line); } line = input.ReadLine().Trim(); } if (hasParsableInformation == false) { //logger.info("No parsable info found"); skipUntilEmptyOrCommentLine(line); } else { // now that headers are parsed, read the data while (line != null && line.Length > 0 && line[0] != '#') { //logger.debug("new row"); SupportClass.Tokenizer tokenizer = new SupportClass.Tokenizer(line); if (tokenizer.Count < headerCount) { //logger.warn("Column count mismatch; assuming continued on next line"); //logger.debug("Found #expected, #found: " + headerCount + ", " + tokenizer.Count); tokenizer = new SupportClass.Tokenizer(line + input.ReadLine()); } int colIndex = 0; // process one row IAtom atom = crystal.Builder.newAtom("C"); Point3d frac = new Point3d(); Point3d real = new Point3d(); bool hasFractional = false; bool hasCartesian = false; while (tokenizer.HasMoreTokens()) { colIndex++; System.String field = tokenizer.NextToken(); //logger.debug("Parsing col,token: " + colIndex + "=" + field); if (colIndex == atomLabel) { if (atomSymbol == -1) { // no atom symbol found, use label System.String element = extractFirstLetters(field); atom.Symbol = element; } atom.ID = field; } else if (colIndex == atomFractX) { hasFractional = true; frac.x = parseIntoDouble(field); } else if (colIndex == atomFractY) { hasFractional = true; frac.y = parseIntoDouble(field); } else if (colIndex == atomFractZ) { hasFractional = true; frac.z = parseIntoDouble(field); } else if (colIndex == atomSymbol) { atom.Symbol = field; } else if (colIndex == atomRealX) { hasCartesian = true; //logger.debug("Adding x3: " + parseIntoDouble(field)); real.x = parseIntoDouble(field); } else if (colIndex == atomRealY) { hasCartesian = true; //logger.debug("Adding y3: " + parseIntoDouble(field)); real.y = parseIntoDouble(field); } else if (colIndex == atomRealZ) { hasCartesian = true; //logger.debug("Adding x3: " + parseIntoDouble(field)); real.z = parseIntoDouble(field); } } if (hasCartesian) { Vector3d a = crystal.A; Vector3d b = crystal.B; Vector3d c = crystal.C; frac = CrystalGeometryTools.cartesianToFractional(a, b, c, real); atom.setFractionalPoint3d(frac); } if (hasFractional) { atom.setFractionalPoint3d(frac); } //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Object.toString' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" //logger.debug("Adding atom: " + atom); crystal.addAtom(atom); // look up next row line = input.ReadLine().Trim(); } } }
/// <summary> Computes the L-infinite distance between this point and /// point p1. The L-infinite distance is equal to /// MAX[abs(x1-x2), abs(y1-y2), abs(z1-z2)]. /// </summary> /// <param name="p1">the other point /// </param> /// <returns> the L-infinite distance /// </returns> public double distanceLinf(Point3d p1) { double tmp; tmp = System.Math.Max(System.Math.Abs(this.x - p1.x), System.Math.Abs(this.y - p1.y)); return System.Math.Max(tmp, System.Math.Abs(this.z - p1.z)); }
public virtual IPseudoAtom newPseudoAtom(String label, Point3d point3d) { return new PseudoAtom(label, point3d); }
/// <summary> Constructs and initializes a Point3d from the specified Point3d.</summary> /// <param name="p1">the Point3d containing the initialization x y z data /// </param> public Point3d(Point3d p1):base(p1) { }
/// <summary> Returns the geometric center of all the atoms in this atomContainer. /// See comment for center(IAtomContainer atomCon, Dimension areaDim, HashMap renderingCoordinates) for details on coordinate sets /// /// </summary> /// <param name="ac"> Description of the Parameter /// </param> /// <returns> the geometric center of the atoms in this atomContainer /// </returns> public static Point3d get3DCenter(IAtomContainer ac) { double centerX = 0; double centerY = 0; double centerZ = 0; double counter = 0; IAtom[] atoms = ac.Atoms; for (int i = 0; i < atoms.Length; i++) { if (atoms[i].getPoint3d() != null) { centerX += atoms[i].getPoint3d().x; centerY += atoms[i].getPoint3d().y; centerZ += atoms[i].getPoint3d().z; counter++; } } Point3d point = new Point3d(centerX / (counter), centerY / (counter), centerZ / (counter)); return point; }
/// <summary> Returns the square of the distance between this point and point p1.</summary> /// <param name="p1">the other point /// </param> /// <returns> the square of the distance /// </returns> public double distanceSquared(Point3d p1) { double dx, dy, dz; dx = this.x - p1.x; dy = this.y - p1.y; dz = this.z - p1.z; return (dx * dx + dy * dy + dz * dz); }
/// <summary> Normalizes a point. /// /// </summary> /// <param name="point">The point to normalize /// </param> public static void normalize(Point3d point) { double sum = System.Math.Sqrt(point.x * point.x + point.y * point.y + point.z * point.z); point.x = point.x / sum; point.y = point.y / sum; point.z = point.z / sum; }
public PDBAtom(System.String symbol, Point3d coordinate) : base(symbol, coordinate) { initValues(); }
/// <summary> Constructs an Atom from an Element and a Point3d. /// /// </summary> /// <param name="elementSymbol"> The symbol of the atom /// </param> /// <param name="point3d"> The 3D coordinates of the atom /// </param> public Atom(System.String elementSymbol, javax.vecmath.Point3d point3d) : this(elementSymbol) { this.point3d = point3d; }
/// <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; }
/// <summary> Sets a point specifying the location of this /// atom in a Crystal unit cell. /// /// </summary> /// <param name="point3d"> A point in a 3d fractional unit cell space /// /// </param> /// <seealso cref="getFractionalPoint3d"> /// </seealso> /// <seealso cref="org.openscience.cdk.Crystal"> /// </seealso> public virtual void setFractionalPoint3d(javax.vecmath.Point3d point3d) { this.fractionalPoint3d = point3d; notifyChanged(); }
/// <summary> Constructs an Atom from a String containing an element symbol. /// /// </summary> /// <param name="elementSymbol"> The String describing the element for the Atom /// </param> public Atom(System.String elementSymbol) : base(elementSymbol) { this.fractionalPoint3d = null; this.point3d = null; this.point2d = null; }