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

Robustness of Poscar parser should be further improved #3666

Closed
Andrew-S-Rosen opened this issue Mar 2, 2024 · 4 comments
Closed

Robustness of Poscar parser should be further improved #3666

Andrew-S-Rosen opened this issue Mar 2, 2024 · 4 comments
Labels

Comments

@Andrew-S-Rosen
Copy link
Member

Andrew-S-Rosen commented Mar 2, 2024

Python version

3.9+

Pymatgen version

2024.3.1

Operating system version

No response

Current behavior

When using the various Pymatgen input parsing utilities on the POSCAR below, a BadPoscarWarning is raised even though it is seemingly valid. I've drilled down to the root cause below.

Expected Behavior

A valid parse.

Minimal example

from pymatgen.io.vasp.inputs import Poscar

poscar_text = """
Lu3
1.0
8.212068 -1.711729 -0.004637
8.212068 1.711729 -0.004637
7.856937 -0.000000 2.938818
Lu
3
direct
0.000000 0.000000 -0.000000 Lu
0.221900 0.221900 0.221900 Lu
0.778100 0.778100 0.778100 Lu
"""

Poscar.from_str(poscar_text)

Reports:

ValueError: could not convert string to float: 'Lu3'

Relevant files to reproduce this bug

No response

@Andrew-S-Rosen Andrew-S-Rosen changed the title BadPoscarWarning reported on valid POSCAR Robustness of Poscar parser could be further improved Mar 2, 2024
@Andrew-S-Rosen Andrew-S-Rosen changed the title Robustness of Poscar parser could be further improved Robustness of Poscar parser should be further improved Mar 3, 2024
@DanielYang59
Copy link
Contributor

DanielYang59 commented Mar 4, 2024

It seems you started with an empty first line, which should be the comment line. And therefore the Lu3 line is treated as the scaling factor line thus the error.

This should work:

from pymatgen.io.vasp.inputs import Poscar

poscar_text = """Lu3
1.0
8.212068 -1.711729 -0.004637
8.212068 1.711729 -0.004637
7.856937 -0.000000 2.938818
Lu
3
direct
0.000000 0.000000 -0.000000 Lu
0.221900 0.221900 0.221900 Lu
0.778100 0.778100 0.778100 Lu
"""

Poscar.from_str(poscar_text)

@Andrew-S-Rosen
Copy link
Member Author

Thank you, @DanielYang59. Apologies about the false report here! I was trying to track down a BadPoscarWarning, and it seems like this was a false flag. I'll close this issue until I can find the actual source of the problem. In hindsight, I think the source of my issue was likely some file ending issue when transferring files between Windows/Linux.

@Andrew-S-Rosen Andrew-S-Rosen closed this as not planned Won't fix, can't repro, duplicate, stale Mar 4, 2024
@DanielYang59
Copy link
Contributor

DanielYang59 commented Mar 5, 2024

No worries at all. Not sure if you mean #3662 (to which I confessed...). I tried to run your code on my MacOS machine and didn't notice any BadPoscarWarning.

Maybe you can try git config --global core.autocrlf input to automatically handle file ending as described here? Not sure if this would be helpful though.

This setup should leave you with CRLF endings in Windows checkouts, but LF endings on macOS and Linux systems and in the repository.

@Andrew-S-Rosen
Copy link
Member Author

Nah, what I mean is I transferred a POSCAR from my Linux machine to Windows (or vice versa) and imagine that this probably was potentially the root cause of my problem. In any case, it's all good!

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

No branches or pull requests

2 participants