Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Breaking typo fix: Targe(tt->t)edPenaltiedAbundanceChemenvStrategy #3360

Merged
merged 6 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,10 @@ def get_site_neighbors(self, site, isite=None, dequivsite=None, dthissite=None,
)

nb_set = self.structure_environments.neighbors_sets[isite][cn_map[0]][cn_map[1]]
eqsite_ps = nb_set.neighb_sites
eq_site_ps = nb_set.neighb_sites

coordinated_neighbors = []
for ps in eqsite_ps:
for ps in eq_site_ps:
coords = mysym.operate(ps.frac_coords + dequivsite) + dthissite
ps_site = PeriodicSite(ps._species, coords, ps._lattice)
coordinated_neighbors.append(ps_site)
Expand Down Expand Up @@ -1029,7 +1029,7 @@ def from_dict(cls, d):
return cls(additional_condition=d["additional_condition"])


class TargettedPenaltiedAbundanceChemenvStrategy(SimpleAbundanceChemenvStrategy):
class TargetedPenaltiedAbundanceChemenvStrategy(SimpleAbundanceChemenvStrategy):
"""
Simple ChemenvStrategy using the neighbors that are the most "abundant" in the grid of angle and distance
parameters for the definition of neighbors in the Voronoi approach, with a bias for a given list of target
Expand All @@ -1050,7 +1050,7 @@ def __init__(
max_csm=5.0,
symmetry_measure_type=AbstractChemenvStrategy.DEFAULT_SYMMETRY_MEASURE_TYPE,
):
"""Initializes strategy.
"""Initialize strategy.

Not yet implemented.
:param structure_environments:
Expand All @@ -1072,7 +1072,7 @@ def __init__(
self.target_environments = target_environments
self.target_penalty_type = target_penalty_type
self.max_csm = max_csm
raise NotImplementedError("TargettedPenaltiedAbundanceChemenvStrategy not yet implemented")
raise NotImplementedError("TargetedPenaltiedAbundanceChemenvStrategy not yet implemented")

def get_site_coordination_environment(
self,
Expand Down Expand Up @@ -1157,10 +1157,10 @@ def uniquely_determines_coordination_environments(self):

def as_dict(self):
"""
Bson-serializable dict representation of the TargettedPenaltiedAbundanceChemenvStrategy object.
Bson-serializable dict representation of the TargetedPenaltiedAbundanceChemenvStrategy object.

Returns:
Bson-serializable dict representation of the TargettedPenaltiedAbundanceChemenvStrategy object.
Bson-serializable dict representation of the TargetedPenaltiedAbundanceChemenvStrategy object.
"""
return {
"@module": type(self).__module__,
Expand All @@ -1187,12 +1187,12 @@ def __eq__(self, other: object) -> bool:
@classmethod
def from_dict(cls, d):
"""
Reconstructs the TargettedPenaltiedAbundanceChemenvStrategy object from a dict representation of the
TargettedPenaltiedAbundanceChemenvStrategy object created using the as_dict method.
:param d: dict representation of the TargettedPenaltiedAbundanceChemenvStrategy object
Reconstructs the TargetedPenaltiedAbundanceChemenvStrategy object from a dict representation of the
TargetedPenaltiedAbundanceChemenvStrategy object created using the as_dict method.
:param d: dict representation of the TargetedPenaltiedAbundanceChemenvStrategy object

Returns:
TargettedPenaltiedAbundanceChemenvStrategy object.
TargetedPenaltiedAbundanceChemenvStrategy object.
"""
return cls(
additional_condition=d["additional_condition"],
Expand Down Expand Up @@ -1678,7 +1678,7 @@ def __init__(
delta_cn_weight_estimators=None,
symmetry_measure_type=DEFAULT_SYMMETRY_MEASURE_TYPE,
):
"""Initialize SelfCSMNbSetWeight.
"""Initialize DeltaCSMNbSetWeight.

:param effective_csm_estimator: Ratio function used for the effective CSM (comparison between neighbors sets).
:param weight_estimator: Weight estimator within a given neighbors set.
Expand Down Expand Up @@ -1815,7 +1815,7 @@ def delta_cn_specifics(
symmetry_measure_type="csm_wcs_ctwcc",
effective_csm_estimator=DEFAULT_EFFECTIVE_CSM_ESTIMATOR,
):
"""Initializes DeltaCSMNbSetWeight from specific coordination number differences.
"""Initialize DeltaCSMNbSetWeight from specific coordination number differences.

:param delta_csm_mins: Minimums for each coordination number.
:param delta_csm_maxs: Maximums for each coordination number.
Expand Down Expand Up @@ -1928,9 +1928,6 @@ def __eq__(self, other: object) -> bool:

return self.cn_weights == other.cn_weights and self.initialization_options == other.initialization_options

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSONable dict."""
return {
Expand All @@ -1956,7 +1953,7 @@ def from_dict(cls, dct):

@classmethod
def linearly_equidistant(cls, weight_cn1, weight_cn13):
"""Initializes linearly equidistant weights for each coordination.
"""Initialize linearly equidistant weights for each coordination.

:param weight_cn1: Weight of coordination 1.
:param weight_cn13: Weight of coordination 13.
Expand All @@ -1975,7 +1972,7 @@ def linearly_equidistant(cls, weight_cn1, weight_cn13):

@classmethod
def geometrically_equidistant(cls, weight_cn1, weight_cn13):
"""Initializes geometrically equidistant weights for each coordination.
"""Initialize geometrically equidistant weights for each coordination.

:param weight_cn1: Weight of coordination 1.
:param weight_cn13: Weight of coordination 13.
Expand All @@ -1994,7 +1991,7 @@ def geometrically_equidistant(cls, weight_cn1, weight_cn13):

@classmethod
def explicit(cls, cn_weights):
"""Initializes weights explicitly for each coordination.
"""Initialize weights explicitly for each coordination.

:param cn_weights: Weights for each coordination.

Expand All @@ -2008,7 +2005,7 @@ def explicit(cls, cn_weights):

@classmethod
def from_description(cls, dct):
"""Initializes weights from description.
"""Initialize weights from description.

:param dct: Dictionary description.

Expand Down Expand Up @@ -2225,9 +2222,6 @@ def __eq__(self, other: object) -> bool:
and self.additional_condition == other.additional_condition
)

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSONable dict."""
return {
Expand Down Expand Up @@ -2298,9 +2292,6 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
def __eq__(self, other: object) -> bool:
return isinstance(other, type(self))

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSONable dict."""
return {
Expand Down Expand Up @@ -2365,9 +2356,6 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
def __eq__(self, other: object) -> bool:
return isinstance(other, type(self))

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSONable dict."""
return {
Expand Down Expand Up @@ -2446,9 +2434,6 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
def __eq__(self, other: object) -> bool:
return isinstance(other, type(self))

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSOnable dict."""
return {
Expand Down Expand Up @@ -2530,9 +2515,6 @@ def weight(self, nb_set, structure_environments, cn_map=None, additional_info=No
def __eq__(self, other: object) -> bool:
return isinstance(other, type(self))

def __ne__(self, other):
return not self == other

def as_dict(self):
"""MSONable dict."""
return {
Expand Down Expand Up @@ -2813,9 +2795,6 @@ def __eq__(self, other: object) -> bool:
and self.ce_estimator == other.ce_estimator
)

def __ne__(self, other):
return not self == other

def as_dict(self):
"""
Bson-serializable dict representation of the WeightedNbSetChemenvStrategy object.
Expand Down Expand Up @@ -2982,9 +2961,6 @@ def __eq__(self, other: object) -> bool:
and self.ce_estimator == other.ce_estimator
)

def __ne__(self, other):
return not self == other

def as_dict(self):
"""
Returns:
Expand Down
18 changes: 11 additions & 7 deletions pymatgen/analysis/chemenv/utils/scripts_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@

import numpy as np

from pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies import SimplestChemenvStrategy
from pymatgen.analysis.chemenv.coordination_environments.chemenv_strategies import (
AbstractChemenvStrategy,
SimpleAbundanceChemenvStrategy,
SimplestChemenvStrategy,
TargetedPenaltiedAbundanceChemenvStrategy,
)
from pymatgen.analysis.chemenv.coordination_environments.coordination_geometries import (
UNCLEAR_ENVIRONMENT_SYMBOL,
AllCoordinationGeometries,
Expand Down Expand Up @@ -38,12 +43,11 @@
__email__ = "[email protected]"
__date__ = "Feb 20, 2016"

strategies_class_lookup = {}
strategies_class_lookup["SimplestChemenvStrategy"] = SimplestChemenvStrategy


# strategies_class_lookup['SimpleAbundanceChemenvStrategy'] = SimpleAbundanceChemenvStrategy
# strategies_class_lookup['TargettedPenaltiedAbundanceChemenvStrategy'] = TargettedPenaltiedAbundanceChemenvStrategy
strategies_class_lookup: dict[str, AbstractChemenvStrategy] = {
"SimplestChemenvStrategy": SimplestChemenvStrategy, # type: ignore
"SimpleAbundanceChemenvStrategy": SimpleAbundanceChemenvStrategy, # type: ignore
"TargetedPenaltiedAbundanceChemenvStrategy": TargetedPenaltiedAbundanceChemenvStrategy, # type: ignore
}


def draw_cg(
Expand Down
6 changes: 3 additions & 3 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
from __future__ import annotations

import datetime
import glob
import json
import os
import re
import subprocess
import webbrowser
from glob import glob

import requests
from invoke import task
Expand All @@ -41,7 +41,7 @@ def make_doc(ctx):
ctx.run("rm *.rst", warn=True)
ctx.run("cp markdown/pymatgen*.md .")
ctx.run("rm pymatgen*tests*.md", warn=True)
for fn in glob.glob("pymatgen*.md"):
for fn in glob("pymatgen*.md"):
with open(fn) as f:
lines = [line.rstrip() for line in f if "Submodules" not in line]
if fn == "pymatgen.md":
Expand Down Expand Up @@ -319,7 +319,7 @@ def check_egg_sources_txt_for_completeness():
raise ValueError(f"{src_file} does not exist!")

for ext in ("py", "json", "json.gz", "yaml", "csv"):
for filepath in glob.glob(f"pymatgen/**/*.{ext}", recursive=True):
for filepath in glob(f"pymatgen/**/*.{ext}", recursive=True):
if "/tests/" in filepath or "dao" in filepath:
continue
if filepath not in sources:
Expand Down
22 changes: 11 additions & 11 deletions tests/analysis/test_ewald.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
class TestEwaldSummation(unittest.TestCase):
def setUp(self):
filepath = f"{TEST_FILES_DIR}/POSCAR"
p = Poscar.from_file(filepath, check_for_POTCAR=False)
self.original_s = p.structure
self.s = self.original_s.copy()
self.s.add_oxidation_state_by_element({"Li": 1, "Fe": 2, "P": 5, "O": -2})
poscar = Poscar.from_file(filepath, check_for_POTCAR=False)
self.original_struct = poscar.structure
self.struct = self.original_struct.copy()
self.struct.add_oxidation_state_by_element({"Li": 1, "Fe": 2, "P": 5, "O": -2})

def test_init(self):
ham = EwaldSummation(self.s, compute_forces=True)
ham = EwaldSummation(self.struct, compute_forces=True)
assert ham.real_space_energy == approx(-502.23549897772602, abs=1e-4)
assert ham.reciprocal_space_energy == approx(6.1541071599534654, abs=1e-4)
assert ham.point_energy == approx(-620.22598358035918, abs=1e-4)
Expand All @@ -36,10 +36,10 @@ def test_init(self):
ValueError,
match="Ewald summation can only be performed on structures that are either oxidation state decorated",
):
EwaldSummation(self.original_s)
EwaldSummation(self.original_struct)
# try sites with charge.
charges = []
for site in self.original_s:
for site in self.original_struct:
if site.specie.symbol == "Li":
charges.append(1)
elif site.specie.symbol == "Fe":
Expand All @@ -49,12 +49,12 @@ def test_init(self):
else:
charges.append(-2)

self.original_s.add_site_property("charge", charges)
ham2 = EwaldSummation(self.original_s)
self.original_struct.add_site_property("charge", charges)
ham2 = EwaldSummation(self.original_struct)
assert ham2.real_space_energy == approx(-502.23549897772602, abs=1e-4)

def test_from_dict(self):
ham = EwaldSummation(self.s, compute_forces=True)
ham = EwaldSummation(self.struct, compute_forces=True)
ham2 = EwaldSummation.from_dict(ham.as_dict())
assert ham._real is None
assert not ham._initialized
Expand All @@ -71,7 +71,7 @@ def test_from_dict(self):
assert np.array_equal(ham.total_energy_matrix, ham2.total_energy_matrix)

def test_as_dict(self):
ham = EwaldSummation(self.s, compute_forces=True)
ham = EwaldSummation(self.struct, compute_forces=True)
d = ham.as_dict()
assert d["compute_forces"]
assert d["eta"] == ham._eta
Expand Down
20 changes: 10 additions & 10 deletions tests/analysis/test_molecule_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def generate_Si_cluster():
mol = Molecule.from_sites(struct)
XYZ(mol).write_file(f"{test_dir}/Si_cluster.xyz")

# Rorate the whole molecule
# Rotate the whole molecule
mol_rotated = mol.copy()
rotate(mol_rotated, seed=42)
XYZ(mol_rotated).write_file(f"{test_dir}/Si_cluster_rotated.xyz")
Expand Down Expand Up @@ -127,7 +127,7 @@ def generate_Si2O_cluster():
mol = Molecule.from_sites(struct)
XYZ(mol).write_file(f"{test_dir}/Si2O_cluster.xyz")

# Rorate the whole molecule
# Rotate the whole molecule
mol_rotated = mol.copy()
rotate(mol_rotated, seed=42)
XYZ(mol_rotated).write_file(f"{test_dir}/Si2O_cluster_rotated.xyz")
Expand Down Expand Up @@ -194,8 +194,8 @@ def fit_with_mapper(self, mapper):
]
mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
rotcoords = [op.operate(c) for c in coords]
mol2 = Molecule(["C", "H", "H", "H", "H"], rotcoords)
rot_coords = [op.operate(c) for c in coords]
mol2 = Molecule(["C", "H", "H", "H", "H"], rot_coords)
mm = MoleculeMatcher(mapper=mapper)
assert mm.fit(mol1, mol2)

Expand Down Expand Up @@ -293,10 +293,10 @@ def test_rotated_molecule(self):
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
rotcoords = [op.operate(c) for c in coords]
rot_coords = [op.operate(c) for c in coords]

mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rotcoords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rot_coords)

mm = KabschMatcher(mol1)
_, rmsd = mm.fit(mol2)
Expand Down Expand Up @@ -368,10 +368,10 @@ def test_rotated_molecule(self):
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
rotcoords = [op.operate(c) for c in coords]
rot_coords = [op.operate(c) for c in coords]

mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rotcoords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rot_coords)

mm = HungarianOrderMatcher(mol1)
_, rmsd = mm.fit(mol2)
Expand Down Expand Up @@ -473,10 +473,10 @@ def test_rotated_molecule(self):
]

op = SymmOp.from_origin_axis_angle([0, 0, 0], [0.1, 0.2, 0.3], 60)
rotcoords = [op.operate(c) for c in coords]
rot_coords = [op.operate(c) for c in coords]

mol1 = Molecule(["C", "H", "H", "H", "H"], coords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rotcoords)
mol2 = Molecule(["C", "H", "H", "H", "H"], rot_coords)

mm = GeneticOrderMatcher(mol1, threshold=0.3)
_, rmsd = mm.fit(mol2)[0]
Expand Down
Loading