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

Add formal_chempots option to ChemicalPotentialDiagram to plot the formal chemical potentials rather than the DFT energies #2916

Merged
merged 7 commits into from
Mar 28, 2023

Conversation

kavanase
Copy link
Contributor

The ChemicalPotentialDiagram object for which the (very useful! πŸ™Œ) pymatgen.analysis.chempot_diagram module is written, plots the chemical potential diagram using the absolute DFT energies, rather than the actual (formal) chemical potentials (aka. reference potentials) of the elements, which are the meaningful values that can be compared to experiment.

This is essentially the difference between absolute DFT energies (which on their own are essentially meaningless and differ substantially between different functional choices, input parameter/grid settings, vdW corrections, DFT codes etc) and formation energies (i.e. energies relative to the elemental energies) which are meaningful, and far more robust with respect to input parameter choice.
Moreover, the axis labels for these plots in the output of ChemicalPotentialDiagram.get_plot() (which is also used on the Materials Project website for the chemical potential diagram plots) are given as ΞΌ_X - ΞΌ_X^0, which means it should refer to the formal chemical potentials, but in fact it's the absolute DFT energies that are shown (i.e. ΞΌ_X(DFT)).

This PR adds an optional parameter formal_chempots = True to ChemicalPotentialDiagram which renormalises the entry energies and plots the formal chemical potentials.

    formal_chempots (bool): Whether to plot the formal ('reference') chemical potentials
        (i.e. ΞΌ_X - ΞΌ_X^0) or the absolute DFT reference energies (i.e. ΞΌ_X(DFT)).
        Default is True (i.e. plot formal chemical potentials).                

Example changes:

The chemical potential diagram of the Y-Ti-O-S phase space on the Materials Project (using the old code):
image
You can see the energies of the elemental reference states are not zero as they should be (i.e. not corresponding to their ΞΌ_X - ΞΌ_X^0 axis labels). – Might need to click into the image to see this clearly.

With the updated code we get the expected/desired behaviour:
image
Further examples can be generated using the test data in test_chempot_diagram.py.

I've added docstrings for these additions and also added a full set of tests to test_chempot_diagram.py for this option.

@janosh
Copy link
Member

janosh commented Mar 28, 2023

Thanks @kavanase for the clear explanation and screenshots. Very helpful!

@janosh janosh enabled auto-merge (squash) March 28, 2023 20:58
@janosh janosh merged commit abc65a7 into materialsproject:master Mar 28, 2023
@janosh janosh added enhancement A new feature or improvement to an existing one data viz PRs and issues about pymatgen plotting functionality labels Mar 28, 2023
@kavanase
Copy link
Contributor Author

No problem @janosh, thanks for the speedy merge!

jmmshn pushed a commit to jmmshn/pymatgen that referenced this pull request Mar 30, 2023
…e formal chemical potentials rather than the DFT energies (materialsproject#2916)

* Add `formal_chempots` option to `ChemicalPotentialDiagram` to plot the formal chemical potentials rather than the DFT energies

* Add tests for `formal_chempots` option in `ChemicalPotentialDiagram` to all applicable tests in `test_chempot_diagram.py`

* remove useless dict.copy() in _renormalize_entry(), fix some doc strings and typos

* replace assertArrayAlmostEqual() with pytest.approx() in test_chempot_diagram.py

* use dot access for plot attributes

---------

Co-authored-by: Janosh Riebesell <janosh.riebesell@gmail.com>
@mkhorton
Copy link
Member

mkhorton commented May 8, 2023

Just wanted to second, this was a great change. Thanks @kavanase!

@kavanase
Copy link
Contributor Author

No problem @mkhorton! πŸ˜ƒ
Just curious, do you know if/when this will be reflected in the Phase Diagram Explorer app on the MP website? I guess it's (currently) fixed to a specific pymatgen version, but can't find this anywhere in the docs.

@janosh
Copy link
Member

janosh commented May 10, 2023

@kavanase The web client is currently set to pymatgen==2023.3.23. This fix came just after that release and the next release wasn't until 2 days ago. We'll probably make a another web deployment next week (maybe even this Fri).

@kavanase
Copy link
Contributor Author

Ok cool! Thanks very much for the info @janosh! πŸ™Œ

@janosh
Copy link
Member

janosh commented May 10, 2023

Just pinging @tschaume and @yang-ruoxi to make sure we bump pymatgen for the next web deployment to publish this fix.

@kavanase
Copy link
Contributor Author

@janosh had a browse through, looks great! πŸ˜ƒ
Thanks very much all for the speedy update and deployment! πŸ™Œ

The elemental forms now arise when ΞΌ_X = 0 as expected, and the chemical potential values are physically meaningful (relative rather than absolute DFT energies):
image

image

@mattmcdermott
Copy link
Member

Looks good to me as well. Thanks for making this change @kavanase. I should have fixed this a long time ago ;)

@janosh
Copy link
Member

janosh commented May 15, 2023

Thanks for confirming the fix @kavanase @mattmcdermott.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data viz PRs and issues about pymatgen plotting functionality enhancement A new feature or improvement to an existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants