-
Notifications
You must be signed in to change notification settings - Fork 132
/
PairPotentialExpandedGaussian.cc
98 lines (85 loc) · 3.94 KB
/
PairPotentialExpandedGaussian.cc
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2009-2024 The Regents of the University of Michigan.
// Part of HOOMD-blue, released under the BSD 3-Clause License.
#include "PairPotentialExpandedGaussian.h"
namespace hoomd
{
namespace hpmc
{
PairPotentialExpandedGaussian::PairPotentialExpandedGaussian(
std::shared_ptr<SystemDefinition> sysdef)
: PairPotential(sysdef), m_params(m_type_param_index.getNumElements())
{
}
LongReal PairPotentialExpandedGaussian::energy(const LongReal r_squared,
const vec3<LongReal>& r_ij,
const unsigned int type_i,
const quat<LongReal>& q_i,
const LongReal charge_i,
const unsigned int type_j,
const quat<LongReal>& q_j,
const LongReal charge_j) const
{
unsigned int param_index = m_type_param_index(type_i, type_j);
const auto& param = m_params[param_index];
LongReal r = fast::sqrt(r_squared);
LongReal rmd_2 = (r - param.delta) * (r - param.delta);
LongReal rmd_over_sigma_2 = rmd_2 / param.sigma_2;
LongReal exp_val = fast::exp(-LongReal(1.0) / LongReal(2.0) * rmd_over_sigma_2);
LongReal energy = param.epsilon * exp_val;
if (m_mode == shift || (m_mode == xplor && param.r_on_squared >= param.r_cut_squared))
{
LongReal r_cut = fast::sqrt(param.r_cut_squared);
LongReal rcutmd_2 = (r_cut - param.delta) * (r_cut - param.delta);
LongReal rcutmd_over_sigma_2 = rcutmd_2 / param.sigma_2;
energy -= param.epsilon * fast::exp(-LongReal(1.0) / LongReal(2.0) * rcutmd_over_sigma_2);
}
if (m_mode == xplor && r_squared > param.r_on_squared)
{
LongReal a = param.r_cut_squared - param.r_on_squared;
LongReal denominator = a * a * a;
LongReal b = param.r_cut_squared - r_squared;
LongReal numerator = b * b
* (param.r_cut_squared + LongReal(2.0) * r_squared
- LongReal(3.0) * param.r_on_squared);
energy *= numerator / denominator;
}
return energy;
}
void PairPotentialExpandedGaussian::setParamsPython(pybind11::tuple typ, pybind11::dict params)
{
auto pdata = m_sysdef->getParticleData();
auto type_i = pdata->getTypeByName(typ[0].cast<std::string>());
auto type_j = pdata->getTypeByName(typ[1].cast<std::string>());
unsigned int param_index_1 = m_type_param_index(type_i, type_j);
m_params[param_index_1] = ParamType(params);
unsigned int param_index_2 = m_type_param_index(type_j, type_i);
m_params[param_index_2] = ParamType(params);
notifyRCutChanged();
}
pybind11::dict PairPotentialExpandedGaussian::getParamsPython(pybind11::tuple typ)
{
auto pdata = m_sysdef->getParticleData();
auto type_i = pdata->getTypeByName(typ[0].cast<std::string>());
auto type_j = pdata->getTypeByName(typ[1].cast<std::string>());
unsigned int param_index = m_type_param_index(type_i, type_j);
return m_params[param_index].asDict();
}
namespace detail
{
void exportPairPotentialExpandedGaussian(pybind11::module& m)
{
pybind11::class_<PairPotentialExpandedGaussian,
PairPotential,
std::shared_ptr<PairPotentialExpandedGaussian>>(
m,
"PairPotentialExpandedGaussian")
.def(pybind11::init<std::shared_ptr<SystemDefinition>>())
.def("setParams", &PairPotentialExpandedGaussian::setParamsPython)
.def("getParams", &PairPotentialExpandedGaussian::getParamsPython)
.def_property("mode",
&PairPotentialExpandedGaussian::getMode,
&PairPotentialExpandedGaussian::setMode);
}
} // end namespace detail
} // end namespace hpmc
} // end namespace hoomd