AmoebaVdwForce.cpp 9.6 KB
Newer Older
1
2
3
/* -------------------------------------------------------------------------- *
 *                                OpenMMAmoeba                                *
 * -------------------------------------------------------------------------- *
Evan Pretti's avatar
Evan Pretti committed
4
5
 * This is part of the OpenMM molecular simulation toolkit.                   *
 * See https://openmm.org/development.                                        *
6
 *                                                                            *
7
 * Portions copyright (c) 2008-2026 Stanford University and the Authors.      *
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
 * Authors:                                                                   *
 * 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/OpenMMException.h"
#include "openmm/AmoebaVdwForce.h"
#include "openmm/internal/AmoebaVdwForceImpl.h"
34
#include "openmm/internal/AssertionUtilities.h"
35
36
37
38
39

using namespace OpenMM;
using std::string;
using std::vector;

40
41
42
AmoebaVdwForce::AmoebaVdwForce() : nonbondedMethod(NoCutoff), potentialFunction(Buffered147),
        sigmaCombiningRule("CUBIC-MEAN"), epsilonCombiningRule("HHG"), cutoff(1.0e+10), useDispersionCorrection(true),
        useTypes(false), alchemicalMethod(None), n(5), alpha(0.7) {
43
44
}

45
46
47
48
49
50
51
52
53
54
55
56
int AmoebaVdwForce::getNumParticles() const {
    return parameters.size();
}

int AmoebaVdwForce::getNumParticleTypes() const {
    return types.size();
}

int AmoebaVdwForce::getNumTypePairs() const {
    return pairs.size();
}

57
int AmoebaVdwForce::addParticle(int parentIndex, double sigma, double epsilon, double reductionFactor, bool isAlchemical, double scaleFactor) {
58
59
    if (useTypes)
        throw OpenMMException("AmoebaVdwForce: must use the same version of addParticle() for all particles");
60
    parameters.push_back(VdwInfo(parentIndex, sigma, epsilon, -1, reductionFactor, isAlchemical, scaleFactor));
61
62
63
    return parameters.size()-1;
}

64
int AmoebaVdwForce::addParticle(int parentIndex, int typeIndex, double reductionFactor, bool isAlchemical, double scaleFactor) {
65
66
67
    if (parameters.size() > 0 && !useTypes)
        throw OpenMMException("AmoebaVdwForce: must use the same version of addParticle() for all particles");
    useTypes = true;
68
    parameters.push_back(VdwInfo(parentIndex, 1.0, 0.0, typeIndex, reductionFactor, isAlchemical, scaleFactor));
69
70
71
    return parameters.size()-1;
}

72
73
void AmoebaVdwForce::getParticleParameters(int particleIndex, int& parentIndex,double& sigma, double& epsilon, double& reductionFactor,
                                           bool& isAlchemical, int& typeIndex, double& scaleFactor) const {
74
    ASSERT_VALID_INDEX(particleIndex, parameters);
75
    parentIndex     = parameters[particleIndex].parentIndex;
76
77
78
    sigma           = parameters[particleIndex].sigma;
    epsilon         = parameters[particleIndex].epsilon;
    reductionFactor = parameters[particleIndex].reductionFactor;
79
    isAlchemical    = parameters[particleIndex].isAlchemical;
80
    typeIndex       = parameters[particleIndex].typeIndex;
81
    scaleFactor     = parameters[particleIndex].scaleFactor;
82
83
}

84
85
void AmoebaVdwForce::setParticleParameters(int particleIndex, int parentIndex,double sigma, double epsilon, double reductionFactor,
                                           bool isAlchemical, int typeIndex, double scaleFactor) {
86
    ASSERT_VALID_INDEX(particleIndex, parameters);
87
    parameters[particleIndex].parentIndex     = parentIndex;
88
89
90
    parameters[particleIndex].sigma           = sigma;
    parameters[particleIndex].epsilon         = epsilon;
    parameters[particleIndex].reductionFactor = reductionFactor;
91
    parameters[particleIndex].isAlchemical    = isAlchemical;
92
    parameters[particleIndex].typeIndex       = typeIndex;
93
    parameters[particleIndex].scaleFactor     = scaleFactor;
94
95
96
97
98
99
100
101
102
}

int AmoebaVdwForce::addParticleType(double sigma, double epsilon) {
    types.push_back(ParticleTypeInfo(sigma, epsilon));
    return types.size()-1;
}

void AmoebaVdwForce::getParticleTypeParameters(int typeIndex, double& sigma, double& epsilon) const {
    ASSERT_VALID_INDEX(typeIndex, types);
Peter Eastman's avatar
Peter Eastman committed
103
104
    sigma = types[typeIndex].sigma;
    epsilon = types[typeIndex].epsilon;
105
106
107
108
}

void AmoebaVdwForce::setParticleTypeParameters(int typeIndex, double sigma, double epsilon) {
    ASSERT_VALID_INDEX(typeIndex, types);
Peter Eastman's avatar
Peter Eastman committed
109
110
    types[typeIndex].sigma = sigma;
    types[typeIndex].epsilon = epsilon;
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
}

int AmoebaVdwForce::addTypePair(int type1, int type2, double sigma, double epsilon) {
    pairs.push_back(TypePairInfo(type1, type2, sigma, epsilon));
    return pairs.size()-1;
}

void AmoebaVdwForce::getTypePairParameters(int pairIndex, int& type1, int& type2, double& sigma, double& epsilon) const {
    ASSERT_VALID_INDEX(pairIndex, pairs);
    type1 = pairs[pairIndex].type1;
    type2 = pairs[pairIndex].type2;
    sigma = pairs[pairIndex].sigma;
    epsilon = pairs[pairIndex].epsilon;
}

void AmoebaVdwForce::setTypePairParameters(int pairIndex, int type1, int type2, double sigma, double epsilon) {
    ASSERT_VALID_INDEX(pairIndex, pairs);
    pairs[pairIndex].type1 = type1;
    pairs[pairIndex].type2 = type2;
    pairs[pairIndex].sigma = sigma;
    pairs[pairIndex].epsilon = epsilon;
132
133
}

134
void AmoebaVdwForce::setSigmaCombiningRule(const std::string& inputSigmaCombiningRule) {
135
136
137
    sigmaCombiningRule = inputSigmaCombiningRule;
}

peastman's avatar
peastman committed
138
const std::string& AmoebaVdwForce::getSigmaCombiningRule() const {
139
140
141
    return sigmaCombiningRule;
}

142
void AmoebaVdwForce::setEpsilonCombiningRule(const std::string& inputEpsilonCombiningRule) {
143
144
145
    epsilonCombiningRule = inputEpsilonCombiningRule;
}

peastman's avatar
peastman committed
146
const std::string& AmoebaVdwForce::getEpsilonCombiningRule() const {
147
148
149
    return epsilonCombiningRule;
}

150
void AmoebaVdwForce::setParticleExclusions(int particleIndex, const std::vector< int >& inputExclusions) {
151

152
153
   if (exclusions.size() < parameters.size()) {
       exclusions.resize(parameters.size());
154
   }
155
156
   if (static_cast<int>(exclusions.size()) < particleIndex) {
       exclusions.resize(particleIndex + 10);
157
   }
158
159
   for (unsigned int ii = 0; ii < inputExclusions.size(); ii++) {
       exclusions[particleIndex].push_back(inputExclusions[ii]);
160
161
162
   }
}

163
void AmoebaVdwForce::getParticleExclusions(int particleIndex, std::vector< int >& outputExclusions) const {
164

165
166
167
   if (particleIndex < static_cast<int>(exclusions.size())) {
       outputExclusions.resize(exclusions[particleIndex].size());
       for (unsigned int ii = 0; ii < exclusions[particleIndex].size(); ii++) {
168
169
170
171
172
173
           outputExclusions[ii] = exclusions[particleIndex][ii];
       }
   }

}

peastman's avatar
peastman committed
174
175
176
177
178
double AmoebaVdwForce::getCutoffDistance() const {
    return cutoff;
}

void AmoebaVdwForce::setCutoffDistance(double inputCutoff) {
179
180
181
    cutoff = inputCutoff;
}

peastman's avatar
peastman committed
182
183
184
185
void AmoebaVdwForce::setCutoff(double inputCutoff) {
    setCutoffDistance(inputCutoff);
}

186
double AmoebaVdwForce::getCutoff() const {
peastman's avatar
peastman committed
187
    return getCutoffDistance();
188
189
}

190
191
AmoebaVdwForce::NonbondedMethod AmoebaVdwForce::getNonbondedMethod() const {
    return nonbondedMethod;
192
193
}

194
void AmoebaVdwForce::setNonbondedMethod(NonbondedMethod method) {
195
196
    if (method < 0 || method > 1)
        throw OpenMMException("AmoebaVdwForce: Illegal value for nonbonded method");
197
    nonbondedMethod = method;
198
199
}

200
201
202
203
204
205
206
207
208
209
AmoebaVdwForce::AlchemicalMethod AmoebaVdwForce::getAlchemicalMethod() const {
    return alchemicalMethod;
}

void AmoebaVdwForce::setAlchemicalMethod(AlchemicalMethod method) {
    if (method < 0 || method > 2)
        throw OpenMMException("AmoebaVdwForce: Illegal value for alchemical method");
    alchemicalMethod = method;
}

210
void AmoebaVdwForce::setSoftcorePower(int power) {
211
212
213
    n = power;
}

214
int AmoebaVdwForce::getSoftcorePower() const {
215
216
217
218
219
220
221
222
223
224
225
226
    return n;
}

void AmoebaVdwForce::setSoftcoreAlpha(double a) {
    alpha = a;
}

double AmoebaVdwForce::getSoftcoreAlpha() const {
    return alpha;
}


227
ForceImpl* AmoebaVdwForce::createImpl() const {
228
229
230
    return new AmoebaVdwForceImpl(*this);
}

231
232
233
void AmoebaVdwForce::updateParametersInContext(Context& context) {
    dynamic_cast<AmoebaVdwForceImpl&>(getImplInContext(context)).updateParametersInContext(getContextImpl(context));
}