Class Grid


  • public class Grid
    extends Object
    A grid to be used for calculating atom contacts through a spatial hashing algorithm.

    The grid is composed of cells of size of the cutoff so that the distances that need to be calculated are reduced to those within each cell and to the neighbouring cells.

    Usage, for generic 3D points:

      Point3d[] points = ...;
      Grid grid = new Grid(8.0);
      grid.addCoords(points);
      List<Contact> contacts = getIndicesContacts();
     
    Usage, for atoms:
      Atom[] atoms = ...;
      Grid grid = new Grid(8.0);
      grid.addCoords(atoms);
      AtomContactSet contacts = getAtomContacts();
     
    Author:
    Jose Duarte
    • Constructor Detail

      • Grid

        public Grid​(double cutoff)
        Creates a Grid, the cutoff is in the same units as the coordinates (Angstroms if they are atom coordinates) and can be specified to a precision of 0.01.
        Parameters:
        cutoff -
    • Method Detail

      • addAtoms

        public void addAtoms​(Atom[] iAtoms,
                             Atom[] jAtoms)
        Adds the i and j atoms and fills the grid. Their bounds will be computed. Subsequent call to getIndicesContacts() or getAtomContacts() will produce the interatomic contacts.
        Parameters:
        iAtoms -
        jAtoms -
      • addAtoms

        public void addAtoms​(Atom[] iAtoms,
                             BoundingBox icoordbounds,
                             Atom[] jAtoms,
                             BoundingBox jcoordbounds)
        Adds the i and j atoms and fills the grid, passing their bounds (array of size 6 with x,y,z minima and x,y,z maxima) This way the bounds don't need to be recomputed. Subsequent call to getIndicesContacts() or getAtomContacts() will produce the interatomic contacts.
        Parameters:
        iAtoms -
        icoordbounds -
        jAtoms -
        jcoordbounds -
      • addAtoms

        public void addAtoms​(Atom[] atoms)
        Adds a set of atoms, subsequent call to getIndicesContacts() or getAtomContacts() will produce the interatomic contacts. The bounding box of the atoms will be computed based on input array
        Parameters:
        atoms -
      • addCoords

        public void addCoords​(javax.vecmath.Point3d[] iAtoms,
                              javax.vecmath.Point3d[] jAtoms)
        Adds the i and j coordinates and fills the grid. Their bounds will be computed. Subsequent call to getIndicesContacts() will produce the contacts, i.e. the set of points within distance cutoff. Subsequent calls to method getAtomContacts() will produce a NullPointerException since this only adds coordinates and no atom information.
        Parameters:
        iAtoms -
        jAtoms -
      • addCoords

        public void addCoords​(javax.vecmath.Point3d[] iAtoms,
                              BoundingBox icoordbounds,
                              javax.vecmath.Point3d[] jAtoms,
                              BoundingBox jcoordbounds)
        Adds the i and j coordinates and fills the grid, passing their bounds (array of size 6 with x,y,z minima and x,y,z maxima) This way the bounds don't need to be recomputed. Subsequent call to getIndicesContacts() will produce the contacts, i.e. the set of points within distance cutoff. Subsequent calls to method getAtomContacts() will produce a NullPointerException since this only adds coordinates and no atom information.
        Parameters:
        iAtoms -
        icoordbounds -
        jAtoms -
        jcoordbounds -
      • addCoords

        public void addCoords​(javax.vecmath.Point3d[] atoms)
        Adds a set of coordinates, subsequent call to getIndicesContacts() will produce the contacts, i.e. the set of points within distance cutoff. The bounding box of the atoms will be computed based on input array. Subsequent calls to method getAtomContacts() will produce a NullPointerException since this only adds coordinates and no atom information.
        Parameters:
        atoms -
      • addCoords

        public void addCoords​(javax.vecmath.Point3d[] atoms,
                              BoundingBox bounds)
        Adds a set of coordinates, subsequent call to getIndicesContacts() will produce the contacts, i.e. the set of points within distance cutoff. The bounds calculated elsewhere can be passed, or if null they are computed. Subsequent calls to method getAtomContacts() will produce a NullPointerException since this only adds coordinates and no atom information.
        Parameters:
        atoms -
        bounds -
      • getAtomContacts

        public AtomContactSet getAtomContacts()
        Returns all contacts, i.e. all atoms that are within the cutoff distance. If both iAtoms and jAtoms are defined then contacts are between iAtoms and jAtoms, if jAtoms is null, then contacts are within the iAtoms.
        Returns:
      • getContacts

        @Deprecated
        public AtomContactSet getContacts()
        Deprecated.
        use getAtomContacts() instead
        Returns all contacts, i.e. all atoms that are within the cutoff distance. If both iAtoms and jAtoms are defined then contacts are between iAtoms and jAtoms, if jAtoms is null, then contacts are within the iAtoms.
        Returns:
      • getIndicesContacts

        public List<ContactgetIndicesContacts()
        Returns all contacts, i.e. all atoms that are within the cutoff distance, as simple Contact objects containing the atom indices pairs and the distance. If both iAtoms and jAtoms are defined then contacts are between iAtoms and jAtoms, if jAtoms is null, then contacts are within the iAtoms.
        Returns:
      • hasAnyContact

        public boolean hasAnyContact​(javax.vecmath.Point3d[] atoms)
        Fast determination of whether any atoms from a given set fall within the cutoff of iAtoms. If addAtoms(Atom[], Atom[]) was called with two sets of atoms, contacts to either set are considered.
        Parameters:
        atoms -
        Returns:
      • isNoOverlap

        public boolean isNoOverlap()
        Tells whether (after having added atoms to grid) the i and j grids are not overlapping. Overlap is defined as enclosing bounds of the 2 grids being no more than one cell size apart.
        Returns:
        true if the 2 grids don't overlap, false if they do
      • getIAtoms

        protected javax.vecmath.Point3d[] getIAtoms()
      • getJAtoms

        protected javax.vecmath.Point3d[] getJAtoms()