Skip to content

Commit 3f61317

Browse files
authored
Fix generate_phonon_displacements magmom removal side effect (#1064)
* fix lints and typos * fix generate_phonon_displacements side effect: removes magmoms of passed structure in-place * fix ruff PYI063 Use PEP 570 syntax for positional-only parameters
1 parent 3d55b2b commit 3f61317

File tree

8 files changed

+33
-28
lines changed

8 files changed

+33
-28
lines changed

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ default_language_version:
33
exclude: ^(.github/|tests/test_data/abinit/)
44
repos:
55
- repo: https://github.com/charliermarsh/ruff-pre-commit
6-
rev: v0.7.3
6+
rev: v0.8.0
77
hooks:
88
- id: ruff
99
args: [--fix]
@@ -45,7 +45,7 @@ repos:
4545
args: [--ignore-words-list, 'titel,statics,ba,nd,te,atomate']
4646
types_or: [python, rst, markdown]
4747
- repo: https://github.com/kynan/nbstripout
48-
rev: 0.8.0
48+
rev: 0.8.1
4949
hooks:
5050
- id: nbstripout
5151
args:

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ ignore = [
207207
"PLR0913", # too many arguments
208208
"PLR0915", # too many local statements
209209
"PLR2004",
210-
"PT004", # pytest-missing-fixture-name-underscore
211210
"PT006", # pytest-parametrize-names-wrong-type
212211
"PT013", # pytest-incorrect-pytest-import
213212
"PTH", # prefer Pathlib to os.path

src/atomate2/ase/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class AseBaseModel(BaseModel):
9999
)
100100
molecule: Optional[Molecule] = Field(None, description="The molecule at this step.")
101101

102-
def model_post_init(self, __context: Any) -> None:
102+
def model_post_init(self, _context: Any) -> None:
103103
"""Establish alias to structure and molecule fields."""
104104
if self.structure is None and isinstance(self.mol_or_struct, Structure):
105105
self.structure = self.mol_or_struct

src/atomate2/common/flows/qha.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class CommonQhaMaker(Maker, ABC):
3737
Then we scale the relaxed structure, and
3838
then compute harmonic phonons for each scaled
3939
structure with Phonopy.
40-
Finally, we compute the Gibb's free energy and
40+
Finally, we compute the Gibbs free energy and
4141
other thermodynamic properties available from
4242
the quasi-harmonic approximation.
4343

src/atomate2/common/jobs/electrode.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,17 @@ def get_relaxed_job_summaries(
250250
"""
251251
relax_jobs = []
252252
outputs = []
253-
for ii, structure in enumerate(structures):
253+
for idx, structure in enumerate(structures):
254254
job_ = relax_maker.make(structure=structure)
255255
relax_jobs.append(job_)
256-
job_.append_name(f" {append_name} ({ii})")
257-
d_ = {
258-
"structure": job_.output.structure,
259-
"entry": job_.output.entry,
260-
"dir_name": job_.output.dir_name,
261-
"uuid": job_.output.uuid,
262-
}
263-
outputs.append(RelaxJobSummary(**d_))
256+
job_.append_name(f" {append_name} ({idx})")
257+
job_summary = RelaxJobSummary(
258+
structure=job_.output.structure,
259+
entry=job_.output.entry,
260+
dir_name=job_.output.dir_name,
261+
uuid=job_.output.uuid,
262+
)
263+
outputs.append(job_summary)
264264

265265
replace_flow = Flow(relax_jobs, output=outputs)
266266
return Response(replace=replace_flow, output=outputs)

src/atomate2/common/jobs/phonons.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,23 @@ def generate_phonon_displacements(
122122
scheme to generate kpath
123123
code:
124124
code to perform the computations
125+
126+
Returns
127+
-------
128+
List[Structure]
129+
Displaced structures
125130
"""
126131
warnings.warn(
127132
"Initial magnetic moments will not be considered for the determination "
128133
"of the symmetry of the structure and thus will be removed now.",
129-
stacklevel=1,
130-
)
131-
cell = get_phonopy_structure(
132-
structure.remove_site_property(property_name="magmom")
133-
if "magmom" in structure.site_properties
134-
else structure
134+
stacklevel=2,
135135
)
136+
if "magmom" in structure.site_properties:
137+
# remove_site_property is in-place so make a structure copy first
138+
no_mag_struct = structure.copy().remove_site_property(property_name="magmom")
139+
else:
140+
no_mag_struct = structure
141+
cell = get_phonopy_structure(no_mag_struct)
136142
factor = get_factor(code)
137143

138144
# a bit of code repetition here as I currently

src/atomate2/forcefields/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ForcefieldResult(AseResult):
2222
None, description="The structure in the final trajectory frame."
2323
)
2424

25-
def model_post_init(self, __context: Any) -> None:
25+
def model_post_init(self, _context: Any) -> None:
2626
"""Populate final_structure attr."""
2727
self.final_structure = getattr(
2828
self, "final_structure", self.final_mol_or_struct

tests/vasp/test_sets.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def test_user_incar_settings():
5252

5353
# check to see if user incar settings (even when set to nonsensical values, as done
5454
# below) are always preserved.
55-
uis = {
55+
user_settings = {
5656
"ALGO": "VeryFast",
5757
"EDIFF": 1e-30,
5858
"EDIFFG": -1e-10,
@@ -80,16 +80,16 @@ def test_user_incar_settings():
8080
"LDAUTYPE": 2,
8181
}
8282

83-
static_set_generator = StaticSetGenerator(user_incar_settings=uis)
83+
static_set_generator = StaticSetGenerator(user_incar_settings=user_settings)
8484
incar = static_set_generator.get_input_set(structure, potcar_spec=True)["INCAR"]
8585

86-
for key in uis:
86+
for key, val in user_settings.items():
8787
if isinstance(incar[key], str):
88-
assert incar[key].lower() == uis[key].lower()
89-
elif isinstance(uis[key], dict):
90-
assert incar[key] == [uis[key][str(site.specie)] for site in structure]
88+
assert incar[key].lower() == val.lower()
89+
elif isinstance(val, dict):
90+
assert incar[key] == [val[str(site.specie)] for site in structure]
9191
else:
92-
assert incar[key] == uis[key]
92+
assert incar[key] == val
9393

9494

9595
@pytest.mark.parametrize(

0 commit comments

Comments
 (0)