From cd077da2e1fb645211054e5b65510e462093cf5c Mon Sep 17 00:00:00 2001 From: pee8379 Date: Mon, 3 Apr 2023 00:12:48 +0900 Subject: [PATCH 1/2] Update for qe v7.2 From QE v7.2, pw.x prints each contributions to forces acting on atoms (i.e. non-local, ionic, local, core correction, etc...), right after original 'Forces acting on atoms' without blank line. Thus, it make 'list index out of range' error, from ret.append(...) in get_force. This changes make length of list blk in get_forces same as total number of atoms, avoiding out of range error. Signed-off-by: pee8379 --- dpdata/qe/scf.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/dpdata/qe/scf.py b/dpdata/qe/scf.py index f78be7cb..e51e2837 100755 --- a/dpdata/qe/scf.py +++ b/dpdata/qe/scf.py @@ -107,9 +107,10 @@ def get_energy(lines): return energy -def get_force(lines): +def get_force(lines, natoms): blk = get_block(lines, "Forces acting on atoms", skip=1) ret = [] + blk = blk[0:sum(natoms)] for ii in blk: ret.append([float(jj) for jj in ii.split("=")[1].split()]) ret = np.array(ret) @@ -146,7 +147,7 @@ def get_frame(fname): cell = get_cell(inlines) atom_names, natoms, types, coords = get_coords(inlines, cell) energy = get_energy(outlines) - force = get_force(outlines) + force = get_force (outlines, natoms) stress = get_stress(outlines) * np.linalg.det(cell) return ( atom_names, From b4379771022bd56e6aeb1cededd453c2eacb9f2c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Apr 2023 15:13:54 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- dpdata/qe/scf.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dpdata/qe/scf.py b/dpdata/qe/scf.py index e51e2837..72202358 100755 --- a/dpdata/qe/scf.py +++ b/dpdata/qe/scf.py @@ -110,7 +110,7 @@ def get_energy(lines): def get_force(lines, natoms): blk = get_block(lines, "Forces acting on atoms", skip=1) ret = [] - blk = blk[0:sum(natoms)] + blk = blk[0 : sum(natoms)] for ii in blk: ret.append([float(jj) for jj in ii.split("=")[1].split()]) ret = np.array(ret) @@ -147,7 +147,7 @@ def get_frame(fname): cell = get_cell(inlines) atom_names, natoms, types, coords = get_coords(inlines, cell) energy = get_energy(outlines) - force = get_force (outlines, natoms) + force = get_force(outlines, natoms) stress = get_stress(outlines) * np.linalg.det(cell) return ( atom_names,