1 #ifndef REFERENCE_DENSITY_KERNELS_H_
2 #define REFERENCE_DENSITY_KERNELS_H_
36 #include <openmm/Platform.h>
41 namespace ost{
namespace mol{
namespace mm{
68 double execute(OpenMM::ContextImpl& context,
bool includeForces,
bool includeEnergy);
78 inline Real GetValue(
int a,
int b,
int c){
79 return data_[a * idx_helper_one_ + b * idx_helper_two_ + c];
85 Real dx = x - x_origin_;
86 Real dy = y - y_origin_;
87 Real dz = z - z_origin_;
89 int x_bin = std::floor(dx * one_over_x_sampling_);
90 int y_bin = std::floor(dy * one_over_y_sampling_);
91 int z_bin = std::floor(dz * one_over_z_sampling_);
93 if(x_bin < 0 || x_bin >= (x_extent_-1) ||
94 y_bin < 0 || y_bin >= (y_extent_-1) ||
95 z_bin < 0 || z_bin >= (z_extent_-1))
return 0.0;
98 dx = (dx - x_bin * x_sampling_) * one_over_x_sampling_;
99 dy = (dy - y_bin * y_sampling_) * one_over_y_sampling_;
100 dz = (dz - z_bin * z_sampling_) * one_over_z_sampling_;
102 intpol_values_[0] = this->GetValue(x_bin,y_bin,z_bin);
103 intpol_values_[1] = this->GetValue(x_bin+1,y_bin,z_bin);
104 intpol_values_[2] = this->GetValue(x_bin,y_bin+1,z_bin);
105 intpol_values_[3] = this->GetValue(x_bin+1,y_bin+1,z_bin);
106 intpol_values_[4] = this->GetValue(x_bin,y_bin,z_bin+1);
107 intpol_values_[5] = this->GetValue(x_bin+1,y_bin,z_bin+1);
108 intpol_values_[6] = this->GetValue(x_bin,y_bin+1,z_bin+1);
109 intpol_values_[7] = this->GetValue(x_bin+1,y_bin+1,z_bin+1);
112 Real f11 = (1.0 - dx) * intpol_values_[0] + dx * intpol_values_[1];
113 Real f12 = (1.0 - dx) * intpol_values_[2] + dx * intpol_values_[3];
114 Real f21 = (1.0 - dx) * intpol_values_[4] + dx * intpol_values_[5];
115 Real f22 = (1.0 - dx) * intpol_values_[6] + dx * intpol_values_[7];
117 Real f1 = (1.0 - dy) * f11 + dy * f12;
118 Real f2 = (1.0 - dy) * f21 + dy * f22;
120 return (1.0 - dz) * f1 + dz * f2;
125 Real intpol_values_[8];
131 Real one_over_x_sampling_;
132 Real one_over_y_sampling_;
133 Real one_over_z_sampling_;
134 Real half_x_sampling_;
135 Real half_y_sampling_;
136 Real half_z_sampling_;
149 Real one_sqrt_2_pi_s_;
152 std::vector<Real> density_values_;
153 std::vector<Real> body_values_;
158 std::vector<float> particle_masses_;
159 std::vector<std::vector<int> > bodies_;
~ReferenceCalcDensityForceKernel()
ReferenceCalcDensityForceKernel(std::string name, const OpenMM::Platform &platform)
void copyParametersToContext(OpenMM::ContextImpl &context, const DensityForce &force)
double execute(OpenMM::ContextImpl &context, bool includeForces, bool includeEnergy)
void initialize(const OpenMM::System &system, const DensityForce &force)