- Main Page
- Related Pages
- Classes
- Files

- File List

# CustomIntegrator.h

    00001 #ifndef OPENMM_CUSTOMINTEGRATOR_H_
    00002 #define OPENMM_CUSTOMINTEGRATOR_H_
    00003
    00004 /* -------------------------------------------------------------------------- *
    00005  *                                   OpenMM                                   *
    00006  * -------------------------------------------------------------------------- *
    00007  * This is part of the OpenMM molecular simulation toolkit originating from   *
    00008  * Simbios, the NIH National Center for Physics-Based Simulation of           *
    00009  * Biological Structures at Stanford, funded under the NIH Roadmap for        *
    00010  * Medical Research, grant U54 GM072970. See https://simtk.org.               *
    00011  *                                                                            *
    00012  * Portions copyright (c) 2011-2012 Stanford University and the Authors.      *
    00013  * Authors: Peter Eastman                                                     *
    00014  * Contributors:                                                              *
    00015  *                                                                            *
    00016  * Permission is hereby granted, free of charge, to any person obtaining a    *
    00017  * copy of this software and associated documentation files (the "Software"), *
    00018  * to deal in the Software without restriction, including without limitation  *
    00019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,   *
    00020  * and/or sell copies of the Software, and to permit persons to whom the      *
    00021  * Software is furnished to do so, subject to the following conditions:       *
    00022  *                                                                            *
    00023  * The above copyright notice and this permission notice shall be included in *
    00024  * all copies or substantial portions of the Software.                        *
    00025  *                                                                            *
    00026  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
    00027  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   *
    00028  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    *
    00029  * THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,    *
    00030  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR      *
    00031  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE  *
    00032  * USE OR OTHER DEALINGS IN THE SOFTWARE.                                     *
    00033  * -------------------------------------------------------------------------- */
    00034
    00035 #include "Integrator.h"
    00036 #include "Vec3.h"
    00037 #include "openmm/Kernel.h"
    00038 #include "internal/windowsExport.h"
    00039 #include <string>
    00040 #include <vector>
    00041
    00042 namespace OpenMM {
    00043
    00212 class OPENMM_EXPORT CustomIntegrator : public Integrator {
    00213 public:
    00217     enum ComputationType {
    00221         ComputeGlobal = 0,
    00225         ComputePerDof = 1,
    00229         ComputeSum = 2,
    00233         ConstrainPositions = 3,
    00237         ConstrainVelocities = 4,
    00241         UpdateContextState = 5
    00242     };
    00248     CustomIntegrator(double stepSize);
    00252     int getNumGlobalVariables() const {
    00253         return globalNames.size();
    00254     }
    00258     int getNumPerDofVariables() const {
    00259         return perDofNames.size();
    00260     }
    00264     int getNumComputations() const {
    00265         return computations.size();
    00266     }
    00274     int addGlobalVariable(const std::string& name, double initialValue);
    00281     const std::string& getGlobalVariableName(int index) const;
    00290     int addPerDofVariable(const std::string& name, double initialValue);
    00297     const std::string& getPerDofVariableName(int index) const;
    00304     double getGlobalVariable(int index) const;
    00311     double getGlobalVariableByName(const std::string& name) const;
    00318     void setGlobalVariable(int index, double value);
    00325     void setGlobalVariableByName(const std::string& name, double value);
    00333     void getPerDofVariable(int index, std::vector<Vec3>& values) const;
    00341     void getPerDofVariableByName(const std::string& name, std::vector<Vec3>& values) const;
    00348     void setPerDofVariable(int index, const std::vector<Vec3>& values);
    00355     void setPerDofVariableByName(const std::string& name, const std::vector<Vec3>& values);
    00365     int addComputeGlobal(const std::string& variable, const std::string& expression);
    00376     int addComputePerDof(const std::string& variable, const std::string& expression);
    00388     int addComputeSum(const std::string& variable, const std::string& expression);
    00395     int addConstrainPositions();
    00402     int addConstrainVelocities();
    00409     int addUpdateContextState();
    00421     void getComputationStep(int index, ComputationType& type, std::string& variable, std::string& expression) const;
    00427     const std::string& getKineticEnergyExpression() const;
    00433     void setKineticEnergyExpression(const std::string& expression);
    00437     int getRandomNumberSeed() const {
    00438         return randomNumberSeed;
    00439     }
    00448     void setRandomNumberSeed(int seed) {
    00449         randomNumberSeed = seed;
    00450     }
    00456     void step(int steps);
    00457 protected:
    00463     void initialize(ContextImpl& context);
    00468     void cleanup();
    00472     void stateChanged(State::DataType changed);
    00476     std::vector<std::string> getKernelNames();
    00480     double computeKineticEnergy();
    00481 private:
    00482     class ComputationInfo;
    00483     std::vector<std::string> globalNames;
    00484     std::vector<std::string> perDofNames;
    00485     mutable std::vector<double> globalValues;
    00486     std::vector<std::vector<Vec3> > perDofValues;
    00487     std::vector<ComputationInfo> computations;
    00488     std::string kineticEnergy;
    00489     mutable bool globalsAreCurrent;
    00490     int randomNumberSeed;
    00491     bool forcesAreValid;
    00492     Kernel kernel;
    00493 };
    00494
    00499 class CustomIntegrator::ComputationInfo {
    00500 public:
    00501     ComputationType type;
    00502     std::string variable, expression;
    00503     ComputationInfo() {
    00504     }
    00505     ComputationInfo(ComputationType type, const std::string& variable, const std::string& expression) :
    00506         type(type), variable(variable), expression(expression) {
    00507     }
    00508 };
    00509
    00510 } // namespace OpenMM
    00511
    00512 #endif /*OPENMM_CUSTOMINTEGRATOR_H_*/