pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

Cannot init `Cohpcar` in `matgenb ` example notebook: `ValueError: setting an array element with a sequence.`

Open DanielYang59 opened this issue 1 year ago • 11 comments

Two LOBSTER examples in matgenb seems to be failing:

  • https://github.com/materialsvirtuallab/matgenb/blob/master/notebooks/2018-03-14-Plotting%20COHP%20from%20LOBSTER.ipynb
  • https://github.com/materialsvirtuallab/matgenb/blob/master/notebooks/2019-01-11-How%20to%20plot%20and%20evaluate%20output%20files%20from%20Lobster.ipynb
from pymatgen.io.lobster import Cohpcar


COHPCAR_path = "COHPCAR.lobster.txt"
cohpcar = Cohpcar(filename=COHPCAR_path)

Gives:

Traceback (most recent call last):
  File "/home/yang/developer/pymatgen/debug/recreate_cohp.py", line 5, in <module>
    cohpcar = Cohpcar(filename=COHPCAR_path)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/yang/developer/pymatgen/src/pymatgen/io/lobster/outputs.py", line 138, in __init__
    data = np.array([np.array(line.split(), dtype=float) for line in lines[num_bonds + 3 :]]).transpose()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (402,) + inhomogeneous part.

COHPCAR.lobster.txt

cc @JaGeo @QuantumChemist @naik-aakash

DanielYang59 avatar Dec 04 '24 09:12 DanielYang59

There is a second notebook. This one is not needed and outdated

JaGeo avatar Dec 04 '24 09:12 JaGeo

Thanks for the quick response! This one 2019-01-11-How to plot and evaluate output files from Lobster.ipynb? This seems to be failing for the same reason

DanielYang59 avatar Dec 04 '24 09:12 DanielYang59

@naik-aakash could you take a look?

JaGeo avatar Dec 04 '24 09:12 JaGeo

In general, it would be great if the tutorials would be directly tested on a new pymatgen version. In the current way, we have a very hard time to update them.

JaGeo avatar Dec 04 '24 09:12 JaGeo

I'm btw not very actively working on the LOBSTER stuff.

QuantumChemist avatar Dec 04 '24 09:12 QuantumChemist

Hi @JaGeo , @DanielYang59 , I can look into it 😄

naik-aakash avatar Dec 04 '24 16:12 naik-aakash

@naik-aakash Thanks a lot :)

I'm btw not very actively working on the LOBSTER stuff.

Sorry I didn't know that, but I would keep that in mind

In general, it would be great if the tutorials would be directly tested on a new pymatgen version. In the current way, we have a very hard time to update them.

I believe everything would suffer if not checked/maintained regularly. I guess it's good to trigger the test workflow of matgenb when pymatgen has a new release, but it looks like we might need a custom trigger for this (i.e. GitHub may not provide native support for this).

Or perhaps just make our life easier and trigger that every few months.

I have collected this into my TODO list :)

DanielYang59 avatar Dec 04 '24 16:12 DanielYang59

Hi @DanielYang59 , I had a chance to quickly look into this issue. Seems it not any bug in parser but the example file on the repository has for some reason got added an new line at last line causing this error. Simply removing this trailing line seemed to fix the issue. For both the example it is same problem.

Here is an updated file that can be used instead (the only change is for the last line unexpected "\n" is removed, this is usually not the case of files generated by LOBSTER)

Fixed: COHPCAR.lobster.txt

naik-aakash avatar Dec 22 '24 12:12 naik-aakash

Seems it not any bug in parser but the example file on the repository has for some reason got added an new line at last line causing this error. Simply removing this trailing line seemed to fix the issue. For both the example it is same problem.

Hi @naik-aakash wish everything is doing well. That is hugely appreciated. If that's really the case, then LOBSTER might be violating the POSIX standard definition of "line" IMO:

3.185 Line A sequence of zero or more non- characters plus a terminating character.

As per the above definition, every line (including the last) should end with a terminating "newline" char (which might look like an "empty line at the end" in a text editor but it's not).

In other words, a text file should always end as b'somedata\n' (or other line ending char) instead of b'somedata'

Perhaps it's good to reach out to LOBSTER team about this? Or at least we could enhance related parsers from our side to be insensitive of such terminating chars :)

DanielYang59 avatar Dec 22 '24 13:12 DanielYang59

@naik-aakash maybe (after the Christmas break 👀), you can regenerate a cohpcar with the latest Lobster version. Then, we can check this in detail

JaGeo avatar Dec 22 '24 13:12 JaGeo

I just had a chance to generate a COHPCAR.lobster using LOBSTER 5.1.1, with the included VASP "diamond" example. As far as I can tell there's no line ending char to the last line.

COHPCAR.lobster.txt

DanielYang59 avatar Feb 11 '25 09:02 DanielYang59