View Javadoc
1   // ******************************************************************************
2   //
3   // Title:       Force Field X.
4   // Description: Force Field X - Software for Molecular Biophysics.
5   // Copyright:   Copyright (c) Michael J. Schnieders 2001-2024.
6   //
7   // This file is part of Force Field X.
8   //
9   // Force Field X is free software; you can redistribute it and/or modify it
10  // under the terms of the GNU General Public License version 3 as published by
11  // the Free Software Foundation.
12  //
13  // Force Field X is distributed in the hope that it will be useful, but WITHOUT
14  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16  // details.
17  //
18  // You should have received a copy of the GNU General Public License along with
19  // Force Field X; if not, write to the Free Software Foundation, Inc., 59 Temple
20  // Place, Suite 330, Boston, MA 02111-1307 USA
21  //
22  // Linking this library statically or dynamically with other modules is making a
23  // combined work based on this library. Thus, the terms and conditions of the
24  // GNU General Public License cover the whole combination.
25  //
26  // As a special exception, the copyright holders of this library give you
27  // permission to link this library with independent modules to produce an
28  // executable, regardless of the license terms of these independent modules, and
29  // to copy and distribute the resulting executable under terms of your choice,
30  // provided that you also meet, for each linked independent module, the terms
31  // and conditions of the license of that module. An independent module is a
32  // module which is not derived from or based on this library. If you modify this
33  // library, you may extend this exception to your version of the library, but
34  // you are not obligated to do so. If you do not wish to do so, delete this
35  // exception statement from your version.
36  //
37  // ******************************************************************************
38  package ffx.potential.groovy;
39  
40  import static org.apache.commons.math3.util.FastMath.floor;
41  import static org.apache.commons.math3.util.FastMath.random;
42  import static org.junit.Assert.assertEquals;
43  
44  import ffx.potential.groovy.test.Gradient;
45  import ffx.potential.utils.PotentialTest;
46  import org.junit.Test;
47  
48  /** JUnit Tests for the Volume Script */
49  public class VolumeTest extends PotentialTest {
50  
51    private final double tolerance = 0.001;
52  
53    /**
54     * Test Connolly molecular surface area and volume without hydrogen and a 1.4 A exclude radius.
55     */
56    @Test
57    public void testConnollyMolecularButane() {
58      // Configure input arguments for the Volume script.
59      String filepath = getResourcePath("butane.xyz");
60      String[] args = {"-c", "-p", "1.4", "-m", filepath};
61      binding.setVariable("args", args);
62      // Construct and evaluate the Volume script.
63      Volume volume = new Volume(binding).run();
64      potentialScript = volume;
65      assertEquals(79.85081214917432, volume.totalVolume, tolerance);
66      assertEquals(98.14422780202705, volume.totalSurfaceArea, tolerance);
67    }
68  
69    /** Test Connolly SEV & SASA with a 1.4 A exclude radius. */
70    @Test
71    public void testConnollyMolecularCrambin() {
72      // Configure input arguments for the Volume script.
73      String filepath = getResourcePath("crambin.xyz");
74      String[] args = {"-c", "-m", "-p", "1.4", filepath};
75      binding.setVariable("args", args);
76  
77      // Construct and evaluate the Volume script.
78      Volume volume = new Volume(binding).run();
79      potentialScript = volume;
80      assertEquals(5222.628196815338, volume.totalVolume, tolerance);
81      assertEquals(2326.375086471378, volume.totalSurfaceArea, tolerance);
82    }
83  
84    /**
85     * Test Connolly molecular surface area and volume without hydrogen and a 1.4 A exclude radius.
86     */
87    @Test
88    public void testConnollyMolecularEthylbenzene() {
89      // Configure input arguments for the Volume script.
90      String filepath = getResourcePath("ethylbenzene.xyz");
91      String[] args = {"-c", "-p", "1.4", "-m", filepath};
92      binding.setVariable("args", args);
93  
94      // Construct and evaluate the Volume script.
95      Volume volume = new Volume(binding).run();
96      potentialScript = volume;
97      assertEquals(126.96932864947797, volume.totalVolume, tolerance);
98      assertEquals(137.7753894764906, volume.totalSurfaceArea, tolerance);
99    }
100 
101   /**
102    * Test Connolly molecular surface area and volume without hydrogen and a 1.4 A exclude radius.
103    */
104   @Test
105   public void testConnollyMolecularHydrogenButane() {
106     // Configure input arguments for the Volume script.
107     String filepath = getResourcePath("butane.xyz");
108     String[] args = {"-c", "-p", "1.4", "-m", "-y", filepath};
109     binding.setVariable("args", args);
110 
111     // Construct and evaluate the Volume script.
112     Volume volume = new Volume(binding).run();
113     potentialScript = volume;
114     assertEquals(119.0512090546068, volume.totalVolume, tolerance);
115     assertEquals(132.598010667639, volume.totalSurfaceArea, tolerance);
116   }
117 
118   /** Test Connolly SEV & SASA with a 1.4 A exclude radius and hydrogen atoms. */
119   @Test
120   public void testConnollyMolecularHydrogenCrambin() {
121     // Configure input arguments for the Volume script.
122     String filepath = getResourcePath("crambin.xyz");
123     String[] args = {"-c", "-m", "-p", "1.4", "-y", filepath};
124     binding.setVariable("args", args);
125 
126     // Construct and evaluate the Volume script.
127     Volume volume = new Volume(binding).run();
128     potentialScript = volume;
129     assertEquals(5890.028072142157, volume.totalVolume, tolerance);
130     assertEquals(2456.835858765312, volume.totalSurfaceArea, tolerance);
131   }
132 
133   /** Test Connolly molecular surface area and volume with hydrogen and a 1.4 A exclude radius. */
134   @Test
135   public void testConnollyMolecularHydrogenEthylbenzene() {
136     // Configure input arguments for the Volume script.
137     String filepath = getResourcePath("ethylbenzene.xyz");
138     String[] args = {"-c", "-p", "1.4", "-m", "-y", filepath};
139     binding.setVariable("args", args);
140 
141     // Construct and evaluate the Volume script.
142     Volume volume = new Volume(binding).run();
143     potentialScript = volume;
144     assertEquals(165.83018235892447, volume.totalVolume, tolerance);
145     assertEquals(171.91980284282084, volume.totalSurfaceArea, tolerance);
146   }
147 
148   /** Test Connolly SEV & SASA without hydrogen and a 1.4 A exclude radius. */
149   @Test
150   public void testConnollySEVButane() {
151     // Configure input arguments for the Volume script.
152     String filepath = getResourcePath("butane.xyz");
153     String[] args = {"-c", "-p", "1.4", filepath};
154     binding.setVariable("args", args);
155 
156     // Construct and evaluate the Volume script.
157     Volume volume = new Volume(binding).run();
158     potentialScript = volume;
159     assertEquals(302.0524178356785, volume.totalVolume, tolerance);
160     assertEquals(227.49657650050898, volume.totalSurfaceArea, tolerance);
161   }
162 
163   /** Test Connolly SEV & SASA with a 1.4 A exclude radius. */
164   @Test
165   public void testConnollySEVCrambin() {
166     // Configure input arguments for the Volume script.
167     String filepath = getResourcePath("crambin.xyz");
168     String[] args = {"-c", "-p", "1.4", filepath};
169     binding.setVariable("args", args);
170 
171     // Construct and evaluate the Volume script.
172     Volume volume = new Volume(binding).run();
173     potentialScript = volume;
174     assertEquals(8956.620463626994, volume.totalVolume, tolerance);
175     assertEquals(3015.7687533888334, volume.totalSurfaceArea, tolerance);
176   }
177 
178   /** Test Connolly SEV & SASA without hydrogen and a 1.4 A exclude radius. */
179   @Test
180   public void testConnollySEVEthylbenzene() {
181     // Configure input arguments for the Volume script.
182     String filepath = getResourcePath("ethylbenzene.xyz");
183     String[] args = {"-c", "-p", "1.4", filepath};
184     binding.setVariable("args", args);
185 
186     // Construct and evaluate the Volume script.
187     Volume volume = new Volume(binding).run();
188     potentialScript = volume;
189     assertEquals(418.96380636214514, volume.totalVolume, tolerance);
190     assertEquals(287.56961427851286, volume.totalSurfaceArea, tolerance);
191   }
192 
193   /** Test Connolly SEV & SASA with hydrogen and a 1.4 A exclude radius. */
194   @Test
195   public void testConnollySEVHydrogenButane() {
196     // Configure input arguments for the Volume script.
197     String filepath = getResourcePath("butane.xyz");
198     String[] args = {"-c", "-p", "1.4", "-y", filepath};
199     binding.setVariable("args", args);
200 
201     // Construct and evaluate the Volume script.
202     Volume volume = new Volume(binding).run();
203     potentialScript = volume;
204     assertEquals(402.708673112844, volume.totalVolume, tolerance);
205     assertEquals(280.836964340470, volume.totalSurfaceArea, tolerance);
206   }
207 
208   /** Test Connolly SEV & SASA with a 1.4 A exclude radius and hydrogen atoms. */
209   @Test
210   public void testConnollySEVHydrogenCrambin() {
211     // Configure input arguments for the Volume script.
212     String filepath = getResourcePath("crambin.xyz");
213     String[] args = {"-c", "-p", "1.4", "-y", filepath};
214     binding.setVariable("args", args);
215 
216     // Construct and evaluate the Volume script.
217     Volume volume = new Volume(binding).run();
218     potentialScript = volume;
219     assertEquals(9804.262055253388, volume.totalVolume, tolerance);
220     assertEquals(3142.106787870207, volume.totalSurfaceArea, tolerance);
221   }
222 
223   /** Test Connolly SEV & SASA with hydrogen and a 1.4 A exclude radius. */
224   @Test
225   public void testConnollySEVHydrogenEthylbenzene() {
226     // Configure input arguments for the Volume script.
227     String filepath = getResourcePath("ethylbenzene.xyz");
228     String[] args = {"-c", "-p", "1.4", "-y", filepath};
229     binding.setVariable("args", args);
230 
231     // Construct and evaluate the Volume script.
232     Volume volume = new Volume(binding).run();
233     potentialScript = volume;
234     assertEquals(518.612603965319, volume.totalVolume, tolerance);
235     assertEquals(340.264998320387, volume.totalSurfaceArea, tolerance);
236   }
237 
238   /** Test Connolly SEV & SASA with hydrogen and a 1.4 A exclude radius. */
239   @Test
240   public void testConnollySEVHydrogenEthylbenzeneDerivatives() {
241     // Configure input arguments for the Gradient script.
242     String filepath = getResourcePath("ethylbenzene.xyz");
243     String[] args = {"--tol", "5.0e-2", filepath};
244     binding.setVariable("args", args);
245 
246     // Construct and evaluate the Gradient script
247     Gradient gradient = new Gradient(binding).run();
248     potentialScript = gradient;
249     assertEquals("Ethylbenzene gradient failures: ", 0, gradient.nFailures);
250   }
251 
252   /** Test Connolly vdW volume and surface area (probe radius = 0.0). */
253   @Test
254   public void testConnollyVDWCrambin() {
255     // Configure input arguments for the Volume script.
256     String filepath = getResourcePath("crambin.xyz");
257     String[] args = {"-c", "-p", "0.0", filepath};
258     binding.setVariable("args", args);
259 
260     // Construct and evaluate the Volume script.
261     Volume volume = new Volume(binding).run();
262     potentialScript = volume;
263     assertEquals(4418.303482563956, volume.totalVolume, tolerance);
264     assertEquals(4168.547763834282, volume.totalSurfaceArea, tolerance);
265   }
266 
267   /** Test GaussVol without hydrogen and a 0.4 A radii offset. */
268   @Test
269   public void testGaussVolButane() {
270     // Configure input arguments for the Volume script.
271     String filepath = getResourcePath("butane.xyz");
272     String[] args = {"-o", "0.4", filepath};
273     binding.setVariable("args", args);
274 
275     // Construct and evaluate the Volume script.
276     Volume volume = new Volume(binding).run();
277     potentialScript = volume;
278     assertEquals(125.5120767378517, volume.totalVolume, tolerance);
279     assertEquals(134.50524040566165, volume.totalSurfaceArea, tolerance);
280   }
281 
282   /** Test GaussVol without hydrogen and a 0.0 A radii offset. */
283   @Test
284   public void testGaussVolCrambin() {
285     // Configure input arguments for the Volume script.
286     String filepath = getResourcePath("crambin.xyz");
287     String[] args = {"-o", "0.0", filepath};
288     binding.setVariable("args", args);
289 
290     // Construct and evaluate the Volume script.
291     Volume volume = new Volume(binding).run();
292     potentialScript = volume;
293     assertEquals(4371.667466648112, volume.totalVolume, tolerance);
294     assertEquals(3971.0619085859435, volume.totalSurfaceArea, tolerance);
295   }
296 
297   /** Test GaussVol derivatives. */
298   @Test
299   public void testGaussVolCrambinDerivatives() {
300     // Configure input arguments for the Gradient script.
301     System.setProperty("gkterm", "true");
302     System.setProperty("cavmodel", "gauss-disp");
303     // Choose a random atom to test.
304     int atomID = (int) floor(random() * 642) + 1;
305     String filepath = getResourcePath("crambin.xyz");
306     String[] args = {"--ga", Integer.toString(atomID), filepath};
307     binding.setVariable("args", args);
308 
309     // Construct and evaluate the Gradient script
310     Gradient gradient = new Gradient(binding).run();
311     potentialScript = gradient;
312     assertEquals("Crambin gradient failures: ", 0, gradient.nFailures);
313   }
314 
315   /** Test GaussVol without hydrogen and a 0.4 A radii offset. */
316   @Test
317   public void testGaussVolEthylbenzene() {
318     // Configure input arguments for the Volume script.
319     String filepath = getResourcePath("ethylbenzene.xyz");
320     String[] args = {"-o", "0.4", filepath};
321     binding.setVariable("args", args);
322 
323     // Construct and evaluate the Volume script.
324     Volume volume = new Volume(binding).run();
325     potentialScript = volume;
326     assertEquals(194.44960348422916, volume.totalVolume, tolerance);
327     assertEquals(193.55314214639066, volume.totalSurfaceArea, tolerance);
328   }
329 
330   /** Test GaussVol derivatives. */
331   @Test
332   public void testGaussVolHydrogenEthylbenzeneDerivatives() {
333     // Configure input arguments for the Gradient script.
334     System.setProperty("gkterm", "true");
335     System.setProperty("cavmodel", "gauss-disp");
336     
337     String filepath = getResourcePath("ethylbenzene.xyz");
338     String[] args = {filepath};
339     binding.setVariable("args", args);
340 
341     // Construct and evaluate the Gradient script
342     Gradient gradient = new Gradient(binding).run();
343     potentialScript = gradient;
344     assertEquals("Ethylbenzene gradient failures: ", 0, gradient.nFailures);
345   }
346 }