Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Brownian dynamics: propagate spatially fixed yet freely rotatable particles #4548

Merged
merged 1 commit into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/core/thermostats/brownian_inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ bd_drag_rot(Thermostat::GammaType const &brownian_gamma_rotation, Particle &p,

Utils::Vector3d dphi = {};
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
// only a conservative part of the torque is used here
#ifndef PARTICLE_ANISOTROPY
dphi[j] = p.torque()[j] * dt / gamma;
Expand Down Expand Up @@ -304,12 +304,11 @@ bd_drag_vel_rot(Thermostat::GammaType const &brownian_gamma_rotation,

Utils::Vector3d omega = {};
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
// only conservative part of the force is used here
#ifndef PARTICLE_ANISOTROPY
omega[j] = p.torque()[j] / gamma;
#else
if (p.can_rotate_around(j)) {
#ifdef PARTICLE_ANISOTROPY
omega[j] = p.torque()[j] / gamma[j];
#else
omega[j] = p.torque()[j] / gamma;
#endif // PARTICLE_ANISOTROPY
}
}
Expand Down Expand Up @@ -343,7 +342,7 @@ bd_random_walk_rot(BrownianThermostat const &brownian, Particle const &p,
auto const noise = Random::noise_gaussian<RNGSalt::BROWNIAN_ROT_INC>(
brownian.rng_counter(), brownian.rng_seed(), p.id());
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
#ifndef PARTICLE_ANISOTROPY
if (sigma_pos > 0.0) {
dphi[j] = noise[j] * sigma_pos * sqrt(dt);
Expand Down Expand Up @@ -378,7 +377,7 @@ bd_random_walk_vel_rot(BrownianThermostat const &brownian, Particle const &p) {
auto const noise = Random::noise_gaussian<RNGSalt::BROWNIAN_ROT_WALK>(
brownian.rng_counter(), brownian.rng_seed(), p.id());
for (int j = 0; j < 3; j++) {
if (!p.is_fixed_along(j)) {
if (p.can_rotate_around(j)) {
domega[j] = sigma_vel * noise[j] / sqrt(p.rinertia()[j]);
}
}
Expand Down
26 changes: 26 additions & 0 deletions testsuite/python/brownian_dynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,32 @@ def test_07__virtual(self):
np.testing.assert_almost_equal(np.copy(virtual.v), [0, 0, 0])
np.testing.assert_almost_equal(np.copy(physical.v), [0, 0, 0])

@utx.skipIfMissingFeatures(["ROTATION", "EXTERNAL_FORCES"])
def test_fix_rotation(self):
system = self.system
system.time_step = 0.01
part = system.part.add(
pos=3 * [0.],
fix=3 * [True],
rotation=3 * [True])

# torque only
part.ext_torque = [0, 0, 1.3]
system.thermostat.set_brownian(
kT=0, gamma=1, gamma_rotation=1.5, act_on_virtual=False, seed=41)
system.integrator.set_brownian_dynamics()
system.integrator.run(3)
np.testing.assert_allclose(
part.omega_lab, [
0, 0, 1.3 / 1.5], atol=1e-14)

# noise only
part.ext_torque = 3 * [0.]
system.thermostat.set_brownian(
kT=1, gamma=1, gamma_rotation=1.5, act_on_virtual=False, seed=41)
system.integrator.run(3)
self.assertGreater(np.linalg.norm(part.omega_lab), 0.)


if __name__ == "__main__":
ut.main()