Skip to content

Commit 9a48215

Browse files
committed
[wip] updating the test file
1 parent 00aec1e commit 9a48215

File tree

2 files changed

+37
-53
lines changed

2 files changed

+37
-53
lines changed

src/atomate2/vasp/jobs/adsorption.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,24 @@ def adsorption_calculations(
251251
outputs["adsorption_energy"].append(ads_energy)
252252
outputs["dirs"].append(adslabs_data["dirs"][i])
253253

254-
sorted_outputs = sorted(
255-
zip(
256-
outputs["adsorption_configuration"],
257-
outputs["configuration_number"],
258-
outputs["adsorption_energy"],
259-
outputs["dirs"],
260-
),
261-
key=lambda x: x[2],
254+
# Combine and sort
255+
combined_outputs = list(
256+
zip(
257+
outputs["adsorption_configuration"],
258+
outputs["configuration_number"],
259+
outputs["adsorption_energy"],
260+
outputs["dirs"],
262261
)
262+
)
263+
sorted_combined_outputs = sorted(combined_outputs, key=lambda x: x[2])
264+
265+
# Reconstruct sorted outputs
266+
sorted_outputs = {
267+
"adsorption_configuration": [item[0] for item in sorted_combined_outputs],
268+
"configuration_number": [item[1] for item in sorted_combined_outputs],
269+
"adsorption_energy": [item[2] for item in sorted_combined_outputs],
270+
"dirs": [item[3] for item in sorted_combined_outputs],
271+
}
263272

264273
return sorted_outputs
265274

tests/vasp/flows/test_adsorption.py

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,8 @@ def test_adsorption(mock_vasp, clean_dir, test_dir):
2020
"adsorption static maker - static configuration 2": "Au_adsorption/ads_static_3_3",
2121
}
2222

23-
# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
2423
fake_run_vasp_kwargs = {
25-
"bulk relaxation maker - bulk relaxation job": {
26-
"incar_settings": ["NSW", "ISIF"]
27-
},
28-
"molecule relaxation maker - molecule relaxation job": {
29-
"incar_settings": ["NSW", "ISIF"]
30-
},
31-
"adsorption relaxation maker - slab relaxation job": {
32-
"incar_settings": ["NSW", "ISIF"]
33-
},
34-
"molecule static maker - molecule static job": {
35-
"incar_settings": ["NSW", "ISIF"]
36-
},
37-
"adsorption static maker - slab static job": {
38-
"incar_settings": ["NSW", "ISIF"]
39-
},
40-
"adsorption relaxation maker - configuration 0": {
41-
"incar_settings": ["NSW", "ISIF"]
42-
},
43-
"adsorption relaxation maker - configuration 1": {
44-
"incar_settings": ["NSW", "ISIF"]
45-
},
46-
"adsorption relaxation maker - configuration 2": {
47-
"incar_settings": ["NSW", "ISIF"]
48-
},
49-
"adsorption static maker - static configuration 0": {
50-
"incar_settings": ["NSW", "ISIF"]
51-
},
52-
"adsorption static maker - static configuration 1": {
53-
"incar_settings": ["NSW", "ISIF"]
54-
},
55-
"adsorption static maker - static configuration 2": {
56-
"incar_settings": ["NSW", "ISIF"]
57-
},
24+
path: {"incar_settings": ["ISIF", "NSW"]} for path in ref_paths
5825
}
5926

6027
# automatically use fake VASP and write POTCAR.spec during the test
@@ -80,12 +47,12 @@ def test_adsorption(mock_vasp, clean_dir, test_dir):
8047
# Run the flow or job and ensure that it finished running successfully
8148
responses = run_locally(flow, create_folders=True, ensure_success=True)
8249

83-
# Check that the correct number of jobs are created
84-
assert (
85-
len(responses) == 16 or len(responses) == 9
86-
), "Unexpected number of jobs in the flow."
50+
job_names = []
51+
for job_uuid, job_responses in responses.items():
52+
for response_index, response in job_responses.items():
53+
if hasattr(response.output, "task_label"):
54+
job_names.append(response.output.task_label)
8755

88-
# Verify job names and order
8956
expected_job_names = [
9057
"bulk relaxation maker - bulk relaxation job",
9158
"molecule relaxation maker - molecule relaxation job",
@@ -99,10 +66,18 @@ def test_adsorption(mock_vasp, clean_dir, test_dir):
9966
"adsorption static maker - static configuration 1",
10067
"adsorption static maker - static configuration 2",
10168
]
102-
for response, expected_name in zip(responses, expected_job_names):
103-
assert (
104-
response.name == expected_name
105-
), f"Job '{response.name}' does not match expected '{expected_name}'."
69+
for actual_name in expected_job_names:
70+
assert actual_name in job_names, f"Job '{actual_name}' not found."
71+
72+
assert (
73+
flow[-1].uuid in responses
74+
), "adsorption calculation job not found in responses"
10675

107-
# assert flow[-2].uuid in responses
108-
# assert flow[-1].uuid in responses
76+
adsorption_calculation_job = responses.get(flow[-1].uuid)
77+
for response_index, response in adsorption_calculation_job.items():
78+
adsorption_energy = response.output.get("adsorption_energy")
79+
assert adsorption_energy == [
80+
-3.0084328299999967,
81+
-2.9288308699999916,
82+
-2.092973299999997,
83+
], "adsorption energy not found in response"

0 commit comments

Comments
 (0)