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.Pointer;
41 import com.sun.jna.ptr.DoubleByReference;
42 import com.sun.jna.ptr.IntByReference;
43 import com.sun.jna.ptr.PointerByReference;
44
45 import java.nio.DoubleBuffer;
46 import java.nio.IntBuffer;
47
48 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Boolean.OpenMM_True;
49 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addAcceptor;
50 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addDonor;
51 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addExclusion;
52 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addFunction;
53 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addGlobalParameter;
54 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addPerAcceptorParameter;
55 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addPerDonorParameter;
56 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_addTabulatedFunction;
57 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_create;
58 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_destroy;
59 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getAcceptorParameters;
60 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getCutoffDistance;
61 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getDonorParameters;
62 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getEnergyFunction;
63 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getExclusionParticles;
64 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getFunctionParameters;
65 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getGlobalParameterDefaultValue;
66 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getGlobalParameterName;
67 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNonbondedMethod;
68 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumAcceptors;
69 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumDonors;
70 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumExclusions;
71 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumFunctions;
72 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumGlobalParameters;
73 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumPerAcceptorParameters;
74 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumPerDonorParameters;
75 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getNumTabulatedFunctions;
76 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getPerAcceptorParameterName;
77 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getPerDonorParameterName;
78 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getTabulatedFunction;
79 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_getTabulatedFunctionName;
80 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setAcceptorParameters;
81 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setCutoffDistance;
82 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setDonorParameters;
83 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setEnergyFunction;
84 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setExclusionParticles;
85 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setFunctionParameters;
86 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setGlobalParameterDefaultValue;
87 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setGlobalParameterName;
88 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setNonbondedMethod;
89 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setPerAcceptorParameterName;
90 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_setPerDonorParameterName;
91 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_updateParametersInContext;
92 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomHbondForce_usesPeriodicBoundaryConditions;
93
94 /**
95 * This class supports a wide variety of energy functions used to represent hydrogen bonding. It computes
96 * interactions between "donor" particle groups and "acceptor" particle groups, where each group may include
97 * up to three particles. Typically a donor group consists of a hydrogen atom and the atoms it is bonded to,
98 * and an acceptor group consists of a negatively charged atom and the atoms it is bonded to.
99 *
100 * <p>We refer to the particles in a donor group as d1, d2 and d3, and the particles in an acceptor group as
101 * a1, a2, and a3. For each donor and each acceptor, CustomHbondForce evaluates a user supplied algebraic
102 * expression to determine the interaction energy. The expression may depend on arbitrary distances, angles,
103 * and dihedral angles defined by any of the six particles involved. The function distance(p1, p2) is the distance
104 * between the particles p1 and p2 (where "p1" and "p2" should be replaced by the names of the actual particles
105 * to calculate the distance between), angle(p1, p2, p3) is the angle formed by the three specified particles,
106 * and dihedral(p1, p2, p3, p4) is the dihedral angle formed by the four specified particles.
107 *
108 * <p>The expression also may involve tabulated functions, and may depend on arbitrary
109 * global, per-donor, and per-acceptor parameters. It also optionally supports periodic boundary conditions
110 * and cutoffs for long range interactions.
111 *
112 * <p>To use this class, create a CustomHbondForce object, passing an algebraic expression to the constructor
113 * that defines the interaction energy between each donor and acceptor. Then call addPerDonorParameter() to define per-donor
114 * parameters, addPerAcceptorParameter() to define per-acceptor parameters, and addGlobalParameter() to define
115 * global parameters. The values of per-donor and per-acceptor parameters are specified as part of the system
116 * definition, while values of global parameters may be modified during a simulation by calling Context::setParameter().
117 *
118 * <p>Next, call addDonor() and addAcceptor() to define donors and acceptors and specify their parameter values.
119 * After a donor or acceptor has been added, you can modify its parameters by calling setDonorParameters() or
120 * setAcceptorParameters(). This will have no effect on Contexts that already exist unless you call updateParametersInContext().
121 *
122 * <p>CustomHbondForce also lets you specify "exclusions", particular combinations of donors and acceptors whose
123 * interactions should be omitted from force and energy calculations. This is most often used for particles
124 * that are bonded to each other.
125 *
126 * <p>As an example, the following code creates a CustomHbondForce that implements a simple harmonic potential
127 * to keep the distance between a1 and d1, and the angle formed by a1-d1-d2, near ideal values:
128 *
129 * <pre>{@code
130 * CustomHbondForce force = new CustomHbondForce("k*(distance(a1,d1)-r0)^2*(angle(a1,d1,d2)-theta0)^2");
131 * }</pre>
132 *
133 * <p>This force depends on three parameters: k, r0, and theta0. The following code defines these as per-donor parameters:
134 *
135 * <pre>{@code
136 * force.addPerDonorParameter("k");
137 * force.addPerDonorParameter("r0");
138 * force.addPerDonorParameter("theta0");
139 * }</pre>
140 *
141 * <p>Expressions may involve the operators + (add), - (subtract), * (multiply), / (divide), and ^ (power), and the following
142 * functions: sqrt, exp, log, sin, cos, sec, csc, tan, cot, asin, acos, atan, atan2, sinh, cosh, tanh, erf, erfc, min, max, abs, floor, ceil, step, delta, select. All trigonometric functions
143 * are defined in radians, and log is the natural logarithm. step(x) = 0 if x < 0, 1 otherwise. delta(x) = 1 if x = 0, 0 otherwise.
144 * select(x,y,z) = z if x = 0, y otherwise.
145 *
146 * <p>In addition, you can call addTabulatedFunction() to define a new function based on tabulated values. You specify the function by
147 * creating a TabulatedFunction object. That function can then appear in the expression.
148 */
149 public class CustomHbondForce extends Force {
150
151 /**
152 * Create a new CustomHbondForce.
153 *
154 * @param energy The energy expression for the hydrogen bond interaction.
155 */
156 public CustomHbondForce(String energy) {
157 super(OpenMM_CustomHbondForce_create(energy));
158 }
159
160 /**
161 * Add an acceptor to the force.
162 *
163 * @param a1 The index of the first atom that defines the acceptor.
164 * @param a2 The index of the second atom that defines the acceptor.
165 * @param a3 The index of the third atom that defines the acceptor.
166 * @param parameters The parameters for the acceptor.
167 * @return The index of the acceptor that was added.
168 */
169 public int addAcceptor(int a1, int a2, int a3, PointerByReference parameters) {
170 return OpenMM_CustomHbondForce_addAcceptor(pointer, a1, a2, a3, parameters);
171 }
172
173 /**
174 * Add a donor to the force.
175 *
176 * @param d1 The index of the first atom that defines the donor.
177 * @param d2 The index of the second atom that defines the donor.
178 * @param d3 The index of the third atom that defines the donor.
179 * @param parameters The parameters for the donor.
180 * @return The index of the donor that was added.
181 */
182 public int addDonor(int d1, int d2, int d3, PointerByReference parameters) {
183 return OpenMM_CustomHbondForce_addDonor(pointer, d1, d2, d3, parameters);
184 }
185
186 /**
187 * Add an exclusion to the force.
188 *
189 * @param donor The index of the donor.
190 * @param acceptor The index of the acceptor.
191 * @return The index of the exclusion that was added.
192 */
193 public int addExclusion(int donor, int acceptor) {
194 return OpenMM_CustomHbondForce_addExclusion(pointer, donor, acceptor);
195 }
196
197 /**
198 * Add a tabulated function that may appear in the energy expression.
199 *
200 * @param name The name of the function as it appears in expressions.
201 * @param function A TabulatedFunction object defining the function.
202 * @param min The minimum value of the independent variable for which the function is defined.
203 * @param max The maximum value of the independent variable for which the function is defined.
204 * @return The index of the function that was added.
205 */
206 public int addFunction(String name, PointerByReference function, double min, double max) {
207 return OpenMM_CustomHbondForce_addFunction(pointer, name, function, min, max);
208 }
209
210 /**
211 * Add a tabulated function that may appear in the energy expression.
212 *
213 * @param name The name of the function as it appears in expressions.
214 * @param function A TabulatedFunction object defining the function.
215 * @param min The minimum value of the independent variable for which the function is defined.
216 * @param max The maximum value of the independent variable for which the function is defined.
217 * @return The index of the function that was added.
218 */
219 public int addFunction(Pointer name, PointerByReference function, double min, double max) {
220 return OpenMM_CustomHbondForce_addFunction(pointer, name, function, min, max);
221 }
222
223 /**
224 * Add a global parameter to the force.
225 *
226 * @param name The name of the parameter.
227 * @param defaultValue The default value of the parameter.
228 * @return The index of the parameter that was added.
229 */
230 public int addGlobalParameter(String name, double defaultValue) {
231 return OpenMM_CustomHbondForce_addGlobalParameter(pointer, name, defaultValue);
232 }
233
234 /**
235 * Add a global parameter to the force.
236 *
237 * @param name The name of the parameter.
238 * @param defaultValue The default value of the parameter.
239 * @return The index of the parameter that was added.
240 */
241 public int addGlobalParameter(Pointer name, double defaultValue) {
242 return OpenMM_CustomHbondForce_addGlobalParameter(pointer, name, defaultValue);
243 }
244
245 /**
246 * Add a per-acceptor parameter to the force.
247 *
248 * @param name The name of the parameter.
249 * @return The index of the parameter that was added.
250 */
251 public int addPerAcceptorParameter(String name) {
252 return OpenMM_CustomHbondForce_addPerAcceptorParameter(pointer, name);
253 }
254
255 /**
256 * Add a per-acceptor parameter to the force.
257 *
258 * @param name The name of the parameter.
259 * @return The index of the parameter that was added.
260 */
261 public int addPerAcceptorParameter(Pointer name) {
262 return OpenMM_CustomHbondForce_addPerAcceptorParameter(pointer, name);
263 }
264
265 /**
266 * Add a per-donor parameter to the force.
267 *
268 * @param name The name of the parameter.
269 * @return The index of the parameter that was added.
270 */
271 public int addPerDonorParameter(String name) {
272 return OpenMM_CustomHbondForce_addPerDonorParameter(pointer, name);
273 }
274
275 /**
276 * Add a per-donor parameter to the force.
277 *
278 * @param name The name of the parameter.
279 * @return The index of the parameter that was added.
280 */
281 public int addPerDonorParameter(Pointer name) {
282 return OpenMM_CustomHbondForce_addPerDonorParameter(pointer, name);
283 }
284
285 /**
286 * Add a tabulated function that may appear in the energy expression.
287 *
288 * @param name The name of the function as it appears in expressions.
289 * @param function A TabulatedFunction object defining the function.
290 * @return The index of the function that was added.
291 */
292 public int addTabulatedFunction(String name, PointerByReference function) {
293 return OpenMM_CustomHbondForce_addTabulatedFunction(pointer, name, function);
294 }
295
296 /**
297 * Add a tabulated function that may appear in the energy expression.
298 *
299 * @param name The name of the function as it appears in expressions.
300 * @param function A TabulatedFunction object defining the function.
301 * @return The index of the function that was added.
302 */
303 public int addTabulatedFunction(Pointer name, PointerByReference function) {
304 return OpenMM_CustomHbondForce_addTabulatedFunction(pointer, name, function);
305 }
306
307 /**
308 * Destroy the force.
309 */
310 @Override
311 public void destroy() {
312 if (pointer != null) {
313 OpenMM_CustomHbondForce_destroy(pointer);
314 pointer = null;
315 }
316 }
317
318 /**
319 * Get the parameters for an acceptor.
320 *
321 * @param index The index of the acceptor.
322 * @param a1 The index of the first atom that defines the acceptor (output).
323 * @param a2 The index of the second atom that defines the acceptor (output).
324 * @param a3 The index of the third atom that defines the acceptor (output).
325 * @param parameters The parameters for the acceptor (output).
326 */
327 public void getAcceptorParameters(int index, IntByReference a1, IntByReference a2, IntByReference a3, PointerByReference parameters) {
328 OpenMM_CustomHbondForce_getAcceptorParameters(pointer, index, a1, a2, a3, parameters);
329 }
330
331 /**
332 * Get the parameters for an acceptor.
333 *
334 * @param index The index of the acceptor.
335 * @param a1 The index of the first atom that defines the acceptor (output).
336 * @param a2 The index of the second atom that defines the acceptor (output).
337 * @param a3 The index of the third atom that defines the acceptor (output).
338 * @param parameters The parameters for the acceptor (output).
339 */
340 public void getAcceptorParameters(int index, IntBuffer a1, IntBuffer a2, IntBuffer a3, PointerByReference parameters) {
341 OpenMM_CustomHbondForce_getAcceptorParameters(pointer, index, a1, a2, a3, parameters);
342 }
343
344 /**
345 * Get the cutoff distance.
346 *
347 * @return The cutoff distance, measured in nm.
348 */
349 public double getCutoffDistance() {
350 return OpenMM_CustomHbondForce_getCutoffDistance(pointer);
351 }
352
353 /**
354 * Get the parameters for a donor.
355 *
356 * @param index The index of the donor.
357 * @param d1 The index of the first atom that defines the donor (output).
358 * @param d2 The index of the second atom that defines the donor (output).
359 * @param d3 The index of the third atom that defines the donor (output).
360 * @param parameters The parameters for the donor (output).
361 */
362 public void getDonorParameters(int index, IntByReference d1, IntByReference d2, IntByReference d3, PointerByReference parameters) {
363 OpenMM_CustomHbondForce_getDonorParameters(pointer, index, d1, d2, d3, parameters);
364 }
365
366 /**
367 * Get the parameters for a donor.
368 *
369 * @param index The index of the donor.
370 * @param d1 The index of the first atom that defines the donor (output).
371 * @param d2 The index of the second atom that defines the donor (output).
372 * @param d3 The index of the third atom that defines the donor (output).
373 * @param parameters The parameters for the donor (output).
374 */
375 public void getDonorParameters(int index, IntBuffer d1, IntBuffer d2, IntBuffer d3, PointerByReference parameters) {
376 OpenMM_CustomHbondForce_getDonorParameters(pointer, index, d1, d2, d3, parameters);
377 }
378
379 /**
380 * Get the energy expression for the force.
381 *
382 * @return The energy expression for the force.
383 */
384 public String getEnergyFunction() {
385 Pointer p = OpenMM_CustomHbondForce_getEnergyFunction(pointer);
386 if (p == null) {
387 return null;
388 }
389 return p.getString(0);
390 }
391
392 /**
393 * Get the particles in an exclusion.
394 *
395 * @param index The index of the exclusion.
396 * @param donor The index of the donor (output).
397 * @param acceptor The index of the acceptor (output).
398 */
399 public void getExclusionParticles(int index, IntByReference donor, IntByReference acceptor) {
400 OpenMM_CustomHbondForce_getExclusionParticles(pointer, index, donor, acceptor);
401 }
402
403 /**
404 * Get the particles in an exclusion.
405 *
406 * @param index The index of the exclusion.
407 * @param donor The index of the donor (output).
408 * @param acceptor The index of the acceptor (output).
409 */
410 public void getExclusionParticles(int index, IntBuffer donor, IntBuffer acceptor) {
411 OpenMM_CustomHbondForce_getExclusionParticles(pointer, index, donor, acceptor);
412 }
413
414 /**
415 * Get the parameters for a tabulated function.
416 *
417 * @param index The index of the function.
418 * @param name The name of the function as it appears in expressions (output).
419 * @param function A TabulatedFunction object defining the function (output).
420 * @param min The minimum value of the independent variable for which the function is defined (output).
421 * @param max The maximum value of the independent variable for which the function is defined (output).
422 */
423 public void getFunctionParameters(int index, PointerByReference name, PointerByReference function, DoubleByReference min, DoubleByReference max) {
424 OpenMM_CustomHbondForce_getFunctionParameters(pointer, index, name, function, min, max);
425 }
426
427 /**
428 * Get the parameters for a tabulated function.
429 *
430 * @param index The index of the function.
431 * @param name The name of the function as it appears in expressions (output).
432 * @param function A TabulatedFunction object defining the function (output).
433 * @param min The minimum value of the independent variable for which the function is defined (output).
434 * @param max The maximum value of the independent variable for which the function is defined (output).
435 */
436 public void getFunctionParameters(int index, PointerByReference name, PointerByReference function, DoubleBuffer min, DoubleBuffer max) {
437 OpenMM_CustomHbondForce_getFunctionParameters(pointer, index, name, function, min, max);
438 }
439
440 /**
441 * Get the default value of a global parameter.
442 *
443 * @param index The index of the parameter.
444 * @return The default value of the parameter.
445 */
446 public double getGlobalParameterDefaultValue(int index) {
447 return OpenMM_CustomHbondForce_getGlobalParameterDefaultValue(pointer, index);
448 }
449
450 /**
451 * Get the name of a global parameter.
452 *
453 * @param index The index of the parameter.
454 * @return The name of the parameter.
455 */
456 public String getGlobalParameterName(int index) {
457 Pointer p = OpenMM_CustomHbondForce_getGlobalParameterName(pointer, index);
458 if (p == null) {
459 return null;
460 }
461 return p.getString(0);
462 }
463
464 /**
465 * Get the nonbonded method.
466 *
467 * @return The nonbonded method.
468 */
469 public int getNonbondedMethod() {
470 return OpenMM_CustomHbondForce_getNonbondedMethod(pointer);
471 }
472
473 /**
474 * Get the number of acceptors.
475 *
476 * @return The number of acceptors.
477 */
478 public int getNumAcceptors() {
479 return OpenMM_CustomHbondForce_getNumAcceptors(pointer);
480 }
481
482 /**
483 * Get the number of donors.
484 *
485 * @return The number of donors.
486 */
487 public int getNumDonors() {
488 return OpenMM_CustomHbondForce_getNumDonors(pointer);
489 }
490
491 /**
492 * Get the number of exclusions.
493 *
494 * @return The number of exclusions.
495 */
496 public int getNumExclusions() {
497 return OpenMM_CustomHbondForce_getNumExclusions(pointer);
498 }
499
500 /**
501 * Get the number of tabulated functions.
502 *
503 * @return The number of tabulated functions.
504 * @deprecated This method exists only for backward compatibility. Use getNumTabulatedFunctions() instead.
505 */
506 @Deprecated
507 public int getNumFunctions() {
508 return OpenMM_CustomHbondForce_getNumFunctions(pointer);
509 }
510
511 /**
512 * Get the number of global parameters.
513 *
514 * @return The number of global parameters.
515 */
516 public int getNumGlobalParameters() {
517 return OpenMM_CustomHbondForce_getNumGlobalParameters(pointer);
518 }
519
520 /**
521 * Get the number of per-acceptor parameters.
522 *
523 * @return The number of per-acceptor parameters.
524 */
525 public int getNumPerAcceptorParameters() {
526 return OpenMM_CustomHbondForce_getNumPerAcceptorParameters(pointer);
527 }
528
529 /**
530 * Get the number of per-donor parameters.
531 *
532 * @return The number of per-donor parameters.
533 */
534 public int getNumPerDonorParameters() {
535 return OpenMM_CustomHbondForce_getNumPerDonorParameters(pointer);
536 }
537
538 /**
539 * Get the number of tabulated functions.
540 *
541 * @return The number of tabulated functions.
542 */
543 public int getNumTabulatedFunctions() {
544 return OpenMM_CustomHbondForce_getNumTabulatedFunctions(pointer);
545 }
546
547 /**
548 * Get the name of a per-acceptor parameter.
549 *
550 * @param index The index of the parameter.
551 * @return The name of the parameter.
552 */
553 public String getPerAcceptorParameterName(int index) {
554 Pointer p = OpenMM_CustomHbondForce_getPerAcceptorParameterName(pointer, index);
555 if (p == null) {
556 return null;
557 }
558 return p.getString(0);
559 }
560
561 /**
562 * Get the name of a per-donor parameter.
563 *
564 * @param index The index of the parameter.
565 * @return The name of the parameter.
566 */
567 public String getPerDonorParameterName(int index) {
568 Pointer p = OpenMM_CustomHbondForce_getPerDonorParameterName(pointer, index);
569 if (p == null) {
570 return null;
571 }
572 return p.getString(0);
573 }
574
575 /**
576 * Get a reference to a tabulated function that may appear in the energy expression.
577 *
578 * @param index The index of the function.
579 * @return The TabulatedFunction object defining the function.
580 */
581 public PointerByReference getTabulatedFunction(int index) {
582 return OpenMM_CustomHbondForce_getTabulatedFunction(pointer, index);
583 }
584
585 /**
586 * Get the name of a tabulated function that may appear in the energy expression.
587 *
588 * @param index The index of the function.
589 * @return The name of the function as it appears in expressions.
590 */
591 public String getTabulatedFunctionName(int index) {
592 Pointer p = OpenMM_CustomHbondForce_getTabulatedFunctionName(pointer, index);
593 if (p == null) {
594 return null;
595 }
596 return p.getString(0);
597 }
598
599 /**
600 * Set the parameters for an acceptor.
601 *
602 * @param index The index of the acceptor.
603 * @param a1 The index of the first atom that defines the acceptor.
604 * @param a2 The index of the second atom that defines the acceptor.
605 * @param a3 The index of the third atom that defines the acceptor.
606 * @param parameters The parameters for the acceptor.
607 */
608 public void setAcceptorParameters(int index, int a1, int a2, int a3, PointerByReference parameters) {
609 OpenMM_CustomHbondForce_setAcceptorParameters(pointer, index, a1, a2, a3, parameters);
610 }
611
612 /**
613 * Set the cutoff distance.
614 *
615 * @param distance The cutoff distance, measured in nm.
616 */
617 public void setCutoffDistance(double distance) {
618 OpenMM_CustomHbondForce_setCutoffDistance(pointer, distance);
619 }
620
621 /**
622 * Set the parameters for a donor.
623 *
624 * @param index The index of the donor.
625 * @param d1 The index of the first atom that defines the donor.
626 * @param d2 The index of the second atom that defines the donor.
627 * @param d3 The index of the third atom that defines the donor.
628 * @param parameters The parameters for the donor.
629 */
630 public void setDonorParameters(int index, int d1, int d2, int d3, PointerByReference parameters) {
631 OpenMM_CustomHbondForce_setDonorParameters(pointer, index, d1, d2, d3, parameters);
632 }
633
634 /**
635 * Set the energy expression for the force.
636 *
637 * @param energy The energy expression for the force.
638 */
639 public void setEnergyFunction(String energy) {
640 OpenMM_CustomHbondForce_setEnergyFunction(pointer, energy);
641 }
642
643 /**
644 * Set the energy expression for the force.
645 *
646 * @param energy The energy expression for the force.
647 */
648 public void setEnergyFunction(Pointer energy) {
649 OpenMM_CustomHbondForce_setEnergyFunction(pointer, energy);
650 }
651
652 /**
653 * Set the particles in an exclusion.
654 *
655 * @param index The index of the exclusion.
656 * @param donor The index of the donor.
657 * @param acceptor The index of the acceptor.
658 */
659 public void setExclusionParticles(int index, int donor, int acceptor) {
660 OpenMM_CustomHbondForce_setExclusionParticles(pointer, index, donor, acceptor);
661 }
662
663 /**
664 * Set the parameters for a tabulated function.
665 *
666 * @param index The index of the function.
667 * @param name The name of the function as it appears in expressions.
668 * @param function A TabulatedFunction object defining the function.
669 * @param min The minimum value of the independent variable for which the function is defined.
670 * @param max The maximum value of the independent variable for which the function is defined.
671 */
672 public void setFunctionParameters(int index, String name, PointerByReference function, double min, double max) {
673 OpenMM_CustomHbondForce_setFunctionParameters(pointer, index, name, function, min, max);
674 }
675
676 /**
677 * Set the parameters for a tabulated function.
678 *
679 * @param index The index of the function.
680 * @param name The name of the function as it appears in expressions.
681 * @param function A TabulatedFunction object defining the function.
682 * @param min The minimum value of the independent variable for which the function is defined.
683 * @param max The maximum value of the independent variable for which the function is defined.
684 */
685 public void setFunctionParameters(int index, Pointer name, PointerByReference function, double min, double max) {
686 OpenMM_CustomHbondForce_setFunctionParameters(pointer, index, name, function, min, max);
687 }
688
689 /**
690 * Set the default value of a global parameter.
691 *
692 * @param index The index of the parameter.
693 * @param defaultValue The default value of the parameter.
694 */
695 public void setGlobalParameterDefaultValue(int index, double defaultValue) {
696 OpenMM_CustomHbondForce_setGlobalParameterDefaultValue(pointer, index, defaultValue);
697 }
698
699 /**
700 * Set the name of a global parameter.
701 *
702 * @param index The index of the parameter.
703 * @param name The name of the parameter.
704 */
705 public void setGlobalParameterName(int index, String name) {
706 OpenMM_CustomHbondForce_setGlobalParameterName(pointer, index, name);
707 }
708
709 /**
710 * Set the name of a global parameter.
711 *
712 * @param index The index of the parameter.
713 * @param name The name of the parameter.
714 */
715 public void setGlobalParameterName(int index, Pointer name) {
716 OpenMM_CustomHbondForce_setGlobalParameterName(pointer, index, name);
717 }
718
719 /**
720 * Set the nonbonded method.
721 *
722 * @param method The nonbonded method.
723 */
724 public void setNonbondedMethod(int method) {
725 OpenMM_CustomHbondForce_setNonbondedMethod(pointer, method);
726 }
727
728 /**
729 * Set the name of a per-acceptor parameter.
730 *
731 * @param index The index of the parameter.
732 * @param name The name of the parameter.
733 */
734 public void setPerAcceptorParameterName(int index, String name) {
735 OpenMM_CustomHbondForce_setPerAcceptorParameterName(pointer, index, name);
736 }
737
738 /**
739 * Set the name of a per-acceptor parameter.
740 *
741 * @param index The index of the parameter.
742 * @param name The name of the parameter.
743 */
744 public void setPerAcceptorParameterName(int index, Pointer name) {
745 OpenMM_CustomHbondForce_setPerAcceptorParameterName(pointer, index, name);
746 }
747
748 /**
749 * Set the name of a per-donor parameter.
750 *
751 * @param index The index of the parameter.
752 * @param name The name of the parameter.
753 */
754 public void setPerDonorParameterName(int index, String name) {
755 OpenMM_CustomHbondForce_setPerDonorParameterName(pointer, index, name);
756 }
757
758 /**
759 * Set the name of a per-donor parameter.
760 *
761 * @param index The index of the parameter.
762 * @param name The name of the parameter.
763 */
764 public void setPerDonorParameterName(int index, Pointer name) {
765 OpenMM_CustomHbondForce_setPerDonorParameterName(pointer, index, name);
766 }
767
768 /**
769 * Update the parameters in a Context to match those stored in this Force object.
770 *
771 * @param context The Context in which to update the parameters.
772 */
773 public void updateParametersInContext(Context context) {
774 if (context.hasContextPointer()) {
775 OpenMM_CustomHbondForce_updateParametersInContext(pointer, context.getPointer());
776 }
777 }
778
779 /**
780 * Check if the force uses periodic boundary conditions.
781 *
782 * @return True if the force uses periodic boundary conditions.
783 */
784 @Override
785 public boolean usesPeriodicBoundaryConditions() {
786 int pbc = OpenMM_CustomHbondForce_usesPeriodicBoundaryConditions(pointer);
787 return pbc == OpenMM_True;
788 }
789 }