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.openmm;
39
40 import com.sun.jna.ptr.PointerByReference;
41
42 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_getConstraintTolerance;
43 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_getIntegrationForceGroups;
44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_getStepSize;
45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_setConstraintTolerance;
46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_setIntegrationForceGroups;
47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_setStepSize;
48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Integrator_step;
49
50 /**
51 * An Integrator defines a method for simulating a System by integrating the equations of motion.
52 * This is an abstract class. Subclasses define particular integration methods.
53 * <p>
54 * Each Integrator object is bound to a particular Context which it integrates. This connection
55 * is specified by passing the Integrator as an argument to the constructor of the Context.
56 */
57 public abstract class Integrator {
58
59 /**
60 * OpenMM Integrator pointer.
61 */
62 protected PointerByReference pointer;
63
64 /**
65 * Constructor.
66 */
67 public Integrator(PointerByReference pointer) {
68 this.pointer = pointer;
69 }
70
71 /**
72 * This method will be called by subclasses when the integrator is destroyed.
73 */
74 public abstract void destroy();
75
76 /**
77 * Get the tolerance within which constraints must be satisfied during the simulation.
78 *
79 * @return The constraint tolerance in nm.
80 */
81 public double getConstraintTolerance() {
82 return OpenMM_Integrator_getConstraintTolerance(pointer);
83 }
84
85 /**
86 * Get the set of force groups this integrator acts on.
87 *
88 * @return The bit flags indicating which force groups this integrator acts on.
89 */
90 public int getIntegrationForceGroups() {
91 return OpenMM_Integrator_getIntegrationForceGroups(pointer);
92 }
93
94 /**
95 * Get the OpenMM Integrator pointer.
96 *
97 * @return The OpenMM Integrator pointer.
98 */
99 public PointerByReference getPointer() {
100 return pointer;
101 }
102
103 /**
104 * Get the size of each time step, in picoseconds.
105 *
106 * @return The step size in ps.
107 */
108 public double getStepSize() {
109 return OpenMM_Integrator_getStepSize(pointer);
110 }
111
112 /**
113 * Set the tolerance within which constraints must be satisfied during the
114 * simulation. The default value is 1e-5 nm.
115 *
116 * @param tolerance The tolerance within which constraints must be satisfied.
117 */
118 public void setConstraintTolerance(double tolerance) {
119 OpenMM_Integrator_setConstraintTolerance(pointer, tolerance);
120 }
121
122 /**
123 * Set the force groups this integrator acts on.
124 *
125 * @param groups The bit flags indicating which force groups this integrator acts on.
126 */
127 public void setIntegrationForceGroups(int groups) {
128 OpenMM_Integrator_setIntegrationForceGroups(pointer, groups);
129 }
130
131 /**
132 * Set the OpenMM Integrator pointer.
133 *
134 * @param pointer The OpenMM Integrator pointer.
135 */
136 public void setPointer(PointerByReference pointer) {
137 this.pointer = pointer;
138 }
139
140 /**
141 * Set the size of each time step, in picoseconds.
142 *
143 * @param stepSize The step size in ps.
144 */
145 public void setStepSize(double stepSize) {
146 OpenMM_Integrator_setStepSize(pointer, stepSize);
147 }
148
149 /**
150 * Integrate the system forward in time by the specified number of time steps.
151 *
152 * @param steps The number of steps to take.
153 */
154 public void step(int steps) {
155 OpenMM_Integrator_step(pointer, steps);
156 }
157 }