Skip to content

Commit a3ed184

Browse files
committed
Merge branch 'refactor-core-matcher-fc2ec' of github.com:materialsproject/pymatgen into refactor-core-matcher-fc2ec
2 parents 2582c96 + 1cd742a commit a3ed184

12 files changed

+267
-88
lines changed

dev_scripts/chemenv/check_new_coordination_geometry.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from __future__ import annotations
22

3-
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import AllCoordinationGeometries
4-
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import LocalGeometryFinder
3+
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
4+
AllCoordinationGeometries,
5+
)
6+
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import (
7+
LocalGeometryFinder,
8+
)
59

610
all_cg = AllCoordinationGeometries()
711

dev_scripts/chemenv/explicit_permutations.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class Algo:
3636
# Choose the geometry
3737
all_cg = AllCoordinationGeometries()
3838
while True:
39-
cg_symbol = input("Enter symbol of the geometry for which you want to get the explicit permutations : ")
39+
cg_symbol = input(
40+
"Enter symbol of the geometry for which you want to get the explicit permutations : "
41+
)
4042
try:
4143
cg = all_cg[cg_symbol]
4244
break
@@ -59,8 +61,10 @@ class Algo:
5961
lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
6062

6163
points_perfect = lgf.perfect_geometry.points_wocs_ctwocc()
62-
csms, perms, algos, local2perfect_maps, perfect2local_maps = lgf.coordination_geometry_symmetry_measures_standard(
63-
coordination_geometry=cg, algo=algo, points_perfect=points_perfect
64+
csms, perms, algos, local2perfect_maps, perfect2local_maps = (
65+
lgf.coordination_geometry_symmetry_measures_standard(
66+
coordination_geometry=cg, algo=algo, points_perfect=points_perfect
67+
)
6468
)
6569

6670
csms_with_recorded_permutation: list[float] = []
@@ -90,8 +94,12 @@ class Algo:
9094
if test == "y":
9195
if len(cg.algorithms) != 1:
9296
raise ValueError("Multiple algorithms !")
93-
cg._algorithms = [ExplicitPermutationsAlgorithm(permutations=explicit_permutations)]
97+
cg._algorithms = [
98+
ExplicitPermutationsAlgorithm(permutations=explicit_permutations)
99+
]
94100
new_geom_dir = "new_geometry_files"
95101
os.makedirs(new_geom_dir, exist_ok=True)
96-
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
102+
with open(
103+
f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8"
104+
) as file:
97105
json.dump(cg.as_dict(), file)

dev_scripts/chemenv/explicit_permutations_plane_algorithm.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010

1111
import numpy as np
1212

13-
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import AllCoordinationGeometries
13+
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
14+
AllCoordinationGeometries,
15+
)
1416
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import (
1517
AbstractGeometry,
1618
LocalGeometryFinder,
@@ -21,7 +23,9 @@
2123
# Choose the geometry
2224
all_cg = AllCoordinationGeometries()
2325
while True:
24-
cg_symbol = input("Enter symbol of the geometry for which you want to get the explicit permutations : ")
26+
cg_symbol = input(
27+
"Enter symbol of the geometry for which you want to get the explicit permutations : "
28+
)
2529
try:
2630
cg = all_cg[cg_symbol]
2731
break
@@ -74,8 +78,12 @@
7478
):
7579
if found:
7680
break
77-
for ipoints in itertools.combinations(sep_plane_algo.plane_points, n_points):
78-
points_combination = [lgf.local_geometry.coords[ipoint] for ipoint in ipoints]
81+
for ipoints in itertools.combinations(
82+
sep_plane_algo.plane_points, n_points
83+
):
84+
points_combination = [
85+
lgf.local_geometry.coords[ipoint] for ipoint in ipoints
86+
]
7987
if n_points == 2:
8088
if collinear(
8189
points_combination[0],
@@ -107,11 +115,15 @@
107115
found = True
108116
break
109117
elif n_points > 3:
110-
local_plane = Plane.from_npoints(points_combination, best_fit="least_square_distance")
118+
local_plane = Plane.from_npoints(
119+
points_combination, best_fit="least_square_distance"
120+
)
111121
found = True
112122
break
113123
else:
114-
raise ValueError("Wrong number of points to initialize separation plane")
124+
raise ValueError(
125+
"Wrong number of points to initialize separation plane"
126+
)
115127

116128
points_perfect = lgf.perfect_geometry.points_wocs_ctwocc()
117129
# Actual test of the permutations
@@ -159,5 +171,9 @@
159171
if test == "y":
160172
cg._algorithms = new_algos
161173
cg_dict = cg.as_dict()
162-
with open(f"../coordination_geometries_files_new/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
174+
with open(
175+
f"../coordination_geometries_files_new/{cg_symbol}.json",
176+
mode="w",
177+
encoding="utf-8",
178+
) as file:
163179
json.dump(cg_dict, file)

dev_scripts/chemenv/get_plane_permutations_optimized.py

Lines changed: 62 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
import numpy as np
1717
import tabulate
1818

19-
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import AllCoordinationGeometries
19+
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
20+
AllCoordinationGeometries,
21+
)
2022
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometry_finder import (
2123
AbstractGeometry,
2224
LocalGeometryFinder,
@@ -157,7 +159,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
157159

158160
cg = all_cg[cg_symbol]
159161

160-
print(f"Getting explicit permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n")
162+
print(
163+
f"Getting explicit permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n"
164+
)
161165

162166
# Setup of the local geometry finder
163167
lgf = LocalGeometryFinder()
@@ -180,7 +184,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
180184
algo._permutations = algo.explicit_permutations
181185
algo.minimum_number_of_points = 4
182186
if algo.algorithm_type == "EXPLICIT_PERMUTATIONS":
183-
raise ValueError("Do something for the explicit ones ... (these should anyway be by far ok!)")
187+
raise ValueError(
188+
"Do something for the explicit ones ... (these should anyway be by far ok!)"
189+
)
184190
if algo.explicit_optimized_permutations is None:
185191
eop = "no"
186192
else:
@@ -198,7 +204,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
198204
f"{len(algo.explicit_permutations)} explicit permutations"
199205
)
200206
if algo.other_plane_points is None:
201-
input("Multiplicity and other plane points is not defined for this algorithm !")
207+
input(
208+
"Multiplicity and other plane points is not defined for this algorithm !"
209+
)
202210

203211
# Setup of safe permutations
204212
permutations = algo.safe_separation_permutations(
@@ -221,8 +229,12 @@ def random_permutations_iterator(initial_permutation, n_permutations):
221229
printing_volume=printing_volume,
222230
)
223231

224-
points_combination = [lgf.local_geometry._coords[ii] for ii in plane_point_indices]
225-
local_plane = Plane.from_npoints(points_combination, best_fit="least_square_distance")
232+
points_combination = [
233+
lgf.local_geometry._coords[ii] for ii in plane_point_indices
234+
]
235+
local_plane = Plane.from_npoints(
236+
points_combination, best_fit="least_square_distance"
237+
)
226238

227239
# Actual test of the permutations
228240
csms, perms, algos, sep_perms = lgf._cg_csm_separation_plane(
@@ -246,7 +258,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
246258
for icsm, csm in enumerate(csms):
247259
found = False
248260
for csm2 in csms_with_recorded_permutation:
249-
if np.isclose(csm["symmetry_measure"], csm2["symmetry_measure"], rtol=0.0):
261+
if np.isclose(
262+
csm["symmetry_measure"], csm2["symmetry_measure"], rtol=0.0
263+
):
250264
found = True
251265
break
252266
if not found:
@@ -269,8 +283,12 @@ def random_permutations_iterator(initial_permutation, n_permutations):
269283
print("Explicit permutations per plane :")
270284
for eppp in explicit_permutations_per_plane:
271285
print(eppp)
272-
raise ValueError("Explicit permutations different from one plane to another !")
273-
algo.explicit_permutations = [list(perm) for perm in list(explicit_permutations_per_plane[0])]
286+
raise ValueError(
287+
"Explicit permutations different from one plane to another !"
288+
)
289+
algo.explicit_permutations = [
290+
list(perm) for perm in list(explicit_permutations_per_plane[0])
291+
]
274292
algo.explicit_permutations.sort()
275293
algo.explicit_permutations = np.array(algo.explicit_permutations)
276294
print(f"Explicit permutations found ({len(algo.explicit_permutations)})")
@@ -292,7 +310,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
292310
elif test == "q":
293311
raise SystemExit(0)
294312
# 2. Optimization of the permutations
295-
print(f"Getting explicit optimized permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n")
313+
print(
314+
f"Getting explicit optimized permutations for geometry {cg.name!r} (symbol : {cg_symbol!r})\n"
315+
)
296316
perms_used_algos: list[dict] = [{} for _ in cg.algorithms]
297317

298318
# Loop on algorithms
@@ -305,7 +325,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
305325
f"side_1 : [{', '.join(map(str, algo.point_groups[1]))}])"
306326
)
307327
if algo.algorithm_type == "EXPLICIT_PERMUTATIONS":
308-
raise ValueError("Do something for the explicit ones ... (these should anyway be by far ok!)")
328+
raise ValueError(
329+
"Do something for the explicit ones ... (these should anyway be by far ok!)"
330+
)
309331

310332
# Definition of the facets
311333
all_planes_point_indices = [algo.plane_points]
@@ -318,7 +340,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
318340
perms_iterator = itertools.permutations(indices)
319341
n_permutations = factorial(cg.coordination_number)
320342
elif permutations_setup_type == "n":
321-
if n_permutations and n_permutations >= factorial(cg.coordination_number):
343+
if n_permutations and n_permutations >= factorial(
344+
cg.coordination_number
345+
):
322346
perms_iterator = itertools.permutations(indices)
323347
n_permutations = factorial(cg.coordination_number)
324348
else:
@@ -327,7 +351,9 @@ def random_permutations_iterator(initial_permutation, n_permutations):
327351
)
328352
elif permutations_setup_type in ["x", "y"] and n_perm_factor:
329353
n_permutations = n_perm_factor * len(algo.explicit_permutations)
330-
if permutations_setup_type == "y" and n_permutations >= factorial(cg.coordination_number):
354+
if permutations_setup_type == "y" and n_permutations >= factorial(
355+
cg.coordination_number
356+
):
331357
perms_iterator = itertools.permutations(indices)
332358
n_permutations = factorial(cg.coordination_number)
333359
else:
@@ -361,17 +387,27 @@ def random_permutations_iterator(initial_permutation, n_permutations):
361387

