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.numerics;
39
40 import java.util.Collections;
41 import java.util.List;
42
43 /**
44 * The Potential interface defines methods required by an optimizer or molecular dynamics.
45 *
46 * @author Michael J. Schnieders
47 * @since 1.0
48 */
49 public interface Potential extends OptimizationInterface {
50
51 /**
52 * getAcceleration.
53 *
54 * @param acceleration an array of double values.
55 * @return an array of double values.
56 */
57 double[] getAcceleration(double[] acceleration);
58
59 /**
60 * Returns the list of Constraints associated with this Potential. The default implementation
61 * returns an empty list.
62 *
63 * @return All Constraints.
64 */
65 default List<Constraint> getConstraints() {
66 return Collections.emptyList();
67 }
68
69 /**
70 * Get the Potential Energy terms that is active.
71 *
72 * @return the STATE
73 */
74 STATE getEnergyTermState();
75
76 /**
77 * Set the Potential Energy terms that should be active.
78 *
79 * @param state include FAST varying energy terms, SLOW varying energy terms or BOTH.
80 */
81 void setEnergyTermState(STATE state);
82
83 /**
84 * Get the mass of each degree of freedom. This is required for molecular dynamics.
85 *
86 * @return The mass of each degree of freedom.
87 */
88 double[] getMass();
89
90 /**
91 * getPreviousAcceleration.
92 *
93 * @param previousAcceleration an array of double values.
94 * @return an array of double values.
95 */
96 double[] getPreviousAcceleration(double[] previousAcceleration);
97
98 /**
99 * Get the type of all variables.
100 *
101 * @return The VARIABLE_TYPE of each variable.
102 */
103 VARIABLE_TYPE[] getVariableTypes();
104
105 /**
106 * getVelocity.
107 *
108 * @param velocity an array of double values.
109 * @return an array of double values.
110 */
111 double[] getVelocity(double[] velocity);
112
113 /**
114 * setAcceleration.
115 *
116 * @param acceleration an array of double values.
117 */
118 void setAcceleration(double[] acceleration);
119
120 /**
121 * setPreviousAcceleration.
122 *
123 * @param previousAcceleration an array of double values.
124 */
125 void setPreviousAcceleration(double[] previousAcceleration);
126
127 /**
128 * setVelocity.
129 *
130 * @param velocity an array of double values.
131 */
132 void setVelocity(double[] velocity);
133
134 /**
135 * Writes additional restart information, if any (e.g. OST histogram and lambda restart files). The
136 * recursive flag should generally only be true for the top-level Potential called.
137 *
138 * @param recursive Whether to have all underlying Potentials write additional restart info.
139 */
140 default void writeAdditionalRestartInfo(boolean recursive) {
141 if (recursive) {
142 getUnderlyingPotentials().forEach((Potential p) -> p.writeAdditionalRestartInfo(false));
143 } // Else, no-op.
144 }
145
146 /**
147 * Recognized variables currently include Cartesian coordinates and OTHER.
148 */
149 enum VARIABLE_TYPE {
150 /**
151 * X-coordinate.
152 */
153 X,
154 /**
155 * Y-coordinate.
156 */
157 Y,
158 /**
159 * Z-coordinate.
160 */
161 Z,
162 /**
163 * Other variable type.
164 */
165 OTHER
166 }
167
168 /**
169 * Set the state of the Potential to include FAST varying energy terms, SLOW varying energy terms
170 * or BOTH.
171 */
172 enum STATE {
173 /**
174 * Include FAST varying energy terms.
175 */
176 FAST,
177 /**
178 * Include SLOW varying energy terms.
179 */
180 SLOW,
181 /**
182 * Include both FAST and SLOW varying energy terms.
183 */
184 BOTH
185 }
186 }