Skip to content

Commit aba9dd3

Browse files
committed
Fix water entropy crash for pure solvent systems and ensure consistent universe usage
1 parent cba3d8e commit aba9dd3

1 file changed

Lines changed: 35 additions & 12 deletions

File tree

CodeEntropy/entropy/workflow.py

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,15 @@ def __init__(
9393
def execute(self) -> None:
9494
"""Run the full entropy workflow and emit results.
9595
96-
This method orchestrates the complete pipeline, populates shared data,
97-
and triggers the DAG/graph executions. Final results are logged and saved
98-
via `ResultsReporter`.
96+
This orchestrates the complete entropy pipeline:
97+
1. Build trajectory slice.
98+
2. Apply atom selection to create a reduced universe.
99+
3. Detect hierarchy levels.
100+
4. Group molecules.
101+
5. Split groups into water and non-water.
102+
6. Optionally compute water entropy (only if solute exists).
103+
7. Run level DAG and entropy graph.
104+
8. Finalize and persist results.
99105
"""
100106
traj = self._build_trajectory_slice()
101107
console.print(
@@ -109,9 +115,11 @@ def execute(self) -> None:
109115
reduced_universe, self._args.grouping
110116
)
111117

112-
nonwater_groups, water_groups = self._split_water_groups(groups)
118+
nonwater_groups, water_groups = self._split_water_groups(
119+
reduced_universe, groups
120+
)
113121

114-
if self._args.water_entropy and water_groups:
122+
if self._args.water_entropy and water_groups and nonwater_groups:
115123
self._compute_water_entropy(traj, water_groups)
116124
else:
117125
nonwater_groups.update(water_groups)
@@ -254,25 +262,40 @@ def _detect_levels(self, reduced_universe: Any) -> Any:
254262
return levels
255263

256264
def _split_water_groups(
257-
self, groups: Mapping[int, Any]
265+
self,
266+
universe: Any,
267+
groups: Mapping[int, Any],
258268
) -> Tuple[Dict[int, Any], Dict[int, Any]]:
259269
"""Partition molecule groups into water and non-water groups.
260270
271+
This method identifies which molecule groups correspond to water
272+
molecules based on residue membership.
273+
261274
Args:
262-
groups: Mapping of group id -> molecule ids.
275+
universe (Any):
276+
The MDAnalysis Universe used to build the molecule groups
277+
(typically the reduced_universe).
278+
groups (Mapping[int, Any]):
279+
Mapping of group_id -> list of molecule fragment indices.
263280
264281
Returns:
265-
Tuple of (nonwater_groups, water_groups).
282+
Tuple[Dict[int, Any], Dict[int, Any]]:
283+
A tuple containing:
284+
285+
- nonwater_groups:
286+
Mapping of group_id -> molecule ids that are NOT water.
287+
- water_groups:
288+
Mapping of group_id -> molecule ids that contain water.
266289
"""
267-
water_atoms = self._universe.select_atoms("water")
290+
water_atoms = universe.select_atoms("water")
268291
water_resids = {res.resid for res in water_atoms.residues}
269292

270293
water_groups = {
271294
gid: mol_ids
272295
for gid, mol_ids in groups.items()
273296
if any(
274297
res.resid in water_resids
275-
for mol in [self._universe.atoms.fragments[i] for i in mol_ids]
298+
for mol in [universe.atoms.fragments[i] for i in mol_ids]
276299
for res in mol.residues
277300
)
278301
}
@@ -293,10 +316,10 @@ def _compute_water_entropy(
293316
if not water_groups or not self._args.water_entropy:
294317
return
295318

296-
water_entropy = WaterEntropy(self._args)
319+
water_entropy = WaterEntropy(self._args, self._reporter)
297320

298321
for group_id in water_groups.keys():
299-
water_entropy._calculate_water_entropy(
322+
water_entropy.calculate_and_log(
300323
universe=self._universe,
301324
start=traj.start,
302325
end=traj.end,

0 commit comments

Comments
 (0)