gridmlip 0.2.5__tar.gz → 0.2.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.
Files changed (37) hide show
  1. {gridmlip-0.2.5/gridmlip.egg-info → gridmlip-0.2.6}/PKG-INFO +2 -2
  2. {gridmlip-0.2.5 → gridmlip-0.2.6}/README.md +1 -1
  3. gridmlip-0.2.6/gridmlip/_distortion.py +112 -0
  4. gridmlip-0.2.6/gridmlip/_version.py +1 -0
  5. gridmlip-0.2.6/gridmlip/select.py +91 -0
  6. {gridmlip-0.2.5 → gridmlip-0.2.6/gridmlip.egg-info}/PKG-INFO +2 -2
  7. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip.egg-info/requires.txt +2 -0
  8. {gridmlip-0.2.5 → gridmlip-0.2.6}/setup.cfg +2 -0
  9. gridmlip-0.2.5/gridmlip/_distortion.py +0 -44
  10. gridmlip-0.2.5/gridmlip/_version.py +0 -1
  11. gridmlip-0.2.5/gridmlip/select.py +0 -1
  12. {gridmlip-0.2.5 → gridmlip-0.2.6}/LICENSE +0 -0
  13. {gridmlip-0.2.5 → gridmlip-0.2.6}/MANIFEST.in +0 -0
  14. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/__init__.py +0 -0
  15. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/_generate.py +0 -0
  16. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/_mesh.py +0 -0
  17. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/_neighborhood.py +0 -0
  18. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/_percolation_analysis.py +0 -0
  19. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/_void_search.py +0 -0
  20. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/cli.py +0 -0
  21. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/core.py +0 -0
  22. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/integrations/__init__.py +0 -0
  23. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/integrations/bvse.py +0 -0
  24. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/integrations/gnn_lib.py +0 -0
  25. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/integrations/mace.py +0 -0
  26. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/integrations/sevennet.py +0 -0
  27. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip/utils.py +0 -0
  28. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip.egg-info/SOURCES.txt +0 -0
  29. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip.egg-info/dependency_links.txt +0 -0
  30. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip.egg-info/top_level.txt +0 -0
  31. {gridmlip-0.2.5 → gridmlip-0.2.6}/gridmlip.egg-info/zip-safe +0 -0
  32. {gridmlip-0.2.5 → gridmlip-0.2.6}/pyproject.toml +0 -0
  33. {gridmlip-0.2.5 → gridmlip-0.2.6}/scripts/__init__.py +0 -0
  34. {gridmlip-0.2.5 → gridmlip-0.2.6}/scripts/_nebtools.py +0 -0
  35. {gridmlip-0.2.5 → gridmlip-0.2.6}/scripts/_void_search.py +0 -0
  36. {gridmlip-0.2.5 → gridmlip-0.2.6}/scripts/estimate_bvel13k_dataset_size.py +0 -0
  37. {gridmlip-0.2.5 → gridmlip-0.2.6}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gridmlip
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: gridmlip
5
5
  Home-page: https://github.com/dembart/gridmlip
6
6
  Author: Artem Dembitskiy
@@ -74,7 +74,7 @@ g = Grid.from_file(
74
74
  )
75
75
 
76
76
  ### Prepare inequivalent atomic configurations
77
- atoms_list = g.construct_configurations(config_format='ase')
77
+ atoms_list = g.construct_cfgs(config_format='ase')
78
78
 
79
79
  ### Predict energies
80
80
  energy_list, forces_list = evaluate_atoms_list(
@@ -55,7 +55,7 @@ g = Grid.from_file(
55
55
  )
56
56
 
57
57
  ### Prepare inequivalent atomic configurations
58
- atoms_list = g.construct_configurations(config_format='ase')
58
+ atoms_list = g.construct_cfgs(config_format='ase')
59
59
 
60
60
  ### Predict energies
61
61
  energy_list, forces_list = evaluate_atoms_list(
@@ -0,0 +1,112 @@
1
+ import warnings
2
+ import numpy as np
3
+ from ase import Atoms
4
+
5
+
6
+ def _get_rng(rng=None):
7
+ if isinstance(rng, np.random.Generator):
8
+ return rng
9
+ return np.random.default_rng(rng)
10
+
11
+
12
+ def distort_cell_bounded(
13
+ atoms: Atoms,
14
+ strain_std: float = 0.02,
15
+ max_volume_change: float = 0.05,
16
+ max_principal_strain: float = 0.05,
17
+ max_abs_shear_strain: float = 0.05,
18
+ rng: np.random.Generator | None = None,
19
+ max_attempts: int = 100,
20
+ ) -> Atoms:
21
+ """
22
+ Generate a randomly distorted cell with bounded volume change,
23
+ bounded principal stretches, and bounded shear-strain components.
24
+ """
25
+
26
+ rng = _get_rng(rng)
27
+
28
+ original_cell = atoms.get_cell().array.copy()
29
+
30
+ lower_volume = 1.0 - max_volume_change
31
+ upper_volume = 1.0 + max_volume_change
32
+
33
+ for _ in range(max_attempts):
34
+ eps = rng.normal(loc=0.0, scale=strain_std, size=(3, 3))
35
+ eps = 0.5 * (eps + eps.T)
36
+
37
+ eps_offdiag = eps - np.diag(np.diag(eps))
38
+ if np.max(np.abs(eps_offdiag)) > max_abs_shear_strain:
39
+ continue
40
+
41
+ F = np.eye(3) + eps
42
+
43
+ principal_stretches = np.linalg.svd(F, compute_uv=False)
44
+ if (
45
+ np.min(principal_stretches) < 1.0 - max_principal_strain
46
+ or np.max(principal_stretches) > 1.0 + max_principal_strain
47
+ ):
48
+ continue
49
+
50
+ volume_ratio = np.linalg.det(F)
51
+ if not (lower_volume <= volume_ratio <= upper_volume):
52
+ continue
53
+
54
+ new_cell = original_cell @ F.T
55
+ rattled = atoms.copy()
56
+ # scale_atoms=True ensures atomic positions scale with the new cell boundaries
57
+ rattled.set_cell(new_cell, scale_atoms=True)
58
+
59
+ rattled.info["cell_rattle_strain_std"] = strain_std
60
+ rattled.info["cell_rattle_strain"] = eps.tolist()
61
+ rattled.info["cell_volume_ratio"] = volume_ratio
62
+ rattled.info["cell_principal_stretches"] = principal_stretches.tolist()
63
+
64
+ return rattled
65
+
66
+ raise RuntimeError(
67
+ "Could not generate a cell satisfying all deformation constraints."
68
+ )
69
+
70
+
71
+ def rattle_positions(atoms, std=0.05, rng=None):
72
+ """Randomly rattle atomic positions."""
73
+ rng = _get_rng(rng)
74
+
75
+ rattled = atoms.copy()
76
+ rattled.rattle(stdev=std, rng=rng)
77
+ rattled.arrays["original_positions"] = atoms.positions.copy()
78
+ return rattled
79
+
80
+
81
+ def rattle_atoms(
82
+ atoms: Atoms,
83
+ pos_std: float = 0.05,
84
+ strain_std: float = 0.02,
85
+ max_volume_change: float = 0.05,
86
+ max_principal_strain: float = 0.05,
87
+ max_abs_shear_strain: float = 0.05,
88
+ rng: np.random.Generator | None = None,
89
+ max_attempts: int = 100,
90
+ ) -> Atoms:
91
+
92
+ rattled_pos = rattle_positions(atoms, std=pos_std, rng=rng)
93
+
94
+ try:
95
+ final_structure = distort_cell_bounded(
96
+ rattled_pos,
97
+ strain_std=strain_std,
98
+ max_volume_change=max_volume_change,
99
+ max_principal_strain=max_principal_strain,
100
+ max_abs_shear_strain=max_abs_shear_strain,
101
+ rng=rng,
102
+ max_attempts=max_attempts,
103
+ )
104
+ return final_structure
105
+ except RuntimeError as e:
106
+ # Catch the exception, trigger a warning, and fall back to the position-rattled structure
107
+ warnings.warn(
108
+ f"Cell distortion failed: {e}. Returning position-rattled structure only.",
109
+ UserWarning,
110
+ stacklevel=2
111
+ )
112
+ return rattled_pos
@@ -0,0 +1 @@
1
+ __version__ = "0.2.6"
@@ -0,0 +1,91 @@
1
+ import numpy as np
2
+ import fpsample
3
+
4
+ def fps_with_stop(
5
+ points: np.ndarray,
6
+ max_samples: int = 100,
7
+ rel_tol: float = 0.01,
8
+ start_idx: int | None | str = 'centroid',
9
+ rollback: bool = True,
10
+ h: int = 5,
11
+ ) -> np.ndarray:
12
+ """
13
+ FPS sampling with a relative-distance-change stopping criterion.
14
+
15
+ Parameters
16
+ ----------
17
+
18
+ points : np.ndarray
19
+ sample features
20
+
21
+ max_samples : int
22
+ maximum number of samples to select
23
+
24
+ rel_tol : float
25
+ stopping criterion for relative distance change
26
+
27
+ start_idx : int | None | "centroid"
28
+ index of the first sample
29
+ if "centroid" the nearest to the centroid sample will be used
30
+
31
+ rollback : bool
32
+ include the point breaking the stopping criterion
33
+
34
+ h : int
35
+ parameters of the fpsample.bucket_fps_kdline_sampling
36
+ see the fpsample docs
37
+
38
+
39
+
40
+ """
41
+ points = np.ascontiguousarray(points, dtype=np.float32)
42
+ N, D = points.shape
43
+ if max_samples >= N:
44
+ max_samples = N
45
+ assert max_samples > 0
46
+
47
+ # over-sample with fpsample
48
+
49
+ if start_idx == 'centroid':
50
+ centroid = points.mean(axis=0)
51
+ start_idx = int(np.argmin(np.linalg.norm(points - centroid, axis=1)))
52
+
53
+ if D > 8:
54
+ # KD-tree backend supports at most 8 dims
55
+ indices = fpsample.fps_sampling(
56
+ points, max_samples, start_idx=start_idx
57
+ ).astype(np.int64)
58
+ else:
59
+ # clamp h so the bucket size is valid: 2**h <= N
60
+
61
+ h_eff = max(1, min(h, int(np.floor(np.log2(max(N, 1))))))
62
+
63
+ indices = fpsample.bucket_fps_kdline_sampling(
64
+ points, max_samples, h=h_eff, start_idx=start_idx
65
+ ).astype(np.int64)
66
+
67
+ if len(indices) <= 2:
68
+ return indices
69
+
70
+ # traverse and apply stopping criterion
71
+ selected = [int(indices[0])]
72
+ min_dists = np.linalg.norm(points - points[indices[0]], axis=1)
73
+ prev_d = None
74
+
75
+ for k in range(1, len(indices)):
76
+ idx = int(indices[k])
77
+ curr_d = float(min_dists[idx])
78
+
79
+ if prev_d is not None and prev_d > 0.0:
80
+ if abs(curr_d - prev_d) / prev_d < rel_tol:
81
+ if not rollback:
82
+ selected.append(idx)
83
+ break
84
+
85
+ selected.append(idx)
86
+ prev_d = curr_d
87
+
88
+ new_d = np.linalg.norm(points - points[idx], axis=1)
89
+ np.minimum(min_dists, new_d, out=min_dists)
90
+
91
+ return np.asarray(selected, dtype=np.int64)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: gridmlip
3
- Version: 0.2.5
3
+ Version: 0.2.6
4
4
  Summary: gridmlip
5
5
  Home-page: https://github.com/dembart/gridmlip
6
6
  Author: Artem Dembitskiy
@@ -74,7 +74,7 @@ g = Grid.from_file(
74
74
  )
75
75
 
76
76
  ### Prepare inequivalent atomic configurations
77
- atoms_list = g.construct_configurations(config_format='ase')
77
+ atoms_list = g.construct_cfgs(config_format='ase')
78
78
 
79
79
  ### Predict energies
80
80
  energy_list, forces_list = evaluate_atoms_list(
@@ -1,6 +1,8 @@
1
1
  numpy
2
2
  spglib
3
3
  ase
4
+ ions
4
5
  tqdm
5
6
  scipy
6
7
  joblib
8
+ fpsample
@@ -26,9 +26,11 @@ install_requires =
26
26
  numpy
27
27
  spglib
28
28
  ase
29
+ ions
29
30
  tqdm
30
31
  scipy
31
32
  joblib
33
+ fpsample
32
34
 
33
35
  [egg_info]
34
36
  tag_build =
@@ -1,44 +0,0 @@
1
- import numpy as np
2
-
3
-
4
- def _get_rng(rng=None):
5
- if isinstance(rng, np.random.Generator):
6
- return rng
7
- return np.random.default_rng(rng)
8
-
9
-
10
- def distort_lattice(atoms, std=0.03, rng=None):
11
- """Randomly apply independent strain to the three lattice vectors."""
12
- rng = _get_rng(rng)
13
-
14
- cell = atoms.cell.array.copy()
15
- lengths = np.linalg.norm(cell, axis=1)
16
-
17
- scale = rng.uniform(
18
- 1 - std,
19
- 1 + std,
20
- size=3,
21
- )
22
-
23
- new_lengths = lengths * scale
24
- new_cell = cell * (new_lengths / lengths)[:, None]
25
-
26
- distorted = atoms.copy()
27
- distorted.info["original_cell"] = atoms.cell.array.copy()
28
- distorted.set_cell(new_cell, scale_atoms=True)
29
-
30
- return distorted
31
-
32
-
33
- def rattle_positions(atoms, std=0.05, rng=None):
34
- """Randomly rattle atomic positions."""
35
- rng = _get_rng(rng)
36
-
37
- rattled = atoms.copy()
38
- rattled.arrays["original_positions"] = (
39
- rattled.positions.copy()
40
- )
41
-
42
- rattled.rattle(stdev=std, rng=rng)
43
-
44
- return rattled
@@ -1 +0,0 @@
1
- __version__ = "0.2.5"
@@ -1 +0,0 @@
1
- # FPS sampling with/without relative distance
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes