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

Fix lattice velocities formatting #3433

Merged
merged 6 commits into from
Oct 31, 2023
Merged

Conversation

gpetretto
Copy link
Contributor

Summary

This PR fixes a problem in #3428 that I encountered while performing some more tests with NpT MD simulations: in the case of lattice velocities VASP seems to be strict in the format when reading the POSCAR. After some tests it seems that this should be the best format to allow the correct parsing of this quantity in VASP.

Sorry for the error in the previous PR.

@@ -545,7 +547,8 @@ def get_str(self, direct: bool = True, vasp4_compatible: bool = False, significa
lines.append("Lattice velocities and vectors")
lines.append(" 1")
for v in self.lattice_velocities:
lines.append(" ".join(format_str.format(i) for i in v))
# vasp is strict about the format when reading this quantity
lines.append(" ".join(f" {i: .7E}" for i in v))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If VASP is strict about this, could you add a test that checks for the right float precision?

@janosh janosh added io Input/output functionality fix Bug fix PRs vasp Vienna Ab initio Simulation Package md Molecular dynamics needs testing PRs that are not ready to merge due to lacking tests labels Oct 30, 2023
@gpetretto
Copy link
Contributor Author

Hi @janosh, I added a check on the format of the produced POSCAR. It should be noted that in this case it just checks that the format is equivalent to the one written from the Poscar object. This seems to be the only option that is correctly parsed by VASP, even though it is not exactly equilant to what is produced by fortran, since in the scientific notation python has a number >0 as the first digit, while the floats written from fortran start with a 0.
This will prevent regressions, but does not strictly check the correctness of the format. I have found one library that reproduces the i/o operations as done in fortran: https://github.com/brendanarnold/py-fortranformat. This would provide a more stringent test, but I suppose it might not be worth to add this as a dependency (even though only for dev) just for this.

@janosh janosh removed the needs testing PRs that are not ready to merge due to lacking tests label Oct 31, 2023
Copy link
Member

@janosh janosh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gpetretto! 👍

@janosh janosh enabled auto-merge (squash) October 31, 2023 13:43
@janosh janosh merged commit eee88ab into materialsproject:master Oct 31, 2023
21 checks passed
@gpetretto gpetretto deleted the develop branch November 30, 2023 16:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PRs io Input/output functionality md Molecular dynamics vasp Vienna Ab initio Simulation Package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants