org.biojava.nbio.structure.contact.GridCell Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of biojava-structure Show documentation
Show all versions of biojava-structure Show documentation
The protein structure modules of BioJava.
/*
* BioJava development code
*
* This code may be freely distributed and modified under the
* terms of the GNU Lesser General Public Licence. This should
* be distributed with the code. If you do not have a copy,
* see:
*
* http://www.gnu.org/copyleft/lesser.html
*
* Copyright for this code is held jointly by the individual
* authors. These should be listed in @author doc comments.
*
* For more information on the BioJava project and its aims,
* or to join the biojava-l mailing list, visit the home page
* at:
*
* http://www.biojava.org/
*
*/
package org.biojava.nbio.structure.contact;
import java.util.ArrayList;
import java.util.List;
import javax.vecmath.Point3d;
/**
* A grid cell to be used in contact calculation via spatial hashing algorithm.
*
* @author Jose Duarte
*
*/
public class GridCell {
private Grid grid;
private ArrayList iIndices;
private ArrayList jIndices;
public GridCell(Grid parent){
iIndices = new ArrayList<>();
jIndices = new ArrayList<>();
this.grid = parent;
}
public void addIindex(int serial){
iIndices.add(serial);
}
public void addJindex(int serial){
jIndices.add(serial);
}
public int getNumIindices() {
return iIndices.size();
}
public int getNumJindices() {
return jIndices.size();
}
/**
* Calculates all distances of atoms within this cell returning those that are within the given cutoff
* as a list of Contacts containing the indices of the pair and the calculated distance.
*
* If {@link Grid#getJAtoms()} is null, distances are within the iAtoms only
* @return
*/
public List getContactsWithinCell(){
List contacts = new ArrayList<>();
Point3d[] iAtoms = grid.getIAtoms();
Point3d[] jAtoms = grid.getJAtoms();
double cutoff = grid.getCutoff();
if (jAtoms==null) {
for (int i:iIndices) {
for (int j:iIndices) {
if (j>i) {
double distance = iAtoms[i].distance(iAtoms[j]);
if (distance getContactsToOtherCell(GridCell otherCell){
List contacts = new ArrayList<>();
Point3d[] iAtoms = grid.getIAtoms();
Point3d[] jAtoms = grid.getJAtoms();
double cutoff = grid.getCutoff();
if (jAtoms==null) {
for (int i:iIndices) {
for (int j:otherCell.iIndices) {
if (j>i) {
double distance = iAtoms[i].distance(iAtoms[j]);
if (distance