pymdkit 1.7.6__tar.gz → 1.7.7__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 (110) hide show
  1. {pymdkit-1.7.6 → pymdkit-1.7.7}/CHANGELOG.md +41 -35
  2. {pymdkit-1.7.6/src/pymdkit.egg-info → pymdkit-1.7.7}/PKG-INFO +57 -10
  3. {pymdkit-1.7.6 → pymdkit-1.7.7}/README.md +56 -9
  4. {pymdkit-1.7.6 → pymdkit-1.7.7}/pyproject.toml +1 -1
  5. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/__init__.py +1 -1
  6. pymdkit-1.7.7/src/pymdkit/commands/_dope_optimize.py +322 -0
  7. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/convert.py +3 -0
  8. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/dope.py +24 -2
  9. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/gpumd_job.py +117 -106
  10. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/supercell.py +34 -12
  11. {pymdkit-1.7.6 → pymdkit-1.7.7/src/pymdkit.egg-info}/PKG-INFO +57 -10
  12. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit.egg-info/SOURCES.txt +2 -0
  13. pymdkit-1.7.7/tests/test_dope_performance.py +201 -0
  14. pymdkit-1.7.7/tests/test_gpumd_job_fixes.py +176 -0
  15. pymdkit-1.7.6/src/pymdkit/commands/_dope_optimize.py +0 -146
  16. {pymdkit-1.7.6 → pymdkit-1.7.7}/LICENSE +0 -0
  17. {pymdkit-1.7.6 → pymdkit-1.7.7}/MANIFEST.in +0 -0
  18. {pymdkit-1.7.6 → pymdkit-1.7.7}/setup.cfg +0 -0
  19. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/_config.py +0 -0
  20. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/_logging.py +0 -0
  21. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/__init__.py +0 -0
  22. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_cifio.py +0 -0
  23. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_dope_certify.py +0 -0
  24. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_extxyz.py +0 -0
  25. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_fileio.py +0 -0
  26. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_geometry.py +0 -0
  27. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd.py +0 -0
  28. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd_final_structure.py +0 -0
  29. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd_msd.py +0 -0
  30. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd_run.py +0 -0
  31. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd_status.py +0 -0
  32. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_gpumd_thermo.py +0 -0
  33. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_ionhop.py +0 -0
  34. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_lattice.py +0 -0
  35. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_auto.py +0 -0
  36. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_conductivity.py +0 -0
  37. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_coordinates.py +0 -0
  38. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_fit.py +0 -0
  39. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_io.py +0 -0
  40. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_provenance.py +0 -0
  41. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_range.py +0 -0
  42. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_reuse.py +0 -0
  43. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_thermo.py +0 -0
  44. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_msd_uncertainty.py +0 -0
  45. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_oxidation.py +0 -0
  46. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_parallel.py +0 -0
  47. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_precision.py +0 -0
  48. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_pred_msd_plan.py +0 -0
  49. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_pred_msd_reference.py +0 -0
  50. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_reduction.py +0 -0
  51. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_submit.py +0 -0
  52. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_submit_vasp.py +0 -0
  53. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_supercell.py +0 -0
  54. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_symmetry.py +0 -0
  55. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_vasp_ehull.py +0 -0
  56. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_vasp_final_structure.py +0 -0
  57. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_vasp_nep.py +0 -0
  58. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_vasp_output.py +0 -0
  59. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/_vaspset.py +0 -0
  60. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/chemsys_entry.py +0 -0
  61. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/compute_rmsd.py +0 -0
  62. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/config.py +0 -0
  63. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/ewald.py +0 -0
  64. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/gpumd_out.py +0 -0
  65. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/ionhop.py +0 -0
  66. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/msd.py +0 -0
  67. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/nep_rmse.py +0 -0
  68. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/perturb.py +0 -0
  69. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/pred_msd_time.py +0 -0
  70. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/rd.py +0 -0
  71. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/realloc_occ.py +0 -0
  72. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/submit.py +0 -0
  73. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/trjconv.py +0 -0
  74. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/vasp_job.py +0 -0
  75. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/commands/vasp_out.py +0 -0
  76. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit/pymdkit_main.py +0 -0
  77. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit.egg-info/dependency_links.txt +0 -0
  78. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit.egg-info/entry_points.txt +0 -0
  79. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit.egg-info/requires.txt +0 -0
  80. {pymdkit-1.7.6 → pymdkit-1.7.7}/src/pymdkit.egg-info/top_level.txt +0 -0
  81. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/data/88-Li2YCl3-63-d1.cif +0 -0
  82. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_config_logging.py +0 -0
  83. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_convert.py +0 -0
  84. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_dope_certify.py +0 -0
  85. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_dope_optimize.py +0 -0
  86. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_ehull.py +0 -0
  87. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_gpumd_out.py +0 -0
  88. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_ionhop.py +0 -0
  89. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_lattice_symmetry.py +0 -0
  90. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_auto.py +0 -0
  91. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_fit.py +0 -0
  92. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_large.py +0 -0
  93. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_phase3.py +0 -0
  94. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_range.py +0 -0
  95. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_reuse.py +0 -0
  96. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_msd_uncertainty.py +0 -0
  97. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_parallel.py +0 -0
  98. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_pred_msd_time.py +0 -0
  99. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_progress.py +0 -0
  100. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_realloc_occ.py +0 -0
  101. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_rmsd_gpu.py +0 -0
  102. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_rmsd_max.py +0 -0
  103. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_rmsd_two_folder.py +0 -0
  104. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_submit.py +0 -0
  105. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_v165.py +0 -0
  106. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_v170_job_infrastructure.py +0 -0
  107. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_v170_vasp_consolidation.py +0 -0
  108. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_v172_vasp_writing.py +0 -0
  109. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_vasp_out.py +0 -0
  110. {pymdkit-1.7.6 → pymdkit-1.7.7}/tests/test_vaspset.py +0 -0
@@ -1,35 +1,41 @@
1
- # Changelog
2
-
3
- ## 1.7.5
4
-
5
- - `pmk msd` reuses validated full-trajectory and range results with version-1
6
- provenance, including compatible 1.7.4 results. Newly calculated and reused
7
- results share the total-only batch summaries, with rollback if publication
8
- fails.
9
- - Add `pmk ionhop` for iodine-aligned Li site hopping in GPUMD trajectories,
10
- with single and multi-temperature modes and nearest-neighbor hop frequencies.
11
- SciPy is a direct dependency for the cKDTree CPU backend.
12
-
13
- ## 1.7.4
14
-
15
- - `pmk msd -ne` retains finite, positive Einstein diffusion coefficients and
16
- Nernst–Einstein conductivity when the fit-quality diagnostics would reject the
17
- window. The result is reported and aggregated as WARNING, with the original
18
- diagnostic details preserved. This applies to automatic and manual windows.
19
- - Missing valid regression, failed requested estimators, and invalid NE inputs
20
- still fail the calculation and preserve existing aggregate summaries.
21
-
22
- ## 1.7.3
23
-
24
- - `pmk msd` analyzes fixed-cell GPUMD NVT trajectories, selects or accepts a
25
- fitting window, and optionally reports Nernst–Einstein conductivity. It uses
26
- free-intercept OLS by default. Optional WLS and GLS also estimate the intercept.
27
- Forced-origin fitting has been removed from production.
28
- - `pmk pred-msd-time` uses validated full-trajectory OLS references to forecast
29
- higher-temperature Li conductivity, diffusion, and NVT production duration.
30
- The Arrhenius forecast and square-root duration scaling are planning heuristics.
31
- The durations carry no guarantee of MSD convergence.
32
- - `pmk gpumd-job -msd-time` generates GPUMD 4.2-compatible jobs with explicit
33
- NVT temperatures, run lengths, and optional `compute_msd` sample counts.
34
- Fixed-cell NVT production is required for MSD analysis. Earlier NPT equilibration
35
- is supported when its frames are excluded from the analyzed trajectory.
1
+ # Changelog
2
+
3
+ ## 1.7.7
4
+
5
+ - Speed up automatic dope exchange scoring using exact incremental distances and bounded two-dimensional work arrays.
6
+ - Add deterministic shared-memory restart multiprocessing through `--n-jobs` (default 1), preserving search budgets and optional MILP certification.
7
+ - Restart seed streams change from 1.7.6; worker counts produce equivalent selections.
8
+
9
+ ## 1.7.5
10
+
11
+ - `pmk msd` reuses validated full-trajectory and range results with version-1
12
+ provenance, including compatible 1.7.4 results. Newly calculated and reused
13
+ results share the total-only batch summaries, with rollback if publication
14
+ fails.
15
+ - Add `pmk ionhop` for iodine-aligned Li site hopping in GPUMD trajectories,
16
+ with single and multi-temperature modes and nearest-neighbor hop frequencies.
17
+ SciPy is a direct dependency for the cKDTree CPU backend.
18
+
19
+ ## 1.7.4
20
+
21
+ - `pmk msd -ne` retains finite, positive Einstein diffusion coefficients and
22
+ Nernst–Einstein conductivity when the fit-quality diagnostics would reject the
23
+ window. The result is reported and aggregated as WARNING, with the original
24
+ diagnostic details preserved. This applies to automatic and manual windows.
25
+ - Missing valid regression, failed requested estimators, and invalid NE inputs
26
+ still fail the calculation and preserve existing aggregate summaries.
27
+
28
+ ## 1.7.3
29
+
30
+ - `pmk msd` analyzes fixed-cell GPUMD NVT trajectories, selects or accepts a
31
+ fitting window, and optionally reports Nernst–Einstein conductivity. It uses
32
+ free-intercept OLS by default. Optional WLS and GLS also estimate the intercept.
33
+ Forced-origin fitting has been removed from production.
34
+ - `pmk pred-msd-time` uses validated full-trajectory OLS references to forecast
35
+ higher-temperature Li conductivity, diffusion, and NVT production duration.
36
+ The Arrhenius forecast and square-root duration scaling are planning heuristics.
37
+ The durations carry no guarantee of MSD convergence.
38
+ - `pmk gpumd-job -msd-time` generates GPUMD 4.2-compatible jobs with explicit
39
+ NVT temperatures, run lengths, and optional `compute_msd` sample counts.
40
+ Fixed-cell NVT production is required for MSD analysis. Earlier NPT equilibration
41
+ is supported when its frames are excluded from the analyzed trajectory.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pymdkit
3
- Version: 1.7.6
3
+ Version: 1.7.7
4
4
  Summary: A Python command-line toolkit for high-throughput atomistic workflows in AI-driven materials design.
5
5
  Author-email: Yueda Wang <ydwang0608@ustc.edu.cn>
6
6
  License-Expression: GPL-3.0-or-later
@@ -37,6 +37,30 @@ materials design. Install `pymdkit` once and call its tools from anywhere as
37
37
  Commands expose explicit, documented CLI interfaces designed for reproducible shell,
