Skip to content

Add an opt-in linear fit of the vibrational free energy for QHA volumes with imaginary modes - #1632

Open
hrushikesh-s wants to merge 6 commits into
materialsproject:mainfrom
hrushikesh-s:qha-fit-imaginary-volumes
Open

hrushikesh-s wants to merge 6 commits into
materialsproject:mainfrom
hrushikesh-s:qha-fit-imaginary-volumes

Conversation

@hrushikesh-s

@hrushikesh-s hrushikesh-s commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Include a summary of major changes in bullet points:

  • The QHA leaves out the volumes with imaginary modes, and fails if fewer than 4 volumes are left. This PR adds the option fit_imaginary_volumes to analyze_free_energy and the QHA makers. It is off by default.
  • With the option, the volumes with imaginary modes are kept. Their vibrational free energy, heat capacity and entropy come from a straight-line fit in the volume through the volumes without imaginary modes, at each temperature, as in Deringer et al., Phys. Rev. B 89, 094303 (2014). This needs at least 2 volumes without imaginary modes. The electronic energies stay those of the calculations. A warning lists the fitted volumes.
  • We tested it on the force field QHAs of Impose the sum rules on phonopy force constants and do not store them in the forcefield QHA #1628 (39 materials, 7 volumes each). With MACE-OMAT-0-medium, 4 of the 5 QHAs that failed now run. With UPET, 6 of the 11 now run. The others have no volume without imaginary modes.
  • To see how good the fit is, we took the QHAs whose 7 volumes all have no imaginary modes. We kept the phonons of only some of the volumes and fitted the others. The table gives the error of the thermal expansion at 300 K, compared with the QHA from all 7 volumes. "Typical" is the median over the QHAs, and "worst" is the largest error. With 4 volumes kept, the QHA also runs without the fit, so the table also shows the error when the other 3 volumes are left out.
Volumes kept (of 7) Other volumes MACE-OMAT-0-medium, 23 QHAs: typical worst UPET, 17 QHAs: typical worst
smallest 2 fitted 13.6% 35.3% 5.5% 36.9%
smallest 3 fitted 8.5% 32.6% 8.8% 21.2%
middle 3 fitted 4.0% 16.4% 3.6% 39.2%
largest 3 fitted 10.7% 29.0% 13.5% 67.3%
smallest 4 fitted 7.6% 31.7% 5.2% 22.3%
smallest 4 left out 10.9% 52.6% 19.8% 187.9%
largest 4 fitted 7.0% 20.5% 10.0% 41.4%
largest 4 left out 5.0% 24.7% 10.5% 85.0%

The fit does not change the bulk modulus, since the electronic energies of all volumes are kept. Leaving 3 volumes out changes it by up to 19%. The fit gives only an estimate, which is why it is opt-in. The raw data and the scripts are attached: qha_fit_imaginary_volumes.zip and qha_fit_4of7.zip

Additional dependencies introduced (if any)

  • List all new dependencies needed and justify why. While adding dependencies that bring
    significantly useful functionality is perfectly fine, adding ones that add trivial
    functionality, e.g., to use one single easily implementable function, is frowned upon.
    Justify why that dependency is needed. Especially frowned upon are circular dependencies.

  • None

TODO (if any)

If this is a work-in-progress, write something about what else needs to be done.

  • None

Checklist

Work-in-progress pull requests are encouraged, but please put [WIP] in the pull request
title.

Before a pull request can be merged, the following items must be checked:

  • Code is in the standard Python style.
    The easiest way to handle this is to run the following in the correct sequence on
    your local machine. Start with running ruff and ruff format on your new code. This will
    automatically reformat your code to PEP8 conventions and fix many linting issues.
  • Doc strings have been added in the Numpy docstring format.
    Run ruff on your code.
  • Type annotations are highly encouraged. Run mypy to
    type check your code.
  • Tests have been added for any new functionality or bug fixes.
  • All linting and tests pass.

Note that the CI system will run all the above checks. But it will be much more
efficient if you already fix most errors prior to submitting the PR. It is highly
recommended that you use the pre-commit hook provided in the repository. Simply run
pre-commit install and a check will be run prior to allowing commits.

@JaGeo

JaGeo commented Oct 27, 2026

Copy link
Copy Markdown
Member

It could be good to also add it as an alternative to "ignore_imaginary_frequencies" and simply fit them from the ones that are real. A common scenario could be: you compress a material and it switches the phase. While it is stable at extended volumes.

… none, and document fit_imaginary_volumes in the QHA makers
@hrushikesh-s
hrushikesh-s marked this pull request as ready for review October 27, 2026 06:53
@hrushikesh-s

Copy link
Copy Markdown
Collaborator Author

Good point. fit_imaginary_volumes=True now works as an alternative to ignore_imaginary_modes.

Whenever at least 2 volumes have no imaginary modes, the volumes with imaginary modes are kept instead of left out. Their vibrational free energies come from a linear fit in the volume to the stable volumes, at each temperature.

In your eg, the compressed volumes would now stay in the QHA.

@JaGeo

JaGeo commented Oct 27, 2026

Copy link
Copy Markdown
Member

@hrushikesh-s that's great! Thanks. Will add another preprint where we used such an approach here soon.

Maybe you can check the approach when you keep 4 out of 7 volumes, for example

@hrushikesh-s hrushikesh-s changed the title [WIP] Add an opt-in linear fit of the vibrational free energy for QHA volumes with imaginary modes Add an opt-in linear fit of the vibrational free energy for QHA volumes with imaginary modes Oct 27, 2026
@hrushikesh-s

Copy link
Copy Markdown
Collaborator Author

@JaGeo, thanks, would be happy to cite your preprint in the docs once it is out...
With 4 of the 7 volumes kept, the fit works about as well as with 2 or 3, and better than leaving the volumes out.

I checked this with the force field QHAs from the description whose 7 volumes all have no imaginary modes (23 with MACE, 17 with UPET). I kept the 4 smallest or the 4 largest volumes, and treated the other 3 as if they had imaginary modes. The 4 largest is your example of unstable compressed volumes. Then I compared the thermal expansion at 300 K with the QHA from all 7 volumes.

With the other 3 volumes fitted, the typical error is 5% to 10%, and the worst is 41%.
With them left out, as the code does by default, the typical error is 5% to 20%, and the worst is 188%.

The fit also keeps the bulk modulus the same as with all 7 volumes, while leaving the volumes out changes it by up to 19%. The table and the raw data are now in the PR description, and the docs are updated.

@JaGeo

JaGeo commented Oct 27, 2026

Copy link
Copy Markdown
Member

Very nice! That's pretty cool that you were able to test this this fast!

t_max: float | None = None
pressure: float | None = None
ignore_imaginary_modes: bool = False
fit_imaginary_volumes: bool = False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is one potential problem here: we need to check if this argument and the one before are switched om at the same time

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, good catch!
With ignore_imaginary_modes=True all volumes are already kept, so the fit silently did nothing.
The QHA maker and analyze_free_energy now raise an error if both are True, with a test for each.
Does that look fine?

@JaGeo

JaGeo commented Nov 13, 2026

Copy link
Copy Markdown
Member

@hrushikesh-s This is the preprint that I mentioned: https://arxiv.org/abs/2611.15767v1 Maybe you can add it in a follow-up PR.

@hrushikesh-s

Copy link
Copy Markdown
Collaborator Author

@JaGeo Thanks! Since this PR is still open, I went ahead and added Bustamante et al. (10.48550/arXiv.2611.15767) directly to the analyze_free_energy docstring, due.cite, and docs/user/codes/vasp.md here.

This branch has not been deployed

No deployments
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