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

When reading in a POTCAR file with pymatgen.io.vasp.inputs.Potcar, the object can't distinguish between PBE_54 and PBE. #3951

Open
nhew1994 opened this issue Jul 26, 2024 · 6 comments
Labels

Comments

@nhew1994
Copy link

Python version

3.12.4

Pymatgen version

2024.6.10

Operating system version

Ubuntu-22.04

Current behavior

I have a POTCAR file written with PBE_54. When I read it into a Potcar object, potcar.functional will equal PBE instead of PBE_54.

Expected Behavior

I would expect it to be PBE_54 to reflect the actual POTCAR file being read.

Minimal example

from pymatgen.io.vasp.inputs import Potcar
path = "path_to_POTCAR_file"
potcar = Potcar.from_file(path)
print(potcar.functional)

Relevant files to reproduce this bug

Try any PBE_54 POTCAR file.

@nhew1994 nhew1994 added the bug label Jul 26, 2024
@DanielYang59
Copy link
Contributor

I think this is intended:

functional_tags: ClassVar[dict[str, dict[Literal["name", "class"], str]]] = {
"pe": {"name": "PBE", "class": "GGA"},
"91": {"name": "PW91", "class": "GGA"},
"rp": {"name": "revPBE", "class": "GGA"},
"am": {"name": "AM05", "class": "GGA"},
"ps": {"name": "PBEsol", "class": "GGA"},
"pw": {"name": "PW86", "class": "GGA"},
"lm": {"name": "Langreth-Mehl-Hu", "class": "GGA"},
"pb": {"name": "Perdew-Becke", "class": "GGA"},
"ca": {"name": "Perdew-Zunger81", "class": "LDA"},
"hl": {"name": "Hedin-Lundquist", "class": "LDA"},
"wi": {"name": "Wigner Interpolation", "class": "LDA"},
}

Probably because POTCAR itself doesn't carry a one-to-one mapping to VASP version (but compatible functionals) itself with its LEXCH tag. I could be wrong here, so let's see if @esoteric-ephemera has any corrections.

I think the reason versioned functional tags exist in pymatgen is to help locate the corresponding POTCAR directories from local file system:

functional_dir: ClassVar[dict[str, str]] = {
"PBE": "POT_GGA_PAW_PBE",
"PBE_52": "POT_GGA_PAW_PBE_52",
"PBE_52_W_HASH": "POTPAW_PBE_52",
"PBE_54": "POT_GGA_PAW_PBE_54",
"PBE_54_W_HASH": "POTPAW_PBE_54",
"PBE_64": "POT_PAW_PBE_64",

@nhew1994
Copy link
Author

Hi @DanielYang59. Thank you for the reply.

At the moment, I am storing my results on my personal MongoDB database. When I read in a POTCAR file that I used with PBE_54, I would just like it to say PBE_54 to reflect the actual 54 version that I use instead of the old PBE.

I am wondering if there is any way around this. If not, that is ok.

@DanielYang59
Copy link
Contributor

DanielYang59 commented Jul 30, 2024

No problem at all.

I wish I could be more helpful on this, but I don't have much experience with the functionality you were looking for. Hopefully others would have smarter solutions.

The functional property of PotcarSingle is not writable, however that of Potcar (a collection of PotcarSingle) is writable, therefore you could overwrite it directly:

from pymatgen.io.vasp.inputs import Potcar


potcar = Potcar.from_file("POTCAR")
potcar.functional = "PBE_54"

print(potcar.functional)  # >>> "PBE_54"

But you have to double check if such modification breaks any downstream operations (i.e. OPs that require functional to be exactly PBE).

If you just want to "tag" the Potcar, perhaps you could add a separate attribute:

potcar = Potcar.from_file("POTCAR")
potcar.functional_versioned = "PBE_54"

print(potcar.functional_versioned) # >>> "PBE_54"

Hope this helps.

@nhew1994
Copy link
Author

@DanielYang59 Thanks again for your help. I've opted for the first option (overwrite directly) for now.

Cheers.

@nhew1994 nhew1994 reopened this Jul 30, 2024
@DanielYang59
Copy link
Contributor

All good, and do let me know if you (or any other) come up with smarter options :)

@esoteric-ephemera
Copy link
Contributor

esoteric-ephemera commented Jul 31, 2024

This has also confused me in the past but I don't know that it's a bug. The PotcarSingle class assumes instantiation from a string (or file), but has an optional from_symbol_and_functional instantiation method

Conversely, the Potcar class (a list of PotcarSingle's) assumes instantiation from symbols and a functional, with an optional from_file instantiation

It would probably make sense to have these be consistent in terms of what the default construction method is, but there's not enough reason to change this now and incur obvious breaking changes

So as @DanielYang59 said, the functional attr of any PotcarSingle reflects the DFT functional used to generate it (PBE or LDA)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants