chgnet icon indicating copy to clipboard operation
chgnet copied to clipboard

[Bug]: VASP labels Parsing issue

Open danialWang opened this issue 1 year ago • 2 comments

Email (Optional)

No response

Version

v0.3.8

Which OS(es) are you using?

  • [ ] MacOS
  • [ ] Windows
  • [X] Linux

What happened?

I am trying to json data and get the structures, energies and forces as shows in the fine_tuning.ipynb. However, there is an error in reading the json data. The error message shows the list indices was set as a string rather than integers.

Code snippet

dataset_dict = read_json("./my_vasp_calc_dir/chgnet_dataset.json")
structures = [Structure.from_dict(struct) for struct in dataset_dict["structure"]]
energies = dataset_dict["energy_per_atom"]
forces = dataset_dict["force"]

Log output

Traceback (most recent call last):
  File "/kfs3/scratch/dwang19/storage/data/wzy/LGFCBI/chgnet/reading.py", line 33, in <module>
    structures = [Structure.from_dict(struct)]
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dwang19/miniforge/envs/lammps/lib/python3.12/site-packages/pymatgen/core/structure.py", line 2814, in from_dict
    lattice = Lattice.from_dict(dct["lattice"])
                                ~~~^^^^^^^^^^^
  File "/home/dwang19/miniforge/envs/lammps/lib/python3.12/site-packages/pymatgen/core/structure.py", line 218, in __getitem__
    return self.sites[ind]  # type: ignore[return-value]
           ~~~~~~~~~~^^^^^
TypeError: list indices must be integers or slices, not str

Code of Conduct

  • [X] I agree to follow this project's Code of Conduct

danialWang avatar Jun 10 '24 01:06 danialWang

Can you try update your pymatgen version?

bowen-bd avatar Jun 10 '24 04:06 bowen-bd

Hi Bowen, Thank you for your quick response. I did use the latest version of pymatgen (2024.6.4). I found in the source code of pymatgen.core.Structure, there is a todo note, which may related to the error as I received. I have attach the code below. This line has been noted from 10-2023 version of Pymatgen. Is it possible the errors comes from the Pymatgen? Do you have any suggestions to solve the issue? Thanks!

TODO return type needs fixing (can be list[Site] but raises lots of mypy errors)

def __getitem__(self, ind: int | slice) -> Site:

danialWang avatar Jun 10 '24 13:06 danialWang