Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
5d9ae810
Commit
5d9ae810
authored
Apr 26, 2008
by
Mark Friedrichs
Browse files
Initial checkin
parent
45ed59f8
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
1394 additions
and
0 deletions
+1394
-0
platforms/brook/include/BrookKernelFactory.h
platforms/brook/include/BrookKernelFactory.h
+50
-0
platforms/brook/include/BrookPlatform.h
platforms/brook/include/BrookPlatform.h
+61
-0
platforms/brook/include/BrookStreamFactory.h
platforms/brook/include/BrookStreamFactory.h
+50
-0
platforms/brook/src/BrookFloatStreamImpl.cpp
platforms/brook/src/BrookFloatStreamImpl.cpp
+249
-0
platforms/brook/src/BrookFloatStreamImpl.h
platforms/brook/src/BrookFloatStreamImpl.h
+71
-0
platforms/brook/src/BrookIntStreamImpl.cpp
platforms/brook/src/BrookIntStreamImpl.cpp
+88
-0
platforms/brook/src/BrookIntStreamImpl.h
platforms/brook/src/BrookIntStreamImpl.h
+64
-0
platforms/brook/src/BrookKernelFactory.cpp
platforms/brook/src/BrookKernelFactory.cpp
+52
-0
platforms/brook/src/BrookKernels.cpp
platforms/brook/src/BrookKernels.cpp
+312
-0
platforms/brook/src/BrookKernels.h
platforms/brook/src/BrookKernels.h
+277
-0
platforms/brook/src/BrookPlatform.cpp
platforms/brook/src/BrookPlatform.cpp
+63
-0
platforms/brook/src/BrookStreamFactory.cpp
platforms/brook/src/BrookStreamFactory.cpp
+57
-0
No files found.
platforms/brook/include/BrookKernelFactory.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKKERNELFACTORY_H_
#define OPENMM_BROOKKERNELFACTORY_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "KernelFactory.h"
namespace
OpenMM
{
/**
* This KernelFactory creates all kernels for BrookPlatform.
*/
class
BrookKernelFactory
:
public
KernelFactory
{
public:
KernelImpl
*
createKernelImpl
(
std
::
string
name
,
const
Platform
&
platform
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKKERNELFACTORY_H_*/
platforms/brook/include/BrookPlatform.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKPLATFORM_H_
#define OPENMM_BROOKPLATFORM_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "Platform.h"
#include "BrookStreamFactory.h"
namespace
OpenMM
{
/**
* This Platform subclass uses the reference implementations of all the OpenMM kernels.
*/
class
BrookPlatform
:
public
Platform
{
public:
BrookPlatform
();
std
::
string
getName
()
const
{
return
"Brook"
;
}
double
getSpeed
()
const
{
return
10.0
;
}
bool
supportsDoublePrecision
()
const
;
const
StreamFactory
&
getDefaultStreamFactory
()
const
;
private:
BrookStreamFactory
defaultStreamFactory
;
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKPLATFORM_H_*/
platforms/brook/include/BrookStreamFactory.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKSTREAMFACTORY_H_
#define OPENMM_BROOKSTREAMFACTORY_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "StreamFactory.h"
namespace
OpenMM
{
/**
* This StreamFactory creates all streams for BrookPlatform.
*/
class
BrookStreamFactory
:
public
StreamFactory
{
public:
StreamImpl
*
createStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
int
streamWidth
,
const
Platform
&
platform
)
const
;
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKSTREAMFACTORY_H_*/
platforms/brook/src/BrookFloatStreamImpl.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookFloatStreamImpl.h"
using
namespace
OpenMM
;
BrookFloatStreamImpl
::
BrookFloatStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
int
streamWidth
,
const
Platform
&
platform
,
float
inputDefaultDangleValue
)
:
StreamImpl
(
name
,
size
,
type
,
platform
)
{
switch
(
type
)
{
case
Stream
::
Float
:
case
Stream
::
Float2
:
case
Stream
::
Float3
:
case
Stream
::
Float4
:
baseType
=
Stream
::
Float
;
break
;
case
Stream
::
Double
:
case
Stream
::
Double2
:
case
Stream
::
Double3
:
case
Stream
::
Double4
:
baseType
=
Stream
::
Float
;
break
;
}
switch
(
type
)
{
case
Stream
::
Float
:
case
Stream
::
Double
:
width
=
1
;
break
;
case
Stream
::
Float2
:
case
Stream
::
Double2
:
width
=
2
;
break
;
case
Stream
::
Float3
:
case
Stream
::
Double3
:
width
=
3
;
break
;
case
Stream
::
Float4
:
case
Stream
::
Double4
:
width
=
4
;
break
;
}
defaultDangleValue
=
inputDefaultDangleValue
;
// set stream height based on specified stream width
streamWidth
=
inputStreamWidth
;
streamHeight
=
size
/
streamWidth
+
((
size
%
streamWidth
)
?
1
:
0
);
streamSize
=
streamHeight
*
streamWidth
;
// create Brook stream handle
switch
(
width
){
case
1
:
aStream
=
brook
::
stream
::
create
<
float
>
(
streamHeight
,
streamWidth
);
break
;
case
2
:
aStream
=
brook
::
stream
::
create
<
float2
>
(
streamHeight
,
streamWidth
);
break
;
case
3
:
aStream
=
brook
::
stream
::
create
<
float3
>
(
streamHeight
,
streamWidth
);
break
;
case
4
:
aStream
=
brook
::
stream
::
create
<
float4
>
(
streamHeight
,
streamWidth
);
break
;
}
// allocate memory for data buffer
data
=
new
float
*
[
streamSize
];
for
(
int
i
=
0
;
i
<
streamSize
;
++
i
){
data
[
i
]
=
new
float
[
width
];
}
if
(
sizeof
(
float
)
!=
sizeof
(
RealOpenMM
)
){
realOpenMMData
=
new
RealOpenMM
*
[
streamSize
];
for
(
int
i
=
0
;
i
<
streamSize
;
++
i
){
realOpenMMData
[
i
]
=
new
RealOpenMM
[
width
];
}
}
else
{
realOpenMMData
=
NULL
;
}
}
BrookFloatStreamImpl
::~
BrookFloatStreamImpl
()
{
delete
aStream
;
delete
data
[];
delete
realOpenMMData
[];
}
void
BrookFloatStreamImpl
::
loadFromArray
(
const
void
*
array
)
{
if
(
baseType
==
Stream
::
Float
){
float
*
arrayData
=
(
float
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
){
for
(
int
j
=
0
;
j
<
width
;
++
j
){
data
[
i
][
j
]
=
arrayData
[
i
*
width
+
j
];
}
}
}
else
{
double
*
arrayData
=
(
double
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
){
for
(
int
j
=
0
;
j
<
width
;
++
j
){
data
[
i
][
j
]
=
(
float
)
arrayData
[
i
*
width
+
j
];
}
}
}
// set dangling values
_loadDanglingValues
();
// write to GPU
aStream
.
read
(
data
);
}
void
BrookFloatStreamImpl
::
saveToArray
(
void
*
array
)
{
// get data from GPU
aStream
.
write
(
data
);
// load into array
if
(
baseType
==
Stream
::
Float
){
float
*
arrayData
=
(
float
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
){
for
(
int
j
=
0
;
j
<
width
;
++
j
){
arrayData
[
i
*
width
+
j
]
=
data
[
i
][
j
];
}
}
}
else
{
double
*
arrayData
=
(
double
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
){
for
(
int
j
=
0
;
j
<
width
;
++
j
){
arrayData
[
i
*
width
+
j
]
=
data
[
i
][
j
];
}
}
}
}
void
BrookFloatStreamImpl
::
fillWithValue
(
void
*
value
){
if
(
baseType
==
Stream
::
Float
)
{
float
valueData
=
*
((
float
*
)
value
);
for
(
int
i
=
0
;
i
<
getSize
();
i
++
){
for
(
int
j
=
0
;
j
<
width
;
j
++
){
data
[
i
][
j
]
=
valueData
;
}
}
}
else
{
double
valueData
=
*
((
double
*
)
value
);
for
(
int
i
=
0
;
i
<
getSize
();
i
++
){
for
(
int
j
=
0
;
j
<
width
;
j
++
){
data
[
i
][
j
]
=
valueData
;
}
}
}
_loadDanglingValues
();
aStream
.
read
(
data
);
}
const
RealOpenMM
*
const
*
BrookFloatStreamImpl
::
getData
()
const
{
// retreive data from GPU
aStream
.
write
(
data
);
// check if RealOpenMM is float; if not, then
// copy into realOpenMMData[][] array
if
(
realOpenMMData
){
for
(
int
i
=
0
;
i
<
getSize
();
i
++
){
for
(
int
j
=
0
;
j
<
width
;
j
++
){
realOpenMMData
[
i
][
j
]
=
(
RealOpenMM
)
data
[
i
][
j
];
}
}
return
realOpenMMData
;
}
else
{
return
data
;
}
}
RealOpenMM
**
BrookFloatStreamImpl
::
getData
()
{
aStream
.
write
(
data
);
if
(
realOpenMMData
){
for
(
int
i
=
0
;
i
<
getSize
();
i
++
){
for
(
int
j
=
0
;
j
<
width
;
j
++
){
realOpenMMData
[
i
][
j
]
=
(
RealOpenMM
)
data
[
i
][
j
];
}
}
return
realOpenMMData
;
}
else
{
return
data
;
}
}
void
BrookFloatStreamImpl
::
_loadDanglingValues
(
float
danglingValue
){
for
(
int
ii
=
getSize
();
ii
<
streamSize
;
ii
++
){
for
(
int
jj
=
0
;
jj
<
width
;
jj
++
){
data
[
ii
][
jj
]
=
danglingValue
;
}
}
}
void
BrookFloatStreamImpl
::
_loadDanglingValues
(
void
){
_loadDanglingValues
(
defaultDangleValue
);
}
platforms/brook/src/BrookFloatStreamImpl.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKFLOATSTREAMIMPL_H_
#define OPENMM_BROOKFLOATSTREAMIMPL_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
#include <brook/brook.hpp>
#include "SimTKUtilities/SimTKOpenMMRealType.h"
namespace
OpenMM
{
/**
* This is the implementation of Float and Double streams in the reference Platform.
*/
class
BrookFloatStreamImpl
:
public
StreamImpl
{
public:
BrookFloatStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
int
streamWidth
,
const
Platform
&
platform
,
float
defaultDangleValue
);
~
BrookFloatStreamImpl
();
void
loadFromArray
(
const
void
*
array
);
void
saveToArray
(
void
*
array
);
void
fillWithValue
(
void
*
value
);
const
RealOpenMM
*
const
*
getData
()
const
;
RealOpenMM
**
getData
();
private:
int
width
;
int
streamWidth
;
int
streamHeight
;
int
streamSize
;
float
defaultDangleValue
;
Stream
::
DataType
baseType
;
brook
::
stream
aStream
;
float
**
data
;
RealOpenMM
**
realOpenMMData
;
void
_loadDanglingValues
(
void
);
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKFLOATSTREAMIMPL_H_*/
platforms/brook/src/BrookIntStreamImpl.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookIntStreamImpl.h"
using
namespace
OpenMM
;
BrookIntStreamImpl
::
BrookIntStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
const
Platform
&
platform
)
:
StreamImpl
(
name
,
size
,
type
,
platform
)
{
switch
(
type
)
{
case
Stream
::
Integer
:
width
=
1
;
break
;
case
Stream
::
Integer2
:
width
=
2
;
break
;
case
Stream
::
Integer3
:
width
=
3
;
break
;
case
Stream
::
Integer4
:
width
=
4
;
break
;
}
data
=
new
int
*
[
size
];
for
(
int
i
=
0
;
i
<
size
;
++
i
)
data
[
i
]
=
new
int
[
width
];
}
BrookIntStreamImpl
::~
BrookIntStreamImpl
()
{
delete
data
;
}
void
BrookIntStreamImpl
::
loadFromArray
(
const
void
*
array
)
{
int
*
arrayData
=
(
int
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
)
for
(
int
j
=
0
;
j
<
width
;
++
j
)
data
[
i
][
j
]
=
arrayData
[
i
*
width
+
j
];
}
void
BrookIntStreamImpl
::
saveToArray
(
void
*
array
)
{
int
*
arrayData
=
(
int
*
)
array
;
for
(
int
i
=
0
;
i
<
getSize
();
++
i
)
for
(
int
j
=
0
;
j
<
width
;
++
j
)
arrayData
[
i
*
width
+
j
]
=
data
[
i
][
j
];
}
void
BrookIntStreamImpl
::
fillWithValue
(
void
*
value
)
{
int
valueData
=
*
((
int
*
)
value
);
for
(
int
i
=
0
;
i
<
getSize
();
++
i
)
for
(
int
j
=
0
;
j
<
width
;
++
j
)
data
[
i
][
j
]
=
valueData
;
}
const
int
*
const
*
BrookIntStreamImpl
::
getData
()
const
{
return
data
;
}
int
**
BrookIntStreamImpl
::
getData
()
{
return
data
;
}
platforms/brook/src/BrookIntStreamImpl.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKINTSTREAMIMPL_H_
#define OPENMM_BROOKINTSTREAMIMPL_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "StreamImpl.h"
#include "brook/brook.hpp"
namespace
OpenMM
{
/**
* This is the implementation of Float and Double streams in the reference Platform.
*/
class
BrookIntStreamImpl
:
public
StreamImpl
{
public:
BrookIntStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
const
Platform
&
platform
);
~
BrookIntStreamImpl
();
void
loadFromArray
(
const
void
*
array
);
void
saveToArray
(
void
*
array
);
void
fillWithValue
(
void
*
value
);
const
int
*
const
*
getData
()
const
;
int
**
getData
();
private:
int
width
;
Stream
::
DataType
baseType
;
int
**
data
;
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKINTSTREAMIMPL_H_*/
platforms/brook/src/BrookKernelFactory.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookKernelFactory.h"
#include "BrookKernels.h"
using
namespace
OpenMM
;
KernelImpl
*
BrookKernelFactory
::
createKernelImpl
(
std
::
string
name
,
const
Platform
&
platform
)
const
{
if
(
name
==
CalcStandardMMForceFieldKernel
::
Name
())
return
new
BrookCalcStandardMMForceFieldKernel
(
name
,
platform
);
if
(
name
==
CalcGBSAOBCForceFieldKernel
::
Name
())
return
new
BrookCalcGBSAOBCForceFieldKernel
(
name
,
platform
);
if
(
name
==
IntegrateVerletStepKernel
::
Name
())
return
new
BrookIntegrateVerletStepKernel
(
name
,
platform
);
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
return
new
BrookIntegrateLangevinStepKernel
(
name
,
platform
);
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
return
new
BrookIntegrateBrownianStepKernel
(
name
,
platform
);
if
(
name
==
ApplyAndersenThermostatKernel
::
Name
())
return
new
BrookApplyAndersenThermostatKernel
(
name
,
platform
);
if
(
name
==
CalcKineticEnergyKernel
::
Name
())
return
new
BrookCalcKineticEnergyKernel
(
name
,
platform
);
}
platforms/brook/src/BrookKernels.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookKernels.h"
#include "BrookFloatStreamImpl.h"
#include "SimTKBrook/BrookAngleBondIxn.h"
#include "SimTKBrook/BrookBondForce.h"
#include "SimTKBrook/BrookHarmonicBondIxn.h"
#include "SimTKBrook/BrookLJCoulomb14.h"
#include "SimTKBrook/BrookLJCoulombIxn.h"
#include "SimTKBrook/BrookProperDihedralBond.h"
#include "SimTKBrook/BrookRbDihedralBond.h"
#include "SimTKBrook/BrookStochasticDynamics.h"
#include "SimTKBrook/BrookShakeAlgorithm.h"
#include <cmath>
#include <limits>
using
namespace
OpenMM
;
using
namespace
std
;
int
**
allocateIntArray
(
int
length
,
int
width
)
{
int
**
array
=
new
int
*
[
length
];
for
(
int
i
=
0
;
i
<
length
;
++
i
)
array
[
i
]
=
new
int
[
width
];
return
array
;
}
RealOpenMM
**
allocateRealArray
(
int
length
,
int
width
)
{
RealOpenMM
**
array
=
new
RealOpenMM
*
[
length
];
for
(
int
i
=
0
;
i
<
length
;
++
i
)
array
[
i
]
=
new
RealOpenMM
[
width
];
return
array
;
}
int
**
copyToArray
(
const
vector
<
vector
<
int
>
>
vec
)
{
if
(
vec
.
size
()
==
0
)
return
new
int
*
[
0
];
int
**
array
=
allocateIntArray
(
vec
.
size
(),
vec
[
0
].
size
());
for
(
int
i
=
0
;
i
<
vec
.
size
();
++
i
)
for
(
int
j
=
0
;
j
<
vec
[
i
].
size
();
++
j
)
array
[
i
][
j
]
=
vec
[
i
][
j
];
return
array
;
}
RealOpenMM
**
copyToArray
(
const
vector
<
vector
<
double
>
>
vec
)
{
if
(
vec
.
size
()
==
0
)
return
new
RealOpenMM
*
[
0
];
RealOpenMM
**
array
=
allocateRealArray
(
vec
.
size
(),
vec
[
0
].
size
());
for
(
int
i
=
0
;
i
<
vec
.
size
();
++
i
)
for
(
int
j
=
0
;
j
<
vec
[
i
].
size
();
++
j
)
array
[
i
][
j
]
=
vec
[
i
][
j
];
return
array
;
}
void
disposeIntArray
(
int
**
array
,
int
size
)
{
if
(
array
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
delete
[]
array
[
i
];
delete
[]
array
;
}
}
void
disposeRealArray
(
RealOpenMM
**
array
,
int
size
)
{
if
(
array
)
{
for
(
int
i
=
0
;
i
<
size
;
++
i
)
delete
[]
array
[
i
];
delete
[]
array
;
}
}
BrookCalcStandardMMForceFieldKernel
::~
BrookCalcStandardMMForceFieldKernel
()
{
disposeIntArray
(
bondIndexArray
,
numBonds
);
disposeRealArray
(
bondParamArray
,
numBonds
);
disposeIntArray
(
angleIndexArray
,
numAngles
);
disposeRealArray
(
angleParamArray
,
numAngles
);
disposeIntArray
(
periodicTorsionIndexArray
,
numPeriodicTorsions
);
disposeRealArray
(
periodicTorsionParamArray
,
numPeriodicTorsions
);
disposeIntArray
(
rbTorsionIndexArray
,
numRBTorsions
);
disposeRealArray
(
rbTorsionParamArray
,
numRBTorsions
);
disposeRealArray
(
atomParamArray
,
numAtoms
);
disposeIntArray
(
exclusionArray
,
numAtoms
);
disposeIntArray
(
bonded14IndexArray
,
num14
);
disposeRealArray
(
bonded14ParamArray
,
num14
);
}
void
BrookCalcStandardMMForceFieldKernel
::
initialize
(
const
vector
<
vector
<
int
>
>&
bondIndices
,
const
vector
<
vector
<
double
>
>&
bondParameters
,
const
vector
<
vector
<
int
>
>&
angleIndices
,
const
vector
<
vector
<
double
>
>&
angleParameters
,
const
vector
<
vector
<
int
>
>&
periodicTorsionIndices
,
const
vector
<
vector
<
double
>
>&
periodicTorsionParameters
,
const
vector
<
vector
<
int
>
>&
rbTorsionIndices
,
const
vector
<
vector
<
double
>
>&
rbTorsionParameters
,
const
vector
<
vector
<
int
>
>&
bonded14Indices
,
double
lj14Scale
,
double
coulomb14Scale
,
const
vector
<
set
<
int
>
>&
exclusions
,
const
vector
<
vector
<
double
>
>&
nonbondedParameters
)
{
numAtoms
=
nonbondedParameters
.
size
();
numBonds
=
bondIndices
.
size
();
numAngles
=
angleIndices
.
size
();
numPeriodicTorsions
=
periodicTorsionIndices
.
size
();
numRBTorsions
=
rbTorsionIndices
.
size
();
num14
=
bonded14Indices
.
size
();
bondIndexArray
=
copyToArray
(
bondIndices
);
bondParamArray
=
copyToArray
(
bondParameters
);
angleIndexArray
=
copyToArray
(
angleIndices
);
angleParamArray
=
copyToArray
(
angleParameters
);
periodicTorsionIndexArray
=
copyToArray
(
periodicTorsionIndices
);
periodicTorsionParamArray
=
copyToArray
(
periodicTorsionParameters
);
rbTorsionIndexArray
=
copyToArray
(
rbTorsionIndices
);
rbTorsionParamArray
=
copyToArray
(
rbTorsionParameters
);
atomParamArray
=
allocateRealArray
(
numAtoms
,
3
);
RealOpenMM
sqrtEps
=
std
::
sqrt
(
138.935485
);
for
(
int
i
=
0
;
i
<
numAtoms
;
++
i
)
{
atomParamArray
[
i
][
0
]
=
0.5
*
nonbondedParameters
[
i
][
1
];
atomParamArray
[
i
][
1
]
=
2.0
*
sqrt
(
nonbondedParameters
[
i
][
2
]);
atomParamArray
[
i
][
2
]
=
nonbondedParameters
[
i
][
0
]
*
sqrtEps
;
}
exclusionArray
=
new
int
*
[
numAtoms
];
for
(
int
i
=
0
;
i
<
numAtoms
;
++
i
)
{
exclusionArray
[
i
]
=
new
int
[
exclusions
[
i
].
size
()
+
1
];
exclusionArray
[
i
][
0
]
=
exclusions
[
i
].
size
();
int
index
=
0
;
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
exclusionArray
[
i
][
++
index
]
=
*
iter
;
}
bonded14IndexArray
=
copyToArray
(
bonded14Indices
);
bonded14ParamArray
=
allocateRealArray
(
num14
,
3
);
for
(
int
i
=
0
;
i
<
num14
;
++
i
)
{
int
atom1
=
bonded14Indices
[
i
][
0
];
int
atom2
=
bonded14Indices
[
i
][
1
];
bonded14ParamArray
[
i
][
0
]
=
atomParamArray
[
atom1
][
0
]
+
atomParamArray
[
atom2
][
0
];
bonded14ParamArray
[
i
][
1
]
=
lj14Scale
*
(
atomParamArray
[
atom1
][
1
]
*
atomParamArray
[
atom2
][
1
]);
bonded14ParamArray
[
i
][
2
]
=
coulomb14Scale
*
(
atomParamArray
[
atom1
][
2
]
*
atomParamArray
[
atom2
][
2
]);
}
}
void
BrookCalcStandardMMForceFieldKernel
::
executeForces
(
const
Stream
&
positions
,
Stream
&
forces
)
{
RealOpenMM
**
posData
=
const_cast
<
RealOpenMM
**>
(((
BrookFloatStreamImpl
&
)
positions
.
getImpl
()).
getData
());
// Brook code needs to be made const correct
RealOpenMM
**
forceData
=
((
BrookFloatStreamImpl
&
)
forces
.
getImpl
()).
getData
();
BrookBondForce
refBondForce
;
BrookHarmonicBondIxn
harmonicBond
;
refBondForce
.
calculateForce
(
numBonds
,
bondIndexArray
,
posData
,
bondParamArray
,
forceData
,
0
,
0
,
0
,
harmonicBond
);
BrookAngleBondIxn
angleBond
;
refBondForce
.
calculateForce
(
numAngles
,
angleIndexArray
,
posData
,
angleParamArray
,
forceData
,
0
,
0
,
0
,
angleBond
);
BrookProperDihedralBond
periodicTorsionBond
;
refBondForce
.
calculateForce
(
numPeriodicTorsions
,
periodicTorsionIndexArray
,
posData
,
periodicTorsionParamArray
,
forceData
,
0
,
0
,
0
,
periodicTorsionBond
);
BrookRbDihedralBond
rbTorsionBond
;
refBondForce
.
calculateForce
(
numRBTorsions
,
rbTorsionIndexArray
,
posData
,
rbTorsionParamArray
,
forceData
,
0
,
0
,
0
,
rbTorsionBond
);
BrookLJCoulombIxn
clj
;
clj
.
calculatePairIxn
(
numAtoms
,
posData
,
atomParamArray
,
exclusionArray
,
0
,
forceData
,
0
,
0
);
BrookLJCoulomb14
nonbonded14
;
refBondForce
.
calculateForce
(
num14
,
bonded14IndexArray
,
posData
,
bonded14ParamArray
,
forceData
,
0
,
0
,
0
,
nonbonded14
);
}
double
BrookCalcStandardMMForceFieldKernel
::
executeEnergy
(
const
Stream
&
positions
)
{
RealOpenMM
**
posData
=
const_cast
<
RealOpenMM
**>
(((
BrookFloatStreamImpl
&
)
positions
.
getImpl
()).
getData
());
// Brook code needs to be made const correct
RealOpenMM
**
forceData
=
allocateRealArray
(
numAtoms
,
3
);
int
arraySize
=
max
(
max
(
max
(
max
(
numAtoms
,
numBonds
),
numAngles
),
numPeriodicTorsions
),
numRBTorsions
);
RealOpenMM
*
energyArray
=
new
RealOpenMM
[
arraySize
];
RealOpenMM
energy
=
0
;
BrookBondForce
refBondForce
;
BrookHarmonicBondIxn
harmonicBond
;
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
energyArray
[
i
]
=
0
;
refBondForce
.
calculateForce
(
numBonds
,
bondIndexArray
,
posData
,
bondParamArray
,
forceData
,
energyArray
,
0
,
&
energy
,
harmonicBond
);
BrookAngleBondIxn
angleBond
;
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
energyArray
[
i
]
=
0
;
refBondForce
.
calculateForce
(
numAngles
,
angleIndexArray
,
posData
,
angleParamArray
,
forceData
,
energyArray
,
0
,
&
energy
,
angleBond
);
BrookProperDihedralBond
periodicTorsionBond
;
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
energyArray
[
i
]
=
0
;
refBondForce
.
calculateForce
(
numPeriodicTorsions
,
periodicTorsionIndexArray
,
posData
,
periodicTorsionParamArray
,
forceData
,
energyArray
,
0
,
&
energy
,
periodicTorsionBond
);
BrookRbDihedralBond
rbTorsionBond
;
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
energyArray
[
i
]
=
0
;
refBondForce
.
calculateForce
(
numRBTorsions
,
rbTorsionIndexArray
,
posData
,
rbTorsionParamArray
,
forceData
,
energyArray
,
0
,
&
energy
,
rbTorsionBond
);
BrookLJCoulombIxn
clj
;
clj
.
calculatePairIxn
(
numAtoms
,
posData
,
atomParamArray
,
exclusionArray
,
0
,
forceData
,
0
,
&
energy
);
BrookLJCoulomb14
nonbonded14
;
for
(
int
i
=
0
;
i
<
arraySize
;
++
i
)
energyArray
[
i
]
=
0
;
refBondForce
.
calculateForce
(
num14
,
bonded14IndexArray
,
posData
,
bonded14ParamArray
,
forceData
,
energyArray
,
0
,
&
energy
,
nonbonded14
);
disposeRealArray
(
forceData
,
numAtoms
);
delete
[]
energyArray
;
return
energy
;
}
void
BrookCalcGBSAOBCForceFieldKernel
::
initialize
(
const
vector
<
double
>&
bornRadii
,
const
vector
<
vector
<
double
>
>&
atomParameters
,
double
solventDielectric
,
double
soluteDielectric
)
{
}
void
BrookCalcGBSAOBCForceFieldKernel
::
executeForces
(
const
Stream
&
positions
,
Stream
&
forces
)
{
}
double
BrookCalcGBSAOBCForceFieldKernel
::
executeEnergy
(
const
Stream
&
positions
)
{
return
0.0
;
// TODO implement correctly
}
void
BrookIntegrateVerletStepKernel
::
initialize
(
const
vector
<
double
>&
masses
,
const
vector
<
vector
<
int
>
>&
constraintIndices
,
const
vector
<
double
>&
constraintLengths
)
{
}
void
BrookIntegrateVerletStepKernel
::
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
stepSize
)
{
}
#include <iostream>
BrookIntegrateLangevinStepKernel
::~
BrookIntegrateLangevinStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
shake
)
delete
shake
;
if
(
masses
)
delete
[]
masses
;
if
(
constraintIndices
)
disposeIntArray
(
constraintIndices
,
numConstraints
);
if
(
shakeParameters
)
disposeRealArray
(
shakeParameters
,
numConstraints
);
}
void
BrookIntegrateLangevinStepKernel
::
initialize
(
const
vector
<
double
>&
masses
,
const
vector
<
vector
<
int
>
>&
constraintIndices
,
const
vector
<
double
>&
constraintLengths
)
{
this
->
masses
=
new
RealOpenMM
[
masses
.
size
()];
for
(
int
i
=
0
;
i
<
masses
.
size
();
++
i
)
this
->
masses
[
i
]
=
masses
[
i
];
numConstraints
=
constraintIndices
.
size
();
this
->
constraintIndices
=
allocateIntArray
(
numConstraints
,
2
);
for
(
int
i
=
0
;
i
<
numConstraints
;
++
i
)
{
this
->
constraintIndices
[
i
][
0
]
=
constraintIndices
[
i
][
0
];
this
->
constraintIndices
[
i
][
1
]
=
constraintIndices
[
i
][
1
];
}
shakeParameters
=
allocateRealArray
(
constraintLengths
.
size
(),
1
);
for
(
int
i
=
0
;
i
<
constraintLengths
.
size
();
++
i
)
shakeParameters
[
i
][
0
]
=
constraintLengths
[
i
];
}
void
BrookIntegrateLangevinStepKernel
::
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
temperature
,
double
friction
,
double
stepSize
)
{
RealOpenMM
**
posData
=
((
BrookFloatStreamImpl
&
)
positions
.
getImpl
()).
getData
();
RealOpenMM
**
velData
=
((
BrookFloatStreamImpl
&
)
velocities
.
getImpl
()).
getData
();
RealOpenMM
**
forceData
=
const_cast
<
RealOpenMM
**>
(((
BrookFloatStreamImpl
&
)
forces
.
getImpl
()).
getData
());
// Brook code needs to be made const correct
if
(
dynamics
==
0
||
temperature
!=
prevTemp
||
friction
!=
prevFriction
||
stepSize
!=
prevStepSize
)
{
// Recreate the computation objects with the new parameters.
if
(
dynamics
)
{
delete
dynamics
;
delete
shake
;
}
RealOpenMM
tau
=
(
friction
==
0.0
?
0.0
:
1.0
/
friction
);
dynamics
=
new
BrookStochasticDynamics
(
positions
.
getSize
(),
stepSize
,
tau
,
temperature
);
shake
=
new
BrookShakeAlgorithm
(
numConstraints
,
constraintIndices
,
shakeParameters
);
dynamics
->
setBrookShakeAlgorithm
(
shake
);
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
dynamics
->
update
(
positions
.
getSize
(),
posData
,
velData
,
forceData
,
masses
);
}
void
BrookIntegrateBrownianStepKernel
::
initialize
(
const
vector
<
double
>&
masses
,
const
vector
<
vector
<
int
>
>&
constraintIndices
,
const
vector
<
double
>&
constraintLengths
)
{
}
void
BrookIntegrateBrownianStepKernel
::
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
temperature
,
double
friction
,
double
stepSize
)
{
}
void
BrookApplyAndersenThermostatKernel
::
initialize
(
const
vector
<
double
>&
masses
)
{
}
void
BrookApplyAndersenThermostatKernel
::
execute
(
Stream
&
velocities
,
double
temperature
,
double
collisionFrequency
,
double
stepSize
)
{
}
void
BrookCalcKineticEnergyKernel
::
initialize
(
const
vector
<
double
>&
masses
)
{
this
->
masses
=
masses
;
}
double
BrookCalcKineticEnergyKernel
::
execute
(
const
Stream
&
velocities
)
{
RealOpenMM
**
velData
=
const_cast
<
RealOpenMM
**>
(((
BrookFloatStreamImpl
&
)
velocities
.
getImpl
()).
getData
());
// Brook code needs to be made const correct
double
energy
=
0.0
;
for
(
int
i
=
0
;
i
<
masses
.
size
();
++
i
)
energy
+=
masses
[
i
]
*
(
velData
[
i
][
0
]
*
velData
[
i
][
0
]
+
velData
[
i
][
1
]
*
velData
[
i
][
1
]
+
velData
[
i
][
2
]
*
velData
[
i
][
2
]);
return
0.5
*
energy
;
}
platforms/brook/src/BrookKernels.h
0 → 100644
View file @
5d9ae810
#ifndef OPENMM_BROOKKERNELS_H_
#define OPENMM_BROOKKERNELS_H_
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "kernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
class
BrookStochasticDynamics
;
class
BrookShakeAlgorithm
;
namespace
OpenMM
{
/**
* This kernel is invoked by StandardMMForceField to calculate the forces acting on the system.
*/
class
BrookCalcStandardMMForceFieldKernel
:
public
CalcStandardMMForceFieldKernel
{
public:
BrookCalcStandardMMForceFieldKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
CalcStandardMMForceFieldKernel
(
name
,
platform
)
{
}
~
BrookCalcStandardMMForceFieldKernel
();
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bondIndices the two atoms connected by each bond term
* @param bondParameters the force parameters (length, k) for each bond term
* @param angleIndices the three atoms connected by each angle term
* @param angleParameters the force parameters (angle, k) for each angle term
* @param periodicTorsionIndices the four atoms connected by each periodic torsion term
* @param periodicTorsionParameters the force parameters (k, phase, periodicity) for each periodic torsion term
* @param rbTorsionIndices the four atoms connected by each Ryckaert-Bellemans torsion term
* @param rbTorsionParameters the coefficients (in order of increasing powers) for each Ryckaert-Bellemans torsion term
* @param bonded14Indices each element contains the indices of two atoms whose nonbonded interactions should be reduced since
* they form a bonded 1-4 pair
* @param lj14Scale the factor by which van der Waals interactions should be reduced for bonded 1-4 pairs
* @param coulomb14Scale the factor by which Coulomb interactions should be reduced for bonded 1-4 pairs
* @param exclusions the i'th element lists the indices of all atoms with which the i'th atom should not interact through
* nonbonded forces. Bonded 1-4 pairs are also included in this list, since they should be omitted from
* the standard nonbonded calculation.
* @param nonbondedParameters the nonbonded force parameters (charge, sigma, epsilon) for each atom
*/
void
initialize
(
const
std
::
vector
<
std
::
vector
<
int
>
>&
bondIndices
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
bondParameters
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
angleIndices
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
angleParameters
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
periodicTorsionIndices
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
periodicTorsionParameters
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
rbTorsionIndices
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
rbTorsionParameters
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
bonded14Indices
,
double
lj14Scale
,
double
coulomb14Scale
,
const
std
::
vector
<
std
::
set
<
int
>
>&
exclusions
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
nonbondedParameters
);
/**
* Execute the kernel to calculate the forces.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
void
executeForces
(
const
Stream
&
positions
,
Stream
&
forces
);
/**
* Execute the kernel to calculate the energy.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @return the potential energy due to the StandardMMForceField
*/
double
executeEnergy
(
const
Stream
&
positions
);
private:
int
numAtoms
,
numBonds
,
numAngles
,
numPeriodicTorsions
,
numRBTorsions
,
num14
;
int
**
bondIndexArray
,
**
angleIndexArray
,
**
periodicTorsionIndexArray
,
**
rbTorsionIndexArray
,
**
exclusionArray
,
**
bonded14IndexArray
;
RealOpenMM
**
bondParamArray
,
**
angleParamArray
,
**
periodicTorsionParamArray
,
**
rbTorsionParamArray
,
**
atomParamArray
,
**
bonded14ParamArray
;
};
/**
* This kernel is invoked by GBSAOBCForceField to calculate the forces acting on the system.
*/
class
BrookCalcGBSAOBCForceFieldKernel
:
public
CalcGBSAOBCForceFieldKernel
{
public:
BrookCalcGBSAOBCForceFieldKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
CalcGBSAOBCForceFieldKernel
(
name
,
platform
)
{
}
/**
* Initialize the kernel, setting up the values of all the force field parameters.
*
* @param bornRadii the initial value of the Born radius for each atom
* @param atomParameters the force parameters (charge, atomic radius, scaling factor) for each atom
* @param solventDielectric the dielectric constant of the solvent
* @param soluteDielectric the dielectric constant of the solute
*/
void
initialize
(
const
std
::
vector
<
double
>&
bornRadii
,
const
std
::
vector
<
std
::
vector
<
double
>
>&
atomParameters
,
double
solventDielectric
,
double
soluteDielectric
);
/**
* Execute the kernel to calculate the forces.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom. On entry, this contains the forces that
* have been calculated so far. The kernel should add its own forces to the values already in the stream.
*/
void
executeForces
(
const
Stream
&
positions
,
Stream
&
forces
);
/**
* Execute the kernel to calculate the energy.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @return the potential energy due to the GBSAOBCForceField
*/
double
executeEnergy
(
const
Stream
&
positions
);
};
/**
* This kernel is invoked by VerletIntegrator to take one time step.
*/
class
BrookIntegrateVerletStepKernel
:
public
IntegrateVerletStepKernel
{
public:
BrookIntegrateVerletStepKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
IntegrateVerletStepKernel
(
name
,
platform
)
{
}
/**
* 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
*/
void
initialize
(
const
std
::
vector
<
double
>&
masses
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
constraintIndices
,
const
std
::
vector
<
double
>&
constraintLengths
);
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param stepSize the integration step size
*/
void
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
stepSize
);
};
/**
* This kernel is invoked by LangevinIntegrator to take one time step.
*/
class
BrookIntegrateLangevinStepKernel
:
public
IntegrateLangevinStepKernel
{
public:
BrookIntegrateLangevinStepKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
IntegrateLangevinStepKernel
(
name
,
platform
),
dynamics
(
0
),
shake
(
0
),
masses
(
0
),
shakeParameters
(
0
),
constraintIndices
(
0
)
{
}
~
BrookIntegrateLangevinStepKernel
();
/**
* 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
*/
void
initialize
(
const
std
::
vector
<
double
>&
masses
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
constraintIndices
,
const
std
::
vector
<
double
>&
constraintLengths
);
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/
void
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
temperature
,
double
friction
,
double
stepSize
);
private:
BrookStochasticDynamics
*
dynamics
;
BrookShakeAlgorithm
*
shake
;
RealOpenMM
*
masses
;
RealOpenMM
**
shakeParameters
;
int
**
constraintIndices
;
int
numConstraints
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
};
/**
* This kernel is invoked by BrownianIntegrator to take one time step.
*/
class
BrookIntegrateBrownianStepKernel
:
public
IntegrateBrownianStepKernel
{
public:
BrookIntegrateBrownianStepKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
IntegrateBrownianStepKernel
(
name
,
platform
)
{
}
/**
* 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
*/
void
initialize
(
const
std
::
vector
<
double
>&
masses
,
const
std
::
vector
<
std
::
vector
<
int
>
>&
constraintIndices
,
const
std
::
vector
<
double
>&
constraintLengths
);
/**
* Execute the kernel.
*
* @param positions a Stream of type Double3 containing the position (x, y, z) of each atom
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param forces a Stream of type Double3 containing the force (x, y, z) on each atom
* @param temperature the temperature of the heat bath
* @param friction the friction coefficient coupling the system to the heat bath
* @param stepSize the integration step size
*/
void
execute
(
Stream
&
positions
,
Stream
&
velocities
,
const
Stream
&
forces
,
double
temperature
,
double
friction
,
double
stepSize
);
};
/**
* This kernel is invoked by AndersenThermostat at the start of each time step to adjust the atom velocities.
*/
class
BrookApplyAndersenThermostatKernel
:
public
ApplyAndersenThermostatKernel
{
public:
BrookApplyAndersenThermostatKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
ApplyAndersenThermostatKernel
(
name
,
platform
)
{
}
/**
* Initialize the kernel, setting up the values of unchanging parameters.
*
* @param masses the mass of each atom
*/
void
initialize
(
const
std
::
vector
<
double
>&
masses
);
/**
* Execute the kernel.
*
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @param temperature the temperature of the heat bath
* @param collisionFrequency the frequency at which atom collide with particles in the heat bath
* @param stepSize the integration step size
*/
void
execute
(
Stream
&
velocities
,
double
temperature
,
double
collisionFrequency
,
double
stepSize
);
};
/**
* This kernel is invoked to calculate the kinetic energy of the system.
*/
class
BrookCalcKineticEnergyKernel
:
public
CalcKineticEnergyKernel
{
public:
BrookCalcKineticEnergyKernel
(
std
::
string
name
,
const
Platform
&
platform
)
:
CalcKineticEnergyKernel
(
name
,
platform
)
{
}
/**
* Initialize the kernel, setting up the atomic masses.
*
* @param masses the mass of each atom
*/
void
initialize
(
const
std
::
vector
<
double
>&
masses
);
/**
* Execute the kernel.
*
* @param velocities a Stream of type Double3 containing the velocity (x, y, z) of each atom
* @return the kinetic energy of the system
*/
double
execute
(
const
Stream
&
velocities
);
private:
std
::
vector
<
double
>
masses
;
};
}
// namespace OpenMM
#endif
/*OPENMM_BROOKKERNELS_H_*/
platforms/brook/src/BrookPlatform.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "BrookPlatform.h"
#include "BrookKernelFactory.h"
#include "BrookKernels.h"
#include "SimTKUtilities/SimTKOpenMMRealType.h"
using
namespace
OpenMM
;
BrookPlatform
*
registerBrookPlatform
()
{
BrookPlatform
*
platform
=
new
BrookPlatform
();
Platform
::
registerPlatform
(
platform
);
}
BrookPlatform
*
staticPlatform
=
registerBrookPlatform
();
BrookPlatform
::
BrookPlatform
()
{
BrookKernelFactory
*
factory
=
new
BrookKernelFactory
();
registerKernelFactory
(
CalcStandardMMForceFieldKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGBSAOBCForceFieldKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
ApplyAndersenThermostatKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcKineticEnergyKernel
::
Name
(),
factory
);
}
bool
BrookPlatform
::
supportsDoublePrecision
()
const
{
return
(
sizeof
(
RealOpenMM
)
>=
sizeof
(
double
));
}
const
StreamFactory
&
BrookPlatform
::
getDefaultStreamFactory
()
const
{
return
defaultStreamFactory
;
}
platforms/brook/src/BrookStreamFactory.cpp
0 → 100644
View file @
5d9ae810
/* -------------------------------------------------------------------------- *
* 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. *
* -------------------------------------------------------------------------- */
#include "OpenMMException.h"
#include "BrookStreamFactory.h"
#include "BrookFloatStreamImpl.h"
#include "BrookIntStreamImpl.h"
using
namespace
OpenMM
;
StreamImpl
*
BrookStreamFactory
::
createStreamImpl
(
std
::
string
name
,
int
size
,
Stream
::
DataType
type
,
int
streamWidth
,
const
Platform
&
platform
)
const
{
switch
(
type
)
{
case
Stream
::
Float
:
case
Stream
::
Float2
:
case
Stream
::
Float3
:
case
Stream
::
Float4
:
case
Stream
::
Double
:
case
Stream
::
Double2
:
case
Stream
::
Double3
:
case
Stream
::
Double4
:
return
new
BrookFloatStreamImpl
(
name
,
size
,
type
,
streamWidth
,
platform
);
case
Stream
::
Integer
:
case
Stream
::
Integer2
:
case
Stream
::
Integer3
:
case
Stream
::
Integer4
:
return
new
BrookIntStreamImpl
(
name
,
size
,
type
,
streamWidth
,
platform
);
}
throw
OpenMMException
(
"Tried to create a Stream with an illegal DataType."
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment