CustomBondForce.cpp 5.13 KB
Newer Older
1
2
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
/* -------------------------------------------------------------------------- *
 *                                   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-2009 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 "openmm/Force.h"
#include "openmm/OpenMMException.h"
#include "openmm/CustomBondForce.h"
35
#include "openmm/internal/AssertionUtilities.h"
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "openmm/internal/CustomBondForceImpl.h"
#include <cmath>
#include <map>
#include <sstream>
#include <utility>

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

CustomBondForce::CustomBondForce(const string& energy) : energyExpression(energy) {
}

const string& CustomBondForce::getEnergyFunction() const {
    return energyExpression;
}

void CustomBondForce::setEnergyFunction(const std::string& energy) {
    energyExpression = energy;
}

int CustomBondForce::addPerBondParameter(const string& name) {
    parameters.push_back(BondParameterInfo(name));
    return parameters.size()-1;
}

const string& CustomBondForce::getPerBondParameterName(int index) const {
64
    ASSERT_VALID_INDEX(index, parameters);
65
66
67
68
    return parameters[index].name;
}

void CustomBondForce::setPerBondParameterName(int index, const string& name) {
69
    ASSERT_VALID_INDEX(index, parameters);
70
71
72
73
74
75
76
77
78
    parameters[index].name = name;
}

int CustomBondForce::addGlobalParameter(const string& name, double defaultValue) {
    globalParameters.push_back(GlobalParameterInfo(name, defaultValue));
    return globalParameters.size()-1;
}

const string& CustomBondForce::getGlobalParameterName(int index) const {
79
    ASSERT_VALID_INDEX(index, globalParameters);
80
81
82
83
    return globalParameters[index].name;
}

void CustomBondForce::setGlobalParameterName(int index, const string& name) {
84
    ASSERT_VALID_INDEX(index, globalParameters);
85
86
87
88
    globalParameters[index].name = name;
}

double CustomBondForce::getGlobalParameterDefaultValue(int index) const {
89
    ASSERT_VALID_INDEX(index, globalParameters);
90
91
92
93
    return globalParameters[index].defaultValue;
}

void CustomBondForce::setGlobalParameterDefaultValue(int index, double defaultValue) {
94
    ASSERT_VALID_INDEX(index, globalParameters);
95
96
97
98
99
100
101
102
103
    globalParameters[index].defaultValue = defaultValue;
}

int CustomBondForce::addBond(int particle1, int particle2, const vector<double>& parameters) {
    bonds.push_back(BondInfo(particle1, particle2, parameters));
    return bonds.size()-1;
}

void CustomBondForce::getBondParameters(int index, int& particle1, int& particle2, std::vector<double>& parameters) const {
104
    ASSERT_VALID_INDEX(index, bonds);
105
106
107
108
109
110
    particle1 = bonds[index].particle1;
    particle2 = bonds[index].particle2;
    parameters = bonds[index].parameters;
}

void CustomBondForce::setBondParameters(int index, int particle1, int particle2, const vector<double>& parameters) {
111
    ASSERT_VALID_INDEX(index, bonds);
112
113
114
115
116
117
118
119
120
    bonds[index].parameters = parameters;
    bonds[index].particle1 = particle1;
    bonds[index].particle2 = particle2;
}

ForceImpl* CustomBondForce::createImpl() {
    return new CustomBondForceImpl(*this);
}