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

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

Open
DanielYang59 opened this issue Dec 4, 2024 · 10 comments

Comments

@DanielYang59
Copy link
Contributor

DanielYang59 commented Dec 4, 2024

Two LOBSTER examples in matgenb seems to be failing:

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

@JaGeo
Copy link
Member

JaGeo commented Dec 4, 2024

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

@DanielYang59
Copy link
Contributor Author

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

@JaGeo
Copy link
Member

JaGeo commented Dec 4, 2024

@naik-aakash could you take a look?

@JaGeo
Copy link
Member

JaGeo commented Dec 4, 2024

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.

@QuantumChemist
Copy link
Contributor

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

@naik-aakash
Copy link
Contributor

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

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Dec 4, 2024

@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 :)

@naik-aakash
Copy link
Contributor

naik-aakash commented Dec 22, 2024

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

@DanielYang59
Copy link
Contributor Author

DanielYang59 commented Dec 22, 2024

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 :)

@JaGeo
Copy link
Member

JaGeo commented Dec 22, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants