dpdata 0.2.22__tar.gz → 0.2.24__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (136) hide show
  1. {dpdata-0.2.22 → dpdata-0.2.24}/.pre-commit-config.yaml +1 -1
  2. {dpdata-0.2.22 → dpdata-0.2.24}/PKG-INFO +3 -2
  3. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/_version.py +9 -4
  4. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/abacus/md.py +11 -14
  5. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/abacus/relax.py +11 -21
  6. dpdata-0.2.24/dpdata/abacus/scf.py +250 -0
  7. dpdata-0.2.22/dpdata/abacus/scf.py → dpdata-0.2.24/dpdata/abacus/stru.py +248 -373
  8. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/abacus.py +3 -2
  9. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/system.py +1 -3
  10. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/PKG-INFO +3 -2
  11. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/SOURCES.txt +1 -0
  12. {dpdata-0.2.22 → dpdata-0.2.24}/.git-blame-ignore-revs +0 -0
  13. {dpdata-0.2.22 → dpdata-0.2.24}/.git_archival.txt +0 -0
  14. {dpdata-0.2.22 → dpdata-0.2.24}/.gitattributes +0 -0
  15. {dpdata-0.2.22 → dpdata-0.2.24}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  16. {dpdata-0.2.22 → dpdata-0.2.24}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  17. {dpdata-0.2.22 → dpdata-0.2.24}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  18. {dpdata-0.2.22 → dpdata-0.2.24}/.github/ISSUE_TEMPLATE/generic-issue.yml +0 -0
  19. {dpdata-0.2.22 → dpdata-0.2.24}/.github/dependabot.yml +0 -0
  20. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/benchmark.yml +0 -0
  21. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/mirror_gitee.yml +0 -0
  22. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/pub-pypi.yml +0 -0
  23. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/pyright.yml +0 -0
  24. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/test.yml +0 -0
  25. {dpdata-0.2.22 → dpdata-0.2.24}/.github/workflows/test_import.yml +0 -0
  26. {dpdata-0.2.22 → dpdata-0.2.24}/.gitignore +0 -0
  27. {dpdata-0.2.22 → dpdata-0.2.24}/.readthedocs.yaml +0 -0
  28. {dpdata-0.2.22 → dpdata-0.2.24}/LICENSE +0 -0
  29. {dpdata-0.2.22 → dpdata-0.2.24}/MANIFEST.in +0 -0
  30. {dpdata-0.2.22 → dpdata-0.2.24}/README.md +0 -0
  31. {dpdata-0.2.22 → dpdata-0.2.24}/benchmark/__init__.py +0 -0
  32. {dpdata-0.2.22 → dpdata-0.2.24}/benchmark/test_import.py +0 -0
  33. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/__about__.py +0 -0
  34. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/__init__.py +0 -0
  35. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/__main__.py +0 -0
  36. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/abacus/__init__.py +0 -0
  37. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/amber/__init__.py +0 -0
  38. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/amber/mask.py +0 -0
  39. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/amber/md.py +0 -0
  40. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/amber/sqm.py +0 -0
  41. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/ase_calculator.py +0 -0
  42. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/bond_order_system.py +0 -0
  43. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/cli.py +0 -0
  44. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/cp2k/__init__.py +0 -0
  45. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/cp2k/cell.py +0 -0
  46. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/cp2k/output.py +0 -0
  47. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/data_type.py +0 -0
  48. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/deepmd/__init__.py +0 -0
  49. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/deepmd/comp.py +0 -0
  50. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/deepmd/hdf5.py +0 -0
  51. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/deepmd/mixed.py +0 -0
  52. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/deepmd/raw.py +0 -0
  53. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/dftbplus/__init__.py +0 -0
  54. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/dftbplus/output.py +0 -0
  55. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/driver.py +0 -0
  56. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/fhi_aims/__init__.py +0 -0
  57. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/fhi_aims/output.py +0 -0
  58. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/format.py +0 -0
  59. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/gaussian/__init__.py +0 -0
  60. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/gaussian/gjf.py +0 -0
  61. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/gaussian/log.py +0 -0
  62. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/gromacs/__init__.py +0 -0
  63. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/gromacs/gro.py +0 -0
  64. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/lammps/__init__.py +0 -0
  65. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/lammps/dump.py +0 -0
  66. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/lammps/lmp.py +0 -0
  67. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/md/__init__.py +0 -0
  68. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/md/msd.py +0 -0
  69. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/md/pbc.py +0 -0
  70. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/md/rdf.py +0 -0
  71. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/md/water.py +0 -0
  72. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/openmx/__init__.py +0 -0
  73. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/openmx/omx.py +0 -0
  74. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/orca/__init__.py +0 -0
  75. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/orca/output.py +0 -0
  76. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/periodic_table.json +0 -0
  77. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/periodic_table.py +0 -0
  78. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugin.py +0 -0
  79. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/3dmol.py +0 -0
  80. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/__init__.py +0 -0
  81. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/amber.py +0 -0
  82. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/ase.py +0 -0
  83. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/cp2k.py +0 -0
  84. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/deepmd.py +0 -0
  85. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/dftbplus.py +0 -0
  86. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/fhi_aims.py +0 -0
  87. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/gaussian.py +0 -0
  88. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/gromacs.py +0 -0
  89. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/lammps.py +0 -0
  90. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/list.py +0 -0
  91. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/n2p2.py +0 -0
  92. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/openmx.py +0 -0
  93. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/orca.py +0 -0
  94. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/psi4.py +0 -0
  95. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/pwmat.py +0 -0
  96. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/pymatgen.py +0 -0
  97. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/qe.py +0 -0
  98. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/rdkit.py +0 -0
  99. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/siesta.py +0 -0
  100. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/vasp.py +0 -0
  101. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/plugins/xyz.py +0 -0
  102. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/psi4/__init__.py +0 -0
  103. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/psi4/input.py +0 -0
  104. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/psi4/output.py +0 -0
  105. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pwmat/__init__.py +0 -0
  106. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pwmat/atomconfig.py +0 -0
  107. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pwmat/movement.py +0 -0
  108. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/py.typed +0 -0
  109. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pymatgen/__init__.py +0 -0
  110. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pymatgen/molecule.py +0 -0
  111. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/pymatgen/structure.py +0 -0
  112. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/qe/__init__.py +0 -0
  113. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/qe/scf.py +0 -0
  114. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/qe/traj.py +0 -0
  115. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/rdkit/__init__.py +0 -0
  116. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/rdkit/sanitize.py +0 -0
  117. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/rdkit/utils.py +0 -0
  118. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/siesta/__init__.py +0 -0
  119. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/siesta/aiMD_output.py +0 -0
  120. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/siesta/output.py +0 -0
  121. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/stat.py +0 -0
  122. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/unit.py +0 -0
  123. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/utils.py +0 -0
  124. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/vasp/__init__.py +0 -0
  125. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/vasp/outcar.py +0 -0
  126. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/vasp/poscar.py +0 -0
  127. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/vasp/xml.py +0 -0
  128. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/xyz/__init__.py +0 -0
  129. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/xyz/quip_gap_xyz.py +0 -0
  130. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata/xyz/xyz.py +0 -0
  131. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/dependency_links.txt +0 -0
  132. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/entry_points.txt +0 -0
  133. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/requires.txt +0 -0
  134. {dpdata-0.2.22 → dpdata-0.2.24}/dpdata.egg-info/top_level.txt +0 -0
  135. {dpdata-0.2.22 → dpdata-0.2.24}/pyproject.toml +0 -0
  136. {dpdata-0.2.22 → dpdata-0.2.24}/setup.cfg +0 -0
@@ -21,7 +21,7 @@ repos:
21
21
  # Python
22
22
  - repo: https://github.com/astral-sh/ruff-pre-commit
23
23
  # Ruff version.
24
- rev: v0.9.2
24
+ rev: v0.11.0
25
25
  hooks:
26
26
  - id: ruff
27
27
  args: ["--fix"]
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: dpdata
3
- Version: 0.2.22
3
+ Version: 0.2.24
4
4
  Summary: Manipulating data formats of DeePMD-kit, VASP, QE, PWmat, and LAMMPS, etc.
5
5
  Author: DeepModeling
6
6
  Author-email: Han Wang <wang_han@iapcm.ac.cn>
@@ -211,6 +211,7 @@ Requires-Dist: jupyterlite-xeus; extra == "docs"
211
211
  Provides-Extra: benchmark
212
212
  Requires-Dist: pytest; extra == "benchmark"
213
213
  Requires-Dist: pytest-codspeed; extra == "benchmark"
214
+ Dynamic: license-file
214
215
 
215
216
  # dpdata
216
217
 
@@ -1,8 +1,13 @@
1
- # file generated by setuptools_scm
1
+ # file generated by setuptools-scm
2
2
  # don't change, don't track in version control
3
+
4
+ __all__ = ["__version__", "__version_tuple__", "version", "version_tuple"]
5
+
3
6
  TYPE_CHECKING = False
