"devtools/vscode:/vscode.git/clone" did not exist on "1cd905b4a6ca25f59e0a6c71f7a75f9f4a450193"
BrookIntegrateVerletStepKernel.cpp 6.02 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
/* -------------------------------------------------------------------------- *
 *                                   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.                                     *
 * -------------------------------------------------------------------------- */

Mark Friedrichs's avatar
Mark Friedrichs committed
32
#include "BrookIntegrateVerletStepKernel.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
33
34
35
36
37
#include "BrookStreamInternal.h"

using namespace OpenMM;
using namespace std;

Mark Friedrichs's avatar
Mark Friedrichs committed
38
39
40
41
42
43
44
45
/** 
 * BrookIntegrateVerletStepKernel constructor
 * 
 * @param name        name of the stream to create
 * @param platform    platform
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
46
47
48
49
50
51
52
53
54
BrookIntegrateVerletStepKernel::BrookIntegrateVerletStepKernel( std::string name, const Platform& platform ) :
                                IntegrateVerletStepKernel( name, platform ){

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

   // static const std::string methodName      = "BrookIntegrateVerletStepKernel::BrookIntegrateVerletStepKernel";

// ---------------------------------------------------------------------------------------
   
Mark Friedrichs's avatar
Mark Friedrichs committed
55
56
   _brookVerletDynamics   = NULL;
   _brookShakeAlgorithm   = NULL;
Mark Friedrichs's avatar
Mark Friedrichs committed
57
58
}

Mark Friedrichs's avatar
Mark Friedrichs committed
59
60
61
62
63
/** 
 * BrookIntegrateVerletStepKernel destructor
 * 
 */
  
Mark Friedrichs's avatar
Mark Friedrichs committed
64
65
66
67
68
69
70
BrookIntegrateVerletStepKernel::~BrookIntegrateVerletStepKernel( ){

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

   // static const std::string methodName      = "BrookIntegrateVerletStepKernel::~BrookIntegrateVerletStepKernel";

// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
71
72
73

   delete _brookVerletDynamics;
   delete _brookShakeAlgorithm;
Mark Friedrichs's avatar
Mark Friedrichs committed
74
75
76
   
}

Mark Friedrichs's avatar
Mark Friedrichs committed
77
78
79
80
81
82
83
84
85
/** 
 * Initialize the kernel, setting up all parameters related to integrator.
 * 
 * @param masses             the mass of each atom
 * @param constraintIndices  each element contains the indices of two atoms whose distance should be constrained
 * @param constraintLengths  the required distance between each pair of constrained atoms
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
86
87
88
89
90
91
92
93
94
95
void BrookIntegrateVerletStepKernel::initialize( const vector<double>& masses,
                                                 const vector<vector<int> >& constraintIndices,
                                                 const vector<double>& constraintLengths ){

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

   // static const std::string methodName      = "BrookIntegrateVerletStepKernel::initialize";

// ---------------------------------------------------------------------------------------
   
Mark Friedrichs's avatar
Mark Friedrichs committed
96
97
98
99
100
101
   _brookVerletDynamics          = new BrookVerletDynamics( );
   _brookVerletDynamics->setup( masses, getPlatform() );

   _brookShakeAlgorithm          = new BrookShakeAlgorithm( );
   _brookShakeAlgorithm->setup( masses, constraintIndices, constraintLengths, getPlatform() );

Mark Friedrichs's avatar
Mark Friedrichs committed
102
103
}

Mark Friedrichs's avatar
Mark Friedrichs committed
104
105
106
107
108
109
110
111
112
113
/** 
 * Execute kernel
 * 
 * @param positions          atom coordinates
 * @param velocities         atom velocities
 * @param forces             atom forces
 * @param stepSize           integration step size
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
114
115
void BrookIntegrateVerletStepKernel::execute( Stream& positions, Stream& velocities,
                                              const Stream& forces, double stepSize ){
Mark Friedrichs's avatar
Mark Friedrichs committed
116

Mark Friedrichs's avatar
Mark Friedrichs committed
117
118
// ---------------------------------------------------------------------------------------

Mark Friedrichs's avatar
Mark Friedrichs committed
119
120
   double epsilon                           = 1.0e-04;
   static const std::string methodName      = "BrookIntegrateVerletStepKernel::execute";
Mark Friedrichs's avatar
Mark Friedrichs committed
121
122

// ---------------------------------------------------------------------------------------
Mark Friedrichs's avatar
Mark Friedrichs committed
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137

   // first time through initialize _brookVerletDynamics

   // for each subsequent call, check if parameters need to be updated due to a change
   // in the step size

   // take step

   double difference = stepSize - (double) _brookVerletDynamics->getStepSize();
   if( fabs( difference ) > epsilon ){
//printf( "%s calling updateParameters\n", methodName.c_str() );
      _brookVerletDynamics->updateParameters( stepSize );
   }
   _brookVerletDynamics->update( positions, velocities, forces, *_brookShakeAlgorithm );

Mark Friedrichs's avatar
Mark Friedrichs committed
138
139
}