Skip to content

Commit

Permalink
Fix system.part choice for Gibbs sample (espressomd#4283)
Browse files Browse the repository at this point in the history
Fixes / Avoids espressomd#4278 causing a RuntimeError if a box runs empty
  • Loading branch information
kodiakhq[bot] authored Jun 23, 2021
2 parents 96f2718 + ed9d67a commit 885081c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions samples/gibbs_ensemble/gibbs_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ def send_info(self):

def move_particle(self, DX_MAX):
""" Move random particle inside the box """
self.old_particle = np.random.choice(self.system.part)
random_particle_id = np.random.choice(self.system.part[:].id)
self.old_particle = self.system.part[random_particle_id]
self.old_pos = self.old_particle.pos
self.old_particle.pos = self.old_pos + \
(0.5 - np.random.random(size=3)) * DX_MAX
Expand All @@ -104,7 +105,8 @@ def revert_add_particle(self):

def remove_particle(self):
""" Remove a random particle """
self.old_particle = np.random.choice(self.system.part).to_dict()
random_particle_id = np.random.choice(self.system.part[:].id)
self.old_particle = self.system.part[random_particle_id].to_dict()
self.system.part[self.old_particle["id"]].remove()
self.send_energy()

Expand Down
2 changes: 1 addition & 1 deletion samples/gibbs_ensemble/run_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def validate_info(boxes):
np.testing.assert_equal(
box.num_part,
msg[2],
err_msg="Server side box length (actual) differs from client side (desired)")
err_msg="Server side num part (actual) differs from client side (desired)")
logging.debug(
"Validation correct. Values of {}:\nBox length:\t{}\nNum Part:\t{}.".format(
box.box_name, box.box_length, box.num_part))
Expand Down

0 comments on commit 885081c

Please sign in to comment.