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 static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_addExclusion;
41  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_addGlobalParameter;
42  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_addInteractionGroup;
43  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_addParticle;
44  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_addPerParticleParameter;
45  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_create;
46  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_destroy;
47  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_setCutoffDistance;
48  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_setNonbondedMethod;
49  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_setSwitchingDistance;
50  import static edu.uiowa.jopenmm.OpenMMLibrary.OpenMM_CustomNonbondedForce_setUseSwitchingFunction;
51  
52  /**
53   * Custom Non-bonded Force.
54   */
55  public class CustomNonbondedForce extends Force {
56  
57    public CustomNonbondedForce(String energy) {
58      pointer = OpenMM_CustomNonbondedForce_create(energy);
59    }
60  
61    /**
62     * Add a global parameter.
63     *
64     * @param name  The parameter name.
65     * @param value The parameter value.
66     */
67    public void addGlobalParameter(String name, double value) {
68      OpenMM_CustomNonbondedForce_addGlobalParameter(pointer, name, value);
69    }
70  
71    /**
72     * Add a per particle parameter.
73     *
74     * @param name The parameter name.
75     */
76    public void addPerParticleParameter(String name) {
77      OpenMM_CustomNonbondedForce_addPerParticleParameter(pointer, name);
78    }
79  
80    /**
81     * Add a particle to the force.
82     *
83     * @param parameters The particle parameters.
84     */
85    public void addParticle(DoubleArray parameters) {
86      OpenMM_CustomNonbondedForce_addParticle(pointer, parameters.getPointer());
87    }
88  
89    /**
90     * Add an interaction group.
91     *
92     * @param group1 The first group.
93     * @param group2 The second group.
94     */
95    public void addInteractionGroup(IntSet group1, IntSet group2) {
96      OpenMM_CustomNonbondedForce_addInteractionGroup(pointer, group1.getPointer(), group2.getPointer());
97    }
98  
99    /**
100    * Set the nonbonded method.
101    *
102    * @param method The nonbonded method.
103    */
104   public void setNonbondedMethod(int method) {
105     OpenMM_CustomNonbondedForce_setNonbondedMethod(pointer, method);
106   }
107 
108   /**
109    * Set the cutoff distance.
110    *
111    * @param off The cutoff distance.
112    */
113   public void setCutoffDistance(double off) {
114     OpenMM_CustomNonbondedForce_setCutoffDistance(pointer, off);
115   }
116 
117   /**
118    * Flag to contol use of a switching function.
119    *
120    * @param useSwitchingFunction If 1, the switching function is used.
121    */
122   public void setUseSwitchingFunction(int useSwitchingFunction) {
123     OpenMM_CustomNonbondedForce_setUseSwitchingFunction(pointer, useSwitchingFunction);
124   }
125 
126   /**
127    * Set the switching distance.
128    *
129    * @param switchingDistance The switching distance.
130    */
131   public void setSwitchingDistance(double switchingDistance) {
132     OpenMM_CustomNonbondedForce_setSwitchingDistance(pointer, switchingDistance);
133   }
134 
135   /**
136    * Add an exclusion.
137    *
138    * @param particle1 The first particle.
139    * @param particle2 The second particle.
140    */
141   public void addExclusion(int particle1, int particle2) {
142     OpenMM_CustomNonbondedForce_addExclusion(pointer, particle1, particle2);
143   }
144 
145   /**
146    * Destroy the force.
147    */
148   public void destroy() {
149     if (pointer != null) {
150       OpenMM_CustomNonbondedForce_destroy(pointer);
151       pointer = null;
152     }
153   }
154 }