Skip to content
Prev Previous commit
Next Next commit
Supporting neighbors with and without SH
  • Loading branch information
josemduarte committed Jan 2, 2019
commit 3b99afd899a668036e5a6f4eccf1a673a9198da0
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ public void run() {
private double cons;
private List<Contact> contacts;

private boolean useSpatialHashingForNeighbors;

/**
* Constructs a new AsaCalculator. Subsequently call {@link #calculateAsas()}
* or {@link #getGroupAsas()} to calculate the ASAs
Expand All @@ -122,6 +124,8 @@ public AsaCalculator(Structure structure, double probe, int nSpherePoints, int n
this.probe = probe;
this.nThreads = nThreads;

this.useSpatialHashingForNeighbors = true;

// initialising the radii by looking them up through AtomRadii
radii = new double[atomCoords.length];
for (int i=0;i<atomCoords.length;i++) {
Expand Down Expand Up @@ -150,6 +154,8 @@ public AsaCalculator(Atom[] atoms, double probe, int nSpherePoints, int nThreads
this.probe = probe;
this.nThreads = nThreads;

this.useSpatialHashingForNeighbors = true;

for (Atom atom:atoms) {
if (atom.getElement()==Element.H)
throw new IllegalArgumentException("Can't calculate ASA for an array that contains Hydrogen atoms ");
Expand Down Expand Up @@ -190,6 +196,8 @@ public AsaCalculator(Point3d[] atomCoords, double probe, int nSpherePoints, int
this.probe = probe;
this.nThreads = nThreads;

this.useSpatialHashingForNeighbors = true;

// initialising the radii to the given radius for all atoms
radii = new double[atomCoords.length];
for (int i=0;i<atomCoords.length;i++) {
Expand Down Expand Up @@ -299,6 +307,10 @@ public double[] calculateAsas() {
return asas;
}

public void setUseSpatialHashingForNeighbors(boolean useSpatialHashingForNeighbors) {
this.useSpatialHashingForNeighbors = useSpatialHashingForNeighbors;
}

/**
* Returns list of 3d coordinates of points on a sphere using the
* Golden Section Spiral algorithm.
Expand Down Expand Up @@ -408,7 +420,12 @@ private static double maxValue(double[] array) {

private double calcSingleAsa(int i) {
Point3d atom_i = atomCoords[i];
Integer[] neighbor_indices = findNeighborIndicesSpatialHashing(i);
Integer[] neighbor_indices;
if (useSpatialHashingForNeighbors) {
neighbor_indices = findNeighborIndicesSpatialHashing(i);
} else {
neighbor_indices = findNeighborIndices(i);
}
int n_neighbor = neighbor_indices.length;
int j_closest_neighbor = 0;
double radius = probe + radii[i];
Expand Down