dpdata 0.2.24__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.24 → dpdata-0.2.25}/.github/workflows/benchmark.yml +1 -1
  2. {dpdata-0.2.24 → dpdata-0.2.25}/.github/workflows/pyright.yml +1 -1
  3. {dpdata-0.2.24 → dpdata-0.2.25}/.github/workflows/test.yml +2 -2
  4. {dpdata-0.2.24 → dpdata-0.2.25}/.pre-commit-config.yaml +1 -1
  5. {dpdata-0.2.24 → dpdata-0.2.25}/PKG-INFO +1 -1
  6. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/_version.py +2 -2
  7. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/abacus/stru.py +52 -30
  8. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/data_type.py +37 -0
  9. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/deepmd/mixed.py +33 -13
  10. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/lammps/lmp.py +48 -15
  11. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/ase.py +15 -8
  12. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/system.py +2 -2
  13. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/vasp/outcar.py +91 -17
  14. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/PKG-INFO +1 -1
  15. {dpdata-0.2.24 → dpdata-0.2.25}/.git-blame-ignore-revs +0 -0
  16. {dpdata-0.2.24 → dpdata-0.2.25}/.git_archival.txt +0 -0
  17. {dpdata-0.2.24 → dpdata-0.2.25}/.gitattributes +0 -0
  18. {dpdata-0.2.24 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
  19. {dpdata-0.2.24 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/config.yml +0 -0
  20. {dpdata-0.2.24 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
  21. {dpdata-0.2.24 → dpdata-0.2.25}/.github/ISSUE_TEMPLATE/generic-issue.yml +0 -0
  22. {dpdata-0.2.24 → dpdata-0.2.25}/.github/dependabot.yml +0 -0
  23. {dpdata-0.2.24 → dpdata-0.2.25}/.github/workflows/mirror_gitee.yml +0 -0
  24. {dpdata-0.2.24 → dpdata-0.2.25}/.github/workflows/pub-pypi.yml +0 -0
  25. {dpdata-0.2.24 → dpdata-0.2.25}/.github/workflows/test_import.yml +0 -0
  26. {dpdata-0.2.24 → dpdata-0.2.25}/.gitignore +0 -0
  27. {dpdata-0.2.24 → dpdata-0.2.25}/.readthedocs.yaml +0 -0
  28. {dpdata-0.2.24 → dpdata-0.2.25}/LICENSE +0 -0
  29. {dpdata-0.2.24 → dpdata-0.2.25}/MANIFEST.in +0 -0
  30. {dpdata-0.2.24 → dpdata-0.2.25}/README.md +0 -0
  31. {dpdata-0.2.24 → dpdata-0.2.25}/benchmark/__init__.py +0 -0
  32. {dpdata-0.2.24 → dpdata-0.2.25}/benchmark/test_import.py +0 -0
  33. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/__about__.py +0 -0
  34. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/__init__.py +0 -0
  35. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/__main__.py +0 -0
  36. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/abacus/__init__.py +0 -0
  37. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/abacus/md.py +0 -0
  38. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/abacus/relax.py +0 -0
  39. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/abacus/scf.py +0 -0
  40. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/amber/__init__.py +0 -0
  41. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/amber/mask.py +0 -0
  42. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/amber/md.py +0 -0
  43. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/amber/sqm.py +0 -0
  44. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/ase_calculator.py +0 -0
  45. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/bond_order_system.py +0 -0
  46. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/cli.py +0 -0
  47. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/cp2k/__init__.py +0 -0
  48. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/cp2k/cell.py +0 -0
  49. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/cp2k/output.py +0 -0
  50. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/deepmd/__init__.py +0 -0
  51. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/deepmd/comp.py +0 -0
  52. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/deepmd/hdf5.py +0 -0
  53. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/deepmd/raw.py +0 -0
  54. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/dftbplus/__init__.py +0 -0
  55. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/dftbplus/output.py +0 -0
  56. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/driver.py +0 -0
  57. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/fhi_aims/__init__.py +0 -0
  58. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/fhi_aims/output.py +0 -0
  59. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/format.py +0 -0
  60. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/gaussian/__init__.py +0 -0
  61. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/gaussian/gjf.py +0 -0
  62. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/gaussian/log.py +0 -0
  63. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/gromacs/__init__.py +0 -0
  64. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/gromacs/gro.py +0 -0
  65. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/lammps/__init__.py +0 -0
  66. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/lammps/dump.py +0 -0
  67. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/md/__init__.py +0 -0
  68. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/md/msd.py +0 -0
  69. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/md/pbc.py +0 -0
  70. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/md/rdf.py +0 -0
  71. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/md/water.py +0 -0
  72. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/openmx/__init__.py +0 -0
  73. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/openmx/omx.py +0 -0
  74. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/orca/__init__.py +0 -0
  75. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/orca/output.py +0 -0
  76. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/periodic_table.json +0 -0
  77. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/periodic_table.py +0 -0
  78. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugin.py +0 -0
  79. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/3dmol.py +0 -0
  80. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/__init__.py +0 -0
  81. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/abacus.py +0 -0
  82. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/amber.py +0 -0
  83. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/cp2k.py +0 -0
  84. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/deepmd.py +0 -0
  85. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/dftbplus.py +0 -0
  86. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/fhi_aims.py +0 -0
  87. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/gaussian.py +0 -0
  88. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/gromacs.py +0 -0
  89. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/lammps.py +0 -0
  90. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/list.py +0 -0
  91. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/n2p2.py +0 -0
  92. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/openmx.py +0 -0
  93. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/orca.py +0 -0
  94. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/psi4.py +0 -0
  95. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/pwmat.py +0 -0
  96. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/pymatgen.py +0 -0
  97. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/qe.py +0 -0
  98. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/rdkit.py +0 -0
  99. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/siesta.py +0 -0
  100. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/vasp.py +0 -0
  101. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/plugins/xyz.py +0 -0
  102. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/psi4/__init__.py +0 -0
  103. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/psi4/input.py +0 -0
  104. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/psi4/output.py +0 -0
  105. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pwmat/__init__.py +0 -0
  106. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pwmat/atomconfig.py +0 -0
  107. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pwmat/movement.py +0 -0
  108. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/py.typed +0 -0
  109. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pymatgen/__init__.py +0 -0
  110. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pymatgen/molecule.py +0 -0
  111. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/pymatgen/structure.py +0 -0
  112. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/qe/__init__.py +0 -0
  113. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/qe/scf.py +0 -0
  114. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/qe/traj.py +0 -0
  115. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/rdkit/__init__.py +0 -0
  116. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/rdkit/sanitize.py +0 -0
  117. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/rdkit/utils.py +0 -0
  118. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/siesta/__init__.py +0 -0
  119. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/siesta/aiMD_output.py +0 -0
  120. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/siesta/output.py +0 -0
  121. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/stat.py +0 -0
  122. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/unit.py +0 -0
  123. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/utils.py +0 -0
  124. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/vasp/__init__.py +0 -0
  125. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/vasp/poscar.py +0 -0
  126. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/vasp/xml.py +0 -0
  127. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/xyz/__init__.py +0 -0
  128. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/xyz/quip_gap_xyz.py +0 -0
  129. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata/xyz/xyz.py +0 -0
  130. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/SOURCES.txt +0 -0
  131. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/dependency_links.txt +0 -0
  132. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/entry_points.txt +0 -0
  133. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/requires.txt +0 -0
  134. {dpdata-0.2.24 → dpdata-0.2.25}/dpdata.egg-info/top_level.txt +0 -0
  135. {dpdata-0.2.24 → dpdata-0.2.25}/pyproject.toml +0 -0
  136. {dpdata-0.2.24 → 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.11.0
24
+ rev: v0.12.5
25
25
  hooks:
26
26
  - id: ruff
27
27
  args: ["--fix"]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dpdata
3
- Version: 0.2.24
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>
@@ -17,5 +17,5 @@ __version__: str
17
17
  __version_tuple__: VERSION_TUPLE
18
18
  version_tuple: VERSION_TUPLE
19
19
 
20
- __version__ = version = '0.2.24'
21
- __version_tuple__ = version_tuple = (0, 2, 24)
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:
@@ -378,7 +378,7 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
378
378
  parse_pos_oneline(coords_lines[line_idx])
379
379
  )
380
380
 
381
- 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))
382
382
 
383
383
  move.append(imove)
384
384
  velocity.append(ivelocity)
@@ -422,6 +422,25 @@ def parse_pos(coords_lines, atom_names, celldm, cell):
422
422
  return atom_numbs, coords, move, mags, velocity, sc, lambda_
423
423
 
424
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
+
425
444
  def get_frame_from_stru(stru):
426
445
  """Read the ABACUS STRU file and return the dpdata frame.
427
446
 
@@ -473,6 +492,7 @@ def get_frame_from_stru(stru):
473
492
  blocks["ATOMIC_POSITIONS"], atom_names, celldm, cell
474
493
  )
475
494
 
495
+ cell, coords = right_hand_rule(cell, coords)
476
496
  data = {
477
497
  "atom_names": atom_names,
478
498
  "atom_numbs": atom_numbs,
@@ -731,66 +751,68 @@ def make_unlabeled_stru(
731
751
  out += "0.0\n"
732
752
  out += str(data["atom_numbs"][iele]) + "\n"
733
753
  for iatom in range(data["atom_numbs"][iele]):
734
- 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
735
757
  iout = f"{data['coords'][frame_idx][iatomtype, 0]:.12f} {data['coords'][frame_idx][iatomtype, 1]:.12f} {data['coords'][frame_idx][iatomtype, 2]:.12f}"
736
758
  # add flags for move, velocity, mag, angle1, angle2, and sc
737
759
  if move is not None:
738
760
  if (
739
- isinstance(ndarray2list(move[natom_tot]), (list, tuple))
740
- and len(move[natom_tot]) == 3
761
+ isinstance(ndarray2list(move[iatomtype]), (list, tuple))
762
+ and len(move[iatomtype]) == 3
741
763
  ):
742
764
  iout += " " + " ".join(
743
- ["1" if ii else "0" for ii in move[natom_tot]]
765
+ ["1" if ii else "0" for ii in move[iatomtype]]
744
766
  )
745
- elif isinstance(ndarray2list(move[natom_tot]), (int, float, bool)):
746
- 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"
747
769
  else:
748
770
  iout += " 1 1 1"
749
771
 
750
772
  if (
751
773
  velocity is not None
752
- and isinstance(ndarray2list(velocity[natom_tot]), (list, tuple))
753
- and len(velocity[natom_tot]) == 3
774
+ and isinstance(ndarray2list(velocity[iatomtype]), (list, tuple))
775
+ and len(velocity[iatomtype]) == 3
754
776
  ):
755
- iout += " v " + " ".join([f"{ii:.12f}" for ii in velocity[natom_tot]])
777
+ iout += " v " + " ".join([f"{ii:.12f}" for ii in velocity[iatomtype]])
756
778
 
757
779
  if mag is not None:
758
- if isinstance(ndarray2list(mag[natom_tot]), (list, tuple)) and len(
759
- mag[natom_tot]
780
+ if isinstance(ndarray2list(mag[iatomtype]), (list, tuple)) and len(
781
+ mag[iatomtype]
760
782
  ) in [1, 3]:
761
- iout += " mag " + " ".join([f"{ii:.12f}" for ii in mag[natom_tot]])
762
- elif isinstance(ndarray2list(mag[natom_tot]), (int, float)):
763
- 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}"
764
786
 
765
787
  if angle1 is not None and isinstance(
766
- ndarray2list(angle1[natom_tot]), (int, float)
788
+ ndarray2list(angle1[iatomtype]), (int, float)
767
789
  ):
768
- iout += " angle1 " + f"{angle1[natom_tot]:.12f}"
790
+ iout += " angle1 " + f"{angle1[iatomtype]:.12f}"
769
791
 
770
792
  if angle2 is not None and isinstance(
771
- ndarray2list(angle2[natom_tot]), (int, float)
793
+ ndarray2list(angle2[iatomtype]), (int, float)
772
794
  ):
773
- iout += " angle2 " + f"{angle2[natom_tot]:.12f}"
795
+ iout += " angle2 " + f"{angle2[iatomtype]:.12f}"
774
796
 
775
797
  if sc is not None:
776
- if isinstance(ndarray2list(sc[natom_tot]), (list, tuple)) and len(
777
- sc[natom_tot]
798
+ if isinstance(ndarray2list(sc[iatomtype]), (list, tuple)) and len(
799
+ sc[iatomtype]
778
800
  ) in [1, 3]:
779
801
  iout += " sc " + " ".join(
780
- ["1" if ii else "0" for ii in sc[natom_tot]]
802
+ ["1" if ii else "0" for ii in sc[iatomtype]]
781
803
  )
782
- elif isinstance(ndarray2list(sc[natom_tot]), (int, float, bool)):
783
- 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"
784
806
 
785
807
  if lambda_ is not None:
786
- if isinstance(ndarray2list(lambda_[natom_tot]), (list, tuple)) and len(
787
- lambda_[natom_tot]
808
+ if isinstance(ndarray2list(lambda_[iatomtype]), (list, tuple)) and len(
809
+ lambda_[iatomtype]
788
810
  ) in [1, 3]:
789
811
  iout += " lambda " + " ".join(
790
- [f"{ii:.12f}" for ii in lambda_[natom_tot]]
812
+ [f"{ii:.12f}" for ii in lambda_[iatomtype]]
791
813
  )
792
- elif isinstance(ndarray2list(lambda_[natom_tot]), (int, float)):
793
- iout += " lambda " + f"{lambda_[natom_tot]:.12f}"
814
+ elif isinstance(ndarray2list(lambda_[iatomtype]), (int, float)):
815
+ iout += " lambda " + f"{lambda_[iatomtype]:.12f}"
794
816
 
795
817
  out += iout + "\n"
796
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,
@@ -1102,9 +1102,9 @@ class System:
1102
1102
  all_dtypes = cls.DTYPES + tuple(data_type)
1103
1103
  dtypes_dict = {}
1104
1104
  for dt in all_dtypes:
1105
- if dt.name in dtypes_dict:
1105
+ if dt.name in dtypes_dict and dt != dtypes_dict[dt.name]:
1106
1106
  warnings.warn(
1107
- 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.",
1108
1108
  UserWarning,
1109
1109
  )
1110
1110
  dtypes_dict[dt.name] = dt
@@ -6,31 +6,93 @@ import warnings
6
6
  import numpy as np
7
7
 
8
8
 
9
- def system_info(lines, type_idx_zero=False):
9
+ def atom_name_from_potcar_string(instr: str) -> str:
10
+ """Get atom name from a potcar element name.
11
+
12
+ e.g. Sn_d -> Sn
13
+
14
+ Parameters
15
+ ----------
16
+ instr : str
17
+ input potcar elemenet name
18
+
19
+ Returns
20
+ -------
21
+ name: str
22
+ name of atoms
23
+ """
24
+ if "_" in instr:
25
+ # for case like : TITEL = PAW_PBE Sn_d 06Sep2000
26
+ return instr.split("_")[0]
27
+ else:
28
+ return instr
29
+
30
+
31
+ def system_info(
32
+ lines: list[str],
33
+ type_idx_zero: bool = False,
34
+ ) -> tuple[list[str], list[int], np.ndarray, int | None, int | None]:
35
+ """Get system information from lines of an OUTCAR file.
36
+
37
+ Parameters
38
+ ----------
39
+ lines : list[str]
40
+ the lines of the OUTCAR file
41
+ type_idx_zero : bool
42
+ if true atom types starts from 0 otherwise from 1.
43
+
44
+ Returns
45
+ -------
46
+ atom_names: list[str]
47
+ name of atoms
48
+ atom_numbs: list[int]
49
+ number of atoms that have a certain name. same length as atom_names
50
+ atom_types: np.ndarray
51
+ type of each atom, the array has same lenght as number of atoms
52
+ nelm: optional[int]
53
+ the value of NELM parameter
54
+ nwrite: optional[int]
55
+ the value of NWRITE parameter
56
+ """
10
57
  atom_names = []
58
+ atom_names_potcar = []
11
59
  atom_numbs = None
12
60
  nelm = None
61
+ nwrite = None
13
62
  for ii in lines:
14
- ii_word_list = ii.split()
15
63
  if "TITEL" in ii:
16
64
  # get atom names from POTCAR info, tested only for PAW_PBE ...
65
+ # for case like : TITEL = PAW_PBE Sn_d 06Sep2000
17
66
  _ii = ii.split()[3]
18
- if "_" in _ii:
19
- # for case like : TITEL = PAW_PBE Sn_d 06Sep2000
20
- atom_names.append(_ii.split("_")[0])
21
- else:
22
- atom_names.append(_ii)
67
+ atom_names.append(atom_name_from_potcar_string(_ii))
68
+ elif "POTCAR:" in ii:
69
+ # get atom names from POTCAR info, tested only for PAW_PBE ...
70
+ # for case like : POTCAR: PAW_PBE Ti 08Apr2002
71
+ _ii = ii.split()[2]
72
+ atom_names_potcar.append(atom_name_from_potcar_string(_ii))
23
73
  # a stricker check for "NELM"; compatible with distingct formats in different versions(6 and older, newers_expect-to-work) of vasp
24
74
  elif nelm is None:
25
75
  m = re.search(r"NELM\s*=\s*(\d+)", ii)
26
76
  if m:
27
77
  nelm = int(m.group(1))
78
+ elif nwrite is None:
79
+ m = re.search(r"NWRITE\s*=\s*(\d+)", ii)
80
+ if m:
81
+ nwrite = int(m.group(1))
28
82
  if "ions per type" in ii:
29
83
  atom_numbs_ = [int(s) for s in ii.split()[4:]]
30
84
  if atom_numbs is None:
31
85
  atom_numbs = atom_numbs_
32
86
  else:
33
87
  assert atom_numbs == atom_numbs_, "in consistent numb atoms in OUTCAR"
88
+ if len(atom_names) == 0:
89
+ # try to use atom_names_potcar
90
+ if len(atom_names_potcar) == 0:
91
+ raise ValueError("cannot get atom names from potcar")
92
+ nnames = len(atom_names_potcar)
93
+ # the names are repeated. check if it is the case
94
+ assert atom_names_potcar[: nnames // 2] == atom_names_potcar[nnames // 2 :]
95
+ atom_names = atom_names_potcar[: nnames // 2]
34
96
  assert nelm is not None, "cannot find maximum steps for each SC iteration"
35
97
  assert atom_numbs is not None, "cannot find ion type info in OUTCAR"
36
98
  atom_names = atom_names[: len(atom_numbs)]
@@ -41,7 +103,7 @@ def system_info(lines, type_idx_zero=False):
41
103
  atom_types.append(idx)
42
104
  else:
43
105
  atom_types.append(idx + 1)
44
- return atom_names, atom_numbs, np.array(atom_types, dtype=int), nelm
106
+ return atom_names, atom_numbs, np.array(atom_types, dtype=int), nelm, nwrite
45
107
 
46
108
 
47
109
  def get_outcar_block(fp, ml=False):
@@ -57,12 +119,24 @@ def get_outcar_block(fp, ml=False):
57
119
  return blk
58
120
 
59
121
 
122
+ def check_outputs(coord, cell, force):
123
+ if len(force) == 0:
124
+ raise ValueError("cannot find forces in OUTCAR block")
125
+ if len(coord) == 0:
126
+ raise ValueError("cannot find coordinates in OUTCAR block")
127
+ if len(cell) == 0:
128
+ raise ValueError("cannot find cell in OUTCAR block")
129
+ return True
130
+
131
+
60
132
  # we assume that the force is printed ...
61
133
  def get_frames(fname, begin=0, step=1, ml=False, convergence_check=True):
62
134
  fp = open(fname)
63
135
  blk = get_outcar_block(fp)
64
136
 
65
- atom_names, atom_numbs, atom_types, nelm = system_info(blk, type_idx_zero=True)
137
+ atom_names, atom_numbs, atom_types, nelm, nwrite = system_info(
138
+ blk, type_idx_zero=True
139
+ )
66
140
  ntot = sum(atom_numbs)
67
141
 
68
142
  all_coords = []
@@ -78,9 +152,15 @@ def get_frames(fname, begin=0, step=1, ml=False, convergence_check=True):
78
152
  coord, cell, energy, force, virial, is_converge = analyze_block(
79
153
  blk, ntot, nelm, ml
80
154
  )
81
- if len(coord) == 0:
155
+ if energy is None:
82
156
  break
83
- if is_converge or not convergence_check:
157
+ if nwrite == 0:
158
+ has_label = len(force) > 0 and len(coord) > 0 and len(cell) > 0
159
+ if not has_label:
160
+ warnings.warn("cannot find labels in the frame, ingore")
161
+ else:
162
+ has_label = check_outputs(coord, cell, force)
163
+ if (is_converge or not convergence_check) and has_label:
84
164
  all_coords.append(coord)
85
165
  all_cells.append(cell)
86
166
  all_energies.append(energy)
@@ -144,12 +224,6 @@ def analyze_block(lines, ntot, nelm, ml=False):
144
224
  is_converge = False
145
225
  elif energy_token[ml_index] in ii:
146
226
  energy = float(ii.split()[energy_index[ml_index]])
147
- if len(force) == 0:
148
- raise ValueError("cannot find forces in OUTCAR block")
149
- if len(coord) == 0:
150
- raise ValueError("cannot find coordinates in OUTCAR block")
151
- if len(cell) == 0:
152
- raise ValueError("cannot find cell in OUTCAR block")
153
227
  return coord, cell, energy, force, virial, is_converge
154
228
  elif cell_token[ml_index] in ii:
155
229
  for dd in range(3):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dpdata
3
- Version: 0.2.24
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>
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes