Skip to content

Commit

Permalink
Merge branch 'main' into pydantic2
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh authored Oct 12, 2023
2 parents 3f496a9 + afcce84 commit a5efa2e
Show file tree
Hide file tree
Showing 27 changed files with 119 additions and 74 deletions.
20 changes: 17 additions & 3 deletions docs/about/contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Lawrence Livermore National Laboratory
[jmmshn]: https://github.com/jmmshn
[0000-0002-2743-7531]: https://orcid.org/0000-0002-2743-7531

**Janosh Riebesell** [![gh]][janosh] [![orc]][0000-0001-5233-3462]\
**Janosh Riebesell** [![gh]][janosh] [![orc]][0000-0001-5233-3462] \
PhD Student \
Cambridge University

Expand Down Expand Up @@ -68,16 +68,30 @@ Microsoft Research
[0000-0001-7777-8871]: https://orcid.org/0000-0001-7777-8871

**Zhuoying Zhu** [![gh]][zhuoying] [![orc]][0000-0003-1775-7651] \
Postdoctoral researcher\
Postdoctoral Researcher \
Lawrence Berkeley National Laboratory

[zhuoying]: https://github.com/zhuoying
[0000-0003-1775-7651]: https://orcid.org/0000-0003-1775-7651

**Aakash Ashok Naik** [![gh]][naik-aakash] [![orc]][0000-0002-6071-6786] \
PhD student\
PhD student \
Federal Institute for Materials Research and Testing (Berlin) \
Friedrich Schiller University Jena

[naik-aakash]: https://github.com/naik-aakash
[0000-0002-6071-6786]: https://orcid.org/0000-0002-6071-6786

**Aaron Kaplan** [![gh]][esoteric-ephemera] [![orc]][0000-0003-3439-4856] \
Postdoctoral Researcher \
Lawrence Berkeley National Laboratory

[esoteric-ephemera]: https://github.com/esoteric-ephemera
[0000-0003-3439-4856]: https://orcid.org/0000-0003-3439-4856

**Matthew McDermott** [![gh]][mattmcdermott] [![orc]][0000-0002-4071-3000] \
PhD student \
University of California, Berkeley

[mattmcdermott]: https://github.com/mattmcdermott
[0000-0002-4071-3000]: https://orcid.org/0000-0002-4071-3000
25 changes: 25 additions & 0 deletions docs/user/atomate-1-vs-2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Atomate 1 vs 2

This document contains introductory context for people coming from atomate 1.
One of atomate2's core ideas is to allow scaling from a single material, to 100 materials, or 100,000 materials. Therefore, both local submission options and a connection to workflow managers such as FireWorks exist. We plan to support more workflow managers in the future to further ease job submission.
## Relation between managers running the actual jobs and the workflow as written in `atomate2`

There is no leakage between job manager and the workflow definition in `atomate2`. For example, Fireworks is not a required dependency of `atomate2` or `jobflow`. Any `atomate2` workflow can be run using the local manager or an extensible set of external providers, Fireworks just one among them. E.g. all tests are run with mocked calls to the executables using the local manager.

## Do I need to write separate codes for different managers?

If you are adding a new manager option beyond local or FireWorks, you'll need to write a new converter in `jobflow` that takes a job or flow and converts it to the analogous object(s) for the manager you wish to use. This does not impact the `atomate2` code in any way.

Typically, the workflow is as follows:

1. Write a workflow in `atomate2` that represents a job or flow.
2. Import the job or flow in your script/notebook from `atomate2`.
3. Convert the job or flow to manager-compatible objects using a convenience function in `jobflow`.
4. Define the specs for the new object type based on your desired resources.
5. Dispatch the jobs.

## What if a workflow manager stops being maintained?

`atomate2` and `jobflow` remain unaffected in such a case. The user can choose a different manager to suit their needs. This ensures that workflow definition and dispatch are fully decoupled.

In an ideal world, `jobflow` would offer multiple manager options, allowing users to run `atomate2` codes as per their preference. This full decoupling is one of the most powerful features of this stack.
2 changes: 1 addition & 1 deletion src/atomate2/amset/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ def from_directory(
from amset.io import load_mesh
from amset.util import cast_dict_list

additional_fields = {} if additional_fields is None else additional_fields
additional_fields = additional_fields or {}
dir_name = Path(dir_name)

settings = loadfn("settings.yaml")
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/common/schemas/cclib.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def from_logfile(

logger.info(f"Getting task doc from {logfile}")

additional_fields = {} if additional_fields is None else additional_fields
additional_fields = additional_fields or {}

# Let's parse the log file with cclib
cclib_obj = ccread(logfile, logging.ERROR)
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/cp2k/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def run_cp2k(
custodian_kwargs : dict
Keyword arguments that are passed to :obj:`.Custodian`.
"""
cp2k_job_kwargs = {} if cp2k_job_kwargs is None else cp2k_job_kwargs
custodian_kwargs = {} if custodian_kwargs is None else custodian_kwargs
cp2k_job_kwargs = cp2k_job_kwargs or {}
custodian_kwargs = custodian_kwargs or {}

cp2k_cmd = expandvars(cp2k_cmd)
split_cp2k_cmd = shlex.split(cp2k_cmd)
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/cp2k/schemas/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def from_directory(
"""
logger.info(f"Getting task doc in: {dir_name}")

additional_fields = {} if additional_fields is None else additional_fields
additional_fields = additional_fields or {}
dir_name = Path(dir_name)
task_files = _find_cp2k_files(dir_name, volumetric_files=volumetric_files)

Expand Down
20 changes: 9 additions & 11 deletions src/atomate2/cp2k/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
"""
self.cp2k_input = cp2k_input
self.optional_files = {} if optional_files is None else optional_files
self.optional_files = optional_files or {}

def write_input(
self,
Expand All @@ -98,8 +98,8 @@ def write_input(
Whether to overwrite an input file if it already exists.
"""
directory = Path(directory)
if make_dir and not directory.exists():
os.makedirs(directory)
if make_dir:
os.makedirs(directory, exist_ok=True)

inputs = {
"input": {"filename": "cp2k.inp", "object": self.cp2k_input},
Expand Down Expand Up @@ -270,9 +270,7 @@ def get_input_updates(self, structure, prev_input) -> dict:
raise NotImplementedError

def get_kpoints_updates(
self,
structure: Structure,
prev_input: Cp2kInput = None,
self, structure: Structure, prev_input: Cp2kInput = None
) -> dict:
"""
Get updates to the kpoints configuration for this calculation type.
Expand Down Expand Up @@ -329,8 +327,8 @@ def _get_input(
input_updates: dict = None,
):
"""Get the input."""
previous_input = {} if previous_input is None else previous_input
input_updates = {} if input_updates is None else input_updates
previous_input = previous_input or {}
input_updates = input_updates or {}
input_settings = dict(self.config_dict["cp2k_input"])

# Generate base input but override with user input settings
Expand All @@ -349,9 +347,9 @@ def _get_input(
and input_settings[setting]
and callable(getattr(cp2k_input, setting))
):
subsettings = input_settings.get(setting)
sub_settings = input_settings.get(setting)
getattr(cp2k_input, setting)(
**subsettings if isinstance(subsettings, dict) else {}
**sub_settings if isinstance(sub_settings, dict) else {}
)

cp2k_input.update(overrides)
Expand Down Expand Up @@ -399,7 +397,7 @@ def _get_kpoints(
kpoints_updates: dict[str, Any] | None,
) -> Kpoints | None:
"""Get the kpoints object."""
kpoints_updates = {} if kpoints_updates is None else kpoints_updates
kpoints_updates = kpoints_updates or {}

# use user setting if set otherwise default to base config settings
if self.user_kpoints_settings != {}:
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/lobster/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def run_lobster(
custodian_kwargs : dict
Keyword arguments that are passed to :obj:`.Custodian`.
"""
lobster_job_kwargs = {} if lobster_job_kwargs is None else lobster_job_kwargs
custodian_kwargs = {} if custodian_kwargs is None else custodian_kwargs
lobster_job_kwargs = lobster_job_kwargs or {}
custodian_kwargs = custodian_kwargs or {}

lobster_cmd = expandvars(lobster_cmd)
split_lobster_cmd = shlex.split(lobster_cmd)
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/lobster/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def from_directory(
which_bonds: str
mode for condensed bonding analysis: "cation-anion" and "all".
"""
plot_kwargs = {} if plot_kwargs is None else plot_kwargs
plot_kwargs = plot_kwargs or {}
dir_name = Path(dir_name)
cohpcar_path = dir_name / "COHPCAR.lobster.gz"
charge_path = dir_name / "CHARGE.lobster.gz"
Expand Down Expand Up @@ -451,7 +451,7 @@ def from_directory(
LobsterTaskDocument
A task document for the lobster calculation.
"""
additional_fields = {} if additional_fields is None else additional_fields
additional_fields = additional_fields or {}
dir_name = Path(dir_name)

# Read in lobsterout and lobsterin
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/vasp/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def copy_vasp_outputs(

# check at least one type of POTCAR file is included
if len([f for f in optional_files if "POTCAR" in f.name]) == 0:
raise FileNotFoundError("Could not find POTCAR file to copy.")
raise FileNotFoundError(f"Could not find a POTCAR file in {src_dir!r} to copy")

copy_files(
src_dir,
Expand Down
2 changes: 1 addition & 1 deletion src/atomate2/vasp/jobs/defect.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def calculate_finite_diff(
previous calculations).
"""
ref_calc_dir = distorted_calc_dirs[ref_calc_index]
run_vasp_kwargs = {} if run_vasp_kwargs is None else run_vasp_kwargs
run_vasp_kwargs = run_vasp_kwargs or {}
fc = FileClient()
copy_vasp_outputs(ref_calc_dir, additional_vasp_files=["WAVECAR"], file_client=fc)

Expand Down
1 change: 1 addition & 0 deletions src/atomate2/vasp/jobs/mp.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ class MPPreRelaxMaker(BaseVaspMaker):
"GGA": "PS",
"LWAVE": True,
"LCHARG": True,
"METAGGA": None,
},
)
)
Expand Down
4 changes: 2 additions & 2 deletions src/atomate2/vasp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def run_vasp(
custodian_kwargs : dict
Keyword arguments that are passed to :obj:`.Custodian`.
"""
vasp_job_kwargs = {} if vasp_job_kwargs is None else vasp_job_kwargs
custodian_kwargs = {} if custodian_kwargs is None else custodian_kwargs
vasp_job_kwargs = vasp_job_kwargs or {}
custodian_kwargs = custodian_kwargs or {}

vasp_cmd = expandvars(vasp_cmd)
vasp_gamma_cmd = expandvars(vasp_gamma_cmd)
Expand Down
12 changes: 6 additions & 6 deletions src/atomate2/vasp/sets/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def __init__(
self.poscar = poscar
self.potcar = potcar
self.kpoints = kpoints
self.optional_files = {} if optional_files is None else optional_files
self.optional_files = optional_files or {}

def write_input(
self,
Expand All @@ -89,8 +89,8 @@ def write_input(
Whether to overwrite an input file if it already exists.
"""
directory = Path(directory)
if make_dir and not directory.exists():
os.makedirs(directory)
if make_dir:
os.makedirs(directory, exist_ok=True)

inputs = {
"INCAR": self.incar,
Expand Down Expand Up @@ -620,8 +620,8 @@ def _get_incar(
ispin: int = None,
):
"""Get the INCAR."""
previous_incar = {} if previous_incar is None else previous_incar
incar_updates = {} if incar_updates is None else incar_updates
previous_incar = previous_incar or {}
incar_updates = incar_updates or {}
incar_settings = dict(self.config_dict["INCAR"])
config_magmoms = incar_settings.get("MAGMOM", {})
auto_updates = {}
Expand Down Expand Up @@ -717,7 +717,7 @@ def _get_kpoints(
bandgap: float | None,
) -> Kpoints | None:
"""Get the kpoints file."""
kpoints_updates = {} if kpoints_updates is None else kpoints_updates
kpoints_updates = kpoints_updates or {}

# use user setting if set otherwise default to base config settings
if self.user_kpoints_settings != {}:
Expand Down
4 changes: 3 additions & 1 deletion tests/forcefields/test_jobs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from pytest import approx
from pytest import approx, importorskip

importorskip("quippy")


def test_chgnet_static_maker(si_structure):
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions tests/test_data/vasp/Si_hse_optics/hse_optics/inputs/INCAR
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALGO = All
ALGO = Normal
EDIFF = 1e-05
ENAUG = 1360.0
ENCUT = 680.0
Expand All @@ -20,10 +20,12 @@ LVTOT = True
LWAVE = False
NBANDS = 11
NCORE = 4
NEDOS = 5062
NEDOS = 1265
NELM = 200
NELMIN = 5
NSW = 0
PREC = Accurate
PRECFOCK = Fast
SIGMA = 0.05
CSHIFT = 1e-5
LDAU = False
7 changes: 4 additions & 3 deletions tests/test_data/vasp/Si_hse_optics/hse_static/inputs/INCAR
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ALGO = All
ALGO = Normal
EDIFF = 1e-05
ENAUG = 1360
ENCUT = 680
Expand All @@ -10,10 +10,11 @@ KSPACING = 0.5
LAECHG = True
LASPH = True
LCHARG = True
LELF = True
LELF = False
LHFCALC = True
LMIXTAU = True
LORBIT = 11
LDAU = False
LREAL = False
LVTOT = True
LWAVE = False
Expand All @@ -23,4 +24,4 @@ NELM = 200
NSW = 0
PREC = Accurate
PRECFOCK = Fast
SIGMA = 0.05
SIGMA = 0.2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ LREAL = Auto
LVTOT = True
LWAVE = True
MAGMOM = 2*0.0
METAGGA = R2scan
NELM = 200
NSW = 99
PREC = Accurate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ ALGO = Fast
EDIFF = 1e-05
ENAUG = 1360.0
ENCUT = 680.0
GGA = Ps
ISMEAR = -5
ISPIN = 2
KSPACING = 0.29539340980039036
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ EDIFF = 1e-05
EDIFFG = -0.05
ENAUG = 1360.0
ENCUT = 680.0
GGA = Ps
IBRION = 2
ISIF = 3
ISMEAR = 0
ISMEAR = -5
ISPIN = 2
KSPACING = 0.28253269576667883
LAECHG = True
Expand Down
Binary file modified tests/test_data/vasp/Si_old_double_relax/outputs/POTCAR.gz
Binary file not shown.
Loading

0 comments on commit a5efa2e

Please sign in to comment.