"openmmapi/src/LCPOForce.cpp" did not exist on "2f553a66c61be51c2f5ac6021857f5fa48c0b9ba"
VirtualSite.cpp 5.65 KB
Newer Older
Peter Eastman's avatar
Peter Eastman committed
1
2
3
4
5
6
7
8
/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
9
 * Portions copyright (c) 2012-2014 Stanford University and the Authors.      *
Peter Eastman's avatar
Peter Eastman committed
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: 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/VirtualSite.h"
#include "openmm/OpenMMException.h"
34
#include <cmath>
Peter Eastman's avatar
Peter Eastman committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <vector>

using namespace OpenMM;
using namespace std;

void VirtualSite::setParticles(const vector<int>& particleIndices) {
    particles = particleIndices;
}

int VirtualSite::getNumParticles() const {
    return particles.size();
}

int VirtualSite::getParticle(int particle) const {
    return particles[particle];
}

52
TwoParticleAverageSite::TwoParticleAverageSite(int particle1, int particle2, double weight1, double weight2) :
Peter Eastman's avatar
Peter Eastman committed
53
54
55
56
57
58
59
        weight1(weight1), weight2(weight2) {
    vector<int> particles(2);
    particles[0] = particle1;
    particles[1] = particle2;
    setParticles(particles);
}

60
double TwoParticleAverageSite::getWeight(int particle) const {
Peter Eastman's avatar
Peter Eastman committed
61
62
63
64
65
66
67
    if (particle == 0)
        return weight1;
    if (particle == 1)
        return weight2;
    throw OpenMMException("Illegal index for particle");
}

68
ThreeParticleAverageSite::ThreeParticleAverageSite(int particle1, int particle2, int particle3, double weight1, double weight2, double weight3) :
Peter Eastman's avatar
Peter Eastman committed
69
70
71
72
73
74
75
76
        weight1(weight1), weight2(weight2), weight3(weight3) {
    vector<int> particles(3);
    particles[0] = particle1;
    particles[1] = particle2;
    particles[2] = particle3;
    setParticles(particles);
}

77
double ThreeParticleAverageSite::getWeight(int particle) const {
Peter Eastman's avatar
Peter Eastman committed
78
79
80
81
82
83
84
85
86
    if (particle == 0)
        return weight1;
    if (particle == 1)
        return weight2;
    if (particle == 2)
        return weight3;
    throw OpenMMException("Illegal index for particle");
}

87
OutOfPlaneSite::OutOfPlaneSite(int particle1, int particle2, int particle3, double weight12, double weight13, double weightCross) :
Peter Eastman's avatar
Peter Eastman committed
88
89
90
91
92
93
94
95
        weight12(weight12), weight13(weight13), weightCross(weightCross) {
    vector<int> particles(3);
    particles[0] = particle1;
    particles[1] = particle2;
    particles[2] = particle3;
    setParticles(particles);
}

96
double OutOfPlaneSite::getWeight12() const {
Peter Eastman's avatar
Peter Eastman committed
97
98
99
    return weight12;
}

100
double OutOfPlaneSite::getWeight13() const {
Peter Eastman's avatar
Peter Eastman committed
101
102
103
    return weight13;
}

104
double OutOfPlaneSite::getWeightCross() const {
Peter Eastman's avatar
Peter Eastman committed
105
106
    return weightCross;
}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

LocalCoordinatesSite::LocalCoordinatesSite(int particle1, int particle2, int particle3, const Vec3& originWeights, const Vec3& xWeights, const Vec3& yWeights, const Vec3& localPosition) :
        originWeights(originWeights), xWeights(xWeights), yWeights(yWeights), localPosition(localPosition) {
    if (fabs(originWeights[0]+originWeights[1]+originWeights[2]-1.0) > 1e-6)
        throw OpenMMException("LocalCoordinatesSite: Weights for computing origin must add to 1");
    if (fabs(xWeights[0]+xWeights[1]+xWeights[2]) > 1e-6)
        throw OpenMMException("LocalCoordinatesSite: Weights for computing x axis must add to 0");
    if (fabs(yWeights[0]+yWeights[1]+yWeights[2]) > 1e-6)
        throw OpenMMException("LocalCoordinatesSite: Weights for computing y axis must add to 0");
    vector<int> particles(3);
    particles[0] = particle1;
    particles[1] = particle2;
    particles[2] = particle3;
    setParticles(particles);
}

const Vec3& LocalCoordinatesSite::getOriginWeights() const {
    return originWeights;
}

const Vec3& LocalCoordinatesSite::getXWeights() const {
    return xWeights;
}

const Vec3& LocalCoordinatesSite::getYWeights() const {
    return yWeights;
}

const Vec3& LocalCoordinatesSite::getLocalPosition() const {
    return localPosition;
}