CodeEntropy 2.2.4__py3-none-any.whl → 2.4.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- CodeEntropy/__init__.py +1 -1
- CodeEntropy/config/argparse.py +232 -66
- CodeEntropy/config/runtime.py +18 -3
- CodeEntropy/core/dask_clusters.py +279 -0
- CodeEntropy/entropy/workflow.py +148 -89
- CodeEntropy/levels/axes.py +550 -55
- CodeEntropy/levels/dihedrals/__init__.py +0 -0
- CodeEntropy/levels/dihedrals/angle_observations.py +271 -0
- CodeEntropy/levels/dihedrals/conformational_state_builder.py +204 -0
- CodeEntropy/levels/dihedrals/kernels.py +116 -0
- CodeEntropy/levels/dihedrals/peak_detection.py +270 -0
- CodeEntropy/levels/dihedrals/state_assignment.py +281 -0
- CodeEntropy/levels/dihedrals/topology.py +233 -0
- CodeEntropy/levels/execution/__init__.py +0 -0
- CodeEntropy/levels/execution/chunks.py +28 -0
- CodeEntropy/levels/execution/policy.py +84 -0
- CodeEntropy/levels/execution/reducers.py +386 -0
- CodeEntropy/levels/execution/scheduler.py +306 -0
- CodeEntropy/levels/execution/tasks.py +330 -0
- CodeEntropy/levels/graph/__init__.py +0 -0
- CodeEntropy/levels/graph/conformation_dag.py +95 -0
- CodeEntropy/levels/graph/frame_dag.py +108 -0
- CodeEntropy/levels/graph/level_dag.py +206 -0
- CodeEntropy/levels/neighbors.py +144 -202
- CodeEntropy/levels/nodes/accumulators.py +13 -27
- CodeEntropy/levels/nodes/axes_topology.py +316 -0
- CodeEntropy/levels/nodes/covariance.py +240 -152
- CodeEntropy/levels/search.py +33 -37
- CodeEntropy/trajectory/__init__.py +0 -0
- CodeEntropy/trajectory/frames.py +134 -0
- CodeEntropy/{levels → trajectory}/mda.py +148 -92
- CodeEntropy/trajectory/source.py +49 -0
- {codeentropy-2.2.4.dist-info → codeentropy-2.4.1.dist-info}/METADATA +6 -5
- codeentropy-2.4.1.dist-info/RECORD +65 -0
- {codeentropy-2.2.4.dist-info → codeentropy-2.4.1.dist-info}/WHEEL +1 -1
- CodeEntropy/levels/dihedrals.py +0 -538
- CodeEntropy/levels/frame_dag.py +0 -116
- CodeEntropy/levels/level_dag.py +0 -331
- CodeEntropy/levels/nodes/conformations.py +0 -105
- CodeEntropy/levels/nodes/find_neighbors.py +0 -95
- codeentropy-2.2.4.dist-info/RECORD +0 -48
- {codeentropy-2.2.4.dist-info → codeentropy-2.4.1.dist-info}/entry_points.txt +0 -0
- {codeentropy-2.2.4.dist-info → codeentropy-2.4.1.dist-info}/licenses/LICENSE +0 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Helpers for setting up Dask clusters on HPC using SLURM.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import logging
|
|
8
|
+
import os
|
|
9
|
+
import shlex
|
|
10
|
+
import subprocess
|
|
11
|
+
import sys
|
|
12
|
+
|
|
13
|
+
import psutil
|
|
14
|
+
from dask.distributed import Client
|
|
15
|
+
from dask_jobqueue import SLURMCluster
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HPCDaskManager:
|
|
21
|
+
"""
|
|
22
|
+
Manage SLURM-backed Dask clusters and submission utilities for HPC environments.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, args):
|
|
26
|
+
"""
|
|
27
|
+
Initialise HPCDaskManager with runtime arguments.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
args: Parsed CLI arguments containing HPC and conda configuration.
|
|
31
|
+
"""
|
|
32
|
+
self.args = args
|
|
33
|
+
|
|
34
|
+
def _conda_env(self) -> str:
|
|
35
|
+
"""Determine the activated conda/mamba environment."""
|
|
36
|
+
try:
|
|
37
|
+
return os.environ["CONDA_DEFAULT_ENV"]
|
|
38
|
+
except KeyError:
|
|
39
|
+
logger.error("Please activate your conda/mamba environment.")
|
|
40
|
+
raise SystemExit(1) from None
|
|
41
|
+
|
|
42
|
+
def _conda_exec(self) -> str:
|
|
43
|
+
"""Determine whether conda or mamba should be used for activation."""
|
|
44
|
+
if os.environ.get("MAMBA_EXE"):
|
|
45
|
+
return "mamba"
|
|
46
|
+
|
|
47
|
+
if os.environ.get("CONDA_EXE"):
|
|
48
|
+
return "conda"
|
|
49
|
+
|
|
50
|
+
logger.error(
|
|
51
|
+
"Cannot determine your conda executable. "
|
|
52
|
+
"Please make sure conda or mamba has been initialised."
|
|
53
|
+
)
|
|
54
|
+
raise SystemExit(1)
|
|
55
|
+
|
|
56
|
+
def _conda_path(self) -> str:
|
|
57
|
+
"""Determine the path to the conda executable used for shell initialisation."""
|
|
58
|
+
conda_exe = os.environ.get("CONDA_EXE")
|
|
59
|
+
|
|
60
|
+
if conda_exe:
|
|
61
|
+
return conda_exe
|
|
62
|
+
|
|
63
|
+
logger.error("Please make sure conda is set up correctly.")
|
|
64
|
+
raise SystemExit(1)
|
|
65
|
+
|
|
66
|
+
def resolve_conda_settings(self) -> None:
|
|
67
|
+
"""
|
|
68
|
+
Fill missing conda/mamba settings from the active environment.
|
|
69
|
+
|
|
70
|
+
Explicit user-provided values are preserved. Auto-detection is only used
|
|
71
|
+
when values are missing.
|
|
72
|
+
"""
|
|
73
|
+
args = self.args
|
|
74
|
+
|
|
75
|
+
if not getattr(args, "conda_env", None):
|
|
76
|
+
args.conda_env = self._conda_env()
|
|
77
|
+
|
|
78
|
+
if not getattr(args, "conda_exec", None):
|
|
79
|
+
args.conda_exec = self._conda_exec()
|
|
80
|
+
|
|
81
|
+
if not getattr(args, "conda_path", None) or args.conda_path == "conda":
|
|
82
|
+
args.conda_path = self._conda_path()
|
|
83
|
+
|
|
84
|
+
def check_slurm_env(self) -> None:
|
|
85
|
+
"""
|
|
86
|
+
Remove inherited SLURM environment variables that can break nested srun calls.
|
|
87
|
+
|
|
88
|
+
This is important when the master CodeEntropy process itself is already
|
|
89
|
+
running inside a SLURM allocation and then launches Dask worker jobs.
|
|
90
|
+
"""
|
|
91
|
+
for variable in (
|
|
92
|
+
"SLURM_CPU_BIND",
|
|
93
|
+
"SLURM_MEM_PER_CPU",
|
|
94
|
+
"SLURM_MEM_PER_GPU",
|
|
95
|
+
"SLURM_MEM_PER_NODE",
|
|
96
|
+
):
|
|
97
|
+
os.environ.pop(variable, None)
|
|
98
|
+
|
|
99
|
+
def system_network_interface(self) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Get the best candidate for the HPC network interface.
|
|
102
|
+
|
|
103
|
+
This deliberately follows the WaterEntropy-style behaviour and only
|
|
104
|
+
selects from known HPC-safe interfaces. It avoids selecting arbitrary
|
|
105
|
+
interfaces such as eno1, which may exist on the master node but not on
|
|
106
|
+
worker nodes.
|
|
107
|
+
"""
|
|
108
|
+
hpc_nics = ["bond0", "ib0", "hsn0", "eth0"]
|
|
109
|
+
interfaces = list(psutil.net_if_addrs().keys())
|
|
110
|
+
|
|
111
|
+
for iface in hpc_nics:
|
|
112
|
+
if iface in interfaces:
|
|
113
|
+
return iface
|
|
114
|
+
|
|
115
|
+
raise RuntimeError(
|
|
116
|
+
"Could not find a known HPC network interface. "
|
|
117
|
+
f"Available interfaces: {interfaces}. "
|
|
118
|
+
"Expected one of: bond0, ib0, hsn0, eth0."
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
def slurm_directives(self) -> tuple[list[str], list[str]]:
|
|
122
|
+
"""
|
|
123
|
+
Process additional SLURM directives and directives to skip.
|
|
124
|
+
|
|
125
|
+
Returns:
|
|
126
|
+
Tuple containing extra directives and skipped directives.
|
|
127
|
+
"""
|
|
128
|
+
args = self.args
|
|
129
|
+
extra: list[str] = []
|
|
130
|
+
|
|
131
|
+
if args.hpc_account:
|
|
132
|
+
extra.append(f"--account={args.hpc_account}")
|
|
133
|
+
if args.hpc_qos:
|
|
134
|
+
extra.append(f"--qos={args.hpc_qos}")
|
|
135
|
+
if args.hpc_constraint:
|
|
136
|
+
extra.append(f"--constraint={args.hpc_constraint}")
|
|
137
|
+
|
|
138
|
+
skip = ["--mem"]
|
|
139
|
+
|
|
140
|
+
return extra, skip
|
|
141
|
+
|
|
142
|
+
def slurm_prologues(self) -> list[str]:
|
|
143
|
+
"""
|
|
144
|
+
Build environment setup commands for the SLURM worker job script.
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
List of shell commands executed before the Dask worker starts.
|
|
148
|
+
"""
|
|
149
|
+
args = self.args
|
|
150
|
+
prologue: list[str] = []
|
|
151
|
+
|
|
152
|
+
for module_name in getattr(args, "hpc_modules", None) or []:
|
|
153
|
+
prologue.append(f"module load {module_name}")
|
|
154
|
+
|
|
155
|
+
prologue.append("unset SLURM_MEM_PER_CPU")
|
|
156
|
+
prologue.append("unset SLURM_MEM_PER_GPU")
|
|
157
|
+
prologue.append("unset SLURM_MEM_PER_NODE")
|
|
158
|
+
prologue.append("unset SLURM_CPU_BIND")
|
|
159
|
+
|
|
160
|
+
prologue.append(f'eval "$({args.conda_path} shell.bash hook)"')
|
|
161
|
+
|
|
162
|
+
if args.conda_exec == "mamba":
|
|
163
|
+
prologue.append(f'eval "$({args.conda_exec} shell hook --shell bash)"')
|
|
164
|
+
|
|
165
|
+
prologue.append(f"{args.conda_exec} activate {args.conda_env}")
|
|
166
|
+
prologue.append("export SLURM_CPU_FREQ_REQ=2250000")
|
|
167
|
+
|
|
168
|
+
return prologue
|
|
169
|
+
|
|
170
|
+
def configure_cluster(self) -> Client:
|
|
171
|
+
"""
|
|
172
|
+
Configure a SLURM-backed Dask cluster.
|
|
173
|
+
|
|
174
|
+
Returns:
|
|
175
|
+
Dask distributed client connected to the SLURMCluster.
|
|
176
|
+
"""
|
|
177
|
+
args = self.args
|
|
178
|
+
|
|
179
|
+
self.resolve_conda_settings()
|
|
180
|
+
|
|
181
|
+
extra, skip = self.slurm_directives()
|
|
182
|
+
prologue = self.slurm_prologues()
|
|
183
|
+
iface = self.system_network_interface()
|
|
184
|
+
|
|
185
|
+
self.check_slurm_env()
|
|
186
|
+
|
|
187
|
+
cluster = SLURMCluster(
|
|
188
|
+
cores=args.hpc_cores,
|
|
189
|
+
processes=args.hpc_processes,
|
|
190
|
+
memory=args.hpc_memory,
|
|
191
|
+
queue=args.hpc_queue,
|
|
192
|
+
job_directives_skip=skip,
|
|
193
|
+
job_extra_directives=extra,
|
|
194
|
+
python="srun python",
|
|
195
|
+
walltime=args.hpc_walltime,
|
|
196
|
+
shebang="#!/bin/bash --login",
|
|
197
|
+
local_directory="$PWD",
|
|
198
|
+
interface=iface,
|
|
199
|
+
job_script_prologue=prologue,
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
cluster.scale(jobs=args.hpc_nodes)
|
|
203
|
+
|
|
204
|
+
client = Client(cluster)
|
|
205
|
+
|
|
206
|
+
with open("dask-cluster-submit.sh", "w", encoding="utf-8") as f:
|
|
207
|
+
f.write(cluster.job_script())
|
|
208
|
+
|
|
209
|
+
return client
|
|
210
|
+
|
|
211
|
+
def submit_master(self) -> None:
|
|
212
|
+
"""
|
|
213
|
+
Submit a SLURM job that runs the master CodeEntropy process.
|
|
214
|
+
|
|
215
|
+
This generates a temporary SLURM script and submits it via sbatch.
|
|
216
|
+
"""
|
|
217
|
+
self.resolve_conda_settings()
|
|
218
|
+
|
|
219
|
+
cli = list(sys.argv[1:])
|
|
220
|
+
|
|
221
|
+
if "--submit" in cli:
|
|
222
|
+
idx = cli.index("--submit")
|
|
223
|
+
cli.pop(idx)
|
|
224
|
+
|
|
225
|
+
if idx < len(cli) and str(cli[idx]).lower() in {"true", "false"}:
|
|
226
|
+
cli.pop(idx)
|
|
227
|
+
|
|
228
|
+
script_name = "CodeEntropy-master-submit.sh"
|
|
229
|
+
|
|
230
|
+
with open(script_name, "w", encoding="utf-8") as f:
|
|
231
|
+
f.write("#!/bin/bash --login\n\n")
|
|
232
|
+
f.write("#SBATCH --job-name=codeentropy-master\n")
|
|
233
|
+
f.write("#SBATCH --nodes=1\n")
|
|
234
|
+
f.write("#SBATCH --ntasks=1\n")
|
|
235
|
+
f.write("#SBATCH --cpus-per-task=2\n")
|
|
236
|
+
f.write(f"#SBATCH --time={self.args.hpc_walltime}\n")
|
|
237
|
+
f.write(f"#SBATCH --partition={self.args.hpc_queue}\n")
|
|
238
|
+
f.write("#SBATCH --output=CodeEntropy-master-%j.out\n")
|
|
239
|
+
f.write("#SBATCH --error=CodeEntropy-master-%j.err\n")
|
|
240
|
+
|
|
241
|
+
if self.args.hpc_account:
|
|
242
|
+
f.write(f"#SBATCH --account={self.args.hpc_account}\n")
|
|
243
|
+
|
|
244
|
+
if self.args.hpc_qos:
|
|
245
|
+
f.write(f"#SBATCH --qos={self.args.hpc_qos}\n")
|
|
246
|
+
|
|
247
|
+
if self.args.hpc_constraint:
|
|
248
|
+
f.write(f"#SBATCH --constraint={self.args.hpc_constraint}\n")
|
|
249
|
+
|
|
250
|
+
f.write("\n")
|
|
251
|
+
|
|
252
|
+
for module_name in getattr(self.args, "hpc_modules", None) or []:
|
|
253
|
+
f.write(f"module load {module_name}\n")
|
|
254
|
+
|
|
255
|
+
f.write("unset SLURM_MEM_PER_CPU\n")
|
|
256
|
+
f.write("unset SLURM_MEM_PER_GPU\n")
|
|
257
|
+
f.write("unset SLURM_MEM_PER_NODE\n")
|
|
258
|
+
f.write("unset SLURM_CPU_BIND\n")
|
|
259
|
+
|
|
260
|
+
f.write(f'eval "$({self.args.conda_path} shell.bash hook)"\n')
|
|
261
|
+
|
|
262
|
+
if self.args.conda_exec == "mamba":
|
|
263
|
+
f.write(f'eval "$({self.args.conda_exec} shell hook --shell bash)"\n')
|
|
264
|
+
|
|
265
|
+
f.write(f"{self.args.conda_exec} activate {self.args.conda_env}\n")
|
|
266
|
+
f.write("export SLURM_CPU_FREQ_REQ=2250000\n")
|
|
267
|
+
f.write("export CODEENTROPY_SUBMITTED_JOB=1\n\n")
|
|
268
|
+
|
|
269
|
+
command = " ".join(["srun", "CodeEntropy", shlex.join(cli)])
|
|
270
|
+
f.write(f"{command}\n")
|
|
271
|
+
|
|
272
|
+
self.check_slurm_env()
|
|
273
|
+
|
|
274
|
+
try:
|
|
275
|
+
result = subprocess.check_output(["sbatch", script_name])
|
|
276
|
+
print(result.decode("utf-8"))
|
|
277
|
+
except subprocess.CalledProcessError as exc:
|
|
278
|
+
print(exc.output.decode("utf-8", errors="replace"))
|
|
279
|
+
raise
|
CodeEntropy/entropy/workflow.py
CHANGED
|
@@ -16,19 +16,20 @@ The manager intentionally delegates calculations to dedicated components.
|
|
|
16
16
|
from __future__ import annotations
|
|
17
17
|
|
|
18
18
|
import logging
|
|
19
|
-
import math
|
|
20
19
|
from collections import defaultdict
|
|
21
20
|
from collections.abc import Mapping
|
|
22
|
-
from dataclasses import dataclass
|
|
23
21
|
from typing import Any
|
|
24
22
|
|
|
25
23
|
import pandas as pd
|
|
26
24
|
|
|
25
|
+
from CodeEntropy.core.dask_clusters import HPCDaskManager
|
|
27
26
|
from CodeEntropy.core.logging import LoggingConfig
|
|
28
27
|
from CodeEntropy.entropy.graph import EntropyGraph
|
|
29
28
|
from CodeEntropy.entropy.water import WaterEntropy
|
|
29
|
+
from CodeEntropy.levels.graph.level_dag import LevelDAG
|
|
30
30
|
from CodeEntropy.levels.hierarchy import HierarchyBuilder
|
|
31
|
-
from CodeEntropy.
|
|
31
|
+
from CodeEntropy.trajectory.frames import FrameSelection
|
|
32
|
+
from CodeEntropy.trajectory.source import FrameSource
|
|
32
33
|
|
|
33
34
|
logger = logging.getLogger(__name__)
|
|
34
35
|
console = LoggingConfig.get_console()
|
|
@@ -36,23 +37,6 @@ console = LoggingConfig.get_console()
|
|
|
36
37
|
SharedData = dict[str, Any]
|
|
37
38
|
|
|
38
39
|
|
|
39
|
-
@dataclass(frozen=True)
|
|
40
|
-
class TrajectorySlice:
|
|
41
|
-
"""Trajectory slicing parameters.
|
|
42
|
-
|
|
43
|
-
Attributes:
|
|
44
|
-
start: Inclusive start frame index.
|
|
45
|
-
end: Exclusive end frame index (or a concrete index derived from args).
|
|
46
|
-
step: Step size between frames.
|
|
47
|
-
n_frames: Number of frames in the slice.
|
|
48
|
-
"""
|
|
49
|
-
|
|
50
|
-
start: int
|
|
51
|
-
end: int
|
|
52
|
-
step: int
|
|
53
|
-
n_frames: int
|
|
54
|
-
|
|
55
|
-
|
|
56
40
|
class EntropyWorkflow:
|
|
57
41
|
"""Coordinate entropy calculations across structural levels.
|
|
58
42
|
|
|
@@ -95,21 +79,22 @@ class EntropyWorkflow:
|
|
|
95
79
|
"""Run the full entropy workflow and emit results.
|
|
96
80
|
|
|
97
81
|
This orchestrates the complete entropy pipeline:
|
|
98
|
-
1. Build trajectory
|
|
99
|
-
2. Apply atom
|
|
82
|
+
1. Build trajectory frame selection.
|
|
83
|
+
2. Apply atom/frame selection to create the current analysis universe.
|
|
100
84
|
3. Detect hierarchy levels.
|
|
101
85
|
4. Group molecules.
|
|
102
86
|
5. Split groups into water and non-water.
|
|
103
|
-
6. Optionally compute water entropy
|
|
87
|
+
6. Optionally compute water entropy.
|
|
104
88
|
7. Run level DAG and entropy graph.
|
|
105
89
|
8. Finalize and persist results.
|
|
106
90
|
"""
|
|
107
|
-
|
|
91
|
+
frame_selection = self._build_frame_selection()
|
|
108
92
|
console.print(
|
|
109
|
-
f"Analyzing a total of {
|
|
93
|
+
f"Analyzing a total of {frame_selection.n_frames} "
|
|
94
|
+
f"frames in this calculation."
|
|
110
95
|
)
|
|
111
96
|
|
|
112
|
-
reduced_universe = self._build_reduced_universe()
|
|
97
|
+
reduced_universe = self._build_reduced_universe(frame_selection)
|
|
113
98
|
|
|
114
99
|
levels = self._detect_levels(reduced_universe)
|
|
115
100
|
groups = self._group_molecules.grouping_molecules(
|
|
@@ -121,7 +106,7 @@ class EntropyWorkflow:
|
|
|
121
106
|
)
|
|
122
107
|
|
|
123
108
|
if self._args.water_entropy and water_groups and nonwater_groups:
|
|
124
|
-
self._compute_water_entropy(
|
|
109
|
+
self._compute_water_entropy(frame_selection, water_groups)
|
|
125
110
|
else:
|
|
126
111
|
nonwater_groups.update(water_groups)
|
|
127
112
|
|
|
@@ -129,34 +114,105 @@ class EntropyWorkflow:
|
|
|
129
114
|
reduced_universe=reduced_universe,
|
|
130
115
|
levels=levels,
|
|
131
116
|
groups=nonwater_groups,
|
|
132
|
-
|
|
117
|
+
frame_selection=frame_selection,
|
|
133
118
|
)
|
|
134
119
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
120
|
+
self._configure_parallel_frame_execution(shared_data)
|
|
121
|
+
|
|
122
|
+
try:
|
|
123
|
+
with self._reporter.progress(transient=False) as p:
|
|
124
|
+
self._run_level_dag(shared_data, progress=p)
|
|
125
|
+
self._run_entropy_graph(shared_data, progress=p)
|
|
126
|
+
finally:
|
|
127
|
+
client = shared_data.get("dask_client")
|
|
128
|
+
if client is not None:
|
|
129
|
+
client.close()
|
|
138
130
|
|
|
139
131
|
self._finalize_molecule_results()
|
|
140
132
|
self._reporter.log_tables()
|
|
141
133
|
|
|
134
|
+
def _configure_parallel_frame_execution(self, shared_data: SharedData) -> None:
|
|
135
|
+
"""Attach a Dask client to shared_data if parallel frames are requested.
|
|
136
|
+
|
|
137
|
+
Supports:
|
|
138
|
+
- Local Dask via --parallel_frames true / --use_dask true
|
|
139
|
+
- SLURM-backed Dask via --hpc true
|
|
140
|
+
"""
|
|
141
|
+
use_parallel = bool(
|
|
142
|
+
getattr(self._args, "parallel_frames", False)
|
|
143
|
+
or getattr(self._args, "use_dask", False)
|
|
144
|
+
or getattr(self._args, "hpc", False)
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
if not use_parallel:
|
|
148
|
+
return
|
|
149
|
+
|
|
150
|
+
if "dask_client" in shared_data:
|
|
151
|
+
shared_data["parallel_frames"] = True
|
|
152
|
+
return
|
|
153
|
+
|
|
154
|
+
if getattr(self._args, "hpc", False):
|
|
155
|
+
client = HPCDaskManager(self._args).configure_cluster()
|
|
156
|
+
shared_data["dask_client"] = client
|
|
157
|
+
shared_data["parallel_frames"] = True
|
|
158
|
+
return
|
|
159
|
+
|
|
160
|
+
try:
|
|
161
|
+
from dask.distributed import Client
|
|
162
|
+
except ImportError as exc:
|
|
163
|
+
raise RuntimeError(
|
|
164
|
+
"Parallel frame execution was requested, but dask.distributed "
|
|
165
|
+
"is not installed."
|
|
166
|
+
) from exc
|
|
167
|
+
|
|
168
|
+
shared_data["dask_client"] = Client(
|
|
169
|
+
processes=True,
|
|
170
|
+
n_workers=getattr(self._args, "dask_workers", None),
|
|
171
|
+
threads_per_worker=getattr(self._args, "dask_threads_per_worker", 1),
|
|
172
|
+
)
|
|
173
|
+
shared_data["parallel_frames"] = True
|
|
174
|
+
|
|
175
|
+
def _build_frame_selection(self) -> FrameSelection:
|
|
176
|
+
"""Build the workflow frame selection.
|
|
177
|
+
|
|
178
|
+
Returns:
|
|
179
|
+
FrameSelection containing absolute source-trajectory frame indices.
|
|
180
|
+
|
|
181
|
+
Notes:
|
|
182
|
+
Physical frame slicing is not used. The selected frame indices are the
|
|
183
|
+
global workflow frame contract and are consumed by FrameSource.
|
|
184
|
+
"""
|
|
185
|
+
start, end, step = self._get_trajectory_bounds()
|
|
186
|
+
return FrameSelection.from_bounds(
|
|
187
|
+
start=start,
|
|
188
|
+
stop=end,
|
|
189
|
+
step=step,
|
|
190
|
+
)
|
|
191
|
+
|
|
142
192
|
def _build_shared_data(
|
|
143
193
|
self,
|
|
144
194
|
reduced_universe: Any,
|
|
145
195
|
levels: Any,
|
|
146
196
|
groups: Mapping[int, Any],
|
|
147
|
-
|
|
197
|
+
frame_selection: FrameSelection,
|
|
148
198
|
) -> SharedData:
|
|
149
199
|
"""Build the shared_data dict used by nodes and graphs.
|
|
150
200
|
|
|
151
201
|
Args:
|
|
152
|
-
reduced_universe:
|
|
202
|
+
reduced_universe: Active analysis universe after atom selection.
|
|
203
|
+
The trajectory is not physically frame-sliced.
|
|
153
204
|
levels: Level definition per molecule id.
|
|
154
|
-
groups: Mapping of group id
|
|
155
|
-
|
|
205
|
+
groups: Mapping of group id to molecule ids.
|
|
206
|
+
frame_selection: Explicit absolute workflow frame selection.
|
|
156
207
|
|
|
157
208
|
Returns:
|
|
158
209
|
Shared data dictionary for DAG/graph execution.
|
|
159
210
|
"""
|
|
211
|
+
frame_source = FrameSource(
|
|
212
|
+
universe=reduced_universe,
|
|
213
|
+
selection=frame_selection,
|
|
214
|
+
)
|
|
215
|
+
|
|
160
216
|
shared_data: SharedData = {
|
|
161
217
|
"entropy_manager": self,
|
|
162
218
|
"run_manager": self._run_manager,
|
|
@@ -166,10 +222,14 @@ class EntropyWorkflow:
|
|
|
166
222
|
"reduced_universe": reduced_universe,
|
|
167
223
|
"levels": levels,
|
|
168
224
|
"groups": dict(groups),
|
|
169
|
-
"start":
|
|
170
|
-
"end":
|
|
171
|
-
"step":
|
|
172
|
-
"n_frames":
|
|
225
|
+
"start": frame_selection.source_start,
|
|
226
|
+
"end": frame_selection.source_stop_exclusive,
|
|
227
|
+
"step": frame_selection.infer_source_step(),
|
|
228
|
+
"n_frames": frame_selection.n_frames,
|
|
229
|
+
"frame_selection": frame_selection,
|
|
230
|
+
"frame_source": frame_source,
|
|
231
|
+
"frame_indices": list(frame_selection.indices),
|
|
232
|
+
"source_frame_indices": list(frame_selection.indices),
|
|
173
233
|
}
|
|
174
234
|
return shared_data
|
|
175
235
|
|
|
@@ -198,66 +258,56 @@ class EntropyWorkflow:
|
|
|
198
258
|
entropy_results = EntropyGraph().build().execute(shared_data, progress=progress)
|
|
199
259
|
shared_data.update(entropy_results)
|
|
200
260
|
|
|
201
|
-
def
|
|
202
|
-
"""
|
|
261
|
+
def _get_trajectory_bounds(self) -> tuple[int, int, int]:
|
|
262
|
+
"""Return validated start, end, and step frame indices from args.
|
|
203
263
|
|
|
204
264
|
Returns:
|
|
205
|
-
|
|
265
|
+
Tuple of ``(start, end, step)``.
|
|
266
|
+
|
|
267
|
+
Raises:
|
|
268
|
+
ValueError: If the frame window is invalid.
|
|
206
269
|
"""
|
|
207
|
-
|
|
208
|
-
n_frames = self._get_number_frames(start, end, step)
|
|
209
|
-
return TrajectorySlice(start=start, end=end, step=step, n_frames=n_frames)
|
|
270
|
+
n_total = len(self._universe.trajectory)
|
|
210
271
|
|
|
211
|
-
|
|
212
|
-
|
|
272
|
+
start = 0 if self._args.start is None else int(self._args.start)
|
|
273
|
+
end = (
|
|
274
|
+
n_total
|
|
275
|
+
if self._args.end is None or int(self._args.end) == -1
|
|
276
|
+
else int(self._args.end)
|
|
277
|
+
)
|
|
278
|
+
step = 1 if self._args.step is None else int(self._args.step)
|
|
213
279
|
|
|
214
|
-
Returns:
|
|
215
|
-
Tuple of (start, end, step).
|
|
216
|
-
"""
|
|
217
|
-
start = self._args.start or 0
|
|
218
|
-
end = len(self._universe.trajectory) if self._args.end == -1 else self._args.end
|
|
219
|
-
step = self._args.step or 1
|
|
220
280
|
return start, end, step
|
|
221
281
|
|
|
222
|
-
def
|
|
223
|
-
"""
|
|
282
|
+
def _build_reduced_universe(self, frame_selection: FrameSelection) -> Any:
|
|
283
|
+
"""Apply atom selection and return the active analysis universe.
|
|
224
284
|
|
|
225
285
|
Args:
|
|
226
|
-
|
|
227
|
-
end: Exclusive end frame index.
|
|
228
|
-
step: Step between frames.
|
|
286
|
+
frame_selection: Workflow frame selection. Used for validation.
|
|
229
287
|
|
|
230
288
|
Returns:
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
return math.floor((end - start) / step)
|
|
234
|
-
|
|
235
|
-
def _build_reduced_universe(self) -> Any:
|
|
236
|
-
"""Apply atom and frame selection and return the reduced universe.
|
|
289
|
+
MDAnalysis Universe after atom selection. Frames are not physically
|
|
290
|
+
sliced; selected-frame access is handled by FrameSource.
|
|
237
291
|
|
|
238
|
-
|
|
239
|
-
|
|
292
|
+
Raises:
|
|
293
|
+
ValueError: If no frames are selected.
|
|
240
294
|
"""
|
|
295
|
+
if frame_selection.n_frames == 0:
|
|
296
|
+
raise ValueError("Frame selection is empty.")
|
|
297
|
+
|
|
241
298
|
selection = self._args.selection_string
|
|
242
|
-
|
|
243
|
-
end = len(self._universe.trajectory) if self._args.end == -1 else self._args.end
|
|
244
|
-
step = self._args.step
|
|
299
|
+
|
|
245
300
|
if selection == "all":
|
|
246
|
-
|
|
247
|
-
else:
|
|
248
|
-
reduced_atoms = self._universe_operations.select_atoms(
|
|
249
|
-
self._universe, selection
|
|
250
|
-
)
|
|
251
|
-
name = f"{len(reduced_atoms.trajectory)}_frame_dump_atom_selection"
|
|
252
|
-
self._run_manager.write_universe(reduced_atoms, name)
|
|
301
|
+
return self._universe
|
|
253
302
|
|
|
254
|
-
|
|
255
|
-
|
|
303
|
+
reduced_atoms = self._universe_operations.select_atoms(
|
|
304
|
+
self._universe,
|
|
305
|
+
selection,
|
|
256
306
|
)
|
|
257
|
-
name = f"{len(
|
|
258
|
-
self._run_manager.write_universe(
|
|
307
|
+
name = f"{len(reduced_atoms.trajectory)}_frame_dump_atom_selection"
|
|
308
|
+
self._run_manager.write_universe(reduced_atoms, name)
|
|
259
309
|
|
|
260
|
-
return
|
|
310
|
+
return reduced_atoms
|
|
261
311
|
|
|
262
312
|
def _detect_levels(self, reduced_universe: Any) -> Any:
|
|
263
313
|
"""Detect hierarchy levels for each molecule in the reduced universe.
|
|
@@ -316,25 +366,34 @@ class EntropyWorkflow:
|
|
|
316
366
|
return nonwater_groups, water_groups
|
|
317
367
|
|
|
318
368
|
def _compute_water_entropy(
|
|
319
|
-
self,
|
|
369
|
+
self,
|
|
370
|
+
frame_selection: FrameSelection,
|
|
371
|
+
water_groups: Mapping[int, Any],
|
|
320
372
|
) -> None:
|
|
321
373
|
"""Compute water entropy for each water group and adjust selection string.
|
|
322
374
|
|
|
323
375
|
Args:
|
|
324
|
-
|
|
325
|
-
water_groups: Mapping of group id
|
|
376
|
+
frame_selection: Workflow frame selection.
|
|
377
|
+
water_groups: Mapping of group id to molecule ids for waters.
|
|
326
378
|
"""
|
|
327
379
|
if not water_groups or not self._args.water_entropy:
|
|
328
380
|
return
|
|
329
381
|
|
|
382
|
+
start = frame_selection.source_start
|
|
383
|
+
end = frame_selection.source_stop_exclusive
|
|
384
|
+
step = frame_selection.infer_source_step()
|
|
385
|
+
|
|
386
|
+
if start is None or end is None:
|
|
387
|
+
return
|
|
388
|
+
|
|
330
389
|
water_entropy = WaterEntropy(self._args, self._reporter)
|
|
331
390
|
|
|
332
391
|
for group_id in water_groups.keys():
|
|
333
392
|
water_entropy.calculate_and_log(
|
|
334
393
|
universe=self._universe,
|
|
335
|
-
start=
|
|
336
|
-
end=
|
|
337
|
-
step=
|
|
394
|
+
start=start,
|
|
395
|
+
end=end,
|
|
396
|
+
step=step,
|
|
338
397
|
group_id=group_id,
|
|
339
398
|
)
|
|
340
399
|
|
|
@@ -344,8 +403,8 @@ class EntropyWorkflow:
|
|
|
344
403
|
else "not water"
|
|
345
404
|
)
|
|
346
405
|
|
|
347
|
-
logger.debug(
|
|
348
|
-
logger.debug(
|
|
406
|
+
logger.debug("WaterEntropy: molecule_data= %s", self._reporter.molecule_data)
|
|
407
|
+
logger.debug("WaterEntropy: residue_data= %s", self._reporter.residue_data)
|
|
349
408
|
|
|
350
409
|
def _finalize_molecule_results(self) -> None:
|
|
351
410
|
"""Aggregate group totals and persist results to JSON.
|