From 7a4ec3610d2b540f4c0f2e0c2ef73892c93ddf00 Mon Sep 17 00:00:00 2001 From: Jinzhe Zeng Date: Sun, 28 Apr 2024 03:56:04 -0400 Subject: [PATCH] fix: fix invalid escape sequence Fix the warning below: ``` ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:6 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:6: DeprecationWarning: invalid escape sequence '\|' latt_patt = "\|\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)" ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:7 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:7: DeprecationWarning: invalid escape sequence '\|' pos_patt_first = "\|\s+[0-9]{1,}[:]\s\w+\s(\w+)(\s.*[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)" ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:8 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:8: DeprecationWarning: invalid escape sequence '\s' pos_patt_other = "\s+[a][t][o][m]\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+(\w{1,2})" ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:9 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:9: DeprecationWarning: invalid escape sequence '\|' force_patt = "\|\s+[0-9]{1,}\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})" ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:10 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/fhi_aims/output.py:10: DeprecationWarning: invalid escape sequence '\s' eng_patt = "Total energy uncorrected.*([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+eV" ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:41 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:41: DeprecationWarning: invalid escape sequence '\s' while len(re.split("\s+", lines[blk_idx])) == 0: ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:44 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:44: DeprecationWarning: invalid escape sequence '\s' if len(re.split("\s+", lines[blk_idx])) == 0 or lines[blk_idx] == "": ../../../../../opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:332 /opt/hostedtoolcache/Python/3.11.9/x64/lib/python3.11/site-packages/dpdata/abacus/scf.py:332: DeprecationWarning: invalid escape sequence '\s' if len(re.split("\s+", geometry_inlines[iline])) >= 3: ``` --- dpdata/abacus/scf.py | 6 +++--- dpdata/fhi_aims/output.py | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/dpdata/abacus/scf.py b/dpdata/abacus/scf.py index 975ef539..966410d6 100644 --- a/dpdata/abacus/scf.py +++ b/dpdata/abacus/scf.py @@ -38,10 +38,10 @@ def get_block(lines, keyword, skip=0, nlines=None): found = True blk_idx = idx + 1 + skip line_idx = 0 - while len(re.split("\s+", lines[blk_idx])) == 0: + while len(re.split(r"\s+", lines[blk_idx])) == 0: blk_idx += 1 while line_idx < nlines and blk_idx != len(lines): - if len(re.split("\s+", lines[blk_idx])) == 0 or lines[blk_idx] == "": + if len(re.split(r"\s+", lines[blk_idx])) == 0 or lines[blk_idx] == "": blk_idx += 1 continue ret.append(lines[blk_idx]) @@ -329,7 +329,7 @@ def get_nele_from_stru(geometry_inlines): for iline in range( keyword_line_index[idx] + 1, keyword_line_index[idx + 1] ): - if len(re.split("\s+", geometry_inlines[iline])) >= 3: + if len(re.split(r"\s+", geometry_inlines[iline])) >= 3: nele += 1 return nele diff --git a/dpdata/fhi_aims/output.py b/dpdata/fhi_aims/output.py index c4cd9257..9947a231 100755 --- a/dpdata/fhi_aims/output.py +++ b/dpdata/fhi_aims/output.py @@ -3,12 +3,12 @@ import numpy as np -latt_patt = "\|\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)" -pos_patt_first = "\|\s+[0-9]{1,}[:]\s\w+\s(\w+)(\s.*[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)" -pos_patt_other = "\s+[a][t][o][m]\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+(\w{1,2})" -force_patt = "\|\s+[0-9]{1,}\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})" -eng_patt = "Total energy uncorrected.*([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+eV" -# atom_numb_patt="Number of atoms.*([0-9]{1,})" +latt_patt = r"\|\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)\s+([0-9]{1,}[.][0-9]*)" +pos_patt_first = r"\|\s+[0-9]{1,}[:]\s\w+\s(\w+)(\s.*[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)(\s+[-]?[0-9]{1,}[.][0-9]*)" +pos_patt_other = r"\s+[a][t][o][m]\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+([-]?[0-9]{1,}[.][0-9]*)\s+(\w{1,2})" +force_patt = r"\|\s+[0-9]{1,}\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})" +eng_patt = r"Total energy uncorrected.*([-]?[0-9]{1,}[.][0-9]*[E][+-][0-9]{1,})\s+eV" +# atom_numb_patt=r"Number of atoms.*([0-9]{1,})" debug = False