Commit d7b3a3c2 authored by Lee-Ping Wang's avatar Lee-Ping Wang
Browse files

Merge branch 'master' of github.com:SimTk/openmm

parents 7bb2bb89 99df6758
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
using namespace OpenMM; using namespace OpenMM;
extern "C" void registerPlatforms() { extern "C" OPENMM_EXPORT void registerPlatforms() {
} }
extern "C" void registerKernelFactories() { extern "C" OPENMM_EXPORT void registerKernelFactories() {
try { try {
Platform& platform = Platform::getPlatformByName("OpenCL"); Platform& platform = Platform::getPlatformByName("OpenCL");
OpenCLDrudeKernelFactory* factory = new OpenCLDrudeKernelFactory(); OpenCLDrudeKernelFactory* factory = new OpenCLDrudeKernelFactory();
......
...@@ -34,10 +34,10 @@ ...@@ -34,10 +34,10 @@
using namespace OpenMM; using namespace OpenMM;
extern "C" void registerPlatforms() { extern "C" OPENMM_EXPORT void registerPlatforms() {
} }
extern "C" void registerKernelFactories() { extern "C" OPENMM_EXPORT void registerKernelFactories() {
try { try {
Platform& platform = Platform::getPlatformByName("CUDA"); Platform& platform = Platform::getPlatformByName("CUDA");
CudaRpmdKernelFactory* factory = new CudaRpmdKernelFactory(); CudaRpmdKernelFactory* factory = new CudaRpmdKernelFactory();
......
...@@ -296,12 +296,25 @@ void CudaIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& pos ...@@ -296,12 +296,25 @@ void CudaIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& pos
throw OpenMMException("RPMDIntegrator: Cannot set positions before the integrator is added to a Context"); throw OpenMMException("RPMDIntegrator: Cannot set positions before the integrator is added to a Context");
if (pos.size() != numParticles) if (pos.size() != numParticles)
throw OpenMMException("RPMDIntegrator: wrong number of values passed to setPositions()"); throw OpenMMException("RPMDIntegrator: wrong number of values passed to setPositions()");
// Adjust the positions based on the current cell offsets.
const vector<int>& order = cu.getAtomIndex();
double4 periodicBoxSize = cu.getPeriodicBoxSize();
vector<Vec3> offsetPos(numParticles);
for (int i = 0; i < numParticles; ++i) {
int4 offset = cu.getPosCellOffsets()[i];
offsetPos[order[i]] = pos[order[i]] + Vec3(offset.x*periodicBoxSize.x, offset.y*periodicBoxSize.y, offset.z*periodicBoxSize.z);
}
// Record the positions.
CUresult result; CUresult result;
if (cu.getUseDoublePrecision()) { if (cu.getUseDoublePrecision()) {
vector<double4> posq(cu.getPaddedNumAtoms()); vector<double4> posq(cu.getPaddedNumAtoms());
cu.getPosq().download(posq); cu.getPosq().download(posq);
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = make_double4(pos[i][0], pos[i][1], pos[i][2], posq[i].w); posq[i] = make_double4(offsetPos[i][0], offsetPos[i][1], offsetPos[i][2], posq[i].w);
result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(double4), &posq[0], numParticles*sizeof(double4)); result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(double4), &posq[0], numParticles*sizeof(double4));
} }
else if (cu.getUseMixedPrecision()) { else if (cu.getUseMixedPrecision()) {
...@@ -309,14 +322,14 @@ void CudaIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& pos ...@@ -309,14 +322,14 @@ void CudaIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& pos
cu.getPosq().download(posqf); cu.getPosq().download(posqf);
vector<double4> posq(cu.getPaddedNumAtoms()); vector<double4> posq(cu.getPaddedNumAtoms());
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = make_double4(pos[i][0], pos[i][1], pos[i][2], posqf[i].w); posq[i] = make_double4(offsetPos[i][0], offsetPos[i][1], offsetPos[i][2], posqf[i].w);
result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(double4), &posq[0], numParticles*sizeof(double4)); result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(double4), &posq[0], numParticles*sizeof(double4));
} }
else { else {
vector<float4> posq(cu.getPaddedNumAtoms()); vector<float4> posq(cu.getPaddedNumAtoms());
cu.getPosq().download(posq); cu.getPosq().download(posq);
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = make_float4((float) pos[i][0], (float) pos[i][1], (float) pos[i][2], posq[i].w); posq[i] = make_float4((float) offsetPos[i][0], (float) offsetPos[i][1], (float) offsetPos[i][2], posq[i].w);
result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(float4), &posq[0], numParticles*sizeof(float4)); result = cuMemcpyHtoD(positions->getDevicePointer()+copy*cu.getPaddedNumAtoms()*sizeof(float4), &posq[0], numParticles*sizeof(float4));
} }
if (result != CUDA_SUCCESS) { if (result != CUDA_SUCCESS) {
......
...@@ -28,16 +28,16 @@ ...@@ -28,16 +28,16 @@
#include "OpenCLRpmdKernelFactory.h" #include "OpenCLRpmdKernelFactory.h"
#include "OpenCLRpmdKernels.h" #include "OpenCLRpmdKernels.h"
#include "openmm/internal/windowsExport.h" #include "openmm/internal/windowsExportRpmd.h"
#include "openmm/internal/ContextImpl.h" #include "openmm/internal/ContextImpl.h"
#include "openmm/OpenMMException.h" #include "openmm/OpenMMException.h"
using namespace OpenMM; using namespace OpenMM;
extern "C" void registerPlatforms() { extern "C" OPENMM_EXPORT void registerPlatforms() {
} }
extern "C" void registerKernelFactories() { extern "C" OPENMM_EXPORT void registerKernelFactories() {
try { try {
Platform& platform = Platform::getPlatformByName("OpenCL"); Platform& platform = Platform::getPlatformByName("OpenCL");
OpenCLRpmdKernelFactory* factory = new OpenCLRpmdKernelFactory(); OpenCLRpmdKernelFactory* factory = new OpenCLRpmdKernelFactory();
......
...@@ -312,11 +312,24 @@ void OpenCLIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& p ...@@ -312,11 +312,24 @@ void OpenCLIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& p
throw OpenMMException("RPMDIntegrator: Cannot set positions before the integrator is added to a Context"); throw OpenMMException("RPMDIntegrator: Cannot set positions before the integrator is added to a Context");
if (pos.size() != numParticles) if (pos.size() != numParticles)
throw OpenMMException("RPMDIntegrator: wrong number of values passed to setPositions()"); throw OpenMMException("RPMDIntegrator: wrong number of values passed to setPositions()");
// Adjust the positions based on the current cell offsets.
const vector<int>& order = cl.getAtomIndex();
mm_double4 periodicBoxSize = cl.getPeriodicBoxSizeDouble();
vector<Vec3> offsetPos(numParticles);
for (int i = 0; i < numParticles; ++i) {
mm_int4 offset = cl.getPosCellOffsets()[i];
offsetPos[order[i]] = pos[order[i]] + Vec3(offset.x*periodicBoxSize.x, offset.y*periodicBoxSize.y, offset.z*periodicBoxSize.z);
}
// Record the positions.
if (cl.getUseDoublePrecision()) { if (cl.getUseDoublePrecision()) {
vector<mm_double4> posq(cl.getPaddedNumAtoms()); vector<mm_double4> posq(cl.getPaddedNumAtoms());
cl.getPosq().download(posq); cl.getPosq().download(posq);
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = mm_double4(pos[i][0], pos[i][1], pos[i][2], posq[i].w); posq[i] = mm_double4(offsetPos[i][0], offsetPos[i][1], offsetPos[i][2], posq[i].w);
cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_double4), numParticles*sizeof(mm_double4), &posq[0]); cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_double4), numParticles*sizeof(mm_double4), &posq[0]);
} }
else if (cl.getUseMixedPrecision()) { else if (cl.getUseMixedPrecision()) {
...@@ -324,14 +337,14 @@ void OpenCLIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& p ...@@ -324,14 +337,14 @@ void OpenCLIntegrateRPMDStepKernel::setPositions(int copy, const vector<Vec3>& p
cl.getPosq().download(posqf); cl.getPosq().download(posqf);
vector<mm_double4> posq(cl.getPaddedNumAtoms()); vector<mm_double4> posq(cl.getPaddedNumAtoms());
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = mm_double4(pos[i][0], pos[i][1], pos[i][2], posqf[i].w); posq[i] = mm_double4(offsetPos[i][0], offsetPos[i][1], offsetPos[i][2], posqf[i].w);
cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_double4), numParticles*sizeof(mm_double4), &posq[0]); cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_double4), numParticles*sizeof(mm_double4), &posq[0]);
} }
else { else {
vector<mm_float4> posq(cl.getPaddedNumAtoms()); vector<mm_float4> posq(cl.getPaddedNumAtoms());
cl.getPosq().download(posq); cl.getPosq().download(posq);
for (int i = 0; i < numParticles; i++) for (int i = 0; i < numParticles; i++)
posq[i] = mm_float4((cl_float) pos[i][0], (cl_float) pos[i][1], (cl_float) pos[i][2], posq[i].w); posq[i] = mm_float4((cl_float) offsetPos[i][0], (cl_float) offsetPos[i][1], (cl_float) offsetPos[i][2], posq[i].w);
cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_float4), numParticles*sizeof(mm_float4), &posq[0]); cl.getQueue().enqueueWriteBuffer(positions->getDeviceBuffer(), CL_TRUE, copy*cl.getPaddedNumAtoms()*sizeof(mm_float4), numParticles*sizeof(mm_float4), &posq[0]);
} }
} }
......
...@@ -41,10 +41,25 @@ import simtk.openmm as mm ...@@ -41,10 +41,25 @@ import simtk.openmm as mm
# Enumerated values for implicit solvent model # Enumerated values for implicit solvent model
HCT = object() class HCT(object):
OBC1 = object() def __repr__(self):
OBC2 = object() return 'HCT'
GBn = object() HCT = HCT()
class OBC1(object):
def __repr__(self):
return 'OBC1'
OBC1 = OBC1()
class OBC2(object):
def __repr__(self):
return 'OBC2'
OBC2 = OBC2()
class GBn(object):
def __repr__(self):
return 'GBn'
GBn = GBn()
class AmberPrmtopFile(object): class AmberPrmtopFile(object):
"""AmberPrmtopFile parses an AMBER prmtop file and constructs a Topology and (optionally) an OpenMM System from it.""" """AmberPrmtopFile parses an AMBER prmtop file and constructs a Topology and (optionally) an OpenMM System from it."""
......
...@@ -42,17 +42,47 @@ from simtk.openmm.app import Topology ...@@ -42,17 +42,47 @@ from simtk.openmm.app import Topology
# Enumerated values for nonbonded method # Enumerated values for nonbonded method
NoCutoff = object() class NoCutoff(object):
CutoffNonPeriodic = object() def __repr__(self):
CutoffPeriodic = object() return 'NoCutoff'
Ewald = object() NoCutoff = NoCutoff()
PME = object()
class CutoffNonPeriodic(object):
def __repr__(self):
return 'CutoffNonPeriodic'
CutoffNonPeriodic = CutoffNonPeriodic()
class CutoffPeriodic(object):
def __repr__(self):
return 'CutoffPeriodic'
CutoffPeriodic = CutoffPeriodic()
class Ewald(object):
def __repr__(self):
return 'Ewald'
Ewald = Ewald()
class PME(object):
def __repr__(self):
return 'PME'
PME = PME()
# Enumerated values for constraint type # Enumerated values for constraint type
HBonds = object() class HBonds(object):
AllBonds = object() def __repr__(self):
HAngles = object() return 'HBonds'
HBonds = HBonds()
class AllBonds(object):
def __repr__(self):
return 'AllBonds'
AllBonds = AllBonds()
class HAngles(object):
def __repr__(self):
return 'HAngles'
HAngles = HAngles()
# A map of functions to parse elements of the XML file. # A map of functions to parse elements of the XML file.
......
...@@ -40,6 +40,10 @@ class Vec3(tuple): ...@@ -40,6 +40,10 @@ class Vec3(tuple):
"""Create a new Vec3.""" """Create a new Vec3."""
return tuple.__new__(cls, (x, y, z)) return tuple.__new__(cls, (x, y, z))
def __getnewargs__(self):
"Support for pickle protocol 2: http://docs.python.org/2/library/pickle.html#pickling-and-unpickling-normal-class-instances"
return self[0], self[1], self[2]
def __add__(self, other): def __add__(self, other):
"""Add two Vec3s.""" """Add two Vec3s."""
return Vec3(self[0]+other[0], self[1]+other[1], self[2]+other[2]) return Vec3(self[0]+other[0], self[1]+other[1], self[2]+other[2])
......
...@@ -218,6 +218,10 @@ class SwigInputBuilder: ...@@ -218,6 +218,10 @@ class SwigInputBuilder:
for name in sorted(integratorSubclassList): for name in sorted(integratorSubclassList):
self.fOut.write(",\n OpenMM::%s" % name) self.fOut.write(",\n OpenMM::%s" % name)
self.fOut.write(");\n\n") self.fOut.write(");\n\n")
self.fOut.write("%factory(OpenMM::Integrator& OpenMM::Context::getIntegrator")
for name in sorted(integratorSubclassList):
self.fOut.write(",\n OpenMM::%s" % name)
self.fOut.write(");\n\n")
self.fOut.write("%factory(OpenMM::VirtualSite& OpenMM::System::getVirtualSite, OpenMM::TwoParticleAverageSite, OpenMM::ThreeParticleAverageSite, OpenMM::OutOfPlaneSite);\n\n") self.fOut.write("%factory(OpenMM::VirtualSite& OpenMM::System::getVirtualSite, OpenMM::TwoParticleAverageSite, OpenMM::ThreeParticleAverageSite, OpenMM::OutOfPlaneSite);\n\n")
self.fOut.write("\n") self.fOut.write("\n")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment