Skip to content

parse multiple epsilon values for lj/cut/soft#88

Merged
Yi-FanLi merged 12 commits intodeepmodeling:develfrom
Yi-FanLi:hti_epsilon_pair
Mar 10, 2025
Merged

parse multiple epsilon values for lj/cut/soft#88
Yi-FanLi merged 12 commits intodeepmodeling:develfrom
Yi-FanLi:hti_epsilon_pair

Conversation

@Yi-FanLi
Copy link
Collaborator

@Yi-FanLi Yi-FanLi commented Mar 9, 2025

This PR supports parsing pair-specific epsilon values (epsilon_0_0, epsilon_0_1, epsilon_1_1, etc) for multiple types. This feature can be useful for atomic liquids with multiple atom types.

Summary by CodeRabbit

  • New Features

    • Introduced a new JSON configuration file for simulation setup, including parameters for soft and deep interactions.
    • Enhanced simulation processing by centralizing the handling of Lennard-Jones parameters for consistent energy difference calculations.
  • Refactor

    • Streamlined redundant logic across multiple components to improve maintainability and reliability of energy output calculations.

@coderabbitai
Copy link

coderabbitai bot commented Mar 9, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

The pull request introduces a new function, parse_lj_sigma_epsilon, in dpti/hti_liq.py to centralize the processing of Lennard-Jones potential parameters (epsilon, sigma, and activation). This function replaces repeated inline logic in _ff_soft_on, _ff_deep_on, and _ff_soft_off by checking for these parameters (ensuring no conflict with _0_0 variants) and constructing pair coefficients accordingly. The energy difference calculation (e_diff) is updated to use the new function’s output, and the thermo_style in _gen_lammps_input_ideal now references v_e_diff.

Changes

File Change Summary
dpti/hti_liq.py - Added new function parse_lj_sigma_epsilon to encapsulate Lennard-Jones parameter processing.
- Replaced inline logic in _ff_soft_on, _ff_deep_on, and _ff_soft_off with a call to the new function.
- Updated the energy difference computation and modified the thermo_style string in _gen_lammps_input_ideal to reference v_e_diff.
examples/hti.SiO2-liq.json - Introduced a new JSON configuration file for simulation setup, detailing parameters such as equi_conf, ncopies, soft and deep interaction parameters, and simulation settings like nsteps and temp.

Possibly related PRs

  • pass element_num to sparam in hti_liq #81: The changes in the main PR introduce a new function for processing Lennard-Jones parameters, while the retrieved PR modifies the handling of soft parameters by adding an element_num to sparam, indicating that they are related through their shared focus on parameter handling in the same file.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d197d98 and 6d1259f.

📒 Files selected for processing (1)
  • examples/hti.SiO2-liq.json (1 hunks)

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e12bc0f and 5a19c77.

📒 Files selected for processing (1)
  • dpti/hti_liq.py (5 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
dpti/hti_liq.py

50-55: .format call is missing argument(s) for placeholder(s): p

(F524)

🔇 Additional comments (7)
dpti/hti_liq.py (7)

76-76: LGTM: Good refactoring to use the new function.

The refactoring simplifies the code by using the new centralized function for parameter processing.


79-80: Compute and variable definitions align with the refactoring.

The compute definition for lj_pe and the variable definition for e_diff are properly updated to match the new parameter processing approach.


98-98: LGTM: Consistent use of the refactored function.

Properly using the same centralized function for the hybrid case.


108-108: LGTM: Consistent variable assignment.

The variable assignment for e_diff is correctly defined using the compute array element.


126-126: LGTM: Consistent application of the refactoring pattern.

The refactoring pattern is consistently applied across all force field setup functions.


129-130: Compute and variable definitions align with the refactoring.

The compute and variable definitions are properly updated to match the parameter handling approach.


197-197: LGTM: Updated thermo_style to use variable instead of compute.

The thermo_style is updated to use v_e_diff instead of c_e_diff[1], which aligns with the variable-based approach in the refactored code.

Comment on lines +31 to +67
def parse_lj_sigma_epsilon(ret, sparam, hybrid=False):
element_num = sparam.get("element_num", 1)
sigma_key_index = filter(
lambda t: t[0] <= t[1],
((i, j) for i in range(element_num) for j in range(element_num)),
)
activation = sparam["activation"]
epsilon = sparam.get("epsilon", None)
epsilon_0_0 = sparam.get("epsilon_0_0", None)
if hybrid:
pair_coeff_str = "lj/cut/soft "
else:
pair_coeff_str = ""
if epsilon is not None:
assert (
epsilon_0_0 is None
), "epsilon and epsilon_0_0 cannot be set at the same time"
ret += f"variable EPSILON equal {epsilon:f}\n"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {p:s}${{EPSILON}} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["sigma_" + str(i) + "_" + str(j)],
)
else:
assert epsilon_0_0 is not None, "epsilon or epsilon_0_0 must be set"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {:s}{:f} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["epsilon_" + str(i) + "_" + str(j)],
sparam["sigma_" + str(i) + "_" + str(j)],
activation,
)
return ret
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

The new function centralizes parameter processing nicely, but contains a formatting bug.

This new function appropriately centralizes the logic for processing Lennard-Jones parameters, making the code more maintainable. However, there's a formatting error in the string template.

In line 50, the string contains a {p:s} placeholder, but no corresponding p value is provided in the .format() call. Fix it like this:

-            ret += "pair_coeff      {} {} {p:s}${{EPSILON}} {:f} {:f}\n".format(
+            ret += "pair_coeff      {} {} {}${{EPSILON}} {:f} {:f}\n".format(
                 i + 1,
                 j + 1,
                 pair_coeff_str,
                 sparam["sigma_" + str(i) + "_" + str(j)],
+                activation,
             )
📝 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 parse_lj_sigma_epsilon(ret, sparam, hybrid=False):
element_num = sparam.get("element_num", 1)
sigma_key_index = filter(
lambda t: t[0] <= t[1],
((i, j) for i in range(element_num) for j in range(element_num)),
)
activation = sparam["activation"]
epsilon = sparam.get("epsilon", None)
epsilon_0_0 = sparam.get("epsilon_0_0", None)
if hybrid:
pair_coeff_str = "lj/cut/soft "
else:
pair_coeff_str = ""
if epsilon is not None:
assert (
epsilon_0_0 is None
), "epsilon and epsilon_0_0 cannot be set at the same time"
ret += f"variable EPSILON equal {epsilon:f}\n"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {p:s}${{EPSILON}} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["sigma_" + str(i) + "_" + str(j)],
)
else:
assert epsilon_0_0 is not None, "epsilon or epsilon_0_0 must be set"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {:s}{:f} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["epsilon_" + str(i) + "_" + str(j)],
sparam["sigma_" + str(i) + "_" + str(j)],
activation,
)
return ret
def parse_lj_sigma_epsilon(ret, sparam, hybrid=False):
element_num = sparam.get("element_num", 1)
sigma_key_index = filter(
lambda t: t[0] <= t[1],
((i, j) for i in range(element_num) for j in range(element_num)),
)
activation = sparam["activation"]
epsilon = sparam.get("epsilon", None)
epsilon_0_0 = sparam.get("epsilon_0_0", None)
if hybrid:
pair_coeff_str = "lj/cut/soft "
else:
pair_coeff_str = ""
if epsilon is not None:
assert (
epsilon_0_0 is None
), "epsilon and epsilon_0_0 cannot be set at the same time"
ret += f"variable EPSILON equal {epsilon:f}\n"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {}${{EPSILON}} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["sigma_" + str(i) + "_" + str(j)],
activation,
)
else:
assert epsilon_0_0 is not None, "epsilon or epsilon_0_0 must be set"
for i, j in sigma_key_index:
ret += "pair_coeff {} {} {:s}{:f} {:f} {:f}\n".format(
i + 1,
j + 1,
pair_coeff_str,
sparam["epsilon_" + str(i) + "_" + str(j)],
sparam["sigma_" + str(i) + "_" + str(j)],
activation,
)
return ret
🧰 Tools
🪛 Ruff (0.8.2)

50-55: .format call is missing argument(s) for placeholder(s): p

(F524)

@Yi-FanLi Yi-FanLi merged commit 7009516 into deepmodeling:devel Mar 10, 2025
1 of 7 checks passed
felix5572 pushed a commit to felix5572/dpti that referenced this pull request Mar 16, 2025
* parse multiple epsilon values for lj/cut/soft

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* correct pair_coeff for hybrid style

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* support multiple activation values

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* support using a single sigma to set sigma for all pairs

* add an example for hti_liq of 2 atomic types

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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