Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a2e7327
Migrate potential interface from atomistics to pyiron_lammps
jan-janssen Nov 8, 2025
5f29115
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2025
e8d3465
Add LAMMPS file interface function
jan-janssen Nov 8, 2025
381a624
Merge branch 'potential' into lammps_function
jan-janssen Nov 8, 2025
79c6cb3
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2025
520f1ea
refactor
jan-janssen Nov 8, 2025
289123c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2025
2fcdedb
fix file interface
jan-janssen Nov 8, 2025
aa892fe
Add calc functions to init
jan-janssen Nov 8, 2025
7fc139f
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 8, 2025
e946f96
Add potential to init
jan-janssen Nov 16, 2025
a2b6303
Add potential test
jan-janssen Nov 16, 2025
b48ebb1
Merge branch 'potential' into lammps_function
jan-janssen Nov 16, 2025
0196abb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 17, 2025
98cb97a
Merge remote-tracking branch 'origin/main' into lammps_function
jan-janssen Nov 19, 2025
8a53bd9
Add a first test
jan-janssen Nov 19, 2025
2a4e10c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
fd034b0
Add resource path
jan-janssen Nov 19, 2025
4d2101f
Merge remote-tracking branch 'origin/lammps_function' into lammps_fun…
jan-janssen Nov 19, 2025
8c91424
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
cc39ac5
fix resource path
jan-janssen Nov 19, 2025
47a1ee7
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2025
c5ae8e3
move files
jan-janssen Nov 19, 2025
6cc5e0a
Delete tests/static/potentials_lammps.csv
jan-janssen Nov 19, 2025
601a76b
Delete tests/static/potential_LAMMPS/1999--Mishin-Y--Al--LAMMPS--ipr1…
jan-janssen Nov 19, 2025
0a2c502
add calc static test
jan-janssen Nov 20, 2025
232995e
Merge remote-tracking branch 'origin/lammps_function' into lammps_fun…
jan-janssen Nov 20, 2025
6a614f9
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
5f32e2c
remove print
jan-janssen Nov 20, 2025
fdc415c
Merge branch 'lammps_function' of github.com:pyiron/pyiron_lammps int…
jan-janssen Nov 20, 2025
800c2d7
test missing ionic steps
jan-janssen Nov 20, 2025
abf5590
first minimize
jan-janssen Nov 20, 2025
8e9ebc0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
f3bda4c
pressure rotation
jan-janssen Nov 20, 2025
7adda1d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
37b2379
simplify tests
jan-janssen Nov 20, 2025
4dd26b2
remove argument
jan-janssen Nov 20, 2025
fc80c8e
feat: Increase test coverage for compatibility module (#268)
google-labs-jules[bot] Nov 20, 2025
81a583b
Delete .gitignore
jan-janssen Nov 20, 2025
98e73cd
fix tests
jan-janssen Nov 20, 2025
46ec6a0
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
86da131
Add LammpsStructureCompatibility - work in progress
jan-janssen Nov 20, 2025
318f5a6
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
38ba25d
minor changes
jan-janssen Nov 20, 2025
06c94af
Merge branch 'LammpsStructureCompatibility' of github.com:pyiron/pyir…
jan-janssen Nov 20, 2025
f82bb3d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
1587277
Fix water
jan-janssen Nov 20, 2025
ee4d7e5
Merge branch 'LammpsStructureCompatibility' of github.com:pyiron/pyir…
jan-janssen Nov 20, 2025
99512a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 20, 2025
f376116
Merge remote-tracking branch 'origin/main' into lammps_function_water
jan-janssen Nov 20, 2025
dffaf72
Merge remote-tracking branch 'origin/LammpsStructureCompatibility' in…
jan-janssen Nov 20, 2025
c815c16
fix time step
jan-janssen Nov 21, 2025
6d0220a
Add support for atom_type selection
jan-janssen Nov 21, 2025
a263de3
fix ionic steps
jan-janssen Nov 21, 2025
8ca0644
fix another test
jan-janssen Nov 27, 2025
19c5a01
test parameter validation for structure optimization
jan-janssen Nov 27, 2025
87a577f
fix broken test
jan-janssen Nov 27, 2025
bb9a8b6
fix test
jan-janssen Nov 27, 2025
192006b
fix value error test
jan-janssen Nov 27, 2025
8b2d4a2
add nve test
jan-janssen Nov 27, 2025
dee5eb4
another test for minimize with wrong units
jan-janssen Nov 27, 2025
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
5 changes: 5 additions & 0 deletions pyiron_lammps/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import pyiron_lammps._version
from pyiron_lammps.compatibility.calculate import calc_md, calc_minimize, calc_static
from pyiron_lammps.compatibility.file import (
lammps_file_initialization,
lammps_file_interface_function,
)
from pyiron_lammps.output import parse_lammps_output as parse_lammps_output_files
from pyiron_lammps.potential import get_potential_by_name, get_potential_dataframe
from pyiron_lammps.structure import write_lammps_datafile as write_lammps_structure
Expand Down
Empty file.
479 changes: 479 additions & 0 deletions pyiron_lammps/compatibility/calculate.py

Large diffs are not rendered by default.

159 changes: 159 additions & 0 deletions pyiron_lammps/compatibility/file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
import os
import subprocess
from typing import Optional

from ase.atoms import Atoms

from pyiron_lammps.compatibility.calculate import (
calc_md,
calc_minimize,
calc_static,
)
from pyiron_lammps.output import parse_lammps_output
from pyiron_lammps.potential import get_potential_by_name
from pyiron_lammps.structure import write_lammps_datafile


def lammps_file_interface_function(
working_directory: str,
structure: Atoms,
potential: str,
calc_mode: str = "static",
calc_kwargs: Optional[dict] = None,
units: str = "metal",
lmp_command: str = "mpiexec -n 1 --oversubscribe lmp_mpi -in lmp.in",
resource_path: Optional[str] = None,
):
"""
A single function to execute a LAMMPS calculation based on the LAMMPS job implemented in pyiron

Examples:

>>> import os
>>> from ase.build import bulk
>>> from pyiron_atomistics.lammps.lammps import lammps_function
>>>
>>> shell_output, parsed_output, job_crashed = lammps_function(
... working_directory=os.path.abspath("lmp_working_directory"),
... structure=bulk("Al", cubic=True),
... potential='2009--Mendelev-M-I--Al-Mg--LAMMPS--ipr1',
... calc_mode="md",
... calc_kwargs={"temperature": 500.0, "pressure": 0.0, "n_ionic_steps": 1000, "n_print": 100},
... cutoff_radius=None,
... units="metal",
... bonds_kwargs={},
... enable_h5md=False,
... )

Args:
working_directory (str): directory in which the LAMMPS calculation is executed
structure (Atoms): ase.atoms.Atoms - atomistic structure
potential (str): Name of the LAMMPS potential based on the NIST database and the OpenKIM database
calc_mode (str): select mode of calculation ["static", "md", "minimize", "vcsgc"]
calc_kwargs (dict): key-word arguments for the calculate function, the input parameters depend on the calc_mode:
"static": No parameters
"md": "temperature", "pressure", "n_ionic_steps", "time_step", "n_print", "temperature_damping_timescale",
"pressure_damping_timescale", "seed", "tloop", "initial_temperature", "langevin", "delta_temp",
"delta_press", job_name", "rotation_matrix"
"minimize": "ionic_energy_tolerance", "ionic_force_tolerance", "max_iter", "pressure", "n_print", "style",
"rotation_matrix"
"vcsgc": "mu", "ordered_element_list", "target_concentration", "kappa", "mc_step_interval", "swap_fraction",
"temperature_mc", "window_size", "window_moves", "temperature", "pressure", "n_ionic_steps",
"time_step", "n_print", "temperature_damping_timescale", "pressure_damping_timescale", "seed",
"initial_temperature", "langevin", "job_name", "rotation_matrix"
Comment thread
coderabbitai[bot] marked this conversation as resolved.
cutoff_radius (float): cut-off radius for the interatomic potential
units (str): Units for LAMMPS
bonds_kwargs (dict): key-word arguments to create atomistic bonds:
"species", "element_list", "cutoff_list", "max_bond_list", "bond_type_list", "angle_type_list",
server_kwargs (dict): key-word arguments to create server object - the available parameters are:
"user", "host", "run_mode", "queue", "qid", "cores", "threads", "new_h5", "structure_id", "run_time",
"memory_limit", "accept_crash", "additional_arguments", "gpus", "conda_environment_name",
"conda_environment_path"
enable_h5md (bool): activate h5md mode for LAMMPS
write_restart_file (bool): enable writing the LAMMPS restart file
read_restart_file (bool): enable loading the LAMMPS restart file
restart_file (str): file name of the LAMMPS restart file to copy
executable_version (str): LAMMPS version to for the execution
executable_path (str): path to the LAMMPS executable
input_control_file (str|list|dict): Option to modify the LAMMPS input file directly

Comment on lines +48 to +79
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

Function docstring is out of sync with the actual signature and supported modes

lammps_file_interface_function’s docstring still describes the much richer pyiron_atomistics.lammps.lammps.lammps_function interface:

  • Mentions calc_mode options including "vcsgc" (not supported here).
  • Lists many parameters (cutoff_radius, bonds_kwargs, server_kwargs, enable_h5md, restart options, executable_*`, etc.) that are not present in the function signature and are not handled anywhere.

Currently, only:

(working_directory, structure, potential, calc_mode, calc_kwargs, units, lmp_command, resource_path)

are accepted, and calc_mode is restricted to "static", "md", "minimize" (other values raise ValueError).

To avoid confusion for users of this new entry point:

  • Either update the docstring to match this slimmer API and explicitly state that higher‑level features are provided elsewhere, or
  • Extend the function to accept and honour (or at least plumb through) the documented arguments if full drop‑in compatibility is required.

Similarly, remove or clarify "vcsgc" in both the calc_mode description and calc_kwargs breakdown unless support is planned here.

Also applies to: 87-105, 107-121


🏁 Script executed:

#!/bin/bash
# Extract the function definition, docstring, and implementation
cat pyiron_lammps/compatibility/file.py | head -150 | tail -110

Length of output: 5353


🏁 Script executed:

#!/bin/bash
# Search for calc_mode validation and ValueError handling
rg -n -A5 -B5 'calc_mode' pyiron_lammps/compatibility/file.py

Length of output: 2890


🏁 Script executed:

#!/bin/bash
# Look for parameter handling in the file (cutoff_radius, bonds_kwargs, etc.)
rg -n 'cutoff_radius|bonds_kwargs|server_kwargs|enable_h5md|restart_file|executable' pyiron_lammps/compatibility/file.py

Length of output: 793


Update docstring to match actual function signature and supported calc_modes

lammps_file_interface_function has a simplified API incompatible with its docstring. The function accepts only: working_directory, structure, potential, calc_mode, calc_kwargs, units, lmp_command, resource_path (8 parameters), but the docstring documents 18+ additional parameters (cutoff_radius, bonds_kwargs, server_kwargs, enable_h5md, restart/executable options, etc.) that are never handled.

Similarly, the docstring lists "vcsgc" as a supported calc_mode (line 52), but the implementation (lines 119–121) only accepts "static", "md", or "minimize", raising ValueError for any other value.

Users following the docstring will encounter immediate errors. Either:

  • Update the docstring to match the current slimmer API and clarify that advanced features are in the upstream interface, or
  • Accept and plumb the documented parameters if full compatibility is intended.

Also remove "vcsgc" from the docstring unless support is added.

Returns:
str, dict, bool: Tuple consisting of the shell output (str), the parsed output (dict) and a boolean flag if
the execution raised an accepted error.
"""
if calc_kwargs is None:
calc_kwargs = {}

os.makedirs(working_directory, exist_ok=True)
potential_dataframe = get_potential_by_name(
potential_name=potential, resource_path=resource_path
)
lmp_str_lst = lammps_file_initialization(structure=structure)
lmp_str_lst += potential_dataframe["Config"]
lmp_str_lst += ["variable dumptime equal {} ".format(calc_kwargs.get("n_print", 1))]
lmp_str_lst += [
"dump 1 all custom ${dumptime} dump.out id type xsu ysu zsu fx fy fz vx vy vz",
'dump_modify 1 sort id format line "%d %d %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g %20.15g"',
]
Comment on lines +87 to +97
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

lammps_file_initialization ignores the units argument passed to lammps_file_interface_function

You accept units in lammps_file_interface_function and pass it to:

  • write_lammps_datafile(..., units=units, ...)
  • parse_lammps_output(..., units=units, ...)

but you call:

lmp_str_lst = lammps_file_initialization(structure=structure)

lammps_file_initialization has its own units parameter defaulting to "metal", so the LAMMPS input file will always contain:

units metal

even if the caller requested a different unit system. This desynchronises the simulation units from the datafile/output parsing.

You probably want:

-    lmp_str_lst = lammps_file_initialization(structure=structure)
+    lmp_str_lst = lammps_file_initialization(structure=structure, units=units)

so all components (input, datafile, parsing) agree on the unit system.

Also applies to: 123-124

🤖 Prompt for AI Agents
In pyiron_lammps/compatibility/file.py around lines 87 to 105 (and also check
lines 123-124), lammps_file_initialization is called without forwarding the
units parameter so the generated LAMMPS input always uses the default "metal";
update the call to pass units=units (e.g., lmp_str_lst =
lammps_file_initialization(structure=structure, units=units)) so the input,
datafile, and output parsing all use the same unit system.


if calc_mode == "static":
lmp_str_lst += calc_static()
elif calc_mode == "md":
if "n_ionic_steps" in calc_kwargs.keys():
n_ionic_steps = int(calc_kwargs.pop("n_ionic_steps"))
else:
n_ionic_steps = 1
calc_kwargs["units"] = units
lmp_str_lst += calc_md(**calc_kwargs)
lmp_str_lst += ["run {} ".format(n_ionic_steps)]
elif calc_mode == "minimize":
calc_kwargs["units"] = units
lmp_str_tmp_lst, structure = calc_minimize(structure=structure, **calc_kwargs)
lmp_str_lst += lmp_str_tmp_lst
else:
raise ValueError(
f"calc_mode must be one of: static, md or minimize, not {calc_mode}"
)

with open(os.path.join(working_directory, "lmp.in"), "w") as f:
f.writelines([l + "\n" for l in lmp_str_lst])

write_lammps_datafile(
structure=structure,
potential_elements=potential_dataframe["Species"],
bond_dict=None,
units=units,
file_name="lammps.data",
working_directory=working_directory,
)

shell = subprocess.check_output(
lmp_command,
cwd=working_directory,
shell=True,
universal_newlines=True,
env=os.environ.copy(),
)
Comment on lines +130 to +136
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

subprocess.check_output(..., shell=True) may be risky if lmp_command is not trusted

The function executes:

shell = subprocess.check_output(
    lmp_command,
    cwd=working_directory,
    shell=True,
    universal_newlines=True,
    env=os.environ.copy(),
)

Using shell=True with a string command is standard in many HPC wrappers, but it means any untrusted content in lmp_command is interpreted by the shell.

If lmp_command can be influenced by untrusted input, you may want to:

  • Switch to shell=False and pass a list of arguments, e.g. ["mpiexec", "-n", "1", "--oversubscribe", "lmp_mpi", "-in", "lmp.in"], or
  • Clearly document that lmp_command must be trusted and is executed via the shell.

Given this is a low‑level interface, tightening it or documenting the expectation would be enough.


I'll verify this security concern by examining the code context to determine if lmp_command is actually user-controlled and if there's genuine risk.




🏁 Script executed:

#!/bin/bash
# Examine the full function context around the subprocess call
cat pyiron_lammps/compatibility/file.py | head -150 | tail -50

Length of output: 1799


🏁 Script executed:

#!/bin/bash
# Get broader context of the file to understand function signature and parameters
grep -n "def " pyiron_lammps/compatibility/file.py

Length of output: 113


🏁 Script executed:

#!/bin/bash
# Search for lmp_command usage and origin in the file
rg -n "lmp_command" pyiron_lammps/compatibility/file.py -B 5 -A 5

Length of output: 748


🏁 Script executed:

#!/bin/bash
# Check for any imports and the overall structure of this module
head -50 pyiron_lammps/compatibility/file.py

Length of output: 1609


I need to examine where this function is called to understand the actual risk profile.


---

🏁 Script executed:

```shell
#!/bin/bash
# Find all callers of lammps_file_interface_function
rg -n "lammps_file_interface_function" --type py -B 2 -A 2

Length of output: 624


🏁 Script executed:

#!/bin/bash
# Check if the function is exported or documented as public API
grep -r "lammps_file_interface_function" --include="*.py" --include="*.md" . 2>/dev/null | head -20

Length of output: 137


🏁 Script executed:

#!/bin/bash
# Look for __init__.py or __all__ exports to see if function is in public API
find . -name "__init__.py" -type f -exec grep -l "lammps_file_interface_function" {} \;

Length of output: 27


Tighten lmp_command handling to prevent shell injection

The security concern is valid. lmp_command is a user-controllable function parameter exported in the public API, passed directly to subprocess.check_output(..., shell=True) without validation. Callers can inject arbitrary shell commands.

Recommended fixes:

  1. Switch to shell=False and accept lmp_command as a list: ["mpiexec", "-n", "1", "--oversubscribe", "lmp_mpi", "-in", "lmp.in"]
  2. Or, add input validation (allowlist known commands/patterns) and document that lmp_command must be trusted
  3. Or, parse and validate lmp_command to ensure it only contains expected executable and known-safe options
🧰 Tools
🪛 Ruff (0.14.5)

126-126: subprocess call with shell=True identified, security issue

(S602)

output = parse_lammps_output(
working_directory=working_directory,
structure=structure,
potential_elements=potential_dataframe["Species"],
units=units,
prism=None,
dump_h5_file_name="dump.h5",
dump_out_file_name="dump.out",
log_lammps_file_name="log.lammps",
)
return shell, output, False


def lammps_file_initialization(structure, dimension=3, units="metal"):
boundary = " ".join(["p" if coord else "f" for coord in structure.pbc])
init_commands = [
"units " + units,
"dimension " + str(dimension),
"boundary " + boundary + "",
"atom_style atomic",
"read_data lammps.data",
]
return init_commands
Loading
Loading