BrookIntegrateLangevinStepKernel.cpp 6.82 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
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
/* -------------------------------------------------------------------------- *
 *                                   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 "BrookIntegrateKernals.h"
#include "BrookStreamInternal.h"

using namespace OpenMM;
using namespace std;

Mark Friedrichs's avatar
Mark Friedrichs committed
38
39
BrookIntegrateLangevinStepKernel::BrookIntegrateLangevinStepKernel( std::string name, const Platform& platform ) :
                                IntegrateLangevinStepKernel( name, platform ){
Mark Friedrichs's avatar
Mark Friedrichs committed
40
41
42

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
43
   // static const std::string methodName      = "BrookIntegrateLangevinStepKernel::BrookIntegrateLangevinStepKernel";
Mark Friedrichs's avatar
Mark Friedrichs committed
44
45

// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
46
47
48
49
50
51
52
53
54

   _numberOfConstraints            = -1;

   _brookStochasticDynamics        = NULL;
   _brookShakeAlgorithm            = NULL;
   _atomMasses                     = NULL;
   _shakeParameters                = NULL;
   _constraintIndices              = NULL;
   _shakeParameters                = NULL;
Mark Friedrichs's avatar
Mark Friedrichs committed
55
56
57
   
}

Mark Friedrichs's avatar
Mark Friedrichs committed
58
BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel( ){
Mark Friedrichs's avatar
Mark Friedrichs committed
59
60
61

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
62
   // static const std::string methodName      = "BrookIntegrateLangevinStepKernel::~BrookIntegrateLangevinStepKernel";
Mark Friedrichs's avatar
Mark Friedrichs committed
63
64
65

// ---------------------------------------------------------------------------------------
   
Mark Friedrichs's avatar
Mark Friedrichs committed
66
67
68
69
70
71
72
   delete _brookkStochasticDynamics;
   delete _brookShakeAlgorithm;
   delete _atomMasses;
   delete _shakeParameters;
   delete _constraintIndices;
   delete _shakeParameters;

Mark Friedrichs's avatar
Mark Friedrichs committed
73
74
}

Mark Friedrichs's avatar
Mark Friedrichs committed
75
void BrookIntegrateLangevinStepKernel::initialize( const vector<double>& masses,
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
76
77
                                                   const vector<vector<int> >& constraintIndices,
                                                   const vector<double>& constraintLengths ){
Mark Friedrichs's avatar
Mark Friedrichs committed
78
79
80

// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
81
   // static const std::string methodName      = "BrookIntegrateLangevinStepKernel::initialize";
Mark Friedrichs's avatar
Mark Friedrichs committed
82
83
84

// ---------------------------------------------------------------------------------------
   
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
85
86
   _brookkStochasticDynamics = new BrookStochasticDynamics( masses );
   _brookShakeAlgorithm      = new BrookShakeAlgorithm( masses, constraintIndices, constraintLengths );
Mark Friedrichs's avatar
Mark Friedrichs committed
87
88
89
90
91
/*
    this->masses = new RealOpenMM[masses.size()];
    for (size_t i = 0; i < masses.size(); ++i)
        this->masses[i] = static_cast<RealOpenMM>( masses[i] );
    numConstraints = constraintIndices.size();
Mark Friedrichs's avatar
Mark Friedrichs committed
92
    this->constraintIndices = allocateIntArray(numConstraints, 2); 
Mark Friedrichs's avatar
Mark Friedrichs committed
93
94
95
    for (int i = 0; i < numConstraints; ++i) {
        this->constraintIndices[i][0] = constraintIndices[i][0];
        this->constraintIndices[i][1] = constraintIndices[i][1];
Mark Friedrichs's avatar
Mark Friedrichs committed
96
97
    }   
    shakeParameters = allocateRealArray(constraintLengths.size(), 1); 
Mark Friedrichs's avatar
Mark Friedrichs committed
98
99
    for (size_t i = 0; i < constraintLengths.size(); ++i)
        shakeParameters[i][0] = static_cast<RealOpenMM>( constraintLengths[i] );
Mark Friedrichs's avatar
Mark Friedrichs committed
100

Mark Friedrichs's avatar
Mark Friedrichs committed
101
102
103
*/
}

Mark Friedrichs's avatar
Mark Friedrichs committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/** 
 * Execute kernel
 * 
 * @param positions          atom coordinates
 * @param velocities         atom velocities
 * @param forces             atom forces
 * @param temperature        heat bath temperature
 * @param friction           friction coefficient coupling the system to the heat bath
 * @param stepSize           integration step size
 *
 */

void BrookIntegrateLangevinStepKernel::execute( Stream& positions, Stream& velocities,
                                                const Stream& forces, double temperature,
                                                double friction, double stepSize ){

Mark Friedrichs's avatar
Mark Friedrichs committed
120
121
// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
122
   //static const std::string methodName      = "BrookIntegrateLangevinStepKernel::execute";
Mark Friedrichs's avatar
Mark Friedrichs committed
123
124
125

// ---------------------------------------------------------------------------------------
   
Mark Friedrichs's avatar
Mark Friedrichs committed
126
127
128
129
   // first time through initialize _brookStochasticDynamics

   // for each subsequent call, check if parameters need to be updated due to a change
   // in T, gamma, or the step size
Mark Friedrichs's avatar
Mark Friedrichs committed
130

Mark Friedrichs's avatar
Mark Friedrichs committed
131
132
133
134
135
   // take step

   if( _brookStochasticDynamics == NULL ){
      _brookStochasticDynamics = new BrookStochasticDynamics( getNumberOfAtoms(), static_cast<RealOpenMM>(stepSize), 
                                                              static_cast<RealOpenMM>(tau), static_cast<RealOpenMM>(temperature) );
Mark Friedrichs's avatar
Mods  
Mark Friedrichs committed
136
137
   } else if( temperature != _brookStochasticDynamics->getTemperatur() || friction != _brookStochasticDynamics->getFriction() ){
      _brookStochasticDynamics->updateParameters( temperature, friction );
Mark Friedrichs's avatar
Mark Friedrichs committed
138
139
140
141
   } 
   _brookStochasticDynamics->update( positions, velocities, forces );

}