Skip to content

Commit

Permalink
simplify: dict.get(key, None) -> dict.get(key)
Browse files Browse the repository at this point in the history
fix typo
  • Loading branch information
janosh committed Jul 10, 2023
1 parent a6759f8 commit 2369172
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 27 deletions.
8 changes: 4 additions & 4 deletions docs/user/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This guide will get you up and running in an environment for running high-throug
workflows with atomate2. atomate2 is built on the pymatgen, custodian, jobflow, and
FireWorks libraries. Briefly:

- [pymatgen] is used create input files and analyze the output of materials science codes.
- [pymatgen] is used to create input files and analyze the output of materials science codes.
- [custodian] runs your simulation code (e.g., VASP) and performs error checking/handling
and checkpointing.
- [jobflow] is used to design computational workflows.
Expand All @@ -22,9 +22,9 @@ Note that this installation tutorial is VASP-centric since almost all functional
currently in atomate2 pertains to VASP.

[pymatgen]: http://pymatgen.org
[custodian]: https://materialsproject.github.io/custodian/
[fireworks]: https://materialsproject.github.io/fireworks/
[jobflow]: https://materialsproject.github.io/jobflow/
[custodian]: https://materialsproject.github.io/custodian
[fireworks]: https://materialsproject.github.io/fireworks
[jobflow]: https://materialsproject.github.io/jobflow

### Objectives

Expand Down
12 changes: 6 additions & 6 deletions src/atomate2/common/schemas/cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ def from_logfile(
metadata = jsanitize(cclib_obj.metadata)

# monty datetime bug workaround: github.com/materialsvirtuallab/monty/issues/275
if metadata.get("wall_time", None):
metadata["wall_time"] = [str(m) for m in metadata["wall_time"]]
if metadata.get("cpu_time", None):
metadata["cpu_time"] = [str(m) for m in metadata["cpu_time"]]
if wall_time := metadata.get("wall_time"):
metadata["wall_time"] = [*map(str, wall_time)]
if cpu_time := metadata.get("cpu_time"):
metadata["cpu_time"] = [*map(str, cpu_time)]

# Get the final energy to store as its own key/value pair
energy = (
Expand All @@ -159,8 +159,8 @@ def from_logfile(
# the input if it is XYZ-formatted though since the Molecule object
# does not support internal coordinates or Gaussian Z-matrix.
if (
cclib_obj.metadata.get("coord_type", None) == "xyz"
and cclib_obj.metadata.get("coords", None) is not None
cclib_obj.metadata.get("coord_type") == "xyz"
and cclib_obj.metadata.get("coords") is not None
):
coords_obj = cclib_obj.metadata["coords"]
input_species = [Element(row[0]) for row in coords_obj]
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/common/schemas/defects.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,10 @@ def dQ_entries(e1, e2):
return get_dQ(e1.structure, e2.structure)

# ensure the "dir_name" is provided for each entry
if any(e.data.get("dir_name", None) is None for e in entries1 + entries2):
if any(entry.data.get("dir_name") is None for entry in entries1 + entries2):
raise ValueError("[dir_name] must be provided for all entries.")

if any(e.data.get("uuid", None) is None for e in entries1 + entries2):
if any(entry.data.get("uuid") is None for entry in entries1 + entries2):
raise ValueError("[uuid] must be provided for all entries.")

idx1, ent_r1 = find_entry(entries1, relaxed_uuid1)
Expand Down
6 changes: 3 additions & 3 deletions src/atomate2/cp2k/schemas/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ def from_cp2k_output(cls, output: Cp2kOutput):
"""Initialize from Cp2kOutput object."""
return cls(
structure=output.initial_structure,
atomic_kind_info=output.data.get("atomic_kind_info", None),
atomic_kind_info=output.data.get("atomic_kind_info"),
cp2k_input=output.input.as_dict(),
dft=output.data.get("dft", None),
cp2k_global=output.data.get("global", None),
dft=output.data.get("dft"),
cp2k_global=output.data.get("global"),
)


Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/cp2k/schemas/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def from_cp2k_calc_doc(cls, calc_doc: Calculation) -> "OutputSummary":
The calculation output summary.
"""
if calc_doc.output.ionic_steps:
forces = calc_doc.output.ionic_steps[-1].get("forces", None)
stress = calc_doc.output.ionic_steps[-1].get("stress", None)
forces = calc_doc.output.ionic_steps[-1].get("forces")
stress = calc_doc.output.ionic_steps[-1].get("stress")
else:
forces = None
stress = None
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/utils/file_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ def auto_fileclient(method: Callable | None = None):
def decorator(func):
@wraps(func)
def gen_fileclient(*args, **kwargs):
file_client = kwargs.get("file_client", None)
file_client = kwargs.get("file_client")
if file_client is None:
with FileClient() as file_client:
kwargs["file_client"] = file_client
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/vasp/schemas/calc_types/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def _variant_equal(v1, v2) -> bool:
for functional_class in ["HF", "VDW", "METAGGA", "GGA"]:
for special_type, params in _RUN_TYPE_DATA[functional_class].items():
if all(
_variant_equal(vasp_parameters.get(param, None), value)
_variant_equal(vasp_parameters.get(param), value)
for param, value in params.items()
):
return RunType(f"{special_type}{is_hubbard}")
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/vasp/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ def _get_u_param(lda_param, lda_config, structure):

def _get_ediff(param, value, structure, incar_settings):
"""Get EDIFF."""
if incar_settings.get("EDIFF", None) is None and param == "EDIFF_PER_ATOM":
if incar_settings.get("EDIFF") is None and param == "EDIFF_PER_ATOM":
return float(value) * structure.num_sites
return float(incar_settings["EDIFF"])

Expand Down
4 changes: 2 additions & 2 deletions tests/common/schemas/test_cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def test_cclib_taskdoc(test_dir):
assert doc["nelectrons"] == 16
assert "schemas" in doc["dir_name"]
assert "gau_testopt.log.gz" in doc["logfile"]
assert doc.get("attributes", None) is not None
assert doc.get("metadata", None) is not None
assert doc.get("attributes") is not None
assert doc.get("metadata") is not None
assert doc["metadata"]["success"] is True
assert doc["attributes"]["molecule_initial"][0].coords == pytest.approx([0, 0, 0])
assert doc["molecule"][0].coords == pytest.approx([0.397382, 0.0, 0.0])
Expand Down
8 changes: 3 additions & 5 deletions tests/vasp/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,9 @@ def check_kpoints(ref_path: Path):
user = Incar.from_file("INCAR")
ref = Incar.from_file(ref_path / "inputs" / "INCAR")

if user.get("KSPACING", None) != ref.get("KSPACING", None):
raise ValueError(
"KSPACING is not consistent: "
f"{user.get('KSPACING', None)} != {ref.get('KSPACING', None)}"
)
user_ksp, ref_ksp = user.get("KSPACING"), ref.get("KSPACING")
if user_ksp != ref_ksp:
raise ValueError(f"KSPACING is not consistent: {user_ksp} != {ref_ksp}")


def check_poscar(ref_path: Path):
Expand Down

0 comments on commit 2369172

Please sign in to comment.