"platforms/opencl/vscode:/vscode.git/clone" did not exist on "caa4fc5a4e0b73270b8ab6caa726272396eac3b7"
AmoebaVdwForce.cpp 9.3 KB
Newer Older
1
2
3
4
5
6
7
8
/* -------------------------------------------------------------------------- *
 *                                OpenMMAmoeba                                *
 * -------------------------------------------------------------------------- *
 * 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.               *
 *                                                                            *
9
 * Portions copyright (c) 2008-2020 Stanford University and the Authors.      *
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
 * 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"
36
#include "openmm/internal/AssertionUtilities.h"
37
38
39
40
41

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

42
43
44
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) {
45
46
}

47
int AmoebaVdwForce::addParticle(int parentIndex, double sigma, double epsilon, double reductionFactor, bool isAlchemical) {
48
49
50
51
52
53
54
55
56
57
58
    if (useTypes)
        throw OpenMMException("AmoebaVdwForce: must use the same version of addParticle() for all particles");
    parameters.push_back(VdwInfo(parentIndex, sigma, epsilon, -1, reductionFactor, isAlchemical));
    return parameters.size()-1;
}

int AmoebaVdwForce::addParticle(int parentIndex, int typeIndex, double reductionFactor, bool isAlchemical) {
    if (parameters.size() > 0 && !useTypes)
        throw OpenMMException("AmoebaVdwForce: must use the same version of addParticle() for all particles");
    useTypes = true;
    parameters.push_back(VdwInfo(parentIndex, 1.0, 0.0, typeIndex, reductionFactor, isAlchemical));
59
60
61
    return parameters.size()-1;
}

62
void AmoebaVdwForce::getParticleParameters(int particleIndex, int& parentIndex,
63
64
                                           double& sigma, double& epsilon, double& reductionFactor, bool& isAlchemical, int& typeIndex) const {
    ASSERT_VALID_INDEX(particleIndex, parameters);
65
    parentIndex     = parameters[particleIndex].parentIndex;
66
67
68
    sigma           = parameters[particleIndex].sigma;
    epsilon         = parameters[particleIndex].epsilon;
    reductionFactor = parameters[particleIndex].reductionFactor;
69
    isAlchemical    = parameters[particleIndex].isAlchemical;
70
    typeIndex       = parameters[particleIndex].typeIndex;
71
72
}

73
void AmoebaVdwForce::setParticleParameters(int particleIndex, int parentIndex,
74
75
                                           double sigma, double epsilon, double reductionFactor, bool isAlchemical, int typeIndex) {
    ASSERT_VALID_INDEX(particleIndex, parameters);
76
    parameters[particleIndex].parentIndex     = parentIndex;
77
78
79
    parameters[particleIndex].sigma           = sigma;
    parameters[particleIndex].epsilon         = epsilon;
    parameters[particleIndex].reductionFactor = reductionFactor;
80
    parameters[particleIndex].isAlchemical    = isAlchemical;
81
82
83
84
85
86
87
88
89
90
    parameters[particleIndex].typeIndex       = typeIndex;
}

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
91
92
    sigma = types[typeIndex].sigma;
    epsilon = types[typeIndex].epsilon;
93
94
95
96
}

void AmoebaVdwForce::setParticleTypeParameters(int typeIndex, double sigma, double epsilon) {
    ASSERT_VALID_INDEX(typeIndex, types);
Peter Eastman's avatar
Peter Eastman committed
97
98
    types[typeIndex].sigma = sigma;
    types[typeIndex].epsilon = epsilon;
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
}

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;
120
121
}

122
void AmoebaVdwForce::setSigmaCombiningRule(const std::string& inputSigmaCombiningRule) {
123
124
125
    sigmaCombiningRule = inputSigmaCombiningRule;
}

peastman's avatar
peastman committed
126
const std::string& AmoebaVdwForce::getSigmaCombiningRule() const {
127
128
129
    return sigmaCombiningRule;
}

130
void AmoebaVdwForce::setEpsilonCombiningRule(const std::string& inputEpsilonCombiningRule) {
131
132
133
    epsilonCombiningRule = inputEpsilonCombiningRule;
}

peastman's avatar
peastman committed
134
const std::string& AmoebaVdwForce::getEpsilonCombiningRule() const {
135
136
137
    return epsilonCombiningRule;
}

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

140
141
   if (exclusions.size() < parameters.size()) {
       exclusions.resize(parameters.size());
142
   }
143
144
   if (static_cast<int>(exclusions.size()) < particleIndex) {
       exclusions.resize(particleIndex + 10);
145
   }
146
147
   for (unsigned int ii = 0; ii < inputExclusions.size(); ii++) {
       exclusions[particleIndex].push_back(inputExclusions[ii]);
148
149
150
   }
}

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

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

}

peastman's avatar
peastman committed
162
163
164
165
166
double AmoebaVdwForce::getCutoffDistance() const {
    return cutoff;
}

void AmoebaVdwForce::setCutoffDistance(double inputCutoff) {
167
168
169
    cutoff = inputCutoff;
}

peastman's avatar
peastman committed
170
171
172
173
void AmoebaVdwForce::setCutoff(double inputCutoff) {
    setCutoffDistance(inputCutoff);
}

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

178
179
AmoebaVdwForce::NonbondedMethod AmoebaVdwForce::getNonbondedMethod() const {
    return nonbondedMethod;
180
181
}

182
void AmoebaVdwForce::setNonbondedMethod(NonbondedMethod method) {
183
184
    if (method < 0 || method > 1)
        throw OpenMMException("AmoebaVdwForce: Illegal value for nonbonded method");
185
    nonbondedMethod = method;
186
187
}

188
189
190
191
192
193
194
195
196
197
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;
}

198
void AmoebaVdwForce::setSoftcorePower(int power) {
199
200
201
    n = power;
}

202
int AmoebaVdwForce::getSoftcorePower() const {
203
204
205
206
207
208
209
210
211
212
213
214
    return n;
}

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

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


215
ForceImpl* AmoebaVdwForce::createImpl() const {
216
217
218
    return new AmoebaVdwForceImpl(*this);
}

219
220
221
void AmoebaVdwForce::updateParametersInContext(Context& context) {
    dynamic_cast<AmoebaVdwForceImpl&>(getImplInContext(context)).updateParametersInContext(getContextImpl(context));
}