38
38
  HPC, and AI-agent workflows, and each underlying script is still runnable on its own.
39
39
 
40
+ ## 1.7.7 release notes
41
+
42
+ - Automatic `pmk dope` uses exact incremental exchange scores and bounded 2D
43
+ work arrays, preserving the three ranking metrics and search budgets.
44
+ - `--n-jobs N` runs independent restarts in N processes (default: 1).
45
+ Choose N for your CPU allocation; large problems benefit most and speedup
46
+ need not be proportional. This does not set MILP solver threads.
47
+ - Restart seeds now use `SeedSequence.spawn`: results are reproducible across
48
+ worker counts, but a seed need not reproduce the 1.7.6 configurations.
49
+ - Exact enumeration stays serial. Summary metadata reports actual workers,
50
+ timings (worker times are summed), sweeps, and attempted/accepted exchanges.
51
+
52
+ ```powershell
53
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies -ref vac vac -seed 42 --n-jobs 1
54
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies-n4 -ref vac vac -seed 42 --n-jobs 4
55
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies-n8 -ref vac vac -seed 42 --n-jobs 8
56
+ ```
57
+
58
+ Values above 1 require automatic optimization; ordinary generation and legacy
59
+ removal reject them. One process creates no workers. The float64 distance matrix
60
+ is shared read-only; workers return candidates and the parent writes and validates
61
+ outputs. Optional threadpoolctl limits numerical threads within each worker.
62
+ `--certify-optimum` and `--certify-time-limit` retain their existing meaning.
63
+
40
64
  ## 1.7.6 release notes
41
65
 
42
66
  - `pmk dope -ref ELEMENT ELEMENT` now optimizes minimum periodic separation
@@ -125,7 +149,7 @@ installed.
125
149
  On a machine with Internet access, run:
126
150
 
127
151
  ```bash
128
- python -m pip download pymdkit==1.7.6 -d pymdkit-offline
152
+ python -m pip download pymdkit==1.7.7 -d pymdkit-offline
129
153
  ```
130
154
 
131
155
  This downloads `pymdkit` and the dependencies resolved by pip into the
@@ -133,14 +157,14 @@ This downloads `pymdkit` and the dependencies resolved by pip into the
133
157
  system. Then, inside the target pymdkit Python or conda environment, run:
134
158
 
135
159
  ```bash
136
- python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.6
160
+ python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.7
137
161
  ```
138
162
 
139
163
  For optional GPU use, prepare the bundle on a networked machine compatible with
140
164
  the target HPC platform and Python environment:
141
165
 
142
166
  ```bash
143
- python -m pip download "pymdkit[gpu-cuda12]==1.7.6" -d pymdkit-offline
167
+ python -m pip download "pymdkit[gpu-cuda12]==1.7.7" -d pymdkit-offline
144
168
  ```
145
169
 
146
170
  Transfer the whole `pymdkit-offline` directory, then install from it on the
@@ -148,7 +172,7 @@ target system:
148
172
 
149
173
  ```bash
150
174
  python -m pip install --no-index --find-links=pymdkit-offline \
151
- "pymdkit[gpu-cuda12]==1.7.6"
175
+ "pymdkit[gpu-cuda12]==1.7.7"
152
176
  ```
153
177
 
154
178
  This GPU bundle includes the optional `cupy-cuda12x` package. Its wheels must also
@@ -258,8 +282,8 @@ pmk supercell -i model.vasp -o model-sc.vasp -matrix 1x1x2
258
282
  pmk supercell -if structures -of capped -max-abc 40
259
283
  pmk supercell -if structures -of close -close-abc 50
260
284
 
261
- pmk gpumd-job -if Li3YCl6-all -supercell-close-abc 50 -nep nep.txt -in run.in -temp 300 320 340 360 -group Li Y Cl
262
- pmk gpumd-job -it train.xyz -supercell-matrix 2x2x2 -nep nep.txt -group Li Y Cl
285
+ pmk gpumd-job -if Li3YCl6-all -supercell-close-abc 50 -nep nep.txt -in run.in -temp 300 320 340 360 -group Li Y Cl -pos-only no
286
+ pmk gpumd-job -it train.xyz -supercell-matrix 2x2x2 -nep nep.txt -group Li Y Cl -pos-only no
263
287
  pmk submit -gpumd
264
288
  pmk submit -gpumd -subscript custom_gpumd.pbs -queue pbs -max-job-num 30
265
289
 
@@ -420,9 +444,32 @@ once globally and the selection is then partitioned by Config_type.
420
444
  and `-in` default to `nep.txt` and `run.in` in the invocation directory. Each
421
445
  job receives `model.xyz` as extxyz, the potential as `nep.txt`, and the input as
422
446
  `run.in`; the `potential` line is synchronized to `nep.txt`. With `-temp`, PMK
423
- creates `<structure>/<T>/`, replaces every `target_t` token with T, applies
424
- `-group` to all model files, and normalizes `npt_scr` pressure components for
425
- the actual orthorhombic or triclinic cell. In `-if` mode, an existing final job
447
+ creates `<structure>/<T>/` and replaces every `target_t` token with T.
448
+ `-pos-only yes` is the default: each model has exactly
449
+ `Properties=species:S:1:pos:R:3` and four fields per atom (species, x, y, z).
450
+ Cell, PBC, coordinates and atom order are retained; momenta, forces, group labels
451
+ and all other per-atom properties are omitted. Use `-pos-only no` to retain the
452
+ previous full-property writer, including labels assigned with `-group`.
453
+
454
+ ```bash
455
+ pmk gpumd-job -if opted-vasp -nep nep.txt -in run.in -temp 300 400 500 600
456
+ pmk gpumd-job -if opted-vasp -nep nep.txt -in run.in -temp 300 400 500 600 -pos-only no
457
+ ```
458
+
459
+ Explicit `npt_scr` pressure tokens, including zero and scientific notation, are
460
+ preserved. Cubic cells retain scalar pressure syntax and its elastic modulus and
461
+ coupling parameters. Non-cubic orthorhombic cells expand scalar pressure and modulus
462
+ into three matching components. Non-orthogonal cells use six components: scalar
463
+ pressure expands to three normal pressures and zero shear pressures, with the
464
+ specified modulus repeated. Existing complete directional controls are preserved;
465
+ when expanding three components to six, missing shear pressures are zero and
466
+ missing shear moduli use the established value 100. Cubic geometry requires angles
467
+ within 1e-4 degrees of 90 and a maximum length difference no greater than
468
+ `1e-6 A + 1e-5 * max(a,b,c)`. This is a cell-metric check, not a space-group analysis.
469
+ Only wholly absent pressure controls use the established defaults (`1e-04`, modulus
470
+ 100, coupling 1000); incomplete control lists report an error. Template files,
471
+ comments, and unrelated commands remain intact apart from the existing temperature
472
+ and potential-filename substitutions. In `-if` mode, an existing final job
426
473
  folder (including an empty one) is left untouched while missing siblings are
427
474
  still generated. With `-temp`, every structure/temperature folder is checked
428
475
  independently.
@@ -7,6 +7,30 @@ materials design. Install `pymdkit` once and call its tools from anywhere as
7
7
  Commands expose explicit, documented CLI interfaces designed for reproducible shell,
8
8
  HPC, and AI-agent workflows, and each underlying script is still runnable on its own.
9
9
 
10
+ ## 1.7.7 release notes
11
+
12
+ - Automatic `pmk dope` uses exact incremental exchange scores and bounded 2D
13
+ work arrays, preserving the three ranking metrics and search budgets.
14
+ - `--n-jobs N` runs independent restarts in N processes (default: 1).
15
+ Choose N for your CPU allocation; large problems benefit most and speedup
16
+ need not be proportional. This does not set MILP solver threads.
17
+ - Restart seeds now use `SeedSequence.spawn`: results are reproducible across
18
+ worker counts, but a seed need not reproduce the 1.7.6 configurations.
19
+ - Exact enumeration stays serial. Summary metadata reports actual workers,
20
+ timings (worker times are summed), sweeps, and attempted/accepted exchanges.
21
+
22
+ ```powershell
23
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies -ref vac vac -seed 42 --n-jobs 1
24
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies-n4 -ref vac vac -seed 42 --n-jobs 4
25
+ pmk dope -i LiI-777.vasp -se Li -sn 392 -we vac -on 10 -o vacancies-n8 -ref vac vac -seed 42 --n-jobs 8
26
+ ```
27
+
28
+ Values above 1 require automatic optimization; ordinary generation and legacy
29
+ removal reject them. One process creates no workers. The float64 distance matrix
30
+ is shared read-only; workers return candidates and the parent writes and validates
31
+ outputs. Optional threadpoolctl limits numerical threads within each worker.
32
+ `--certify-optimum` and `--certify-time-limit` retain their existing meaning.
33
+
10
34
  ## 1.7.6 release notes
11
35
 
12
36
  - `pmk dope -ref ELEMENT ELEMENT` now optimizes minimum periodic separation
@@ -95,7 +119,7 @@ installed.
95
119
  On a machine with Internet access, run:
96
120
 
97
121
  ```bash
98
- python -m pip download pymdkit==1.7.6 -d pymdkit-offline
122
+ python -m pip download pymdkit==1.7.7 -d pymdkit-offline
99
123
  ```
100
124
 
101
125
  This downloads `pymdkit` and the dependencies resolved by pip into the
@@ -103,14 +127,14 @@ This downloads `pymdkit` and the dependencies resolved by pip into the
103
127
  system. Then, inside the target pymdkit Python or conda environment, run:
104
128
 
105
129
  ```bash
106
- python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.6
130
+ python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.7
107
131
  ```
108
132
 
109
133
  For optional GPU use, prepare the bundle on a networked machine compatible with
110
134
  the target HPC platform and Python environment:
111
135
 
112
136
  ```bash
113
- python -m pip download "pymdkit[gpu-cuda12]==1.7.6" -d pymdkit-offline
137
+ python -m pip download "pymdkit[gpu-cuda12]==1.7.7" -d pymdkit-offline
114
138
  ```
115
139
 
116
140
  Transfer the whole `pymdkit-offline` directory, then install from it on the
@@ -118,7 +142,7 @@ target system:
118
142
 
119
143
  ```bash
120
144
  python -m pip install --no-index --find-links=pymdkit-offline \
121
- "pymdkit[gpu-cuda12]==1.7.6"
145
+ "pymdkit[gpu-cuda12]==1.7.7"
122
146
  ```
123
147
 
124
148
  This GPU bundle includes the optional `cupy-cuda12x` package. Its wheels must also
@@ -228,8 +252,8 @@ pmk supercell -i model.vasp -o model-sc.vasp -matrix 1x1x2
228
252
  pmk supercell -if structures -of capped -max-abc 40
229
253
  pmk supercell -if structures -of close -close-abc 50
230
254
 