4
7
  if TYPE_CHECKING:
5
- from typing import Tuple, Union
8
+ from typing import Tuple
9
+ from typing import Union
10
+
6
11
  VERSION_TUPLE = Tuple[Union[int, str], ...]
7
12
  else:
8
13
  VERSION_TUPLE = object
@@ -12,5 +17,5 @@ __version__: str
12
17
  __version_tuple__: VERSION_TUPLE
13
18
  version_tuple: VERSION_TUPLE
14
19
 
15
- __version__ = version = '0.2.22'
16
- __version_tuple__ = version_tuple = (0, 2, 22)
20
+ __version__ = version = '0.2.24'
21
+ __version_tuple__ = version_tuple = (0, 2, 24)
@@ -9,12 +9,11 @@ from dpdata.utils import open_file
9
9
 
10
10
  from .scf import (
11
11
  bohr2ang,
12
- get_cell,
13
- get_coords,
14
12
  get_geometry_in,
15
13
  get_mag_force,
16
14
  kbar2evperang3,
17
15
  )
16
+ from .stru import get_frame_from_stru
18
17
 
19
18
  # Read in geometries from an ABACUS MD trajectory.
20
19
  # The atomic coordinates are read in from generated files in OUT.XXXX.
@@ -164,12 +163,12 @@ def get_frame(fname):
164
163
  geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
165
164
  path_out = get_path_out(fname, inlines)
166
165
 
167
- with open_file(geometry_path_in) as fp:
168
- geometry_inlines = fp.read().split("\n")
169
- celldm, cell = get_cell(geometry_inlines)
170
- atom_names, natoms, types, coords, move, magmom = get_coords(
171
- celldm, cell, geometry_inlines, inlines
172
- )
166
+ data = get_frame_from_stru(geometry_path_in)
167
+ natoms = data["atom_numbs"]
168
+ # should remove spins from STRU file
169
+ if "spins" in data:
170
+ data.pop("spins")
171
+
173
172
  # This coords is not to be used.
174
173
  dump_freq = get_coord_dump_freq(inlines=inlines)
175
174
  # ndump = int(os.popen("ls -l %s | grep 'md_pos_' | wc -l" %path_out).readlines()[0])
@@ -203,10 +202,6 @@ def get_frame(fname):
203
202
 
204
203
  magmom, magforce = get_mag_force(outlines)
205
204
 
206
- data = {}
207
- data["atom_names"] = atom_names
208
- data["atom_numbs"] = natoms
209
- data["atom_types"] = types
210
205
  data["cells"] = cells
211
206
  # for idx in range(ndump):
212
207
  # data['cells'][:, :, :] = cell
@@ -221,7 +216,9 @@ def get_frame(fname):
221
216
  data["spins"] = magmom
222
217
  if len(magforce) > 0:
223
218
  data["force_mags"] = magforce
224
- if len(move) > 0:
225
- data["move"] = move
219
+
220
+ # need to expand the move.
221
+ if "move" in data:
222
+ data["move"] = [data["move"][0] for i in range(ndump)]
226
223
 
227
224
  return data
