Skip to content

fix restart#298

Merged
jan-janssen merged 5 commits intomainfrom
restart
Jan 24, 2026
Merged

fix restart#298
jan-janssen merged 5 commits intomainfrom
restart

Conversation

@jan-janssen
Copy link
Copy Markdown
Member

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

Summary by CodeRabbit

  • New Features
    • Added support for reading from and writing to restart files in LAMMPS simulations, enabling continuation of previous calculations and checkpoint-based workflows.
    • Introduced configuration options to enable restart file functionality and specify restart file names within MD calculations.

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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jan 24, 2026

Warning

Rate limit exceeded

@jan-janssen has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 11 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📝 Walkthrough

Walkthrough

A single file was modified to add restart file handling capability to LAMMPS simulations through new parameters (write_restart_file, read_restart_file, restart_file) and logic to manage restart file operations during MD calculations and initialization.

Changes

Cohort / File(s) Summary
Restart File Support
src/pyiron_lammps/compatibility/file.py
Added shutil import; extended lammps_file_interface_function() with boolean controls for restart file I/O and restart file name parameter. Added conditional logic to copy restart files, initialize with restart data (setting initial_temperature to 0.0 and adding reset_timestep 0), and append write restart commands. Updated lammps_file_initialization() signature to accept restart parameters and conditionally append read_restart commands or preserve existing initialization commands.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop, the restart files flow,
Read them in, write them out just so,
MD simulations now restart with grace,
No need to begin from the starting place!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 'fix restart' is directly related to the changeset, which adds restart functionality (read/write restart files) to the LAMMPS interface, but is quite generic and doesn't clearly convey the specific implementation details.

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


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.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.30%. Comparing base (783c651) to head (1f19646).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #298      +/-   ##
==========================================
+ Coverage   82.12%   82.30%   +0.18%     
==========================================
  Files          11       11              
  Lines        1141     1153      +12     
==========================================
+ Hits          937      949      +12     
  Misses        204      204              

☔ 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.

Copy link
Copy Markdown

@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/pyiron_lammps/compatibility/file.py`:
- Around line 218-224: The lammps_file_initialization function can raise
TypeError because os.path.basename(restart_file) is called even when
restart_file is None while read_restart_file=True; update
lammps_file_initialization to validate the parameter combination (e.g., if
read_restart_file: require restart_file is not None and raise a clear ValueError
mentioning restart_file) or guard the append (only call os.path.basename and
append the read_restart command when restart_file is a non-empty string);
reference the symbols lammps_file_initialization, read_restart_file,
restart_file, and os.path.basename when making the change.
🧹 Nitpick comments (2)
src/pyiron_lammps/compatibility/file.py (2)

101-106: Consider renaming ambiguous loop variable l.

Per PEP 8, l (lowercase L) is ambiguous as it can be confused with 1 or I in some fonts. Consider renaming to line or cmd for clarity. This applies to the existing code pattern throughout the file.

♻️ Suggested rename
-    for l in lammps_file_initialization(
+    for line in lammps_file_initialization(
         structure=structure,
         units=units,
         read_restart_file=read_restart_file,
         restart_file=restart_file,
     ):
-        if l.startswith("units") and "units" in potential_replace:
+        if line.startswith("units") and "units" in potential_replace:
             lmp_str_lst.append(potential_replace["units"])
-        elif l.startswith("atom_style") and "atom_style" in potential_replace:
+        elif line.startswith("atom_style") and "atom_style" in potential_replace:
             lmp_str_lst.append(potential_replace["atom_style"])
             atom_type = potential_replace["atom_style"].split()[-1]
-        elif l.startswith("dimension") and "dimension" in potential_replace:
+        elif line.startswith("dimension") and "dimension" in potential_replace:
             lmp_str_lst.append(potential_replace["dimension"])
         else:
-            lmp_str_lst.append(l)
+            lmp_str_lst.append(line)

177-183: Consider validating restart file existence before copying.

If read_restart_file=True but the file doesn't exist, users will see a cryptic FileNotFoundError from shutil.copyfile. A descriptive error message would improve the user experience.

♻️ Suggested validation
     if read_restart_file:
+        if not os.path.isfile(restart_file):
+            raise FileNotFoundError(
+                f"Restart file not found: {os.path.abspath(restart_file)}"
+            )
         shutil.copyfile(
             os.path.abspath(restart_file),
             os.path.join(working_directory, os.path.basename(restart_file)),
         )

Comment on lines +218 to +224
def lammps_file_initialization(
structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
):
init_commands = ["units " + units]
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",
]
if read_restart_file:
init_commands.append(f"read_restart {os.path.basename(restart_file)}")
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 | 🟡 Minor

Potential TypeError if restart_file is None when read_restart_file=True.

The default restart_file=None combined with read_restart_file=True will cause os.path.basename(None) to raise a TypeError. While the main function always passes a value, this function could be called directly by external code.

Consider either validating the parameter combination or changing the default to match the main function.

🐛 Option 1: Add validation
 def lammps_file_initialization(
     structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
 ):
     init_commands = ["units " + units]
     boundary = " ".join(["p" if coord else "f" for coord in structure.pbc])
     if read_restart_file:
+        if restart_file is None:
+            raise ValueError("restart_file must be specified when read_restart_file=True")
         init_commands.append(f"read_restart {os.path.basename(restart_file)}")
♻️ Option 2: Use consistent default
 def lammps_file_initialization(
-    structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
+    structure, dimension=3, units="metal", read_restart_file=False, restart_file="restart.out"
 ):
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
def lammps_file_initialization(
structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
):
init_commands = ["units " + units]
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",
]
if read_restart_file:
init_commands.append(f"read_restart {os.path.basename(restart_file)}")
def lammps_file_initialization(
structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
):
init_commands = ["units " + units]
boundary = " ".join(["p" if coord else "f" for coord in structure.pbc])
if read_restart_file:
if restart_file is None:
raise ValueError("restart_file must be specified when read_restart_file=True")
init_commands.append(f"read_restart {os.path.basename(restart_file)}")
Suggested change
def lammps_file_initialization(
structure, dimension=3, units="metal", read_restart_file=False, restart_file=None
):
init_commands = ["units " + units]
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",
]
if read_restart_file:
init_commands.append(f"read_restart {os.path.basename(restart_file)}")
def lammps_file_initialization(
structure, dimension=3, units="metal", read_restart_file=False, restart_file="restart.out"
):
init_commands = ["units " + units]
boundary = " ".join(["p" if coord else "f" for coord in structure.pbc])
if read_restart_file:
init_commands.append(f"read_restart {os.path.basename(restart_file)}")
🤖 Prompt for AI Agents
In `@src/pyiron_lammps/compatibility/file.py` around lines 218 - 224, The
lammps_file_initialization function can raise TypeError because
os.path.basename(restart_file) is called even when restart_file is None while
read_restart_file=True; update lammps_file_initialization to validate the
parameter combination (e.g., if read_restart_file: require restart_file is not
None and raise a clear ValueError mentioning restart_file) or guard the append
(only call os.path.basename and append the read_restart command when
restart_file is a non-empty string); reference the symbols
lammps_file_initialization, read_restart_file, restart_file, and
os.path.basename when making the change.

@jan-janssen jan-janssen merged commit e06337b into main Jan 24, 2026
21 checks passed
@jan-janssen jan-janssen deleted the restart branch January 24, 2026 19:51
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.

1 participant