Skip to content

Commit 89c63b5

Browse files
ensure perfect_match in mcsqs is parsed appropriately
1 parent 1302a38 commit 89c63b5

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

src/atomate2/common/jobs/transform.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,25 @@ def make( # type: ignore[override]
178178
if len(list(os.scandir(mcsqs_dir))) == 0:
179179
mcsqs_dir.unlink()
180180

181+
# For MCSQS, check whether the `perfect_match` was found
182+
# otherwise, SQSTask will throw a validation error
183+
found_perfect_match = False
184+
if (
185+
isinstance(best_objective, str)
186+
and best_objective.lower() == "perfect_match"
187+
):
188+
best_objective = None
189+
found_perfect_match = True
190+
181191
sqs_structures = None
182192
sqs_scores = None
183193
if isinstance(sqs_structs, list) and len(sqs_structs) > 1:
184194
sqs_structures = [entry["structure"] for entry in sqs_structs[1:]]
185195
sqs_scores = [entry["objective_function"] for entry in sqs_structs[1:]]
196+
for i, score in enumerate(sqs_scores):
197+
if isinstance(score, str) and score.lower() == "perfect_match":
198+
sqs_scores[i] = None
199+
found_perfect_match = True
186200

187201
return SQSTask(
188202
transformation=self.transformation,
@@ -192,4 +206,5 @@ def make( # type: ignore[override]
192206
sqs_structures=sqs_structures,
193207
sqs_scores=sqs_scores,
194208
sqs_method=self.transformation.sqs_method,
209+
found_perfect_match=found_perfect_match,
195210
)

src/atomate2/common/schemas/transform.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,23 @@ class SQSTask(TransformTask):
4343
None,
4444
description=(
4545
"The minimum value of the SQS obejective function, "
46-
"corresponding to the structure in `final_structure`"
46+
"corresponding to the structure in `final_structure`."
47+
"If None, but `found_perfect_match` is True, then the "
48+
"ideal SQS structure was found."
4749
),
4850
)
4951
sqs_structures: list[Structure] | None = Field(
5052
None, description="A list of other good SQS candidates."
5153
)
52-
sqs_scores: list[float] | None = Field(
54+
sqs_scores: list[float | None] | None = Field(
5355
None,
5456
description=(
55-
"The objective function values for the structures in `sqs_structures`"
57+
"The objective function values for the structures in `sqs_structures`."
58+
"If any value is `None` and `found_perfect_match` is True, then the "
59+
"ideal SQS structure was found."
5660
),
5761
)
62+
found_perfect_match: bool = Field(
63+
default=False,
64+
description="Whether the lowest possible SQS objective was attained.",
65+
)

0 commit comments

Comments
 (0)