Skip to content

Commit 4b84d78

Browse files
authored
fix minor code formatting issues + typos (#1070)
1 parent 4244da9 commit 4b84d78

File tree

10 files changed

+65
-106
lines changed

10 files changed

+65
-106
lines changed

docs/user/codes/vasp.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
(codes.vasp)=
2+
23
# VASP
34

45
At present, most workflows in atomate2 use the Vienna *ab initio* simulation package
@@ -260,21 +261,19 @@ With the help of phonopy, these forces are then converted into a dynamical matri
260261
The dynamical matrices of three structures are then used as an input to the phonopy Grueneisen api
261262
to compute mode-dependent Grueneisen parameters.
262263

263-
264264
### Quasi-harmonic Workflow
265+
265266
Uses the quasi-harmonic approximation with the help of Phonopy to compute thermodynamic properties.
266267
First, a tight relaxation is performed. Subsequently, several optimizations at different constant
267268
volumes are performed. At each of the volumes, an additional phonon run is performed as well.
268269
Afterwards, equation of state fits are performed with phonopy.
269270

270-
271-
272271
### Equation of State Workflow
272+
273273
An equation of state workflow is implemented. First, a tight relaxation is performed. Subsequently, several optimizations at different constant
274274
volumes are performed. Additional static calculations might be performed afterwards to arrive at more
275275
accurate energies. Then, an equation of state fit is performed with pymatgen.
276276

277-
278277
### LOBSTER
279278

280279
Perform bonding analysis with [LOBSTER](http://cohp.de/) and [LobsterPy](https://github.com/jageo/lobsterpy)

src/atomate2/common/flows/anharmonicity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def make(
8181
A previous calculation directory to use for copying outputs.
8282
Default is None.
8383
born: Optional[list[Matrix3D]]
84-
Instead of recomputing born charges and epsilon, these values can also be
84+
Instead of recomputing Born charges and epsilon, these values can also be
8585
provided manually. If born and epsilon_static are provided, the born run
8686
will be skipped it can be provided in the VASP convention with information
8787
for every atom in unit cell. Please be careful when converting structures

src/atomate2/common/flows/gruneisen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class BaseGruneisenMaker(Maker, ABC):
4040
generated for all the three structures (ground state, expanded and shrunk volume)
4141
and accurate forces are computed for these structures. With the help of phonopy,
4242
these forces are then converted into a dynamical matrix. This dynamical matrix of
43-
three structures is then used as an input for the phonopy Grueneisen api
43+
three structures is then used as an input for the phonopy Grueneisen API
4444
to compute Grueneisen parameters.
4545
4646

src/atomate2/common/flows/phonons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def make(
187187
prev_dir : str or Path or None
188188
A previous calculation directory to use for copying outputs.
189189
born: Matrix3D
190-
Instead of recomputing born charges and epsilon, these values can also be
190+
Instead of recomputing Born charges and epsilon, these values can also be
191191
provided manually. If born and epsilon_static are provided, the born run
192192
will be skipped it can be provided in the VASP convention with information
193193
for every atom in unit cell. Please be careful when converting structures

src/atomate2/common/flows/qha.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -25,28 +25,24 @@
2525
from atomate2.common.flows.phonons import BasePhononMaker
2626
from atomate2.forcefields.jobs import ForceFieldRelaxMaker
2727
from atomate2.vasp.jobs.core import BaseVaspMaker
28+
2829
supported_eos = frozenset(("vinet", "birch_murnaghan", "murnaghan"))
2930

3031

3132
@dataclass
3233
class CommonQhaMaker(Maker, ABC):
33-
"""
34-
Use the quasi-harmonic approximation.
34+
"""Use the quasi-harmonic approximation.
3535
36-
First relax a structure.
37-
Then we scale the relaxed structure, and
38-
then compute harmonic phonons for each scaled
39-
structure with Phonopy.
40-
Finally, we compute the Gibbs free energy and
41-
other thermodynamic properties available from
42-
the quasi-harmonic approximation.
36+
First relax a structure. Then we scale the relaxed structure, and then compute
37+
harmonic phonons for each scaled structure with Phonopy. Finally, we compute the
38+
Gibbs free energy and other thermodynamic properties available from the
39+
quasi-harmonic approximation.
4340
4441
Note: We do not consider electronic free energies so far.
4542
This might be problematic for metals (see e.g.,
4643
Wolverton and Zunger, Phys. Rev. B, 52, 8813 (1994).)
4744
48-
Note: Magnetic Materials have never been computed with
49-
this workflow.
45+
Note: Magnetic Materials have never been computed with this workflow.
5046
5147
Parameters
5248
----------
@@ -84,7 +80,6 @@ class CommonQhaMaker(Maker, ABC):
8480
with 3 90 degree angles
8581
get_supercell_size_kwargs: dict
8682
kwargs that will be passed to get_supercell_size to determine supercell size
87-
8883
"""
8984

9085
name: str = "QHA Maker"
@@ -128,10 +123,7 @@ def make(
128123
.Flow, a QHA flow
129124
"""
130125
if self.eos_type not in supported_eos:
131-
raise ValueError(
132-
"EOS not supported.",
133-
"Please choose 'vinet', 'birch_murnaghan', 'murnaghan'",
134-
)
126+
raise ValueError(f"EOS not supported. Choose one of {set(supported_eos)}")
135127

136128
qha_jobs = []
137129

@@ -148,7 +140,7 @@ def make(
148140
eos_job = self.eos.make(structure)
149141
qha_jobs.append(eos_job)
150142

151-
# implement a supercell job to get matrix for just the equillibrium structure
143+
# implement a supercell job to get matrix for just the equilibrium structure
152144
if supercell_matrix is None:
153145
supercell = get_supercell_size(
154146
eos_output=eos_job.output,
@@ -162,7 +154,6 @@ def make(
162154
supercell_matrix = supercell.output
163155

164156
# pass the matrix to the phonon_jobs, allow to set a consistent matrix instead
165-
166157
phonon_jobs = get_phonon_jobs(
167158
phonon_maker=self.phonon_maker,
168159
eos_output=eos_job.output,

src/atomate2/common/jobs/anharmonicity.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,16 @@ class ImaginaryModeError(Exception):
4444

4545
def __init__(self, largest_mode: float) -> None:
4646
self.largest_mode = largest_mode
47-
self.message = f"""Structure has imaginary modes: the largest optical
48-
eigenmode {largest_mode} < 0.0001"""
47+
self.message = (
48+
f"Structure has imaginary modes: the largest optical eigenmode "
49+
f"{largest_mode} < 0.0001"
50+
)
4951
super().__init__(self.message)
5052

5153

5254
@job
5355
def get_phonon_supercell(
54-
structure: Structure,
55-
supercell_matrix: np.ndarray,
56+
structure: Structure, supercell_matrix: np.ndarray
5657
) -> Structure:
5758
"""Get the phonon supercell of a structure.
5859
@@ -68,12 +69,9 @@ def get_phonon_supercell(
6869
Structure
6970
The phonopy structure
7071
"""
71-
cell = get_phonopy_structure(structure)
72-
phonon = Phonopy(
73-
cell,
74-
supercell_matrix,
75-
)
76-
return get_pmg_structure(phonon.supercell)
72+
unit_cell = get_phonopy_structure(structure)
73+
phonopy = Phonopy(unit_cell, supercell_matrix)
74+
return get_pmg_structure(phonopy.supercell)
7775

7876

7977
def get_sigma_per_site(

src/atomate2/common/jobs/gruneisen.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from atomate2.common.schemas.phonons import PhononBSDOSDoc
1818

1919
if TYPE_CHECKING:
20+
from pathlib import Path
21+
2022
from pymatgen.core.structure import Structure
2123

2224
from atomate2.common.flows.phonons import BasePhononMaker
@@ -128,11 +130,11 @@ def run_phonon_jobs(
128130
)
129131
def compute_gruneisen_param(
130132
code: str,
131-
phonopy_yaml_paths_dict: dict,
132-
phonon_imaginary_modes_info: dict,
133+
phonopy_yaml_paths_dict: dict[str, Path],
134+
phonon_imaginary_modes_info: dict[str, bool],
133135
kpath_scheme: str,
134136
symprec: float,
135-
mesh: tuple | float = (20, 20, 20),
137+
mesh: tuple[int, int, int] | float = (20, 20, 20),
136138
structure: Structure = None,
137139
**compute_gruneisen_param_kwargs,
138140
) -> GruneisenParameterDocument:

src/atomate2/common/jobs/qha.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,7 @@ def get_supercell_size(
5656
)
5757

5858

59-
@job(
60-
data=[PhononBSDOSDoc],
61-
)
59+
@job(data=[PhononBSDOSDoc])
6260
def get_phonon_jobs(
6361
phonon_maker: BasePhononMaker, eos_output: dict, supercell_matrix: list[list[float]]
6462
) -> Flow:

src/atomate2/common/schemas/phonons.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ class PhononBSDOSDoc(StructureMetadata, extra="allow"): # type: ignore[call-arg
201201

202202
born: Optional[list[Matrix3D]] = Field(
203203
None,
204-
description="born charges as computed from phonopy. Only for symmetrically "
204+
description="Born charges as computed from phonopy. Only for symmetrically "
205205
"different atoms",
206206
)
207207

@@ -280,7 +280,7 @@ def from_forces_born(
280280
epsilon_static: Matrix3D
281281
The high-frequency dielectric constant
282282
born: Matrix3D
283-
born charges
283+
Born charges
284284
**kwargs:
285285
additional arguments
286286
"""
@@ -329,7 +329,7 @@ def from_forces_born(
329329
)
330330
else:
331331
raise ValueError(
332-
"Number of born charges does not agree with number of atoms"
332+
"Number of Born charges does not agree with number of atoms"
333333
)
334334
if code == "vasp" and not np.all(np.isclose(borns, 0.0)):
335335
phonon.nac_params = {
@@ -595,7 +595,8 @@ def get_kpath(
595595
**kpath_kwargs:
596596
additional parameters that can be passed to this method as a dict
597597
"""
598-
if kpath_scheme in ("setyawan_curtarolo", "latimer_munro", "hinuma"):
598+
valid_schemes = {"setyawan_curtarolo", "latimer_munro", "hinuma", "seekpath"}
599+
if kpath_scheme in (valid_schemes - {"seekpath"}):
599600
high_symm_kpath = HighSymmKpath(
600601
structure, path_type=kpath_scheme, symprec=symprec, **kpath_kwargs
601602
)
@@ -604,7 +605,9 @@ def get_kpath(
604605
high_symm_kpath = KPathSeek(structure, symprec=symprec, **kpath_kwargs)
605606
kpath = high_symm_kpath._kpath # noqa: SLF001
606607
else:
607-
raise ValueError(f"Unexpected {kpath_scheme=}")
608+
raise ValueError(
609+
f"Unexpected {kpath_scheme=}, must be one of {valid_schemes}"
610+
)
608611

609612
path = copy.deepcopy(kpath["path"])
610613

tests/vasp/flows/test_phonons.py

Lines changed: 28 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -265,66 +265,41 @@ def test_phonon_wf_vasp_only_displacements_kpath(
265265
responses = run_locally(job, create_folders=True, ensure_success=True)
266266

267267
# validate the outputs
268-
# print(type(responses))
269-
assert isinstance(responses[job.jobs[-1].uuid][1].output, PhononBSDOSDoc)
268+
ph_doc = responses[job.jobs[-1].uuid][1].output
269+
assert isinstance(ph_doc, PhononBSDOSDoc)
270270

271271
assert_allclose(
272-
responses[job.jobs[-1].uuid][1].output.free_energies,
272+
ph_doc.free_energies,
273273
[5776.14995034, 5617.74737777, 4725.50269363, 3043.81827626, 694.49078355],
274274
atol=1e-3,
275275
)
276276

277+
assert isinstance(ph_doc.phonon_bandstructure, PhononBandStructureSymmLine)
278+
assert isinstance(ph_doc.phonon_dos, PhononDos)
279+
assert isinstance(ph_doc.thermal_displacement_data, ThermalDisplacementData)
280+
assert isinstance(ph_doc.structure, Structure)
281+
assert_allclose(ph_doc.temperatures, [0, 100, 200, 300, 400])
282+
assert ph_doc.has_imaginary_modes is False
283+
force_const = ph_doc.force_constants.force_constants[0][0][0][0]
284+
assert force_const == pytest.approx(13.032324)
285+
assert isinstance(ph_doc.jobdirs, PhononJobDirs)
286+
assert isinstance(ph_doc.uuids, PhononUUIDs)
287+
assert ph_doc.total_dft_energy is None
288+
assert ph_doc.born is None
289+
assert ph_doc.epsilon_static is None
290+
assert ph_doc.supercell_matrix == ((-1, 1, 1), (1, -1, 1), (1, 1, -1))
291+
assert ph_doc.primitive_matrix == ((1, 0, 0), (0, 1, 0), (0, 0, 1))
292+
assert ph_doc.code == "vasp"
277293
assert isinstance(
278-
responses[job.jobs[-1].uuid][1].output.phonon_bandstructure,
279-
PhononBandStructureSymmLine,
280-
)
281-
assert isinstance(responses[job.jobs[-1].uuid][1].output.phonon_dos, PhononDos)
282-
assert isinstance(
283-
responses[job.jobs[-1].uuid][1].output.thermal_displacement_data,
284-
ThermalDisplacementData,
285-
)
286-
assert isinstance(responses[job.jobs[-1].uuid][1].output.structure, Structure)
287-
assert_allclose(
288-
responses[job.jobs[-1].uuid][1].output.temperatures, [0, 100, 200, 300, 400]
289-
)
290-
assert responses[job.jobs[-1].uuid][1].output.has_imaginary_modes is False
291-
assert_allclose(
292-
responses[job.jobs[-1].uuid][1].output.force_constants.force_constants[0][0][0][
293-
0
294-
],
295-
13.032324,
296-
)
297-
assert isinstance(responses[job.jobs[-1].uuid][1].output.jobdirs, PhononJobDirs)
298-
assert isinstance(responses[job.jobs[-1].uuid][1].output.uuids, PhononUUIDs)
299-
assert responses[job.jobs[-1].uuid][1].output.total_dft_energy is None
300-
assert responses[job.jobs[-1].uuid][1].output.born is None
301-
assert responses[job.jobs[-1].uuid][1].output.epsilon_static is None
302-
assert_allclose(
303-
responses[job.jobs[-1].uuid][1].output.supercell_matrix,
304-
[[-1.0, 1.0, 1.0], [1.0, -1.0, 1.0], [1.0, 1.0, -1.0]],
305-
)
306-
assert_allclose(
307-
responses[job.jobs[-1].uuid][1].output.primitive_matrix,
308-
[[1, 0, 0], [0, 1, 0], [0, 0, 1]],
309-
atol=1e-8,
310-
)
311-
assert responses[job.jobs[-1].uuid][1].output.code == "vasp"
312-
assert isinstance(
313-
responses[job.jobs[-1].uuid][1].output.phonopy_settings,
294+
ph_doc.phonopy_settings,
314295
PhononComputationalSettings,
315296
)
316-
assert responses[job.jobs[-1].uuid][1].output.phonopy_settings.npoints_band == 101
317-
assert (
318-
responses[job.jobs[-1].uuid][1].output.phonopy_settings.kpath_scheme
319-
== kpath_scheme
320-
)
321-
assert (
322-
responses[job.jobs[-1].uuid][1].output.phonopy_settings.kpoint_density_dos
323-
== 7_000
324-
)
297+
assert ph_doc.phonopy_settings.npoints_band == 101
298+
assert ph_doc.phonopy_settings.kpath_scheme == kpath_scheme
299+
assert ph_doc.phonopy_settings.kpoint_density_dos == 7_000
325300

326301

327-
# test supply of born charges, epsilon, DFT energy, supercell
302+
# test supply of Born charges, epsilon, DFT energy, supercell
328303
def test_phonon_wf_vasp_only_displacements_add_inputs_raises(
329304
mock_vasp, clean_dir, si_structure: Structure
330305
):
@@ -337,16 +312,9 @@ def test_phonon_wf_vasp_only_displacements_add_inputs_raises(
337312
# automatically use fake VASP and write POTCAR.spec during the test
338313
mock_vasp(ref_paths, fake_run_vasp_kwargs)
339314

340-
born = [
341-
[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
342-
[[0, 0, 0], [0, 0, 0], [0, 0, 0]],
343-
[[0, 0, 0], [0, 0, 0], [0, 0, 0.1]],
344-
]
345-
epsilon_static = [
346-
[5.25, 0, 0],
347-
[0, 5.25, 0],
348-
[0, 0, 5.25],
349-
]
315+
born = np.zeros((3, 3))
316+
born[-1, -1] = 0.1
317+
epsilon_static = 5.25 * np.eye(3)
350318
total_dft_energy_per_formula_unit = -5
351319

352320
job = PhononMaker(
@@ -368,7 +336,7 @@ def test_phonon_wf_vasp_only_displacements_add_inputs_raises(
368336
run_locally(job, create_folders=True, ensure_success=True)
369337

370338

371-
# test supply of born charges, epsilon, DFT energy, supercell
339+
# test supply of Born charges, epsilon, DFT energy, supercell
372340
def test_phonon_wf_vasp_only_displacements_add_inputs(
373341
mock_vasp, clean_dir, si_structure: Structure
374342
):

0 commit comments

Comments
 (0)