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.DoubleByReference;
41 import com.sun.jna.ptr.IntByReference;
42 import com.sun.jna.ptr.PointerByReference;
43
44 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Continuous2DFunction_create;
45 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Continuous2DFunction_destroy;
46 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Continuous2DFunction_getFunctionParameters;
47 import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_Continuous2DFunction_setFunctionParameters;
48
49 /**
50 * This is a TabulatedFunction that computes a continuous two dimensional function.
51 */
52 public class Continuous2DFunction extends TabulatedFunction {
53
54 /**
55 * Create a Continuous2DFunction f(x,y) based on a set of tabulated values.
56 *
57 * @param values the tabulated values of the function f(x,y) at xsize uniformly spaced values of x between xmin
58 * and xmax, and ysize values of y between ymin and ymax. A natural cubic spline is used to interpolate between the tabulated values.
59 * The function is assumed to be zero when x or y is outside its specified range. The values should be ordered so that
60 * values[i+xsize*j] = f(x_i,y_j), where x_i is the i'th uniformly spaced value of x. This must be of length xsize*ysize.
61 * @param xsize the number of table elements along the x direction
62 * @param ysize the number of table elements along the y direction
63 * @param xmin the value of x corresponding to the first element of values
64 * @param xmax the value of x corresponding to the last element of values
65 * @param ymin the value of y corresponding to the first element of values
66 * @param ymax the value of y corresponding to the last element of values
67 * @param periodic whether the interpolated function is periodic
68 */
69 public Continuous2DFunction(PointerByReference values, int xsize, int ysize, double xmin, double xmax, double ymin, double ymax, boolean periodic) {
70 super(OpenMM_Continuous2DFunction_create(xsize, ysize, values, xmin, xmax, ymin, ymax, periodic ? 1 : 0));
71 }
72
73 /**
74 * Destroy the continuous 2D function.
75 */
76 @Override
77 public void destroy() {
78 if (pointer != null) {
79 OpenMM_Continuous2DFunction_destroy(pointer);
80 pointer = null;
81 }
82 }
83
84 /**
85 * Get the parameters for the tabulated function.
86 *
87 * @param values the tabulated values of the function f(x,y) at xsize uniformly spaced values of x between xmin
88 * and xmax, and ysize values of y between ymin and ymax. A natural cubic spline is used to interpolate between the tabulated values.
89 * The function is assumed to be zero when x or y is outside its specified range. The values should be ordered so that
90 * values[i+xsize*j] = f(x_i,y_j), where x_i is the i'th uniformly spaced value of x. This must be of length xsize*ysize.
91 * @param xsize the number of table elements along the x direction
92 * @param ysize the number of table elements along the y direction
93 * @param xmin the value of x corresponding to the first element of values
94 * @param xmax the value of x corresponding to the last element of values
95 * @param ymin the value of y corresponding to the first element of values
96 * @param ymax the value of y corresponding to the last element of values
97 */
98 public void getFunctionParameters(PointerByReference values, IntByReference xsize, IntByReference ysize,
99 DoubleByReference xmin, DoubleByReference xmax,
100 DoubleByReference ymin, DoubleByReference ymax) {
101 OpenMM_Continuous2DFunction_getFunctionParameters(pointer, xsize, ysize, values, xmin, xmax, ymin, ymax);
102 }
103
104 /**
105 * Set the parameters for the tabulated function.
106 *
107 * @param values the tabulated values of the function f(x,y) at xsize uniformly spaced values of x between xmin
108 * and xmax, and ysize values of y between ymin and ymax. A natural cubic spline is used to interpolate between the tabulated values.
109 * The function is assumed to be zero when x or y is outside its specified range. The values should be ordered so that
110 * values[i+xsize*j] = f(x_i,y_j), where x_i is the i'th uniformly spaced value of x. This must be of length xsize*ysize.
111 * @param xsize the number of table elements along the x direction
112 * @param ysize the number of table elements along the y direction
113 * @param xmin the value of x corresponding to the first element of values
114 * @param xmax the value of x corresponding to the last element of values
115 * @param ymin the value of y corresponding to the first element of values
116 * @param ymax the value of y corresponding to the last element of values
117 */
118 public void setFunctionParameters(PointerByReference values, int xsize, int ysize,
119 double xmin, double xmax, double ymin, double ymax) {
120 OpenMM_Continuous2DFunction_setFunctionParameters(pointer, xsize, ysize, values, xmin, xmax, ymin, ymax);
121 }
122 }