MonteCarloAnisotropicBarostat.h 8.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
#ifndef OPENMM_MONTECARLOANISOTROPICBAROSTAT_H_
#define OPENMM_MONTECARLOANISOTROPICBAROSTAT_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
13
 * Portions copyright (c) 2010-2013 Stanford University and the Authors.      *
 * Authors: Peter Eastman, Lee-Ping Wang                                      *
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 * 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 "Force.h"
#include "Vec3.h"
#include <string>
#include "internal/windowsExport.h"

namespace OpenMM {

/**
 * This class uses a Monte Carlo algorithm to adjust the size of the periodic box, simulating the
 * effect of constant pressure.
 *
46
47
48
49
50
51
 * This class is similar to MonteCarloBarostat, but each Monte Carlo move is applied to only one axis
 * of the periodic box (unlike MonteCarloBarostat, which scales the entire box isotropically).  This
 * means that the box may change shape as well as size over the course of the simulation.  It also
 * allows you to specify a different pressure for each axis of the box, or to keep the box size fixed
 * along certain axes while still allowing it to change along others.
 * 
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 * This class assumes the simulation is also being run at constant temperature, and requires you
 * to specify the system temperature (since it affects the acceptance probability for Monte Carlo
 * moves).  It does not actually perform temperature regulation, however.  You must use another
 * mechanism along with it to maintain the temperature, such as LangevinIntegrator or AndersenThermostat.
 */

class OPENMM_EXPORT MonteCarloAnisotropicBarostat : public Force {
public:
    /**
     * This is the name of the parameter which stores the current pressure acting on
     * the X-axis (in bar).
     */
    static const std::string& PressureX() {
        static const std::string key = "MonteCarloPressureX";
        return key;
    }
    /**
     * This is the name of the parameter which stores the current pressure acting on
     * the Y-axis (in bar).
     */
    static const std::string& PressureY() {
        static const std::string key = "MonteCarloPressureY";
        return key;
    }
    /**
     * This is the name of the parameter which stores the current pressure acting on
     * the Z-axis (in bar).
     */
    static const std::string& PressureZ() {
        static const std::string key = "MonteCarloPressureZ";
        return key;
    }
    /**
     * Create a MonteCarloAnisotropicBarostat.
     *
     * @param defaultPressure   The default pressure acting on each axis (in bar)
     * @param temperature       the temperature at which the system is being maintained (in Kelvin)
89
90
91
     * @param scaleX            whether to allow the X dimension of the periodic box to change size
     * @param scaleY            whether to allow the Y dimension of the periodic box to change size
     * @param scaleZ            whether to allow the Z dimension of the periodic box to change size
92
     * @param frequency         the frequency at which Monte Carlo pressure changes should be attempted (in time steps)
93
     */
94
    MonteCarloAnisotropicBarostat(const Vec3& defaultPressure, double temperature, bool scaleX = true, bool scaleY = true, bool scaleZ = true, int frequency = 25);
95
96
97
    /**
     * Get the default pressure (in bar).
     *
98
     * @return the default pressure acting along each axis, measured in bar.
99
     */
100
    const Vec3& getDefaultPressure() const {
101
102
        return defaultPressure;
    }
103
104
105
106
107
108
    /**
     * Set the default pressure acting on the system.  This will affect any new Contexts you create,
     * but not ones that already exist.
     *
     * @param pressure   the default pressure acting on the system, measured in bar.
     */
109
    void setDefaultPressure(const Vec3& pressure) {
110
111
        defaultPressure = pressure;
    }
112
    /**
113
     * Get whether to allow the X dimension of the periodic box to change size.
114
115
116
117
118
     */
    bool getScaleX() const {
      return scaleX;
    }
    /**
119
     * Get whether to allow the Y dimension of the periodic box to change size.
120
121
122
123
124
     */
    bool getScaleY() const {
      return scaleY;
    }
    /**
125
     * Get whether to allow the Z dimension of the periodic box to change size.
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
     */
    bool getScaleZ() const {
      return scaleZ;
    }
    /**
     * Get the frequency (in time steps) at which Monte Carlo pressure changes should be attempted.  If this is set to
     * 0, the barostat is disabled.
     */
    int getFrequency() const {
        return frequency;
    }
    /**
     * Set the frequency (in time steps) at which Monte Carlo pressure changes should be attempted.  If this is set to
     * 0, the barostat is disabled.
     */
    void setFrequency(int freq) {
        frequency = freq;
    }
    /**
     * Get the temperature at which the system is being maintained, measured in Kelvin.
     */
    double getTemperature() const {
        return temperature;
    }
    /**
     * Set the temperature at which the system is being maintained.
     *
     * @param temp     the system temperature, measured in Kelvin.
     */
    void setTemperature(double temp) {
        temperature = temp;
    }
    /**
     * Get the random number seed.  See setRandomNumberSeed() for details.
     */
    int getRandomNumberSeed() const {
        return randomNumberSeed;
    }
    /**
     * Set the random number seed.  It is guaranteed that if two simulations are run
     * with different random number seeds, the sequence of Monte Carlo steps will be different.  On
     * the other hand, no guarantees are made about the behavior of simulations that use the same seed.
     * In particular, Platforms are permitted to use non-deterministic algorithms which produce different
     * results on successive runs, even if those runs were initialized identically.
     */
    void setRandomNumberSeed(int seed) {
        randomNumberSeed = seed;
    }
protected:
    ForceImpl* createImpl() const;
private:
    Vec3 defaultPressure;
    double temperature;
    bool scaleX, scaleY, scaleZ;
    int frequency, randomNumberSeed;
181
};
182
183
184
185

} // namespace OpenMM

#endif /*OPENMM_MONTECARLOANISOTROPICBAROSTAT_H_*/