AmoebaBondForce.h 6.83 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 "openmm/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
51
52
 * a bond has been added, you can modify its force field parameters by calling setBondParameters().
 */

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

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

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

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

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

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

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

    /**
     * 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
102
     * @param k             the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
103
104
     * @return the index of the bond that was added
     */
105
106

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

    /**
     * Get the force field parameters for a bond term.
     * 
111
112
113
114
     * @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
115
     * @param quadratic k   the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
116
     */
117
118

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

    /**
     * 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
127
     * @param k         the quadratic force constant for the bond
Mark Friedrichs's avatar
Mark Friedrichs committed
128
     */
129
    void setBondParameters(int index, int particle1, int particle2, double length, double quadraticK );
130
131
132
133
134
135
136
137
138
139
    /**
     * 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);
Mark Friedrichs's avatar
Mark Friedrichs committed
140
141
142
143
144
145
146
147
148

protected:
    double _globalQuarticK, _globalCubicK;
    ForceImpl* createImpl();
private:
    class BondInfo;
    std::vector<BondInfo> bonds;
};

149
class AmoebaBondForce::BondInfo {
Mark Friedrichs's avatar
Mark Friedrichs committed
150
151
public:
    int particle1, particle2;
152
    double length, quadraticK;
Mark Friedrichs's avatar
Mark Friedrichs committed
153
154
155
156
    BondInfo() {
        particle1 = particle2    = -1;
        length    = quadraticK   = 0.0;
    }
157
158
    BondInfo(int particle1, int particle2, double length, double  quadraticK ) :
        particle1(particle1), particle2(particle2), length(length), quadraticK(quadraticK) {
Mark Friedrichs's avatar
Mark Friedrichs committed
159
160
161
    }
};

162
} // namespace OpenMM
Mark Friedrichs's avatar
Mark Friedrichs committed
163

164
#endif /*OPENMM_AMOEBA_BOND_FORCE_H_*/