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.openmm;
39  
40  import com.sun.jna.ptr.DoubleByReference;
41  import com.sun.jna.ptr.IntByReference;
42  
43  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_addParticle;
44  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_create;
45  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_createExceptionsFromBonds;
46  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_destroy;
47  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_getExceptionParameters;
48  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_getNumExceptions;
49  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_getParticleParameters;
50  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setCutoffDistance;
51  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setExceptionParameters;
52  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setNonbondedMethod;
53  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setPMEParameters;
54  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setParticleParameters;
55  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setSwitchingDistance;
56  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setUseDispersionCorrection;
57  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_setUseSwitchingFunction;
58  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_NonbondedForce_updateParametersInContext;
59  
60  /**
61   * Nonbonded Force.
62   */
63  public class NonbondedForce extends Force {
64  
65    public NonbondedForce() {
66      pointer = OpenMM_NonbondedForce_create();
67    }
68  
69    /**
70     * Add a particle.
71     *
72     * @param charge The atomic charge.
73     * @param sigma  The vdW sigma.
74     * @param eps    The vdW eps.
75     */
76    public void addParticle(double charge, double sigma, double eps) {
77      OpenMM_NonbondedForce_addParticle(pointer, charge, sigma, eps);
78    }
79  
80    /**
81     * Set the particle parameters.
82     *
83     * @param index  The particle index.
84     * @param charge The atomic charge.
85     * @param sigma  The vdW sigma.
86     * @param eps    The vdW eps.
87     */
88    public void setParticleParameters(int index, double charge, double sigma, double eps) {
89      OpenMM_NonbondedForce_setParticleParameters(pointer, index, charge, sigma, eps);
90    }
91  
92    /**
93     * Get the particle parameters.
94     *
95     * @param index  The particle index.
96     * @param charge The atomic charge.
97     * @param sigma  The vdW sigma.
98     * @param eps    The vdW eps.
99     */
100   public void getParticleParameters(int index, DoubleByReference charge, DoubleByReference sigma, DoubleByReference eps) {
101     OpenMM_NonbondedForce_getParticleParameters(pointer, index, charge, sigma, eps);
102   }
103 
104   /**
105    * Create exceptions from bonds.
106    *
107    * @param bondArray      The bond array.
108    * @param coulomb14Scale The coulomb 1-4 scale.
109    * @param lj14Scale      The LJ 1-4 scale.
110    */
111   public void createExceptionsFromBonds(BondArray bondArray, double coulomb14Scale, double lj14Scale) {
112     OpenMM_NonbondedForce_createExceptionsFromBonds(pointer, bondArray.getPointer(), coulomb14Scale, lj14Scale);
113   }
114 
115   /**
116    * Get the exception parameters.
117    *
118    * @param index      The exception index.
119    * @param particle1  The first particle.
120    * @param particle2  The second particle.
121    * @param chargeProd The charge product.
122    * @param sigma      The sigma vdW parameter.
123    * @param eps        The eps vdW parameter.
124    */
125   public void getExceptionParameters(int index, IntByReference particle1, IntByReference particle2,
126                                      DoubleByReference chargeProd, DoubleByReference sigma, DoubleByReference eps) {
127     OpenMM_NonbondedForce_getExceptionParameters(pointer, index, particle1, particle2, chargeProd, sigma, eps);
128   }
129 
130   /**
131    * Set the exception parameters.
132    *
133    * @param index      The exception index.
134    * @param particle1  The first particle.
135    * @param particle2  The second particle.
136    * @param chargeProd The charge product.
137    * @param sigma      The sigma vdW parameter.
138    * @param eps        The eps vdW parameter.
139    */
140   public void setExceptionParameters(int index, int particle1, int particle2, double chargeProd, double sigma, double eps) {
141     OpenMM_NonbondedForce_setExceptionParameters(pointer, index, particle1, particle2, chargeProd, sigma, eps);
142   }
143 
144   /**
145    * Set the nonbonded method.
146    *
147    * @param method The nonbonded method.
148    */
149   public void setNonbondedMethod(int method) {
150     OpenMM_NonbondedForce_setNonbondedMethod(pointer, method);
151   }
152 
153   /**
154    * Set the PME parameters.
155    *
156    * @param aEwald The Ewald alpha.
157    * @param nx     The PME grid size in x.
158    * @param ny     The PME grid size in y.
159    * @param nz     The PME grid size in z.
160    */
161   public void setPMEParameters(double aEwald, int nx, int ny, int nz) {
162     OpenMM_NonbondedForce_setPMEParameters(pointer, aEwald, nx, ny, nz);
163   }
164 
165   /**
166    * Set the cutoff distance.
167    *
168    * @param cutoffDistance The cutoff distance.
169    */
170   public void setCutoffDistance(double cutoffDistance) {
171     OpenMM_NonbondedForce_setCutoffDistance(pointer, cutoffDistance);
172   }
173 
174   /**
175    * Set if a switching function will be used.
176    *
177    * @param useSwitchingFunction The switching distance flag.
178    */
179   public void setUseSwitchingFunction(int useSwitchingFunction) {
180     OpenMM_NonbondedForce_setUseSwitchingFunction(pointer, useSwitchingFunction);
181   }
182 
183   /**
184    * Set the switching distance.
185    *
186    * @param switchingDistance The switching distance.
187    */
188   public void setSwitchingDistance(double switchingDistance) {
189     OpenMM_NonbondedForce_setSwitchingDistance(pointer, switchingDistance);
190   }
191 
192   /**
193    * Set if a dispersion correction will be used.
194    *
195    * @param useDispersionCorrection The dispersion correction flag.
196    */
197   public void setUseDispersionCorrection(int useDispersionCorrection) {
198     OpenMM_NonbondedForce_setUseDispersionCorrection(pointer, useDispersionCorrection);
199   }
200 
201   /**
202    * Get the number of exceptions.
203    *
204    * @return The number of exceptions.
205    */
206   public int getNumExceptions() {
207     return OpenMM_NonbondedForce_getNumExceptions(pointer);
208   }
209 
210   /**
211    * Update the parameters in the OpenMM Context.
212    *
213    * @param context The OpenMM Context.
214    */
215   public void updateParametersInContext(Context context) {
216     if (context.hasContextPointer()) {
217       OpenMM_NonbondedForce_updateParametersInContext(pointer, context.getPointer());
218     }
219   }
220 
221   public void destroy() {
222     if (pointer != null) {
223       OpenMM_NonbondedForce_destroy(pointer);
224       pointer = null;
225     }
226   }
227 
228 }