362388
# Loop on the facets
363389
separation_permutations = []
364-
for idx_plane, plane_point_indices in enumerate(all_planes_point_indices):
390+
for idx_plane, plane_point_indices in enumerate(
391+
all_planes_point_indices
392+
):
365393
prt2(
366394
string=f"In plane {idx_plane} ({'-'.join(str(pp) for pp in plane_point_indices)})",
367395
printing_volume=printing_volume,
368396
)
369397

370398
# Setup of separation plane
371-
perm_plane_points_indices = [indices_perm.index(plane_point) for plane_point in plane_point_indices]
399+
perm_plane_points_indices = [
400+
indices_perm.index(plane_point)
401+
for plane_point in plane_point_indices
402+
]
372403
shuffle(perm_plane_points_indices)
373-
points_combination = [lgf.local_geometry._coords[ii] for ii in perm_plane_points_indices]
374-
local_plane = Plane.from_npoints(points_combination, best_fit="least_square_distance")
404+
points_combination = [
405+
lgf.local_geometry._coords[ii]
406+
for ii in perm_plane_points_indices
407+
]
408+
local_plane = Plane.from_npoints(
409+
points_combination, best_fit="least_square_distance"
410+
)
375411

376412
# Get the results for this algorithm and plane
377413
csms, perms, algos, sep_perms = lgf._cg_csm_separation_plane(
@@ -431,9 +467,13 @@ def random_permutations_iterator(initial_permutation, n_permutations):
431467
explicit_optimized_permutations.sort()
432468
print(explicit_optimized_permutations)
433469
print()
434-
test = input(f'Set optimized permutations for algorithm {idx} ? ("y" to confirm)')
470+
test = input(
471+
f'Set optimized permutations for algorithm {idx} ? ("y" to confirm)'
472+
)
435473
if test == "y":
436-
algo.explicit_optimized_permutations = np.array(explicit_optimized_permutations)
474+
algo.explicit_optimized_permutations = np.array(
475+
explicit_optimized_permutations
476+
)
437477

438478
test = input(
439479
f"Save coordination geometry {cg.name!r} (symbol {cg_symbol!r}) and new explicit and optimized "
@@ -442,5 +482,7 @@ def random_permutations_iterator(initial_permutation, n_permutations):
442482
if test == "y":
443483
new_geom_dir = "new_geometry_files"
444484
os.makedirs(new_geom_dir, exist_ok=True)
445-
with open(f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8") as file:
485+
with open(
486+
f"{new_geom_dir}/{cg_symbol}.json", mode="w", encoding="utf-8"
487+
) as file:
446488
json.dump(cg.as_dict(), file)

dev_scripts/chemenv/plane_multiplicity.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
from __future__ import annotations
44

5-
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import AllCoordinationGeometries
5+
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
6+
AllCoordinationGeometries,
7+
)
68

79
__author__ = "David Waroquiers"
810
__copyright__ = "Copyright 2012, The Materials Project"

0 commit comments

Comments
 (0)