231
- pmk gpumd-job -if Li3YCl6-all -supercell-close-abc 50 -nep nep.txt -in run.in -temp 300 320 340 360 -group Li Y Cl
232
- pmk gpumd-job -it train.xyz -supercell-matrix 2x2x2 -nep nep.txt -group Li Y Cl
255
+ pmk gpumd-job -if Li3YCl6-all -supercell-close-abc 50 -nep nep.txt -in run.in -temp 300 320 340 360 -group Li Y Cl -pos-only no
256
+ pmk gpumd-job -it train.xyz -supercell-matrix 2x2x2 -nep nep.txt -group Li Y Cl -pos-only no
233
257
  pmk submit -gpumd
234
258
  pmk submit -gpumd -subscript custom_gpumd.pbs -queue pbs -max-job-num 30
235
259
 
@@ -390,9 +414,32 @@ once globally and the selection is then partitioned by Config_type.
390
414
  and `-in` default to `nep.txt` and `run.in` in the invocation directory. Each
391
415
  job receives `model.xyz` as extxyz, the potential as `nep.txt`, and the input as
392
416
  `run.in`; the `potential` line is synchronized to `nep.txt`. With `-temp`, PMK
393
- creates `<structure>/<T>/`, replaces every `target_t` token with T, applies
394
- `-group` to all model files, and normalizes `npt_scr` pressure components for
395
- the actual orthorhombic or triclinic cell. In `-if` mode, an existing final job
417
+ creates `<structure>/<T>/` and replaces every `target_t` token with T.
418
+ `-pos-only yes` is the default: each model has exactly
419
+ `Properties=species:S:1:pos:R:3` and four fields per atom (species, x, y, z).
420
+ Cell, PBC, coordinates and atom order are retained; momenta, forces, group labels
421
+ and all other per-atom properties are omitted. Use `-pos-only no` to retain the
422
+ previous full-property writer, including labels assigned with `-group`.
423
+
424
+ ```bash
425
+ pmk gpumd-job -if opted-vasp -nep nep.txt -in run.in -temp 300 400 500 600
426
+ pmk gpumd-job -if opted-vasp -nep nep.txt -in run.in -temp 300 400 500 600 -pos-only no
427
+ ```
428
+
429
+ Explicit `npt_scr` pressure tokens, including zero and scientific notation, are
430
+ preserved. Cubic cells retain scalar pressure syntax and its elastic modulus and
431
+ coupling parameters. Non-cubic orthorhombic cells expand scalar pressure and modulus
432
+ into three matching components. Non-orthogonal cells use six components: scalar
433
+ pressure expands to three normal pressures and zero shear pressures, with the
434
+ specified modulus repeated. Existing complete directional controls are preserved;
435
+ when expanding three components to six, missing shear pressures are zero and
436
+ missing shear moduli use the established value 100. Cubic geometry requires angles
437
+ within 1e-4 degrees of 90 and a maximum length difference no greater than
438
+ `1e-6 A + 1e-5 * max(a,b,c)`. This is a cell-metric check, not a space-group analysis.
439
+ Only wholly absent pressure controls use the established defaults (`1e-04`, modulus
440
+ 100, coupling 1000); incomplete control lists report an error. Template files,
441
+ comments, and unrelated commands remain intact apart from the existing temperature
442
+ and potential-filename substitutions. In `-if` mode, an existing final job
396
443
  folder (including an empty one) is left untouched while missing siblings are
397
444
  still generated. With `-temp`, every structure/temperature folder is checked
398
445
  independently.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pymdkit"
7
- version = "1.7.6"
7
+ version = "1.7.7"
8
8
  description = "A Python command-line toolkit for high-throughput atomistic workflows in AI-driven materials design."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,3 +1,3 @@
1
1
  """A Python command-line toolkit for high-throughput atomistic workflows in AI-driven materials design."""
2
2
 
