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.junit.Assert.assertEquals;
41  
42  import ffx.potential.utils.PotentialTest;
43  import ffx.potential.groovy.test.PhGradient;
44  import java.util.Arrays;
45  import java.util.Collection;
46  import java.util.Random;
47  import org.junit.Test;
48  import org.junit.runner.RunWith;
49  import org.junit.runners.Parameterized;
50  
51  /** JUnit Tests for the PhGradient Script */
52  
53  @RunWith(Parameterized.class)
54  public class PhGradientTest extends PotentialTest {
55  
56    private final String info;
57    private final String filename;
58    private final String filepath;
59    private final String key;
60    private final int nBonds;
61    private final int nAngles;
62    private final int nStretchBends;
63    private final int nUreyBradleys;
64    private final int nOutOfPlaneBends;
65    private final int nTorsions;
66    private final int nImproperTorsions;
67    private final int nPiOrbitalTorsions;
68    private final int nTorsionTorsions;
69    private final int nVanDerWaals;
70    private final int nPermanent;
71    private final int nPolar;
72    private final double bondEnergy;
73    private final double angleEnergy;
74    private final double stretchBendEnergy;
75    private final double ureyBradleyEnergy;
76    private final double outOfPlaneBendEnergy;
77    private final double torsionEnergy;
78    private final double improperTorsionEnergy;
79    private final double piOrbitalTorsionEnergy;
80    private final double torsionTorsionEnergy;
81    private final double vanDerWaalsEnergy;
82    private final double permanentEnergy;
83    private final double polarizationEnergy;
84    private final double discretizerEnergy;
85    private final double acidostatEnergy;
86    private final double extendedSystemBias;
87    private final double totalEnergy;
88    private final double tolerance = 1.0e-2;
89  
90    public PhGradientTest(
91        String info,
92        String filename,
93        String key,
94        double bondEnergy,
95        int nBonds,
96        double angleEnergy,
97        int nAngles,
98        double stretchBendEnergy,
99        int nStretchBends,
100       double ureyBradleyEnergy,
101       int nUreyBradleys,
102       double outOfPlaneBendEnergy,
103       int nOutOfPlaneBends,
104       double torsionEnergy,
105       int nTorsions,
106       double improperTorsionEnergy,
107       int nImproperTorsions,
108       double piOrbitalTorsionEnergy,
109       int nPiOrbitalTorsions,
110       double torsionTorsionEnergy,
111       int nTorsionTorsions,
112       double vanDerWaalsEnergy,
113       int nVanDerWaals,
114       double permanentEnergy,
115       int nPermanent,
116       double polarizationEnergy,
117       int nPolar,
118       double discretizerEnergy,
119       double acidostatEnergy) {
120     this.filename = filename;
121     this.info = info;
122     this.key = key;
123     this.bondEnergy = bondEnergy;
124     this.nBonds = nBonds;
125     this.angleEnergy = angleEnergy;
126     this.nAngles = nAngles;
127     this.stretchBendEnergy = stretchBendEnergy;
128     this.nStretchBends = nStretchBends;
129     this.ureyBradleyEnergy = ureyBradleyEnergy;
130     this.nUreyBradleys = nUreyBradleys;
131     this.outOfPlaneBendEnergy = outOfPlaneBendEnergy;
132     this.nOutOfPlaneBends = nOutOfPlaneBends;
133     this.torsionEnergy = torsionEnergy;
134     this.nTorsions = nTorsions;
135     this.improperTorsionEnergy = improperTorsionEnergy;
136     this.nImproperTorsions = nImproperTorsions;
137     this.piOrbitalTorsionEnergy = piOrbitalTorsionEnergy;
138     this.nPiOrbitalTorsions = nPiOrbitalTorsions;
139     this.torsionTorsionEnergy = torsionTorsionEnergy;
140     this.nTorsionTorsions = nTorsionTorsions;
141     this.vanDerWaalsEnergy = vanDerWaalsEnergy;
142     this.nVanDerWaals = nVanDerWaals;
143     this.permanentEnergy = permanentEnergy;
144     this.nPermanent = nPermanent;
145     this.polarizationEnergy = polarizationEnergy;
146     this.nPolar = nPolar;
147     this.discretizerEnergy = discretizerEnergy;
148     this.acidostatEnergy = acidostatEnergy;
149 
150     extendedSystemBias = discretizerEnergy + acidostatEnergy;
151     filepath = getResourcePath(filename);
152     totalEnergy = bondEnergy
153             + angleEnergy
154             + stretchBendEnergy
155             + ureyBradleyEnergy
156             + outOfPlaneBendEnergy
157             + torsionEnergy
158             + improperTorsionEnergy
159             + piOrbitalTorsionEnergy
160             + torsionTorsionEnergy
161             + vanDerWaalsEnergy
162             + permanentEnergy
163             + polarizationEnergy
164             + discretizerEnergy
165             + acidostatEnergy;
166   }
167 
168   @Parameterized.Parameters
169   public static Collection<Object[]> data() {
170     return Arrays.asList(
171         new Object[][] {
172             {
173                 "HDECK peptide",
174                 "HDECK.pdb",
175                 "\n  Titration Lambdas: 0.0000, 0.0000, 0.0000, 0.0000, 0.0000, " +
176                 "\n  Tautomer Lambdas: 0.0000, 0.0000, 0.0000",
177                 28.05522192,
178                 134,
179                 19.63246647,
180                 236,
181                 -1.43838685,
182                 201,
183                 0.0,
184                 0,
185                 0.00032350,
186                 81,
187                 33.46613466,
188                 335,
189                 0.0,
190                 0,
191                 0.00001133,
192                 15,
193                 0.0,
194                 0,
195                 100.22152394,
196                 8541,
197                 -51.85815355,
198                 7648,
199                 -42.77517305,
200                 7648,
201                 -8.00000000,
202                 -3.90174646
203             },
204             {
205                 "HDECK peptide",
206                 "HDECK.pdb",
207                 "\n  Titration Lambdas: 1.0000, 1.0000, 1.0000, 1.0000, 1.0000, " +
208                 "\n  Tautomer Lambdas: 0.0000, 0.0000, 0.0000",
209                 28.05522192,
210                 134,
211                 19.63246647,
212                 236,
213                 -1.43838685,
214                 201,
215                 0.0,
216                 0,
217                 0.00032350,
218                 81,
219                 33.46613466,
220                 335,
221                 0.0,
222                 0,
223                 0.00001133,
224                 15,
225                 0.0,
226                 0,
227                 101.39983768,
228                 8541,
229                 -170.80150311,
230                 8280,
231                 -22.35053436,
232                 8280,
233                 -8.00000000,
234                 -163.72800000
235             }
236         });
237   }
238 
239   @Test
240   public void testEndStateEnergyAndGradient() {
241     // Configure input arguments for the PhGradient script.
242     logger.info(" Testing endstate energy for " + info + "at lambdas: " + key);
243 
244     // Choose a random Atom (1..111) to test XYZ gradient.
245     Random random = new Random();
246     String randomAtom = Integer.toString(random.nextInt(110) + 1);
247 
248     String[] args = {"--testEndStateEnergies", "--esvLambda", "0.0", "-d", "0.000001", "--ga", randomAtom, filepath};
249     binding.setVariable("args", args);
250     // Construct and evaluate the Volume script.
251     PhGradient pHGradient = new PhGradient(binding).run();
252     potentialScript = pHGradient;
253 
254     double[] energyAndInteractionList = pHGradient.endstateEnergyMap.get(key);
255     // Bond Energy
256     assertEquals(info + " Bond Energy", bondEnergy, energyAndInteractionList[0], tolerance);
257     assertEquals(info + " Bond Count", nBonds, (int) energyAndInteractionList[1]);
258     // Angle Energy
259     assertEquals(info + " Angle Energy", angleEnergy, energyAndInteractionList[2], tolerance);
260     assertEquals(info + " Angle Count", nAngles, (int) energyAndInteractionList[3]);
261     // Stretch-Bend Energy
262     assertEquals(info + " Stretch-Bend Energy", stretchBendEnergy, energyAndInteractionList[4],
263         tolerance);
264     assertEquals(info + " Stretch-Bend Count", nStretchBends, (int) energyAndInteractionList[5]);
265     // Urey-Bradley Energy
266     assertEquals(info + " Urey-Bradley Energy", ureyBradleyEnergy, energyAndInteractionList[6],
267         tolerance);
268     assertEquals(info + " Urey-Bradley Count", nUreyBradleys, (int) energyAndInteractionList[7]);
269     // Out-of-Plane Bend
270     assertEquals(info + " Out-of-Plane Bend Energy", outOfPlaneBendEnergy,
271         energyAndInteractionList[8], tolerance);
272     assertEquals(info + " Out-of-Plane Bend Count", nOutOfPlaneBends,
273         (int) energyAndInteractionList[9]);
274     // Torsional Angle
275     assertEquals(info + " Torsion Energy", torsionEnergy, energyAndInteractionList[10], tolerance);
276     assertEquals(info + " Torsion Count", nTorsions, (int) energyAndInteractionList[11]);
277     // Improper Torsional Angle
278     assertEquals(info + " Improper Torsion Energy", improperTorsionEnergy,
279         energyAndInteractionList[12], tolerance);
280     assertEquals(info + " Improper Torsion Count", nImproperTorsions,
281         (int) energyAndInteractionList[13]);
282     // Pi-Orbital Torsion
283     assertEquals(info + " Pi-OrbitalTorsion Energy", piOrbitalTorsionEnergy,
284         energyAndInteractionList[14], tolerance);
285     assertEquals(info + " Pi-OrbitalTorsion Count", nPiOrbitalTorsions,
286         (int) energyAndInteractionList[15]);
287     // Torsion-Torsion
288     assertEquals(info + " Torsion-Torsion Energy", torsionTorsionEnergy,
289         energyAndInteractionList[16], tolerance);
290     assertEquals(info + " Torsion-Torsion Count", nTorsionTorsions,
291         (int) energyAndInteractionList[17]);
292     // van Der Waals
293     assertEquals(info + " van Der Waals Energy", vanDerWaalsEnergy, energyAndInteractionList[18],
294         tolerance);
295     assertEquals(info + " van Der Waals Count", nVanDerWaals, (int) energyAndInteractionList[19]);
296     // Permanent Multipoles
297     assertEquals(info + " Permanent Multipole Energy", permanentEnergy, energyAndInteractionList[20],
298         tolerance);
299     assertEquals(info + " Permanent Multipole Count", nPermanent,
300         (int) energyAndInteractionList[21]);
301     // Polarization Energy
302     assertEquals(info + " Polarization Energy", polarizationEnergy, energyAndInteractionList[22],
303         tolerance);
304     assertEquals(info + " Polarization Count", nPolar, (int) energyAndInteractionList[23]);
305     // Extended System Bias
306     assertEquals(info + " ExtendedSystemBias", extendedSystemBias, energyAndInteractionList[24],
307         tolerance);
308     // Total Energy
309     assertEquals(info + " Total Energy", totalEnergy, energyAndInteractionList[25], tolerance);
310 
311     // Check for a gradient failure.
312     assertEquals("HDECK gradient failures: ", 0, pHGradient.nFailures);
313     assertEquals("HDECK ESV gradient failures: ", 0, pHGradient.nESVFailures);
314   }
315 }
316