ReferencePlatform.cpp 7.08 KB
Newer Older
1
2
3
/* -------------------------------------------------------------------------- *
 *                                   OpenMM                                   *
 * -------------------------------------------------------------------------- *
Evan Pretti's avatar
Evan Pretti committed
4
5
 * This is part of the OpenMM molecular simulation toolkit.                   *
 * See https://openmm.org/development.                                        *
6
 *                                                                            *
7
 * Portions copyright (c) 2008-2026 Stanford University and the Authors.      *
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
 * 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 "ReferencePlatform.h"
#include "ReferenceKernelFactory.h"
#include "ReferenceKernels.h"
33
#include "openmm/internal/ContextImpl.h"
34
#include "SimTKOpenMMRealType.h"
peastman's avatar
peastman committed
35
#include "openmm/Vec3.h"
36
#include <sstream>
37
38

using namespace OpenMM;
39
using namespace std;
40
41
42

ReferencePlatform::ReferencePlatform() {
    ReferenceKernelFactory* factory = new ReferenceKernelFactory();
43
    registerKernelFactory(CalcForcesAndEnergyKernel::Name(), factory);
44
    registerKernelFactory(UpdateStateDataKernel::Name(), factory);
45
    registerKernelFactory(ApplyConstraintsKernel::Name(), factory);
46
    registerKernelFactory(VirtualSitesKernel::Name(), factory);
47
    registerKernelFactory(MinimizeKernel::Name(), factory);
48
    registerKernelFactory(CalcHarmonicBondForceKernel::Name(), factory);
49
    registerKernelFactory(CalcCustomBondForceKernel::Name(), factory);
50
    registerKernelFactory(CalcHarmonicAngleForceKernel::Name(), factory);
51
    registerKernelFactory(CalcCustomAngleForceKernel::Name(), factory);
52
53
    registerKernelFactory(CalcPeriodicTorsionForceKernel::Name(), factory);
    registerKernelFactory(CalcRBTorsionForceKernel::Name(), factory);
54
    registerKernelFactory(CalcCMAPTorsionForceKernel::Name(), factory);
55
    registerKernelFactory(CalcCustomTorsionForceKernel::Name(), factory);
56
    registerKernelFactory(CalcNonbondedForceKernel::Name(), factory);
57
    registerKernelFactory(CalcConstantPotentialForceKernel::Name(), factory);
58
    registerKernelFactory(CalcCustomNonbondedForceKernel::Name(), factory);
59
    registerKernelFactory(CalcGBSAOBCForceKernel::Name(), factory);
60
    registerKernelFactory(CalcCustomGBForceKernel::Name(), factory);
61
    registerKernelFactory(CalcCustomExternalForceKernel::Name(), factory);
62
    registerKernelFactory(CalcCustomHbondForceKernel::Name(), factory);
63
    registerKernelFactory(CalcCustomCentroidBondForceKernel::Name(), factory);
64
    registerKernelFactory(CalcCustomCompoundBondForceKernel::Name(), factory);
65
    registerKernelFactory(CalcCustomCPPForceKernel::Name(), factory);
66
    registerKernelFactory(CalcCustomCVForceKernel::Name(), factory);
67
    registerKernelFactory(CalcATMForceKernel::Name(), factory);
68
    registerKernelFactory(CalcOrientationRestraintForceKernel::Name(), factory);
Peter Eastman's avatar
Peter Eastman committed
69
    registerKernelFactory(CalcPythonForceKernel::Name(), factory);
70
    registerKernelFactory(CalcRGForceKernel::Name(), factory);
71
    registerKernelFactory(CalcRMSDForceKernel::Name(), factory);
72
    registerKernelFactory(CalcCustomManyParticleForceKernel::Name(), factory);
73
    registerKernelFactory(CalcGayBerneForceKernel::Name(), factory);
Evan Pretti's avatar
Evan Pretti committed
74
    registerKernelFactory(CalcLCPOForceKernel::Name(), factory);
75
    registerKernelFactory(IntegrateVerletStepKernel::Name(), factory);
76
    registerKernelFactory(IntegrateNoseHooverStepKernel::Name(), factory);
77
    registerKernelFactory(IntegrateLangevinMiddleStepKernel::Name(), factory);
78
    registerKernelFactory(IntegrateBrownianStepKernel::Name(), factory);
79
    registerKernelFactory(IntegrateVariableLangevinStepKernel::Name(), factory);
80
    registerKernelFactory(IntegrateVariableVerletStepKernel::Name(), factory);
81
    registerKernelFactory(IntegrateCustomStepKernel::Name(), factory);
Peter Eastman's avatar
Peter Eastman committed
82
    registerKernelFactory(IntegrateDPDStepKernel::Name(), factory);
83
    registerKernelFactory(IntegrateQTBStepKernel::Name(), factory);
84
    registerKernelFactory(ApplyAndersenThermostatKernel::Name(), factory);
85
    registerKernelFactory(ApplyMonteCarloBarostatKernel::Name(), factory);
86
    registerKernelFactory(RemoveCMMotionKernel::Name(), factory);
87
}
88

89
90
91
92
double ReferencePlatform::getSpeed() const {
    return 1;
}

93
bool ReferencePlatform::supportsDoublePrecision() const {
peastman's avatar
peastman committed
94
    return true;
95
96
}

97
void ReferencePlatform::contextCreated(ContextImpl& context, const map<string, string>& properties) const {
98
99
100
101
    int numThreads = 0;
    if (properties.find("Threads") != properties.end())
        stringstream(properties.at("Threads")) >> numThreads;
    context.setPlatformData(new PlatformData(context.getSystem(), numThreads));
102
103
}

104
void ReferencePlatform::contextDestroyed(ContextImpl& context) const {
105
106
107
    PlatformData* data = reinterpret_cast<PlatformData*>(context.getPlatformData());
    delete data;
}
108

109
110
ReferencePlatform::PlatformData::PlatformData(const System& system, int numThreads) : time(0.0), stepCount(0),
        numParticles(system.getNumParticles()), threads(numThreads) {
peastman's avatar
peastman committed
111
112
113
114
115
    positions = new vector<Vec3>(numParticles);
    velocities = new vector<Vec3>(numParticles);
    forces = new vector<Vec3>(numParticles);
    periodicBoxSize = new Vec3();
    periodicBoxVectors = new Vec3[3];
116
    constraints = new ReferenceConstraints(system);
117
    virtualSites = new ReferenceVirtualSites(system);
118
    energyParameterDerivatives = new map<string, double>();
119
120
121
}

ReferencePlatform::PlatformData::~PlatformData() {
122
123
124
125
126
127
    delete positions;
    delete velocities;
    delete forces;
    delete periodicBoxSize;
    delete[] periodicBoxVectors;
    delete constraints;
128
    delete virtualSites;
129
    delete energyParameterDerivatives;
130
}