Skip to content

Fix mass-weighting of centre-of-mass (COM) force#550

Draft
hjstroud wants to merge 19 commits intomainfrom
fix/mass-weighted-force
Draft

Fix mass-weighting of centre-of-mass (COM) force#550
hjstroud wants to merge 19 commits intomainfrom
fix/mass-weighted-force

Conversation

@hjstroud
Copy link
Copy Markdown
Collaborator

@hjstroud hjstroud commented Mar 16, 2026

This PR aims to address issue #549 by correcting the mass-weighting procedure for the COM-type interaction. In doing so, this PR makes the following changes to the code:

  • Changes the mass weighted forces (and energies) to correctly re-weight the forces by mass in a dimensionally consistent way, according to the equations below:
Screenshot 2026-03-17 at 12 08 43
  • Preserves the non-mass-weighted COM force procedure previously implemented

@hjstroud hjstroud self-assigned this Mar 16, 2026
@hjstroud hjstroud added the bug Something isn't working label Mar 16, 2026
@hjstroud hjstroud linked an issue Mar 16, 2026 that may be closed by this pull request
2 tasks
hjstroud added 11 commits March 17, 2026 12:06
…r of mass-weighted interactions means that single atom interactions are not scaled up by mass, so scaling factor has to compensate)
…pler (new behaviour of mass-weighted interactions means that single atom interactions are not scaled up by mass, so scaling factor has to compensate))
…r (new behaviour of mass-weighted interactions means that single atom interactions are not scaled up by mass, so scaling factor has to compensate))
…x/mass-weighted-force

# Conflicts:
#	python-libraries/nanover-server/src/nanover/imd/imd_force.py
@hjstroud
Copy link
Copy Markdown
Collaborator Author

One test failing: nanover-server/tests/test_core/imd/test_imd_force.py:232 (test_interaction_force_zero_mass_singleatom)

Don't know whether this test makes sense anymore, perhaps we need to check if any of the masses of the atoms to which a force is applied have zero masses? Previously this will only have been caught by the mass-weighted implementation of the force (returning zero energy in this case), so non-mass-weighted forces will have had non-zero energy, results that are clearly inconsistent and should be addressed anyway.

…ion are zero, and explicitly check the total mass of the interaction atoms regardless of weighting scheme
…raction with a set of particles of which a subset have zero mass
@hjstroud
Copy link
Copy Markdown
Collaborator Author

For now, I have altered the function that applies the interactive forces to calculate the total mass of the particle group regardless of the weighting scheme (i.e. mass-weighted or non-mass-weighted), and if the total mass of the group is zero then the forces and energies are also zero. This should cover the following cases:

  • interaction with a single particle with zero mass
  • interaction with a group of particles all with zero mass

If only a subset of the particle group have zero mass, this is automatically covered for the mass-weighted case. However in the non-mass-weighted case, if a subset of atoms have zero mass it is necessary to define which atoms have zero mass and only distribute the applied force over the atoms with non-zero mass. I have adjusted the implementation of the non-mass-weighted force to cover this scenario.

If we keep this it will be important to put a note in the documentation to let users know that the interaction forces are only distributed over particles in the selection with non-zero masses.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect mass-weighting for centre-of-mass (COM) force

1 participant