CederGroupHub / chgnet

Pretrained universal neural network potential for charge-informed atomistic modeling https://chgnet.lbl.gov
https://doi.org/10.1038/s42256-023-00716-3
Other
214 stars 54 forks source link

[Bug]: VASP labels Parsing issue #163

Open danialWang opened 4 weeks ago

danialWang commented 4 weeks ago

Email (Optional)

No response

Version

v0.3.8

Which OS(es) are you using?

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

BowenD-UCB commented 4 weeks ago

Can you try update your pymatgen version?

danialWang commented 4 weeks ago

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: