From 3f66ce6ec0e44ab8f422edb27c37540ae33db010 Mon Sep 17 00:00:00 2001 From: Rodrigo V Honorato Date: Thu, 19 Sep 2024 15:10:47 +0200 Subject: [PATCH] add fallback logic to define `cns_exec` --- src/haddock/core/defaults.py | 16 ++++++++++++++-- src/haddock/modules/topology/topoaa/__init__.py | 7 +++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/haddock/core/defaults.py b/src/haddock/core/defaults.py index fa8a8805f..d957e6676 100644 --- a/src/haddock/core/defaults.py +++ b/src/haddock/core/defaults.py @@ -1,19 +1,31 @@ """All default parameters used by the framework.""" import importlib.resources +import os import string +import sys from pathlib import Path import yaml from pkg_resources import resource_filename import haddock -from haddock import core_path +from haddock import core_path, log BINARY_DIR = Path(importlib.resources.files(haddock) / "bin") # type: ignore -cns_exec = Path(resource_filename("haddock", "bin/cns")) +cns_exec = Path(resource_filename("haddock", "bin/cns_")) +if not cns_exec.exists(): + log.warning("CNS executable not found at %s", cns_exec) + _cns_exec = os.environ.get("CNS_EXEC") + if _cns_exec is None: + log.error( + "Please define the location the CNS binary by setting a CNS_EXEC system variable" + ) + sys.exit(1) + else: + cns_exec = Path(_cns_exec) CONTACT_FCC_EXEC = Path(resource_filename("haddock", "bin/contact_fcc")) FAST_RMSDMATRIX_EXEC = Path(resource_filename("haddock", "bin/fast-rmsdmatrix")) diff --git a/src/haddock/modules/topology/topoaa/__init__.py b/src/haddock/modules/topology/topoaa/__init__.py index b8b5ed111..29f556b3d 100644 --- a/src/haddock/modules/topology/topoaa/__init__.py +++ b/src/haddock/modules/topology/topoaa/__init__.py @@ -29,7 +29,7 @@ from functools import partial from pathlib import Path -from haddock.core.defaults import MODULE_DEFAULT_YAML +from haddock.core.defaults import MODULE_DEFAULT_YAML, cns_exec from haddock.core.typing import FilePath, Optional, ParamDict, ParamMap, Union from haddock.libs import libpdb from haddock.libs.libcns import ( @@ -37,7 +37,7 @@ load_workflow_params, prepare_output, prepare_single_input, -) + ) from haddock.libs.libontology import Format, PDBFile, TopologyFile from haddock.libs.libstructure import make_molecules from haddock.libs.libsubprocess import CNSJob @@ -262,13 +262,12 @@ def _run(self) -> None: # Add new job to the pool output_filename = Path(f"{model.stem}.{Format.CNS_OUTPUT}") err_fname = f"{model.stem}.cnserr" - job = CNSJob( topoaa_input, output_filename, err_fname, envvars=self.envvars, - cns_exec=self.params["cns_exec"], + cns_exec=cns_exec, ) jobs.append(job)