Skip to content

Getting a CustomCentroidBondForce error when attempting to add RadiusOfGyrationSq to system. #105

@dsclassen

Description

@dsclassen

I'm seeing an error when I attempt to implement RadiusOfGyrationSq

# Add custom CV for radius of gyration
num_atoms = system.getNumParticles()
print(f"Number of atoms in system: {num_atoms}")
rgsq = cvpack.RadiusOfGyrationSq(list(range(num_atoms)),pbc=False ,weighByMass=False, name="RadiusOfGyrationSq")
rgsq.addToSystem(system)

# Create integrator
timestep = 0.001 * picoseconds
print(f"Using timestep: {timestep}")
integrator = VerletIntegrator(timestep)

# Load previous state (restart)
with open(os.path.join( heat_dir, heated_restart_file_name), encoding="utf-8") as f:
    state = XmlSerializer.deserialize(f.read())

# Create simulation
simulation = Simulation(modeller.topology, system, integrator)
simulation.context.setState(state)

and this is the error:

Number of atoms in system: 8234
Using timestep: 0.001 ps
Traceback (most recent call last):
  File "/Users/classen/projects/openmm-test/scripts/md.py", line 81, in <module>
    simulation = Simulation(modeller.topology, system, integrator)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/classen/miniconda3/envs/openmm/lib/python3.12/site-packages/openmm/app/simulation.py", line 102, in __init__
    self.context = mm.Context(self.system, self.integrator)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/classen/miniconda3/envs/openmm/lib/python3.12/site-packages/openmm/openmm.py", line 2488, in __init__
    _openmm.Context_swiginit(self, _openmm.new_Context(*args))
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^
openmm.OpenMMException: CustomCentroidBondForce: Weights for group 3132 add to 0

I am defining other restraints earlier in the md.py file, but if I comment out rgsq.addToSystem(system) then the simulation runs without error.

p.s. I am using a version of this Rigid Body code which may be interfering with cvpack?

https://github.com/openmm/openmm/blob/master/examples/extras/rigid.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions