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.groovy.test.LambdaGradient;
43  import ffx.potential.utils.PotentialTest;
44  import org.junit.Test;
45  
46  /**
47   * Tests test.LambdaGradient command to determine that the end state potentials and derivatives are
48   * correct.
49   *
50   * @author Aaron J. Nessler
51   * @author Mallory R. Tollefson
52   */
53  public class LambdaGradientTest extends PotentialTest {
54  
55    /** Tests the End States of the LambdaGradient class. */
56    @Test
57    public void testLambdaGradient() {
58      // Prepare the Binding with input arguments.
59      String xyzpath = getResourcePath("phenacetin.xyz");
60      String[] args = {"--ac", "1-26", xyzpath};
61      binding.setVariable("args", args);
62  
63      // Construct and evaluate the script.
64      LambdaGradient lambdaGradient = new LambdaGradient(binding).run();
65      potentialScript = lambdaGradient;
66  
67      double expectedPotentialEnergyVac = -7.70864934;
68      double expectedPotentialEnergyXtal = -36.227069280713586;
69      double actualPotentialEnergyVac = lambdaGradient.e0;
70      double actualPotentialEnergyXtal = lambdaGradient.e1;
71  
72      assertEquals(expectedPotentialEnergyVac, actualPotentialEnergyVac, 1E-6);
73      assertEquals(expectedPotentialEnergyXtal, actualPotentialEnergyXtal, 1E-6);
74      assertEquals(0, lambdaGradient.ndEdLFailures);
75      assertEquals(0, lambdaGradient.nd2EdL2Failures);
76      assertEquals(0, lambdaGradient.ndEdXdLFailures);
77      assertEquals(0, lambdaGradient.ndEdXFailures);
78    }
79  
80    @Test
81    public void testLambdaGradientHelp() {
82      // Set up the input arguments for the LambdaGradient script.
83      String[] args = {"-h"};
84      binding.setVariable("args", args);
85  
86      // Construct and evaluate the script.
87      LambdaGradient lambdaGradient = new LambdaGradient(binding).run();
88      potentialScript = lambdaGradient;
89    }
90  
91    /** Tests the End States of the LambdaGradient class when softcore is active. */
92    @Test
93    public void testLambdaGradientIntermolecularSoftcore() {
94      // Set up the input arguments for the LambdaGradient script.
95      String xyzpath = getResourcePath("ethylparaben.xyz");
96      String[] args = {"--ac", "1-44", xyzpath};
97      binding.setVariable("args", args);
98  
99      // Construct and evaluate the script.
100     LambdaGradient lambdaGradient = new LambdaGradient(binding).run();
101     potentialScript = lambdaGradient;
102 
103     double expectedPotentialEnergyVac = -6.67890842;
104     double expectedPotentialEnergyXtal = -57.410945848200896;
105     double actualPotentialEnergyVac = lambdaGradient.e0;
106     double actualPotentialEnergyXtal = lambdaGradient.e1;
107 
108     assertEquals(expectedPotentialEnergyVac, actualPotentialEnergyVac, 1E-6);
109     assertEquals(expectedPotentialEnergyXtal, actualPotentialEnergyXtal, 1E-6);
110     assertEquals(0, lambdaGradient.ndEdLFailures);
111     assertEquals(0, lambdaGradient.nd2EdL2Failures);
112     assertEquals(0, lambdaGradient.ndEdXdLFailures);
113     assertEquals(0, lambdaGradient.ndEdXFailures);
114   }
115 
116   /** Tests the End States of the LambdaGradient class when mapped via sym op. */
117   @Test
118   public void testLambdaGradientSymOp() {
119     // Set up the input arguments for the LambdaGradient script.
120     String roy02path = getResourcePath("roy02_P1.xyz");
121     String roy31path = getResourcePath("roy31.xyz");
122     String[] args = {"--sf", "TRIG", "--ls", "-l", "0.5", roy02path, roy31path};
123     binding.setVariable("args", args);
124 
125     // Construct and evaluate the script.
126     LambdaGradient lambdaGradient = new LambdaGradient(binding).run();
127     potentialScript = lambdaGradient;
128 
129     double expectedPotentialEnergyVac = -32.31574626689126;
130     double expectedPotentialEnergyXtal = -43.95639068837232;
131     double actualPotentialEnergyVac = lambdaGradient.e0;
132     double actualPotentialEnergyXtal = lambdaGradient.e1;
133 
134     assertEquals(expectedPotentialEnergyVac, actualPotentialEnergyVac, 1E-6);
135     assertEquals(expectedPotentialEnergyXtal, actualPotentialEnergyXtal, 1E-6);
136     assertEquals(0, lambdaGradient.ndEdLFailures);
137     assertEquals(0, lambdaGradient.nd2EdL2Failures);
138     assertEquals(0, lambdaGradient.ndEdXdLFailures);
139     assertEquals(0, lambdaGradient.ndEdXFailures);
140   }
141 }