dpdata 0.2.21__tar.gz → 0.2.23__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 (137) hide show
  1. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/benchmark.yml +6 -1
  2. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/test.yml +10 -4
  3. {dpdata-0.2.21 → dpdata-0.2.23}/.pre-commit-config.yaml +3 -3
  4. {dpdata-0.2.21 → dpdata-0.2.23}/.readthedocs.yaml +1 -1
  5. {dpdata-0.2.21 → dpdata-0.2.23}/PKG-INFO +6 -8
  6. {dpdata-0.2.21 → dpdata-0.2.23}/README.md +1 -1
  7. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/_version.py +2 -2
  8. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/abacus/md.py +19 -20
  9. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/abacus/relax.py +13 -21
  10. dpdata-0.2.23/dpdata/abacus/scf.py +250 -0
  11. dpdata-0.2.21/dpdata/abacus/scf.py → dpdata-0.2.23/dpdata/abacus/stru.py +344 -408
  12. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/ase_calculator.py +2 -1
  13. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/data_type.py +1 -1
  14. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/deepmd/comp.py +2 -2
  15. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/deepmd/hdf5.py +2 -2
  16. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/deepmd/mixed.py +3 -3
  17. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/deepmd/raw.py +1 -1
  18. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/driver.py +2 -1
  19. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/gaussian/gjf.py +4 -4
  20. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/lammps/dump.py +104 -2
  21. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/lammps/lmp.py +74 -15
  22. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/abacus.py +24 -4
  23. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/amber.py +2 -2
  24. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/ase.py +9 -3
  25. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/deepmd.py +30 -0
  26. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/gaussian.py +2 -2
  27. dpdata-0.2.23/dpdata/plugins/lammps.py +101 -0
  28. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/n2p2.py +9 -9
  29. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/pwmat.py +3 -1
  30. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/pymatgen.py +4 -5
  31. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/vasp.py +19 -1
  32. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pwmat/atomconfig.py +2 -2
  33. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pymatgen/structure.py +10 -1
  34. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/qe/traj.py +2 -2
  35. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/rdkit/sanitize.py +2 -2
  36. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/stat.py +19 -18
  37. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/system.py +19 -14
  38. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/unit.py +24 -6
  39. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/utils.py +1 -6
  40. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/vasp/outcar.py +3 -3
  41. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/vasp/poscar.py +52 -7
  42. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/vasp/xml.py +5 -5
  43. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/xyz/quip_gap_xyz.py +5 -5
  44. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/PKG-INFO +6 -8
  45. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/SOURCES.txt +1 -0
  46. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/requires.txt +2 -3
  47. {dpdata-0.2.21 → dpdata-0.2.23}/pyproject.toml +4 -8
  48. dpdata-0.2.21/dpdata/plugins/lammps.py +0 -51
  49. {dpdata-0.2.21 → dpdata-0.2.23}/.git-blame-ignore-revs +0 -0
  50. {dpdata-0.2.21 → dpdata-0.2.23}/.git_archival.txt +0 -0
  51. {dpdata-0.2.21 → dpdata-0.2.23}/.gitattributes +0 -0
  52. {dpdata-0.2.21 → dpdata-0.2.23}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  53. {dpdata-0.2.21 → dpdata-0.2.23}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  54. {dpdata-0.2.21 → dpdata-0.2.23}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  55. {dpdata-0.2.21 → dpdata-0.2.23}/.github/ISSUE_TEMPLATE/generic-issue.yml +0 -0
  56. {dpdata-0.2.21 → dpdata-0.2.23}/.github/dependabot.yml +0 -0
  57. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/mirror_gitee.yml +0 -0
  58. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/pub-pypi.yml +0 -0
  59. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/pyright.yml +0 -0
  60. {dpdata-0.2.21 → dpdata-0.2.23}/.github/workflows/test_import.yml +0 -0
  61. {dpdata-0.2.21 → dpdata-0.2.23}/.gitignore +0 -0
  62. {dpdata-0.2.21 → dpdata-0.2.23}/LICENSE +0 -0
  63. {dpdata-0.2.21 → dpdata-0.2.23}/MANIFEST.in +0 -0
  64. {dpdata-0.2.21 → dpdata-0.2.23}/benchmark/__init__.py +0 -0
  65. {dpdata-0.2.21 → dpdata-0.2.23}/benchmark/test_import.py +0 -0
  66. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/__about__.py +0 -0
  67. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/__init__.py +0 -0
  68. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/__main__.py +0 -0
  69. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/abacus/__init__.py +0 -0
  70. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/amber/__init__.py +0 -0
  71. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/amber/mask.py +0 -0
  72. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/amber/md.py +0 -0
  73. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/amber/sqm.py +0 -0
  74. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/bond_order_system.py +0 -0
  75. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/cli.py +0 -0
  76. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/cp2k/__init__.py +0 -0
  77. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/cp2k/cell.py +0 -0
  78. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/cp2k/output.py +0 -0
  79. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/deepmd/__init__.py +0 -0
  80. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/dftbplus/__init__.py +0 -0
  81. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/dftbplus/output.py +0 -0
  82. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/fhi_aims/__init__.py +0 -0
  83. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/fhi_aims/output.py +0 -0
  84. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/format.py +0 -0
  85. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/gaussian/__init__.py +0 -0
  86. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/gaussian/log.py +0 -0
  87. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/gromacs/__init__.py +0 -0
  88. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/gromacs/gro.py +0 -0
  89. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/lammps/__init__.py +0 -0
  90. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/md/__init__.py +0 -0
  91. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/md/msd.py +0 -0
  92. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/md/pbc.py +0 -0
  93. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/md/rdf.py +0 -0
  94. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/md/water.py +0 -0
  95. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/openmx/__init__.py +0 -0
  96. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/openmx/omx.py +0 -0
  97. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/orca/__init__.py +0 -0
  98. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/orca/output.py +0 -0
  99. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/periodic_table.json +0 -0
  100. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/periodic_table.py +0 -0
  101. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugin.py +0 -0
  102. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/3dmol.py +0 -0
  103. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/__init__.py +0 -0
  104. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/cp2k.py +0 -0
  105. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/dftbplus.py +0 -0
  106. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/fhi_aims.py +0 -0
  107. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/gromacs.py +0 -0
  108. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/list.py +0 -0
  109. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/openmx.py +0 -0
  110. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/orca.py +0 -0
  111. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/psi4.py +0 -0
  112. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/qe.py +0 -0
  113. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/rdkit.py +0 -0
  114. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/siesta.py +0 -0
  115. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/plugins/xyz.py +0 -0
  116. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/psi4/__init__.py +0 -0
  117. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/psi4/input.py +0 -0
  118. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/psi4/output.py +0 -0
  119. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pwmat/__init__.py +0 -0
  120. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pwmat/movement.py +0 -0
  121. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/py.typed +0 -0
  122. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pymatgen/__init__.py +0 -0
  123. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/pymatgen/molecule.py +0 -0
  124. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/qe/__init__.py +0 -0
  125. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/qe/scf.py +0 -0
  126. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/rdkit/__init__.py +0 -0
  127. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/rdkit/utils.py +0 -0
  128. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/siesta/__init__.py +0 -0
  129. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/siesta/aiMD_output.py +0 -0
  130. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/siesta/output.py +0 -0
  131. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/vasp/__init__.py +0 -0
  132. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/xyz/__init__.py +0 -0
  133. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata/xyz/xyz.py +0 -0
  134. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/dependency_links.txt +0 -0
  135. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/entry_points.txt +0 -0
  136. {dpdata-0.2.21 → dpdata-0.2.23}/dpdata.egg-info/top_level.txt +0 -0
  137. {dpdata-0.2.21 → dpdata-0.2.23}/setup.cfg +0 -0
@@ -13,7 +13,12 @@ jobs:
13
13
  uses: actions/setup-python@v5
14
14
  with:
15
15
  python-version: 3.12
16
- - run: curl -LsSf https://astral.sh/uv/install.sh | sh
16
+ - uses: astral-sh/setup-uv@v5
17
+ with:
18
+ enable-cache: true
19
+ cache-dependency-glob: |
20
+ **/requirements*.txt
21
+ **/pyproject.toml
17
22
  - name: Install dependencies
18
23
  run: uv pip install --system .[test,amber,ase,pymatgen,benchmark] rdkit openbabel-wheel
19
24
  - name: Run benchmarks
@@ -6,10 +6,10 @@ on:
6
6
 
7
7
  jobs:
8
8
  build:
9
- runs-on: ubuntu-latest
9
+ runs-on: ubuntu-22.04
10
10
  strategy:
11
11
  matrix:
12
- python-version: ["3.7", "3.8", "3.12"]
12
+ python-version: ["3.8", "3.12"]
13
13
 
14
14
  steps:
15
15
  - uses: actions/checkout@v4
@@ -18,13 +18,19 @@ jobs:
18
18
  uses: actions/setup-python@v5
19
19
  with:
20
20
  python-version: ${{ matrix.python-version }}
21
- - run: curl -LsSf https://astral.sh/uv/install.sh | sh
21
+ - uses: astral-sh/setup-uv@v5
22
+ with:
23
+ enable-cache: true
24
+ cache-dependency-glob: |
25
+ **/requirements*.txt
26
+ **/pyproject.toml
27
+ cache-suffix: "py${{ matrix.python-version }}"
22
28
  - name: Install dependencies
