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

.as_dict() method on VaspInput causes an AttributeError #3821

Open
Andrew-S-Rosen opened this issue May 12, 2024 · 0 comments
Open

.as_dict() method on VaspInput causes an AttributeError #3821

Andrew-S-Rosen opened this issue May 12, 2024 · 0 comments
Labels

Comments

@Andrew-S-Rosen
Copy link
Member

Andrew-S-Rosen commented May 12, 2024

Python version

3.11

Pymatgen version

2024.5.1

Operating system version

No response

Current behavior

When calling VaspInputSet.get_input_set(), the returned VaspInput has a broken .as_dict() method. That is reported below. The returned VaspInput is already a dict, so that's what should be presented. What is somewhat confusing though is that the method should really be called .get_vasp_input() since it returns a VaspInput and not a VaspInputSet.

from pymatgen.core import Structure
from pymatgen.io.vasp.sets import MPStaticSet

s = Structure(
    lattice=[[0, 2.13, 2.13], [2.13, 0, 2.13], [2.13, 2.13, 0]],
    species=["Ni", "O"],
    coords=[[0, 0, 0], [0.5, 0.5, 0.5]],
)
vasp_input = MPStaticSet().get_input_set(structure=s, potcar_spec=True)
print(vasp_input.as_dict())

Traceback:

File ~/software/miniconda/envs/quacc/lib/python3.11/site-packages/pymatgen/io/vasp/inputs.py:2758, in VaspInput.as_dict(self)
   2756 def as_dict(self) -> dict:
   2757     """MSONable dict."""
-> 2758     dct = {key: val.as_dict() for key, val in self.items()}
   2759     dct["@module"] = type(self).__module__
   2760     dct["@class"] = type(self).__name__

File ~/software/miniconda/envs/quacc/lib/python3.11/site-packages/pymatgen/io/vasp/inputs.py:2758, in <dictcomp>(.0)
   2756 def as_dict(self) -> dict:
   2757     """MSONable dict."""
-> 2758     dct = {key: val.as_dict() for key, val in self.items()}
   2759     dct["@module"] = type(self).__module__
   2760     dct["@class"] = type(self).__name__

AttributeError: 'list' object has no attribute 'as_dict'

Expected Behavior

The .as_dict() method should return a dictionary.

@Andrew-S-Rosen Andrew-S-Rosen changed the title .as_dict() method on VaspInputSet causes an AttributeError .as_dict() method on VaspInput causes an AttributeError May 12, 2024
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

1 participant