-
Notifications
You must be signed in to change notification settings - Fork 4
LAMMPS: Add vmax option for structure optimization #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
@@ -49,11 +49,12 @@ def optimize_positions_and_volume_with_lammpslib( | |
| maxiter: int = 100000, | ||
| maxeval: int = 10000000, | ||
| thermo: int = 10, | ||
| vmax: Optional[float] = None, | ||
| lmp=None, | ||
| **kwargs, | ||
| ) -> Atoms: | ||
| template_str = ( | ||
| LAMMPS_MINIMIZE_VOLUME | ||
| _get_vmax_command(vmax=vmax) | ||
| + "\n" | ||
| + LAMMPS_THERMO_STYLE | ||
| + "\n" | ||
|
|
@@ -593,3 +594,13 @@ def evaluate_with_lammpslib( | |
| ) | ||
| lmp.close() | ||
| return results_dict | ||
|
|
||
|
|
||
| def _get_vmax_command(vmax: Optional[float]) -> str: | ||
| if vmax is not None: | ||
| if isinstance(vmax, float): | ||
| return LAMMPS_MINIMIZE_VOLUME + " vmax {vmax}".format(vmax=vmax) | ||
| else: | ||
| raise TypeError("vmax must be a float.") | ||
| else: | ||
| return LAMMPS_MINIMIZE_VOLUME | ||
|
Comment on lines
+599
to
+606
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix type check to accept integers. The 🐛 Proposed fix to accept both int and float def _get_vmax_command(vmax: Optional[float]) -> str:
if vmax is not None:
- if isinstance(vmax, float):
+ if isinstance(vmax, (int, float)):
return LAMMPS_MINIMIZE_VOLUME + " vmax {vmax}".format(vmax=vmax)
else:
raise TypeError("vmax must be a float.")
else:
return LAMMPS_MINIMIZE_VOLUMEOptional: Consider refactoring the error message. As per static analysis hint (TRY003), consider using a shorter error message or defining a custom exception class for consistency with Python conventions. ♻️ Example refactor def _get_vmax_command(vmax: Optional[float]) -> str:
if vmax is not None:
if isinstance(vmax, (int, float)):
return LAMMPS_MINIMIZE_VOLUME + " vmax {vmax}".format(vmax=vmax)
else:
- raise TypeError("vmax must be a float.")
+ raise TypeError(f"Expected numeric vmax, got {type(vmax).__name__}")
else:
return LAMMPS_MINIMIZE_VOLUME🧰 Tools🪛 Ruff (0.14.10)604-604: Avoid specifying long messages outside the exception class (TRY003) 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
LAMMPS fix box/relax vmax parameter documentation valid values💡 Result:
The vmax value is a positive fractional limit on how much the box may change in one minimizer iteration. Valid values:
References: LAMMPS fix box/relax documentation. [1][2]
Sources
[1] LAMMPS fix box/relax manual (release).
[2] LAMMPS documentation / examples (fix box/relax description).
🏁 Script executed:
Repository: pyiron/atomistics
Length of output: 111
🏁 Script executed:
Repository: pyiron/atomistics
Length of output: 704
🏁 Script executed:
Repository: pyiron/atomistics
Length of output: 1854
Add validation for
vmaxparameter to ensure it is positive.According to LAMMPS documentation,
vmaxmust be a positive number (> 0.0). The current implementation only checks if the value is a float type, but does not validate the valid range. This should be enforced in_get_vmax_command()to provide immediate feedback to users rather than letting LAMMPS fail at runtime.Suggested validation addition
🤖 Prompt for AI Agents