Skip to content

Fix rescaling of non-cubic boxes - #5337

Merged
jngrad merged 3 commits into
espressomd:pythonfrom
RudolfWeeber:fix/bug-16-box-rescale-noncubic
Aug 27, 2026
Merged

Fix rescaling of non-cubic boxes#5337
jngrad merged 3 commits into
espressomd:pythonfrom
RudolfWeeber:fix/bug-16-box-rescale-noncubic

Conversation

@RudolfWeeber

Copy link
Copy Markdown
Contributor

change_volume_and_rescale_particles("xyz") computed a single scalar scale
from the x-axis (length * length_inv()[0]) and applied it to all three
particle coordinates, silently corrupting y/z positions on any non-cubic
box. The cubic-box assert was compiled out under NDEBUG.

Fix: for coord==3, capture old per-axis lengths, apply shrinking axes
before the box resize and growing axes after, each with its own
length/old_lengths[axis] scale factor
(src/script_interface/system/System.cpp). Also removes the now-vacuous
cubic-box assert.

Regression test: test_isotropic_rescale_noncubic_box added to Test
in testsuite/python/system.py.

Fixes bug #16 of the adversarial bug sweep.

…tors

change_volume_and_rescale_particles("xyz") computed a single scalar scale
from the x-axis (length * length_inv()[0]) and applied it to all three
particle coordinates, silently corrupting y/z positions on any non-cubic
box.  The cubic-box assert was compiled out under NDEBUG.

Fix: for coord==3, store the old per-axis lengths, apply shrinking axes
before the box resize and growing axes after, each with its own
length/old_lengths[axis] scale factor.

Also remove the now-unnecessary cubic-box assert for coord==3.

Regression test added to testsuite/python/system.py: non-cubic
[10,20,30] → [5,5,5] rescale verifies each coordinate scales by its
own new/old ratio.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@RudolfWeeber

Copy link
Copy Markdown
Contributor Author

Bug is genuine IMO. Test case needs fixing.

@RudolfWeeber RudolfWeeber added this to the ESPResSo 5.0.2 milestone Jul 23, 2026
@jngrad
jngrad marked this pull request as ready for review August 27, 2026 19:24
@jngrad jngrad changed the title script_interface/system: fix xyz rescale using per-axis scale factors Fix rescaling of non-cubic boxes Aug 27, 2026
@jngrad
jngrad merged commit 79f7ae1 into espressomd:python Aug 27, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants