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.algorithms.groovy;
39  
40  import static org.junit.Assert.assertEquals;
41  
42  import ffx.algorithms.misc.AlgorithmsTest;
43  import org.junit.Test;
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 = -221.0842558097416;
77      double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
78      assertEquals(expectedTotalPotential, actualTotalPotential, 1E-7);
79  
80      double expectedApproximateEnergy = -216.93107790352414;
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 = -221.0842558097416; //-221.48751140045158
110     double actualTotalPotential =
111         manyBody.getPotential().getTotalEnergy();
112     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-7);
113 
114     double expectedApproximateEnergy = -220.31899441275732;
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",
124         getResourcePath("5awl.pdb")
125     };
126     binding.setVariable("args", args);
127     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
128 
129     // Evaluate the script.
130     ManyBody manyBody = new ManyBody(binding).run();
131     algorithmsScript = manyBody;
132 
133     // Evaluate the script.
134     manyBody.run();
135     double expectedTotalPotential = -221.0842558097416;
136     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
137     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
138 
139     double expectedApproximateEnergy = -212.4798252638091;
140     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
141     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
142 
143     // Delete restart file.
144     manyBody.getManyBodyOptions().getRestartFile().delete();
145   }
146 
147   @Test
148   public void testManyBodyHelp() {
149     // Set-up the input arguments for the Biotype script.
150     String[] args = {"-h"};
151     binding.setVariable("args", args);
152 
153     // Evaluate the script.
154     ManyBody manyBody = new ManyBody(binding).run();
155     algorithmsScript = manyBody;
156   }
157 
158   /**
159    * Tests ManyBody.groovy and RotamerOptimization.java by running a monte carlo optimization
160    * simulation on a small pdb file. Elimination criteria are not used during this test. A Monte
161    * Carlo search is done on the permutations.
162    */
163   @Test
164   public void testManyBodyMonteCarlo() {
165 
166     // These properties will be cleared automatically after the test.
167     System.setProperty("polarization", "direct");
168     System.setProperty("manybody-testing", "true");
169     System.setProperty("manybody-testing-mc", "true");
170 
171     // Set-up the input arguments for the script.
172     String[] args = {
173         "-a", "2",
174         "-L", "2",
175         "--tC", "2",
176         "--pr", "2",
177         "--mC", "100",
178         getResourcePath("5awl.pdb")
179     };
180     binding.setVariable("args", args);
181     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
182 
183     // Evaluate the script.
184     ManyBody manyBody = new ManyBody(binding);
185     algorithmsScript = manyBody;
186     manyBody.run();
187 
188     double expectedTotalPotential = -204.72742343060315;
189     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
190     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
191 
192     double expectedApproximateEnergy = -195.16120410395288;
193     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
194     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
195 
196     // Delete restart file.
197     manyBody.getManyBodyOptions().getRestartFile().delete();
198   }
199 
200   /**
201    * Tests the restart file functionality. The test applies a 1.5 angstrom 2-body and 3-body cutoff
202    * but the restart file was generated using 2-body and 3-body cutoffs of 2 angstroms.
203    */
204   @Test
205   public void testManyBodyRestart() {
206     // Set-up the input arguments for the script.
207     String[] args = {"-a", "2", "-L", "2", "--tC", "1.5", "-T", "--thC", "1.5", "--eR",
208         getResourcePath("5awl.test.restart"),
209         getResourcePath("5awl.pdb")
210     };
211     binding.setVariable("args", args);
212     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
213 
214     // Evaluate the script.
215     ManyBody manyBody = new ManyBody(binding).run();
216     algorithmsScript = manyBody;
217 
218     double expectedTotalPotential = -220.14890239220347;
219     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
220     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
221 
222     double expectedApproximateEnergy = -290.57260490705966;
223     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
224     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-5);
225   }
226 
227   @Test
228   public void testManyBodyTitration() {
229     // Set-up the input arguments for the script.
230     String[] args = {"--pH","7.0","--eR",
231         getResourcePath("DEHK.rot.restart"),
232         getResourcePath("DEHK.rot.pdb")
233     };
234     binding.setVariable("args", args);
235     binding.setVariable("baseDir", registerTemporaryDirectory().toFile());
236 
237     // Evaluate the script.
238     ManyBody manyBody = new ManyBody(binding).run();
239     algorithmsScript = manyBody;
240 
241     double expectedTotalPotential = -93.18377835710643;
242     double actualTotalPotential = manyBody.getPotential().getTotalEnergy();
243     assertEquals(expectedTotalPotential, actualTotalPotential, 1E-5);
244 
245     double expectedApproximateEnergy = -179.5339377645139;
246     double actualApproximateEnergy = manyBody.getManyBodyOptions().getApproximate();
247     //TODO: Adjust delta back to norm and determine why getApproximate() is returning funky values
248     assertEquals(expectedApproximateEnergy, actualApproximateEnergy, 1E-0);
249   }
250 
251 }