Skip to content

Commit

Permalink
add class BaseMaker(Maker, ABC) in new atomate2/common/jobs/base.py
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 27, 2023
1 parent 47f564c commit 3d25536
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 7 deletions.
44 changes: 44 additions & 0 deletions src/atomate2/common/jobs/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""BaseMaker enforces a specific 'make' method signature for all atomate2 makers."""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, Any

from jobflow import Flow, Maker, Response

if TYPE_CHECKING:
from pymatgen.core import Structure

Check warning on line 11 in src/atomate2/common/jobs/base.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/common/jobs/base.py#L11

Added line #L11 was not covered by tests


class BaseMaker(Maker, ABC):
"""
Abstract base class for atomate2 Makers.
This class is designed to enforce a consistent signature for the 'make' method.
All subclasses must implement this method with identical signature so they are
easily exchangeable in Flows.
"""

@abstractmethod
def make(
self,
structure: Structure,
*args: Any,
**kwargs: Any,
) -> Response | Flow:
"""
Abstract method for making a job or task. Must be implemented by subclasses.
Parameters
----------
structure : Structure
The structure for the task or job.
prev_dir : str | Path | None, optional
The previous directory path, if applicable.
Returns
-------
Response
A jobflow.Response object containing the outcome of the task or job.
"""
11 changes: 6 additions & 5 deletions src/atomate2/forcefields/flows/relax.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
from dataclasses import dataclass, field
from typing import TYPE_CHECKING

from jobflow import Flow, Maker
from jobflow import Flow

from atomate2.common.jobs.base import BaseMaker
from atomate2.forcefields.jobs import CHGNetRelaxMaker, M3GNetRelaxMaker
from atomate2.vasp.jobs.core import RelaxMaker

Expand All @@ -17,7 +18,7 @@


@dataclass
class CHGNetVaspRelaxMaker(Maker):
class CHGNetVaspRelaxMaker(BaseMaker):
"""
Maker to (pre)relax a structure using CHGNet and then run VASP.
Expand All @@ -35,7 +36,7 @@ class CHGNetVaspRelaxMaker(Maker):
chgnet_maker: CHGNetRelaxMaker = field(default_factory=CHGNetRelaxMaker)
vasp_maker: BaseVaspMaker = field(default_factory=RelaxMaker)

def make(self, structure: Structure) -> Flow:
def make(self, structure: Structure, *args, **kwargs) -> Flow:
"""
Create a flow with a CHGNet (pre)relaxation followed by a VASP relaxation.
Expand All @@ -58,7 +59,7 @@ def make(self, structure: Structure) -> Flow:


@dataclass
class M3GNetVaspRelaxMaker(Maker):
class M3GNetVaspRelaxMaker(BaseMaker):
"""
Maker to (pre)relax a structure using M3GNet and then run VASP.
Expand All @@ -76,7 +77,7 @@ class M3GNetVaspRelaxMaker(Maker):
m3gnet_maker: M3GNetRelaxMaker = field(default_factory=M3GNetRelaxMaker)
vasp_maker: BaseVaspMaker = field(default_factory=RelaxMaker)

def make(self, structure: Structure) -> Flow:
def make(self, structure: Structure, *args, **kwargs) -> Flow:
"""
Create a flow with a M3GNet (pre)relaxation followed by a VASP relaxation.
Expand Down
9 changes: 7 additions & 2 deletions src/atomate2/vasp/flows/amset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from atomate2 import SETTINGS
from atomate2.amset.jobs import AmsetMaker
from atomate2.common.jobs.base import BaseMaker

Check warning on line 14 in src/atomate2/vasp/flows/amset.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/vasp/flows/amset.py#L14

Added line #L14 was not covered by tests
from atomate2.vasp.flows.core import DoubleRelaxMaker
from atomate2.vasp.flows.elastic import ElasticMaker
from atomate2.vasp.jobs.amset import (
Expand Down Expand Up @@ -59,7 +60,7 @@


@dataclass
class DeformationPotentialMaker(Maker):
class DeformationPotentialMaker(BaseMaker):

Check warning on line 63 in src/atomate2/vasp/flows/amset.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/vasp/flows/amset.py#L63

Added line #L63 was not covered by tests
"""
Maker to generate acoustic deformation potentials for amset.
Expand All @@ -86,8 +87,10 @@ class DeformationPotentialMaker(Maker):
def make(
self,
structure: Structure,
*args,
prev_dir: str | Path | None = None,
ibands: tuple[list[int], list[int]] = None,
**kwargs,
) -> Flow:
"""
Make flow to calculate acoustic deformation potentials.
Expand Down Expand Up @@ -323,7 +326,7 @@ def make(


@dataclass
class HSEVaspAmsetMaker(Maker):
class HSEVaspAmsetMaker(BaseMaker):

Check warning on line 329 in src/atomate2/vasp/flows/amset.py

View check run for this annotation

Codecov / codecov/patch

src/atomate2/vasp/flows/amset.py#L329

Added line #L329 was not covered by tests
"""
Maker to calculate transport properties using AMSET with HSE06 VASP inputs.
Expand Down Expand Up @@ -385,7 +388,9 @@ class HSEVaspAmsetMaker(Maker):
def make(
self,
structure: Structure,
*args,
prev_dir: str | Path | None = None,
**kwargs,
) -> Flow:
"""
Make flow to calculate electronic transport properties using AMSET and VASP.
Expand Down

0 comments on commit 3d25536

Please sign in to comment.