Skip to content

Commit b63156a

Browse files
committed
Refactor water entropy handling into group-aware pipeline:
- Integrated water entropy into the same group framework as other molecules: - Each water group now gets a proper `group_id`, label, residue count, and atom count - Entropy components (orientational, vibrational-translational, vibrational-rotational) are logged consistently - Updated `_handle_water_entropy` to: - Compute entropy per water group - Exclude water from selection string when `--water-entropy` is enabled - Use MDAnalysis residue names to build accurate group labels - Modified `execute` to: - Separate `water_groups` from `nonwater_groups` - If `water_entropy=True`: handle waters separately and exclude them from later analysis - If `water_entropy=False`: merge water back into non-water groups so they are included in full entropy calculation - Improved `DataLogger` outputs: - Added/cleaned group label mapping table for better tracking - Ensured consistent handling of residue names and frame counts
1 parent 290ee42 commit b63156a

2 files changed

Lines changed: 170 additions & 95 deletions

File tree

CodeEntropy/config/data_logger.py

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def __init__(self, console=None):
1818
self.console = console or Console()
1919
self.molecule_data = []
2020
self.residue_data = []
21+
self.group_labels = {}
2122

2223
def save_dataframes_as_json(self, molecule_df, residue_df, output_file):
2324
"""Save multiple DataFrames into a single JSON file with separate keys"""
@@ -34,20 +35,29 @@ def clean_residue_name(self, resname):
3435
"""Ensures residue names are stripped and cleaned before being stored"""
3536
return re.sub(r"[-–—]", "", str(resname))
3637

37-
def add_results_data(self, resname, level, entropy_type, value):
38+
def add_results_data(self, group_id, level, entropy_type, value):
3839
"""Add data for molecule-level entries"""
39-
resname = self.clean_residue_name(resname)
40-
self.molecule_data.append((resname, level, entropy_type, value))
40+
self.molecule_data.append((group_id, level, entropy_type, value))
4141

42-
def add_residue_data(self, resid, resname, level, entropy_type, frame_count, value):
42+
def add_residue_data(
43+
self, group_id, resname, level, entropy_type, frame_count, value
44+
):
4345
"""Add data for residue-level entries"""
4446
resname = self.clean_residue_name(resname)
4547
if isinstance(frame_count, np.ndarray):
4648
frame_count = frame_count.tolist()
4749
self.residue_data.append(
48-
[resid, resname, level, entropy_type, frame_count, value]
50+
[group_id, resname, level, entropy_type, frame_count, value]
4951
)
5052

53+
def add_group_label(self, group_id, label, residue_count=None, atom_count=None):
54+
"""Store a mapping from group ID to a descriptive label and metadata"""
55+
self.group_labels[group_id] = {
56+
"label": label,
57+
"residue_count": residue_count,
58+
"atom_count": atom_count,
59+
}
60+
5161
def log_tables(self):
5262
"""Display rich tables in terminal"""
5363

@@ -67,7 +77,7 @@ def log_tables(self):
6777

6878
if self.residue_data:
6979
table = Table(title="Residue Entropy Results", show_lines=True, expand=True)
70-
table.add_column("Residue ID", justify="center", style="bold cyan")
80+
table.add_column("Group ID", justify="center", style="bold cyan")
7181
table.add_column("Residue Name", justify="center", style="cyan")
7282
table.add_column("Level", justify="center", style="magenta")
7383
table.add_column("Type", justify="center", style="green")
@@ -78,3 +88,22 @@ def log_tables(self):
7888
table.add_row(*[str(cell) for cell in row])
7989

8090
console.print(table)
91+
92+
if self.group_labels:
93+
label_table = Table(
94+
title="Group ID to Residue Label Mapping", show_lines=True, expand=True
95+
)
96+
label_table.add_column("Group ID", justify="center", style="bold cyan")
97+
label_table.add_column("Residue Label", justify="center", style="green")
98+
label_table.add_column("Residue Count", justify="center", style="magenta")
99+
label_table.add_column("Atom Count", justify="center", style="yellow")
100+
101+
for group_id, info in self.group_labels.items():
102+
label_table.add_row(
103+
str(group_id),
104+
info["label"],
105+
str(info.get("residue_count", "")),
106+
str(info.get("atom_count", "")),
107+
)
108+
109+
console.print(label_table)

0 commit comments

Comments
 (0)