Skip to content

Commit 5f0bc75

Browse files
authored
Allow MatPesStaticFlowMaker(static2=None) (#997)
* allow setting MatPesStaticFlowMaker(static2=None) * expand test_matpes_static_flow_maker to check maker=None cases
1 parent 7add7ca commit 5f0bc75

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

src/atomate2/vasp/flows/matpes.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class MatPesStaticFlowMaker(Maker):
5050
),
5151
)
5252
)
53-
static2: Maker = field(
53+
static2: Maker | None = field(
5454
default_factory=lambda: MatPesMetaGGAStaticMaker(
5555
# start from pre-conditioned WAVECAR from static1 to speed up convergence
5656
# could copy CHGCAR too but is redundant since VASP can reconstruct it from
@@ -69,6 +69,11 @@ class MatPesStaticFlowMaker(Maker):
6969
)
7070
)
7171

72+
def __post_init__(self) -> None:
73+
"""Validate flow."""
74+
if (self.static1, self.static2, self.static3) == (None, None, None):
75+
raise ValueError("Must provide at least one StaticMaker")
76+
7277
def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow:
7378
"""Create a flow with MatPES statics.
7479
@@ -89,10 +94,20 @@ def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow
8994
Flow
9095
A flow containing 2 or 3 statics.
9196
"""
92-
static1 = self.static1.make(structure, prev_dir=prev_dir)
93-
static2 = self.static2.make(structure, prev_dir=static1.output.dir_name)
94-
output = {"static1": static1.output, "static2": static2.output}
95-
jobs = [static1, static2]
97+
jobs = []
98+
output = {}
99+
100+
if self.static1 is not None:
101+
static1 = self.static1.make(structure, prev_dir=prev_dir)
102+
jobs += [static1]
103+
output["static1"] = static1.output
104+
105+
prev_dir = static1.output.dir_name if self.static1 is not None else prev_dir
106+
107+
if self.static2 is not None:
108+
static2 = self.static2.make(structure, prev_dir=prev_dir)
109+
jobs += [static2]
110+
output["static2"] = static2.output
96111

97112
# only run 3rd static if set generator not None and structure contains at least
98113
# one element with Hubbard +U corrections
@@ -104,7 +119,7 @@ def make(self, structure: Structure, prev_dir: str | Path | None = None) -> Flow
104119
anion in elems and elems & {*cations}
105120
for anion, cations in u_corrections.items()
106121
):
107-
static3 = self.static3.make(structure, prev_dir=static1.output.dir_name)
122+
static3 = self.static3.make(structure, prev_dir=prev_dir)
108123
output["static3"] = static3.output
109124
jobs += [static3]
110125

tests/vasp/flows/test_matpes.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,29 @@ def test_matpes_static_flow_maker(mock_vasp, clean_dir, vasp_test_dir):
4646

4747
assert isinstance(flow.output, dict)
4848
assert {*flow.output} == {"static1", "static2"}
49+
50+
# Test setting single maker to None
51+
flow_maker = MatPesStaticFlowMaker(static1=None)
52+
flow = flow_maker.make(si_struct)
53+
assert len(flow) == 1
54+
assert flow[0].name == "MatPES meta-GGA static"
55+
56+
flow_maker = MatPesStaticFlowMaker(static2=None)
57+
flow = flow_maker.make(si_struct)
58+
assert len(flow) == 1
59+
assert flow[0].name == "MatPES GGA static"
60+
61+
# Test setting two makers to None
62+
flow_maker = MatPesStaticFlowMaker(static1=None, static2=None)
63+
flow = flow_maker.make(si_struct)
64+
assert len(flow) == 0
65+
66+
# Test setting all three makers to None
67+
with pytest.raises(ValueError, match="Must provide at least one StaticMaker"):
68+
MatPesStaticFlowMaker(static1=None, static2=None, static3=None)
69+
70+
# Test no static3 if structure requires no Hubbard U corrections
71+
flow_maker = MatPesStaticFlowMaker(static1=None, static2=None)
72+
flow = flow_maker.make(si_struct)
73+
assert len(flow) == 0
74+
assert flow.output == {}

0 commit comments

Comments
 (0)