System.h 7.24 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef OPENMM_SYSTEM_H_
#define OPENMM_SYSTEM_H_

/* -------------------------------------------------------------------------- *
 *                                   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.               *
 *                                                                            *
12
 * Portions copyright (c) 2008-2009 Stanford University and the Authors.      *
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 * 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 <vector>
36
#include "internal/windowsExport.h"
37
38
39

namespace OpenMM {

40
class OPENMM_EXPORT Force;
41
42
43
44
45
46

/**
 * This class represents a molecular system.  The definition of a System involves
 * three elements:
 * 
 * <ol>
Peter Eastman's avatar
Peter Eastman committed
47
 * <li>The set of particles in the system</li>
48
 * <li>The forces acting on them</li>
49
 * <li>Pairs of particles whose separation should be constrained to a fixed value</li>
50
51
 * </ol>
 * 
52
53
54
55
 * The particles and constraints are defined directly by the System object, while
 * forces are defined by objects that extend the Force class.  After creating a
 * System, call addParticle() once for each particle, addConstraint() for each constraint,
 * and addForce() for each Force.
56
57
 */

58
class OPENMM_EXPORT System {
59
60
61
62
public:
    /**
     * Create a new System.
     */
63
    System();
64
65
    ~System();
    /**
Peter Eastman's avatar
Peter Eastman committed
66
     * Get the number of particles in this System.
67
     */
Peter Eastman's avatar
Peter Eastman committed
68
    int getNumParticles() const {
69
70
        return masses.size();
    }
71
72
73
74
75
76
77
78
    /**
     * Add a particle to the System.
     *
     * @param mass   the mass of the particle (in atomic mass units)
     */
    void addParticle(double mass) {
        masses.push_back(mass);
    }
79
    /**
Peter Eastman's avatar
Peter Eastman committed
80
     * Get the mass (in atomic mass units) of a particle.
81
     * 
Peter Eastman's avatar
Peter Eastman committed
82
     * @param index the index of the particle for which to get the mass
83
     */
Peter Eastman's avatar
Peter Eastman committed
84
    double getParticleMass(int index) const {
85
86
87
        return masses[index];
    }
    /**
Peter Eastman's avatar
Peter Eastman committed
88
     * Set the mass (in atomic mass units) of a particle.
89
     * 
Peter Eastman's avatar
Peter Eastman committed
90
91
     * @param index  the index of the particle for which to set the mass
     * @param mass   the mass of the particle
92
     */
Peter Eastman's avatar
Peter Eastman committed
93
    void setParticleMass(int index, double mass) {
94
95
96
97
98
99
100
101
        masses[index] = mass;
    }
    /**
     * Get the number of distance constraints in this System.
     */
    int getNumConstraints() const {
        return constraints.size();
    }
102
103
104
105
106
107
108
109
    /**
     * Add a constraint to the System.
     *
     * @param particle1 the index of the first particle involved in the constraint
     * @param particle2 the index of the second particle involved in the constraint
     * @param distance  the required distance between the two particles, measured in nm
     */
    void addConstraint(int particle1, int particle2, double distance);
110
111
112
113
    /**
     * Get the parameters defining a distance constraint.
     * 
     * @param index     the index of the constraint for which to get parameters
Peter Eastman's avatar
Peter Eastman committed
114
115
116
     * @param particle1 the index of the first particle involved in the constraint
     * @param particle2 the index of the second particle involved in the constraint
     * @param distance  the required distance between the two particles, measured in nm
117
     */
Peter Eastman's avatar
Peter Eastman committed
118
    void getConstraintParameters(int index, int& particle1, int& particle2, double& distance) const;
119
120
121
122
    /**
     * Set the parameters defining a distance constraint.
     * 
     * @param index     the index of the constraint for which to set parameters
Peter Eastman's avatar
Peter Eastman committed
123
124
125
     * @param particle1 the index of the first particle involved in the constraint
     * @param particle2 the index of the second particle involved in the constraint
     * @param distance  the required distance between the two particles, measured in nm
126
     */
Peter Eastman's avatar
Peter Eastman committed
127
    void setConstraintParameters(int index, int particle1, int particle2, double distance);
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
    /**
     * Add a Force to the System.  The Force should have been created on the heap with the
     * "new" operator.  The System takes over ownership of it, and deletes the Force when the
     * System itself is deleted.
     */
    void addForce(Force* force) {
        forces.push_back(force);
    }
    /**
     * Get the number of Force objects that have been added to the System.
     */
    int getNumForces() const {
        return forces.size();
    }
    /**
     * Get a reference to one of the Forces in this System.
     * 
     * @param index  the index of the Force to get
     */
147
148
149
150
151
152
153
154
    const Force& getForce(int index) const {
        return *forces[index];
    }
    /**
     * Get a reference to one of the Forces in this System.
     *
     * @param index  the index of the Force to get
     */
155
156
157
158
159
    Force& getForce(int index) {
        return *forces[index];
    }
private:
    class ConstraintInfo;
160

Peter Eastman's avatar
Peter Eastman committed
161
162
163
164
165
166
// Retarded visual studio compiler complains about being unable to 
// export private stl class members.
// This stanza explains that it should temporarily shut up.
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4251)
167
168
#endif

Peter Eastman's avatar
Peter Eastman committed
169
    std::vector<double> masses;
170
171
    std::vector<ConstraintInfo> constraints;
    std::vector<Force*> forces;
172

Peter Eastman's avatar
Peter Eastman committed
173
174
175
176
#if defined(_MSC_VER)
#pragma warning(pop)
#endif

177
178
179
180
};

class System::ConstraintInfo {
public:
Peter Eastman's avatar
Peter Eastman committed
181
    int particle1, particle2;
182
183
    double distance;
    ConstraintInfo() {
Peter Eastman's avatar
Peter Eastman committed
184
        particle1 = particle2 = -1;
185
186
        distance = 0.0;
    }
187
188
189
    ConstraintInfo(int particle1, int particle2, double distance) :
        particle1(particle1), particle2(particle2), distance(distance) {
    }
190
191
192
193
194
};

} // namespace OpenMM

#endif /*OPENMM_SYSTEM_H_*/