23
29
  run: uv pip install --system .[test,amber,ase,pymatgen] coverage ./tests/plugin rdkit openbabel-wheel
24
30
  - name: Test
25
31
  run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report
26
32
  - name: Run codecov
27
- uses: codecov/codecov-action@v4
33
+ uses: codecov/codecov-action@v5
28
34
  env:
29
35
  CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
30
36
  pass:
@@ -2,7 +2,7 @@
2
2
  # See https://pre-commit.com/hooks.html for more hooks
3
3
  repos:
4
4
  - repo: https://github.com/pre-commit/pre-commit-hooks
5
- rev: v4.6.0
5
+ rev: v5.0.0
6
6
  hooks:
7
7
  # there are many log files in tests
8
8
  # TODO: seperate py files and log files
@@ -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.6.5
24
+ rev: v0.9.6
25
25
  hooks:
26
26
  - id: ruff
27
27
  args: ["--fix"]
@@ -36,7 +36,7 @@ repos:
36
36
  args: ["--write"]
37
37
  # Python inside docs
38
38
  - repo: https://github.com/asottile/blacken-docs
39
- rev: 1.18.0
39
+ rev: 1.19.1
40
40
  hooks:
41
41
  - id: blacken-docs
42
42
  ci:
@@ -3,7 +3,7 @@ version: 2
3
3
  build:
4
4
  os: ubuntu-22.04
5
5
  tools:
6
- python: "mambaforge-22.9"
6
+ python: "mambaforge-23.11"
7
7
  conda:
8
8
  environment: docs/rtd_environment.yml
9
9
  sphinx:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: dpdata
3
- Version: 0.2.21
3
+ Version: 0.2.23
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>
@@ -174,13 +174,12 @@ Project-URL: Homepage, https://github.com/deepmodeling/dpdata
174
174
  Project-URL: documentation, https://docs.deepmodeling.com/projects/dpdata
175
175
  Project-URL: repository, https://github.com/deepmodeling/dpdata
176
176
  Keywords: lammps,vasp,deepmd-kit
177
- Classifier: Programming Language :: Python :: 3.7
178
177
  Classifier: Programming Language :: Python :: 3.8
179
178
  Classifier: Programming Language :: Python :: 3.9
180
179
  Classifier: Programming Language :: Python :: 3.10
181
180
  Classifier: Programming Language :: Python :: 3.11
182
181
  Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)
183
- Requires-Python: >=3.7
182
+ Requires-Python: >=3.8
184
183
  Description-Content-Type: text/markdown
185
184
  License-File: LICENSE
186
185
  Requires-Dist: numpy>=1.14.3
@@ -191,7 +190,6 @@ Requires-Dist: wcmatch
191
190
  Requires-Dist: importlib_metadata>=1.4; python_version < "3.8"
192
191
  Requires-Dist: typing_extensions; python_version < "3.8"
193
192
  Provides-Extra: test
194
- Requires-Dist: numpy<2; extra == "test"
195
193
  Provides-Extra: ase
196
194
  Requires-Dist: ase; extra == "ase"
197
195
  Provides-Extra: amber
@@ -202,10 +200,10 @@ Requires-Dist: pymatgen; extra == "pymatgen"
202
200
  Provides-Extra: docs
203
201
  Requires-Dist: sphinx; extra == "docs"
204
202
  Requires-Dist: recommonmark; extra == "docs"
205
- Requires-Dist: sphinx_rtd_theme>=1.0.0rc1; extra == "docs"
203
+ Requires-Dist: sphinx-book-theme; extra == "docs"
206
204
  Requires-Dist: numpydoc; extra == "docs"
207
205
  Requires-Dist: myst-parser; extra == "docs"
208
- Requires-Dist: deepmodeling-sphinx>=0.1.1; extra == "docs"
206
+ Requires-Dist: deepmodeling-sphinx>=0.3.0; extra == "docs"
209
207
  Requires-Dist: sphinx-argparse<0.5.0; extra == "docs"
210
208
  Requires-Dist: rdkit; extra == "docs"
211
209
  Requires-Dist: jupyterlite-sphinx; extra == "docs"
@@ -224,7 +222,7 @@ Requires-Dist: pytest-codspeed; extra == "benchmark"
224
222
 
225
223
  ## Installation
226
224
 
227
- DP-GEN only supports Python 3.7 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install DP-GEN:
225
+ dpdata only supports Python 3.8 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install dpdata:
228
226
 
229
227
  - Install via pip: `pip install dpdata`
230
228
  - Install via conda: `conda install -c conda-forge dpdata`
@@ -8,7 +8,7 @@
8
8
 
9
9
  ## Installation
10
10
 
