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-2025.
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.algorithms.groovy;
39  
40  import ffx.algorithms.misc.AlgorithmsTest;
41  import org.junit.Test;
42  
43  import static org.junit.Assert.assertEquals;
44  
45  /**
46   * Tests many body optimization and the many body groovy script under global, box and monte carlo
47   * parameter conditions.
48   *
49   * @author Mallory R. Tollefson
50   */
51  public class ManyBodyTest extends AlgorithmsTest {
52  
53    /**
54     * Tests ManyBody.groovy and RotamerOptimization.java by running a box optimization simulation on a
55     * small pdb file.
56     */
57    @Test
58    public void testManyBodyBoxOptimization() {
59      // Set-up the input arguments for the script.
60      String[] args = {
61          "-a", "5",
62          "-L", "2",
63          "--bL", "10",
64          "--bB", "2",
65          "--tC", "2",
66          "--pr", "2",
67          getResourcePath("5awl.pdb")
68      };
69      binding.setVariable("args", args);
70      binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
71  
72      // Evaluate the script.
73      ManyBody manyBody = new ManyBody(binding).run();
74      algorithmsScript = manyBody;
75  
76      double expectedTotalPotential = -230.1392872420811;
77      double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
78      assertEquals(expectedTotalPotential, actualTotalPotential, 1E-7);
79  
80      double expectedApproximateEnergy = -225.97693128995238;
81      double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
82      assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-7);
83    }
84  
85    /**
86     * Tests the restart file functionality for box optimization. The test applies a 1.5 angstrom
87     * 2-body and 3-body cutoff but the restart file was generated using 2-body and 3-body cutoffs of 2
88     * angstroms.
89     */
90    @Test
91    public void testManyBodyBoxRestart() {
92      // Set-up the input arguments for the script.
93      String[] args = {
94          "-a", "5",
95          "--bL", "10",
96          "--tC", "1.5",
97          "-T", "--thC",
98          "1.5", "--eR",
99          getResourcePath("5awl.box.restart"),
100         getResourcePath("5awl.pdb")
101     };
102     binding.setVariable("args", args);
103     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
104 
105     // Evaluate the script.
106     ManyBody manyBody = new ManyBody(binding).run();
107     algorithmsScript = manyBody;
108 
109     double expectedTotalPotential = -230.13928724208006; //-221.48751140045158
110     double actualTotalPotential =
111         manyBody.getPotential().getTotalEnergy();
112     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-7);
113 
114     double expectedApproximateEnergy = -230.88286802981403;
115     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
116     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-7);
117   }
118 
119   @Test
120   public void testManyBodyGlobal() {
121     // Set-up the input arguments for the script.
122     String[] args = {
123         "-a", "2", "-L", "2", "--tC", "2", getResourcePath("5awl.pdb")
124     };
125     binding.setVariable("args", args);
126     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
127 
128     // Evaluate the script.
129     ManyBody manyBody = new ManyBody(binding).run();
130     algorithmsScript = manyBody;
131 
132     // Evaluate the script.
133     manyBody.run();
134     double expectedTotalPotential = -230.1392865715949;
135     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
136     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
137 
138     double expectedApproximateEnergy = -216.57578192741352;
139     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
140     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
141 
142     // Delete restart file.
143     manyBody.getManyBodyOptions().getRestartFile().delete();
144   }
145 
146   @Test
147   public void testManyBodyHelp() {
148     // Set-up the input arguments for the Biotype script.
149     String[] args = {"-h"};
150     binding.setVariable("args", args);
151 
152     // Evaluate the script.
153     ManyBody manyBody = new ManyBody(binding).run();
154     algorithmsScript = manyBody;
155   }
156 
157   /**
158    * Tests ManyBody.groovy and RotamerOptimization.java by running a monte carlo optimization
159    * simulation on a small pdb file. Elimination criteria are not used during this test. A Monte
160    * Carlo search is done on the permutations.
161    */
162   @Test
163   public void testManyBodyMonteCarlo() {
164 
165     // These properties will be cleared automatically after the test.
166     System.setProperty("polarization", "direct");
167     System.setProperty("manybody-testing", "true");
168     System.setProperty("manybody-testing-mc", "true");
169 
170     // Set-up the input arguments for the script.
171     String[] args = {
172         "-a", "2",
173         "-L", "2",
174         "--tC", "2",
175         "--pr", "2",
176         "--mC", "100",
177         getResourcePath("5awl.pdb")
178     };
179     binding.setVariable("args", args);
180     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
181 
182     // Evaluate the script.
183     ManyBody manyBody = new ManyBody(binding);
184     algorithmsScript = manyBody;
185     manyBody.run();
186 
187     double expectedTotalPotential = -204.72742343060315;
188     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
189     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
190 
191     double expectedApproximateEnergy = -195.16120410395288;
192     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
193     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
194 
195     // Delete restart file.
196     manyBody.getManyBodyOptions().getRestartFile().delete();
197   }
198 
199   /**
200    * Tests the restart file functionality. The test applies a 1.5 angstrom 2-body and 3-body cutoff
201    * but the restart file was generated using 2-body and 3-body cutoffs of 2 angstroms.
202    */
203   @Test
204   public void testManyBodyRestart() {
205     // Set-up the input arguments for the script.
206     String[] args = {"-a", "2", "-L", "2", "--tC", "1.5", "-T", "--thC", "1.5", "--eR",
207         getResourcePath("5awl.test.restart"),
208         getResourcePath("5awl.pdb")
209     };
210     binding.setVariable("args", args);
211     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
212 
213     // Evaluate the script.
214     ManyBody manyBody = new ManyBody(binding).run();
215     algorithmsScript = manyBody;
216 
217     double expectedTotalPotential = -230.33490844427203;
218     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
219     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
220 
221     double expectedApproximateEnergy = -296.824576745933;
222     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
223     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
224   }
225 
226   @Test
227   public void testManyBodyTitration() {
228     // Set-up the input arguments for the script.
229     String[] args = {"--tR", "--pH", "7.0", "--eR",
230         getResourcePath("DEHK.rot.restart"),
231         getResourcePath("DEHK.rot.pdb")
232     };
233     binding.setVariable("args", args);
234     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
235 
236     // Evaluate the script.
237     ManyBody manyBody = new ManyBody(binding).run();
238     algorithmsScript = manyBody;
239 
240     double expectedTotalPotential = -321.72679980;
241     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
242     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
243 
244     double expectedApproximateEnergy = -227.523807;
245     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
246     //TODO: Adjust delta back to norm and determine why getApproximate() is returning funky values
247     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-0);
248   }
249 
250 }