Skip to content

Commit

Permalink
merge devel to master to release v0.2.23 (#794)
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

- **Chores**
  - Upgraded the pre-commit configuration to improve code quality.

- **New Features**
- Introduced robust parsing and generation for simulation structure
files, enhancing the reliability of data extraction.

- **Refactor**
- Streamlined the processing of structural and atomic information,
resulting in clearer error messages and more consistent output.

- **Tests**
- Optimized file management during test setups and teardowns to ensure
reliable handling of simulation files.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
njzjz authored Feb 14, 2025
2 parents 5b7af6f + bd42e6a commit 35a0af0
Show file tree
Hide file tree
Showing 9 changed files with 882 additions and 769 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ repos:
# Python
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.9.2
rev: v0.9.6
hooks:
- id: ruff
args: ["--fix"]
Expand Down
25 changes: 11 additions & 14 deletions dpdata/abacus/md.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@

from .scf import (
bohr2ang,
get_cell,
get_coords,
get_geometry_in,
get_mag_force,
kbar2evperang3,
)
from .stru import get_frame_from_stru

# Read in geometries from an ABACUS MD trajectory.
# The atomic coordinates are read in from generated files in OUT.XXXX.
Expand Down Expand Up @@ -164,12 +163,12 @@ def get_frame(fname):
geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
path_out = get_path_out(fname, inlines)

with open_file(geometry_path_in) as fp:
geometry_inlines = fp.read().split("\n")
celldm, cell = get_cell(geometry_inlines)
atom_names, natoms, types, coords, move, magmom = get_coords(
celldm, cell, geometry_inlines, inlines
)
data = get_frame_from_stru(geometry_path_in)
natoms = data["atom_numbs"]
# should remove spins from STRU file
if "spins" in data:
data.pop("spins")

# This coords is not to be used.
dump_freq = get_coord_dump_freq(inlines=inlines)
# ndump = int(os.popen("ls -l %s | grep 'md_pos_' | wc -l" %path_out).readlines()[0])
Expand Down Expand Up @@ -203,10 +202,6 @@ def get_frame(fname):

magmom, magforce = get_mag_force(outlines)

data = {}
data["atom_names"] = atom_names
data["atom_numbs"] = natoms
data["atom_types"] = types
data["cells"] = cells
# for idx in range(ndump):
# data['cells'][:, :, :] = cell
Expand All @@ -221,7 +216,9 @@ def get_frame(fname):
data["spins"] = magmom
if len(magforce) > 0:
data["force_mags"] = magforce
if len(move) > 0:
data["move"] = move

# need to expand the move.
if "move" in data:
data["move"] = [data["move"][0] for i in range(ndump)]

return data
32 changes: 11 additions & 21 deletions dpdata/abacus/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
bohr2ang,
collect_force,
collect_stress,
get_cell,
get_coords,
get_geometry_in,
get_mag_force,
kbar2evperang3,
)
from .stru import get_frame_from_stru

# Read in geometries from an ABACUS RELAX(CELL-RELAX) trajectory in OUT.XXXX/runnning_relax/cell-relax.log.

Expand Down Expand Up @@ -47,7 +46,7 @@ def get_coords_from_log(loglines, natoms):
natoms_log += int(line.split()[-1])

assert natoms_log > 0 and natoms_log == natoms, (
"ERROR: detected atom number in log file is %d" % natoms # noqa: UP031
f"ERROR: detected atom number in log file is {natoms_log}, while the atom number in STRU file is {natoms}"
)

energy = []
Expand Down Expand Up @@ -180,31 +179,22 @@ def get_frame(fname):
with open_file(path_in) as fp:
inlines = fp.read().split("\n")
geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
with open_file(geometry_path_in) as fp:
geometry_inlines = fp.read().split("\n")
celldm, cell = get_cell(geometry_inlines)
atom_names, natoms, types, coord_tmp, move, magmom = get_coords(
celldm, cell, geometry_inlines, inlines
)

data = get_frame_from_stru(geometry_path_in)
natoms = sum(data["atom_numbs"])
# should remove spins from STRU file
if "spins" in data:
data.pop("spins")

logf = get_log_file(fname, inlines)
assert os.path.isfile(logf), f"Error: can not find {logf}"
with open_file(logf) as f1:
lines = f1.readlines()

atomnumber = 0
for i in natoms:
atomnumber += i
energy, cells, coords, force, stress, virial = get_coords_from_log(
lines, atomnumber
)
energy, cells, coords, force, stress, virial = get_coords_from_log(lines, natoms)

magmom, magforce = get_mag_force(lines)

data = {}
data["atom_names"] = atom_names
data["atom_numbs"] = natoms
data["atom_types"] = types
data["cells"] = cells
data["coords"] = coords
data["energies"] = energy
Expand All @@ -218,7 +208,7 @@ def get_frame(fname):
data["spins"] = magmom
if len(magforce) > 0:
data["force_mags"] = magforce
if len(move) > 0:
data["move"] = move
if "move" in data:
data["move"] = [data["move"][0] for i in range(len(data["energies"]))]

return data
Loading

0 comments on commit 35a0af0

Please sign in to comment.