|
31 | 31 |
|
32 | 32 |
|
33 | 33 | /** |
34 | | - * A grid to be used for calculating atom contacts through spatial hashing algorithm. |
35 | | - * |
| 34 | + * A grid to be used for calculating atom contacts through a spatial hashing algorithm. |
| 35 | + * <p> |
36 | 36 | * The grid is composed of cells of size of the cutoff so that the distances that need to be calculated |
37 | 37 | * are reduced to those within each cell and to the neighbouring cells. |
| 38 | + * <p> |
| 39 | + * Usage, for generic 3D points: |
| 40 | + * <pre> |
| 41 | + * Point3d[] points = ...; |
| 42 | + * Grid grid = new Grid(8.0); |
| 43 | + * grid.addCoords(points); |
| 44 | + * List<Contact> contacts = getIndicesContacts(); |
| 45 | + * </pre> |
| 46 | + * Usage, for atoms: |
| 47 | + * <pre> |
| 48 | + * Atom[] atoms = ...; |
| 49 | + * Grid grid = new Grid(8.0); |
| 50 | + * grid.addCoords(atoms); |
| 51 | + * AtomContactSet contacts = getAtomContacts(); |
| 52 | + * </pre> |
38 | 53 | * |
39 | 54 | * @author Jose Duarte |
40 | 55 | * |
@@ -67,8 +82,9 @@ public class Grid { |
67 | 82 | private boolean noOverlap; // if the 2 sets of atoms are found not to overlap then this is set to true |
68 | 83 |
|
69 | 84 | /** |
70 | | - * Creates a <code>Grid</code>, the cutoff is in Angstroms and can |
71 | | - * be specified to a precision of 0.01A |
| 85 | + * Creates a <code>Grid</code>, the cutoff is in the same units as the coordinates |
| 86 | + * (Angstroms if they are atom coordinates) and can |
| 87 | + * be specified to a precision of 0.01. |
72 | 88 | * @param cutoff |
73 | 89 | */ |
74 | 90 | public Grid(double cutoff) { |
@@ -170,6 +186,98 @@ public void addAtoms(Atom[] atoms, BoundingBox bounds) { |
170 | 186 |
|
171 | 187 | fillGrid(); |
172 | 188 | } |
| 189 | + |
| 190 | + /** |
| 191 | + * Adds the i and j coordinates and fills the grid. Their bounds will be computed. |
| 192 | + * Subsequent call to {@link #getIndicesContacts()} will produce the |
| 193 | + * contacts, i.e. the set of points within distance cutoff. |
| 194 | + * |
| 195 | + * Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException |
| 196 | + * since this only adds coordinates and no atom information. |
| 197 | + * @param iAtoms |
| 198 | + * @param jAtoms |
| 199 | + */ |
| 200 | + public void addCoords(Point3d[] iAtoms, Point3d[] jAtoms) { |
| 201 | + addCoords(iAtoms, null, jAtoms, null); |
| 202 | + } |
| 203 | + |
| 204 | + /** |
| 205 | + * 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) |
| 206 | + * This way the bounds don't need to be recomputed. |
| 207 | + * Subsequent call to {@link #getIndicesContacts()} will produce the |
| 208 | + * contacts, i.e. the set of points within distance cutoff. |
| 209 | + * |
| 210 | + * Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException |
| 211 | + * since this only adds coordinates and no atom information. |
| 212 | + * @param iAtoms |
| 213 | + * @param icoordbounds |
| 214 | + * @param jAtoms |
| 215 | + * @param jcoordbounds |
| 216 | + */ |
| 217 | + public void addCoords(Point3d[] iAtoms, BoundingBox icoordbounds, Point3d[] jAtoms, BoundingBox jcoordbounds) { |
| 218 | + this.iAtoms = iAtoms; |
| 219 | + this.iAtomObjects = null; |
| 220 | + |
| 221 | + if (icoordbounds!=null) { |
| 222 | + this.ibounds = icoordbounds; |
| 223 | + } else { |
| 224 | + this.ibounds = new BoundingBox(this.iAtoms); |
| 225 | + } |
| 226 | + |
| 227 | + this.jAtoms = jAtoms; |
| 228 | + this.jAtomObjects = null; |
| 229 | + |
| 230 | + if (jAtoms==iAtoms) { |
| 231 | + this.jbounds=ibounds; |
| 232 | + } else { |
| 233 | + if (jcoordbounds!=null) { |
| 234 | + this.jbounds = jcoordbounds; |
| 235 | + } else { |
| 236 | + this.jbounds = new BoundingBox(this.jAtoms); |
| 237 | + |
| 238 | + } |
| 239 | + } |
| 240 | + |
| 241 | + fillGrid(); |
| 242 | + } |
| 243 | + |
| 244 | + /** |
| 245 | + * Adds a set of coordinates, subsequent call to {@link #getIndicesContacts()} will produce the |
| 246 | + * contacts, i.e. the set of points within distance cutoff. |
| 247 | + * The bounding box of the atoms will be computed based on input array. |
| 248 | + * Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException |
| 249 | + * since this only adds coordinates and no atom information. |
| 250 | + * @param atoms |
| 251 | + */ |
| 252 | + public void addCoords(Point3d[] atoms) { |
| 253 | + addCoords(atoms, (BoundingBox) null); |
| 254 | + } |
| 255 | + |
| 256 | + /** |
| 257 | + * Adds a set of coordinates, subsequent call to {@link #getIndicesContacts()} will produce the |
| 258 | + * contacts, i.e. the set of points within distance cutoff. |
| 259 | + * The bounds calculated elsewhere can be passed, or if null they are computed. |
| 260 | + * Subsequent calls to method {@link #getAtomContacts()} will produce a NullPointerException |
| 261 | + * since this only adds coordinates and no atom information. |
| 262 | + * @param atoms |
| 263 | + * @param bounds |
| 264 | + */ |
| 265 | + public void addCoords(Point3d[] atoms, BoundingBox bounds) { |
| 266 | + this.iAtoms = atoms; |
| 267 | + this.iAtomObjects = null; |
| 268 | + |
| 269 | + if (bounds!=null) { |
| 270 | + this.ibounds = bounds; |
| 271 | + } else { |
| 272 | + this.ibounds = new BoundingBox(iAtoms); |
| 273 | + } |
| 274 | + |
| 275 | + this.jAtoms = null; |
| 276 | + this.jAtomObjects = null; |
| 277 | + this.jbounds = null; |
| 278 | + |
| 279 | + fillGrid(); |
| 280 | + } |
173 | 281 |
|
174 | 282 | /** |
175 | 283 | * Creates the grid based on the boundaries defined by all atoms given (iAtoms and jAtoms) |
|
0 commit comments