ForceImpl.h 5.31 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
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
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef OPENMM_FORCEIMPL_H_
#define OPENMM_FORCEIMPL_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.               *
 *                                                                            *
 * Portions copyright (c) 2008 Stanford University and the Authors.           *
 * 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 <map>
#include <vector>

namespace OpenMM {

class Force;
class OpenMMContextImpl;
class Stream;

/**
 * A ForceImpl provides the internal implementation of a Force.  When an OpenMMContext is
 * created for a System, it creates a ForceImpl for each Force in the System.  The ForceImpl
 * is permitted to cache information from the Force or System which is needed to apply the
 * force efficiently.  If the user calls reinitialize() on the OpenMMContext, all ForceImpl
 * objects it had previously created are deleted and recreated from scratch.
 * 
 * This is an abstract class.  Each Force subclass is responsible for defining its own
 * ForceImpl subclass.
 */

class ForceImpl {
public:
    virtual ~ForceImpl() {
    }
59
60
61
62
63
    /**
     * This is called after the ForceImpl is created and before updateContextState(), calcForces(),
     * or calcEnergy() is called on it.  This allows it to do any necessary initialization.
     */
    virtual void initialize(OpenMMContextImpl& context) = 0;
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
    /**
     * Get the Force object from which this ForceImpl was created.
     */
    virtual Force& getOwner() = 0;
    /**
     * This method is called at the beginning of each time step.  It give the ForceImpl a chance
     * to modify the state variables (positions, velocities, and parameters) stored in the
     * OpenMMContext in arbitrary ways before integration is performed.
     * 
     * @param context     the context in which the system is being simulated
     */
    virtual void updateContextState(OpenMMContextImpl& context) = 0;
    /**
     * Calculate the force on each atom generated by this ForceImpl.  The forces should be <i>added</i>
     * to the values already present in the array that is passed in.  If this ForceImpl does not generate
     * any new forces, it should simply return without modifying the array.
     * 
     * @param context     the context in which the system is being simulated
     * @param forces      new forces should be added to the value already stored in this
     */
    virtual void calcForces(OpenMMContextImpl& context, Stream& forces) = 0;
    /**
     * Calculate this ForceImpl's contribution to the potential energy of the system.
     * 
     * @param context     the context in which the system is being simulated
     * @return this force's contribution to the potential energy of the system, or 0 if this
     * force does not contribute to potential energy
     */
    virtual double calcEnergy(OpenMMContextImpl& context) = 0;
    /**
     * Get a map containing the default values for all adjustable parameters defined by this ForceImpl.  These
     * parameters and their default values will automatically be added to the OpenMMContext.
     */
    virtual std::map<std::string, double> getDefaultParameters() = 0;
    /**
     * Get the names of all Kernels used by this Force.
     */
    virtual std::vector<std::string> getKernelNames() = 0;
};

} // namespace OpenMM

#endif /*OPENMM_FORCEIMPL_H_*/