@@ -10,12 +10,11 @@ from .scf import (
10
10
  bohr2ang,
11
11
  collect_force,
12
12
  collect_stress,
13
- get_cell,
14
- get_coords,
15
13
  get_geometry_in,
16
14
  get_mag_force,
17
15
  kbar2evperang3,
18
16
  )
17
+ from .stru import get_frame_from_stru
19
18
 
20
19
  # Read in geometries from an ABACUS RELAX(CELL-RELAX) trajectory in OUT.XXXX/runnning_relax/cell-relax.log.
21
20
 
@@ -47,7 +46,7 @@ def get_coords_from_log(loglines, natoms):
47
46
  natoms_log += int(line.split()[-1])
48
47
 
49
48
  assert natoms_log > 0 and natoms_log == natoms, (
50
- "ERROR: detected atom number in log file is %d" % natoms # noqa: UP031
49
+ f"ERROR: detected atom number in log file is {natoms_log}, while the atom number in STRU file is {natoms}"
51
50
  )
52
51
 
53
52
  energy = []
@@ -180,31 +179,22 @@ def get_frame(fname):
180
179
  with open_file(path_in) as fp:
181
180
  inlines = fp.read().split("\n")
182
181
  geometry_path_in = get_geometry_in(fname, inlines) # base dir of STRU
183
- with open_file(geometry_path_in) as fp:
184
- geometry_inlines = fp.read().split("\n")
185
- celldm, cell = get_cell(geometry_inlines)
186
- atom_names, natoms, types, coord_tmp, move, magmom = get_coords(
187
- celldm, cell, geometry_inlines, inlines
188
- )
182
+
183
+ data = get_frame_from_stru(geometry_path_in)
184
+ natoms = sum(data["atom_numbs"])
185
+ # should remove spins from STRU file
186
+ if "spins" in data:
187
+ data.pop("spins")
189
188
 
190
189
  logf = get_log_file(fname, inlines)
191
190
  assert os.path.isfile(logf), f"Error: can not find {logf}"
192
191
  with open_file(logf) as f1:
193
192
  lines = f1.readlines()
194
193
 
195
- atomnumber = 0
196
- for i in natoms:
197
- atomnumber += i
198
- energy, cells, coords, force, stress, virial = get_coords_from_log(
199
- lines, atomnumber
200
- )
194
+ energy, cells, coords, force, stress, virial = get_coords_from_log(lines, natoms)
201
195
 
202
196
  magmom, magforce = get_mag_force(lines)
203
197
 
204
- data = {}
205
- data["atom_names"] = atom_names
206
- data["atom_numbs"] = natoms
207
- data["atom_types"] = types
208
198
  data["cells"] = cells
209
199
  data["coords"] = coords
210
200
  data["energies"] = energy
@@ -218,7 +208,7 @@ def get_frame(fname):
218
208
  data["spins"] = magmom
219
209
  if len(magforce) > 0:
220
210
  data["force_mags"] = magforce
221
- if len(move) > 0:
222
- data["move"] = move
211
+ if "move" in data:
212
+ data["move"] = [data["move"][0] for i in range(len(data["energies"]))]
223
213
 
224
214
  return data
