Skip to content

Commit defdd03

Browse files
dpradaclaude
andcommitted
Fix: Narrow MolSysSuite Mass Policy guard to pure molar-mass quantities only.
The condition translating OpenMM molar-mass units (dalton, [M][mol]^-1) to pint pure-mass dalton ([M]) was too broad: it matched any quantity with [M]=1 and [mol]=-1, including kilojoule_per_mole ([L]=2, [T]=-2). This caused puw.convert(openmm_kJ/mol, to_form='pint') to return dalton instead of kilojoule/mole, breaking puw.standardize calls downstream. The guard now also verifies that all other dimensions ([L], [T], [K], [A], [Cd]) are zero, so only true molar-mass scalars (dalton, g/mol…) are remapped. Energy-per-mole quantities pass through the normal str(unit) path unaffected. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent eed5223 commit defdd03

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

pyunitwizard/forms/api_openmm_unit.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,17 @@ def quantity_to_pint(quantity: openmm_unit.Quantity):
333333
unit = get_unit(quantity)
334334

335335
# MolSysSuite Mass Policy: Translate OpenMM Molar Mass to Pure Mass
336+
# OpenMM expresses atomic/molar mass as dalton = [M][mol]^-1.
337+
# Pint dalton is a pure mass [M]. We translate here explicitly so that
338+
# molar-mass quantities arrive in molsysmt as pure-mass dalton, not as
339+
# a per-mole quantity. The guard on all other dimensions being zero
340+
# ensures we only match true molar-mass scalars (dalton, amu, g/mol…)
341+
# and not energy-per-mole quantities like kilojoule_per_mole which share
342+
# [M]=1 and [mol]=-1 but also carry [L]=2 and [T]=-2.
336343
dim = dimensionality(quantity)
337-
if dim.get("[M]") == 1 and dim.get("[mol]") == -1:
344+
_other_dims = ("[L]", "[T]", "[K]", "[A]", "[Cd]")
345+
if (dim.get("[M]") == 1 and dim.get("[mol]") == -1
346+
and all(dim.get(d, 0) == 0 for d in _other_dims)):
338347
# OpenMM "dalton" ([M]/[mol]) -> Pint "dalton" ([M])
339348
return make_pint_quantity(value, "dalton")
340349

0 commit comments

Comments
 (0)