Skip to content

Commit a84609b

Browse files
committed
A test, demoing that SH actually performs much worse
1 parent 3b99afd commit a84609b

2 files changed

Lines changed: 62 additions & 7 deletions

File tree

biojava-structure/src/main/java/org/biojava/nbio/structure/asa/AsaCalculator.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ public class AsaCalculator {
5959
public static final double DEFAULT_PROBE_SIZE = 1.4;
6060
public static final int DEFAULT_NTHREADS = 1;
6161

62+
public static final boolean DEFAULT_USE_SPATIAL_HASHING = true;
63+
6264

6365

6466
// Chothia's amino acid atoms vdw radii
@@ -124,7 +126,7 @@ public AsaCalculator(Structure structure, double probe, int nSpherePoints, int n
124126
this.probe = probe;
125127
this.nThreads = nThreads;
126128

127-
this.useSpatialHashingForNeighbors = true;
129+
this.useSpatialHashingForNeighbors = DEFAULT_USE_SPATIAL_HASHING;
128130

129131
// initialising the radii by looking them up through AtomRadii
130132
radii = new double[atomCoords.length];
@@ -154,7 +156,7 @@ public AsaCalculator(Atom[] atoms, double probe, int nSpherePoints, int nThreads
154156
this.probe = probe;
155157
this.nThreads = nThreads;
156158

157-
this.useSpatialHashingForNeighbors = true;
159+
this.useSpatialHashingForNeighbors = DEFAULT_USE_SPATIAL_HASHING;
158160

159161
for (Atom atom:atoms) {
160162
if (atom.getElement()==Element.H)
@@ -196,7 +198,7 @@ public AsaCalculator(Point3d[] atomCoords, double probe, int nSpherePoints, int
196198
this.probe = probe;
197199
this.nThreads = nThreads;
198200

199-
this.useSpatialHashingForNeighbors = true;
201+
this.useSpatialHashingForNeighbors = DEFAULT_USE_SPATIAL_HASHING;
200202

201203
// initialising the radii to the given radius for all atoms
202204
radii = new double[atomCoords.length];

biojava-structure/src/test/java/org/biojava/nbio/structure/asa/TestAsaCalc.java

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020
*/
2121
package org.biojava.nbio.structure.asa;
2222

23-
import org.biojava.nbio.structure.Structure;
24-
import org.biojava.nbio.structure.StructureException;
25-
import org.biojava.nbio.structure.StructureIO;
23+
import org.biojava.nbio.structure.*;
2624
import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory;
2725
import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider;
2826
import static org.junit.Assert.*;
27+
2928
import org.junit.Test;
3029

3130
import java.io.IOException;
@@ -36,7 +35,7 @@
3635
* Testing of Accessible Surface Area calculations
3736
*
3837
*
39-
* @author duarte_j
38+
* @author Jose Duarte
4039
*
4140
*/
4241
public class TestAsaCalc {
@@ -133,4 +132,58 @@ public void testNeighborIndicesFinding() throws StructureException, IOException
133132
}
134133

135134
}
135+
136+
@Test
137+
public void testPerformance() throws StructureException, IOException {
138+
// important: without this the tests can fail when running in maven (but not in IDE)
139+
// that's because it depends on the order on how tests were run - JD 2018-03-10
140+
ChemCompGroupFactory.setChemCompProvider(new DownloadChemCompProvider());
141+
142+
Structure structure = StructureIO.getStructure("4F5X");
143+
Chain c = structure.getPolyChainByPDB("W");
144+
Atom[] atoms = StructureTools.getAllAtomArray(c);
145+
System.out.printf("Total of %d atoms\n", atoms.length);
146+
147+
int nThreads = 1;
148+
// 1. WITH SPATIAL HASHING
149+
150+
long start = System.currentTimeMillis();
151+
AsaCalculator asaCalc = new AsaCalculator(atoms,
152+
AsaCalculator.DEFAULT_PROBE_SIZE,
153+
100, nThreads);
154+
asaCalc.setUseSpatialHashingForNeighbors(true);
155+
156+
double[] asas = asaCalc.calculateAsas();
157+
long end = System.currentTimeMillis();
158+
System.out.printf("ASA calculation took %6.2f s with spatial hashing\n", (end-start)/1000.0);
159+
160+
double totAtoms = 0;
161+
for (double asa:asas) {
162+
totAtoms += asa;
163+
}
164+
double withSH = totAtoms;
165+
System.out.printf("Total ASA is %6.2f \n", totAtoms);
166+
167+
168+
// 2. WITHOUT SPATIAL HASHING
169+
start = System.currentTimeMillis();
170+
asaCalc = new AsaCalculator(atoms,
171+
AsaCalculator.DEFAULT_PROBE_SIZE,
172+
100, nThreads);
173+
asaCalc.setUseSpatialHashingForNeighbors(false);
174+
175+
asas = asaCalc.calculateAsas();
176+
end = System.currentTimeMillis();
177+
System.out.printf("ASA calculation took %6.2f s without spatial hashing\n", (end-start)/1000.0);
178+
179+
totAtoms = 0;
180+
for (double asa:asas) {
181+
totAtoms += asa;
182+
}
183+
double withoutSH = totAtoms;
184+
System.out.printf("Total ASA is %6.2f \n", totAtoms);
185+
186+
assertEquals(withoutSH, withSH, 0.000001);
187+
188+
}
136189
}

0 commit comments

Comments
 (0)