11
- DP-GEN only supports Python 3.7 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install DP-GEN:
11
+ dpdata only supports Python 3.8 and above. You can [setup a conda/pip environment](https://docs.deepmodeling.com/faq/conda.html), and then use one of the following methods to install dpdata:
12
12
 
13
13
  - Install via pip: `pip install dpdata`
14
14
  - Install via conda: `conda install -c conda-forge dpdata`
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '0.2.21'
16
- __version_tuple__ = version_tuple = (0, 2, 21)
15
+ __version__ = version = '0.2.23'
16
+ __version_tuple__ = version_tuple = (0, 2, 23)
@@ -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.
@@ -56,9 +55,9 @@ def get_coords_from_dump(dumplines, natoms):
56
55
  if "VIRIAL" in dumplines[6]:
57
56
  calc_stress = True
58
57
  check_line = 10
59
- assert (
60
- "POSITION" in dumplines[check_line]
61
- ), "keywords 'POSITION' cannot be found in the 6th line. Please check."
58
+ assert "POSITION" in dumplines[check_line], (
59
+ "keywords 'POSITION' cannot be found in the 6th line. Please check."
60
+ )
62
61
  if "FORCE" in dumplines[check_line]:
63
62
  calc_force = True
64
63
 
@@ -68,7 +67,7 @@ def get_coords_from_dump(dumplines, natoms):
68
67
  else:
69
68
  nframes_dump = int(nlines / (total_natoms + 9))
70
69
  assert nframes_dump > 0, (
71
- "Number of lines in MD_dump file = %d. Number of atoms = %d. The MD_dump file is incomplete."
70
+ "Number of lines in MD_dump file = %d. Number of atoms = %d. The MD_dump file is incomplete." # noqa: UP031
72
71
  % (nlines, total_natoms)
73
72
  )
74
73
  cells = np.zeros([nframes_dump, 3, 3])
@@ -125,7 +124,7 @@ def get_coords_from_dump(dumplines, natoms):
125
124
  )
126
125
  iframe += 1
127
126
  assert iframe == nframes_dump, (
128
- "iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump."
127
+ "iframe=%d, nframe_dump=%d. Number of frames does not match number of lines in MD_dump." # noqa: UP031
129
128
  % (iframe, nframes_dump)
130
129
  )
131
130
  stresses *= kbar2evperang3
@@ -145,7 +144,7 @@ def get_energy(outlines, ndump, dump_freq):
145
144
  energy.append(np.nan)
146
145
  nenergy += 1
147
146
  assert ndump == len(energy), (
148
- "Number of total energies in running_md.log = %d. Number of frames in MD_dump = %d. Please check."
147
+ "Number of total energies in running_md.log = %d. Number of frames in MD_dump = %d. Please check." # noqa: UP031
149
148
  % (len(energy), ndump)
150
149
  )
151
150
  energy = np.array(energy)
@@ -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 = 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])
@@ -191,7 +190,7 @@ def get_frame(fname):
191
190
  force = np.delete(force, i - ndump, axis=0)
192
191
  stress = np.delete(stress, i - ndump, axis=0)
193
192
  energy = np.delete(energy, i - ndump, axis=0)
194
- unconv_stru += "%d " % i
193
+ unconv_stru += "%d " % i # noqa: UP031
195
194
  ndump = len(energy)
196
195
  if unconv_stru != "":
197
196
  warnings.warn(f"Structure {unconv_stru} are unconverged and not collected!")
@@ -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
@@ -220,6 +215,10 @@ def get_frame(fname):
220
215
  if len(magmom) > 0:
221
216
  data["spins"] = magmom
222
217
  if len(magforce) > 0:
223
- data["mag_forces"] = magforce
218
+ data["force_mags"] = magforce
219
+
220
+ # need to expand the move.
221
+ if "move" in data:
222
+ data["move"] = [data["move"][0] for i in range(ndump)]
224
223
 
225
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
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 = []
@@ -76,7 +75,7 @@ def get_coords_from_log(loglines, natoms):
76
75
  list(map(lambda x: float(x) * a0, loglines[i + k].split()[1:4]))
77
76
  )
78
77
  else:
79
- assert False, "Unrecongnized coordinate type, %s, line:%d" % (
78
+ assert False, "Unrecongnized coordinate type, %s, line:%d" % ( # noqa: UP031
80
79
  loglines[i].split()[0],
81
80
  i,
82
81
  )
@@ -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 = 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
@@ -217,6 +207,8 @@ def get_frame(fname):
217
207
  if len(magmom) > 0:
218
208
  data["spins"] = magmom
219
209
  if len(magforce) > 0:
220
- data["mag_forces"] = magforce
210
+ data["force_mags"] = magforce
211
+ if "move" in data:
212
+ data["move"] = [data["move"][0] for i in range(len(data["energies"]))]
221
213
 
222
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