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

thermalize_particle_momenta assigns velocities and angular momentum to constituent particles. #1472

Closed
joaander opened this issue Jan 27, 2023 · 0 comments · Fixed by #1527
Closed
Assignees
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@joaander
Copy link
Member

Description

thermalize_particle_momenta, when given the All filter, will assign non-zero values to the velocities and angular momenta of rigid body constituent particles. hoomd.md.constrain.Rigid does not overwrite these values, though perhaps it should (see #278). Regardless, to behave consistently with ThermodynamicQuantities, thermalize_particle_momenta should assign 0's to constituent particle velocities and angular momenta:

for (unsigned int group_idx = 0; group_idx < group_size; group_idx++)
{
unsigned int j = this->getMemberIndex(group_idx);
unsigned int ptag = h_tag.data[j];
// Seed the RNG
hoomd::RandomGenerator rng(hoomd::Seed(hoomd::RNGIdentifier::ParticleGroupThermalize,
timestep,
m_sysdef->getSeed()),
hoomd::Counter(ptag));
// Generate a random velocity
Scalar mass = h_vel.data[j].w;
Scalar sigma = slow::sqrt(kT / mass);
hoomd::NormalDistribution<Scalar> normal(sigma);
h_vel.data[j].x = normal(rng);
h_vel.data[j].y = normal(rng);
if (n_dimensions > 2)
h_vel.data[j].z = normal(rng);
else
h_vel.data[j].z = 0; // For 2D systems
tot_momentum += mass * vec3<Scalar>(h_vel.data[j]);
// Generate random angular momentum if the particle has rotational degrees of freedom.
vec3<Scalar> p_vec(0, 0, 0);
quat<Scalar> q(h_orientation.data[j]);
vec3<Scalar> I(h_inertia.data[j]);
if (I.x > 0)
p_vec.x = hoomd::NormalDistribution<Scalar>(slow::sqrt(kT * I.x))(rng);
if (I.y > 0)
p_vec.y = hoomd::NormalDistribution<Scalar>(slow::sqrt(kT * I.y))(rng);
if (I.z > 0)
p_vec.z = hoomd::NormalDistribution<Scalar>(slow::sqrt(kT * I.z))(rng);
// Store the angular momentum quaternion
quat<Scalar> p = Scalar(2.0) * q * p_vec;
h_angmom.data[j] = quat_to_scalar4(p);
}

Script

import hoomd

snapshot = hoomd.Snapshot()
snapshot.configuration.box = (10, 10, 10, 0, 0, 0)
snapshot.particles.N = 4
snapshot.particles.types = ['A']
snapshot.particles.body[:] = [0, 0, 2, 2]
snapshot.particles.moment_inertia[:] = [[1,1,1]] * 4

sim = hoomd.Simulation(device=hoomd.device.CPU())
sim.create_state_from_snapshot(snapshot)

sim.state.thermalize_particle_momenta(filter=hoomd.filter.All(), kT=1.0)
thermalized_snapshot = sim.state.get_snapshot()
print(thermalized_snapshot.particles.velocity)
print(thermalized_snapshot.particles.angmom)

Input files

No response

Output

[[-0.66990062  0.13619617  0.63650922]
 [-1.00984745 -0.81729512  1.43739685]
 [ 0.77239644  0.5919247  -0.56883137]
 [ 0.90735163  0.08917425 -1.5050747 ]]
[[ 0.         -0.80604741  0.73100313  1.6675459 ]
 [ 0.         -1.39461841 -3.73358298 -1.2261137 ]
 [ 0.          2.98269913 -0.46326691  1.24673851]
 [ 0.          2.23798918  0.51482892  2.8423569 ]]

Expected output

I expected 0 velocity and angular momentum for particles 1 and 3.

Platform

CPU, GPU, Linux, macOS

Installation method

Compiled from source

HOOMD-blue version

3.8.1

Python version

3.10.6

@joaander joaander added bug Something isn't working good first issue Good for newcomers labels Jan 27, 2023
@melodyyzh melodyyzh self-assigned this Feb 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants