pymdkit 1.7.5__tar.gz → 1.7.6__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.
- {pymdkit-1.7.5/src/pymdkit.egg-info → pymdkit-1.7.6}/PKG-INFO +114 -6
- {pymdkit-1.7.5 → pymdkit-1.7.6}/README.md +113 -5
- {pymdkit-1.7.5 → pymdkit-1.7.6}/pyproject.toml +1 -1
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/__init__.py +1 -1
- pymdkit-1.7.6/src/pymdkit/commands/_dope_certify.py +145 -0
- pymdkit-1.7.6/src/pymdkit/commands/_dope_optimize.py +146 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd_msd.py +11 -11
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_conductivity.py +19 -19
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/dope.py +168 -67
- {pymdkit-1.7.5 → pymdkit-1.7.6/src/pymdkit.egg-info}/PKG-INFO +114 -6
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit.egg-info/SOURCES.txt +4 -0
- pymdkit-1.7.6/tests/test_dope_certify.py +155 -0
- pymdkit-1.7.6/tests/test_dope_optimize.py +207 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/CHANGELOG.md +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/LICENSE +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/MANIFEST.in +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/setup.cfg +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/_config.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/_logging.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/__init__.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_cifio.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_extxyz.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_fileio.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_geometry.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd_final_structure.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd_run.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd_status.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_gpumd_thermo.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_ionhop.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_lattice.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_auto.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_coordinates.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_fit.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_io.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_provenance.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_range.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_reuse.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_thermo.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_msd_uncertainty.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_oxidation.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_parallel.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_precision.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_pred_msd_plan.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_pred_msd_reference.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_reduction.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_submit.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_submit_vasp.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_supercell.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_symmetry.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_vasp_ehull.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_vasp_final_structure.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_vasp_nep.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_vasp_output.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/_vaspset.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/chemsys_entry.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/compute_rmsd.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/config.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/convert.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/ewald.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/gpumd_job.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/gpumd_out.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/ionhop.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/msd.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/nep_rmse.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/perturb.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/pred_msd_time.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/rd.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/realloc_occ.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/submit.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/supercell.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/trjconv.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/vasp_job.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/commands/vasp_out.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit/pymdkit_main.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit.egg-info/dependency_links.txt +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit.egg-info/entry_points.txt +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit.egg-info/requires.txt +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/src/pymdkit.egg-info/top_level.txt +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/data/88-Li2YCl3-63-d1.cif +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_config_logging.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_convert.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_ehull.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_gpumd_out.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_ionhop.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_lattice_symmetry.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_auto.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_fit.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_large.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_phase3.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_range.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_reuse.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_msd_uncertainty.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_parallel.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_pred_msd_time.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_progress.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_realloc_occ.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_rmsd_gpu.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_rmsd_max.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_rmsd_two_folder.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_submit.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_v165.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_v170_job_infrastructure.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_v170_vasp_consolidation.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_v172_vasp_writing.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_vasp_out.py +0 -0
- {pymdkit-1.7.5 → pymdkit-1.7.6}/tests/test_vaspset.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pymdkit
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.6
|
|
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,15 @@ 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.6 release notes
|
|
41
|
+
|
|
42
|
+
- `pmk dope -ref ELEMENT ELEMENT` now optimizes minimum periodic separation
|
|
43
|
+
when used with `-sn` and `-on`; `-we vac -ref vac vac` optimizes vacancy sites.
|
|
44
|
+
- `-d` is removed. Legacy reference removal uses `--reference-cutoffs`.
|
|
45
|
+
- Optimized structures are validated after writing and accompanied by a ranked
|
|
46
|
+
`optimization-summary.txt`. Scientific data reuse replaces the radius table,
|
|
47
|
+
symmetry-expression evaluation and duplicated exact SI constants.
|
|
48
|
+
|
|
40
49
|
## 1.7.5 release notes
|
|
41
50
|
|
|
42
51
|
- `pmk msd` reuses compatible full-trajectory or segment results, including
|
|
@@ -116,7 +125,7 @@ installed.
|
|
|
116
125
|
On a machine with Internet access, run:
|
|
117
126
|
|
|
118
127
|
```bash
|
|
119
|
-
python -m pip download pymdkit==1.7.
|
|
128
|
+
python -m pip download pymdkit==1.7.6 -d pymdkit-offline
|
|
120
129
|
```
|
|
121
130
|
|
|
122
131
|
This downloads `pymdkit` and the dependencies resolved by pip into the
|
|
@@ -124,14 +133,14 @@ This downloads `pymdkit` and the dependencies resolved by pip into the
|
|
|
124
133
|
system. Then, inside the target pymdkit Python or conda environment, run:
|
|
125
134
|
|
|
126
135
|
```bash
|
|
127
|
-
python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.
|
|
136
|
+
python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.6
|
|
128
137
|
```
|
|
129
138
|
|
|
130
139
|
For optional GPU use, prepare the bundle on a networked machine compatible with
|
|
131
140
|
the target HPC platform and Python environment:
|
|
132
141
|
|
|
133
142
|
```bash
|
|
134
|
-
python -m pip download "pymdkit[gpu-cuda12]==1.7.
|
|
143
|
+
python -m pip download "pymdkit[gpu-cuda12]==1.7.6" -d pymdkit-offline
|
|
135
144
|
```
|
|
136
145
|
|
|
137
146
|
Transfer the whole `pymdkit-offline` directory, then install from it on the
|
|
@@ -139,7 +148,7 @@ target system:
|
|
|
139
148
|
|
|
140
149
|
```bash
|
|
141
150
|
python -m pip install --no-index --find-links=pymdkit-offline \
|
|
142
|
-
"pymdkit[gpu-cuda12]==1.7.
|
|
151
|
+
"pymdkit[gpu-cuda12]==1.7.6"
|
|
143
152
|
```
|
|
144
153
|
|
|
145
154
|
This GPU bundle includes the optional `cupy-cuda12x` package. Its wheels must also
|
|
@@ -573,7 +582,7 @@ the strict `-max-ehull` filter using `ehull.txt` by default. All modes use
|
|
|
573
582
|
### Doping structures
|
|
574
583
|
|
|
575
584
|
```text
|
|
576
|
-
pmk dope -i FILE -se SELECTOR... [-sn NUMBER...] -we ELEMENT|
|
|
585
|
+
pmk dope -i FILE -se SELECTOR... [-sn NUMBER...] -we ELEMENT|vac... [-wn NUMBER...] [-on NUMBER] [-ref SELECTOR...] [--reference-cutoffs DISTANCE...] [-o DIR | -output-folder DIR] [-output-format FORMAT] [-seed INTEGER]
|
|
577
586
|
```
|
|
578
587
|
|
|
579
588
|
`dope` replaces `substitute` and preserves its validation,
|
|
@@ -582,6 +591,105 @@ Random mode defaults to `<input-stem>_dope/`; reference-distance mode defaults
|
|
|
582
591
|
to `<input-stem>_dope.cif`. Execution details are written to `dope.log`. The
|
|
583
592
|
standalone `substitute` command is removed.
|
|
584
593
|
|
|
594
|
+
### Automatic separation in 1.7.6
|
|
595
|
+
|
|
596
|
+
```powershell
|
|
597
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we Cu -on 100 -o Li90Cu18I108 -ref Cu Cu -seed 42
|
|
598
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we vac -on 100 -o Li90I108 -ref vac vac -seed 42
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
With `-sn` and `-on`, an identical reference pair enables automatic max–min
|
|
602
|
+
optimization. One selector and one replacement species are supported, including
|
|
603
|
+
`-we Na -ref Na Na`; mixed references are rejected. Without `-ref`, ordinary
|
|
604
|
+
random substitution/removal is unchanged. `vac` is canonical; `none` is deprecated.
|
|
605
|
+
The primary score is the minimum periodic pair distance, including fixed preexisting
|
|
606
|
+
replacement atoms. Vacancy geometry uses original removed-site coordinates.
|
|
607
|
+
|
|
608
|
+
Small spaces (at most 2,000 combinations) are enumerated exactly. Larger spaces use
|
|
609
|
+
seeded randomized farthest insertion and one-site exchanges. Default restart budget:
|
|
610
|
+
`max(4 * outputs, 8 * ceil(eligible / selected))`; at most `2 * selected` sweeps per
|
|
611
|
+
restart, stopping earlier when no improvement is found. Internal `optimize_sites`
|
|
612
|
+
keyword budgets support controlled validation. Initial and optimized candidates are
|
|
613
|
+
pooled, deduplicated by original indices, then ranked by minimum distance, mean
|
|
614
|
+
nearest-neighbor distance and mean pair distance. Scores rounded to 10 decimal places
|
|
615
|
+
resolve numerical ties; overlap diversity and index order break ties. No secondary
|
|
616
|
+
score can override a primary difference larger than that numerical tolerance.
|
|
617
|
+
|
|
618
|
+
`-on 100` returns the best 100 distinct configurations found, not necessarily global
|
|
619
|
+
optima or symmetry-inequivalent structures. Insufficient combinations or exhausted
|
|
620
|
+
budgets report actual counts and termination. Distance-matrix memory is quadratic in
|
|
621
|
+
eligible plus fixed sites. Identical input, seed, arguments and dependency versions
|
|
622
|
+
reproduce selections. Both doping and vacancy operations share this engine.
|
|
623
|
+
|
|
624
|
+
Default filenames remain `<input-stem>_r1.cif`, etc., in `<input-stem>_dope/` or `-o`.
|
|
625
|
+
Optimized CIFs use P1 to preserve the original cell and fractional coordinates;
|
|
626
|
+
VASP output keeps existing species grouping. Every optimized structure is reloaded
|
|
627
|
+
and checked for composition, lattice metric, retained positions and separation.
|
|
628
|
+
`optimization-summary.txt` is tab-separated with JSON metadata in a comment. It
|
|
629
|
+
contains filename, minimum and mean NN distances (Angstrom), packing diagnostic,
|
|
630
|
+
ratio, zero-based original indices and fractional coordinates. Metadata includes seed,
|
|
631
|
+
counts, fixed sites, budgets, method, termination and best/worst/median separation.
|
|
632
|
+
|
|
633
|
+
Optional exact certification runs **after** the same heuristic search:
|
|
634
|
+
|
|
635
|
+
```text
|
|
636
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we Cu -on 100 -o Li90Cu18I108 -ref Cu Cu --certify-optimum
|
|
637
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we vac -on 100 -o Li90I108 -ref vac vac --certify-optimum --certify-time-limit 120
|
|
638
|
+
```
|
|
639
|
+
|
|
640
|
+
`--certify-time-limit` must be finite and positive and requires `--certify-optimum`.
|
|
641
|
+
Its default is 120 seconds for the entire certification stage; it does not change
|
|
642
|
+
the heuristic budget. Certification requires the automatic `-sn/-on/-ref` mode.
|
|
643
|
+
Small enumerated spaces reuse their proof without invoking a solver. Otherwise
|
|
644
|
+
SciPy's `optimize.milp` (SciPy >= 1.9, bundled HiGHS) tests sparse conflict graphs:
|
|
645
|
+
binary x_i selects a site, sum(x_i)=K, and x_i+x_j<=1 when d_ij<t. Candidate sites
|
|
646
|
+
too close to fixed dopants are disabled; conflicting fixed pairs make t infeasible.
|
|
647
|
+
Binary search over discrete periodic distance levels finds the largest feasible
|
|
648
|
+
threshold. A validated configuration plus proof that the next level is infeasible
|
|
649
|
+
(or exhaustion of all levels) certifies the global max-min distance.
|
|
650
|
+
|
|
651
|
+
All distinct float64 distance levels are retained without rounding or grouping.
|
|
652
|
+
Conflicts use strict d<t; returned configurations must satisfy d>=t with no distance
|
|
653
|
+
relaxation. Binary variables are checked within 1e-6 of 0 or 1. This conservative
|
|
654
|
+
policy may require extra solves for nearly identical distances. Proofs refer to
|
|
655
|
+
the computed geometry subject to HiGHS numerical tolerances, not exact arithmetic.
|
|
656
|
+
The packing diagnostic is not used to prune the proof search.
|
|
657
|
+
|
|
658
|
+
`optimality-certificate.json` records input, species, site indices, seed, solver
|
|
659
|
+
and SciPy version, distance policy, per-threshold outcomes, runtime, bounds and
|
|
660
|
+
saved-structure classifications. `CERTIFIED_OPTIMAL` means the proof completed;
|
|
661
|
+
`IMPROVED_NOT_CERTIFIED` means a validated improvement was retained without proof;
|
|
662
|
+
`NOT_CERTIFIED` means no proof or improvement was obtained. Timeouts and solver
|
|
663
|
+
failures retain valid candidates and never imply infeasibility. Invalid returned
|
|
664
|
+
incumbents are errors. Missing MILP support is reported without losing heuristic
|
|
665
|
+
outputs. Valid solver discoveries enter the existing pool before ranking.
|
|
666
|
+
|
|
667
|
+
The certificate distinguishes the optimum from the number of generated structures
|
|
668
|
+
attaining it; `-on 100` does not imply 100 optimal or symmetry-inequivalent structures.
|
|
669
|
+
Default runs do not import or execute certification code or create this report.
|
|
670
|
+
Geometric separation optimality does not establish energetic or thermodynamic stability.
|
|
671
|
+
|
|
672
|
+
The equal-sphere packing diagnostic is
|
|
673
|
+
`D_upper = (6 * (pi / sqrt(18)) * V / (N * pi)) ** (1/3)`, with total objective-site
|
|
674
|
+
count N including fixed dopants. It is a geometric restriction, not an attainable-site
|
|
675
|
+
promise or proof of heuristic optimality. Physical radii are irrelevant. If the
|
|
676
|
+
shortest self-image lattice translation is smaller than this value, the formula need
|
|
677
|
+
not bound the distinct-site objective: metadata marks it inapplicable and the ratio
|
|
678
|
+
is `nan`. No arbitrary physical cutoff is imposed.
|
|
679
|
+
|
|
680
|
+
`-d`/`-distance` is removed and reports migration guidance. Legacy reference removal
|
|
681
|
+
is selected only when both `-sn` and `-on` are absent:
|
|
682
|
+
|
|
683
|
+
```powershell
|
|
684
|
+
pmk dope -i input.cif -se Li -we vac -ref La Ta --reference-cutoffs 1.01 1.02
|
|
685
|
+
```
|
|
686
|
+
|
|
687
|
+
Cutoffs remain Angstrom, one per reference. Omitting them preserves
|
|
688
|
+
`0.7 * (Cordero covalent radius sum)`, sourced from ASE for H through Cm; missing
|
|
689
|
+
radii require an explicit cutoff. Output remains `<input-stem>_dope.cif` in the
|
|
690
|
+
invocation directory. `--reference-cutoffs` is rejected in automatic mode.
|
|
691
|
+
Execution logging remains in `dope.log`.
|
|
692
|
+
|
|
585
693
|
### Breaking changes in v1.7.0
|
|
586
694
|
|
|
587
695
|
- `gpumd-thermo` and `gpumd-msd` are replaced by `gpumd-out -thermo` and
|
|
@@ -7,6 +7,15 @@ 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.6 release notes
|
|
11
|
+
|
|
12
|
+
- `pmk dope -ref ELEMENT ELEMENT` now optimizes minimum periodic separation
|
|
13
|
+
when used with `-sn` and `-on`; `-we vac -ref vac vac` optimizes vacancy sites.
|
|
14
|
+
- `-d` is removed. Legacy reference removal uses `--reference-cutoffs`.
|
|
15
|
+
- Optimized structures are validated after writing and accompanied by a ranked
|
|
16
|
+
`optimization-summary.txt`. Scientific data reuse replaces the radius table,
|
|
17
|
+
symmetry-expression evaluation and duplicated exact SI constants.
|
|
18
|
+
|
|
10
19
|
## 1.7.5 release notes
|
|
11
20
|
|
|
12
21
|
- `pmk msd` reuses compatible full-trajectory or segment results, including
|
|
@@ -86,7 +95,7 @@ installed.
|
|
|
86
95
|
On a machine with Internet access, run:
|
|
87
96
|
|
|
88
97
|
```bash
|
|
89
|
-
python -m pip download pymdkit==1.7.
|
|
98
|
+
python -m pip download pymdkit==1.7.6 -d pymdkit-offline
|
|
90
99
|
```
|
|
91
100
|
|
|
92
101
|
This downloads `pymdkit` and the dependencies resolved by pip into the
|
|
@@ -94,14 +103,14 @@ This downloads `pymdkit` and the dependencies resolved by pip into the
|
|
|
94
103
|
system. Then, inside the target pymdkit Python or conda environment, run:
|
|
95
104
|
|
|
96
105
|
```bash
|
|
97
|
-
python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.
|
|
106
|
+
python -m pip install --no-index --find-links=pymdkit-offline pymdkit==1.7.6
|
|
98
107
|
```
|
|
99
108
|
|
|
100
109
|
For optional GPU use, prepare the bundle on a networked machine compatible with
|
|
101
110
|
the target HPC platform and Python environment:
|
|
102
111
|
|
|
103
112
|
```bash
|
|
104
|
-
python -m pip download "pymdkit[gpu-cuda12]==1.7.
|
|
113
|
+
python -m pip download "pymdkit[gpu-cuda12]==1.7.6" -d pymdkit-offline
|
|
105
114
|
```
|
|
106
115
|
|
|
107
116
|
Transfer the whole `pymdkit-offline` directory, then install from it on the
|
|
@@ -109,7 +118,7 @@ target system:
|
|
|
109
118
|
|
|
110
119
|
```bash
|
|
111
120
|
python -m pip install --no-index --find-links=pymdkit-offline \
|
|
112
|
-
"pymdkit[gpu-cuda12]==1.7.
|
|
121
|
+
"pymdkit[gpu-cuda12]==1.7.6"
|
|
113
122
|
```
|
|
114
123
|
|
|
115
124
|
This GPU bundle includes the optional `cupy-cuda12x` package. Its wheels must also
|
|
@@ -543,7 +552,7 @@ the strict `-max-ehull` filter using `ehull.txt` by default. All modes use
|
|
|
543
552
|
### Doping structures
|
|
544
553
|
|
|
545
554
|
```text
|
|
546
|
-
pmk dope -i FILE -se SELECTOR... [-sn NUMBER...] -we ELEMENT|
|
|
555
|
+
pmk dope -i FILE -se SELECTOR... [-sn NUMBER...] -we ELEMENT|vac... [-wn NUMBER...] [-on NUMBER] [-ref SELECTOR...] [--reference-cutoffs DISTANCE...] [-o DIR | -output-folder DIR] [-output-format FORMAT] [-seed INTEGER]
|
|
547
556
|
```
|
|
548
557
|
|
|
549
558
|
`dope` replaces `substitute` and preserves its validation,
|
|
@@ -552,6 +561,105 @@ Random mode defaults to `<input-stem>_dope/`; reference-distance mode defaults
|
|
|
552
561
|
to `<input-stem>_dope.cif`. Execution details are written to `dope.log`. The
|
|
553
562
|
standalone `substitute` command is removed.
|
|
554
563
|
|
|
564
|
+
### Automatic separation in 1.7.6
|
|
565
|
+
|
|
566
|
+
```powershell
|
|
567
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we Cu -on 100 -o Li90Cu18I108 -ref Cu Cu -seed 42
|
|
568
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we vac -on 100 -o Li90I108 -ref vac vac -seed 42
|
|
569
|
+
```
|
|
570
|
+
|
|
571
|
+
With `-sn` and `-on`, an identical reference pair enables automatic max–min
|
|
572
|
+
optimization. One selector and one replacement species are supported, including
|
|
573
|
+
`-we Na -ref Na Na`; mixed references are rejected. Without `-ref`, ordinary
|
|
574
|
+
random substitution/removal is unchanged. `vac` is canonical; `none` is deprecated.
|
|
575
|
+
The primary score is the minimum periodic pair distance, including fixed preexisting
|
|
576
|
+
replacement atoms. Vacancy geometry uses original removed-site coordinates.
|
|
577
|
+
|
|
578
|
+
Small spaces (at most 2,000 combinations) are enumerated exactly. Larger spaces use
|
|
579
|
+
seeded randomized farthest insertion and one-site exchanges. Default restart budget:
|
|
580
|
+
`max(4 * outputs, 8 * ceil(eligible / selected))`; at most `2 * selected` sweeps per
|
|
581
|
+
restart, stopping earlier when no improvement is found. Internal `optimize_sites`
|
|
582
|
+
keyword budgets support controlled validation. Initial and optimized candidates are
|
|
583
|
+
pooled, deduplicated by original indices, then ranked by minimum distance, mean
|
|
584
|
+
nearest-neighbor distance and mean pair distance. Scores rounded to 10 decimal places
|
|
585
|
+
resolve numerical ties; overlap diversity and index order break ties. No secondary
|
|
586
|
+
score can override a primary difference larger than that numerical tolerance.
|
|
587
|
+
|
|
588
|
+
`-on 100` returns the best 100 distinct configurations found, not necessarily global
|
|
589
|
+
optima or symmetry-inequivalent structures. Insufficient combinations or exhausted
|
|
590
|
+
budgets report actual counts and termination. Distance-matrix memory is quadratic in
|
|
591
|
+
eligible plus fixed sites. Identical input, seed, arguments and dependency versions
|
|
592
|
+
reproduce selections. Both doping and vacancy operations share this engine.
|
|
593
|
+
|
|
594
|
+
Default filenames remain `<input-stem>_r1.cif`, etc., in `<input-stem>_dope/` or `-o`.
|
|
595
|
+
Optimized CIFs use P1 to preserve the original cell and fractional coordinates;
|
|
596
|
+
VASP output keeps existing species grouping. Every optimized structure is reloaded
|
|
597
|
+
and checked for composition, lattice metric, retained positions and separation.
|
|
598
|
+
`optimization-summary.txt` is tab-separated with JSON metadata in a comment. It
|
|
599
|
+
contains filename, minimum and mean NN distances (Angstrom), packing diagnostic,
|
|
600
|
+
ratio, zero-based original indices and fractional coordinates. Metadata includes seed,
|
|
601
|
+
counts, fixed sites, budgets, method, termination and best/worst/median separation.
|
|
602
|
+
|
|
603
|
+
Optional exact certification runs **after** the same heuristic search:
|
|
604
|
+
|
|
605
|
+
```text
|
|
606
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we Cu -on 100 -o Li90Cu18I108 -ref Cu Cu --certify-optimum
|
|
607
|
+
pmk dope -i LiI-333.vasp -se Li -sn 18 -we vac -on 100 -o Li90I108 -ref vac vac --certify-optimum --certify-time-limit 120
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
`--certify-time-limit` must be finite and positive and requires `--certify-optimum`.
|
|
611
|
+
Its default is 120 seconds for the entire certification stage; it does not change
|
|
612
|
+
the heuristic budget. Certification requires the automatic `-sn/-on/-ref` mode.
|
|
613
|
+
Small enumerated spaces reuse their proof without invoking a solver. Otherwise
|
|
614
|
+
SciPy's `optimize.milp` (SciPy >= 1.9, bundled HiGHS) tests sparse conflict graphs:
|
|
615
|
+
binary x_i selects a site, sum(x_i)=K, and x_i+x_j<=1 when d_ij<t. Candidate sites
|
|
616
|
+
too close to fixed dopants are disabled; conflicting fixed pairs make t infeasible.
|
|
617
|
+
Binary search over discrete periodic distance levels finds the largest feasible
|
|
618
|
+
threshold. A validated configuration plus proof that the next level is infeasible
|
|
619
|
+
(or exhaustion of all levels) certifies the global max-min distance.
|
|
620
|
+
|
|
621
|
+
All distinct float64 distance levels are retained without rounding or grouping.
|
|
622
|
+
Conflicts use strict d<t; returned configurations must satisfy d>=t with no distance
|
|
623
|
+
relaxation. Binary variables are checked within 1e-6 of 0 or 1. This conservative
|
|
624
|
+
policy may require extra solves for nearly identical distances. Proofs refer to
|
|
625
|
+
the computed geometry subject to HiGHS numerical tolerances, not exact arithmetic.
|
|
626
|
+
The packing diagnostic is not used to prune the proof search.
|
|
627
|
+
|
|
628
|
+
`optimality-certificate.json` records input, species, site indices, seed, solver
|
|
629
|
+
and SciPy version, distance policy, per-threshold outcomes, runtime, bounds and
|
|
630
|
+
saved-structure classifications. `CERTIFIED_OPTIMAL` means the proof completed;
|
|
631
|
+
`IMPROVED_NOT_CERTIFIED` means a validated improvement was retained without proof;
|
|
632
|
+
`NOT_CERTIFIED` means no proof or improvement was obtained. Timeouts and solver
|
|
633
|
+
failures retain valid candidates and never imply infeasibility. Invalid returned
|
|
634
|
+
incumbents are errors. Missing MILP support is reported without losing heuristic
|
|
635
|
+
outputs. Valid solver discoveries enter the existing pool before ranking.
|
|
636
|
+
|
|
637
|
+
The certificate distinguishes the optimum from the number of generated structures
|
|
638
|
+
attaining it; `-on 100` does not imply 100 optimal or symmetry-inequivalent structures.
|
|
639
|
+
Default runs do not import or execute certification code or create this report.
|
|
640
|
+
Geometric separation optimality does not establish energetic or thermodynamic stability.
|
|
641
|
+
|
|
642
|
+
The equal-sphere packing diagnostic is
|
|
643
|
+
`D_upper = (6 * (pi / sqrt(18)) * V / (N * pi)) ** (1/3)`, with total objective-site
|
|
644
|
+
count N including fixed dopants. It is a geometric restriction, not an attainable-site
|
|
645
|
+
promise or proof of heuristic optimality. Physical radii are irrelevant. If the
|
|
646
|
+
shortest self-image lattice translation is smaller than this value, the formula need
|
|
647
|
+
not bound the distinct-site objective: metadata marks it inapplicable and the ratio
|
|
648
|
+
is `nan`. No arbitrary physical cutoff is imposed.
|
|
649
|
+
|
|
650
|
+
`-d`/`-distance` is removed and reports migration guidance. Legacy reference removal
|
|
651
|
+
is selected only when both `-sn` and `-on` are absent:
|
|
652
|
+
|
|
653
|
+
```powershell
|
|
654
|
+
pmk dope -i input.cif -se Li -we vac -ref La Ta --reference-cutoffs 1.01 1.02
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
Cutoffs remain Angstrom, one per reference. Omitting them preserves
|
|
658
|
+
`0.7 * (Cordero covalent radius sum)`, sourced from ASE for H through Cm; missing
|
|
659
|
+
radii require an explicit cutoff. Output remains `<input-stem>_dope.cif` in the
|
|
660
|
+
invocation directory. `--reference-cutoffs` is rejected in automatic mode.
|
|
661
|
+
Execution logging remains in `dope.log`.
|
|
662
|
+
|
|
555
663
|
### Breaking changes in v1.7.0
|
|
556
664
|
|
|
557
665
|
- `gpumd-thermo` and `gpumd-msd` are replaced by `gpumd-out -thermo` and
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pymdkit"
|
|
7
|
-
version = "1.7.
|
|
7
|
+
version = "1.7.6"
|
|
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"
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Optional discrete max-min proof using sparse binary conflict graphs.
|
|
2
|
+
|
|
3
|
+
Keep every distinct floating-point distance (no grouping or rounding). Graphs
|
|
4
|
+
use strict d < t and incumbents must satisfy d >= t with zero relaxation.
|
|
5
|
+
Thus even near-equal levels cannot be skipped by a tolerance-based proof.
|
|
6
|
+
Certificates concern the computed periodic geometry and HiGHS tolerances,
|
|
7
|
+
not exact arithmetic on experimental crystallographic coordinates.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
import time
|
|
11
|
+
|
|
12
|
+
import numpy as np
|
|
13
|
+
|
|
14
|
+
try:
|
|
15
|
+
from ._dope_optimize import scores
|
|
16
|
+
except ImportError: # direct command script
|
|
17
|
+
from _dope_optimize import scores
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def certify_sites(matrix, eligible_count, count, initial, time_limit=120, *, enumerated=False):
|
|
21
|
+
if not np.isfinite(time_limit) or time_limit <= 0:
|
|
22
|
+
raise ValueError("certification time limit must be finite and positive")
|
|
23
|
+
started = time.monotonic()
|
|
24
|
+
# Match scores(), which takes the minimum over both matrix triangles.
|
|
25
|
+
# This also handles last-bit directional differences in geometry libraries.
|
|
26
|
+
matrix = np.minimum(matrix, matrix.T)
|
|
27
|
+
n = eligible_count
|
|
28
|
+
anchors = list(range(n, len(matrix)))
|
|
29
|
+
best = tuple(sorted(initial))
|
|
30
|
+
if len(best) != count or len(set(best)) != count or any(i < 0 or i >= n for i in best):
|
|
31
|
+
raise ValueError("invalid initial certification configuration")
|
|
32
|
+
heuristic = float(scores(matrix, [list(best) + anchors])[0, 0])
|
|
33
|
+
pairs = matrix[np.triu_indices(len(matrix), 1)]
|
|
34
|
+
if not np.all(np.isfinite(pairs)) or np.any(pairs < 0):
|
|
35
|
+
raise ValueError("invalid periodic distance matrix")
|
|
36
|
+
levels = np.unique(pairs)
|
|
37
|
+
lower = int(np.searchsorted(levels, heuristic))
|
|
38
|
+
upper = len(levels)
|
|
39
|
+
additions = []
|
|
40
|
+
checks = []
|
|
41
|
+
best_distance = heuristic
|
|
42
|
+
milp_best = None
|
|
43
|
+
reason = "all combinations enumerated" if enumerated else "discrete search complete"
|
|
44
|
+
complete = enumerated
|
|
45
|
+
solver_version = None
|
|
46
|
+
if not enumerated:
|
|
47
|
+
try:
|
|
48
|
+
import scipy
|
|
49
|
+
from scipy.optimize import Bounds, LinearConstraint, milp
|
|
50
|
+
from scipy import sparse
|
|
51
|
+
solver_version = scipy.__version__
|
|
52
|
+
except ImportError:
|
|
53
|
+
reason = "SciPy optimize.milp unavailable; certification requires SciPy >= 1.9"
|
|
54
|
+
else:
|
|
55
|
+
ii, jj = np.triu_indices(n, 1)
|
|
56
|
+
edge_distances = matrix[ii, jj]
|
|
57
|
+
while lower + 1 < upper:
|
|
58
|
+
if time.monotonic() - started >= time_limit:
|
|
59
|
+
reason = "global certification time limit reached"
|
|
60
|
+
break
|
|
61
|
+
middle = (lower + upper) // 2
|
|
62
|
+
threshold = float(levels[middle])
|
|
63
|
+
check = dict(threshold=threshold, solver_called=False)
|
|
64
|
+
fixed_conflict = bool(np.any(matrix[n:, n:] < threshold))
|
|
65
|
+
allowed = np.all(matrix[:n, n:] >= threshold, axis=1)
|
|
66
|
+
if fixed_conflict or np.count_nonzero(allowed) < count:
|
|
67
|
+
check.update(status=2, message="fixed-site constraints prove infeasibility")
|
|
68
|
+
checks.append(check)
|
|
69
|
+
upper = middle
|
|
70
|
+
continue
|
|
71
|
+
edges = edge_distances < threshold
|
|
72
|
+
left, right = ii[edges], jj[edges]
|
|
73
|
+
rows = np.arange(1, len(left) + 1)
|
|
74
|
+
graph = sparse.coo_matrix(
|
|
75
|
+
(np.ones(n + 2 * len(left)),
|
|
76
|
+
(np.concatenate((np.zeros(n, dtype=int), rows, rows)),
|
|
77
|
+
np.concatenate((np.arange(n), left, right)))),
|
|
78
|
+
shape=(1 + len(left), n)).tocsc()
|
|
79
|
+
constraints = LinearConstraint(graph, np.r_[count, np.full(len(left), -np.inf)],
|
|
80
|
+
np.r_[count, np.ones(len(left))])
|
|
81
|
+
remaining = time_limit - (time.monotonic() - started)
|
|
82
|
+
if remaining <= 0:
|
|
83
|
+
reason = "global certification time limit reached"
|
|
84
|
+
break
|
|
85
|
+
try:
|
|
86
|
+
result = milp(np.zeros(n), integrality=np.ones(n),
|
|
87
|
+
bounds=Bounds(np.zeros(n), allowed.astype(float)),
|
|
88
|
+
constraints=constraints,
|
|
89
|
+
options=dict(time_limit=remaining, presolve=True, mip_rel_gap=0.0))
|
|
90
|
+
except Exception as exc:
|
|
91
|
+
check.update(status=4, message=str(exc), solver_called=True)
|
|
92
|
+
checks.append(check)
|
|
93
|
+
reason = "solver failure: " + str(exc)
|
|
94
|
+
break
|
|
95
|
+
check.update(status=int(result.status), message=str(result.message), solver_called=True)
|
|
96
|
+
checks.append(check)
|
|
97
|
+
if result.status == 2:
|
|
98
|
+
upper = middle
|
|
99
|
+
continue
|
|
100
|
+
if result.status not in (0, 1):
|
|
101
|
+
reason = "abnormal solver outcome: " + str(result.message)
|
|
102
|
+
break
|
|
103
|
+
x = getattr(result, 'x', None)
|
|
104
|
+
if x is not None:
|
|
105
|
+
x = np.asarray(x)
|
|
106
|
+
if (x.shape != (n,) or not np.all(np.isfinite(x))
|
|
107
|
+
or np.any(np.minimum(abs(x), abs(x - 1)) > 1e-6)):
|
|
108
|
+
raise ValueError("invalid nonbinary MILP incumbent")
|
|
109
|
+
selected = tuple(np.flatnonzero(x > .5).tolist())
|
|
110
|
+
if len(selected) != count:
|
|
111
|
+
raise ValueError("invalid MILP incumbent selection count")
|
|
112
|
+
distance = float(scores(matrix, [list(selected) + anchors])[0, 0])
|
|
113
|
+
if distance < threshold:
|
|
114
|
+
raise ValueError("MILP incumbent violates the tested periodic distance threshold")
|
|
115
|
+
check['validated_distance'] = distance
|
|
116
|
+
additions.append(selected)
|
|
117
|
+
milp_best = max(milp_best or distance, distance)
|
|
118
|
+
if distance > best_distance:
|
|
119
|
+
best, best_distance = selected, distance
|
|
120
|
+
lower = int(np.searchsorted(levels, best_distance))
|
|
121
|
+
elif result.status == 0:
|
|
122
|
+
raise ValueError("successful MILP result has no incumbent")
|
|
123
|
+
if result.status == 1:
|
|
124
|
+
reason = "solver limit: " + str(result.message)
|
|
125
|
+
break
|
|
126
|
+
else:
|
|
127
|
+
complete = True
|
|
128
|
+
status = ("CERTIFIED_OPTIMAL" if complete else
|
|
129
|
+
"IMPROVED_NOT_CERTIFIED" if best_distance > heuristic else "NOT_CERTIFIED")
|
|
130
|
+
report = dict(status=status, method="exact-enumeration" if enumerated else "milp-conflict-graph",
|
|
131
|
+
eligible_sites=n, selected_sites=count, fixed_sites=len(anchors),
|
|
132
|
+
heuristic_best=heuristic, best_found=best_distance, milp_best=milp_best,
|
|
133
|
+
certified_optimum=best_distance if complete else None,
|
|
134
|
+
time_limit=time_limit, runtime=time.monotonic() - started,
|
|
135
|
+
feasibility_checks=sum(c['solver_called'] for c in checks),
|
|
136
|
+
proven_feasible_thresholds=sum('validated_distance' in c for c in checks),
|
|
137
|
+
proven_infeasible_thresholds=sum(c['status'] == 2 for c in checks),
|
|
138
|
+
last_proven_feasible_threshold=best_distance,
|
|
139
|
+
first_proven_infeasible_threshold=float(levels[upper]) if upper < len(levels) else None,
|
|
140
|
+
distance_tolerance=0.0, binary_tolerance=1e-6,
|
|
141
|
+
distance_policy="all distinct float64 levels; strict conflicts; no distance relaxation",
|
|
142
|
+
solver="SciPy MILP (bundled HiGHS)" if not enumerated else None,
|
|
143
|
+
scipy_version=solver_version, termination=reason, checks=checks,
|
|
144
|
+
best_local_indices=[int(i) for i in best])
|
|
145
|
+
return additions, report
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"""Bounded, seeded max-min site selection using pymatgen periodic geometry."""
|
|
2
|
+
|
|
3
|
+
import itertools
|
|
4
|
+
import math
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def packing_bound(volume, count):
|
|
10
|
+
return (6 * (math.pi / math.sqrt(18)) * volume / (count * math.pi)) ** (1 / 3)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def scores(matrix, configurations):
|
|
14
|
+
"""Primary minimum, secondary mean NN, tertiary mean pair separation."""
|
|
15
|
+
indices = np.asarray(configurations, dtype=int)
|
|
16
|
+
distances = matrix[indices[:, :, None], indices[:, None, :]]
|
|
17
|
+
nearest = distances.min(axis=2)
|
|
18
|
+
n = indices.shape[1]
|
|
19
|
+
pairs = distances[:, np.triu_indices(n, 1)[0], np.triu_indices(n, 1)[1]]
|
|
20
|
+
return np.column_stack((nearest.min(axis=1), nearest.mean(axis=1), pairs.mean(axis=1)))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def greedy_sites(matrix, eligible_count, count, anchors, rng):
|
|
24
|
+
"""Randomized farthest insertion; anchors remain fixed."""
|
|
25
|
+
selected = []
|
|
26
|
+
nearest = matrix[:eligible_count, anchors].min(axis=1) if anchors else np.full(eligible_count, np.inf)
|
|
27
|
+
for step in range(count):
|
|
28
|
+
available = np.array([i for i in range(eligible_count) if i not in selected])
|
|
29
|
+
if step == 0 and not anchors:
|
|
30
|
+
pick = int(rng.choice(available))
|
|
31
|
+
else:
|
|
32
|
+
best = nearest[available].max()
|
|
33
|
+
pick = int(rng.choice(available[np.isclose(nearest[available], best, rtol=0, atol=1e-10)]))
|
|
34
|
+
selected.append(pick)
|
|
35
|
+
nearest = np.minimum(nearest, matrix[:eligible_count, pick])
|
|
36
|
+
return selected
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def optimize_sites(structure, eligible, count, fixed=(), requested=1, seed=None,
|
|
40
|
+
restarts=None, sweeps=None, exact_limit=2000,
|
|
41
|
+
certify=False, certify_time_limit=120):
|
|
42
|
+
"""Return ranked (original indices, scores) and search diagnostics.
|
|
43
|
+
|
|
44
|
+
Only small spaces are enumerated. Large spaces use randomized farthest
|
|
45
|
+
insertion and bounded best one-site exchanges. Memory is O(M^2 + M*N^2).
|
|
46
|
+
Scores are rounded to 10 decimal places ONLY for ranking numerical ties.
|
|
47
|
+
"""
|
|
48
|
+
eligible, fixed = sorted(eligible), sorted(fixed)
|
|
49
|
+
n = len(eligible)
|
|
50
|
+
if not 0 < count <= n or requested < 1:
|
|
51
|
+
raise ValueError("selection count and requested output count must be positive and feasible")
|
|
52
|
+
if len(set(eligible + fixed)) != len(eligible) + len(fixed):
|
|
53
|
+
raise ValueError("eligible and fixed sites must be distinct")
|
|
54
|
+
if count + len(fixed) < 2:
|
|
55
|
+
raise ValueError("separation optimization requires at least two objective sites")
|
|
56
|
+
coords = structure.frac_coords[eligible + fixed]
|
|
57
|
+
matrix = structure.lattice.get_all_distances(coords, coords)
|
|
58
|
+
np.fill_diagonal(matrix, np.inf)
|
|
59
|
+
anchors = list(range(n, n + len(fixed)))
|
|
60
|
+
rng = np.random.default_rng(seed)
|
|
61
|
+
total = math.comb(n, count)
|
|
62
|
+
restarts = restarts if restarts is not None else max(4 * requested, 8 * math.ceil(n / count))
|
|
63
|
+
sweeps = sweeps if sweeps is not None else 2 * count
|
|
64
|
+
if restarts < 1 or sweeps < 1:
|
|
65
|
+
raise ValueError("search budgets must be positive")
|
|
66
|
+
pool = {}
|
|
67
|
+
evaluations = 0
|
|
68
|
+
|
|
69
|
+
def evaluate(configurations):
|
|
70
|
+
nonlocal evaluations
|
|
71
|
+
evaluations += len(configurations)
|
|
72
|
+
return scores(matrix, configurations)
|
|
73
|
+
|
|
74
|
+
def retain(selected):
|
|
75
|
+
key = tuple(sorted(selected))
|
|
76
|
+
if key not in pool:
|
|
77
|
+
pool[key] = tuple(evaluate([list(key) + anchors])[0])
|
|
78
|
+
|
|
79
|
+
exact = total <= exact_limit
|
|
80
|
+
if exact:
|
|
81
|
+
for selected in itertools.combinations(range(n), count):
|
|
82
|
+
retain(selected)
|
|
83
|
+
else:
|
|
84
|
+
for _ in range(restarts):
|
|
85
|
+
selected = greedy_sites(matrix, n, count, anchors, rng)
|
|
86
|
+
retain(selected)
|
|
87
|
+
for _sweep in range(sweeps):
|
|
88
|
+
improved = False
|
|
89
|
+
for slot in rng.permutation(count):
|
|
90
|
+
unused = [i for i in range(n) if i not in selected]
|
|
91
|
+
if not unused:
|
|
92
|
+
break
|
|
93
|
+
candidates = np.tile(selected + anchors, (len(unused), 1))
|
|
94
|
+
candidates[:, slot] = unused
|
|
95
|
+
values = evaluate(candidates)
|
|
96
|
+
rounded = np.round(values, 10)
|
|
97
|
+
best = np.lexsort((-rounded[:, 2], -rounded[:, 1], -rounded[:, 0]))[0]
|
|
98
|
+
current = evaluate([selected + anchors])[0]
|
|
99
|
+
if tuple(rounded[best]) > tuple(np.round(current, 10)):
|
|
100
|
+
selected[slot] = unused[best]
|
|
101
|
+
improved = True
|
|
102
|
+
if not improved:
|
|
103
|
+
break
|
|
104
|
+
retain(selected)
|
|
105
|
+
certificate = None
|
|
106
|
+
if certify:
|
|
107
|
+
try:
|
|
108
|
+
from ._dope_certify import certify_sites
|
|
109
|
+
except ImportError:
|
|
110
|
+
from _dope_certify import certify_sites
|
|
111
|
+
best = max(pool, key=lambda key: pool[key][0])
|
|
112
|
+
additions, certificate = certify_sites(matrix, n, count, best,
|
|
113
|
+
certify_time_limit, enumerated=exact)
|
|
114
|
+
for selected in additions:
|
|
115
|
+
retain(selected)
|
|
116
|
+
ranked = sorted(pool, key=lambda key: tuple(-v for v in np.round(pool[key], 10)) + key)
|
|
117
|
+
# Prefer less overlap within score ties, without sacrificing separation.
|
|
118
|
+
chosen = []
|
|
119
|
+
for _, group in itertools.groupby(ranked, key=lambda key: tuple(np.round(pool[key], 10))):
|
|
120
|
+
tied = list(group)
|
|
121
|
+
while tied and len(chosen) < requested:
|
|
122
|
+
key = min(tied, key=lambda k: (max((len(set(k) & set(p)) for p in chosen), default=0), k))
|
|
123
|
+
chosen.append(key)
|
|
124
|
+
tied.remove(key)
|
|
125
|
+
if len(chosen) >= requested:
|
|
126
|
+
break
|
|
127
|
+
if certificate is not None:
|
|
128
|
+
best_key = tuple(certificate['best_local_indices'])
|
|
129
|
+
if best_key not in chosen:
|
|
130
|
+
chosen[-1] = best_key
|
|
131
|
+
chosen.sort(key=lambda key: tuple(-v for v in np.round(pool[key], 10)) + key)
|
|
132
|
+
bound = packing_bound(structure.volume, count + len(fixed))
|
|
133
|
+
# Distinct-pair MIC excludes a site's own images. Sphere packing bounds
|
|
134
|
+
# that objective only if self images cannot overlap at the stated bound.
|
|
135
|
+
reduced = structure.lattice.get_lll_reduced_lattice()
|
|
136
|
+
images = reduced.get_points_in_sphere([[0, 0, 0]], [0, 0, 0], min(reduced.abc) + 1e-8)
|
|
137
|
+
shortest = min(float(item[1]) for item in images if item[1] > 1e-8)
|
|
138
|
+
metadata = dict(method="exact enumeration" if exact else "multi-start farthest insertion + one-site exchanges (best-found)",
|
|
139
|
+
termination="all combinations enumerated" if exact else "finite restart budget exhausted",
|
|
140
|
+
total_combinations=total, unique_candidates=len(pool), score_evaluations=evaluations,
|
|
141
|
+
restarts=0 if exact else restarts,
|
|
142
|
+
sweep_budget=sweeps, upper_bound=bound, packing_bound_applicable=shortest >= bound - 1e-10,
|
|
143
|
+
shortest_self_image=shortest, objective_sites=count + len(fixed), fixed_indices=fixed)
|
|
144
|
+
if certificate is not None:
|
|
145
|
+
metadata['certification'] = certificate
|
|
146
|
+
return [(tuple(eligible[i] for i in key), pool[key]) for key in chosen], metadata
|