Skip to content
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

Update vasprun.converged_ionic logic when EDIFFG=0 #3765

Closed

Conversation

matthewkuner
Copy link
Contributor

@matthewkuner matthewkuner commented Apr 18, 2024

a new test for this has been added as well.

Summary by CodeRabbit

  • New Features
    • Enhanced the convergence detection logic in relaxation runs to include scenarios where EDIFFG=0.
  • Tests
    • Added a new test to ensure accurate handling of specific convergence scenarios in VASP simulations.

Copy link

coderabbitai bot commented Apr 18, 2024

Important

Auto Review Skipped

Review was skipped due to path filters

Files ignored due to path filters (1)
  • tests/files/vasp/outputs/vasprun.ediffg_set_to_0.xml.gz is excluded by !**/*.gz

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent updates in the pymatgen library refine the logic for determining the convergence of ionic steps in VASP simulations. These changes incorporate handling EDIFFG=0 alongside existing criteria for IBRION=1 or IBRION=2, ensuring accurate convergence assessment in relaxation runs. A new test method validates these adjustments by checking ionic steps, final energy, and convergence status in a specific scenario.

Changes

File Path Change Summary
pymatgen/io/vasp/outputs.py Updated logic in converged_ionic method to consider EDIFFG=0 alongside IBRION for convergence.
tests/io/vasp/test_outputs.py Added test_vasprun_ediffg_set_to_0 to validate a VaspRun scenario with specific convergence criteria.

🐇🌟
In the code's woven maze, a rabbit hopped,
Tweaking lines where numbers stopped.
With a hop, skip, and a code-laced leap,
Ensured the atoms peacefully sleep.
Now in the realm where electrons play,
Our rabbit ensures they sway the right way.
🌟🐇


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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

Comment on lines 615 to 623
In case where EDIFFG=0, return True if the max ionic steps are reached.
"""
nsw = self.parameters.get("NSW", 0)
ediffg = self.parameters.get("EDIFFG", 1)
ibrion = self.parameters.get("IBRION", -1 if nsw in (-1, 0) else 0)
if ibrion == 0:
return nsw <= 1 or self.md_n_steps == nsw
if ibrion in [1,2] and ediffg == 0:
return nsw <= 1 or nsw == len(self.ionic_steps)
Copy link

Choose a reason for hiding this comment

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

Refine the logic for handling EDIFFG=0 in converged_ionic method.

-        if ibrion in [1,2] and ediffg == 0:
-            return nsw <= 1 or nsw == len(self.ionic_steps)
+        if ibrion in [1, 2]:
+            if ediffg == 0:
+                return nsw <= 1 or nsw == len(self.ionic_steps)
+            else:
+                return nsw <= 1 or len(self.ionic_steps) < nsw

This change ensures that the method handles cases where EDIFFG is not zero correctly, separating the logic for EDIFFG=0 and other values more clearly.


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.

Suggested change
In case where EDIFFG=0, return True if the max ionic steps are reached.
"""
nsw = self.parameters.get("NSW", 0)
ediffg = self.parameters.get("EDIFFG", 1)
ibrion = self.parameters.get("IBRION", -1 if nsw in (-1, 0) else 0)
if ibrion == 0:
return nsw <= 1 or self.md_n_steps == nsw
if ibrion in [1,2] and ediffg == 0:
return nsw <= 1 or nsw == len(self.ionic_steps)
In case where EDIFFG=0, return True if the max ionic steps are reached.
"""
nsw = self.parameters.get("NSW", 0)
ediffg = self.parameters.get("EDIFFG", 1)
ibrion = self.parameters.get("IBRION", -1 if nsw in (-1, 0) else 0)
if ibrion == 0:
return nsw <= 1 or self.md_n_steps == nsw
if ibrion in [1, 2]:
if ediffg == 0:
return nsw <= 1 or nsw == len(self.ionic_steps)
else:
return nsw <= 1 or len(self.ionic_steps) < nsw

@matthewkuner matthewkuner force-pushed the update_converged_ionic branch from d471345 to 799c69f Compare April 18, 2024 00:16
@matthewkuner
Copy link
Contributor Author

@janosh this is ready for merging

@esoteric-ephemera
Copy link
Contributor

Just for context / documentation: the specific use case for EDIFFG = 0 is to ensure that a relaxation runs for NSW steps. In this case, the user isn't really worried about convergence wrt forces or energy differences, and @matthewkuner's solution prevents custodian from trying to correct the calc because Vasprun.converged_ionic = False. You can think about this as the non-AIMD way to generate a relaxation trajectory with DFT

Signed-off-by: Matthew Kuner <82329282+matthewkuner@users.noreply.github.com>
@janosh janosh added io Input/output functionality fix Bug fix PRs vasp Vienna Ab initio Simulation Package ecosystem Concerning the larger pymatgen ecosystem labels Apr 21, 2024
@janosh janosh enabled auto-merge (squash) April 21, 2024 10:05
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

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

thanks @matthewkuner for this change and @esoteric-ephemera for the context! 👍

@janosh janosh changed the title Update logic in vasprun.converged_ionic to account for cases where users set EDIFFG to 0. Update vasprun.converged_ionic logic when EDIFFG=0 Apr 21, 2024
@janosh janosh force-pushed the update_converged_ionic branch from 60e8a98 to 2330adb Compare April 21, 2024 12:04
@janosh janosh force-pushed the update_converged_ionic branch from 2330adb to f1e9297 Compare April 21, 2024 12:11
@janosh
Copy link
Member

janosh commented Apr 21, 2024

something wrong with the new test file it seems. can't be found for unknown reasons

Also see if file finding will be magically fixed. Praying for this

Signed-off-by: Matthew Kuner <82329282+matthewkuner@users.noreply.github.com>
auto-merge was automatically disabled April 21, 2024 16:02

Head branch was pushed to by a user without write access

@matthewkuner matthewkuner force-pushed the update_converged_ionic branch from e10c93d to 0f05ed2 Compare April 23, 2024 18:00
@matthewkuner
Copy link
Contributor Author

closed in favor of #3783

janosh pushed a commit that referenced this pull request Apr 23, 2024
 (#3783)

* init commit

* add back type hints accidentally removed

* pre-commit auto-fixes

* Fix lobster test

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: esoteric-ephemera <aaron.kaplan.physics@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ecosystem Concerning the larger pymatgen ecosystem fix Bug fix PRs io Input/output functionality vasp Vienna Ab initio Simulation Package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants