Skip to content

Commit cd71ef2

Browse files
committed
return dict from metadata function, then call this function right after to get METADATA
1 parent a5745eb commit cd71ef2

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

ml_peg/analysis/molecular/Wiggle150/analyse_Wiggle150.py

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ def _sorted_xyz_files(model_dir: Path) -> list[Path]:
4040
return sorted(model_dir.glob("*.xyz"), key=lambda path: int(path.stem))
4141

4242

43-
def _extract_metadata() -> tuple[list[str], list[str]]:
43+
def _extract_metadata() -> dict[str, list[str]]:
4444
"""
4545
Return structure identifiers and molecule labels from the first model output.
4646
4747
Returns
4848
-------
49-
tuple[list[str], list[str]]
50-
Ordered structure identifiers and molecule labels.
49+
dict[str, list[str]]
50+
Ordered structure identifiers and molecule labels keyed by ``"structures"``
51+
and ``"molecules"``.
5152
"""
5253
for model_name in MODELS:
5354
model_dir = CALC_PATH / model_name
@@ -63,34 +64,11 @@ def _extract_metadata() -> tuple[list[str], list[str]]:
6364
atoms = read(xyz_file)
6465
structures.append(atoms.info.get("structure", xyz_file.stem))
6566
molecules.append(atoms.info.get("molecule", ""))
66-
return structures, molecules
67-
return [], []
67+
return {"structures": structures, "molecules": molecules}
68+
return {"structures": [], "molecules": []}
6869

6970

70-
def get_structure_names() -> list[str]:
71-
"""
72-
Return ordered structure identifiers for Wiggle150.
73-
74-
Returns
75-
-------
76-
list[str]
77-
Structure identifiers sorted consistently with analysis outputs.
78-
"""
79-
structures, _ = _extract_metadata()
80-
return structures
81-
82-
83-
def get_molecule_labels() -> list[str]:
84-
"""
85-
Return molecule labels corresponding to Wiggle150 structures.
86-
87-
Returns
88-
-------
89-
list[str]
90-
Molecule identifiers aligned with the structure order.
91-
"""
92-
_, molecules = _extract_metadata()
93-
return molecules
71+
METADATA = _extract_metadata()
9472

9573

9674
@pytest.fixture
@@ -100,8 +78,8 @@ def get_molecule_labels() -> list[str]:
10078
x_label="Predicted relative energy / kcal/mol",
10179
y_label="Reference relative energy / kcal/mol",
10280
hoverdata={
103-
"Structure": get_structure_names(),
104-
"Molecule": get_molecule_labels(),
81+
"Structure": METADATA["structures"],
82+
"Molecule": METADATA["molecules"],
10583
},
10684
)
10785
def relative_energies() -> dict[str, list[float]]:

0 commit comments

Comments
 (0)