Skip to content

Conversation

@jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Jan 9, 2026

Summary by CodeRabbit

  • New Features
    • Added configurable velocity rescaling for molecular dynamics simulations. Users can now customize the velocity rescaling factor in thermal expansion calculations and ensemble simulations (NVT, NPT, NPH, Langevin), providing greater control over initial velocity initialization while maintaining backward compatibility (default: 2.0).

✏️ Tip: You can customize this high-level summary in your review settings.

@jan-janssen jan-janssen requested a review from prabhath-c January 9, 2026 11:21
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 9, 2026

📝 Walkthrough

Walkthrough

The pull request replaces a hardcoded velocity scaling factor (2) with a configurable velocity_rescale_factor parameter across LAMMPS molecular dynamics calculations. A boolean disable_initial_velocity flag is replaced with an optional numeric velocity_rescale_factor parameter throughout the codebase, enabling fine-grained control over velocity initialization in thermal simulations.

Changes

Cohort / File(s) Summary
LAMMPS Template Configuration
src/atomistics/calculators/lammps/commands.py
Updated LAMMPS_VELOCITY template string to replace hardcoded 2 * {{ temp }} with {{velocity_rescale_factor}} * {{ temp }}, enabling configurable velocity scaling in velocity creation command.
Parameter Propagation
src/atomistics/calculators/lammps/helpers.py
Added velocity_rescale_factor: float = 2.0 parameter to lammps_thermal_expansion_loop() signature and threaded it through to template rendering context for initial and run configurations.
MD Calculator Interface
src/atomistics/calculators/lammps/libcalculator.py
Replaced disable_initial_velocity: bool = False parameter with velocity_rescale_factor: Optional[float] = 2.0 across four MD functions (calc_molecular_dynamics_nvt_with_lammpslib, calc_molecular_dynamics_npt_with_lammpslib, calc_molecular_dynamics_nph_with_lammpslib, calc_molecular_dynamics_langevin_with_lammpslib). Conditional logic changed from checking boolean flag to checking is not None. Added Optional import from typing.
Test Updates
tests/test_lammpslib_md.py
Updated two test invocations to use velocity_rescale_factor=None instead of disable_initial_velocity argument.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • LAMMPS: Maintain velocity #517: Modifies velocity initialization handling in LAMMPS MD calculations; both PRs target the same MD functions to control velocity creation parameters.

Poem

🐰 A factor now floats where two once was fixed,
Velocity scaling, no longer mixed!
From booleans to numbers, flexibility blooms,
Rescale as you wish in thermal rooms! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and accurately summarizes the main change: replacing a hardcoded velocity rescaling factor with a configurable parameter while maintaining backward compatibility through the default value of 2.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @src/atomistics/calculators/lammps/helpers.py:
- Line 105: The parameter velocity_rescale_factor in
lammps_thermal_expansion_loop is typed as float and will produce an invalid
LAMMPS command if None is passed; change its type to Optional[float] and add the
same conditional guard used in libcalculator.py: only emit/compose the LAMMPS
velocity initialization/rescale command when velocity_rescale_factor is not
None, otherwise skip velocity initialization entirely to avoid generating "None
* temp" in the command.
🧹 Nitpick comments (2)
tests/test_lammpslib_md.py (1)

166-167: Consider adding tests for custom velocity rescale factors.

Both "no velocity" tests use velocity_rescale_factor=None, but there are no tests validating custom non-default values (e.g., velocity_rescale_factor=1.0 or velocity_rescale_factor=3.0). Adding such a test would help ensure the configurable factor works as expected.

src/atomistics/calculators/lammps/libcalculator.py (1)

465-514: Consider exposing velocity_rescale_factor in the thermal expansion function.

The calc_molecular_dynamics_thermal_expansion_with_lammpslib function always uses LAMMPS_VELOCITY (line 491) but doesn't expose the velocity_rescale_factor parameter to callers. It relies on the default value (2.0) in lammps_thermal_expansion_loop.

For API consistency with other MD functions, consider adding the parameter here and passing it through to lammps_thermal_expansion_loop.

♻️ Suggested change
 def calc_molecular_dynamics_thermal_expansion_with_lammpslib(
     structure: Atoms,
     potential_dataframe: pandas.DataFrame,
     Tstart: float = 15.0,
     Tstop: float = 1500.0,
     Tstep: int = 5,
     Tdamp: float = 0.1,
     run: int = 100,
     thermo: int = 100,
     timestep: float = 0.001,
     Pstart: float = 0.0,
     Pstop: float = 0.0,
     Pdamp: float = 1.0,
     seed: int = 4928459,
     dist: str = "gaussian",
+    velocity_rescale_factor: float = 2.0,
     lmp=None,
     output_keys=OutputThermalExpansion.keys(),
     **kwargs,
 ) -> dict:
     ...
     return lammps_thermal_expansion_loop(
         ...
         dist=dist,
+        velocity_rescale_factor=velocity_rescale_factor,
         lmp=lmp,
         ...
     )
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aee9634 and 7c4d470.

