pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

Error with Locpot.from_file/Species.from_str

Open VicTrqt opened this issue 1 year ago • 1 comments

Problem When I try to instantiate a pymatgen.io.vasp.outputs.Locpot object from the file, I get an IndexError from the Species.from_str call. I am using pymatgen v2023.11.12. Example

Python 3.11.6 | packaged by conda-forge | (main, Oct  3 2023, 10:40:35) [GCC 12.3.0] on linux
>>> from pymatgen.io.vasp import Locpot
>>> Locpot.from_file("LOCPOT")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/io/vasp/outputs.py", line 3438, in from_file
    (poscar, data, data_aug) = VolumetricData.parse_file(filename)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/io/vasp/outputs.py", line 3281, in parse_file
    poscar = Poscar.from_str("\n".join(poscar_string))
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/io/vasp/inputs.py", line 432, in from_str
    struct = Structure(
             ^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/core/structure.py", line 3670, in __init__
    super().__init__(
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/core/structure.py", line 929, in __init__
    site = PeriodicSite(
           ^^^^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/core/sites.py", line 334, in __init__
    species = Composition({get_el_sp(species): 1})  # type: ignore
                           ^^^^^^^^^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/core/periodic_table.py", line 1414, in get_el_sp
    return Species.from_str(obj)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^
  File "/home/vtrinquet/anaconda3/envs/test_pmg/lib/python3.11/site-packages/pymatgen/core/periodic_table.py", line 1051, in from_str
    properties = {tokens[0]: ast.literal_eval(tokens[1])}
                                              ~~~~~~^^^
IndexError: list index out of range 

VicTrqt avatar Dec 06 '23 10:12 VicTrqt

Update I noticed I had the same issue when trying to instantiate a Structure from a CONTCAR file... It seems that my compilation of VASP produces a CONTCAR file that features a slash after each element on the 6th line such as X/ Y/ Z/ instead of the usual X Y Z. It works as it should when I remove these slashes.

I think it would be nice to be able to treat this situation directly in pymatgen.

VicTrqt avatar Dec 08 '23 15:12 VicTrqt