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

Enhance poscar_scale function (/data/gen.py)to detect Selective dynamics #1439

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 28, 2023
commit 0c93fe3bf97d613816691652ba63de972fbf44de
9 changes: 5 additions & 4 deletions dpgen/data/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def poscar_scale_cartesian(str_in, scale):
def poscar_scale(poscar_in, poscar_out, scale):
with open(poscar_in) as fin:
lines = list(fin)

# Determine if "Selective dynamics" is present
if lines[7].strip().lower().startswith('s'):
if lines[7].strip().lower().startswith("s"):
coord_type_line = 8 # If present, coordinates type is on line 9
else:
coord_type_line = 7 # If not, coordinates type is on line 8
Expand All @@ -250,14 +250,15 @@ def poscar_scale(poscar_in, poscar_out, scale):
elif "C" == lines[coord_type_line][0] or "c" == lines[coord_type_line][0]:
lines = poscar_scale_cartesian(lines, scale)
else:
raise RuntimeError(f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}")
raise RuntimeError(
f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}"
)
Comment on lines +253 to +255

Choose a reason for hiding this comment

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

Suggestion: The error message in the RuntimeError could be more informative by specifying that the unknown style is related to the coordinate type. [enhancement]

Suggested change
raise RuntimeError(
f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}"
)
raise RuntimeError(
f"Unknown coordinate type at line {coord_type_line + 1}: {lines[coord_type_line]}"
)

Copy link
Member

Choose a reason for hiding this comment

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

So, is it poscar style or coordinate type?


# Write scaled positions back to output file
with open(poscar_out, "w") as fout:
fout.write("".join(lines))



def poscar_scale_abacus(poscar_in, poscar_out, scale, jdata):
stru = get_abacus_STRU(poscar_in)
stru["cells"] *= scale
Expand Down