NonbondedForce.h 11 KB
Newer Older
1
2
#ifndef OPENMM_NONBONDEDFORCE_H_
#define OPENMM_NONBONDEDFORCE_H_
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
 * This is part of the OpenMM molecular simulation toolkit originating from   *
 * Simbios, the NIH National Center for Physics-Based Simulation of           *
 * Biological Structures at Stanford, funded under the NIH Roadmap for        *
 * Medical Research, grant U54 GM072970. See https://simtk.org.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * Authors: Peter Eastman                                                     *
 * Contributors:                                                              *
 *                                                                            *
 * Permission is hereby granted, free of charge, to any person obtaining a    *
 * copy of this software and associated documentation files (the "Software"), *
 * to deal in the Software without restriction, including without limitation  *
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
 * and/or sell copies of the Software, and to permit persons to whom the      *
 * Software is furnished to do so, subject to the following conditions:       *
 *                                                                            *
 * The above copyright notice and this permission notice shall be included in *
 * all copies or substantial portions of the Software.                        *
 *                                                                            *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
 * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
 * -------------------------------------------------------------------------- */

#include "Force.h"
36
#include "Vec3.h"
37
38
#include <map>
#include <vector>
39
#include "internal/windowsExport.h"
40
41
42
43

namespace OpenMM {

/**
44
45
46
 * This class implements nonbonded interactions between particles, including a Coulomb force to represent
 * electrostatics and a Lennard-Jones force to represent van der Waals interactions.  It optionally supports
 * periodic boundary conditions and cutoffs for long range interactions.
47
 * 
48
49
50
51
52
53
54
55
56
 * If the System also contains a HarmonicBondForce, nonbonded interactions are automatically excluded between
 * particles which are separated by three or fewer bonds.  Most molecular force fields omit Coulomb and
 * Lennard-Jones interactions between particles separated by one or two bonds, while using modified parameters
 * for those separated by three bonds (known as "1-4 interactions").  This class lets you provide a list of
 * 1-4 interactions to include in the potential, along with the parameters to use for each one.
 * 
 * When creating a NonbondedForce, you specify the number of atoms and the number of 1-4 interactions as
 * arguments to the constructor.  You then loop over them and call setAtomParameters() for each atom and
 * setNonbond14Parameters() for each 1-4 interaction.
57
58
 */

59
class OPENMM_EXPORT NonbondedForce : public Force {
60
public:
61
62
63
64
65
66
    /**
     * This is an enumeration of the different methods that may be used for handling long range nonbonded forces.
     */
    enum NonbondedMethod {
        /**
         * No cutoff is applied to nonbonded interactions.  The full set of N^2 interactions is computed exactly.
67
         * This necessarily means that periodic boundary conditions cannot be used.  This is the default.
68
69
70
71
         */
        NoCutoff = 0,
        /**
         * Interactions beyond the cutoff distance are ignored.  Coulomb interactions closer than the cutoff distance
72
         * are modified using the reaction field method.
73
74
75
76
77
         */
        CutoffNonPeriodic = 1,
        /**
         * Periodic boundary conditions are used, so that each atom interacts only with the nearest periodic copy of
         * each other atom.  Interactions beyond the cutoff distance are ignored.  Coulomb interactions closer than the
78
         * cutoff distance are modified using the reaction field method.
79
80
81
         */
        CutoffPeriodic = 2
    };
82
    /**
83
     * Create a NonbondedForce.
84
85
     * 
     * @param numAtoms            the number of atoms in the system
86
     * @param numNonbonded14      the number of nonbonded 1-4 terms in the potential function
87
     */
88
    NonbondedForce(int numAtoms, int numNonbonded14);
89
90
91
92
93
94
    /**
     * Get the number of atoms in the system.
     */
    int getNumAtoms() const {
        return atoms.size();
    }
95
96
97
98
99
100
    /**
     * Get the number of nonbonded 1-4 terms in the potential function
     */
    int getNumNonbonded14() const {
        return nb14s.size();
    }
101
102
103
    /**
     * Get the method used for handling long range nonbonded interactions.
     */
104
    NonbondedMethod getNonbondedMethod() const;
105
106
107
108
109
110
111
112
    /**
     * Set the method used for handling long range nonbonded interactions.
     */
    void setNonbondedMethod(NonbondedMethod method);
    /**
     * Get the cutoff distance (in nm) being used for nonbonded interactions.  If the NonbondedMethod in use
     * does not use cutoffs, this value will have no effect.
     */
113
    double getCutoffDistance() const;
114
115
116
117
118
119
    /**
     * Set the cutoff distance (in nm) being used for nonbonded interactions.  If the NonbondedMethod in use
     * does not use cutoffs, this value will have no effect.
     */
    void setCutoffDistance(double distance);
    /**
120
121
     * Get the vectors which define the axes of the periodic box (measured in nm).  If the NonbondedMethod
     * in use does not use periodic boundary conditions, these values will have no effect.
122
     *
123
124
125
126
127
128
     * Currently, only rectangular boxes are supported.  This means that a, b, and c must be aligned with the
     * x, y, and z axes respectively.  Future releases may support arbitrary triclinic boxes.
     *
     * @param a      on exit, this contains the vector defining the first edge of the periodic box
     * @param b      on exit, this contains the vector defining the second edge of the periodic box
     * @param c      on exit, this contains the vector defining the third edge of the periodic box
129
     */
130
    void getPeriodicBoxVectors(Vec3& a, Vec3& b, Vec3& c) const;
131
    /**
132
133
134
135
136
     * Set the vectors which define the axes of the periodic box (measured in nm).  If the NonbondedMethod
     * in use does not use periodic boundary conditions, these values will have no effect.
     *
     * Currently, only rectangular boxes are supported.  This means that a, b, and c must be aligned with the
     * x, y, and z axes respectively.  Future releases may support arbitrary triclinic boxes.
137
     *
138
139
140
     * @param a      the vector defining the first edge of the periodic box
     * @param b      the vector defining the second edge of the periodic box
     * @param c      the vector defining the third edge of the periodic box
141
     */
142
    void setPeriodicBoxVectors(Vec3 a, Vec3 b, Vec3 c);
143
144
145
146
147
    /**
     * Get the nonbonded force parameters for an atom.
     * 
     * @param index     the index of the atom for which to get parameters
     * @param charge    the charge of the atom, measured in units of the proton charge
148
149
     * @param radius    the van der Waals radius of the atom, measured in nm
     * @param depth     the well depth of the van der Waals interaction, measured in kJ/mol
150
151
152
153
154
155
156
     */
    void getAtomParameters(int index, double& charge, double& radius, double& depth) const;
    /**
     * Set the nonbonded force parameters for an atom.
     * 
     * @param index     the index of the atom for which to set parameters
     * @param charge    the charge of the atom, measured in units of the proton charge
157
158
     * @param radius    the van der Waals radius of the atom (sigma in the Lennard Jones potential), measured in nm
     * @param depth     the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
159
160
     */
    void setAtomParameters(int index, double charge, double radius, double depth);
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
    /**
     * Get the force field parameters for a nonbonded 1-4 term.
     * 
     * @param index     the index of the interaction for which to get parameters
     * @param atom1     the index of the first atom involved in the interaction
     * @param atom2     the index of the second atom involved in the interaction
     * @param charge    the scaled product of the atomic charges (i.e. the strength of the Coulomb interaction), measured in units of the proton charge
     * @param radius    the van der Waals radius of the atom (sigma in the Lennard Jones potential), measured in nm
     * @param depth     the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
     */
    void getNonbonded14Parameters(int index, int& atom1, int& atom2, double& charge, double& radius, double& depth) const;
    /**
     * Set the force field parameters for a nonbonded 1-4 term.
     * 
     * @param index     the index of the interaction for which to get parameters
     * @param atom1     the index of the first atom involved in the interaction
     * @param atom2     the index of the second atom involved in the interaction
     * @param charge    the scaled product of the atomic charges (i.e. the strength of the Coulomb interaction), measured in units of the proton charge
     * @param radius    the van der Waals radius of the atom (sigma in the Lennard Jones potential), measured in nm
     * @param depth     the well depth of the van der Waals interaction (epsilon in the Lennard Jones potential), measured in kJ/mol
     */
    void setNonbonded14Parameters(int index, int atom1, int atom2, double charge, double radius, double depth);
183
protected:
184
    ForceImpl* createImpl();
185
186
private:
    class AtomInfo;
187
    class NB14Info;
188
189
    NonbondedMethod nonbondedMethod;
    double cutoffDistance;
190
    Vec3 periodicBoxVectors[3];
191

192
193
194
195
196
197
// Retarded visual studio compiler complains about being unable to 
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
198
#endif
199
    std::vector<AtomInfo> atoms;
200
    std::vector<NB14Info> nb14s;
201
202
203
204
#if defined(_MSC_VER)
#pragma warning(pop)
#endif

205
206
};

207
class NonbondedForce::AtomInfo {
208
209
210
211
212
213
214
public:
    double charge, radius, depth;
    AtomInfo() {
        charge = radius = depth = 0.0;
    }
};

215
class NonbondedForce::NB14Info {
216
217
218
219
220
221
222
223
224
public:
    int atom1, atom2;
    double charge, radius, depth;
    NB14Info() {
        atom1 = atom2 = -1;
        charge = radius = depth = 0.0;
    }
};

225
226
} // namespace OpenMM

227
#endif /*OPENMM_NONBONDEDFORCE_H_*/