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.dynamics.MolecularDynamics;
43  import ffx.algorithms.misc.AlgorithmsTest;
44  import java.util.Arrays;
45  import java.util.Collection;
46  import org.junit.Test;
47  import org.junit.runner.RunWith;
48  import org.junit.runners.Parameterized;
49  import org.junit.runners.Parameterized.Parameters;
50  
51  /** @author Hernan V Bernabe */
52  @RunWith(Parameterized.class)
53  public class DynamicsStochasticTest extends AlgorithmsTest {
54  
55    private String info;
56    private String filename;
57    private double endKineticEnergy;
58    private double endPotentialEnergy;
59    private double endTotalEnergy;
60    private boolean testSeed;
61    private boolean testFriction00;
62    private boolean testFriction01;
63    private double tolerance = 0.1;
64  
65    public DynamicsStochasticTest(
66        String info,
67        String filename,
68        double endKineticEnergy,
69        double endPotentialEnergy,
70        double endTotalEnergy,
71        boolean testSeed,
72        boolean testFriction00,
73        boolean testFriction01) {
74  
75      this.info = info;
76      this.filename = filename;
77      this.endKineticEnergy = endKineticEnergy;
78      this.endPotentialEnergy = endPotentialEnergy;
79      this.endTotalEnergy = endTotalEnergy;
80      this.testSeed = testSeed;
81      this.testFriction00 = testFriction00;
82      this.testFriction01 = testFriction01;
83    }
84  
85    @Parameters
86    public static Collection<Object[]> data() {
87      return Arrays.asList(
88          new Object[][] {
89              {
90                  "Acetamide Peptide Restart and Stochastic Random Seed", // info
91                  "acetamide_res_stoch.xyz", // filename
92                  6.8546, // endKineticEnergy
93                  -26.9921, // endPotentialEnergy
94                  -20.1375, // endTotalEnergy
95                  true, // testSeed
96                  false, // testFriction00
97                  false, // testFriction01
98              },
99              {
100                 "Acetamide Peptide Restart, Stochastic Random Seed and Friction 0.0", // info
101                 "acetamide_res_stoch.xyz", // filename
102                 4.5625, // endKineticEnergy
103                 -29.8043, // endPotentialEnergy
104                 -25.2418, // endTotalEnergy
105                 false, // testSeed
106                 true, // testFriction00
107                 false // testFriction01
108             },
109             {
110                 "Acetamide Peptide Restart, Stochastic Random Seed and Friction 0.1", // info
111                 "acetamide_res_stoch.xyz", // filename
112                 4.5743, // endKineticEnergy
113                 -29.7373, // endPotentialEnergy
114                 -25.1630, // endTotalEnergy
115                 false, // testSeed
116                 false, // testFriction00
117                 true // testFriction01
118             }
119         });
120   }
121 
122   @Test
123   public void testDynamicsStochasticRandomSeed() {
124     if (!testSeed) {
125       return;
126     }
127 
128     // Set-up the input arguments for the script.
129     String[] args = {
130         "-n", "10",
131         "-t", "298.15",
132         "-i", "Stochastic",
133         "-b", "Adiabatic",
134         "-r", "0.001",
135         getResourcePath(filename)
136     };
137     binding.setVariable("args", args);
138 
139     // Construct and evaluate the script.
140     Dynamics dynamics = new Dynamics(binding).run();
141     algorithmsScript = dynamics;
142 
143     MolecularDynamics molDyn = dynamics.getMolecularDynamics();
144 
145     // Assert that the end energies are the same meaning that the Stochastic integrator works as
146     // intended.
147     assertEquals(
148         info + " Final kinetic energy", endKineticEnergy, molDyn.getKineticEnergy(), tolerance);
149     assertEquals(
150         info + " Final potential energy",
151         endPotentialEnergy,
152         molDyn.getPotentialEnergy(),
153         tolerance);
154     assertEquals(info + " Final total energy", endTotalEnergy, molDyn.getTotalEnergy(), tolerance);
155 
156   }
157 
158   @Test
159   public void testDynamicsStochasticRandomSeedFriction0() {
160 
161     if (!testFriction00) {
162       return;
163     }
164 
165     // Set-up the input arguments for the script.
166     String[] args = {
167         "-n", "10",
168         "-t", "298.15",
169         "-i", "Stochastic",
170         "-b", "Adiabatic",
171         "-r", "0.001",
172         getResourcePath(filename)
173     };
174     binding.setVariable("args", args);
175 
176     System.setProperty("friction", "0.0");
177 
178     // Construct and evaluate the script.
179     Dynamics dynamics = new Dynamics(binding).run();
180     algorithmsScript = dynamics;
181 
182     MolecularDynamics molDyn = dynamics.getMolecularDynamics();
183 
184     // Assert that the end energies are the same meaning that the Stochastic integrator works as
185     // intended with friciton 0.0 collisions/picosecond.
186     assertEquals(
187         info + " Final kinetic energy", endKineticEnergy, molDyn.getKineticEnergy(), tolerance);
188     assertEquals(
189         info + " Final potential energy",
190         endPotentialEnergy,
191         molDyn.getPotentialEnergy(),
192         tolerance);
193     assertEquals(info + " Final total energy", endTotalEnergy, molDyn.getTotalEnergy(), tolerance);
194   }
195 
196   @Test
197   public void testDynamicsStochasticRandomSeedFriction01() {
198 
199     if (!testFriction01) {
200       return;
201     }
202 
203     // Set-up the input arguments for the script.
204     String[] args = {
205         "-n", "10",
206         "-t", "298.15",
207         "-i", "Stochastic",
208         "-b", "Adiabatic",
209         "-r", "0.001",
210         getResourcePath(filename)
211     };
212     binding.setVariable("args", args);
213 
214     System.setProperty("friction", "0.1");
215 
216     // Construct and evaluate the script.
217     Dynamics dynamics = new Dynamics(binding).run();
218     algorithmsScript = dynamics;
219 
220     MolecularDynamics molDyn = dynamics.getMolecularDynamics();
221 
222     // Assert that the end energies are the same meaning that the Stochastic integrator works as
223     // intended with friciton 0.0 collisions/picosecond.
224     assertEquals(
225         info + " Final kinetic energy", endKineticEnergy, molDyn.getKineticEnergy(), tolerance);
226     assertEquals(
227         info + " Final potential energy",
228         endPotentialEnergy,
229         molDyn.getPotentialEnergy(),
230         tolerance);
231     assertEquals(info + " Final total energy", endTotalEnergy, molDyn.getTotalEnergy(), tolerance);
232   }
233 }