3
- __version__ = "1.7.6"
3
+ __version__ = "1.7.7"
@@ -0,0 +1,322 @@
1
+ """Bounded, seeded max-min site selection using pymatgen periodic geometry."""
2
+
3
+ import itertools
4
+ import math
5
+ import time
6
+ import multiprocessing
7
+ from multiprocessing import shared_memory
8
+ from concurrent.futures import ProcessPoolExecutor
9
+
10
+ import numpy as np
11
+
12
+
13
+ def packing_bound(volume, count):
14
+ return (6 * (math.pi / math.sqrt(18)) * volume / (count * math.pi)) ** (1 / 3)
15
+
16
+
17
+ def scores(matrix, configurations):
18
+ """Primary minimum, secondary mean NN, tertiary mean pair separation."""
19
+ # Keep the reference scorer bounded even for large batches.
20
+ result = []
21
+ for configuration in configurations:
22
+ indices = np.asarray(configuration, dtype=int)
23
+ distances = matrix[np.ix_(indices, indices)]
24
+ nearest = distances.min(axis=1)
25
+ result.append((nearest.min(), nearest.mean(),
26
+ distances[np.triu_indices(len(indices), 1)].mean()))
27
+ return np.asarray(result)
28
+
29
+
30
+ def greedy_sites(matrix, eligible_count, count, anchors, rng):
31
+ """Randomized farthest insertion; anchors remain fixed."""
32
+ selected = []
33
+ nearest = matrix[:eligible_count, anchors].min(axis=1) if anchors else np.full(eligible_count, np.inf)
34
+ available_mask = np.ones(eligible_count, dtype=bool)
35
+ for step in range(count):
36
+ available = np.flatnonzero(available_mask)
37
+ if step == 0 and not anchors:
38
+ pick = int(rng.choice(available))
39
+ else:
40
+ best = nearest[available].max()
41
+ pick = int(rng.choice(available[np.isclose(nearest[available], best, rtol=0, atol=1e-10)]))
42
+ selected.append(pick)
43
+ available_mask[pick] = False
44
+ np.minimum(nearest, matrix[:eligible_count, pick], out=nearest)
45
+ return selected
46
+
47
+
48
+ def exchange_state(matrix, selected, anchors, n):
49
+ """Exact primary scores [removal slot, unused site], using only 2D arrays.
50
+
51
+ Only endpoints of a global minimum pair can change the remaining minimum.
52
+ Partition retains repeated nearest distances. Both directions are included
53
+ because periodic geometry can differ by a last bit between triangles.
54
+ """
55
+ objective = np.asarray(list(selected) + list(anchors), dtype=int)
56
+ mask = np.ones(n, dtype=bool)
57
+ mask[selected] = False
58
+ unused = np.flatnonzero(mask)
59
+ block = matrix[np.ix_(objective, objective)]
60
+ outgoing = matrix[np.ix_(unused, objective)]
61
+ incoming = matrix[np.ix_(objective, unused)].T
62
+ distances = np.minimum(outgoing, incoming)
63
+ nearest_index = distances.argmin(axis=1)
64
+ two = np.partition(distances, 1, axis=1)[:, :2]
65
+ without = np.full(len(selected), block.min())
66
+ endpoints = np.unravel_index(block.argmin(), block.shape)
67
+ for slot in set(endpoints):
68
+ if slot < len(selected):
69
+ keep = np.arange(len(objective)) != slot
70
+ without[slot] = block[np.ix_(keep, keep)].min()
71
+ primary = np.broadcast_to(two[:, 0], (len(selected), len(unused))).copy()
72
+ for slot in range(len(selected)):
73
+ affected = nearest_index == slot
74
+ primary[slot, affected] = two[affected, 1]
75
+ np.minimum(primary, without[:, None], out=primary)
76
+ # Cache secondary reductions as well: after removal, only objective rows
77
+ # whose unique nearest neighbour was that slot can change their NN.
78
+ row_nearest = block.argmin(axis=1)
79
+ row_two = np.partition(block, 1, axis=1)[:, :2]
80
+ base_nn = np.minimum(incoming, row_two[:, 0]).sum(axis=1)
81
+ out_nearest = outgoing.argmin(axis=1)
82
+ out_two = np.partition(outgoing, 1, axis=1)[:, :2]
83
+ upper = np.triu(block, 1)
84
+ pair_without = upper.sum() - upper.sum(axis=0) - upper.sum(axis=1)
85
+ new_pair = np.cumsum(incoming, axis=1) - incoming
86
+ new_pair += np.cumsum(outgoing[:, ::-1], axis=1)[:, ::-1] - outgoing
87
+ pair_indices = np.triu_indices(len(objective), 1)
88
+ cache = row_nearest, row_two, base_nn, out_nearest, out_two, pair_without, new_pair, pair_indices
89
+ return objective, unused, block, outgoing, incoming, cache, primary
90
+
91
+
92
+ def exchange_scores(matrix, state, slot):
93
+ """Score primary contenders with O(U*K) secondary work, no U*K*K tensor."""
94
+ objective, unused, block, outgoing, incoming, cache, primary = state
95
+ candidates = np.flatnonzero(np.round(primary[slot], 10) == np.round(primary[slot], 10).max())
96
+ row_nearest, row_two, base_nn, out_nearest, out_two, pair_without, new_pair, pair_indices = cache
97
+ nn_sum = base_nn[candidates] - np.minimum(incoming[candidates, slot], row_two[slot, 0])
98
+ affected = np.flatnonzero((row_nearest == slot) & (row_two[:, 0] != row_two[:, 1]))
99
+ for row in affected:
100
+ nn_sum += (np.minimum(incoming[candidates, row], row_two[row, 1])
101
+ - np.minimum(incoming[candidates, row], row_two[row, 0]))
102
+ added_nearest = np.where(out_nearest[candidates] == slot,
103
+ out_two[candidates, 1], out_two[candidates, 0])
104
+ mean_nn = (nn_sum + added_nearest) / len(objective)
105
+ mean_pair = (pair_without[slot] + new_pair[candidates, slot]) / math.comb(len(objective), 2)
106
+ values = np.column_stack((primary[slot, candidates], mean_nn, mean_pair))
107
+ # Different summation orders can straddle a ten-decimal boundary. Only
108
+ # those ambiguous rows need the original reduction order.
109
+ scaled = values[:, 1:] * 1e10
110
+ # The old batched pair array was strided along its reduction axis:
111
+ # NumPy accumulated P pairs sequentially, unlike a contiguous pairwise
112
+ # sum. Include that legacy accumulation error in the boundary envelope.
113
+ tolerance = 32 * np.finfo(float).eps * np.maximum(1, np.abs(values[:, 1:]))
114
+ pairs = math.comb(len(objective), 2)
115
+ gamma = pairs * np.finfo(float).eps / (1 - pairs * np.finfo(float).eps)
116
+ tolerance[:, 1] += gamma * np.abs(mean_pair)
117
+ ambiguous = np.any(np.abs(scaled - np.floor(scaled) - .5) <= tolerance * 1e10, axis=1)
118
+ if np.any(ambiguous):
119
+ lower = np.round(values - np.column_stack((np.zeros(len(values)), tolerance)), 10)
120
+ upper = np.round(values + np.column_stack((np.zeros(len(values)), tolerance)), 10)
121
+ best_lower = max(map(tuple, lower))
122
+ ambiguous &= np.array([tuple(row) >= best_lower for row in upper])
123
+ for row in np.flatnonzero(ambiguous):
124
+ trial = objective.copy()
125
+ trial[slot] = unused[candidates[row]]
126
+ candidate = candidates[row]
127
+ nearest = np.where(row_nearest == slot, row_two[:, 1], row_two[:, 0])
128
+ np.minimum(nearest, incoming[candidate], out=nearest)
129
+ nearest[slot] = added_nearest[row]
130
+ left, right = pair_indices
131
+ pair_values = matrix[trial[left], trial[right]]
132
+ # cumsum is sequential, matching the old strided batched mean;
133
+ # its one-candidate special case used a contiguous pairwise mean.
134
+ pair_mean = (pair_values.cumsum()[-1] / pairs if len(unused) > 1
135
+ else pair_values.mean())
136
+ values[row] = nearest.min(), nearest.mean(), pair_mean
137
+ return unused[candidates], values
138
+
139
+
140
+ def _restart(matrix, n, count, anchors, sweeps, seed):
141
+ rng = np.random.default_rng(seed)
142
+ started = time.perf_counter()
143
+ selected = greedy_sites(matrix, n, count, anchors, rng)
144
+ construction = time.perf_counter() - started
145
+ initial = tuple(sorted(selected))
146
+ pool = {initial: tuple(scores(matrix, [list(initial) + anchors])[0])}
147
+ attempts = accepted = iterations = evaluations = 0
148
+ state = None
149
+ current = scores(matrix, [selected + anchors])[0]
150
+ started = time.perf_counter()
151
+ for _ in range(sweeps):
152
+ iterations += 1
153
+ improved = False
154
+ for slot in rng.permutation(count):
155
+ if count == n:
156
+ break
157
+ if state is None:
158
+ state = exchange_state(matrix, selected, anchors, n)
159
+ attempts += len(state[1])
160
+ unused, values = exchange_scores(matrix, state, slot)
161
+ evaluations += len(values)
162
+ rounded = np.round(values, 10)
163
+ best = np.lexsort((-rounded[:, 2], -rounded[:, 1], -rounded[:, 0]))[0]
164
+ if tuple(rounded[best]) > tuple(np.round(current, 10)):
165
+ selected[slot] = int(unused[best])
166
+ current = scores(matrix, [selected + anchors])[0]
167
+ accepted += 1
168
+ improved = True
169
+ state = None
170
+ if not improved:
171
+ break
172
+ final = tuple(sorted(selected))
173
+ pool[final] = tuple(scores(matrix, [list(final) + anchors])[0])
174
+ return pool, dict(construction_seconds=construction,
175
+ local_search_seconds=time.perf_counter() - started,
176
+ local_sweeps=iterations, attempted_exchanges=attempts,
177
+ accepted_exchanges=accepted, score_evaluations=evaluations + accepted + 3)
178
+
179
+
180
+ def _worker_restart(task):
181
+ name, shape, n, count, anchors, sweeps, seed = task
182
+ memory = shared_memory.SharedMemory(name=name)
183
+ try:
184
+ matrix = np.ndarray(shape, dtype=np.float64, buffer=memory.buf)
185
+ matrix.flags.writeable = False
186
+ # Optional dependency; this path otherwise uses reductions, not BLAS.
187
+ try:
188
+ from threadpoolctl import threadpool_limits
189
+ except ImportError:
190
+ return _restart(matrix, n, count, anchors, sweeps, seed)
191
+ with threadpool_limits(limits=1):
192
+ return _restart(matrix, n, count, anchors, sweeps, seed)
193
+ finally:
194
+ memory.close()
195
+
196
+
197
+ def _restarts(matrix, n, count, anchors, sweeps, seeds, n_jobs):
198
+ if n_jobs == 1:
199
+ return [_restart(matrix, n, count, anchors, sweeps, seed) for seed in seeds]
200
+ memory = shared_memory.SharedMemory(create=True, size=matrix.nbytes)
201
+ try:
202
+ shared = np.ndarray(matrix.shape, dtype=np.float64, buffer=memory.buf)
203
+ shared[:] = matrix
204
+ tasks = [(memory.name, matrix.shape, n, count, anchors, sweeps, seed) for seed in seeds]
205
+ with ProcessPoolExecutor(max_workers=min(n_jobs, len(seeds)),
206
+ mp_context=multiprocessing.get_context('spawn')) as executor:
207
+ return list(executor.map(_worker_restart, tasks))
208
+ finally:
209
+ memory.close()
210
+ memory.unlink()
211
+
212
+
213
+ def optimize_sites(structure, eligible, count, fixed=(), requested=1, seed=None,
214
+ restarts=None, sweeps=None, exact_limit=2000,
215
+ certify=False, certify_time_limit=120, n_jobs=1):
216
+ """Return ranked (original indices, scores) and search diagnostics.
217
+
218
+ Only small spaces are enumerated. Large spaces use randomized farthest
219
+ insertion and bounded best one-site exchanges. Memory per worker is O(M*N + N^2); the O(M^2) matrix is shared.
220
+ Scores are rounded to 10 decimal places ONLY for ranking numerical ties.
221
+ """
222
+ if isinstance(n_jobs, bool) or not isinstance(n_jobs, int) or n_jobs < 1:
223
+ raise ValueError("n_jobs must be a positive integer")
224
+ eligible, fixed = sorted(eligible), sorted(fixed)
225
+ n = len(eligible)
226
+ if not 0 < count <= n or requested < 1:
227
+ raise ValueError("selection count and requested output count must be positive and feasible")
228
+ if len(set(eligible + fixed)) != len(eligible) + len(fixed):
229
+ raise ValueError("eligible and fixed sites must be distinct")
230
+ if count + len(fixed) < 2:
231
+ raise ValueError("separation optimization requires at least two objective sites")
232
+ started = time.perf_counter()
233
+ coords = structure.frac_coords[eligible + fixed]
234
+ matrix = structure.lattice.get_all_distances(coords, coords)
235
+ np.fill_diagonal(matrix, np.inf)
236
+ anchors = list(range(n, n + len(fixed)))
237
+ matrix_seconds = time.perf_counter() - started
238
+ total = math.comb(n, count)
239
+ restarts = restarts if restarts is not None else max(4 * requested, 8 * math.ceil(n / count))
240
+ sweeps = sweeps if sweeps is not None else 2 * count
241
+ if restarts < 1 or sweeps < 1:
242
+ raise ValueError("search budgets must be positive")
243
+ pool = {}
244
+ evaluations = 0
245
+
246
+ def evaluate(configurations):
247
+ nonlocal evaluations
248
+ evaluations += len(configurations)
249
+ return scores(matrix, configurations)
250
+
251
+ def retain(selected):
252
+ key = tuple(sorted(selected))
253
+ if key not in pool:
254
+ pool[key] = tuple(evaluate([list(key) + anchors])[0])
255
+
256
+ counters = {}
257
+ restart_seconds = merge_seconds = 0.0
258
+ exact = total <= exact_limit
259
+ if exact:
260
+ for selected in itertools.combinations(range(n), count):
261
+ retain(selected)
262
+ else:
263
+ seeds = np.random.SeedSequence(seed).spawn(restarts)
264
+ started = time.perf_counter()
265
+ results = _restarts(matrix, n, count, anchors, sweeps, seeds, n_jobs)
266
+ restart_seconds = time.perf_counter() - started
267
+ started = time.perf_counter()
268
+ for candidates, diagnostics in results:
269
+ pool.update(candidates)
270
+ for name, value in diagnostics.items():
271
+ counters[name] = counters.get(name, 0) + value
272
+ evaluations = counters.pop('score_evaluations')
273
+ merge_seconds = time.perf_counter() - started
274
+ certificate = None
275
+ if certify:
276
+ try:
277
+ from ._dope_certify import certify_sites
278
+ except ImportError:
279
+ from _dope_certify import certify_sites
280
+ best = max(pool, key=lambda key: pool[key][0])
281
+ additions, certificate = certify_sites(matrix, n, count, best,
282
+ certify_time_limit, enumerated=exact)
283
+ for selected in additions:
284
+ retain(selected)
285
+ started = time.perf_counter()
286
+ ranked = sorted(pool, key=lambda key: tuple(-v for v in np.round(pool[key], 10)) + key)
287
+ # Prefer less overlap within score ties, without sacrificing separation.
288
+ chosen = []
289
+ for _, group in itertools.groupby(ranked, key=lambda key: tuple(np.round(pool[key], 10))):
290
+ tied = list(group)
291
+ while tied and len(chosen) < requested:
292
+ key = min(tied, key=lambda k: (max((len(set(k) & set(p)) for p in chosen), default=0), k))
293
+ chosen.append(key)
294
+ tied.remove(key)
295
+ if len(chosen) >= requested:
296
+ break
297
+ if certificate is not None:
298
+ best_key = tuple(certificate['best_local_indices'])
299
+ if best_key not in chosen:
300
+ chosen[-1] = best_key
301
+ chosen.sort(key=lambda key: tuple(-v for v in np.round(pool[key], 10)) + key)
302
+ ranking_seconds = time.perf_counter() - started
303
+ bound = packing_bound(structure.volume, count + len(fixed))
304
+ # Distinct-pair MIC excludes a site's own images. Sphere packing bounds
305
+ # that objective only if self images cannot overlap at the stated bound.
306
+ reduced = structure.lattice.get_lll_reduced_lattice()
307
+ images = reduced.get_points_in_sphere([[0, 0, 0]], [0, 0, 0], min(reduced.abc) + 1e-8)
308
+ shortest = min(float(item[1]) for item in images if item[1] > 1e-8)
309
+ metadata = dict(method="exact enumeration" if exact else "multi-start farthest insertion + one-site exchanges (best-found)",
310
+ termination="all combinations enumerated" if exact else "finite restart budget exhausted",
311
+ total_combinations=total, unique_candidates=len(pool), score_evaluations=evaluations,
312
+ restarts=0 if exact else restarts,
313
+ sweep_budget=sweeps, upper_bound=bound, packing_bound_applicable=shortest >= bound - 1e-10,
314
+ shortest_self_image=shortest, objective_sites=count + len(fixed), fixed_indices=fixed)
315
+ metadata.update(counters, distance_matrix_seconds=matrix_seconds,
316
+ restart_seconds=restart_seconds, merge_seconds=merge_seconds,
317
+ ranking_seconds=ranking_seconds, n_jobs=n_jobs,
318
+ workers_used=0 if exact else min(n_jobs, restarts),
319
+ seed_policy='SeedSequence.spawn in restart order')
320
+ if certificate is not None:
321
+ metadata['certification'] = certificate
322
+ return [(tuple(eligible[i] for i in key), pool[key]) for key in chosen], metadata