From 72f398d57cc9e0cd0ae18477895d007bc059577c Mon Sep 17 00:00:00 2001 From: Mancn Date: Thu, 28 Dec 2023 11:50:31 +0800 Subject: [PATCH 1/2] Enhance poscar_scale function to detect Selective dynamics --- dpgen/data/gen.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 27134ef64..934d6b4ad 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -237,16 +237,27 @@ def poscar_scale_cartesian(str_in, scale): def poscar_scale(poscar_in, poscar_out, scale): with open(poscar_in) as fin: lines = list(fin) - if "D" == lines[7][0] or "d" == lines[7][0]: + + # Determine if "Selective dynamics" is present + 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 + + # Process according to the coordinate type + if "D" == lines[coord_type_line][0] or "d" == lines[coord_type_line][0]: lines = poscar_scale_direct(lines, scale) - elif "C" == lines[7][0] or "c" == lines[7][0]: + elif "C" == lines[coord_type_line][0] or "c" == lines[coord_type_line][0]: lines = poscar_scale_cartesian(lines, scale) else: - raise RuntimeError("Unknow poscar style at line 7: %s" % lines[7]) + raise RuntimeError(f"Unknown poscar style at line {coord_type_line + 1}: {lines[coord_type_line]}") + + # 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 From 0c93fe3bf97d613816691652ba63de972fbf44de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 28 Dec 2023 06:37:45 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpgen/data/gen.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/dpgen/data/gen.py b/dpgen/data/gen.py index 934d6b4ad..003e7fda8 100644 --- a/dpgen/data/gen.py +++ b/dpgen/data/gen.py @@ -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 @@ -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]}" + ) # 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