📒 Files selected for processing (4)
  • src/atomistics/calculators/lammps/commands.py
  • src/atomistics/calculators/lammps/helpers.py
  • src/atomistics/calculators/lammps/libcalculator.py
  • tests/test_lammpslib_md.py
🧰 Additional context used
🧬 Code graph analysis (1)
src/atomistics/calculators/lammps/libcalculator.py (1)
src/atomistics/shared/output.py (2)
  • OutputMolecularDynamics (42-51)
  • keys (11-18)
🪛 Ruff (0.14.10)
src/atomistics/calculators/lammps/libcalculator.py

159-159: Do not perform function call OutputMolecularDynamics.keys in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


238-238: Do not perform function call OutputMolecularDynamics.keys in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


321-321: Do not perform function call OutputMolecularDynamics.keys in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)


397-397: Do not perform function call OutputMolecularDynamics.keys in argument defaults; instead, perform the call within the function, or read the default from a module-level singleton variable

(B008)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (15)
  • GitHub Check: unittest_gpaw
  • GitHub Check: unittest_grace
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.11)
  • GitHub Check: unittest_matrix (macos-latest, 3.14)
  • GitHub Check: unittest_mace
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.12)
  • GitHub Check: unittest_matrix (windows-latest, 3.14)
  • GitHub Check: unittest_siesta
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.13)
  • GitHub Check: unittest_qe
  • GitHub Check: unittest_matrix (ubuntu-latest, 3.14)
  • GitHub Check: unittest_old
  • GitHub Check: notebooks
  • GitHub Check: unittest_sphinxdft
  • GitHub Check: coverage
🔇 Additional comments (8)
tests/test_lammpslib_md.py (1)

74-75: Test correctly validates the new velocity_rescale_factor=None behavior.

The test verifies that when velocity_rescale_factor=None, the simulation starts without initial velocities, resulting in near-zero temperature (lines 84-85). This correctly validates the replacement of the old disable_initial_velocity=True behavior.

src/atomistics/calculators/lammps/commands.py (1)

23-23: Clean parameterization of the velocity rescale factor.

The template correctly replaces the hardcoded 2 with the configurable {{velocity_rescale_factor}} placeholder, maintaining the same LAMMPS command structure.

src/atomistics/calculators/lammps/helpers.py (1)

119-119: Propagation looks correct for the thermal expansion use case.

The velocity_rescale_factor is correctly passed to the template render context, which will substitute into LAMMPS_VELOCITY command.

src/atomistics/calculators/lammps/libcalculator.py (5)

157-184: NVT implementation correctly handles the new velocity_rescale_factor parameter.

The conditional logic properly branches between including LAMMPS_VELOCITY (when factor is not None) and excluding it (when None). The parameter is correctly passed to the template render.


236-266: NPT implementation consistent with NVT.

The pattern follows the same correct structure as the NVT function.


319-346: NPH implementation consistent with other MD functions.


395-424: Langevin implementation consistent with other MD functions.


159-159: Pre-existing static analysis warning (B008).

The Ruff B008 warning about function calls in default arguments (OutputMolecularDynamics.keys()) is a pre-existing pattern throughout this file and not introduced by this PR. This is a known trade-off for API discoverability.

Pdamp: float = 1.0,
seed: int = 4928459,
dist: str = "gaussian",
velocity_rescale_factor: float = 2.0,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, find the function at line 105 and surrounding context
sed -n '90,120p' src/atomistics/calculators/lammps/helpers.py

Repository: pyiron/atomistics

Length of output: 945


🏁 Script executed:

# Find the corresponding function in libcalculator.py
rg -n "velocity_rescale_factor" src/ --type py -B 2 -A 2

Repository: pyiron/atomistics

Length of output: 6183


🏁 Script executed:

# Search for how velocity_rescale_factor is used in the template rendering
rg -n "velocity_rescale_factor" src/atomistics/calculators/lammps/ --type py

Repository: pyiron/atomistics

Length of output: 1705


Type inconsistency with libcalculator.py functions.

lammps_thermal_expansion_loop uses velocity_rescale_factor: float = 2.0, while all MD functions in libcalculator.py use Optional[float] = 2.0 with conditional logic to handle None values. The helpers.py function lacks this guard, so passing None would render "None * temp" in the LAMMPS velocity command, causing an error.

Align the type to Optional[float] and add the same conditional logic used in libcalculator.py (skip velocity initialization when None), or document that this function always requires a numeric value.

🤖 Prompt for AI Agents
In @src/atomistics/calculators/lammps/helpers.py at line 105, The parameter
velocity_rescale_factor in lammps_thermal_expansion_loop is typed as float and
will produce an invalid LAMMPS command if None is passed; change its type to
Optional[float] and add the same conditional guard used in libcalculator.py:
only emit/compose the LAMMPS velocity initialization/rescale command when
velocity_rescale_factor is not None, otherwise skip velocity initialization
entirely to avoid generating "None * temp" in the command.

@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.81%. Comparing base (aee9634) to head (7c4d470).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #608   +/-   ##
=======================================
  Coverage   86.81%   86.81%           
=======================================
  Files          43       43           
  Lines        2419     2419           
=======================================
  Hits         2100     2100           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants