Skip to content

Commit

Permalink
Ruff format.
Browse files Browse the repository at this point in the history
  • Loading branch information
shyuep committed Oct 23, 2024
1 parent 567d3dd commit 930ae36
Show file tree
Hide file tree
Showing 276 changed files with 7,709 additions and 1,535 deletions.
31 changes: 24 additions & 7 deletions dev_scripts/chemenv/explicit_permutations_plane_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
perms_on_file = f"Permutations on file in this algorithm ({len(sep_plane_algo._permutations)}) "
print(f"{perms_on_file}\n{sep_plane_algo._permutations}")
permutations = sep_plane_algo.safe_separation_permutations(
ordered_plane=sep_plane_algo.ordered_plane, ordered_point_groups=sep_plane_algo.ordered_point_groups
ordered_plane=sep_plane_algo.ordered_plane,
ordered_point_groups=sep_plane_algo.ordered_point_groups,
)

sep_plane_algo._permutations = permutations
Expand All @@ -56,7 +57,10 @@
lgf = LocalGeometryFinder()
lgf.setup_parameters(structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE)
lgf.setup_test_perfect_environment(
cg_symbol, randomness=True, indices=range(cg.coordination_number), max_random_dist=0.05
cg_symbol,
randomness=True,
indices=range(cg.coordination_number),
max_random_dist=0.05,
)

lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
Expand All @@ -65,27 +69,40 @@
local_plane = None
found = False
for n_points in range(
sep_plane_algo.minimum_number_of_points, min(sep_plane_algo.maximum_number_of_points, 4) + 1
sep_plane_algo.minimum_number_of_points,
min(sep_plane_algo.maximum_number_of_points, 4) + 1,
):
if found:
break
for ipoints in itertools.combinations(sep_plane_algo.plane_points, n_points):
points_combination = [lgf.local_geometry.coords[ipoint] for ipoint in ipoints]
if n_points == 2:
if collinear(
points_combination[0], points_combination[1], lgf.local_geometry.central_site, tolerance=0.25
points_combination[0],
points_combination[1],
lgf.local_geometry.central_site,
tolerance=0.25,
):
continue
local_plane = Plane.from_3points(
points_combination[0], points_combination[1], lgf.local_geometry.central_site
points_combination[0],
points_combination[1],
lgf.local_geometry.central_site,
)
found = True
break
elif n_points == 3:
if collinear(points_combination[0], points_combination[1], points_combination[2], tolerance=0.25):
if collinear(
points_combination[0],
points_combination[1],
points_combination[2],
tolerance=0.25,
):
continue
local_plane = Plane.from_3points(
points_combination[0], points_combination[1], points_combination[2]
points_combination[0],
points_combination[1],
points_combination[2],
)
found = True
break
Expand Down
19 changes: 15 additions & 4 deletions dev_scripts/chemenv/get_plane_permutations_optimized.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,10 @@ def random_permutations_iterator(initial_permutation, n_permutations):

# Setup the random environment
lgf.setup_test_perfect_environment(
cg_symbol, randomness=True, indices=range(cg.coordination_number), max_random_dist=0.05
cg_symbol,
randomness=True,
indices=range(cg.coordination_number),
max_random_dist=0.05,
)
lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
points_perfect = lgf.perfect_geometry.points_wcs_ctwcc()
Expand Down Expand Up @@ -201,7 +204,8 @@ def random_permutations_iterator(initial_permutation, n_permutations):

# Setup of safe permutations
permutations = algo.safe_separation_permutations(
ordered_plane=algo.ordered_plane, ordered_point_groups=algo.ordered_point_groups
ordered_plane=algo.ordered_plane,
ordered_point_groups=algo.ordered_point_groups,
)
algo._permutations = permutations
print(f"Safe permutations found ({len(permutations)})")
Expand Down Expand Up @@ -234,7 +238,10 @@ def random_permutations_iterator(initial_permutation, n_permutations):
)

sym_measures = [c["symmetry_measure"] for c in csms]
prt1(string="Continuous symmetry measures", printing_volume=printing_volume)
prt1(
string="Continuous symmetry measures",
printing_volume=printing_volume,
)
prt1(string=sym_measures, printing_volume=printing_volume)
csms_with_recorded_permutation: list = []
explicit_permutations = []
Expand Down Expand Up @@ -345,7 +352,11 @@ def random_permutations_iterator(initial_permutation, n_permutations):
)
# Setup of the local and perfect geometries
lgf.setup_test_perfect_environment(
cg_symbol, indices=indices_perm, randomness=True, max_random_dist=0.02, random_rotation=True
cg_symbol,
indices=indices_perm,
randomness=True,
max_random_dist=0.02,
random_rotation=True,
)
lgf.perfect_geometry = AbstractGeometry.from_cg(cg=cg)
points_perfect = lgf.perfect_geometry.points_wcs_ctwcc()
Expand Down
15 changes: 14 additions & 1 deletion dev_scripts/chemenv/plane_multiplicity.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@

# I:12
if cg_symbol == "I:12":
opposite_points = {0: 3, 1: 2, 2: 1, 3: 0, 4: 7, 5: 6, 6: 5, 7: 4, 8: 11, 9: 10, 10: 9, 11: 8}
opposite_points = {
0: 3,
1: 2,
2: 1,
3: 0,
4: 7,
5: 6,
6: 5,
7: 4,
8: 11,
9: 10,
10: 9,
11: 8,
}
edges = cg._edges
for edge in edges:
opposite_edge = [opposite_points[edge[0]], opposite_points[edge[1]]]
Expand Down
60 changes: 48 additions & 12 deletions dev_scripts/chemenv/strategies/multi_weights_strategy_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@
class CoordinationEnvironmentMorphing:
"""Morph a coordination environment into another one."""

def __init__(self, initial_environment_symbol, expected_final_environment_symbol, morphing_description):
def __init__(
self,
initial_environment_symbol,
expected_final_environment_symbol,
morphing_description,
):
self.initial_environment_symbol = initial_environment_symbol
self.expected_final_environment_symbol = expected_final_environment_symbol
self.morphing_description = morphing_description
Expand All @@ -52,7 +57,10 @@ def __init__(self, initial_environment_symbol, expected_final_environment_symbol

@classmethod
def simple_expansion(
cls, initial_environment_symbol, expected_final_environment_symbol, neighbors_indices
cls,
initial_environment_symbol,
expected_final_environment_symbol,
neighbors_indices,
) -> CoordinationEnvironmentMorphing:
"""Simple expansion of a coordination environment.
Expand All @@ -65,7 +73,11 @@ def simple_expansion(
CoordinationEnvironmentMorphing
"""
morphing_description = [
{"ineighbor": nbr_idx, "site_type": "neighbor", "expansion_origin": "central_site"}
{
"ineighbor": nbr_idx,
"site_type": "neighbor",
"expansion_origin": "central_site",
}
for nbr_idx in neighbors_indices
]
return cls(
Expand Down Expand Up @@ -111,7 +123,10 @@ def figure_fractions(self, weights_options: dict, morphing_factors: Sequence[flo
se = lgf.compute_structure_environments(only_indices=[0], valences=fake_valences)
strategy.set_structure_environments(structure_environments=se)
result = strategy.get_site_coordination_environments_fractions(
site=se.structure[0], isite=0, return_strategy_dict_info=True, return_all=True
site=se.structure[0],
isite=0,
return_strategy_dict_info=True,
return_all=True,
)
for res in result:
if res["ce_symbol"] == self.initial_environment_symbol:
Expand Down Expand Up @@ -167,7 +182,10 @@ def get_structure(self, morphing_factor):
return Structure(lattice=lattice, species=species, coords=coords, coords_are_cartesian=True)

def estimate_parameters(self, dist_factor_min, dist_factor_max, symmetry_measure_type="csm_wcs_ctwcc"):
only_symbols = [self.initial_environment_symbol, self.expected_final_environment_symbol]
only_symbols = [
self.initial_environment_symbol,
self.expected_final_environment_symbol,
]
# Set up the local geometry finder
lgf = LocalGeometryFinder()
lgf.setup_parameters(structure_refinement=lgf.STRUCTURE_REFINEMENT_NONE)
Expand Down Expand Up @@ -211,18 +229,25 @@ def estimate_parameters(self, dist_factor_min, dist_factor_max, symmetry_measure
if not np.isclose(csm_final, 0.0, rtol=0.0, atol=1e-10):
raise ValueError("Final coordination is not perfect !")

return {"delta_csm_min": csm_initial_min_dist, "self_weight_max_csm": csm_initial_max_dist}
return {
"delta_csm_min": csm_initial_min_dist,
"self_weight_max_csm": csm_initial_max_dist,
}

def get_weights(self, weights_options):
effective_csm_estimator = {"function": "power2_inverse_decreasing", "options": {"max_csm": 8.0}}
effective_csm_estimator = {
"function": "power2_inverse_decreasing",
"options": {"max_csm": 8.0},
}

self_weight_estimator = {
"function": "power2_decreasing_exp",
"options": {"max_csm": 5.4230949041608305, "alpha": 1.0},
}

self_csm_weight = SelfCSMNbSetWeight(
effective_csm_estimator=effective_csm_estimator, weight_estimator=self_weight_estimator
effective_csm_estimator=effective_csm_estimator,
weight_estimator=self_weight_estimator,
)

surface_definition = {
Expand All @@ -239,7 +264,10 @@ def get_weights(self, weights_options):
additional_condition=DistanceAngleAreaNbSetWeight.AC.ONLY_ACB,
)

weight_estimator = {"function": "smootherstep", "options": {"delta_csm_min": 0.5, "delta_csm_max": 3.0}}
weight_estimator = {
"function": "smootherstep",
"options": {"delta_csm_min": 0.5, "delta_csm_max": 3.0},
}

symmetry_measure_type = "csm_wcs_ctwcc"
delta_csm_weight = DeltaCSMNbSetWeight(
Expand Down Expand Up @@ -294,7 +322,9 @@ def get_weights(self, weights_options):
min_dist = ce_pair_dict["dist_factor_min"]
max_dist = ce_pair_dict["dist_factor_max"]
morph = CoordinationEnvironmentMorphing.simple_expansion(
initial_environment_symbol=ce1, expected_final_environment_symbol=ce2, neighbors_indices=n_indices
initial_environment_symbol=ce1,
expected_final_environment_symbol=ce2,
neighbors_indices=n_indices,
)
params = morph.estimate_parameters(dist_factor_min=min_dist, dist_factor_max=max_dist)
print(f"For pair {ce1} to {ce2}, parameters are : ")
Expand All @@ -311,7 +341,11 @@ def get_weights(self, weights_options):
for idx, cn_pair in enumerate(all_cn_pairs):
if len(self_weight_max_csms[cn_pair]) == 0:
continue
ax.plot(idx * np.ones_like(self_weight_max_csms[cn_pair]), self_weight_max_csms[cn_pair], "rx")
ax.plot(
idx * np.ones_like(self_weight_max_csms[cn_pair]),
self_weight_max_csms[cn_pair],
"rx",
)
ax.plot(idx * np.ones_like(delta_csm_mins[cn_pair]), delta_csm_mins[cn_pair], "b+")

ax.set_xticks(range(len(all_cn_pairs)))
Expand All @@ -323,7 +357,9 @@ def get_weights(self, weights_options):

for cn in range(1, 14):
subplot2.plot(
cn * np.ones_like(self_weight_max_csms_per_cn[str(cn)]), self_weight_max_csms_per_cn[str(cn)], "rx"
cn * np.ones_like(self_weight_max_csms_per_cn[str(cn)]),
self_weight_max_csms_per_cn[str(cn)],
"rx",
)

subplot2.set_xticks(range(1, 14))
Expand Down
4 changes: 3 additions & 1 deletion dev_scripts/chemenv/test_algos_all_geoms.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@
# raise ValueError('Do something for the explicit ones ... (these should anyway be by far ok!)')
else:
results = lgf.coordination_geometry_symmetry_measures_separation_plane(
coordination_geometry=cg, separation_plane_algo=algo, points_perfect=points_perfect
coordination_geometry=cg,
separation_plane_algo=algo,
points_perfect=points_perfect,
)
algos_results.append(min(results[0]))

Expand Down
34 changes: 30 additions & 4 deletions dev_scripts/chemenv/view_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,42 @@

if algo.minimum_number_of_points == 2:
vis.add_partial_sphere(
coords=cg_central_site, radius=radius, color=[1, 0, 0], start=0, end=360, opacity=0.5
coords=cg_central_site,
radius=radius,
color=[1, 0, 0],
start=0,
end=360,
opacity=0.5,
)
for pp in pts:
vis.add_partial_sphere(coords=pp, radius=radius, color=[1, 0, 0], start=0, end=360, opacity=0.5)
vis.add_partial_sphere(
coords=pp,
radius=radius,
color=[1, 0, 0],
start=0,
end=360,
opacity=0.5,
)

ps1 = [cg_points[ii] for ii in algo.point_groups[0]]
ps2 = [cg_points[ii] for ii in algo.point_groups[1]]

for pp in ps1:
vis.add_partial_sphere(coords=pp, radius=radius, color=[0, 1, 0], start=0, end=360, opacity=0.5)
vis.add_partial_sphere(
coords=pp,
radius=radius,
color=[0, 1, 0],
start=0,
end=360,
opacity=0.5,
)
for pp in ps2:
vis.add_partial_sphere(coords=pp, radius=radius, color=[0, 0, 1], start=0, end=360, opacity=0.5)
vis.add_partial_sphere(
coords=pp,
radius=radius,
color=[0, 0, 1],
start=0,
end=360,
opacity=0.5,
)
vis.show()
5 changes: 4 additions & 1 deletion dev_scripts/potcar_scrambler.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,10 @@ def generate_fake_potcar_libraries() -> None:
for potcar_path in paths_to_try:
if os.path.isfile(potcar_path):
os.makedirs(rebase_dir, exist_ok=True)
PotcarScrambler.from_file(input_filename=potcar_path, output_filename=f"{rebase_dir}/POTCAR.gz")
PotcarScrambler.from_file(
input_filename=potcar_path,
output_filename=f"{rebase_dir}/POTCAR.gz",
)
break


Expand Down
6 changes: 5 additions & 1 deletion dev_scripts/update_pt_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,11 @@ def gen_iupac_ordering():

order = [item for sublist in (list(product(x, y)) for x, y in order) for item in sublist]
iupac_ordering_dict = dict(
zip([Element.from_row_and_group(row, group) for group, row in order], range(len(order)), strict=True)
zip(
[Element.from_row_and_group(row, group) for group, row in order],
range(len(order)),
strict=True,
)
)

# first clean periodic table of any IUPAC ordering
Expand Down
6 changes: 5 additions & 1 deletion src/pymatgen/alchemy/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ def from_dict(cls, dct: dict) -> Self:
class RemoveDuplicatesFilter(AbstractStructureFilter):
"""This filter removes exact duplicate structures from the transmuter."""

def __init__(self, structure_matcher: dict | StructureMatcher | None = None, symprec: float | None = None) -> None:
def __init__(
self,
structure_matcher: dict | StructureMatcher | None = None,
symprec: float | None = None,
) -> None:
"""Remove duplicate structures based on the structure matcher
and symmetry (if symprec is given).
Expand Down
2 changes: 1 addition & 1 deletion src/pymatgen/alchemy/materials.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class TransformedStructure(MSONable):
def __init__(
self,
structure: Structure,
transformations: AbstractTransformation | Sequence[AbstractTransformation] | None = None,
transformations: (AbstractTransformation | Sequence[AbstractTransformation] | None) = None,
history: list[AbstractTransformation | dict[str, Any]] | None = None,
other_parameters: dict[str, Any] | None = None,
) -> None:
Expand Down
5 changes: 4 additions & 1 deletion src/pymatgen/alchemy/transmuters.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,10 @@ def apply_filter(self, structure_filter: AbstractStructureFilter):
structure_filter: StructureFilter to apply.
"""
self.transformed_structures = list(
filter(lambda ts: structure_filter.test(ts.final_structure), self.transformed_structures)
filter(
lambda ts: structure_filter.test(ts.final_structure),
self.transformed_structures,
)
)
for ts in self.transformed_structures:
ts.append_filter(structure_filter)
Expand Down
Loading

0 comments on commit 930ae36

Please sign in to comment.