Skip to content

Unexpected behavior with create_rigid_bodies() #2214

@josephburkhart

Description

@josephburkhart

Description

When I run Rigid.create_bodies() a second time on the same simulation state with different and nested body definitions (A has B constintuents, B has C constituents), I get unexpected results. Specifically, all particles except for the top-level type (A in the example code) are removed, and all A particles are set to free (their body values are -1). I was surprised, because I expected that I would merely have doubled the number of B particles. The problem seems to be somewhere in hoomd/md/ForceComposite.cc.

Script

import hoomd
sim = hoomd.util.make_example_simulation(particle_types=["A", "B", "C"])

rigid = hoomd.md.constrain.Rigid()
rigid.body["A"] = {
    "constituent_types": ["B", "B"],
    "positions": [[0,-1,0], [0,1,0]],
    "orientations": [(1,0,0,0), (1,0,0,0)]
}

rigid.create_bodies(sim.state)

rigid.body["B"] = {
    "constituent_types": ["C", "C"],
    "positions": [[0,0,-1], [0,0,1]],
    "orientations": [(1,0,0,0), (1,0,0,0)]
}

rigid.create_bodies(sim.state)

print("Types:")
print([sim.state.get_snapshot().particles.types[i] for i in sim.state.get_snapshot().particles.typeid])

print("\nPositions:")
print(sim.state.get_snapshot().particles.position)

print("\nBodies:")
print(sim.state.get_snapshot().particles.body)

Input files

No response

Output

Types:
['A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A']

Positions:
[[0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]
 [0. 0. 0.]]

Bodies:
[-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1]

Expected output

No response

Platform

Linux

Installation method

Conda-forge package

HOOMD-blue version

5.4.0

Python version

3.14.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions