OpenMM

- Main Page
- Related Pages
- Classes

All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
CustomIntegrator.h
1 #ifndef OPENMM_CUSTOMINTEGRATOR_H_
2 #define OPENMM_CUSTOMINTEGRATOR_H_
3
4 /* -------------------------------------------------------------------------- *
5 * OpenMM *
6 * -------------------------------------------------------------------------- *
7 * This is part of the OpenMM molecular simulation toolkit originating from *
8 * Simbios, the NIH National Center for Physics-Based Simulation of *
9 * Biological Structures at Stanford, funded under the NIH Roadmap for *
10 * Medical Research, grant U54 GM072970. See https://simtk.org. *
11 * *
12 * Portions copyright (c) 2011-2012 Stanford University and the Authors. *
13 * Authors: Peter Eastman *
14 * Contributors: *
15 * *
16 * Permission is hereby granted, free of charge, to any person obtaining a *
17 * copy of this software and associated documentation files (the "Software"), *
18 * to deal in the Software without restriction, including without limitation *
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense, *
20 * and/or sell copies of the Software, and to permit persons to whom the *
21 * Software is furnished to do so, subject to the following conditions: *
22 * *
23 * The above copyright notice and this permission notice shall be included in *
24 * all copies or substantial portions of the Software. *
25 * *
26 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
27 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
28 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
29 * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
30 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
31 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
32 * USE OR OTHER DEALINGS IN THE SOFTWARE. *
33 * -------------------------------------------------------------------------- */
34
35 #include "Integrator.h"
36 #include "Vec3.h"
37 #include "openmm/Kernel.h"
38 #include "internal/windowsExport.h"
39 #include <string>
40 #include <vector>
41
42 namespace OpenMM {
43
212 class OPENMM_EXPORT CustomIntegrator : public Integrator {
213 public:
217 enum ComputationType {
221 ComputeGlobal = 0,
225 ComputePerDof = 1,
229 ComputeSum = 2,
233 ConstrainPositions = 3,
237 ConstrainVelocities = 4,
241 UpdateContextState = 5
242 };
248 CustomIntegrator(double stepSize);
252 int getNumGlobalVariables() const {
253 return globalNames.size();
254 }
258 int getNumPerDofVariables() const {
259 return perDofNames.size();
260 }
264 int getNumComputations() const {
265 return computations.size();
266 }
274 int addGlobalVariable(const std::string& name, double initialValue);
281 const std::string& getGlobalVariableName(int index) const;
290 int addPerDofVariable(const std::string& name, double initialValue);
297 const std::string& getPerDofVariableName(int index) const;
304 double getGlobalVariable(int index) const;
311 double getGlobalVariableByName(const std::string& name) const;
318 void setGlobalVariable(int index, double value);
325 void setGlobalVariableByName(const std::string& name, double value);
333 void getPerDofVariable(int index, std::vector<Vec3>& values) const;
341 void getPerDofVariableByName(const std::string& name, std::vector<Vec3>& values) const;
348 void setPerDofVariable(int index, const std::vector<Vec3>& values);
355 void setPerDofVariableByName(const std::string& name, const std::vector<Vec3>& values);
365 int addComputeGlobal(const std::string& variable, const std::string& expression);
376 int addComputePerDof(const std::string& variable, const std::string& expression);
388 int addComputeSum(const std::string& variable, const std::string& expression);
395 int addConstrainPositions();
402 int addConstrainVelocities();
409 int addUpdateContextState();
421 void getComputationStep(int index, ComputationType& type, std::string& variable, std::string& expression) const;
427 const std::string& getKineticEnergyExpression() const;
433 void setKineticEnergyExpression(const std::string& expression);
437 int getRandomNumberSeed() const {
438 return randomNumberSeed;
439 }
452 void setRandomNumberSeed(int seed) {
453 randomNumberSeed = seed;
454 }
460 void step(int steps);
461 protected:
467 void initialize(ContextImpl& context);
472 void cleanup();
476 void stateChanged(State::DataType changed);
480 std::vector<std::string> getKernelNames();
484 double computeKineticEnergy();
485 private:
486 class ComputationInfo;
487 std::vector<std::string> globalNames;
488 std::vector<std::string> perDofNames;
489 mutable std::vector<double> globalValues;
490 std::vector<std::vector<Vec3> > perDofValues;
491 std::vector<ComputationInfo> computations;
492 std::string kineticEnergy;
493 mutable bool globalsAreCurrent;
494 int randomNumberSeed;
495 bool forcesAreValid;
496 Kernel kernel;
497 };
498
503 class CustomIntegrator::ComputationInfo {
504 public:
505 ComputationType type;
506 std::string variable, expression;
507 ComputationInfo() {
508 }
509 ComputationInfo(ComputationType type, const std::string& variable, const std::string& expression) :
510 type(type), variable(variable), expression(expression) {
511 }
512 };
513
514 } // namespace OpenMM
515
516 #endif /*OPENMM_CUSTOMINTEGRATOR_H_*/
OpenMM::CustomIntegrator::getNumPerDofVariables
int getNumPerDofVariables() const
Get the number of per-DOF variables that have been defined.
Definition: CustomIntegrator.h:258
OpenMM::CustomIntegrator
This is an Integrator that can be used to implemented arbitrary, user defined integration algorithms...
Definition: CustomIntegrator.h:212
OpenMM::CustomIntegrator::getNumGlobalVariables
int getNumGlobalVariables() const
Get the number of global variables that have been defined.
Definition: CustomIntegrator.h:252
OpenMM::CustomIntegrator::setRandomNumberSeed
void setRandomNumberSeed(int seed)
Set the random number seed.
Definition: CustomIntegrator.h:452
OpenMM::CustomIntegrator::getRandomNumberSeed
int getRandomNumberSeed() const
Get the random number seed.
Definition: CustomIntegrator.h:437
OpenMM::Integrator
An Integrator defines a method for simulating a System by integrating the equations of motion...
Definition: Integrator.h:54
OpenMM::State::DataType
DataType
This is an enumeration of the types of data which may be stored in a State.
Definition: State.h:61
OpenMM::CustomIntegrator::getNumComputations
int getNumComputations() const
Get the number of computation steps that have been added.
Definition: CustomIntegrator.h:264
OpenMM::Kernel
A Kernel encapsulates a particular implementation of a calculation that can be performed on the data ...
Definition: Kernel.h:58
OpenMM
Definition: AndersenThermostat.h:40
OpenMM::CustomIntegrator::ComputationType
ComputationType
This is an enumeration of the different types of computations that may appear in an integration algor...
Definition: CustomIntegrator.h:217