BrookRemoveCMMotionKernel.cpp 5.4 KB
Newer Older
Mark Friedrichs's avatar
Mark Friedrichs committed
1
2
3
4
5
6
7
8
9
/* -------------------------------------------------------------------------- *
 *                                   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.           *
Mark Friedrichs's avatar
Mark Friedrichs committed
10
 * Authors: Peter Eastman                                                     *
Mark Friedrichs's avatar
Mark Friedrichs committed
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 * 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
33
#include "BrookRemoveCMMotionKernel.h"
#include "BrookStreamInternal.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
34
35

using namespace OpenMM;
Mark Friedrichs's avatar
Mark Friedrichs committed
36
using namespace std;
Mark Friedrichs's avatar
Mark Friedrichs committed
37

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

Mark Friedrichs's avatar
Mark Friedrichs committed
46
47
BrookRemoveCMMotionKernel::BrookRemoveCMMotionKernel( std::string name, const Platform& platform ) :
                              RemoveCMMotionKernel( name, platform ){
48
49
50

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

Mark Friedrichs's avatar
Mark Friedrichs committed
51
   // static const std::string methodName      = "BrookRemoveCMMotionKernel::BrookRemoveCMMotionKernel";
52
53
54

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

Mark Friedrichs's avatar
Mark Friedrichs committed
55
56
}

57
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
58
 * BrookRemoveCMMotionKernel destructor
59
60
 * 
 */
Mark Friedrichs's avatar
Mark Friedrichs committed
61
62
  
BrookRemoveCMMotionKernel::~BrookRemoveCMMotionKernel( ){
63
64
65

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

Mark Friedrichs's avatar
Mark Friedrichs committed
66
   // static const std::string methodName      = "BrookRemoveCMMotionKernel::~BrookRemoveCMMotionKernel";
67
68
69

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

Mark Friedrichs's avatar
Mark Friedrichs committed
70
71
}

72
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
73
 * Initialize the kernel
74
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
75
 * @param masses   array of atom masses
76
77
78
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
79
void BrookRemoveCMMotionKernel::initialize( const vector<double>& masses ){
80
81
82

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

Mark Friedrichs's avatar
Mark Friedrichs committed
83
   // static const std::string methodName      = "BrookRemoveCMMotionKernel::initialize";
84
85
86

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

Mark Friedrichs's avatar
Mark Friedrichs committed
87
88
89
90
91
92
93
94
/*
    this->masses.resize(masses.size());
    for (size_t i = 0; i < masses.size(); ++i)
        this->masses[i] = masses[i];
*/

   return;

Mark Friedrichs's avatar
Mark Friedrichs committed
95
96
}

97
/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
98
 * Execute kernel
99
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
100
 * @param velocities  array of atom velocities
101
102
103
 *
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
104
void BrookRemoveCMMotionKernel::execute( Stream& velocities ){
105
106
107

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

Mark Friedrichs's avatar
Mark Friedrichs committed
108
   // static const std::string methodName      = "BrookRemoveCMMotionKernel::execute";
109
110
111

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

Mark Friedrichs's avatar
Mark Friedrichs committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*
    RealOpenMM** velData = ((BrookFloatStreamImpl&) velocities.getImpl()).getData();
    
    // Calculate the center of mass momentum.
    
    RealOpenMM momentum[] = {0.0, 0.0, 0.0};
    for (size_t i = 0; i < masses.size(); ++i) {
        momentum[0] += static_cast<RealOpenMM>( masses[i]*velData[i][0] );
        momentum[1] += static_cast<RealOpenMM>( masses[i]*velData[i][1] );
        momentum[2] += static_cast<RealOpenMM>( masses[i]*velData[i][2] );
    }
    
    // Adjust the atom velocities.
    
    momentum[0] /= static_cast<RealOpenMM>( masses.size() );
    momentum[1] /= static_cast<RealOpenMM>( masses.size() );
    momentum[2] /= static_cast<RealOpenMM>( masses.size() );
    for (size_t i = 0; i < masses.size(); ++i) {
        velData[i][0] -= static_cast<RealOpenMM>( momentum[0]/masses[i] );
        velData[i][1] -= static_cast<RealOpenMM>( momentum[1]/masses[i] );
        velData[i][2] -= static_cast<RealOpenMM>( momentum[2]/masses[i] );
    }
*/
   return;
Mark Friedrichs's avatar
Mark Friedrichs committed
136
}