Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/atomistics/calculators/lammps/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
LAMMPS_TIMESTEP = "timestep {{timestep}}"


LAMMPS_VELOCITY = "velocity all create $(2 * {{ temp }}) {{seed}} dist {{dist}}"
LAMMPS_VELOCITY = "velocity all create $({{velocity_rescale_factor}} * {{ temp }}) {{seed}} dist {{dist}}"


LAMMPS_ENSEMBLE_NPT = "fix ensemble all npt temp {{Tstart}} {{Tstop}} {{Tdamp}} iso {{Pstart}} {{Pstop}} {{Pdamp}}"
Expand Down
2 changes: 2 additions & 0 deletions src/atomistics/calculators/lammps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def lammps_thermal_expansion_loop(
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.

lmp=None,
output_keys=OutputThermalExpansion.keys(),
**kwargs,
Expand All @@ -115,6 +116,7 @@ def lammps_thermal_expansion_loop(
timestep=timestep,
seed=seed,
dist=dist,
velocity_rescale_factor=velocity_rescale_factor,
),
lmp=lmp,
**kwargs,
Expand Down
22 changes: 13 additions & 9 deletions src/atomistics/calculators/lammps/libcalculator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Optional

import numpy as np
import pandas
Expand Down Expand Up @@ -154,12 +154,12 @@ def calc_molecular_dynamics_nvt_with_lammpslib(
timestep: float = 0.001,
seed: int = 4928459,
dist: str = "gaussian",
disable_initial_velocity: bool = False,
velocity_rescale_factor: Optional[float] = 2.0,
lmp=None,
output_keys=OutputMolecularDynamics.keys(),
**kwargs,
) -> dict:
if not disable_initial_velocity:
if velocity_rescale_factor is not None:
init_str = (
LAMMPS_THERMO_STYLE
+ "\n"
Expand All @@ -180,6 +180,7 @@ def calc_molecular_dynamics_nvt_with_lammpslib(
timestep=timestep,
seed=seed,
dist=dist,
velocity_rescale_factor=velocity_rescale_factor,
)
else:
init_str = (
Expand Down Expand Up @@ -232,12 +233,12 @@ def calc_molecular_dynamics_npt_with_lammpslib(
Pdamp: float = 1.0,
seed: int = 4928459,
dist: str = "gaussian",
disable_initial_velocity: bool = False,
velocity_rescale_factor: Optional[float] = 2.0,
lmp=None,
output_keys=OutputMolecularDynamics.keys(),
**kwargs,
) -> dict:
if not disable_initial_velocity:
if velocity_rescale_factor is not None:
init_str = (
LAMMPS_THERMO_STYLE
+ "\n"
Expand All @@ -261,6 +262,7 @@ def calc_molecular_dynamics_npt_with_lammpslib(
timestep=timestep,
seed=seed,
dist=dist,
velocity_rescale_factor=velocity_rescale_factor,
)
else:
init_str = (
Expand Down Expand Up @@ -314,12 +316,12 @@ def calc_molecular_dynamics_nph_with_lammpslib(
Pdamp: float = 1.0,
seed: int = 4928459,
dist: str = "gaussian",
disable_initial_velocity: bool = False,
velocity_rescale_factor: Optional[float] = 2.0,
lmp=None,
output_keys=OutputMolecularDynamics.keys(),
**kwargs,
) -> dict:
if not disable_initial_velocity:
if velocity_rescale_factor is not None:
init_str = (
LAMMPS_THERMO_STYLE
+ "\n"
Expand All @@ -340,6 +342,7 @@ def calc_molecular_dynamics_nph_with_lammpslib(
timestep=timestep,
seed=seed,
dist=dist,
velocity_rescale_factor=velocity_rescale_factor,
)
else:
init_str = (
Expand Down Expand Up @@ -389,12 +392,12 @@ def calc_molecular_dynamics_langevin_with_lammpslib(
Tdamp: float = 0.1,
seed: int = 4928459,
dist: str = "gaussian",
disable_initial_velocity: bool = False,
velocity_rescale_factor: Optional[float] = 2.0,
lmp=None,
output_keys=OutputMolecularDynamics.keys(),
**kwargs,
):
if not disable_initial_velocity:
if velocity_rescale_factor is not None:
init_str = (
LAMMPS_THERMO_STYLE
+ "\n"
Expand All @@ -417,6 +420,7 @@ def calc_molecular_dynamics_langevin_with_lammpslib(
timestep=timestep,
seed=seed,
dist=dist,
velocity_rescale_factor=velocity_rescale_factor,
)
else:
init_str = (
Expand Down
4 changes: 2 additions & 2 deletions tests/test_lammpslib_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def test_lammps_md_nvt_all_no_velocity(self):
seed=4928459,
dist="gaussian",
lmp=None,
disable_initial_velocity=True,
velocity_rescale_factor=None,
)
self.assertEqual(result_dict["positions"].shape, (10, 32, 3))
self.assertEqual(result_dict["velocities"].shape, (10, 32, 3))
Expand Down Expand Up @@ -163,7 +163,7 @@ def test_lammps_md_npt_all_no_velocity(self):
seed=4928459,
dist="gaussian",
lmp=None,
disable_initial_velocity=True,
velocity_rescale_factor=None,
)
self.assertEqual(result_dict["positions"].shape, (10, 32, 3))
self.assertEqual(result_dict["velocities"].shape, (10, 32, 3))
Expand Down
Loading