glotzerlab / hoomd-blue

Molecular dynamics and Monte Carlo soft matter simulation on GPUs.

Home Page:http://glotzerlab.engin.umich.edu/hoomd-blue

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Negative tilt factors yield incorrect QuickCompress results

janbridley opened this issue · comments

Description

Running QuickCompress on a simulation state where any one (or multiple) tilt factors xy, yz, xz are less than 0 causes the tilt factors to change incorrectly.

  • Specifying a target box with the same (negative) tilt factor changes the current tilt factor by some amount dx
  • Specifying a target box with any other (negative, positive, or zero) tilt factor changes the tilt factor by the same about dx (all else being constant)

Compression should work regardless of the sign of the tilt factors, but it seems like the negative sign causes an error: UpdaterQuickCompress.cc::scaleValue() calls std::min(target, current/proposed_move_size). If current is less than 1, the scaled value will be the minimum and the incorrect box move will be accepted.

I will implement a fix for this!

Script

import hoomd
import gsd.hoomd

sim = hoomd.Simulation(device=hoomd.device.CPU(), seed=1234)
sim.operations.integrator = hoomd.hpmc.integrate.Sphere()
sim.operations.integrator.shape["A"] = dict(diameter=1.0)

# Set up a simulation with a noncubic box and a negative tilt factor
frame = gsd.hoomd.Frame()
frame.particles.N = 1
frame.particles.position = [[0,0,0]]
frame.particles.types = ["A"]
frame.configuration.box = [3, 3, 3, -0.5, 0, 0]

sim.create_state_from_snapshot(frame)

final_box = hoomd.Box.from_box(sim.state.box)
final_box.volume = 0.5
assert(sim.state.box.xy==final_box.xy) # Shape should not change

qc = hoomd.hpmc.update.QuickCompress(trigger=1,target_box=final_box)
sim.operations.updaters.append(qc)

sim.run(1)
print(sim.state.box.xy,final_box.xy)


# Alternatively, trying to compress the box to its positive variant also fails
## final_box = hoomd.Box.from_matrix([[3,1.5,0],[0,3,0],[0,0,3]])
## final_box.volume = 0.5
## print(sim.state.box.xy, final_box.xy) # Shape should change in this example

## qc = hoomd.hpmc.update.QuickCompress(trigger=1,target_box=final_box)
## sim.operations.updaters.append(qc)

## sim.run(1)
## print(sim.state.box.xy,final_box.xy)

Output

`>> -0.5010258004792931 -0.5`

Expected output

>> -0.5 -0.5 # The tilt factors should match

Platform

CPU, macOS

Installation method

Compiled from source

HOOMD-blue version

4.4.1

Python version

3.11.5