AmoebaBondForce.h 7.26 KB
Newer Older
1
2
#ifndef OPENMM_AMOEBA_BOND_FORCE_H_
#define OPENMM_AMOEBA_BOND_FORCE_H_
Mark Friedrichs's avatar
Mark Friedrichs committed
3
4

/* -------------------------------------------------------------------------- *
5
 *                              OpenMMAmoeba                                  *
Mark Friedrichs's avatar
Mark Friedrichs committed
6
7
8
9
10
11
 * -------------------------------------------------------------------------- *
 * 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.               *
 *                                                                            *
12
13
 * Portions copyright (c) 2008-2012 Stanford University and the Authors.      *
 * Authors: Mark Friedrichs, Peter Eastman                                    *
Mark Friedrichs's avatar
Mark Friedrichs committed
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 * 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 "openmm/Force.h"
#include "openmm/Vec3.h"
37
#include "internal/windowsExportAmoeba.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
38
39
40
41
42
43
#include <map>
#include <vector>

namespace OpenMM {

/**
44
45
46
47
48
 * This class implements an interaction between pairs of particles that varies with the distance
 * between them.  The interaction is defined by a 4th order polynomial.  Only the quadratic term
 * is set per-bond.  The coefficients of the higher order terms each have a single value that
 * is set globally.
 * 
49
 * To use it, create an AmoebaBondForce object then call addBond() once for each bond.  After
Mark Friedrichs's avatar
Mark Friedrichs committed
50
 * a bond has been added, you can modify its force field parameters by calling setBondParameters().
51
 * This will have no effect on Contexts that already exist unless you call updateParametersInContext().
Mark Friedrichs's avatar
Mark Friedrichs committed
52
53
 */

54
class OPENMM_EXPORT_AMOEBA AmoebaBondForce : public Force {
Mark Friedrichs's avatar
Cleanup  
Mark Friedrichs committed
55

Mark Friedrichs's avatar
Mark Friedrichs committed
56
public:
Mark Friedrichs's avatar
Cleanup  
Mark Friedrichs committed
57

Mark Friedrichs's avatar
Mark Friedrichs committed
58
    /**
59
     * Create an AmoebaBondForce.
Mark Friedrichs's avatar
Mark Friedrichs committed
60
     */
61
    AmoebaBondForce();
Mark Friedrichs's avatar
Mark Friedrichs committed
62
    /**
63
     * Get the number of bond stretch terms in the potential function
Mark Friedrichs's avatar
Mark Friedrichs committed
64
65
66
67
68
69
70
71
     */
    int getNumBonds() const {
        return bonds.size();
    }

    /**
     * Set the global cubic term
     * 
72
     * @param cubicK        the cubic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
73
     */
74
    void setAmoebaGlobalBondCubic( double cubicK );
Mark Friedrichs's avatar
Mark Friedrichs committed
75
76
77
78
79
80

    /**
     * Get the global cubic term
     * 
     * @return global cubicK term
     */
peastman's avatar
peastman committed
81
    double getAmoebaGlobalBondCubic() const;
Mark Friedrichs's avatar
Mark Friedrichs committed
82
83

    /**
84
     * Set the global quartic term
Mark Friedrichs's avatar
Mark Friedrichs committed
85
     * 
86
     * @param quarticK       the quartic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
87
     */
88
    void setAmoebaGlobalBondQuartic( double quarticK );
Mark Friedrichs's avatar
Mark Friedrichs committed
89
90
91
92
93
94

    /**
     * Get the global quartic term
     * 
     * @return global  quartic term
     */
peastman's avatar
peastman committed
95
    double getAmoebaGlobalBondQuartic() const;
Mark Friedrichs's avatar
Mark Friedrichs committed
96
97
98
99
100
101
102

    /**
     * Add a bond term to the force field.
     *
     * @param particle1     the index of the first particle connected by the bond
     * @param particle2     the index of the second particle connected by the bond
     * @param length        the equilibrium length of the bond, measured in nm
103
     * @param k             the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
104
105
     * @return the index of the bond that was added
     */
106
107

    int addBond(int particle1, int particle2, double length, double quadraticK );
Mark Friedrichs's avatar
Mark Friedrichs committed
108
109
110
111

    /**
     * Get the force field parameters for a bond term.
     * 
112
113
114
115
     * @param index         the index of the bond for which to get parameters
     * @param particle1     the index of the first particle connected by the bond
     * @param particle2     the index of the second particle connected by the bond
     * @param length        the equilibrium length of the bond, measured in nm
116
     * @param quadratic k   the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
117
     */
118
119

    void getBondParameters(int index, int& particle1, int& particle2, double& length, double& quadraticK ) const;
Mark Friedrichs's avatar
Mark Friedrichs committed
120
121
122
123
124
125
126
127

    /**
     * Set the force field parameters for a bond term.
     * 
     * @param index     the index of the bond for which to set parameters
     * @param particle1 the index of the first particle connected by the bond
     * @param particle2 the index of the second particle connected by the bond
     * @param length    the equilibrium length of the bond, measured in nm
128
     * @param k         the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
129
     */
130
    void setBondParameters(int index, int particle1, int particle2, double length, double quadraticK );
131
132
133
134
135
136
137
138
139
140
    /**
     * Update the per-bond parameters in a Context to match those stored in this Force object.  This method provides
     * an efficient method to update certain parameters in an existing Context without needing to reinitialize it.
     * Simply call setBondParameters() to modify this object's parameters, then call updateParametersInState()
     * to copy them over to the Context.
     * 
     * The only information this method updates is the values of per-bond parameters.  The set of particles involved
     * in a bond cannot be changed, nor can new bonds be added.
     */
    void updateParametersInContext(Context& context);
141
142
143
144
145
146
    /**
     * Returns whether or not this force makes use of periodic boundary
     * conditions.
     *
     * @returns true if nonbondedMethod uses PBC and false otherwise
     */
147
148
149
    bool usesPeriodicBoundaryConditions() const {
        return false;
    }
Mark Friedrichs's avatar
Mark Friedrichs committed
150
151
protected:
    double _globalQuarticK, _globalCubicK;
152
    ForceImpl* createImpl() const;
Mark Friedrichs's avatar
Mark Friedrichs committed
153
154
155
156
157
private:
    class BondInfo;
    std::vector<BondInfo> bonds;
};

158
159
160
161
/**
 * This is an internal class used to record information about a bond.
 * @private
 */
162
class AmoebaBondForce::BondInfo {
Mark Friedrichs's avatar
Mark Friedrichs committed
163
164
public:
    int particle1, particle2;
165
    double length, quadraticK;
Mark Friedrichs's avatar
Mark Friedrichs committed
166
167
168
169
    BondInfo() {
        particle1 = particle2    = -1;
        length    = quadraticK   = 0.0;
    }
170
171
    BondInfo(int particle1, int particle2, double length, double  quadraticK ) :
        particle1(particle1), particle2(particle2), length(length), quadraticK(quadraticK) {
Mark Friedrichs's avatar
Mark Friedrichs committed
172
173
174
    }
};

175
} // namespace OpenMM
Mark Friedrichs's avatar
Mark Friedrichs committed
176

177
#endif /*OPENMM_AMOEBA_BOND_FORCE_H_*/