1616import numpy as np
1717import 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+ )
2022from 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 )
0 commit comments