Skip to content

Provide a mechanism to resolve imaginary modes#174

Merged
rul048 merged 63 commits intomaterialyzeai:mainfrom
Andrew-S-Rosen:all_rosen_prs
Mar 17, 2026
Merged

Provide a mechanism to resolve imaginary modes#174
rul048 merged 63 commits intomaterialyzeai:mainfrom
Andrew-S-Rosen:all_rosen_prs

Conversation

@Andrew-S-Rosen
Copy link
Copy Markdown
Contributor

@Andrew-S-Rosen Andrew-S-Rosen commented Mar 10, 2026

Summary

In this PR, I have added a new method that attempts to resolve the imaginary modes by rattling the atoms. This has been shown to drastically reduce the number of imaginary modes when followed by a subsequent relaxation. I tested this workflow out on MOF-5 and found it reduced the percent of modes that are imaginary from 5.72% to precisely 0 after just one pass.

To enable this, I have added a new keyword argument fix_imaginary_attempts: int = 0 that is the (maximum) number of attempts to be made to resolve the imaginary modes. One can imagine smarter ways of resolving the imaginary modes in the future, such as displacing the atoms along the imaginary modes, but I leave that to someone else to do if they wish.

Tests

Besides the unit tests I added, I have run this test on MOF-5 to reproduce the constant-pressure heat capacity in this paper. I get the exact same answer to within <0.01 J/g/K after the imaginary mode correction. Without the imaginary mode correction, the error is very large.

Motivation

When calculating thermochemistry via QHACalc (or even in the harmonic limit with PhononCalc), the thermodynamic properties are only strictly valid if there are no imaginary modes. However, a relaxed structure may not necessarily be dynamically stable, in which case the thermochemistry is largely meaningless due to the presence of imaginary modes, which phonopy simply ignores. There are several papers showing that the fraction of imaginary modes you have can drastically alter the predicted thermochemistry. Since users expect to run QHACalc or PhononCalc and get reliable results, it is important for us to provide a mechanism to not only report when things might be questionable but to also systematically correct them. Since QHACalc calls PhononCalc for each stress factor, this is something that needs to be implemented in PhononCalc directly and unfortunately can't be left to the user.

Checklist

  • Google format doc strings added. Check with ruff.
  • Type annotations included. Check with mypy.
  • Tests added for new features/fixes.
  • If applicable, new classes/functions/modules have duecredit @due.dcite decorators to reference relevant papers by DOI (example)

Tip: Install pre-commit hooks to auto-check types and linting before every commit:

pip install -U pre-commit
pre-commit install

@Andrew-S-Rosen Andrew-S-Rosen marked this pull request as draft March 10, 2026 04:32
@Andrew-S-Rosen Andrew-S-Rosen changed the title [WIP] Add a mechanism to automatically handle imaginary modes in PhononCalc Improved handling of imaginary modes: Part 2 Mar 10, 2026
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
@Andrew-S-Rosen Andrew-S-Rosen marked this pull request as ready for review March 11, 2026 04:16
@Andrew-S-Rosen Andrew-S-Rosen changed the title Improved handling of imaginary modes: Part 2/2 Provide a mechanism to resolve imaginary modes Mar 11, 2026
Signed-off-by: Andrew S. Rosen <asrosen93@gmail.com>
@Andrew-S-Rosen Andrew-S-Rosen marked this pull request as draft March 11, 2026 05:05
@Andrew-S-Rosen Andrew-S-Rosen marked this pull request as ready for review March 11, 2026 18:40
@Andrew-S-Rosen
Copy link
Copy Markdown
Contributor Author

Andrew-S-Rosen commented Mar 11, 2026

@rul048 alright! This one should be ready for review now. 👍 This is the last big one. Thank you!!

@rul048
Copy link
Copy Markdown
Contributor

rul048 commented Mar 16, 2026

The CI failure seems to be related to the recent nvalchemi-toolkit-ops release, which introduced quite a few changes. We will fix it asap.

@rul048
Copy link
Copy Markdown
Contributor

rul048 commented Mar 17, 2026

All tests have now passed! Thanks so much for all the work on this. I really appreciate the thoughtful implementation and thorough testing. This will be very helpful for improving the robustness of QHA and harmonic phonon workflows in MatCalc.

@rul048 rul048 merged commit d2a621b into materialyzeai:main Mar 17, 2026
2 of 3 checks passed
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.

2 participants