Skip to content

Commit e2acb83

Browse files
committed
refactor: rename core classes and standardise architecture
- Rename workflow and entropy components for clearer responsibilities - Standardise manager/node/graph naming across modules - Align class names with current design (workflow + DAG model) - Improve consistency between entropy and levels packages - Update imports and wiring throughout codebase
1 parent 91c865a commit e2acb83

27 files changed

Lines changed: 186 additions & 243 deletions

‎CodeEntropy/cli.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
The entry point is intentionally small and only responsible for:
77
1) Creating a job folder.
8-
2) Constructing a RunManager.
8+
2) Constructing a CodeEntropyRunner.
99
3) Executing the entropy workflow.
1010
4) Handling fatal errors with a non-zero exit code.
1111
"""
@@ -14,7 +14,7 @@
1414

1515
import logging
1616

17-
from CodeEntropy.config.runtime import RunManager
17+
from CodeEntropy.config.runtime import CodeEntropyRunner
1818

1919
logger = logging.getLogger(__name__)
2020

@@ -25,10 +25,10 @@ def main() -> None:
2525
Raises:
2626
SystemExit: Exits with status code 1 on any unhandled exception.
2727
"""
28-
folder = RunManager.create_job_folder()
28+
folder = CodeEntropyRunner.create_job_folder()
2929

3030
try:
31-
run_manager = RunManager(folder=folder)
31+
run_manager = CodeEntropyRunner(folder=folder)
3232
run_manager.run_entropy_workflow()
3333
except Exception as exc:
3434
logger.critical(

‎CodeEntropy/config/argparse.py‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
1) A declarative argument specification (`ARG_SPECS`) used to build an
66
``argparse.ArgumentParser``.
7-
2) A `ConfigManager` that:
7+
2) A `ConfigResolver` that:
88
- loads YAML configuration (if present),
99
- merges YAML values with CLI values (CLI wins),
1010
- adjusts logging verbosity,
@@ -37,7 +37,7 @@ class ArgSpec:
3737
help: Help text shown in CLI usage.
3838
default: Default value if not provided via CLI or YAML.
3939
type: Python type for parsing (e.g., int, float, str, bool). If bool,
40-
`ConfigManager.str2bool` will be used.
40+
`ConfigResolver.str2bool` will be used.
4141
action: Optional argparse action (e.g., "store_true").
4242
nargs: Optional nargs spec (e.g., "+").
4343
"""
@@ -145,7 +145,7 @@ class ArgSpec:
145145
}
146146

147147

148-
class ConfigManager:
148+
class ConfigResolver:
149149
"""Load, merge, and validate CodeEntropy configuration.
150150
151151
This class provides a consistent interface for:
@@ -224,7 +224,7 @@ def str2bool(value: Any) -> bool:
224224
return False
225225
raise argparse.ArgumentTypeError("Boolean value expected (True/False).")
226226

227-
def setup_argparse(self) -> argparse.ArgumentParser:
227+
def build_parser(self) -> argparse.ArgumentParser:
228228
"""Build an ArgumentParser from argument specs.
229229
230230
Returns:
@@ -262,7 +262,7 @@ def setup_argparse(self) -> argparse.ArgumentParser:
262262

263263
return parser
264264

265-
def merge_configs(
265+
def resolve(
266266
self, args: argparse.Namespace, run_config: Optional[Dict[str, Any]]
267267
) -> argparse.Namespace:
268268
"""Merge CLI arguments with YAML configuration and adjust logging level.
@@ -289,7 +289,7 @@ def merge_configs(
289289

290290
args_dict = vars(args)
291291

292-
parser = self.setup_argparse()
292+
parser = self.build_parser()
293293
default_args = parser.parse_args([])
294294
default_dict = vars(default_args)
295295

@@ -360,7 +360,7 @@ def _apply_logging_level(verbose: bool) -> None:
360360
if verbose:
361361
logger.debug("Verbose mode enabled. Logger set to DEBUG level.")
362362

363-
def input_parameters_validation(self, u: Any, args: argparse.Namespace) -> None:
363+
def validate_inputs(self, u: Any, args: argparse.Namespace) -> None:
364364
"""Validate user inputs against sensible runtime constraints.
365365
366366
Args:

‎CodeEntropy/config/runtime.py‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
"""Run orchestration for CodeEntropy.
22
3-
This module provides the RunManager, which is responsible for:
3+
This module provides the CodeEntropyRunner, which is responsible for:
44
- Creating a new job folder for each run
55
- Loading YAML configuration and merging it with CLI arguments
66
- Setting up logging and displaying a Rich splash screen
77
- Building the MDAnalysis Universe (including optional force merging)
8-
- Wiring dependencies and executing the EntropyManager workflow
8+
- Wiring dependencies and executing the EntropyWorkflow workflow
99
- Providing physical-constants helpers used by entropy calculations
1010
1111
Notes on design:
12-
- RunManager focuses on orchestration and simple utilities only.
13-
- Computational logic lives in EntropyManager and the level/entropy DAG modules.
12+
- CodeEntropyRunner focuses on orchestration and simple utilities only.
13+
- Computational logic lives in EntropyWorkflow and the level/entropy DAG modules.
1414
"""
1515

1616
from __future__ import annotations
@@ -32,26 +32,26 @@
3232
from rich.table import Table
3333
from rich.text import Text
3434

35-
from CodeEntropy.config.argparse import ConfigManager
35+
from CodeEntropy.config.argparse import ConfigResolver
3636
from CodeEntropy.core.logging import LoggingConfig
37-
from CodeEntropy.entropy.manager import EntropyManager
38-
from CodeEntropy.levels.dihedrals import DihedralAnalysis
37+
from CodeEntropy.entropy.workflow import EntropyWorkflow
38+
from CodeEntropy.levels.dihedrals import ConformationStateBuilder
3939
from CodeEntropy.levels.mda import UniverseOperations
40-
from CodeEntropy.molecules.grouping import GroupMolecules
41-
from CodeEntropy.results.reporter import DataLogger
40+
from CodeEntropy.molecules.grouping import MoleculeGrouper
41+
from CodeEntropy.results.reporter import ResultsReporter
4242

4343
logger = logging.getLogger(__name__)
4444
console = LoggingConfig.get_console()
4545

4646

47-
class RunManager:
47+
class CodeEntropyRunner:
4848
"""Coordinate setup and execution of entropy analysis runs.
4949
5050
Responsibilities:
5151
- Bootstrapping: job folder, logging, splash screen
5252
- Configuration: YAML loading + CLI parsing + merge and validation
5353
- Universe creation: MDAnalysis Universe (optionally merging forces)
54-
- Dependency wiring and execution: EntropyManager
54+
- Dependency wiring and execution: EntropyWorkflow
5555
- Utilities used by downstream modules: constants and unit conversions
5656
5757
Attributes:
@@ -62,7 +62,7 @@ class RunManager:
6262
_DEF_TEMPER = 298
6363

6464
def __init__(self, folder: str) -> None:
65-
"""Initialize a RunManager for a given working folder.
65+
"""Initialize a CodeEntropyRunner for a given working folder.
6666
6767
This sets up configuration helpers, data logging, and logging configuration.
6868
It also defines physical constants used in entropy calculations.
@@ -71,8 +71,8 @@ def __init__(self, folder: str) -> None:
7171
folder: Job folder path where logs and outputs will be written.
7272
"""
7373
self.folder = folder
74-
self._config_manager = ConfigManager()
75-
self._data_logger = DataLogger()
74+
self._config_manager = ConfigResolver()
75+
self._reporter = ResultsReporter()
7676
self._logging_config = LoggingConfig(folder)
7777

7878
@property
@@ -227,20 +227,20 @@ def run_entropy_workflow(self) -> None:
227227
- Merges args with YAML per-run config
228228
- Builds the MDAnalysis Universe (with optional force merging)
229229
- Validates user parameters
230-
- Constructs dependencies and executes EntropyManager
230+
- Constructs dependencies and executes EntropyWorkflow
231231
- Saves recorded console output to a log file
232232
233233
Raises:
234234
Exception: Re-raises any exception after logging with traceback.
235235
"""
236236
try:
237-
run_logger = self._logging_config.setup_logging()
237+
run_logger = self._logging_config.configure()
238238
self.show_splash()
239239

240240
current_directory = os.getcwd()
241241
config = self._config_manager.load_config(current_directory)
242242

243-
parser = self._config_manager.setup_argparse()
243+
parser = self._config_manager.build_parser()
244244
args, _ = parser.parse_known_args()
245245
args.output_file = os.path.join(self.folder, args.output_file)
246246

@@ -251,12 +251,12 @@ def run_entropy_workflow(self) -> None:
251251
)
252252
continue
253253

254-
args = self._config_manager.merge_configs(args, run_config)
254+
args = self._config_manager.resolve(args, run_config)
255255

256256
log_level = (
257257
logging.DEBUG if getattr(args, "verbose", False) else logging.INFO
258258
)
259-
self._logging_config.update_logging_level(log_level)
259+
self._logging_config.set_level(log_level)
260260

261261
command = " ".join(os.sys.argv)
262262
logging.getLogger("commands").info(command)
@@ -268,28 +268,28 @@ def run_entropy_workflow(self) -> None:
268268
universe_operations = UniverseOperations()
269269
u = self._build_universe(args, universe_operations)
270270

271-
self._config_manager.input_parameters_validation(u, args)
271+
self._config_manager.validate_inputs(u, args)
272272

273-
group_molecules = GroupMolecules()
274-
dihedral_analysis = DihedralAnalysis(
273+
group_molecules = MoleculeGrouper()
274+
dihedral_analysis = ConformationStateBuilder(
275275
universe_operations=universe_operations
276276
)
277277

278-
entropy_manager = EntropyManager(
278+
entropy_manager = EntropyWorkflow(
279279
run_manager=self,
280280
args=args,
281281
universe=u,
282-
data_logger=self._data_logger,
282+
reporter=self._reporter,
283283
group_molecules=group_molecules,
284284
dihedral_analysis=dihedral_analysis,
285285
universe_operations=universe_operations,
286286
)
287287
entropy_manager.execute()
288288

289-
self._logging_config.save_console_log()
289+
self._logging_config.export_console()
290290

291291
except Exception as e:
292-
logger.error("RunManager encountered an error: %s", e, exc_info=True)
292+
logger.error("CodeEntropyRunner encountered an error: %s", e, exc_info=True)
293293
raise
294294

295295
@staticmethod

‎CodeEntropy/core/logging.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def _setup_handlers(self) -> None:
132132
"mdanalysis": mdanalysis_handler,
133133
}
134134

135-
def setup_logging(self) -> logging.Logger:
135+
def configure(self) -> logging.Logger:
136136
"""Attach configured handlers to the appropriate loggers.
137137
138138
This method:
@@ -173,7 +173,7 @@ def _add_handler_once(logger_obj: logging.Logger, handler: logging.Handler) -> N
173173
if handler not in logger_obj.handlers:
174174
logger_obj.addHandler(handler)
175175

176-
def update_logging_level(self, log_level: int) -> None:
176+
def set_level(self, log_level: int) -> None:
177177
"""Update logging levels for root and named loggers.
178178
179179
Notes:
@@ -207,7 +207,7 @@ def _set_logger_handlers_level(logger_obj: logging.Logger, log_level: int) -> No
207207
else:
208208
handler.setLevel(logging.INFO)
209209

210-
def save_console_log(self, filename: str = "program_output.txt") -> None:
210+
def export_console(self, filename: str = "program_output.txt") -> None:
211211
"""Save recorded console output to a file.
212212
213213
Args:

‎CodeEntropy/entropy/configurational.py‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020

2121
@dataclass(frozen=True)
22-
class ConformationAssignmentConfig:
22+
class ConformationConfig:
2323
"""Configuration for assigning conformational states from a dihedral.
2424
2525
Attributes:
@@ -53,28 +53,13 @@ class ConformationalEntropy:
5353

5454
_GAS_CONST: float = 8.3144598484848
5555

56-
def __init__(
57-
self,
58-
run_manager: Any,
59-
args: Any,
60-
universe: Any,
61-
data_logger: Any,
62-
group_molecules: Any,
63-
) -> None:
64-
"""Initialize the conformational entropy helper.
56+
def __init__(self) -> None:
57+
"""Math-only engine.
6558
66-
Args:
67-
run_manager: Workflow run manager.
68-
args: Parsed CLI/config arguments.
69-
universe: MDAnalysis Universe (or compatible container).
70-
data_logger: Optional logger/collector for results.
71-
group_molecules: Grouping helper used elsewhere in the workflow.
59+
This class assigns conformational states and computes conformational entropy.
60+
It does not depend on the workflow runner, universe, grouping, or reporting.
7261
"""
73-
self._run_manager = run_manager
74-
self._args = args
75-
self._universe = universe
76-
self._data_logger = data_logger
77-
self._group_molecules = group_molecules
62+
pass
7863

7964
def assign_conformation(
8065
self,
@@ -113,7 +98,7 @@ def assign_conformation(
11398
"""
11499
_ = number_frames # kept for compatibility; sizing follows the slice length.
115100

116-
config = ConformationAssignmentConfig(
101+
config = ConformationConfig(
117102
bin_width=int(bin_width),
118103
start=int(start),
119104
end=int(end),
@@ -175,7 +160,7 @@ def conformational_entropy_calculation(
175160
return s_conf
176161

177162
@staticmethod
178-
def _validate_assignment_config(config: ConformationAssignmentConfig) -> None:
163+
def _validate_assignment_config(config: ConformationConfig) -> None:
179164
"""Validate conformation assignment configuration.
180165
181166
Args:

‎CodeEntropy/entropy/graph.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131

3232
@dataclass(frozen=True)
33-
class GraphNodeSpec:
33+
class NodeSpec:
3434
"""Specification for a node within the entropy graph.
3535
3636
Attributes:
@@ -66,9 +66,9 @@ def build(self) -> "EntropyGraph":
6666
Self for fluent chaining.
6767
"""
6868
specs = (
69-
GraphNodeSpec("vibrational_entropy", VibrationalEntropyNode()),
70-
GraphNodeSpec("configurational_entropy", ConfigurationalEntropyNode()),
71-
GraphNodeSpec(
69+
NodeSpec("vibrational_entropy", VibrationalEntropyNode()),
70+
NodeSpec("configurational_entropy", ConfigurationalEntropyNode()),
71+
NodeSpec(
7272
"aggregate_entropy",
7373
AggregateEntropyNode(),
7474
deps=("vibrational_entropy", "configurational_entropy"),
@@ -102,7 +102,7 @@ def execute(self, shared_data: SharedData) -> Dict[str, Any]:
102102
results.update(out)
103103
return results
104104

105-
def _add_node(self, spec: GraphNodeSpec) -> None:
105+
def _add_node(self, spec: NodeSpec) -> None:
106106
"""Add a node and its dependencies to the graph.
107107
108108
Args:

0 commit comments

Comments
 (0)