|
20 | 20 | */ |
21 | 21 | package org.biojava.nbio.structure.asa; |
22 | 22 |
|
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.*; |
26 | 24 | import org.biojava.nbio.structure.io.mmcif.ChemCompGroupFactory; |
27 | 25 | import org.biojava.nbio.structure.io.mmcif.DownloadChemCompProvider; |
28 | 26 | import static org.junit.Assert.*; |
| 27 | + |
29 | 28 | import org.junit.Test; |
30 | 29 |
|
31 | 30 | import java.io.IOException; |
|
36 | 35 | * Testing of Accessible Surface Area calculations |
37 | 36 | * |
38 | 37 | * |
39 | | - * @author duarte_j |
| 38 | + * @author Jose Duarte |
40 | 39 | * |
41 | 40 | */ |
42 | 41 | public class TestAsaCalc { |
@@ -133,4 +132,58 @@ public void testNeighborIndicesFinding() throws StructureException, IOException |
133 | 132 | } |
134 | 133 |
|
135 | 134 | } |
| 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 | + } |
136 | 189 | } |
0 commit comments