dpdata 0.2.23__tar.gz → 0.2.25__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.23 → dpdata-0.2.25}/.github/workflows/benchmark.yml +1 -1
  2. {dpdata-0.2.23 → dpdata-0.2.25}/.github/workflows/pyright.yml +1 -1
  3. {dpdata-0.2.23 → dpdata-0.2.25}/.github/workflows/test.yml +2 -2
  4. {dpdata-0.2.23 → dpdata-0.2.25}/.pre-commit-config.yaml +1 -1
  5. {dpdata-0.2.23 → dpdata-0.2.25}/PKG-INFO +3 -2
  6. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/_version.py +9 -4
  7. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/abacus/stru.py +67 -33
  8. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/data_type.py +37 -0
  9. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/deepmd/mixed.py +33 -13
  10. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/lammps/lmp.py +48 -15
  11. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/ase.py +15 -8
  12. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/system.py +3 -5
  13. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/vasp/outcar.py +91 -17
  14. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/PKG-INFO +3 -2
  15. {dpdata-0.2.23 → dpdata-0.2.25}/.git-blame-ignore-revs +0 -0
  16. {dpdata-0.2.23 → dpdata-0.2.25}/.git_archival.txt +0 -0
  17. {dpdata-0.2.23 → dpdata-0.2.25}/.gitattributes +0 -0
  18. {dpdata-0.2.23 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  19. {dpdata-0.2.23 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  20. {dpdata-0.2.23 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  21. {dpdata-0.2.23 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/generic-issue.yml +0 -0
  22. {dpdata-0.2.23 → dpdata-0.2.25}/.github/dependabot.yml +0 -0
  23. {dpdata-0.2.23 → dpdata-0.2.25}/.github/workflows/mirror_gitee.yml +0 -0
  24. {dpdata-0.2.23 → dpdata-0.2.25}/.github/workflows/pub-pypi.yml +0 -0
  25. {dpdata-0.2.23 → dpdata-0.2.25}/.github/workflows/test_import.yml +0 -0
  26. {dpdata-0.2.23 → dpdata-0.2.25}/.gitignore +0 -0
  27. {dpdata-0.2.23 → dpdata-0.2.25}/.readthedocs.yaml +0 -0
  28. {dpdata-0.2.23 → dpdata-0.2.25}/LICENSE +0 -0
  29. {dpdata-0.2.23 → dpdata-0.2.25}/MANIFEST.in +0 -0
  30. {dpdata-0.2.23 → dpdata-0.2.25}/README.md +0 -0
  31. {dpdata-0.2.23 → dpdata-0.2.25}/benchmark/__init__.py +0 -0
  32. {dpdata-0.2.23 → dpdata-0.2.25}/benchmark/test_import.py +0 -0
  33. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/__about__.py +0 -0
  34. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/__init__.py +0 -0
  35. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/__main__.py +0 -0
  36. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/abacus/__init__.py +0 -0
  37. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/abacus/md.py +0 -0
  38. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/abacus/relax.py +0 -0
  39. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/abacus/scf.py +0 -0
  40. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/amber/__init__.py +0 -0
  41. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/amber/mask.py +0 -0
  42. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/amber/md.py +0 -0
  43. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/amber/sqm.py +0 -0
  44. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/ase_calculator.py +0 -0
  45. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/bond_order_system.py +0 -0
  46. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/cli.py +0 -0
  47. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/cp2k/__init__.py +0 -0
  48. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/cp2k/cell.py +0 -0
  49. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/cp2k/output.py +0 -0
  50. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/deepmd/__init__.py +0 -0
  51. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/deepmd/comp.py +0 -0
  52. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/deepmd/hdf5.py +0 -0
  53. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/deepmd/raw.py +0 -0
  54. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/dftbplus/__init__.py +0 -0
  55. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/dftbplus/output.py +0 -0
  56. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/driver.py +0 -0
  57. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/fhi_aims/__init__.py +0 -0
  58. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/fhi_aims/output.py +0 -0
  59. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/format.py +0 -0
  60. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/gaussian/__init__.py +0 -0
  61. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/gaussian/gjf.py +0 -0
  62. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/gaussian/log.py +0 -0
  63. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/gromacs/__init__.py +0 -0
  64. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/gromacs/gro.py +0 -0
  65. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/lammps/__init__.py +0 -0
  66. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/lammps/dump.py +0 -0
  67. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/md/__init__.py +0 -0
  68. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/md/msd.py +0 -0
  69. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/md/pbc.py +0 -0
  70. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/md/rdf.py +0 -0
  71. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/md/water.py +0 -0
  72. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/openmx/__init__.py +0 -0
  73. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/openmx/omx.py +0 -0
  74. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/orca/__init__.py +0 -0
  75. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/orca/output.py +0 -0
  76. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/periodic_table.json +0 -0
  77. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/periodic_table.py +0 -0
  78. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugin.py +0 -0
  79. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/3dmol.py +0 -0
  80. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/__init__.py +0 -0
  81. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/abacus.py +0 -0
  82. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/amber.py +0 -0
  83. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/cp2k.py +0 -0
  84. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/deepmd.py +0 -0
  85. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/dftbplus.py +0 -0
  86. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/fhi_aims.py +0 -0
  87. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/gaussian.py +0 -0
  88. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/gromacs.py +0 -0
  89. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/lammps.py +0 -0
  90. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/list.py +0 -0
  91. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/n2p2.py +0 -0
  92. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/openmx.py +0 -0
  93. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/orca.py +0 -0
  94. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/psi4.py +0 -0
  95. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/pwmat.py +0 -0
  96. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/pymatgen.py +0 -0
  97. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/qe.py +0 -0
  98. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/rdkit.py +0 -0
  99. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/siesta.py +0 -0
  100. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/vasp.py +0 -0
  101. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/plugins/xyz.py +0 -0
  102. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/psi4/__init__.py +0 -0
  103. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/psi4/input.py +0 -0
  104. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/psi4/output.py +0 -0
  105. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pwmat/__init__.py +0 -0
  106. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pwmat/atomconfig.py +0 -0
  107. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pwmat/movement.py +0 -0
  108. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/py.typed +0 -0
  109. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pymatgen/__init__.py +0 -0
  110. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pymatgen/molecule.py +0 -0
  111. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/pymatgen/structure.py +0 -0
  112. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/qe/__init__.py +0 -0
  113. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/qe/scf.py +0 -0
  114. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/qe/traj.py +0 -0
  115. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/rdkit/__init__.py +0 -0
  116. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/rdkit/sanitize.py +0 -0
  117. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/rdkit/utils.py +0 -0
  118. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/siesta/__init__.py +0 -0
  119. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/siesta/aiMD_output.py +0 -0
  120. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/siesta/output.py +0 -0
  121. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/stat.py +0 -0
  122. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/unit.py +0 -0
  123. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/utils.py +0 -0
  124. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/vasp/__init__.py +0 -0
  125. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/vasp/poscar.py +0 -0
  126. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/vasp/xml.py +0 -0
  127. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/xyz/__init__.py +0 -0
  128. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/xyz/quip_gap_xyz.py +0 -0
  129. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata/xyz/xyz.py +0 -0
  130. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/SOURCES.txt +0 -0
  131. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/dependency_links.txt +0 -0
  132. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/entry_points.txt +0 -0
  133. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/requires.txt +0 -0
  134. {dpdata-0.2.23 → dpdata-0.2.25}/dpdata.egg-info/top_level.txt +0 -0
  135. {dpdata-0.2.23 → dpdata-0.2.25}/pyproject.toml +0 -0
  136. {dpdata-0.2.23 → dpdata-0.2.25}/setup.cfg +0 -0
@@ -13,7 +13,7 @@ jobs:
13
13
  uses: actions/setup-python@v5
14
14
  with:
15
15
  python-version: 3.12
16
- - uses: astral-sh/setup-uv@v5
16
+ - uses: astral-sh/setup-uv@v6
17
17
  with:
18
18
  enable-cache: true
19
19
  cache-dependency-glob: |
@@ -13,7 +13,7 @@ jobs:
13
13
  with:
14
14
  python-version: '3.12'
15
15
  - run: pip install uv
16
- - run: uv pip install --system -e .[amber,ase,pymatgen] rdkit openbabel-wheel
16
+ - run: uv pip install --system -e .[amber,ase,pymatgen] 'rdkit<2025.3.3' openbabel-wheel
17
17
  - uses: jakebailey/pyright-action@v2
18
18
  with:
19
19
  version: 1.1.363
@@ -18,7 +18,7 @@ jobs:
18
18
  uses: actions/setup-python@v5
19
19
  with:
20
20
  python-version: ${{ matrix.python-version }}
21
- - uses: astral-sh/setup-uv@v5
21
+ - uses: astral-sh/setup-uv@v6
22
22
  with:
23
23
  enable-cache: true
24
24
  cache-dependency-glob: |
@@ -26,7 +26,7 @@ jobs:
26
26
  **/pyproject.toml
27
27
  cache-suffix: "py${{ matrix.python-version }}"
28
28
  - name: Install dependencies
29
- run: uv pip install --system .[test,amber,ase,pymatgen] coverage ./tests/plugin rdkit openbabel-wheel
29
+ run: uv pip install --system .[test,amber,ase,pymatgen] coverage ./tests/plugin 'rdkit<2025.3.3' openbabel-wheel 'numpy<2.3'
30
30
  - name: Test
31
31
  run: cd tests && coverage run --source=../dpdata -m unittest && cd .. && coverage combine tests/.coverage && coverage report
32
32
  - name: Run codecov
@@ -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.6
24
+ rev: v0.12.5
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.23
3
+ Version: 0.2.25
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.23'
16
- __version_tuple__ = version_tuple = (0, 2, 23)
20
+ __version__ = version = '0.2.25'
21
+ __version_tuple__ = version_tuple = (0, 2, 25)
@@ -314,7 +314,7 @@ def get_atom_mag_cartesian(atommag, angle1, angle2):
314
314
  ]
315
315
 
316
316
 
317
- def get_carteisan_coords(coords, coord_type, celldm, cell):
317
+ def get_cartesian_coords(coords, coord_type, celldm, cell):
318
318
  """Transform the atomic coordinates to cartesian coordinates.
319
319
 
320
320
  Args:
@@ -362,6 +362,7 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
362
362
 
363
363
  ntype = len(atom_names)
364
364
  line_idx = 1 # starting line of first element
365
+ define_atom_mag = False
365
366
  for it in range(ntype):
366
367
  atom_name = coords_lines[line_idx].split()[0]
367
368
  if atom_name != atom_names[it]:
@@ -377,7 +378,7 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
377
378
  parse_pos_oneline(coords_lines[line_idx])
378
379
  )
379
380
 
380
- coords.append(get_carteisan_coords(np.array(pos), coord_type, celldm, cell))
381
+ coords.append(get_cartesian_coords(np.array(pos), coord_type, celldm, cell))
381
382
 
382
383
  move.append(imove)
383
384
  velocity.append(ivelocity)
@@ -390,6 +391,9 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
390
391
  mag = [0, 0, atom_type_mag]
391
392
  mags.append(mag)
392
393
 
394
+ if imagmom is not None:
395
+ define_atom_mag = True
396
+
393
397
  line_idx += 1
394
398
  coords = np.array(coords) # need transformation!!!
395
399
 
@@ -409,11 +413,34 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
409
413
  if all([i is None for i in lambda_]):
410
414
  lambda_ = []
411
415
 
412
- mags = np.array(mags)
416
+ # here return the magnetic moment only when the atom magnetic moment is specified.
417
+ if not define_atom_mag:
418
+ mags = []
419
+ else:
420
+ mags = np.array(mags)
413
421
 
414
422
  return atom_numbs, coords, move, mags, velocity, sc, lambda_
415
423
 
416
424
 
425
+ def right_hand_rule(
426
+ cell: np.ndarray, coord: np.ndarray
427
+ ) -> tuple[np.ndarray, np.ndarray]:
428
+ """Rotate the cell and coord to make the cell fit the right-hand rule.
429
+
430
+ Args:
431
+ cell (np.ndarray): the cell vectors.
432
+ coord (np.ndarray): the atomic coordinates in cartesian.
433
+
434
+ Returns
435
+ -------
436
+ tuple: the rotated cell and coord.
437
+ """
438
+ if np.linalg.det(cell) < 0:
439
+ cell = -cell
440
+ coord = -coord
441
+ return cell, coord
442
+
443
+
417
444
  def get_frame_from_stru(stru):
418
445
  """Read the ABACUS STRU file and return the dpdata frame.
419
446
 
@@ -438,10 +465,13 @@ def get_frame_from_stru(stru):
438
465
 
439
466
  "cells": list of cell vectors,
440
467
  "coords": list of atomic coordinates,
441
- "spins": list of magnetic moments,
468
+ "spins": list of magnetic moments, # return only when set "mag xxx" for each atom in STRU file
442
469
  "moves": list of move flags,
443
470
  }
444
471
  For some keys, if the information is not provided in the STRU file, then it will not be included in the dictionary.
472
+ "spins" is designed for delta spin calculation, and when dpdata.System is write to lmp format, the spin will be written as magmom.
473
+ But we should note that this file format is valid only for a spin lammps job, not for a normal job.
474
+ If you want to use dpgen to run the non-spin job, then you should not define "mag x x x" in the STRU file.
445
475
  """
446
476
  if not os.path.isfile(stru):
447
477
  raise FileNotFoundError(f"ABACUS STRU file {stru} not found!!!")
@@ -462,6 +492,7 @@ def get_frame_from_stru(stru):
462
492
  blocks["ATOMIC_POSITIONS"], atom_names, celldm, cell
463
493
  )
464
494
 
495
+ cell, coords = right_hand_rule(cell, coords)
465
496
  data = {
466
497
  "atom_names": atom_names,
467
498
  "atom_numbs": atom_numbs,
@@ -472,8 +503,9 @@ def get_frame_from_stru(stru):
472
503
  "pp_files": pp_files,
473
504
  "cells": np.array([cell]),
474
505
  "coords": np.array([coords]),
475
- "spins": np.array([mags]),
476
506
  }
507
+ if len(mags) > 0:
508
+ data["spins"] = np.array([mags])
477
509
  if len(orb_files) > 0:
478
510
  data["orb_files"] = orb_files
479
511
  if len(dpks_descriptor) > 0:
@@ -719,66 +751,68 @@ def make_unlabeled_stru(
719
751
  out += "0.0\n"
720
752
  out += str(data["atom_numbs"][iele]) + "\n"
721
753
  for iatom in range(data["atom_numbs"][iele]):
722
- iatomtype = np.nonzero(data["atom_types"] == iele)[0][iatom]
754
+ iatomtype = np.nonzero(data["atom_types"] == iele)[0][
755
+ iatom
756
+ ] # it is the atom index
723
757
  iout = f"{data['coords'][frame_idx][iatomtype, 0]:.12f} {data['coords'][frame_idx][iatomtype, 1]:.12f} {data['coords'][frame_idx][iatomtype, 2]:.12f}"
724
758
  # add flags for move, velocity, mag, angle1, angle2, and sc
725
759
  if move is not None:
726
760
  if (
727
- isinstance(ndarray2list(move[natom_tot]), (list, tuple))
728
- and len(move[natom_tot]) == 3
761
+ isinstance(ndarray2list(move[iatomtype]), (list, tuple))
762
+ and len(move[iatomtype]) == 3
729
763
  ):
730
764
  iout += " " + " ".join(
731
- ["1" if ii else "0" for ii in move[natom_tot]]
765
+ ["1" if ii else "0" for ii in move[iatomtype]]
732
766
  )
733
- elif isinstance(ndarray2list(move[natom_tot]), (int, float, bool)):
734
- iout += " 1 1 1" if move[natom_tot] else " 0 0 0"
767
+ elif isinstance(ndarray2list(move[iatomtype]), (int, float, bool)):
768
+ iout += " 1 1 1" if move[iatomtype] else " 0 0 0"
735
769
  else:
736
770
  iout += " 1 1 1"
737
771
 
738
772
  if (
739
773
  velocity is not None
740
- and isinstance(ndarray2list(velocity[natom_tot]), (list, tuple))
741
- and len(velocity[natom_tot]) == 3
774
+ and isinstance(ndarray2list(velocity[iatomtype]), (list, tuple))
775
+ and len(velocity[iatomtype]) == 3
742
776
  ):
743
- iout += " v " + " ".join([f"{ii:.12f}" for ii in velocity[natom_tot]])
777
+ iout += " v " + " ".join([f"{ii:.12f}" for ii in velocity[iatomtype]])
744
778
 
745
779
  if mag is not None:
746
- if isinstance(ndarray2list(mag[natom_tot]), (list, tuple)) and len(
747
- mag[natom_tot]
780
+ if isinstance(ndarray2list(mag[iatomtype]), (list, tuple)) and len(
781
+ mag[iatomtype]
748
782
  ) in [1, 3]:
749
- iout += " mag " + " ".join([f"{ii:.12f}" for ii in mag[natom_tot]])
750
- elif isinstance(ndarray2list(mag[natom_tot]), (int, float)):
751
- iout += " mag " + f"{mag[natom_tot]:.12f}"
783
+ iout += " mag " + " ".join([f"{ii:.12f}" for ii in mag[iatomtype]])
784
+ elif isinstance(ndarray2list(mag[iatomtype]), (int, float)):
785
+ iout += " mag " + f"{mag[iatomtype]:.12f}"
752
786
 
753
787
  if angle1 is not None and isinstance(
754
- ndarray2list(angle1[natom_tot]), (int, float)
788
+ ndarray2list(angle1[iatomtype]), (int, float)
755
789
  ):
756
- iout += " angle1 " + f"{angle1[natom_tot]:.12f}"
790
+ iout += " angle1 " + f"{angle1[iatomtype]:.12f}"
757
791
 
758
792
  if angle2 is not None and isinstance(
759
- ndarray2list(angle2[natom_tot]), (int, float)
793
+ ndarray2list(angle2[iatomtype]), (int, float)
760
794
  ):
761
- iout += " angle2 " + f"{angle2[natom_tot]:.12f}"
795
+ iout += " angle2 " + f"{angle2[iatomtype]:.12f}"
762
796
 
763
797
  if sc is not None:
764
- if isinstance(ndarray2list(sc[natom_tot]), (list, tuple)) and len(
765
- sc[natom_tot]
798
+ if isinstance(ndarray2list(sc[iatomtype]), (list, tuple)) and len(
799
+ sc[iatomtype]
766
800
  ) in [1, 3]:
767
801
  iout += " sc " + " ".join(
768
- ["1" if ii else "0" for ii in sc[natom_tot]]
802
+ ["1" if ii else "0" for ii in sc[iatomtype]]
769
803
  )
770
- elif isinstance(ndarray2list(sc[natom_tot]), (int, float, bool)):
771
- iout += " sc " + "1" if sc[natom_tot] else "0"
804
+ elif isinstance(ndarray2list(sc[iatomtype]), (int, float, bool)):
805
+ iout += " sc " + "1" if sc[iatomtype] else "0"
772
806
 
773
807
  if lambda_ is not None:
774
- if isinstance(ndarray2list(lambda_[natom_tot]), (list, tuple)) and len(
775
- lambda_[natom_tot]
808
+ if isinstance(ndarray2list(lambda_[iatomtype]), (list, tuple)) and len(
809
+ lambda_[iatomtype]
776
810
  ) in [1, 3]:
777
811
  iout += " lambda " + " ".join(
778
- [f"{ii:.12f}" for ii in lambda_[natom_tot]]
812
+ [f"{ii:.12f}" for ii in lambda_[iatomtype]]
779
813
  )
780
- elif isinstance(ndarray2list(lambda_[natom_tot]), (int, float)):
781
- iout += " lambda " + f"{lambda_[natom_tot]:.12f}"
814
+ elif isinstance(ndarray2list(lambda_[iatomtype]), (int, float)):
815
+ iout += " lambda " + f"{lambda_[iatomtype]:.12f}"
782
816
 
783
817
  out += iout + "\n"
784
818
  natom_tot += 1
@@ -64,6 +64,43 @@ class DataType:
64
64
  self.required = required
65
65
  self.deepmd_name = name if deepmd_name is None else deepmd_name
66
66
 
67
+ def __eq__(self, other) -> bool:
68
+ """Check if two DataType instances are equal.
69
+
70
+ Parameters
71
+ ----------
72
+ other : object
73
+ object to compare with
74
+
75
+ Returns
76
+ -------
77
+ bool
78
+ True if equal, False otherwise
79
+ """
80
+ if not isinstance(other, DataType):
81
+ return False
82
+ return (
83
+ self.name == other.name
84
+ and self.dtype == other.dtype
85
+ and self.shape == other.shape
86
+ and self.required == other.required
87
+ and self.deepmd_name == other.deepmd_name
88
+ )
89
+
90
+ def __repr__(self) -> str:
91
+ """Return string representation of DataType.
92
+
93
+ Returns
94
+ -------
95
+ str
96
+ string representation
97
+ """
98
+ return (
99
+ f"DataType(name='{self.name}', dtype={self.dtype.__name__}, "
100
+ f"shape={self.shape}, required={self.required}, "
101
+ f"deepmd_name='{self.deepmd_name}')"
102
+ )
103
+
67
104
  def real_shape(self, system: System) -> tuple[int]:
68
105
  """Returns expected real shape of a system."""
69
106
  assert self.shape is not None
@@ -4,6 +4,8 @@ import copy
4
4
 
5
5
  import numpy as np
6
6
 
7
+ import dpdata
8
+
7
9
  from .comp import dump as comp_dump
8
10
  from .comp import to_system_data as comp_to_system_data
9
11
 
@@ -27,10 +29,32 @@ def to_system_data(folder, type_map=None, labels=True):
27
29
  all_real_atom_types_concat = index_map[all_real_atom_types_concat]
28
30
  all_cells_concat = data["cells"]
29
31
  all_coords_concat = data["coords"]
32
+
33
+ # handle custom registered data types
30
34
  if labels:
31
- all_eners_concat = data.get("energies")
32
- all_forces_concat = data.get("forces")
33
- all_virs_concat = data.get("virials")
35
+ dtypes = dpdata.system.LabeledSystem.DTYPES
36
+ else:
37
+ dtypes = dpdata.system.System.DTYPES
38
+ reserved = {
39
+ "atom_numbs",
40
+ "atom_names",
41
+ "atom_types",
42
+ "real_atom_names",
43
+ "real_atom_types",
44
+ "cells",
45
+ "coords",
46
+ "orig",
47
+ "nopbc",
48
+ }
49
+ extra_data = {}
50
+ for dtype in dtypes:
51
+ name = dtype.name
52
+ if name in reserved:
53
+ continue
54
+ if not (len(dtype.shape) and dtype.shape[0] == dpdata.system.Axis.NFRAMES):
55
+ continue
56
+ if name in data:
57
+ extra_data[name] = data.pop(name)
34
58
 
35
59
  data_list = []
36
60
  while True:
@@ -56,16 +80,12 @@ def to_system_data(folder, type_map=None, labels=True):
56
80
  all_cells_concat = all_cells_concat[rest_idx]
57
81
  temp_data["coords"] = all_coords_concat[temp_idx]
58
82
  all_coords_concat = all_coords_concat[rest_idx]
59
- if labels:
60
- if all_eners_concat is not None and all_eners_concat.size > 0:
61
- temp_data["energies"] = all_eners_concat[temp_idx]
62
- all_eners_concat = all_eners_concat[rest_idx]
63
- if all_forces_concat is not None and all_forces_concat.size > 0:
64
- temp_data["forces"] = all_forces_concat[temp_idx]
65
- all_forces_concat = all_forces_concat[rest_idx]
66
- if all_virs_concat is not None and all_virs_concat.size > 0:
67
- temp_data["virials"] = all_virs_concat[temp_idx]
68
- all_virs_concat = all_virs_concat[rest_idx]
83
+
84
+ for name in extra_data:
85
+ all_dtype_concat = extra_data[name]
86
+ temp_data[name] = all_dtype_concat[temp_idx]
87
+ extra_data[name] = all_dtype_concat[rest_idx]
88
+
69
89
  data_list.append(temp_data)
70
90
  return data_list
71
91
 
@@ -193,31 +193,64 @@ def to_system_data(lines, type_map=None, type_idx_zero=True):
193
193
  return system_data(lines, type_map=type_map, type_idx_zero=type_idx_zero)
194
194
 
195
195
 
196
+ def rotate_to_lower_triangle(
197
+ cell: np.ndarray, coord: np.ndarray
198
+ ) -> tuple[np.ndarray, np.ndarray]:
199
+ """Rotate the cell to lower triangular and ensure the diagonal elements are non-negative.
200
+
201
+ Args:
202
+ cell (np.ndarray): The original cell matrix.
203
+ coord (np.ndarray): The coordinates of the atoms.
204
+
205
+ Returns
206
+ -------
207
+ tuple[np.ndarray, np.ndarray]: The rotated cell and adjusted coordinates.
208
+ """
209
+ q, _ = np.linalg.qr(cell.T)
210
+ cell = np.matmul(cell, q)
211
+ coord = np.matmul(coord, q)
212
+
213
+ # Ensure the diagonal elements of the cell are non-negative
214
+ rot = np.eye(3)
215
+ if cell[0][0] < 0:
216
+ rot[0][0] = -1
217
+ if cell[1][1] < 0:
218
+ rot[1][1] = -1
219
+ if cell[2][2] < 0:
220
+ rot[2][2] = -1
221
+ cell = np.matmul(cell, rot)
222
+ coord = np.matmul(coord, rot)
223
+ return cell, coord
224
+
225
+
196
226
  def from_system_data(system, f_idx=0):
197
227
  ret = ""
198
228
  ret += "\n"
199
229
  natoms = sum(system["atom_numbs"])
200
230
  ntypes = len(system["atom_numbs"])
231
+ cell, coord = rotate_to_lower_triangle(
232
+ system["cells"][f_idx], system["coords"][f_idx]
233
+ )
201
234
  ret += "%d atoms\n" % natoms # noqa: UP031
202
235
  ret += "%d atom types\n" % ntypes # noqa: UP031
203
236
  ret += (ptr_float_fmt + " " + ptr_float_fmt + " xlo xhi\n") % (
204
237
  0,
205
- system["cells"][f_idx][0][0],
238
+ cell[0][0],
206
239
  ) # noqa: UP031
207
240
  ret += (ptr_float_fmt + " " + ptr_float_fmt + " ylo yhi\n") % (
208
241
  0,
209
- system["cells"][f_idx][1][1],
242
+ cell[1][1],
210
243
  ) # noqa: UP031
211
244
  ret += (ptr_float_fmt + " " + ptr_float_fmt + " zlo zhi\n") % (
212
245
  0,
213
- system["cells"][f_idx][2][2],
246
+ cell[2][2],
214
247
  ) # noqa: UP031
215
248
  ret += (
216
249
  ptr_float_fmt + " " + ptr_float_fmt + " " + ptr_float_fmt + " xy xz yz\n"
217
250
  ) % (
218
- system["cells"][f_idx][1][0],
219
- system["cells"][f_idx][2][0],
220
- system["cells"][f_idx][2][1],
251
+ cell[1][0],
252
+ cell[2][0],
253
+ cell[2][1],
221
254
  ) # noqa: UP031
222
255
  ret += "\n"
223
256
  ret += "Atoms # atomic\n"
@@ -255,9 +288,9 @@ def from_system_data(system, f_idx=0):
255
288
  ret += coord_fmt % (
256
289
  ii + 1,
257
290
  system["atom_types"][ii] + 1,
258
- system["coords"][f_idx][ii][0] - system["orig"][0],
259
- system["coords"][f_idx][ii][1] - system["orig"][1],
260
- system["coords"][f_idx][ii][2] - system["orig"][2],
291
+ coord[ii][0] - system["orig"][0],
292
+ coord[ii][1] - system["orig"][1],
293
+ coord[ii][2] - system["orig"][2],
261
294
  system["spins"][f_idx][ii][0] / spins_norm[ii],
262
295
  system["spins"][f_idx][ii][1] / spins_norm[ii],
263
296
  system["spins"][f_idx][ii][2] / spins_norm[ii],
@@ -267,9 +300,9 @@ def from_system_data(system, f_idx=0):
267
300
  ret += coord_fmt % (
268
301
  ii + 1,
269
302
  system["atom_types"][ii] + 1,
270
- system["coords"][f_idx][ii][0] - system["orig"][0],
271
- system["coords"][f_idx][ii][1] - system["orig"][1],
272
- system["coords"][f_idx][ii][2] - system["orig"][2],
303
+ coord[ii][0] - system["orig"][0],
304
+ coord[ii][1] - system["orig"][1],
305
+ coord[ii][2] - system["orig"][2],
273
306
  system["spins"][f_idx][ii][0],
274
307
  system["spins"][f_idx][ii][1],
275
308
  system["spins"][f_idx][ii][2] + 1,
@@ -279,9 +312,9 @@ def from_system_data(system, f_idx=0):
279
312
  ret += coord_fmt % (
280
313
  ii + 1,
281
314
  system["atom_types"][ii] + 1,
282
- system["coords"][f_idx][ii][0] - system["orig"][0],
283
- system["coords"][f_idx][ii][1] - system["orig"][1],
284
- system["coords"][f_idx][ii][2] - system["orig"][2],
315
+ coord[ii][0] - system["orig"][0],
316
+ coord[ii][1] - system["orig"][1],
317
+ coord[ii][2] - system["orig"][2],
285
318
  ) # noqa: UP031
286
319
  return ret
287
320
 
@@ -63,6 +63,8 @@ class ASEStructureFormat(Format):
63
63
  """Convert ase.Atoms to a LabeledSystem. Energies and forces
64
64
  are calculated by the calculator.
65
65
 
66
+ Note that this method will try to load virials from either virial field or converted from stress tensor.
67
+
66
68
  Parameters
67
69
  ----------
68
70
  atoms : ase.Atoms
@@ -94,13 +96,19 @@ class ASEStructureFormat(Format):
94
96
  "energies": np.array([energies]),
95
97
  "forces": np.array([forces]),
96
98
  }
97
- try:
98
- stress = atoms.get_stress(voigt=False)
99
- except PropertyNotImplementedError:
100
- pass
101
- else:
102
- virials = np.array([-atoms.get_volume() * stress])
103
- info_dict["virials"] = virials
99
+
100
+ # try to get virials from different sources
101
+ virials = atoms.info.get("virial")
102
+ if virials is None:
103
+ try:
104
+ stress = atoms.get_stress(voigt=False)
105
+ except PropertyNotImplementedError:
106
+ pass
107
+ else:
108
+ virials = -atoms.get_volume() * stress
109
+ if virials is not None:
110
+ info_dict["virials"] = np.array([virials])
111
+
104
112
  return info_dict
105
113
 
106
114
  def from_multi_systems(
@@ -166,7 +174,6 @@ class ASEStructureFormat(Format):
166
174
 
167
175
  structures = []
168
176
  species = [data["atom_names"][tt] for tt in data["atom_types"]]
169
-
170
177
  for ii in range(data["coords"].shape[0]):
171
178
  structure = Atoms(
172
179
  symbols=species,
@@ -710,9 +710,7 @@ class System:
710
710
 
711
711
  @post_funcs.register("shift_orig_zero")
712
712
  def _shift_orig_zero(self):
713
- for ff in self.data["coords"]:
714
- for ii in ff:
715
- ii = ii - self.data["orig"]
713
+ self.data["coords"] = self.data["coords"] - self.data["orig"]
716
714
  self.data["orig"] = self.data["orig"] - self.data["orig"]
717
715
  assert (np.zeros([3]) == self.data["orig"]).all()
718
716
 
@@ -1104,9 +1102,9 @@ class System:
1104
1102
  all_dtypes = cls.DTYPES + tuple(data_type)
1105
1103
  dtypes_dict = {}
1106
1104
  for dt in all_dtypes:
1107
- if dt.name in dtypes_dict:
1105
+ if dt.name in dtypes_dict and dt != dtypes_dict[dt.name]:
1108
1106
  warnings.warn(
1109
- f"Data type {dt.name} is registered twice; only the newly registered one will be used.",
1107
+ f"Data type {dt.name} is registered twice with different definitions; only the newly registered one will be used.",
1110
1108
  UserWarning,
1111
1109
  )
1112
1110
  dtypes_dict[dt.name] = dt