rsspolymlp 0.4.6__tar.gz → 0.4.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 (83) hide show
  1. {rsspolymlp-0.4.6/src/rsspolymlp.egg-info → rsspolymlp-0.4.7}/PKG-INFO +1 -1
  2. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/pyproject.toml +1 -1
  3. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/rss_summarize.py +16 -16
  4. rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/assignment_algo.py +187 -0
  5. rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/dataclass.py +24 -0
  6. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/gen_struct_rep.py +72 -129
  7. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/identify_uniqstr.py +22 -22
  8. rsspolymlp-0.4.6/src/rsspolymlp/analysis/struct_matcher/redrep_position.py → rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/position_redrep.py +148 -152
  9. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/primitive_transform.py +87 -85
  10. rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/struct_match.py +379 -0
  11. rsspolymlp-0.4.6/src/rsspolymlp/analysis/struct_matcher/test/gen_lattice.py → rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/test/gen_rand_lattice.py +24 -1
  12. rsspolymlp-0.4.7/src/rsspolymlp/analysis/struct_matcher/test/gen_rand_position.py +65 -0
  13. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/cli_rsspolymlp.py +4 -5
  14. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/cli_rsspolymlp_utils.py +2 -3
  15. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/rsspolymlp.py +3 -2
  16. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/rsspolymlp_utils.py +20 -14
  17. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/interface_spglib.py +10 -0
  18. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/rss/eliminate_duplicates.py +1 -1
  19. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/rss/random_struct.py +1 -1
  20. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7/src/rsspolymlp.egg-info}/PKG-INFO +1 -1
  21. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp.egg-info/SOURCES.txt +4 -2
  22. rsspolymlp-0.4.6/src/rsspolymlp/analysis/struct_matcher/assignment_algo.py +0 -245
  23. rsspolymlp-0.4.6/src/rsspolymlp/analysis/struct_matcher/struct_match.py +0 -293
  24. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/LICENSE +0 -0
  25. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/README.md +0 -0
  26. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/setup.cfg +0 -0
  27. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/__init__.py +0 -0
  28. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/__init__.py +0 -0
  29. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/eos.py +0 -0
  30. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/ghost_minima.py +0 -0
  31. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/phase_analysis.py +0 -0
  32. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/__init__.py +0 -0
  33. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/chiral_spg.py +0 -0
  34. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/struct_matcher/niggli_reduce.py +0 -0
  35. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/analysis/utils/convert_data_format.py +0 -0
  36. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/__init__.py +0 -0
  37. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/cli_rsspolymlp_devkit.py +0 -0
  38. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/cli_rsspolymlp_plot.py +0 -0
  39. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/rsspolymlp_devkit.py +0 -0
  40. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/api/rsspolymlp_plot.py +0 -0
  41. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/__init__.py +0 -0
  42. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/atomic_energy.py +0 -0
  43. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/composition.py +0 -0
  44. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/interface_pypolymlp.py +0 -0
  45. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/interface_vasp.py +0 -0
  46. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/common/property.py +0 -0
  47. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/dataset/compress_vasprun.py +0 -0
  48. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/dataset/gen_mlp_dataset.py +0 -0
  49. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/dataset/split_dataset.py +0 -0
  50. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/estimate_cost.py +0 -0
  51. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/binary/gen_single_model.py +0 -0
  52. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/elemental/gen_hybrid_model.py +0 -0
  53. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/elemental/gen_single_model.py +0 -0
  54. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/n_feature.py +0 -0
  55. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/pypolymlp_gridsearch.py +0 -0
  56. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/model_selection/reduce_grid.py +0 -0
  57. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/pareto_opt_mlp.py +0 -0
  58. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/mlp_dev/polymlp_dev.py +0 -0
  59. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/rss/__init__.py +0 -0
  60. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/rss/load_logfile.py +0 -0
  61. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/rss/optimization_mlp.py +0 -0
  62. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/__init__.py +0 -0
  63. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/lammps_utils.py +0 -0
  64. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/__init__.py +0 -0
  65. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/custom_plt.py +0 -0
  66. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/examples/__init__.py +0 -0
  67. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/examples/example.py +0 -0
  68. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/examples/template.py +0 -0
  69. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/matplot_util/make_plot.py +0 -0
  70. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/opt_sscha/opt_geometry_sscha.py +0 -0
  71. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/opt_sscha/opt_position_sscha.py +0 -0
  72. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/opt_sscha/run_opt_sscha.py +0 -0
  73. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/opt_sscha/sscha_property.py +0 -0
  74. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/pymatgen_utils.py +0 -0
  75. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/vasp_util/__init__.py +0 -0
  76. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/vasp_util/api.py +0 -0
  77. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/vasp_util/gen_incar.py +0 -0
  78. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp/utils/vasp_util/gen_script.py +0 -0
  79. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp.egg-info/dependency_links.txt +0 -0
  80. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp.egg-info/entry_points.txt +0 -0
  81. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp.egg-info/requires.txt +0 -0
  82. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/src/rsspolymlp.egg-info/top_level.txt +0 -0
  83. {rsspolymlp-0.4.6 → rsspolymlp-0.4.7}/tests/test_cli_help.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: rsspolymlp
