Skip to content

Commit

Permalink
abacus: fix bug in collecting force (#669)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **Bug Fixes**
- Modified force data handling in computational simulations to return
`None` instead of an empty list when no forces are present.

- **Tests**
- Added new test scenarios to validate force data handling in labeled
system objects for computational simulations.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Jinzhe Zeng <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Jinzhe Zeng <[email protected]>
  • Loading branch information
3 people authored Jul 2, 2024
1 parent fb85312 commit e429d9a
Show file tree
Hide file tree
Showing 4 changed files with 596 additions and 2 deletions.
4 changes: 2 additions & 2 deletions dpdata/abacus/scf.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def collect_force(outlines):
def get_force(outlines, natoms):
force = collect_force(outlines)
if len(force) == 0:
return [[]]
return None
else:
return np.array(force[-1]) # only return the last force

Expand Down Expand Up @@ -285,7 +285,7 @@ def get_frame(fname):
data["cells"] = cell[np.newaxis, :, :]
data["coords"] = coords[np.newaxis, :, :]
data["energies"] = np.array(energy)[np.newaxis]
data["forces"] = force[np.newaxis, :, :]
data["forces"] = np.empty((0,)) if force is None else force[np.newaxis, :, :]
if stress is not None:
data["virials"] = stress[np.newaxis, :, :]
data["orig"] = np.zeros(3)
Expand Down
17 changes: 17 additions & 0 deletions tests/abacus.scf/INPUT.ch4-noforcestress
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
INPUT_PARAMETERS
#Parameters (General)
suffix ch4-noForceStress
stru_file STRU.ch4 #the filename of file containing atom positions
kpoint_file KPT.ch4 #the name of file containing k points
pseudo_dir ./
nbands 8
#Parameters (Accuracy)
ecutwfc 100
symmetry 1
scf_nmax 50
smearing_method gauss #type of smearing: gauss; fd; fixed; mp; mp2; mv
smearing_sigma 0.01
mixing_type plain
mixing_beta 0.5
cal_force 1
cal_stress 1
Loading

0 comments on commit e429d9a

Please sign in to comment.