@@ -0,0 +1,250 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+ import re
5
+ import warnings
6
+
7
+ import numpy as np
8
+
9
+ from dpdata.utils import open_file
10
+
11
+ from ..unit import LengthConversion, PressureConversion
12
+ from .stru import get_frame_from_stru
13
+
14
+ bohr2ang = LengthConversion("bohr", "angstrom").value()
15
+ kbar2evperang3 = PressureConversion("kbar", "eV/angstrom^3").value()
16
+
17
+
18
+ def CheckFile(ifile):
19
+ if not os.path.isfile(ifile):
20
+ print(f"Can not find file {ifile}")
21
+ return False
22
+ return True
23
+
24
+
25
+ def get_geometry_in(fname, inlines):
26
+ geometry_path_in = os.path.join(fname, "STRU")
27
+ for line in inlines:
28
+ if "stru_file" in line and "stru_file" == line.split()[0]:
29
+ atom_file = line.split()[1]
30
+ geometry_path_in = os.path.join(fname, atom_file)
31
+ break
32
+ return geometry_path_in
33
+
34
+
35
+ def get_path_out(fname, inlines):
36
+ path_out = os.path.join(fname, "OUT.ABACUS/running_scf.log")
37
+ for line in inlines:
38
+ if "suffix" in line and "suffix" == line.split()[0]:
39
+ suffix = line.split()[1]
40
+ path_out = os.path.join(fname, f"OUT.{suffix}/running_scf.log")
41
+ break
42
+ return path_out
43
+
44
+
45
+ def get_energy(outlines):
46
+ Etot = None
47
+ for line in reversed(outlines):
48
+ if "final etot is" in line:
49
+ Etot = float(line.split()[-2]) # in eV
50
+ return Etot, True
51
+ elif "convergence has NOT been achieved!" in line:
52
+ return Etot, False
53
+ elif "convergence has not been achieved" in line:
54
+ return Etot, False
55
+
56
+ return Etot, False
57
+
58
+
59
+ def collect_force(outlines):
60
+ force = []
61
+ for i, line in enumerate(outlines):
62
+ if "TOTAL-FORCE (eV/Angstrom)" in line:
63
+ value_pattern = re.compile(
64
+ r"^\s*[A-Z][a-z]?[1-9][0-9]*\s+[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s+[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s+[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$"
65
+ )
66
+ j = i
67
+ # find the first line of force
68
+ noforce = False
69
+ while not value_pattern.match(outlines[j]):
70
+ j += 1
71
+ if (
72
+ j >= i + 10
73
+ ): # if can not find the first line of force in 10 lines, then stop
74
+ warnings.warn("Warning: can not find the first line of force")
75
+ noforce = True
76
+ break
77
+ if noforce:
78
+ break
79
+
80
+ force.append([])
81
+ while value_pattern.match(outlines[j]):
82
+ force[-1].append([float(ii) for ii in outlines[j].split()[1:4]])
83
+ j += 1
84
+ return force # only return the last force
85
+
86
+
87
+ def get_force(outlines, natoms):
88
+ force = collect_force(outlines)
89
+ if len(force) == 0:
90
+ return None
91
+ else:
92
+ return np.array(force[-1]) # only return the last force
93
+
94
+
95
+ def collect_stress(outlines):
96
+ stress = []
97
+ for i, line in enumerate(outlines):
98
+ if "TOTAL-STRESS (KBAR)" in line:
99
+ value_pattern = re.compile(
100
+ r"^\s*[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s+[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s+[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?\s*$"
101
+ )
102
+ j = i
103
+ nostress = False
104
+ while not value_pattern.match(outlines[j]):
105
+ j += 1
106
+ if (
107
+ j >= i + 10
108
+ ): # if can not find the first line of stress in 10 lines, then stop
109
+ warnings.warn("Warning: can not find the first line of stress")
110
+ nostress = True
111
+ break
112
+ if nostress:
113
+ break
114
+
115
+ stress.append([])
116
+ while value_pattern.match(outlines[j]):
117
+ stress[-1].append(
118
+ list(map(lambda x: float(x), outlines[j].split()[0:3]))
119
+ )
120
+ j += 1
121
+ return stress
122
+
123
+
124
+ def get_stress(outlines):
125
+ stress = collect_stress(outlines)
126
+ if len(stress) == 0:
127
+ return None
128
+ else:
129
+ return np.array(stress[-1]) * kbar2evperang3 # only return the last stress
130
+
131
+
132
+ def get_mag_force(outlines):
133
+ """Read atomic magmom and magnetic force from OUT.ABACUS/running_scf.log.
134
+
135
+ Returns
136
+ -------
137
+ magmom: list of list of atomic magnetic moments (three dimensions: ION_STEP * NATOMS * 1/3)
138
+ magforce: list of list of atomic magnetic forces (three dimensions: ION_STEP * NATOMS * 1/3)
139
+ e.g.:
140
+ -------------------------------------------------------------------------------------------
141
+ Total Magnetism (uB)
142
+ -------------------------------------------------------------------------------------------
143
+ Fe 0.0000000001 0.0000000000 3.0000000307
144
+ Fe -0.0000000000 -0.0000000000 3.0000001151
145
+ -------------------------------------------------------------------------------------------
146
+ -------------------------------------------------------------------------------------------
147
+ Magnetic force (eV/uB)
148
+ -------------------------------------------------------------------------------------------
149
+ Fe 0.0000000000 0.0000000000 -1.2117698671
150
+ Fe 0.0000000000 0.0000000000 -1.2117928796
151
+ -------------------------------------------------------------------------------------------
152
+
153
+ """
154
+ mags = []
155
+ magforces = []
156
+ for i, line in enumerate(outlines):
157
+ if "Total Magnetism (uB)" in line:
158
+ j = i + 2
159
+ mag = []
160
+ while "-------------------------" not in outlines[j]:
161
+ imag = [float(ii) for ii in outlines[j].split()[1:]]
162
+ if len(imag) == 1:
163
+ imag = [0, 0, imag[0]]
164
+ mag.append(imag)
165
+ j += 1
166
+ mags.append(mag)
167
+ if "Magnetic force (eV/uB)" in line:
168
+ j = i + 2
169
+ magforce = []
170
+ while "-------------------------" not in outlines[j]:
171
+ imagforce = [float(ii) for ii in outlines[j].split()[1:]]
172
+ if len(imagforce) == 1:
173
+ imagforce = [0, 0, imagforce[0]]
174
+ magforce.append(imagforce)
175
+ j += 1
176
+ magforces.append(magforce)
177
+ return np.array(mags), np.array(magforces)
178
+
179
+
180
+ def get_frame(fname):
181
+ data = {
182
+ "atom_names": [],
183
+ "atom_numbs": [],
184
+ "atom_types": [],
185
+ "cells": np.array([]),
186
+ "coords": np.array([]),
187
+ "energies": np.array([]),
188
+ "forces": np.array([]),
189
+ }
190
+
191
+ if isinstance(fname, str):
192
+ # if the input parameter is only one string, it is assumed that it is the
193
+ # base directory containing INPUT file;
194
+ path_in = os.path.join(fname, "INPUT")
195
+ else:
196
+ raise RuntimeError("invalid input")
197
+
198
+ if not CheckFile(path_in):
199
+ return data
200
+
201
+ with open_file(path_in) as fp:
202
+ inlines = fp.read().split("\n")
203
+
204
+ geometry_path_in = get_geometry_in(fname, inlines)
205
+
206
+ # get OUT.ABACUS/running_scf.log
207
+ path_out = get_path_out(fname, inlines)
208
+ if not (CheckFile(geometry_path_in) and CheckFile(path_out)):
209
+ return data
210
+ with open_file(path_out) as fp:
211
+ outlines = fp.read().split("\n")
212
+
213
+ # get energy
214
+ energy, converge = get_energy(outlines)
215
+ if not converge:
216
+ return data
217
+
218
+ # read STRU file
219
+ data = get_frame_from_stru(geometry_path_in)
220
+ natoms = sum(data["atom_numbs"])
221
+ # should remove spins from STRU file
222
+ if "spins" in data:
223
+ data.pop("spins")
224
+ move = data.pop("move", None)
225
+
226
+ # get magmom and magforce, force and stress
227
+ magmom, magforce = get_mag_force(outlines)
228
+ if len(magmom) > 0:
229
+ magmom = magmom[-1:]
230
+ if len(magforce) > 0:
231
+ magforce = magforce[-1:]
232
+
233
+ force = get_force(outlines, natoms)
234
+ stress = get_stress(outlines)
235
+
236
+ data["energies"] = np.array(energy)[np.newaxis]
237
+ data["forces"] = np.empty((0,)) if force is None else force[np.newaxis, :, :]
238
+ data["orig"] = np.zeros(3)
239
+ if stress is not None:
240
+ cell = data["cells"][0]
241
+ stress *= np.abs(np.linalg.det(cell))
242
+ data["virials"] = stress[np.newaxis, :, :]
243
+
244
+ if len(magmom) > 0:
245
+ data["spins"] = magmom
246
+ if len(magforce) > 0:
247
+ data["force_mags"] = magforce
248
+ if move is not None:
249
+ data["move"] = move
250
+ return data