3
- Version: 0.4.6
3
+ Version: 0.4.7
4
4
  Summary: A framework for random structure search using polynomial MLPs
5
5
  Author-email: Hayato Wakai <wakai@cms.mtl.kyoto-u.ac.jp>
6
6
  Maintainer-email: Hayato Wakai <wakai@cms.mtl.kyoto-u.ac.jp>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "rsspolymlp"
7
- version = "0.4.6"
7
+ version = "0.4.7"
8
8
  description = "A framework for random structure search using polynomial MLPs"
9
9
  license = "MIT"
10
10
  authors = [
@@ -14,7 +14,7 @@ from pypolymlp.utils.vasp_utils import write_poscar_file
14
14
  from rsspolymlp.analysis.ghost_minima import detect_ghost_minima
15
15
  from rsspolymlp.analysis.struct_matcher.gen_struct_rep import (
16
16
  StructRepGenerator,
17
- StructReps,
17
+ StructRep,
18
18
  )
19
19
  from rsspolymlp.analysis.struct_matcher.identify_uniqstr import (
20
20
  UniqueStructIdentifier,
@@ -38,7 +38,7 @@ class RSSResultSummarizer:
38
38
  num_process: int = -1,
39
39
  backend: str = "loky",
40
40
  assign_method: Literal["redrep", "greedy", "HK", "pymatgen"] = "redrep",
41
- tol_sm: list[float] = [1e-2],
41
+ tol_sm: float = 1e-2,
42
42
  output_poscar: bool = False,
43
43
  thresholds: list[float] = None,
44
44
  parse_vasp: bool = False,
@@ -283,22 +283,22 @@ class RSSResultSummarizer:
283
283
  generator = StructRepGenerator(
284
284
  tol_sm=self.tol_sm,
285
285
  )
286
- struct_reps_list = generator.generate_struct_reps_parallel(
286
+ struct_rep_list = generator.generate_struct_rep_parallel(
287
287
  rss_results,
288
288
  num_process=self.num_process,
289
289
  backend=self.backend,
290
290
  )
291
291
  if self.update_parent:
292
292
  print(" - Eliminating duplicate structures...")
293
- for idx, redreps in enumerate(struct_reps_list):
293
+ for idx, struct_rep in enumerate(struct_rep_list):
294
294
  self.analyzer.identify_duplicate_struct(
295
- unique_struct=redreps,
295
+ struct_rep=struct_rep,
296
296
  other_properties=rss_results[idx],
297
297
  axis_tol=0.03,
298
298
  pos_tol=0.03,
299
299
  )
300
300
  else:
301
- self.analyzer._initialize_unique_structs(struct_reps_list, rss_results)
301
+ self.analyzer._initialize_unique_structs(struct_rep_list, rss_results)
302
302
 
303
303
  return set(processed_paths)
304
304
 
@@ -489,16 +489,16 @@ class RSSResultSummarizer:
489
489
 
490
490
  def dump_json_rss_results(
491
491
  file_name: str,
492
- struct_reps_list: list[StructReps],
492
+ struct_rep_list: list[StructRep],
493
493
  enthalpy_lists: list[float],
494
494
  is_ghost_minima=None,
495
495
  pressure=None,
496
496
  ):
497
497
  if is_ghost_minima is None:
498
- is_ghost_minima = np.full_like(struct_reps_list, False, dtype=bool)
498
+ is_ghost_minima = np.full_like(struct_rep_list, False, dtype=bool)
499
499
 
500
500
  rss_results = []
501
- for idx, _str in enumerate(struct_reps_list):
501
+ for idx, _str in enumerate(struct_rep_list):
502
502
  axis = _str.original_axis
503
503
  positions = _str.original_positions
504
504
  elements = _str.original_elements
@@ -520,7 +520,7 @@ def dump_json_rss_results(
520
520
  "is_ghost_minima": bool(is_ghost_minima[idx]),
521
521
  }
522
522
  )
523
- if len(struct_reps_list) > 0:
523
+ if len(struct_rep_list) > 0:
524
524
  comp_res = compute_composition(elements)
525
525
  rss_result_all = {
526
526
  "elements": comp_res.unique_elements.tolist(),
@@ -540,14 +540,14 @@ def dump_json_rss_results(
540
540
 
541
541
  def log_unique_structures(
542
542
  file_name: str,
543
- struct_reps_list: list[StructReps],
543
+ struct_rep_list: list[StructRep],
544
544
  enthalpy_lists: Optional[list[float]] = None,
545
545
  is_ghost_minima=None,
546
546
  unique_struct_iters=None,
547
547
  print_duplicates: bool = False,
548
548
  ):
549
549
  if is_ghost_minima is None:
550
- is_ghost_minima = np.full_like(struct_reps_list, False, dtype=bool)
550
+ is_ghost_minima = np.full_like(struct_rep_list, False, dtype=bool)
551
551
  energy_min = None
552
552
  if enthalpy_lists is not None:
553
553
  for i in range(len(enthalpy_lists)):
@@ -556,10 +556,10 @@ def log_unique_structures(
556
556
  break
557
557
 
558
558
  struct_num_max = max(
559
- (_s.struct_tag for _s in struct_reps_list if _s.struct_tag is not None),
559
+ (_s.struct_tag for _s in struct_rep_list if _s.struct_tag is not None),
560
560
  default=0,
561
561
  )
562
- for _s in struct_reps_list:
562
+ for _s in struct_rep_list:
563
563
  if _s.struct_tag is None:
564
564
  struct_num_max += 1
565
565
  _s.struct_tag = struct_num_max
@@ -567,7 +567,7 @@ def log_unique_structures(
567
567
  with open(file_name, "a") as f:
568
568
  print("unique_structures:", file=f)
569
569
  for is_ghost in [False, True]:
570
- for idx, _str in enumerate(struct_reps_list):
570
+ for idx, _str in enumerate(struct_rep_list):
571
571
  if energy_min is not None:
572
572
  e_diff = round((enthalpy_lists[idx] - energy_min) * 1000, 2)
573
573
  if (not is_ghost and e_diff < -300) or (
@@ -617,7 +617,7 @@ def log_unique_structures(
617
617
 
618
618
  def log_all_unique_structures(
619
619
  file_name,
620
- unique_structs: list[list[StructReps]],
620
+ unique_structs: list[list[StructRep]],
621
621
  unique_str_prop: Optional[list[list[dict]]] = None,
622
622
  unique_other_prop=None,
623
623
  ):
@@ -0,0 +1,187 @@
1
+ import time
2
+ from typing import Literal
3
+
4
+ import numpy as np
5
+ from scipy.optimize import minimize
6
+ from scipy.sparse import csr_array
7
+ from scipy.sparse.csgraph import maximum_bipartite_matching
8
+
9
+
10
+ def sort_match_screen(
11
+ pos_reps1: np.ndarray,
12
+ pos_reps2: np.ndarray,
13
+ elements1: np.ndarray,
14
+ elements2: np.ndarray,
15
+ axis_abc: np.ndarray,
16
+ pos_tol: float,
17
+ verbose: bool = False,
18
+ ):
19
+ # pos1: (N1, n_atoms, 3)
20
+ # pos2: (N2, n_atoms, 3)
21
+ if len(elements1) != len(elements2):
22
+ return np.zeros((len(pos_reps1), len(pos_reps2)), dtype=bool)
23
+ unique_elements = np.unique(elements1)
24
+
25
+ def sort_positions_axis(pos_reps, elements, axis):
26
+ pos_reps = np.asarray(pos_reps)
27
+ reps_diff = np.empty_like(pos_reps[:, :, axis])
28
+ start = 0
29
+ for el in unique_elements:
30
+ idx = np.flatnonzero(elements == el)
31
+ sorted_reps = np.sort(pos_reps[:, idx, axis], axis=1)
32
+ diff = np.roll(sorted_reps, -1, axis=1) - sorted_reps
33
+ diff[:, -1] += axis_abc[axis]
34
+ reps_diff[:, start : start + len(idx)] = np.sort(diff, axis=1)
35
+ start += len(idx)
36
+ return reps_diff
37
+
38
+ matched = np.ones(
39
+ (len(pos_reps1), len(pos_reps2)),
40
+ dtype=bool,
41
+ )
42
+ if verbose:
43
+ print("code: sort_match_screen (all candidates)")
44
+ print(f" Candidate matches: {np.count_nonzero(matched)}")
45
+ for axis in range(3):
46
+ rows, cols = np.where(matched)
47
+ if len(rows) == 0:
48
+ break
49
+
50
+ t_start_s = time.time()
51
+ pos1_axis = sort_positions_axis(pos_reps1, elements1, axis)
52
+ pos2_axis = sort_positions_axis(pos_reps2, elements2, axis)
53
+ if verbose:
54
+ print(f"code: sort_match_screen (axis {axis})")
55
+ print(f" Sorting: {round((time.time() - t_start_s) * 1000, 2)} ms")
56
+
57
+ t_start_m = time.time()
58
+ diff = pos1_axis[rows] - pos2_axis[cols]
59
+ diff -= axis_abc[axis] * np.round(diff / axis_abc[axis])
60
+ matched[rows, cols] = np.all(np.abs(diff) <= pos_tol, axis=1)
61
+ if verbose:
62
+ print(f" Matching: {round((time.time() - t_start_m) * 1000, 2)} ms")
63
+ print(f" Candidate matches: {np.count_nonzero(matched)}")
64
+ return matched
65
+
66
+
67
+ def position_matching(
68
+ pos1: np.ndarray,
69
+ pos2: np.ndarray,
70
+ elements1: np.ndarray,
71
+ elements2: np.ndarray,
72
+ axis_abc: np.ndarray,
73
+ pos_tol: float,
74
+ assign_method: Literal["greedy", "HK"] = "greedy",
75
+ verbose: bool = False,
76
+ ):
77
+ max_diff = 0
78
+ t_start_g = time.time()
79
+ for el in np.unique(elements1):
80
+ targets1 = np.where(elements1 == el)[0]
81
+ targets2 = np.where(elements2 == el)[0]
82
+ pos1_sub = pos1[targets1]
83
+ pos2_sub = pos2[targets2]
84
+
85
+ col_ind = []
86
+ inv_axis_abc = 1 / axis_abc
87
+ pos_d = pos1_sub[:, None, :] - pos2_sub[None, :, :]
88
+ pos_d -= axis_abc * np.round(pos_d * inv_axis_abc)
89
+ for _ in range(10):
90
+ if assign_method == "greedy":
91
+ pos_d_res, matching = greedy_matching(pos_d, pos_tol=pos_tol * 2)
92
+ elif assign_method == "HK":
93
+ pos_d_res, matching = HK_matching(pos_d, pos_tol=pos_tol * 2)
94
+ else:
95
+ raise ValueError(f"Unknown assignment method: {assign_method}")
96
+
97
+ if matching is None:
98
+ return False, None
99
+
100
+ if np.max(np.abs(pos_d_res)) < pos_tol:
101
+ if max_diff < np.max(np.abs(pos_d_res)):
102
+ max_diff = np.max(np.abs(pos_d_res))
103
+ break
104
+ if np.array_equal(matching, col_ind):
105
+ return False, None
106
+
107
+ col_ind = matching
108
+ translation_correction, max_displacement = optimize_translation(pos_d_res)
109
+ pos_d = pos_d - translation_correction
110
+
111
+ if verbose:
112
+ print("code: position_matching")
113
+ print(f" Matching: {round((time.time() - t_start_g) * 1000, 2)} ms")
114
+
115
+ return True, max_diff
116
+
117
+
118
+ def greedy_matching(pos_d, pos_tol):
119
+ pos_d_res = pos_d.copy()
120
+ pos_d_max = np.max(np.abs(pos_d), axis=2)
121
+
122
+ sorted_pos_d = np.sort(pos_d, axis=0)
123
+ pos_d_minmax = np.max(sorted_pos_d[0])
124
+ if pos_d_minmax > pos_tol:
125
+ return None, None
126
+
127
+ used1 = np.zeros(pos_d_max.shape[0], dtype=bool)
128
+ matching = np.full(len(pos_d_max), -1, dtype=int)
129
+ while not np.all(used1):
130
+ i, j = np.unravel_index(
131
+ np.argmin(pos_d_max),
132
+ pos_d_max.shape,
133
+ )
134
+ if pos_d_max[i, j] >= pos_tol:
135
+ return None, None
136
+ matching[i] = j
137
+ pos_d_max[i, :] = np.inf
138
+ pos_d_max[:, j] = np.inf
139
+ used1[i] = True
140
+ pos_d_res = pos_d_res[np.arange(len(matching)), matching]
141
+ return pos_d_res, matching
142
+
143
+
144
+ def HK_matching(pos_d, pos_tol):
145
+ pos_d_res = pos_d.copy()
146
+ pos_d_max = np.max(np.abs(pos_d), axis=2)
147
+
148
+ sorted_pos_d = np.sort(pos_d, axis=0)
149
+ pos_d_minmax = np.max(sorted_pos_d[0])
150
+ if pos_d_minmax > pos_tol:
151
+ return None, None
152
+
153
+ rows, cols = np.where(pos_d_max <= pos_tol)
154
+ graph = csr_array(
155
+ (
156
+ np.ones(len(rows), dtype=np.int8),
157
+ (rows, cols),
158
+ ),
159
+ shape=pos_d_max.shape,
160
+ )
161
+ matching = maximum_bipartite_matching(graph, perm_type="column")
162
+ if not np.all(matching >= 0):
163
+ return None, None
164
+
165
+ pos_d_res = pos_d_res[np.arange(len(matching)), matching]
166
+ return pos_d_res, matching
167
+
168
+
169
+ def optimize_translation(diffs):
170
+ """Find a translation minimizing the maximum displacement."""
171
+
172
+ def objective(translation):
173
+ corrected = diffs - translation
174
+ return np.max(np.linalg.norm(corrected, axis=1))
175
+
176
+ diffs = np.asarray(diffs, dtype=float)
177
+ initial_translation = np.mean(diffs, axis=0)
178
+ result = minimize(
179
+ objective,
180
+ initial_translation,
181
+ method="Nelder-Mead",
182
+ options={"xatol": 1e-10, "maxiter": 10000},
183
+ )
184
+ translation = result.x
185
+ max_displacement = objective(translation)
186
+
187
+ return translation, max_displacement
@@ -0,0 +1,24 @@
1
+ from dataclasses import dataclass
2
+ from typing import Optional
3
+
4
+ import numpy as np
5
+
6
+
7
+ @dataclass
8
+ class StructRep:
9
+ axis: np.ndarray
10
+ metric_tensor: np.ndarray
11
+ reduced_posreps: dict
12
+ all_posreps: dict
13
+ elements: np.ndarray
14
+ spg_number: int
15
+ spg_list: list[str]
16
+ original_axis: np.ndarray
17
+ original_positions: np.ndarray
18
+ original_elements: np.ndarray
19
+ tol_sm: float
20
+ tol_redpos: list[float]
21
+ normalize_axis: bool
22
+ struct_path: Optional[str]
23
+ struct_tag: Optional[int]
24
+ dupstr_paths: set[str]