BrookStreamFactory.cpp 7.7 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, Mark Friedrichs                                    *
 * 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.                                     *
 * -------------------------------------------------------------------------- */

32
#include <sstream>
Mark Friedrichs's avatar
Mark Friedrichs committed
33
34
#include "OpenMMException.h"
#include "BrookStreamFactory.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
35
#include "BrookStreamImpl.h"
Mark Friedrichs's avatar
Mark Friedrichs committed
36
37
38

using namespace OpenMM;

39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const std::string BrookStreamFactory::AtomPositions              = "atomPositions";
const std::string BrookStreamFactory::AtomVelocities             = "atomVelocities";
const std::string BrookStreamFactory::AtomForces                 = "atomForces";

// bonded streams
                                    
const std::string BrookStreamFactory::BondedAtomIndicesStream    = "BondedAtomIndicesStream";
const std::string BrookStreamFactory::BondedParametersStream     = "BondedParametersStream";
const std::string BrookStreamFactory::UnrolledForceStream        = "UnrolledForceStream";
const std::string BrookStreamFactory::BondedChargeStream         = "BondedChargeStream";
const std::string BrookStreamFactory::BondedInverseMapStreams    = "BondedInverseMapStreams";

// non-bonded streams

const std::string BrookStreamFactory::NonBondedExclusionStream   = "NonBondedExclusionStream";
Mark Friedrichs's avatar
Mark Friedrichs committed
54
55
56
57
58
const std::string BrookStreamFactory::OuterVdwStream             = "OuterVdwStream";
const std::string BrookStreamFactory::InnerSigmaStream           = "InnerSigmaStream";
const std::string BrookStreamFactory::InnerEpsilonStream         = "InnerEpsilonStream";
const std::string BrookStreamFactory::NonBondedChargeStream      = "NonBondedChargeStream";
const std::string BrookStreamFactory::PartialForceStream         = "PartialForceStream";
59

Mark Friedrichs's avatar
Mark Friedrichs committed
60
const double DefaultDangleValue                                  = 1.0e+38;
61
62
63
64
65
66
67
68
/** 
 * BrookStreamFactory constructor
 * 
 * @return BrookStreamFactory
 */

BrookStreamFactory::BrookStreamFactory( void ){

Mark Friedrichs's avatar
Mark Friedrichs committed
69
// ---------------------------------------------------------------------------------------
70

Mark Friedrichs's avatar
Mark Friedrichs committed
71
   //static const std::string methodName      = "BrookStreamFactory::BrookStreamFactory";
72

Mark Friedrichs's avatar
Mark Friedrichs committed
73
// ---------------------------------------------------------------------------------------
74

Mark Friedrichs's avatar
Mark Friedrichs committed
75
76
	_defaultDangleValue                      = 1.0e+38;
	_defaultAtomStreamWidth                  = 32;
77
78
79
80
81
82
83
84
85
86
87
88

}

/** 
 * BrookStreamFactory destructor
 * 
 */

BrookStreamFactory::~BrookStreamFactory( void ){
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
89
90
91
 * Get atom stream width
 * 
 * @return atomStreamWidth
92
 *
Mark Friedrichs's avatar
Mark Friedrichs committed
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
 */

int BrookStreamFactory::getDefaultAtomStreamWidth( void ) const {

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

   //static const std::string methodName      = "BrookStreamFactory::getDefaultAtomStreamWidth";

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

   return _defaultAtomStreamWidth;
}

/** 
 * Set atom stream width
108
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
109
110
111
112
113
114
 * @param atomStreamWidth  atom stream width
 *
 * @return DefaultReturnValue
 *
 * @throw OpenMMException if atomStreamWidth < 1
 *
115
116
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
117
118
119
120
121
int BrookStreamFactory::setDefaultAtomStreamWidth( int atomStreamWidth ){

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

   static const std::string methodName      = "BrookStreamFactory::setDefaultAtomStreamWidth";
122

Mark Friedrichs's avatar
Mark Friedrichs committed
123
124
125
126
127
128
129
130
131
// ---------------------------------------------------------------------------------------

   // validate atom stream width

   if( atomStreamWidth < 1 ){
      std::stringstream message;
      message << methodName << " atomStreamWidth=" << atomStreamWidth << " is less than 1.";
      throw OpenMMException( message.str() );
      return ErrorReturnValue;
132
   }
Mark Friedrichs's avatar
Mark Friedrichs committed
133
134
135
136
137

   _defaultAtomStreamWidth = atomStreamWidth;

   return DefaultReturnValue;

138
139
140
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
141
 * get default dangle value
142
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
143
144
 * @return default dangle value
 *
145
146
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
147
148
149
150
151
double BrookStreamFactory::getDefaultDangleValue( void ) const {

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

   //static const std::string methodName      = "BrookStreamFactory::getDefaultDangleValue";
152

Mark Friedrichs's avatar
Mark Friedrichs committed
153
// ---------------------------------------------------------------------------------------
154

Mark Friedrichs's avatar
Mark Friedrichs committed
155
   return _defaultDangleValue;
156
157
158
}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
159
 * Set default dangle value
160
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
161
162
163
164
 * @param DefaultDangleValue default dangle value
 *
 * @return DefaultReturnValue
 *
165
166
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
167
168
169
170
171
172
173
174
175
176
177
int BrookStreamFactory::setDefaultDangleValue( double defaultDangleValue ){

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

   //static const std::string methodName      = "BrookStreamFactory::setDefaultDangleValue";

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

   _defaultDangleValue = defaultDangleValue;

   return DefaultReturnValue;
178
179
180
181

}

/** 
Mark Friedrichs's avatar
Mark Friedrichs committed
182
 * Create StreamInternal
183
184
185
186
187
 *
 * @param name     stream name
 * @param size     stream size
 * @param type     data type (float, float2, ...)
 * @param platform platform reference
Mark Friedrichs's avatar
Mark Friedrichs committed
188
 * @param context  context (currently ignored)
189
 * 
Mark Friedrichs's avatar
Mark Friedrichs committed
190
 * @return StreamInternal
191
192
 */

Mark Friedrichs's avatar
Mark Friedrichs committed
193
194
StreamImpl* BrookStreamFactory::createStreamImpl( std::string name, int size, Stream::DataType type,
                                                  const Platform& platform, OpenMMContextImpl& context ) const {
195
196
197

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

Mark Friedrichs's avatar
Mark Friedrichs committed
198
   //static const std::string methodName      = "BrookStreamFactory::createStreamImpl";
199
200
201
202

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


Mark Friedrichs's avatar
Mark Friedrichs committed
203
   // stream width hould be based on name & value set in platform; for now only atom stream types
204

Mark Friedrichs's avatar
Mark Friedrichs committed
205
   int streamWidth = getDefaultAtomStreamWidth();
206

Mark Friedrichs's avatar
Mark Friedrichs committed
207
   return new BrookStreamImpl( name, size, streamWidth, type, platform );
208

Mark Friedrichs's avatar
Mark Friedrichs committed
209
}