Esempio n. 1
0
  /**
   * add two atoms ( a + b).
   *
   * @param a an Atom object
   * @param b an Atom object
   * @return an Atom object
   */
  public static final Atom add(Atom a, Atom b) {
    double[] coords = new double[3];

    coords[0] = a.getX() + b.getX();
    coords[1] = a.getY() + b.getY();
    coords[2] = a.getZ() + b.getZ();

    Atom c = new AtomImpl();
    c.setCoords(coords);
    return c;
  }
Esempio n. 2
0
  /**
   * calculate distance between two atoms.
   *
   * @param a an Atom object
   * @param b an Atom object
   * @return a double
   * @throws StructureException ...
   */
  public static final double getDistance(Atom a, Atom b) throws StructureException {
    double x = a.getX() - b.getX();
    double y = a.getY() - b.getY();
    double z = a.getZ() - b.getZ();

    double s = x * x + y * y + z * z;

    double dist = Math.sqrt(s);

    return dist;
  }
Esempio n. 3
0
  /**
   * substract two atoms ( a - b).
   *
   * @param a an Atom object
   * @param b an Atom object
   * @return an Atom object
   * @throws StructureException ...
   */
  public static final Atom substract(Atom a, Atom b) throws StructureException {
    nullCheck(a);
    nullCheck(b);

    double[] coords = new double[3];

    coords[0] = a.getX() - b.getX();
    coords[1] = a.getY() - b.getY();
    coords[2] = a.getZ() - b.getZ();

    Atom c = new AtomImpl();
    c.setCoords(coords);
    return c;
  }
Esempio n. 4
0
  /**
   * Shift a vector.
   *
   * @param a vector a
   * @param b vector b
   */
  public static final void shift(Atom a, Atom b) {

    Atom natom = add(a, b);
    double x = natom.getX();
    double y = natom.getY();
    double z = natom.getZ();
    a.setX(x);
    a.setY(y);
    a.setZ(z);
  }
Esempio n. 5
0
  /**
   * Returns the Vector that needs to be applied to shift a set of atoms to the Centroid, if the
   * centroid is already known
   *
   * @param atomSet array of Atoms
   * @return the vector needed to shift the set of atoms to its geometric center
   */
  public static final Atom getCenterVector(Atom[] atomSet, Atom centroid) {

    double[] coords = new double[3];
    coords[0] = 0 - centroid.getX();
    coords[1] = 0 - centroid.getY();
    coords[2] = 0 - centroid.getZ();

    Atom shiftVec = new AtomImpl();
    shiftVec.setCoords(coords);
    return shiftVec;
  }
Esempio n. 6
0
  /**
   * return the unit vector of vector a .
   *
   * @param a an Atom object
   * @return an Atom object
   */
  public static final Atom unitVector(Atom a) {
    double amount = amount(a);
    Atom U = a;

    double[] coords = new double[3];

    coords[0] = a.getX() / amount;
    coords[1] = a.getY() / amount;
    coords[2] = a.getZ() / amount;

    U.setCoords(coords);
    return U;
  }
Esempio n. 7
0
  /**
   * Rotate an atom around a Matrix object.
   *
   * @param atom atom to be rotated
   * @param m rotation matrix to be applied to the atom
   */
  public static final void rotate(Atom atom, Matrix m) {

    double x = atom.getX();
    double y = atom.getY();
    double z = atom.getZ();
    double[][] ad = new double[][] {{x, y, z}};

    Matrix am = new Matrix(ad);
    Matrix na = am.times(m);

    double[] coords = new double[3];
    coords[0] = na.get(0, 0);
    coords[1] = na.get(0, 1);
    coords[2] = na.get(0, 2);
    atom.setCoords(coords);
  }
Esempio n. 8
0
  /**
   * Shift a Group with a vector.
   *
   * @param group a group object
   * @param a an Atom object representing a shift vector
   */
  public static final void shift(Group group, Atom a) {

    AtomIterator iter = new AtomIterator(group);
    while (iter.hasNext()) {
      Atom atom = null;

      atom = (Atom) iter.next();

      Atom natom = add(atom, a);
      double x = natom.getX();
      double y = natom.getY();
      double z = natom.getZ();
      atom.setX(x);
      atom.setY(y);
      atom.setZ(z);
    }
  }
Esempio n. 9
0
  /**
   * rotate a single atom aroud a rotation matrix. matrix must be a 3x3 matrix.
   *
   * @param atom atom to be rotated
   * @param m a rotation matrix represented as a double[3][3] array
   */
  public static final void rotate(Atom atom, double[][] m) {

    double x = atom.getX();
    double y = atom.getY();
    double z = atom.getZ();

    double nx = m[0][0] * x + m[0][1] * y + m[0][2] * z;
    double ny = m[1][0] * x + m[1][1] * y + m[1][2] * z;
    double nz = m[2][0] * x + m[2][1] * y + m[2][2] * z;

    double[] coords = new double[3];
    coords[0] = nx;
    coords[1] = ny;
    coords[2] = nz;

    atom.setCoords(coords);
  }
Esempio n. 10
0
  /**
   * calculate structure + Matrix coodinates ...
   *
   * @param s the structure to operate on
   * @param matrix a Matrix object
   */
  public static final void plus(Structure s, Matrix matrix) {
    AtomIterator iter = new AtomIterator(s);
    Atom oldAtom = null;
    Atom rotOldAtom = null;
    while (iter.hasNext()) {
      Atom atom = null;

      atom = (Atom) iter.next();
      try {
        if (oldAtom != null) {
          // System.out.println("before " +getDistance(oldAtom,atom));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      oldAtom = (Atom) atom.clone();

      double x = atom.getX();
      double y = atom.getY();
      double z = atom.getZ();
      double[][] ad = new double[][] {{x, y, z}};

      Matrix am = new Matrix(ad);
      Matrix na = am.plus(matrix);

      double[] coords = new double[3];
      coords[0] = na.get(0, 0);
      coords[1] = na.get(0, 1);
      coords[2] = na.get(0, 2);
      atom.setCoords(coords);
      try {
        if (rotOldAtom != null) {
          // System.out.println("after " + getDistance(rotOldAtom,atom));
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
      rotOldAtom = (Atom) atom.clone();
    }
  }
Esempio n. 11
0
  /**
   * Returns the center of mass of the set of atoms.
   *
   * @param atomSet a set of Atoms
   * @return an Atom representing the Centroid of the set of atoms
   */
  public static final Atom getCentroid(Atom[] atomSet) {

    double[] coords = new double[3];

    coords[0] = 0;
    coords[1] = 0;
    coords[2] = 0;

    for (int i = 0; i < atomSet.length; i++) {
      Atom a = atomSet[i];
      coords[0] += a.getX();
      coords[1] += a.getY();
      coords[2] += a.getZ();
    }

    int n = atomSet.length;
    coords[0] = coords[0] / n;
    coords[1] = coords[1] / n;
    coords[2] = coords[2] / n;

    Atom vec = new AtomImpl();
    vec.setCoords(coords);
    return vec;
  }
Esempio n. 12
0
 /**
  * skalar product.
  *
  * @param a an Atom object
  * @param b an Atom object
  * @return a double
  */
 public static final double skalarProduct(Atom a, Atom b) {
   double skalar;
   skalar = a.getX() * b.getX() + a.getY() * b.getY() + a.getZ() * b.getZ();
   return skalar;
 }