Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .venv_haddock/lib/python3.12/site-packages/_distutils_hack/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/_distutils_hack/__pycache__/override.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/_yaml/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/freesasa-2.2.1.dist-info/licenses/LICENSE.txt +22 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/__pycache__/__init__.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/bin/contact_fcc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/bin/contact_fcc.cpython-312-darwin.so +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/bin/fast-rmsdmatrix +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/bin/fast_rmsdmatrix.cpython-312-darwin.so +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__init__.py +8 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_analyse.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_cfg.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_clean.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_cp.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_dmn.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_mpi.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_pp.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_restraints.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_score.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_traceback.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/wrapper_haddock_restraints.cpython-312.pyc +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli.py +217 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_analyse.py +864 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_cfg.py +236 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_clean.py +116 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_cp.py +179 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_dmn.py +333 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_mpi.py +123 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_pp.py +168 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_re.py +60 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_restraints.py +143 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_score.py +300 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_traceback.py +370 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_unpack.py +138 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/clis/wrapper_haddock_restraints.py +20 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/__init__.py +3 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/cns_paths.py +99 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/defaults.py +47 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/exceptions.py +79 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/mandatory.yaml +18 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/optional.yaml +32 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/supported_molecules.py +497 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/core/typing.py +197 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/deps/contact_fcc.cpp +124 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/deps/fast-rmsdmatrix.c +883 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/fcc/__init__.py +0 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/fcc/calc_fcc_matrix.py +96 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/fcc/cluster_fcc.py +187 -0
- .venv_haddock/lib/python3.12/site-packages/haddock/gear/__init__.py +7 -0
.venv_haddock/lib/python3.12/site-packages/_distutils_hack/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (10.6 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/_distutils_hack/__pycache__/override.cpython-312.pyc
ADDED
|
Binary file (308 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/_yaml/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (879 Bytes). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/freesasa-2.2.1.dist-info/licenses/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
The MIT License (MIT)
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2016 Simon Mitternacht
|
| 4 |
+
|
| 5 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 6 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 7 |
+
in the Software without restriction, including without limitation the rights
|
| 8 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 9 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 10 |
+
furnished to do so, subject to the following conditions:
|
| 11 |
+
|
| 12 |
+
The above copyright notice and this permission notice shall be included in all
|
| 13 |
+
copies or substantial portions of the Software.
|
| 14 |
+
|
| 15 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 16 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 17 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 18 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 19 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 20 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 21 |
+
SOFTWARE.
|
| 22 |
+
|
.venv_haddock/lib/python3.12/site-packages/haddock/__pycache__/__init__.cpython-312.pyc
ADDED
|
Binary file (2.46 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/bin/contact_fcc
ADDED
|
Binary file (73.3 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/bin/contact_fcc.cpython-312-darwin.so
ADDED
|
Binary file (89.9 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/bin/fast-rmsdmatrix
ADDED
|
Binary file (52.5 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/bin/fast_rmsdmatrix.cpython-312-darwin.so
ADDED
|
Binary file (69 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__init__.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Command-line interfaces.
|
| 3 |
+
|
| 4 |
+
HADDOCK3 has a series of command-line interfaces (CLIs), from which the most important
|
| 5 |
+
one is ``haddock3``. You can ask help to the CLIs with the ``-h`` flag::
|
| 6 |
+
|
| 7 |
+
haddock3 -h
|
| 8 |
+
"""
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli.cpython-312.pyc
ADDED
|
Binary file (6.98 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_analyse.cpython-312.pyc
ADDED
|
Binary file (27 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_cfg.cpython-312.pyc
ADDED
|
Binary file (6.47 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_clean.cpython-312.pyc
ADDED
|
Binary file (4.15 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_cp.cpython-312.pyc
ADDED
|
Binary file (5.89 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_dmn.cpython-312.pyc
ADDED
|
Binary file (11.5 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_mpi.cpython-312.pyc
ADDED
|
Binary file (3.9 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_pp.cpython-312.pyc
ADDED
|
Binary file (5.81 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_restraints.cpython-312.pyc
ADDED
|
Binary file (4.56 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_score.cpython-312.pyc
ADDED
|
Binary file (10.1 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/cli_traceback.cpython-312.pyc
ADDED
|
Binary file (15 kB). View file
|
|
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/__pycache__/w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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Run HADDOCK3 docking simulation.
|
| 4 |
+
|
| 5 |
+
This is the main command-line client to run HADDOCK3 docking
|
| 6 |
+
simulations. To prepare a simulation, setup configuration file defining
|
| 7 |
+
a HADDOCK3 workflow and use this command-line client to execute that
|
| 8 |
+
workflow.
|
| 9 |
+
|
| 10 |
+
Usage::
|
| 11 |
+
|
| 12 |
+
haddock3 -h
|
| 13 |
+
haddock3 <CONFIG FILE>
|
| 14 |
+
"""
|
| 15 |
+
import argparse
|
| 16 |
+
import sys
|
| 17 |
+
from pathlib import Path
|
| 18 |
+
|
| 19 |
+
from haddock import log
|
| 20 |
+
from haddock.core.defaults import RUNDIR
|
| 21 |
+
from haddock.core.typing import (
|
| 22 |
+
ArgumentParser,
|
| 23 |
+
Callable,
|
| 24 |
+
FilePath,
|
| 25 |
+
LogLevel,
|
| 26 |
+
Namespace,
|
| 27 |
+
Optional,
|
| 28 |
+
)
|
| 29 |
+
from haddock.gear.extend_run import EXTEND_RUN_DEFAULT, add_extend_run
|
| 30 |
+
from haddock.gear.restart_run import add_restart_arg
|
| 31 |
+
from haddock.libs.libcli import add_version_arg, arg_file_exist
|
| 32 |
+
from haddock.libs.liblog import add_loglevel_arg
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# Command line interface parser
|
| 36 |
+
ap = argparse.ArgumentParser()
|
| 37 |
+
|
| 38 |
+
ap.add_argument(
|
| 39 |
+
"workflow",
|
| 40 |
+
type=arg_file_exist,
|
| 41 |
+
help=(
|
| 42 |
+
"The input configuration file path describing "
|
| 43 |
+
"the workflow to be performed"
|
| 44 |
+
),
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
add_restart_arg(ap)
|
| 48 |
+
add_extend_run(ap)
|
| 49 |
+
|
| 50 |
+
ap.add_argument(
|
| 51 |
+
"--setup",
|
| 52 |
+
help="Only setup the run, do not execute",
|
| 53 |
+
action="store_true",
|
| 54 |
+
dest="setup_only",
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
add_loglevel_arg(ap)
|
| 58 |
+
add_version_arg(ap)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _ap() -> ArgumentParser:
|
| 62 |
+
return ap
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 66 |
+
"""Load argument parser args."""
|
| 67 |
+
return ap.parse_args()
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 71 |
+
"""Command-line interface entry point."""
|
| 72 |
+
cmd = load_args(ap)
|
| 73 |
+
main(**vars(cmd))
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def maincli() -> None:
|
| 77 |
+
"""Execute main client."""
|
| 78 |
+
cli(_ap(), main)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def main(
|
| 82 |
+
workflow: FilePath,
|
| 83 |
+
restart: Optional[int] = None,
|
| 84 |
+
extend_run: Optional[FilePath] = EXTEND_RUN_DEFAULT,
|
| 85 |
+
setup_only: bool = False,
|
| 86 |
+
log_level: LogLevel = "INFO",
|
| 87 |
+
) -> None:
|
| 88 |
+
"""
|
| 89 |
+
Run an HADDOCK3 workflow.
|
| 90 |
+
|
| 91 |
+
Parameters
|
| 92 |
+
----------
|
| 93 |
+
workflow : str or pathlib.Path
|
| 94 |
+
The path to the workflow (config file).
|
| 95 |
+
|
| 96 |
+
restart : int
|
| 97 |
+
The step to restart the run from (inclusive).
|
| 98 |
+
Defaults to None, which ignores this option.
|
| 99 |
+
|
| 100 |
+
extend_run : str or Path
|
| 101 |
+
The path created with `haddock3-copy` to start the run from.
|
| 102 |
+
Defaults to None, which ignores this option.
|
| 103 |
+
|
| 104 |
+
setup_only : bool, optional
|
| 105 |
+
Whether to setup the run without running it.
|
| 106 |
+
Defaults to False.
|
| 107 |
+
|
| 108 |
+
log_level : str, optional
|
| 109 |
+
The logging level: INFO, DEBUG, ERROR, WARNING, CRITICAL.
|
| 110 |
+
"""
|
| 111 |
+
# anti-pattern to speed up CLI initiation
|
| 112 |
+
from time import time
|
| 113 |
+
|
| 114 |
+
from haddock.gear.extend_run import WorkflowManagerExtend
|
| 115 |
+
from haddock.gear.greetings import (
|
| 116 |
+
get_adieu,
|
| 117 |
+
get_initial_greeting,
|
| 118 |
+
gen_feedback_messages,
|
| 119 |
+
)
|
| 120 |
+
from haddock.gear.postprocessing import archive_run
|
| 121 |
+
from haddock.gear.prepare_run import setup_run
|
| 122 |
+
from haddock.libs.libio import working_directory
|
| 123 |
+
from haddock.libs.liblog import (
|
| 124 |
+
add_log_for_CLI,
|
| 125 |
+
add_stringio_handler,
|
| 126 |
+
log_file_name,
|
| 127 |
+
log_formatters,
|
| 128 |
+
)
|
| 129 |
+
from haddock.libs.libtimer import convert_seconds_to_min_sec
|
| 130 |
+
from haddock.libs.libutil import log_error_and_exit
|
| 131 |
+
from haddock.libs.libworkflow import WorkflowManager
|
| 132 |
+
from haddock.modules import get_module_steps_folders
|
| 133 |
+
|
| 134 |
+
start = time()
|
| 135 |
+
# the io.StringIO handler is a trick to save the log while run_dir
|
| 136 |
+
# is not read from the configuration file and the log can be saved
|
| 137 |
+
# in the final file.
|
| 138 |
+
#
|
| 139 |
+
# Nonetheless, the log is saved in stdout and stderr in case it
|
| 140 |
+
# breaks before the actual logfile is defined.
|
| 141 |
+
# See lines further down on how we resolve this trick
|
| 142 |
+
add_stringio_handler(
|
| 143 |
+
log,
|
| 144 |
+
log_level=log_level,
|
| 145 |
+
formatter=log_formatters[log_level],
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
log.info(get_initial_greeting())
|
| 149 |
+
|
| 150 |
+
with log_error_and_exit():
|
| 151 |
+
params, other_params = setup_run(
|
| 152 |
+
workflow,
|
| 153 |
+
restart_from=restart,
|
| 154 |
+
extend_run=extend_run,
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
# here we the io.StringIO handler log information, and reset the log
|
| 158 |
+
# handlers to fit the CLI and HADDOCK3 specifications.
|
| 159 |
+
log_temporary = log.handlers[-1].stream.getvalue() # type: ignore
|
| 160 |
+
_run_dir: str = other_params[RUNDIR]
|
| 161 |
+
log_file = Path(_run_dir, log_file_name)
|
| 162 |
+
add_log_for_CLI(log, log_level, log_file)
|
| 163 |
+
|
| 164 |
+
# here we append the log information in the previous io.StringIO()
|
| 165 |
+
# handler in the log file already in the run_dir
|
| 166 |
+
with open(log_file, "a") as fout:
|
| 167 |
+
fout.write(log_temporary)
|
| 168 |
+
|
| 169 |
+
if setup_only:
|
| 170 |
+
log.info("We have setup the run, only.")
|
| 171 |
+
gen_feedback_messages(log.info)
|
| 172 |
+
log.info(get_adieu())
|
| 173 |
+
return
|
| 174 |
+
|
| 175 |
+
if extend_run:
|
| 176 |
+
steps_folders = get_module_steps_folders(extend_run)
|
| 177 |
+
restart_step = max([int(fold.split('_')[0]) for fold in steps_folders])
|
| 178 |
+
restart_step += 1
|
| 179 |
+
WorkflowManager_ = WorkflowManagerExtend
|
| 180 |
+
|
| 181 |
+
else:
|
| 182 |
+
restart_step = restart
|
| 183 |
+
WorkflowManager_ = WorkflowManager
|
| 184 |
+
|
| 185 |
+
with (working_directory(_run_dir), log_error_and_exit()):
|
| 186 |
+
workflow = WorkflowManager_(
|
| 187 |
+
workflow_params=params,
|
| 188 |
+
start=restart_step,
|
| 189 |
+
**other_params,
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
+
# Main loop of execution
|
| 193 |
+
workflow.run()
|
| 194 |
+
|
| 195 |
+
# Run post-processing steps
|
| 196 |
+
if other_params["postprocess"]:
|
| 197 |
+
workflow.postprocess(self_contained=other_params["gen_archive"])
|
| 198 |
+
# Clean outputs
|
| 199 |
+
workflow.clean()
|
| 200 |
+
|
| 201 |
+
# Generate archive of the run
|
| 202 |
+
if other_params["gen_archive"]:
|
| 203 |
+
_run_archive, _analysis_archive = archive_run(_run_dir)
|
| 204 |
+
log.info(f"Run archive created: {_run_archive}!")
|
| 205 |
+
if _analysis_archive:
|
| 206 |
+
log.info(f"Run analysis archive created: {_analysis_archive}")
|
| 207 |
+
|
| 208 |
+
# Finish
|
| 209 |
+
end = time()
|
| 210 |
+
elapsed = convert_seconds_to_min_sec(end - start)
|
| 211 |
+
log.info(f"This HADDOCK3 run took: {elapsed}")
|
| 212 |
+
gen_feedback_messages(log.info)
|
| 213 |
+
log.info(get_adieu())
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
if __name__ == "__main__":
|
| 217 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_analyse.py
ADDED
|
@@ -0,0 +1,864 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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AGE::
|
| 15 |
+
|
| 16 |
+
haddock3-analyse -r <run_dir> -m <num_modules>
|
| 17 |
+
haddock3-analyse -r run1 -m 1 3
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
Where, ``-m 1 3`` means that the analysis will be performed on ``1_rigidbody``
|
| 21 |
+
and ``3_flexref``.
|
| 22 |
+
"""
|
| 23 |
+
|
| 24 |
+
import argparse
|
| 25 |
+
import os
|
| 26 |
+
import shutil
|
| 27 |
+
import sys
|
| 28 |
+
from pathlib import Path
|
| 29 |
+
|
| 30 |
+
from haddock import log
|
| 31 |
+
from haddock.clis.cli_unpack import main as haddock3_unpack
|
| 32 |
+
from haddock.clis.cli_clean import main as haddock3_clean
|
| 33 |
+
from haddock.core.defaults import INTERACTIVE_RE_SUFFIX
|
| 34 |
+
from haddock.core.typing import (
|
| 35 |
+
Any,
|
| 36 |
+
ArgumentParser,
|
| 37 |
+
Callable,
|
| 38 |
+
FilePath,
|
| 39 |
+
ImgFormat,
|
| 40 |
+
Namespace,
|
| 41 |
+
Optional,
|
| 42 |
+
ParamDict,
|
| 43 |
+
ParamMap,
|
| 44 |
+
)
|
| 45 |
+
from haddock.gear.yaml2cfg import read_from_yaml_config
|
| 46 |
+
from haddock.gear.clean_steps import _unpack_gz
|
| 47 |
+
from haddock.libs.libcli import _ParamsToDict
|
| 48 |
+
from haddock.libs.libio import archive_files_ext
|
| 49 |
+
from haddock.libs.libontology import ModuleIO
|
| 50 |
+
from haddock.libs.libplots import (
|
| 51 |
+
ClRank,
|
| 52 |
+
box_plot_handler,
|
| 53 |
+
clt_table_handler,
|
| 54 |
+
read_capri_table,
|
| 55 |
+
report_generator,
|
| 56 |
+
scatter_plot_handler,
|
| 57 |
+
SUPPORTED_OUTPUT_FORMATS,
|
| 58 |
+
)
|
| 59 |
+
from haddock.modules import get_module_steps_folders
|
| 60 |
+
from haddock.modules.analysis.caprieval import (
|
| 61 |
+
DEFAULT_CONFIG as caprieval_params,
|
| 62 |
+
)
|
| 63 |
+
from haddock.modules.analysis.caprieval import HaddockModule
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
ANA_FOLDER = "analysis" # name of the analysis folder
|
| 67 |
+
INTER_STR = INTERACTIVE_RE_SUFFIX # suffix of interactive analysis folders
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
# Command line interface parser
|
| 71 |
+
ap = argparse.ArgumentParser(
|
| 72 |
+
prog="haddock3-analyse",
|
| 73 |
+
description=__doc__,
|
| 74 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
ap.add_argument(
|
| 78 |
+
"-r",
|
| 79 |
+
"--run-dir",
|
| 80 |
+
help="The input run directory.",
|
| 81 |
+
required=True,
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
ap.add_argument(
|
| 85 |
+
"-m",
|
| 86 |
+
"--modules",
|
| 87 |
+
nargs="+",
|
| 88 |
+
help="The number of the steps to copy.",
|
| 89 |
+
required=True,
|
| 90 |
+
type=int,
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
ap.add_argument(
|
| 94 |
+
"-t",
|
| 95 |
+
"--top_clusters",
|
| 96 |
+
help="The number of clusters to show.",
|
| 97 |
+
required=False,
|
| 98 |
+
type=int,
|
| 99 |
+
default=10,
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
ap.add_argument(
|
| 103 |
+
"--format",
|
| 104 |
+
help="produce images in the desired format",
|
| 105 |
+
required=False,
|
| 106 |
+
type=str,
|
| 107 |
+
default=None,
|
| 108 |
+
choices=list(SUPPORTED_OUTPUT_FORMATS),
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
ap.add_argument(
|
| 112 |
+
"--scale", help="scale for images", required=False, type=float, default=1.0
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
ap.add_argument(
|
| 116 |
+
"--inter",
|
| 117 |
+
help="interactive analysis",
|
| 118 |
+
required=False,
|
| 119 |
+
type=bool,
|
| 120 |
+
default=False,
|
| 121 |
+
)
|
| 122 |
+
|
| 123 |
+
ap.add_argument(
|
| 124 |
+
"--is_cleaned",
|
| 125 |
+
help="is the directory going to be cleaned?",
|
| 126 |
+
required=False,
|
| 127 |
+
type=bool,
|
| 128 |
+
default=False,
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
ap.add_argument(
|
| 132 |
+
"--offline",
|
| 133 |
+
help="Should plots js functions be self-contained?",
|
| 134 |
+
required=False,
|
| 135 |
+
type=bool,
|
| 136 |
+
default=False,
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
ap.add_argument(
|
| 140 |
+
"--mode",
|
| 141 |
+
help="mode of execution",
|
| 142 |
+
required=False,
|
| 143 |
+
type=str,
|
| 144 |
+
default="local",
|
| 145 |
+
choices=["local", "batch", "mpi"],
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
ap.add_argument(
|
| 149 |
+
"--ncores",
|
| 150 |
+
help="number of cores to use",
|
| 151 |
+
required=False,
|
| 152 |
+
type=int,
|
| 153 |
+
default=1,
|
| 154 |
+
)
|
| 155 |
+
|
| 156 |
+
ap.add_argument(
|
| 157 |
+
"--self-contained",
|
| 158 |
+
help="If self-contained is set, models will be copied locally in the analysis directory, allowing to visualize structures outside of the haddock3 run.",
|
| 159 |
+
required=False,
|
| 160 |
+
default=False,
|
| 161 |
+
type=bool,
|
| 162 |
+
)
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
ap.add_argument(
|
| 166 |
+
"-p",
|
| 167 |
+
"--other-params",
|
| 168 |
+
dest="other_params",
|
| 169 |
+
help=(
|
| 170 |
+
"Any other parameter of the `caprieval` module."
|
| 171 |
+
"For example: -p reference_fname target.pdb."
|
| 172 |
+
"You can give any number of parameters."
|
| 173 |
+
),
|
| 174 |
+
action=_ParamsToDict,
|
| 175 |
+
default={},
|
| 176 |
+
nargs="*",
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def _ap() -> ArgumentParser:
|
| 181 |
+
return ap
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 185 |
+
"""Load argument parser args."""
|
| 186 |
+
return ap.parse_args()
|
| 187 |
+
|
| 188 |
+
|
| 189 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 190 |
+
"""Command-line interface entry point."""
|
| 191 |
+
cmd = vars(load_args(ap))
|
| 192 |
+
kwargs = cmd.pop("other_params")
|
| 193 |
+
main(**cmd, **kwargs)
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
def maincli() -> None:
|
| 197 |
+
"""Execute main client."""
|
| 198 |
+
cli(_ap(), main)
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
def get_cluster_ranking(
|
| 202 |
+
capri_clt_filename: FilePath,
|
| 203 |
+
top_clusters: int,
|
| 204 |
+
) -> ClRank:
|
| 205 |
+
"""
|
| 206 |
+
Get capri cluster ranking.
|
| 207 |
+
|
| 208 |
+
Parameters
|
| 209 |
+
----------
|
| 210 |
+
capri_clt_filename : str or Path
|
| 211 |
+
capri cluster filename
|
| 212 |
+
top_clusters : int
|
| 213 |
+
Number of clusters to be considered
|
| 214 |
+
|
| 215 |
+
Returns
|
| 216 |
+
-------
|
| 217 |
+
cl_ranking : dict
|
| 218 |
+
{cluster_id : cluster_rank} dictionary
|
| 219 |
+
"""
|
| 220 |
+
cl_ranking: ClRank = {}
|
| 221 |
+
dfcl = read_capri_table(capri_clt_filename)
|
| 222 |
+
for n in range(min(top_clusters, dfcl.shape[0])):
|
| 223 |
+
cl_ranking[dfcl["cluster_id"].iloc[n]] = dfcl["caprieval_rank"].iloc[n]
|
| 224 |
+
return cl_ranking
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
def update_paths(
|
| 228 |
+
capri_ss_filename: FilePath, toch: str = "../", toadd: str = "../../"
|
| 229 |
+
) -> None:
|
| 230 |
+
"""
|
| 231 |
+
Update paths in capri_ss_filename.
|
| 232 |
+
|
| 233 |
+
Parameters
|
| 234 |
+
----------
|
| 235 |
+
capri_ss_filename : str or Path
|
| 236 |
+
capri ss filename
|
| 237 |
+
toch : str
|
| 238 |
+
string to be replaced
|
| 239 |
+
toadd : str
|
| 240 |
+
string to be added
|
| 241 |
+
"""
|
| 242 |
+
new_lines: list[str] = []
|
| 243 |
+
with open(capri_ss_filename, "r") as rfile:
|
| 244 |
+
for ln in rfile:
|
| 245 |
+
new_ln = ln.replace(toch, toadd)
|
| 246 |
+
new_lines.append(new_ln)
|
| 247 |
+
|
| 248 |
+
with open(capri_ss_filename, "w") as wfile:
|
| 249 |
+
for ln in new_lines:
|
| 250 |
+
wfile.write(ln)
|
| 251 |
+
return
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def run_capri_analysis(
|
| 255 |
+
step: str,
|
| 256 |
+
run_dir: FilePath,
|
| 257 |
+
capri_dict: ParamMap,
|
| 258 |
+
is_cleaned: bool,
|
| 259 |
+
mode: str,
|
| 260 |
+
ncores: int,
|
| 261 |
+
) -> None:
|
| 262 |
+
"""
|
| 263 |
+
Run the caprieval analysis.
|
| 264 |
+
|
| 265 |
+
Parameters
|
| 266 |
+
----------
|
| 267 |
+
step : str
|
| 268 |
+
step name
|
| 269 |
+
run_dir : str or Path
|
| 270 |
+
path to run directory
|
| 271 |
+
capri_dict : dict
|
| 272 |
+
capri dictionary of parameters
|
| 273 |
+
"""
|
| 274 |
+
# retrieve json file with all information
|
| 275 |
+
io = ModuleIO()
|
| 276 |
+
filename = Path("..", f"{step}/io.json")
|
| 277 |
+
io.load(filename)
|
| 278 |
+
# unpack the files if they are compressed
|
| 279 |
+
if is_cleaned:
|
| 280 |
+
path_to_unpack = io.output[0].rel_path.parent
|
| 281 |
+
haddock3_unpack(path_to_unpack, ncores=ncores)
|
| 282 |
+
# define step_order. We add one to it, as the caprieval module will
|
| 283 |
+
# interpret itself as being after the selected step
|
| 284 |
+
step_order = int(step.split("_")[0]) + 1
|
| 285 |
+
# create capri
|
| 286 |
+
caprieval_module = HaddockModule(
|
| 287 |
+
order=step_order,
|
| 288 |
+
path=Path(run_dir),
|
| 289 |
+
init_params=caprieval_params,
|
| 290 |
+
)
|
| 291 |
+
caprieval_module.update_params(**capri_dict)
|
| 292 |
+
# updating mode and ncores
|
| 293 |
+
caprieval_module.params["mode"] = mode
|
| 294 |
+
caprieval_module.params["ncores"] = ncores
|
| 295 |
+
# update model info
|
| 296 |
+
caprieval_module.previous_io = io
|
| 297 |
+
# run capri module
|
| 298 |
+
caprieval_module._run()
|
| 299 |
+
# compress files if they should be compressed
|
| 300 |
+
if is_cleaned:
|
| 301 |
+
haddock3_clean(path_to_unpack, ncores=ncores)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def update_capri_dict(default_capri: ParamDict, kwargs: ParamMap) -> ParamDict:
|
| 305 |
+
"""
|
| 306 |
+
Update capri dictionary.
|
| 307 |
+
|
| 308 |
+
Parameters
|
| 309 |
+
----------
|
| 310 |
+
default_capri : dict
|
| 311 |
+
default capri dictionary of parameters
|
| 312 |
+
kwargs : dict
|
| 313 |
+
dictionary of input elements
|
| 314 |
+
|
| 315 |
+
Returns
|
| 316 |
+
-------
|
| 317 |
+
capri_dict : dict
|
| 318 |
+
updated capri dictionary of parameters
|
| 319 |
+
"""
|
| 320 |
+
capri_dict = default_capri.copy()
|
| 321 |
+
for param in kwargs:
|
| 322 |
+
if param not in default_capri:
|
| 323 |
+
sys.exit(
|
| 324 |
+
f"* ERROR * Parameter {param!r} is not "
|
| 325 |
+
"a valid `caprieval` parameter"
|
| 326 |
+
)
|
| 327 |
+
else:
|
| 328 |
+
if param.endswith("fname"): # using full path for files
|
| 329 |
+
rel_path = Path(kwargs[param])
|
| 330 |
+
_param = rel_path.resolve()
|
| 331 |
+
kwargs[param] = _param
|
| 332 |
+
capri_dict[param] = kwargs[param]
|
| 333 |
+
log.info(f"setting {param} to {kwargs[param]}")
|
| 334 |
+
|
| 335 |
+
return capri_dict
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def update_paths_in_capri_dict(
|
| 339 |
+
capri_dict: ParamDict, target_path: FilePath
|
| 340 |
+
) -> ParamDict:
|
| 341 |
+
"""
|
| 342 |
+
Make capri_dict specific to target_path.
|
| 343 |
+
|
| 344 |
+
Parameters
|
| 345 |
+
----------
|
| 346 |
+
capri_dict : dict
|
| 347 |
+
capri dictionary of parameters
|
| 348 |
+
target_path : Path
|
| 349 |
+
path to the output folder
|
| 350 |
+
|
| 351 |
+
Returns
|
| 352 |
+
-------
|
| 353 |
+
new_capri_dict : dict
|
| 354 |
+
target_path-specific capri dictionary of parameters
|
| 355 |
+
"""
|
| 356 |
+
new_capri_dict = capri_dict.copy()
|
| 357 |
+
for key in new_capri_dict:
|
| 358 |
+
if key.endswith("fname") and new_capri_dict[key] not in ["", None]:
|
| 359 |
+
try:
|
| 360 |
+
ref_path = Path(target_path, "reference.pdb")
|
| 361 |
+
shutil.copy(new_capri_dict[key], ref_path)
|
| 362 |
+
new_capri_dict[key] = Path("reference.pdb")
|
| 363 |
+
except FileNotFoundError:
|
| 364 |
+
sys.exit(f"file not found {new_capri_dict[key]}")
|
| 365 |
+
return new_capri_dict
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
def get_top_ranked_mapping(
|
| 369 |
+
capri_filename: FilePath,
|
| 370 |
+
cluster_ranking: ClRank,
|
| 371 |
+
clustered_topX: int = 4,
|
| 372 |
+
unclustered_topX: int = 10,
|
| 373 |
+
) -> dict[Path, Path]:
|
| 374 |
+
"""Obtain mapping of top ranked files to their future paths.
|
| 375 |
+
|
| 376 |
+
Parameters
|
| 377 |
+
----------
|
| 378 |
+
capri_filename : FilePath
|
| 379 |
+
capri_ss.tsv filepath
|
| 380 |
+
cluster_ranking : ClRank
|
| 381 |
+
Cluster ranking, if the form of {cluster_id: cluster_rank} dictionary
|
| 382 |
+
clustered_topX : int, optional
|
| 383 |
+
Number of models to access per cluster. Default is 4.
|
| 384 |
+
unclustered_topX : int, optional
|
| 385 |
+
Number of unclustered models to access. Default is 10.
|
| 386 |
+
|
| 387 |
+
Returns
|
| 388 |
+
-------
|
| 389 |
+
top_ranked_mapping : dict[Path, Path]
|
| 390 |
+
Mapping between original filepath and new (future) one
|
| 391 |
+
"""
|
| 392 |
+
# Set mapping of generated files
|
| 393 |
+
top_ranked_mapping: dict[Path, Path] = {}
|
| 394 |
+
|
| 395 |
+
# Read table
|
| 396 |
+
capri_df = read_capri_table(capri_filename, comment="#")
|
| 397 |
+
# Group by clusters
|
| 398 |
+
gb_cluster = capri_df.groupby("cluster_id")
|
| 399 |
+
|
| 400 |
+
# Loop over clusters
|
| 401 |
+
for cl_id, cl_df in gb_cluster:
|
| 402 |
+
# Filter only top clusters
|
| 403 |
+
if cl_id in cluster_ranking.keys():
|
| 404 |
+
# If clustered structure
|
| 405 |
+
if cl_id != "-":
|
| 406 |
+
# Retrieve only top 4 models per cluster
|
| 407 |
+
structs = cl_df.loc[cl_df["model-cluster_ranking"] <= clustered_topX][["model", "model-cluster_ranking"]] # noqa : E501
|
| 408 |
+
# If un-clustered structures
|
| 409 |
+
else:
|
| 410 |
+
# Retrieve top 10
|
| 411 |
+
structs = cl_df.loc[cl_df["caprieval_rank"] <= unclustered_topX][["model", "caprieval_rank"]] # noqa : E501
|
| 412 |
+
# Rename columns to access them using same keywords
|
| 413 |
+
structs.columns = ["model", "rank"]
|
| 414 |
+
# iterate over the structures
|
| 415 |
+
for _, row in structs.iterrows():
|
| 416 |
+
# Point rank
|
| 417 |
+
rank = row["rank"]
|
| 418 |
+
# set target name
|
| 419 |
+
if cl_id != "-":
|
| 420 |
+
# Give it its cluster name
|
| 421 |
+
target_name = (
|
| 422 |
+
f"cluster_{cluster_ranking[cl_id]}"
|
| 423 |
+
f"_model_{rank}.pdb"
|
| 424 |
+
)
|
| 425 |
+
else:
|
| 426 |
+
# Give it its rank name
|
| 427 |
+
target_name = f"model_{rank}.pdb"
|
| 428 |
+
|
| 429 |
+
# Generate structure path
|
| 430 |
+
struct = Path(row["model"])
|
| 431 |
+
struct_gz = Path(f"{struct}.gz")
|
| 432 |
+
# copy the structure
|
| 433 |
+
if Path(struct).exists():
|
| 434 |
+
top_ranked_mapping[struct] = Path(target_name)
|
| 435 |
+
elif struct_gz.exists():
|
| 436 |
+
top_ranked_mapping[struct_gz] = Path(target_name)
|
| 437 |
+
else:
|
| 438 |
+
log.warning(f"structure {struct} not found")
|
| 439 |
+
return top_ranked_mapping
|
| 440 |
+
|
| 441 |
+
def zip_top_ranked(
|
| 442 |
+
top_ranked_mapping: dict[Path, Path],
|
| 443 |
+
summary_name: str,
|
| 444 |
+
gen_archive: bool,
|
| 445 |
+
) -> Optional[Path]:
|
| 446 |
+
"""
|
| 447 |
+
Zip the top ranked structures.
|
| 448 |
+
|
| 449 |
+
Parameters
|
| 450 |
+
----------
|
| 451 |
+
capri_filename : str or Path
|
| 452 |
+
capri ss filename
|
| 453 |
+
cluster_ranking : dict
|
| 454 |
+
{cluster_id : cluster_rank} dictionary
|
| 455 |
+
summary_name: str
|
| 456 |
+
Base name of the archive to be generated
|
| 457 |
+
gen_archive: bool
|
| 458 |
+
Should the archive be generated?
|
| 459 |
+
clustered_topX: int
|
| 460 |
+
Number of models to access per cluster. Default is 4.
|
| 461 |
+
unclustered_topX: int
|
| 462 |
+
Number of models to access when no clusters. Default is 10.
|
| 463 |
+
|
| 464 |
+
Return
|
| 465 |
+
------
|
| 466 |
+
output_fname : Optional[Path]
|
| 467 |
+
Path to the generated output. Can be a .tgz archive or a directory.
|
| 468 |
+
"""
|
| 469 |
+
for ori_fpath, new_name in top_ranked_mapping.items():
|
| 470 |
+
# If already compressed
|
| 471 |
+
if ori_fpath.suffix == ".gz":
|
| 472 |
+
copied_fpath = Path(shutil.copy(ori_fpath, "."))
|
| 473 |
+
# unpack the file
|
| 474 |
+
_unpack_gz(copied_fpath)
|
| 475 |
+
# Rename it
|
| 476 |
+
shutil.move(copied_fpath.name.replace(".gz", ""), new_name)
|
| 477 |
+
else:
|
| 478 |
+
shutil.copy(ori_fpath, new_name)
|
| 479 |
+
|
| 480 |
+
# Compress pdb files
|
| 481 |
+
if gen_archive:
|
| 482 |
+
archive_was_created = archive_files_ext(".", "pdb")
|
| 483 |
+
# Delete the pdb files
|
| 484 |
+
for file_ in top_ranked_mapping.values():
|
| 485 |
+
Path(file_).unlink()
|
| 486 |
+
output_fname = Path(f"{summary_name}.tgz")
|
| 487 |
+
if archive_was_created:
|
| 488 |
+
# move archive to summary
|
| 489 |
+
shutil.move("pdb.tgz", output_fname)
|
| 490 |
+
log.info(f"Top structures summary archive {output_fname} created!")
|
| 491 |
+
return
|
| 492 |
+
else:
|
| 493 |
+
log.warning(f"Summary archive {output_fname} not created!")
|
| 494 |
+
return None
|
| 495 |
+
# Generate a directory holding all the structures
|
| 496 |
+
else:
|
| 497 |
+
output_fname = Path(summary_name)
|
| 498 |
+
output_fname.mkdir(parents=True, exist_ok=True)
|
| 499 |
+
for ori_fpath, new_name in top_ranked_mapping.items():
|
| 500 |
+
# Create new path
|
| 501 |
+
next_filepath = Path(output_fname, str(new_name))
|
| 502 |
+
# Hold it in mapping dict
|
| 503 |
+
top_ranked_mapping[ori_fpath] = Path(next_filepath)
|
| 504 |
+
# Displace file
|
| 505 |
+
shutil.move(new_name, top_ranked_mapping[ori_fpath])
|
| 506 |
+
log.info(f"Top structures copied into {output_fname}!")
|
| 507 |
+
return output_fname
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
def analyse_step(
|
| 511 |
+
step: str,
|
| 512 |
+
run_dir: FilePath,
|
| 513 |
+
capri_dict: ParamDict,
|
| 514 |
+
target_path: Path,
|
| 515 |
+
top_clusters: int,
|
| 516 |
+
format: Optional[ImgFormat],
|
| 517 |
+
scale: Optional[float],
|
| 518 |
+
is_cleaned: Optional[bool],
|
| 519 |
+
offline: bool = False,
|
| 520 |
+
mode: str = "local",
|
| 521 |
+
ncores: int = 4,
|
| 522 |
+
self_contained: bool = False,
|
| 523 |
+
clustered_topX: int = 4,
|
| 524 |
+
unclustered_topX: int = 10,
|
| 525 |
+
) -> None:
|
| 526 |
+
"""
|
| 527 |
+
Analyse a step.
|
| 528 |
+
|
| 529 |
+
If the step is a caprieval step, use the available capri files.
|
| 530 |
+
Otherwise, launch a capri analysis.
|
| 531 |
+
|
| 532 |
+
Parameters
|
| 533 |
+
----------
|
| 534 |
+
step : str
|
| 535 |
+
step name
|
| 536 |
+
run_dir : str or Path
|
| 537 |
+
path to run directory
|
| 538 |
+
capri_dict : dict
|
| 539 |
+
capri dictionary of parameters
|
| 540 |
+
target_path : Path
|
| 541 |
+
path to the output folder
|
| 542 |
+
top_clusters : int
|
| 543 |
+
Number of clusters to be considered
|
| 544 |
+
format : str
|
| 545 |
+
Produce images in the selected format.
|
| 546 |
+
scale : int
|
| 547 |
+
scale for images.
|
| 548 |
+
is_cleaned: bool
|
| 549 |
+
is the directory going to be cleaned?
|
| 550 |
+
offline: bool
|
| 551 |
+
Should plots js functions be self-contained?
|
| 552 |
+
mode: str
|
| 553 |
+
mode of execution
|
| 554 |
+
ncores: int
|
| 555 |
+
number of cores to use
|
| 556 |
+
self_contained : bool
|
| 557 |
+
Should the analysis directory contain the models?
|
| 558 |
+
clustered_topX: int
|
| 559 |
+
Number of models to access per cluster. Default is 4.
|
| 560 |
+
unclustered_topX: int
|
| 561 |
+
Number of models to access when no clusters. Default is 10.
|
| 562 |
+
"""
|
| 563 |
+
log.info(f"Analysing step {step}")
|
| 564 |
+
# Create directory
|
| 565 |
+
target_path.mkdir(parents=True, exist_ok=False)
|
| 566 |
+
# Build caprieval output file names/paths
|
| 567 |
+
ss_filename = Path("capri_ss.tsv")
|
| 568 |
+
clt_filename = Path("capri_clt.tsv")
|
| 569 |
+
step_name = step.split("_")[1]
|
| 570 |
+
ss_fname = Path(run_dir, f"{step}/{ss_filename}")
|
| 571 |
+
clt_fname = Path(run_dir, f"{step}/{clt_filename}")
|
| 572 |
+
# Search for caprieval output files
|
| 573 |
+
if step_name != "caprieval":
|
| 574 |
+
if ss_fname.exists() and clt_fname.exists():
|
| 575 |
+
log.info(f"step {step} has caprieval data, files are available")
|
| 576 |
+
run_capri = False
|
| 577 |
+
else:
|
| 578 |
+
capri_dict = update_paths_in_capri_dict(capri_dict, target_path)
|
| 579 |
+
run_capri = True
|
| 580 |
+
else:
|
| 581 |
+
log.info(f"step {step} is caprieval, files should be already available")
|
| 582 |
+
run_capri = False
|
| 583 |
+
|
| 584 |
+
# If caprieval data available, just copy them
|
| 585 |
+
if not run_capri:
|
| 586 |
+
shutil.copy(ss_fname, target_path)
|
| 587 |
+
shutil.copy(clt_fname, target_path)
|
| 588 |
+
|
| 589 |
+
# Go to directory where to write all the analysis figures / report
|
| 590 |
+
os.chdir(target_path)
|
| 591 |
+
# if the step is not caprieval, caprieval must be run
|
| 592 |
+
if run_capri:
|
| 593 |
+
run_capri_analysis(step, run_dir, capri_dict, is_cleaned, mode, ncores)
|
| 594 |
+
|
| 595 |
+
log.info("CAPRI files identified")
|
| 596 |
+
# plotting
|
| 597 |
+
|
| 598 |
+
if clt_filename.exists():
|
| 599 |
+
cluster_ranking = get_cluster_ranking(clt_filename, top_clusters)
|
| 600 |
+
else:
|
| 601 |
+
raise Exception(f"clustering file {clt_filename} does not exist")
|
| 602 |
+
if ss_filename.exists():
|
| 603 |
+
# Generate file mapping for top ranked structures
|
| 604 |
+
top_ranked_mapping = get_top_ranked_mapping(
|
| 605 |
+
ss_filename,
|
| 606 |
+
cluster_ranking,
|
| 607 |
+
clustered_topX=clustered_topX,
|
| 608 |
+
unclustered_topX=unclustered_topX,
|
| 609 |
+
)
|
| 610 |
+
# provide a zipped archive of the top ranked structures
|
| 611 |
+
zip_top_ranked(
|
| 612 |
+
top_ranked_mapping,
|
| 613 |
+
"summary",
|
| 614 |
+
not self_contained,
|
| 615 |
+
)
|
| 616 |
+
log.info("Plotting results..")
|
| 617 |
+
scatters = scatter_plot_handler(
|
| 618 |
+
ss_filename,
|
| 619 |
+
cluster_ranking,
|
| 620 |
+
format,
|
| 621 |
+
scale,
|
| 622 |
+
offline=offline,
|
| 623 |
+
)
|
| 624 |
+
boxes = box_plot_handler(
|
| 625 |
+
ss_filename,
|
| 626 |
+
cluster_ranking,
|
| 627 |
+
format,
|
| 628 |
+
scale,
|
| 629 |
+
offline=offline,
|
| 630 |
+
)
|
| 631 |
+
tables = clt_table_handler(
|
| 632 |
+
clt_filename,
|
| 633 |
+
ss_filename,
|
| 634 |
+
is_cleaned,
|
| 635 |
+
topX_clusters=top_clusters,
|
| 636 |
+
clustered_topX=clustered_topX,
|
| 637 |
+
unclustered_topX=unclustered_topX,
|
| 638 |
+
top_ranked_mapping=top_ranked_mapping if self_contained else None,
|
| 639 |
+
)
|
| 640 |
+
report_generator(boxes, scatters, tables, step, ".", offline)
|
| 641 |
+
|
| 642 |
+
|
| 643 |
+
def validate_format(_format: Optional[ImgFormat]) -> Optional[ImgFormat]:
|
| 644 |
+
"""Validate the optional argument `format`.
|
| 645 |
+
|
| 646 |
+
Parameters
|
| 647 |
+
----------
|
| 648 |
+
_format : Optional[ImgFormat]
|
| 649 |
+
A optential output format set by the user.
|
| 650 |
+
|
| 651 |
+
Returns
|
| 652 |
+
-------
|
| 653 |
+
Optional[ImgFormat]
|
| 654 |
+
A valid output format for the figures to be generated.
|
| 655 |
+
|
| 656 |
+
Raises
|
| 657 |
+
------
|
| 658 |
+
ImportError
|
| 659 |
+
When the kaleido package is not installed.
|
| 660 |
+
ValueError
|
| 661 |
+
When the export format is not supported by plotly / kaleido.
|
| 662 |
+
"""
|
| 663 |
+
# Optional, so if not defined, return _format (None)
|
| 664 |
+
if not _format:
|
| 665 |
+
return _format
|
| 666 |
+
# Make sure it is lower case
|
| 667 |
+
format = _format.lower()
|
| 668 |
+
# Check if part of supported output formats
|
| 669 |
+
if format in SUPPORTED_OUTPUT_FORMATS:
|
| 670 |
+
# Make sure the `kaleido` package is installed
|
| 671 |
+
try:
|
| 672 |
+
import kaleido # noqa : F401
|
| 673 |
+
except ImportError:
|
| 674 |
+
raise ImportError(
|
| 675 |
+
f"Exporting with format {format} requires the use of `kaleido`"
|
| 676 |
+
f" package, that seems not to be installed. {os.linesep}"
|
| 677 |
+
"Please install it with: `pip install kaleido==0.2.*`"
|
| 678 |
+
)
|
| 679 |
+
# At this stage, everything should go smooth with the export format
|
| 680 |
+
else:
|
| 681 |
+
# Return supported format
|
| 682 |
+
return format
|
| 683 |
+
# Raise error if unsupported format
|
| 684 |
+
raise ValueError(
|
| 685 |
+
f"Format `{format}` is not supported.{os.linesep}"
|
| 686 |
+
f"Supported formats: {SUPPORTED_OUTPUT_FORMATS}."
|
| 687 |
+
)
|
| 688 |
+
|
| 689 |
+
|
| 690 |
+
def main(
|
| 691 |
+
run_dir: FilePath,
|
| 692 |
+
modules: list[int],
|
| 693 |
+
top_clusters: int,
|
| 694 |
+
format: Optional[ImgFormat],
|
| 695 |
+
scale: Optional[float],
|
| 696 |
+
inter: Optional[bool],
|
| 697 |
+
is_cleaned: Optional[bool],
|
| 698 |
+
offline: bool = False,
|
| 699 |
+
mode: Optional[str] = None,
|
| 700 |
+
ncores: Optional[int] = None,
|
| 701 |
+
self_contained: bool = False,
|
| 702 |
+
**kwargs: Any,
|
| 703 |
+
) -> None:
|
| 704 |
+
"""
|
| 705 |
+
Analyse CLI.
|
| 706 |
+
|
| 707 |
+
Parameters
|
| 708 |
+
----------
|
| 709 |
+
run_dir : str or Path
|
| 710 |
+
Path to the original run directory.
|
| 711 |
+
modules : list of ints
|
| 712 |
+
List of the integer prefix of the modules to copy.
|
| 713 |
+
top_clusters : int
|
| 714 |
+
Number of clusters to be considered.
|
| 715 |
+
format : str
|
| 716 |
+
Produce images in the selected format.
|
| 717 |
+
scale : int
|
| 718 |
+
scale for images.
|
| 719 |
+
inter: bool
|
| 720 |
+
analyse only steps labelled as 'interactive'
|
| 721 |
+
is_cleaned: bool
|
| 722 |
+
is the directory going to be cleaned?
|
| 723 |
+
offline: bool
|
| 724 |
+
Should plots js functions be self-contained?
|
| 725 |
+
mode: str
|
| 726 |
+
mode of execution
|
| 727 |
+
ncores: int
|
| 728 |
+
number of cores to use
|
| 729 |
+
self_contained : bool
|
| 730 |
+
Should the analysis directory contain the models?
|
| 731 |
+
"""
|
| 732 |
+
log.level = 20
|
| 733 |
+
log.info(
|
| 734 |
+
f"Running haddock3-analyse on {run_dir}, modules {modules}, "
|
| 735 |
+
f"with top_clusters = {top_clusters}"
|
| 736 |
+
)
|
| 737 |
+
# Validate output format
|
| 738 |
+
format = validate_format(format)
|
| 739 |
+
|
| 740 |
+
# Obtain starting working directory
|
| 741 |
+
ori_cwd = os.getcwd()
|
| 742 |
+
# modifying the parameters
|
| 743 |
+
default_capri = read_from_yaml_config(caprieval_params)
|
| 744 |
+
capri_dict = update_capri_dict(default_capri, kwargs)
|
| 745 |
+
|
| 746 |
+
os.chdir(run_dir)
|
| 747 |
+
# Create analysis folder
|
| 748 |
+
rundir_cwd = os.getcwd()
|
| 749 |
+
outdir = Path(ANA_FOLDER)
|
| 750 |
+
try:
|
| 751 |
+
outdir.mkdir(exist_ok=False)
|
| 752 |
+
log.info(f"Created directory: {str(outdir.resolve())}")
|
| 753 |
+
except FileExistsError:
|
| 754 |
+
log.warning(f"Directory {str(outdir.resolve())} already exists.")
|
| 755 |
+
|
| 756 |
+
# Reading steps
|
| 757 |
+
log.info("Reading input run directory")
|
| 758 |
+
# get the module folders from the run_dir input
|
| 759 |
+
sel_steps = get_module_steps_folders(Path("./"), modules)
|
| 760 |
+
if inter:
|
| 761 |
+
sel_steps = [st for st in sel_steps if st.endswith(INTER_STR)]
|
| 762 |
+
else:
|
| 763 |
+
sel_steps = [st for st in sel_steps if not st.endswith(INTER_STR)]
|
| 764 |
+
log.info(f"selected steps: {', '.join(sel_steps)}")
|
| 765 |
+
|
| 766 |
+
# analysis
|
| 767 |
+
good_folder_paths: list[Path] = []
|
| 768 |
+
bad_folder_paths: list[Path] = []
|
| 769 |
+
for step in sel_steps:
|
| 770 |
+
subfolder_name = f"{step}_analysis"
|
| 771 |
+
target_path = Path(subfolder_name)
|
| 772 |
+
|
| 773 |
+
# check if subfolder is already present
|
| 774 |
+
dest_path = Path(ANA_FOLDER, subfolder_name)
|
| 775 |
+
if dest_path.exists():
|
| 776 |
+
if len(os.listdir(dest_path)) != 0 and not inter:
|
| 777 |
+
log.warning(
|
| 778 |
+
f"{dest_path} exists and is not empty. "
|
| 779 |
+
"Skipping analysis..."
|
| 780 |
+
)
|
| 781 |
+
continue
|
| 782 |
+
else: # subfolder is empty or is interactive, remove it.
|
| 783 |
+
log.info(f"Removing folder {dest_path}.")
|
| 784 |
+
shutil.rmtree(dest_path)
|
| 785 |
+
|
| 786 |
+
# run the analysis
|
| 787 |
+
try:
|
| 788 |
+
analyse_step(
|
| 789 |
+
step,
|
| 790 |
+
Path("./"),
|
| 791 |
+
capri_dict,
|
| 792 |
+
target_path,
|
| 793 |
+
top_clusters,
|
| 794 |
+
format,
|
| 795 |
+
scale,
|
| 796 |
+
is_cleaned,
|
| 797 |
+
offline=offline,
|
| 798 |
+
mode=mode,
|
| 799 |
+
ncores=ncores,
|
| 800 |
+
self_contained=self_contained,
|
| 801 |
+
)
|
| 802 |
+
except Exception as e:
|
| 803 |
+
log.warning(
|
| 804 |
+
f"Could not execute the analysis for step {step}. "
|
| 805 |
+
f"The following error occurred: {e}"
|
| 806 |
+
)
|
| 807 |
+
bad_folder_paths.append(target_path)
|
| 808 |
+
else:
|
| 809 |
+
good_folder_paths.append(target_path)
|
| 810 |
+
|
| 811 |
+
# going back
|
| 812 |
+
os.chdir(rundir_cwd)
|
| 813 |
+
|
| 814 |
+
# moving files into analysis folder
|
| 815 |
+
if good_folder_paths != []:
|
| 816 |
+
log.info("moving files to analysis folder")
|
| 817 |
+
urls: list[str] = []
|
| 818 |
+
for directory in good_folder_paths:
|
| 819 |
+
shutil.move(directory, outdir)
|
| 820 |
+
url = f"- [{Path(directory, 'report.html')}](http://0.0.0.0:8000/{Path(directory, 'report.html')}) " # noqa : E501
|
| 821 |
+
urls.append(url)
|
| 822 |
+
|
| 823 |
+
# Adding instructions on how to setup the server
|
| 824 |
+
readme_fpath = Path(outdir, "README.md")
|
| 825 |
+
readme_fpath.write_text(
|
| 826 |
+
f"# Usage{os.linesep}{os.linesep}"
|
| 827 |
+
"To view structures or download the structure files, "
|
| 828 |
+
f"in a terminal run the command:{os.linesep}```bash{os.linesep}"
|
| 829 |
+
f"python -m http.server --directory .{os.linesep}```{os.linesep}"
|
| 830 |
+
f"And open the link following links in a web browser:{os.linesep}"
|
| 831 |
+
f"{os.linesep.join(urls)}{os.linesep}"
|
| 832 |
+
)
|
| 833 |
+
assert readme_fpath.exists()
|
| 834 |
+
|
| 835 |
+
if bad_folder_paths != []:
|
| 836 |
+
log.info("cancelling unsuccesful analysis folders")
|
| 837 |
+
for directory in bad_folder_paths:
|
| 838 |
+
if directory.exists():
|
| 839 |
+
shutil.rmtree(directory)
|
| 840 |
+
|
| 841 |
+
# substituting the correct paths in the capri_ss files
|
| 842 |
+
# after moving files into analysis folder
|
| 843 |
+
for directory in good_folder_paths:
|
| 844 |
+
ss_file = Path(outdir, directory, "capri_ss.tsv")
|
| 845 |
+
if ss_file.exists():
|
| 846 |
+
log.info(f"updating paths in {ss_file}")
|
| 847 |
+
update_paths(ss_file, "../", "../../")
|
| 848 |
+
report_file = Path(outdir, directory, "report.html")
|
| 849 |
+
log.info(f"View the results in {report_file}")
|
| 850 |
+
info_msg = (
|
| 851 |
+
"To view structures or download the structure files, "
|
| 852 |
+
f"in a terminal run the command: {os.linesep}"
|
| 853 |
+
f">python -m http.server --directory {rundir_cwd}{os.linesep}"
|
| 854 |
+
# "By default, http server runs on `http://0.0.0.0:8000/`. "
|
| 855 |
+
f"And open the link http://0.0.0.0:8000/{report_file} "
|
| 856 |
+
"in a web browser."
|
| 857 |
+
)
|
| 858 |
+
log.info(info_msg)
|
| 859 |
+
os.chdir(ori_cwd)
|
| 860 |
+
return
|
| 861 |
+
|
| 862 |
+
|
| 863 |
+
if __name__ == "__main__":
|
| 864 |
+
sys.exit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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Extract the default configuration file for each module.
|
| 3 |
+
|
| 4 |
+
By default presents the parameters from the three expertise levels:
|
| 5 |
+
`basic`, `intermediate`, and `guru`.
|
| 6 |
+
|
| 7 |
+
Usage::
|
| 8 |
+
|
| 9 |
+
haddock3-cfg # prints only the general parametes
|
| 10 |
+
haddock3-cfg -g # same as above
|
| 11 |
+
haddock3-cfg -m MODULE # prints only the module parameters
|
| 12 |
+
haddock3-cfg -m MODULE -l LEVEL
|
| 13 |
+
haddock3-cfg -m topoaa -l all
|
| 14 |
+
haddock3-cfg -m rigidbody -l all -g # prints the module and the globals
|
| 15 |
+
"""
|
| 16 |
+
import argparse
|
| 17 |
+
import importlib
|
| 18 |
+
import os
|
| 19 |
+
import sys
|
| 20 |
+
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
from haddock import config_expert_levels, core_path
|
| 24 |
+
from haddock.core.typing import (
|
| 25 |
+
ArgumentParser,
|
| 26 |
+
Callable,
|
| 27 |
+
ExpertLevel,
|
| 28 |
+
Namespace,
|
| 29 |
+
Optional,
|
| 30 |
+
)
|
| 31 |
+
from haddock.modules import modules_category
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
ap = argparse.ArgumentParser(
|
| 35 |
+
prog="HADDOCK3 config retriever",
|
| 36 |
+
description=__doc__,
|
| 37 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
ap.add_argument(
|
| 41 |
+
"-m",
|
| 42 |
+
dest="module",
|
| 43 |
+
help="The module for which you want to retrieve the default configuration.",
|
| 44 |
+
choices=sorted(modules_category.keys()),
|
| 45 |
+
default=None,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
ap.add_argument(
|
| 49 |
+
"-l",
|
| 50 |
+
dest="explevel",
|
| 51 |
+
required=False,
|
| 52 |
+
help='The expertise level of the parameters. Defaults to "all".',
|
| 53 |
+
default="all",
|
| 54 |
+
choices=config_expert_levels + ("all",),
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
ap.add_argument(
|
| 58 |
+
"-g",
|
| 59 |
+
"--globals",
|
| 60 |
+
dest="global_params",
|
| 61 |
+
help="Add also the optional module's general parameters.",
|
| 62 |
+
action="store_true",
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
ap.add_argument(
|
| 66 |
+
"-d",
|
| 67 |
+
"--details",
|
| 68 |
+
dest="details",
|
| 69 |
+
help="Add detailed parameter description found in 'long'.",
|
| 70 |
+
action="store_true",
|
| 71 |
+
default=False,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _ap() -> ArgumentParser:
|
| 76 |
+
return ap
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
# command-line client helper functions
|
| 80 |
+
# load_args, cli, maincli
|
| 81 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 82 |
+
"""Load argument parser args."""
|
| 83 |
+
return ap.parse_args()
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 87 |
+
"""Command-line interface entry point."""
|
| 88 |
+
cmd = load_args(ap)
|
| 89 |
+
|
| 90 |
+
# I didn't want to to have the `--globals` param as a negative parameter
|
| 91 |
+
# ('store_false'). However, `module` and `globals` can't both be false.
|
| 92 |
+
# In order for the commands below performing the same:
|
| 93 |
+
#
|
| 94 |
+
# haddock3-cfg
|
| 95 |
+
# haddock3-cfg -g
|
| 96 |
+
#
|
| 97 |
+
# we need this quick if statement. Which basically adjust the argparse to
|
| 98 |
+
# the default values in the main function.
|
| 99 |
+
# @joaomcteixeira
|
| 100 |
+
if cmd.global_params is False and cmd.module is None:
|
| 101 |
+
cmd.global_params = True
|
| 102 |
+
|
| 103 |
+
main(**vars(cmd))
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def maincli() -> None:
|
| 107 |
+
"""Execute main client."""
|
| 108 |
+
cli(ap, main)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def main(
|
| 112 |
+
module: Optional[str] = None,
|
| 113 |
+
explevel: str = "all",
|
| 114 |
+
global_params: bool = True,
|
| 115 |
+
details: bool = False,
|
| 116 |
+
) -> None:
|
| 117 |
+
"""
|
| 118 |
+
Extract the defaults in the form of a run configuration file.
|
| 119 |
+
|
| 120 |
+
Parameters
|
| 121 |
+
----------
|
| 122 |
+
module : str or None
|
| 123 |
+
The module name to extract the defaults from.
|
| 124 |
+
If ``None`` given, we expect ``global_params`` to be ``True``,
|
| 125 |
+
otherwise nothing will be printed.
|
| 126 |
+
|
| 127 |
+
explevel : str
|
| 128 |
+
Filter the parameters according to the expert level. Output all
|
| 129 |
+
parameters that belong to the referred level or below. Choices
|
| 130 |
+
are: all, easy, expert, and guru.
|
| 131 |
+
|
| 132 |
+
global_params : bool
|
| 133 |
+
Whether to add the module's general global parameter. If
|
| 134 |
+
``True`` and ``module`` is ``None``, outputs only the general
|
| 135 |
+
parameters.
|
| 136 |
+
|
| 137 |
+
details : bool
|
| 138 |
+
Whether to add the 'long' description of each parameter.
|
| 139 |
+
"""
|
| 140 |
+
from haddock import modules_defaults_path
|
| 141 |
+
from haddock.gear.yaml2cfg import yaml2cfg_text
|
| 142 |
+
from haddock.libs.libio import read_from_yaml
|
| 143 |
+
|
| 144 |
+
new_config = ""
|
| 145 |
+
|
| 146 |
+
if global_params:
|
| 147 |
+
# Read general parameters
|
| 148 |
+
general_cfg = read_from_yaml(modules_defaults_path)
|
| 149 |
+
general_params_str = yaml2cfg_text(
|
| 150 |
+
general_cfg,
|
| 151 |
+
module=None,
|
| 152 |
+
explevel="all",
|
| 153 |
+
details=details,
|
| 154 |
+
)
|
| 155 |
+
general_comment = os.linesep.join(
|
| 156 |
+
(
|
| 157 |
+
"#" * 50,
|
| 158 |
+
"# The parameters below are optional parameters. ",
|
| 159 |
+
"# They can either be used as global parameters or as part ",
|
| 160 |
+
"# of the module's parameters",
|
| 161 |
+
"#" * 50,
|
| 162 |
+
)
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
# Read mandatory parmeters
|
| 166 |
+
mandatory_cfg_path = Path(core_path, "mandatory.yaml")
|
| 167 |
+
general_mandatory_cfg = read_from_yaml(mandatory_cfg_path)
|
| 168 |
+
general_mandatory_params_str = yaml2cfg_text(
|
| 169 |
+
general_mandatory_cfg,
|
| 170 |
+
module=None,
|
| 171 |
+
explevel="all",
|
| 172 |
+
details=details,
|
| 173 |
+
mandatory_param=True,
|
| 174 |
+
)
|
| 175 |
+
mandatory_comment = os.linesep.join(
|
| 176 |
+
(
|
| 177 |
+
"#" * 50,
|
| 178 |
+
"# The parameters below are mandatory parameters.",
|
| 179 |
+
"# They must be specified in your configuration file!",
|
| 180 |
+
"#" * 50,
|
| 181 |
+
)
|
| 182 |
+
)
|
| 183 |
+
|
| 184 |
+
# Read optional parameters
|
| 185 |
+
optional_cfg_path = Path(core_path, "optional.yaml")
|
| 186 |
+
general_optional_cfg = read_from_yaml(optional_cfg_path)
|
| 187 |
+
general_optional_params_str = yaml2cfg_text(
|
| 188 |
+
general_optional_cfg,
|
| 189 |
+
module=None,
|
| 190 |
+
explevel="all",
|
| 191 |
+
details=details,
|
| 192 |
+
)
|
| 193 |
+
optional_comment = os.linesep.join(
|
| 194 |
+
(
|
| 195 |
+
"#" * 50,
|
| 196 |
+
"# The parameters below are optional global parameters.",
|
| 197 |
+
"#" * 50,
|
| 198 |
+
)
|
| 199 |
+
)
|
| 200 |
+
# Concatenate all of them
|
| 201 |
+
new_config = os.linesep.join(
|
| 202 |
+
(
|
| 203 |
+
mandatory_comment,
|
| 204 |
+
general_mandatory_params_str,
|
| 205 |
+
optional_comment,
|
| 206 |
+
general_optional_params_str,
|
| 207 |
+
general_comment,
|
| 208 |
+
general_params_str,
|
| 209 |
+
)
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
if module:
|
| 213 |
+
module_name = ".".join(
|
| 214 |
+
(
|
| 215 |
+
"haddock",
|
| 216 |
+
"modules",
|
| 217 |
+
modules_category[module],
|
| 218 |
+
module,
|
| 219 |
+
)
|
| 220 |
+
)
|
| 221 |
+
|
| 222 |
+
module_lib = importlib.import_module(module_name)
|
| 223 |
+
cfg = module_lib.DEFAULT_CONFIG
|
| 224 |
+
|
| 225 |
+
ycfg = read_from_yaml(cfg)
|
| 226 |
+
module_config = yaml2cfg_text(ycfg, module, explevel, details=details)
|
| 227 |
+
|
| 228 |
+
new_config = os.linesep.join((new_config, module_config))
|
| 229 |
+
|
| 230 |
+
sys.stdout.write(new_config)
|
| 231 |
+
|
| 232 |
+
return
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
if __name__ == "__main__":
|
| 236 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_clean.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Clean the output of an HADDOCK3 run directory.
|
| 4 |
+
|
| 5 |
+
The clean process performs file archiving and file compressing
|
| 6 |
+
operations.
|
| 7 |
+
|
| 8 |
+
All `.inp` and `.out` files are deleted except for the first one, which
|
| 9 |
+
is compressed to `.gz`. On the other hand, all `.seed` and `.con` files
|
| 10 |
+
are compressed and archived to `.tgz` files. Finally, `.pdb` and `.psf`
|
| 11 |
+
files are compressed to `.gz`.
|
| 12 |
+
|
| 13 |
+
The <run_directory> can either be a whole HADDOCK3 run folder or a
|
| 14 |
+
specific folder of the workflow step. <ncores> defines the number of
|
| 15 |
+
threads to use; by default uses a single core.
|
| 16 |
+
|
| 17 |
+
Usage::
|
| 18 |
+
|
| 19 |
+
haddock3-clean -h
|
| 20 |
+
haddock3-clean <run_directory>
|
| 21 |
+
haddock3-clean run1
|
| 22 |
+
haddock3-clean run1/1_rigidbody
|
| 23 |
+
haddock3-clean run1 -n # uses all cores
|
| 24 |
+
haddock3-clean run1 -n 2 # uses 2 cores
|
| 25 |
+
"""
|
| 26 |
+
import argparse
|
| 27 |
+
import sys
|
| 28 |
+
|
| 29 |
+
from haddock.core.typing import (
|
| 30 |
+
ArgumentParser,
|
| 31 |
+
Callable,
|
| 32 |
+
FilePath,
|
| 33 |
+
Namespace,
|
| 34 |
+
Optional,
|
| 35 |
+
)
|
| 36 |
+
from haddock.libs import libcli
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
# Command line interface parser
|
| 40 |
+
ap = argparse.ArgumentParser(
|
| 41 |
+
description=__doc__,
|
| 42 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
libcli.add_rundir_arg(ap)
|
| 46 |
+
libcli.add_ncores_arg(ap)
|
| 47 |
+
libcli.add_version_arg(ap)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _ap() -> ArgumentParser:
|
| 51 |
+
return ap
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 55 |
+
"""Load argument parser args."""
|
| 56 |
+
return ap.parse_args()
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 60 |
+
"""Command-line interface entry point."""
|
| 61 |
+
cmd = load_args(ap)
|
| 62 |
+
main(**vars(cmd))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def maincli() -> None:
|
| 66 |
+
"""Execute main client."""
|
| 67 |
+
cli(ap, main)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def main(run_dir: FilePath, ncores: Optional[int] = 1) -> None:
|
| 71 |
+
"""
|
| 72 |
+
Clean a HADDOCK3 directory.
|
| 73 |
+
|
| 74 |
+
Usually, this concerns compressing and archiving files (see below).
|
| 75 |
+
|
| 76 |
+
Parameters
|
| 77 |
+
----------
|
| 78 |
+
run_dir : str or :external:py:class:`pathlib.Path`.
|
| 79 |
+
The path to the run directory or to a folder of a specific step
|
| 80 |
+
of the workflow.
|
| 81 |
+
|
| 82 |
+
ncores : int, or None
|
| 83 |
+
The number of cores to use. If ``None``, use all possible threads.
|
| 84 |
+
Defaults to 1.
|
| 85 |
+
|
| 86 |
+
See Also
|
| 87 |
+
--------
|
| 88 |
+
`haddock.gear.clean_steps`
|
| 89 |
+
"""
|
| 90 |
+
# anti-pattern to speed up CLI initiation
|
| 91 |
+
from pathlib import Path
|
| 92 |
+
|
| 93 |
+
from haddock import log
|
| 94 |
+
from haddock.gear.clean_steps import clean_output
|
| 95 |
+
from haddock.libs.libtimer import log_time
|
| 96 |
+
from haddock.libs.libutil import parse_ncores
|
| 97 |
+
from haddock.modules import get_module_steps_folders, is_step_folder
|
| 98 |
+
|
| 99 |
+
log.info(f"Compressing {str(run_dir)!r} folder")
|
| 100 |
+
ncores = parse_ncores(ncores)
|
| 101 |
+
|
| 102 |
+
if is_step_folder(run_dir):
|
| 103 |
+
with log_time("compressing took"):
|
| 104 |
+
clean_output(run_dir, ncores)
|
| 105 |
+
|
| 106 |
+
else:
|
| 107 |
+
step_folders = get_module_steps_folders(run_dir)
|
| 108 |
+
for folder in step_folders:
|
| 109 |
+
with log_time("compressing took"):
|
| 110 |
+
clean_output(Path(run_dir, folder), ncores)
|
| 111 |
+
|
| 112 |
+
return
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_cp.py
ADDED
|
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
| 4 |
+
|
| 5 |
+
In HADDOCK3 you can copy successful steps from a run directory to a new
|
| 6 |
+
directory and use them as starting points for a new run.
|
| 7 |
+
|
| 8 |
+
Considering the example::
|
| 9 |
+
|
| 10 |
+
run1/
|
| 11 |
+
0_topoaa/
|
| 12 |
+
1_rigidbody/
|
| 13 |
+
2_caprieval/
|
| 14 |
+
3_seletop/
|
| 15 |
+
4_flexref/
|
| 16 |
+
(etc...)
|
| 17 |
+
|
| 18 |
+
You can use `4_flexref` step folder as a starting point for a new run.
|
| 19 |
+
|
| 20 |
+
USAGE::
|
| 21 |
+
|
| 22 |
+
haddock3-copy -r <run_dir> -m <num_modules> -o <new_run_dir>
|
| 23 |
+
haddock3-copy -r run1 -m 0 4 -o run2
|
| 24 |
+
|
| 25 |
+
Where, ``-m 0 4`` will copy ``0_topoaa`` and ``4_flexref`` to <new_run_dir>.
|
| 26 |
+
|
| 27 |
+
**Note:** If the new run uses CNS-dependent modules, you **also need**
|
| 28 |
+
to copy the folder corresponding to the initial topology creation (the
|
| 29 |
+
`topoaa` module).
|
| 30 |
+
|
| 31 |
+
`haddock3-copy` will also copy the corresponding files in the `data`
|
| 32 |
+
directory and update the file contents in the copied folder such that
|
| 33 |
+
the information on the run directory and the new step folder names match.
|
| 34 |
+
The output result of the above commands is::
|
| 35 |
+
|
| 36 |
+
run2/
|
| 37 |
+
0_topoaa/
|
| 38 |
+
1_flexref/
|
| 39 |
+
|
| 40 |
+
Following, you can use the `haddock3` command with the `--extend-run`
|
| 41 |
+
option to continue a new run::
|
| 42 |
+
|
| 43 |
+
haddock3 new-config.cfg --extend-run run2
|
| 44 |
+
"""
|
| 45 |
+
import argparse
|
| 46 |
+
import os
|
| 47 |
+
import sys
|
| 48 |
+
|
| 49 |
+
from haddock import log
|
| 50 |
+
from haddock.core.typing import ArgumentParser, Callable, FilePath, Namespace
|
| 51 |
+
from haddock.libs.libcli import add_version_arg
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# Command line interface parser
|
| 55 |
+
ap = argparse.ArgumentParser(
|
| 56 |
+
description=__doc__,
|
| 57 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
ap.add_argument(
|
| 61 |
+
"-r",
|
| 62 |
+
"--run-dir",
|
| 63 |
+
help="The input run directory.",
|
| 64 |
+
required=True,
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
ap.add_argument(
|
| 68 |
+
"-m",
|
| 69 |
+
"--modules",
|
| 70 |
+
nargs="+",
|
| 71 |
+
help="The IDs of the steps to copy (separated by spaces).",
|
| 72 |
+
required=True,
|
| 73 |
+
type=int,
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
ap.add_argument(
|
| 77 |
+
"-o",
|
| 78 |
+
"--output",
|
| 79 |
+
help="The new run directory.",
|
| 80 |
+
required=True,
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
add_version_arg(ap)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _ap() -> ArgumentParser:
|
| 87 |
+
return ap
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 91 |
+
"""Load argument parser args."""
|
| 92 |
+
return ap.parse_args()
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 96 |
+
"""Command-line interface entry point."""
|
| 97 |
+
cmd = load_args(ap)
|
| 98 |
+
main(**vars(cmd))
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def maincli() -> None:
|
| 102 |
+
"""Execute main client."""
|
| 103 |
+
cli(ap, main)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def main(run_dir: FilePath, modules: list[int], output: FilePath) -> None:
|
| 107 |
+
"""
|
| 108 |
+
Copy steps from a run directory to a new run directory.
|
| 109 |
+
|
| 110 |
+
Also updates paths references in step files accordingly.
|
| 111 |
+
|
| 112 |
+
Parameters
|
| 113 |
+
----------
|
| 114 |
+
run_dir : str or Path
|
| 115 |
+
Path to the original run directory.
|
| 116 |
+
|
| 117 |
+
modules : list of ints
|
| 118 |
+
List of the integer prefix of the modules to copy.
|
| 119 |
+
|
| 120 |
+
output : str or Path
|
| 121 |
+
The new run directory to create and where to copy the steps.
|
| 122 |
+
"""
|
| 123 |
+
from pathlib import Path
|
| 124 |
+
|
| 125 |
+
from haddock.gear.clean_steps import unpack_compressed_and_archived_files
|
| 126 |
+
from haddock.gear.extend_run import (
|
| 127 |
+
copy_renum_step_folders,
|
| 128 |
+
update_contents_of_new_steps,
|
| 129 |
+
)
|
| 130 |
+
from haddock.gear.zerofill import zero_fill
|
| 131 |
+
from haddock.modules import get_module_steps_folders
|
| 132 |
+
|
| 133 |
+
log.info("Reading input run directory")
|
| 134 |
+
# get the module folders from the run_dir input
|
| 135 |
+
steps = get_module_steps_folders(run_dir)
|
| 136 |
+
selected_steps = [steps[i] for i in range(len(steps)) if i in modules]
|
| 137 |
+
log.info(f"selected steps: {', '.join(selected_steps)}")
|
| 138 |
+
|
| 139 |
+
# make new run dir
|
| 140 |
+
outdir = Path(output)
|
| 141 |
+
try:
|
| 142 |
+
outdir.mkdir(parents=True, exist_ok=False)
|
| 143 |
+
except FileExistsError:
|
| 144 |
+
log.error(f"Directory {str(outdir.resolve())} already exists.")
|
| 145 |
+
sys.exit(1)
|
| 146 |
+
log.info(f"Created directory: {str(outdir.resolve())}")
|
| 147 |
+
|
| 148 |
+
# copy folders over
|
| 149 |
+
zero_fill.set_zerofill_number(len(selected_steps))
|
| 150 |
+
new_step_folder = copy_renum_step_folders(run_dir, outdir, selected_steps)
|
| 151 |
+
|
| 152 |
+
# copy data folders
|
| 153 |
+
# `data_steps` are selected to avoid FileNotFoundError because some steps
|
| 154 |
+
# do not have a `data` folder.
|
| 155 |
+
# See https://github.com/haddocking/haddock3/issues/559
|
| 156 |
+
data_steps = [
|
| 157 |
+
step for step in selected_steps
|
| 158 |
+
if os.path.exists(Path(run_dir, "data", step))
|
| 159 |
+
]
|
| 160 |
+
copy_renum_step_folders(
|
| 161 |
+
Path(run_dir, "data"),
|
| 162 |
+
Path(outdir, "data"),
|
| 163 |
+
data_steps,
|
| 164 |
+
)
|
| 165 |
+
|
| 166 |
+
# update step names in files
|
| 167 |
+
# update run dir names in files
|
| 168 |
+
unpack_compressed_and_archived_files(
|
| 169 |
+
new_step_folder,
|
| 170 |
+
ncores=1,
|
| 171 |
+
dec_all=True,
|
| 172 |
+
)
|
| 173 |
+
update_contents_of_new_steps(selected_steps, run_dir, outdir)
|
| 174 |
+
|
| 175 |
+
return
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
if __name__ == "__main__":
|
| 179 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_dmn.py
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
r"""
|
| 2 |
+
HADDOCK3 benchmark submission daemon.
|
| 3 |
+
|
| 4 |
+
For more information read our benchmark tutorial at `docs/benchmark.tut`
|
| 5 |
+
in HADDOCK3 repository site: https://github.com/haddocking/haddock3::
|
| 6 |
+
|
| 7 |
+
(_) L|J
|
| 8 |
+
(") |
|
| 9 |
+
/_\--|
|
| 10 |
+
_/\ / |
|
| 11 |
+
_W_ |
|
| 12 |
+
|
| 13 |
+
Usage::
|
| 14 |
+
|
| 15 |
+
haddock3-dmn -h
|
| 16 |
+
haddock3-dmn <benchmark folder> --job-limit <num> [OPTIONS]
|
| 17 |
+
"""
|
| 18 |
+
import argparse
|
| 19 |
+
import os
|
| 20 |
+
import subprocess
|
| 21 |
+
import sys
|
| 22 |
+
import time
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
|
| 25 |
+
from haddock.core.typing import ArgumentParser, Callable, Namespace, Optional
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
workload_manager_launch = {
|
| 29 |
+
"slurm": "sbatch",
|
| 30 |
+
"torque": "qsub",
|
| 31 |
+
}
|
| 32 |
+
"""options for the different job queue systems supported"""
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
# prepares client arguments
|
| 36 |
+
ap = argparse.ArgumentParser(
|
| 37 |
+
prog="HADDOCK3 benchmark submission daemon.",
|
| 38 |
+
description=__doc__,
|
| 39 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 40 |
+
)
|
| 41 |
+
|
| 42 |
+
ap.add_argument(
|
| 43 |
+
"benchmark_path",
|
| 44 |
+
help="Path to the benchmark folder as prepared by `haddock3-bm` interface.",
|
| 45 |
+
type=Path,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
ap.add_argument(
|
| 49 |
+
"--job-limit",
|
| 50 |
+
dest="job_limit",
|
| 51 |
+
help="How many jobs should run at the same time. Default: 10",
|
| 52 |
+
default=10,
|
| 53 |
+
type=int,
|
| 54 |
+
)
|
| 55 |
+
|
| 56 |
+
ap.add_argument(
|
| 57 |
+
"--job-sys",
|
| 58 |
+
dest="manager",
|
| 59 |
+
help="The system where the jobs will be run. Default `slurm`.",
|
| 60 |
+
choices=tuple(workload_manager_launch.keys()),
|
| 61 |
+
default="slurm",
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
ap.add_argument(
|
| 65 |
+
"--restart",
|
| 66 |
+
help="Restart the RUNNING jobs. DONE jobs won't be touched.",
|
| 67 |
+
action="store_true",
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
ap.add_argument(
|
| 71 |
+
"--sort-first",
|
| 72 |
+
dest="sort_first",
|
| 73 |
+
help=(
|
| 74 |
+
"Sort jobs by size in ascending order. If not given jobs are order by "
|
| 75 |
+
"size in descending order: the biggest first."
|
| 76 |
+
),
|
| 77 |
+
action="store_true",
|
| 78 |
+
)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _ap() -> ArgumentParser:
|
| 82 |
+
return ap
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class Job:
|
| 86 |
+
"""
|
| 87 |
+
Job task.
|
| 88 |
+
|
| 89 |
+
Controls the status of each job.
|
| 90 |
+
|
| 91 |
+
Parameters
|
| 92 |
+
----------
|
| 93 |
+
job_f : pathlib.Path
|
| 94 |
+
The path to the job file.
|
| 95 |
+
|
| 96 |
+
launch_command : str
|
| 97 |
+
The command to launch the job. For example `sbatch`.
|
| 98 |
+
"""
|
| 99 |
+
|
| 100 |
+
def __init__(self, job_f: Path, launch_command: str) -> None:
|
| 101 |
+
self.job_filename = job_f
|
| 102 |
+
|
| 103 |
+
self.launch_command = launch_command
|
| 104 |
+
|
| 105 |
+
# previous jog path
|
| 106 |
+
job_stem = job_f.stem
|
| 107 |
+
self.job_run_folder = Path(job_f.parents[1], f"run-{job_stem}")
|
| 108 |
+
|
| 109 |
+
self.check_done = Path(self.job_run_folder, "DONE")
|
| 110 |
+
self.check_running = Path(self.job_run_folder, "RUNNING")
|
| 111 |
+
self.check_available = Path(self.job_run_folder, "AVAILABLE")
|
| 112 |
+
self.check_fail = Path(self.job_run_folder, "FAIL")
|
| 113 |
+
self.status = None
|
| 114 |
+
|
| 115 |
+
self.status_files = [
|
| 116 |
+
self.check_done,
|
| 117 |
+
self.check_running,
|
| 118 |
+
self.check_fail,
|
| 119 |
+
self.check_available,
|
| 120 |
+
]
|
| 121 |
+
|
| 122 |
+
def get_status(self) -> Optional[str]:
|
| 123 |
+
"""
|
| 124 |
+
Get job status.
|
| 125 |
+
|
| 126 |
+
The job status depends on the present of files: `AVAILABLE`,
|
| 127 |
+
`RUNNING`, `DONE`, and `FAIL` created by `haddock-bm` jobs.
|
| 128 |
+
|
| 129 |
+
Status is assigned to `self.status` and returned.
|
| 130 |
+
"""
|
| 131 |
+
for _file in self.status_files:
|
| 132 |
+
if _file.exists():
|
| 133 |
+
self.status = _file.stem # type: ignore
|
| 134 |
+
break
|
| 135 |
+
return self.status
|
| 136 |
+
|
| 137 |
+
def submit(self) -> None:
|
| 138 |
+
"""
|
| 139 |
+
Submit job.
|
| 140 |
+
|
| 141 |
+
Run command `$launch_command $job_filename`.
|
| 142 |
+
"""
|
| 143 |
+
subprocess.run(cmds := [self.launch_command, str(self.job_filename)])
|
| 144 |
+
print("Job sent: ", cmds)
|
| 145 |
+
|
| 146 |
+
def restart(self) -> None:
|
| 147 |
+
"""
|
| 148 |
+
Restart the status of the job to `AVAILABLE`.
|
| 149 |
+
|
| 150 |
+
Does this by removing all status files and creating the file
|
| 151 |
+
`AVAILABLE`.
|
| 152 |
+
"""
|
| 153 |
+
self.check_done.unlink(missing_ok=True)
|
| 154 |
+
self.check_running.unlink(missing_ok=True)
|
| 155 |
+
self.check_fail.unlink(missing_ok=True)
|
| 156 |
+
self.check_available.touch(exist_ok=True)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def get_current_jobs(grep: str = "BM5") -> int:
|
| 160 |
+
"""
|
| 161 |
+
Get current number of jobs for which job-name has the `grep` word.
|
| 162 |
+
|
| 163 |
+
List of jobs is retrieve using the command `qstat`.
|
| 164 |
+
|
| 165 |
+
Parameters
|
| 166 |
+
----------
|
| 167 |
+
grep : str
|
| 168 |
+
The string to search job-names for.
|
| 169 |
+
|
| 170 |
+
Return
|
| 171 |
+
------
|
| 172 |
+
int
|
| 173 |
+
The number of jobs with the word `grep` in their name.
|
| 174 |
+
"""
|
| 175 |
+
concurrent_cmd = "qstat -a | awk '{print $4}' | grep " + grep + " | wc -l"
|
| 176 |
+
p = subprocess.Popen(
|
| 177 |
+
concurrent_cmd,
|
| 178 |
+
shell=True,
|
| 179 |
+
stdout=subprocess.PIPE,
|
| 180 |
+
stderr=subprocess.STDOUT,
|
| 181 |
+
)
|
| 182 |
+
output = p.communicate()[0]
|
| 183 |
+
njobs = int(output.decode("utf-8"))
|
| 184 |
+
print(f"Found {njobs} in the queue.")
|
| 185 |
+
return njobs
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def calc_size(job_path: Path) -> int:
|
| 189 |
+
"""
|
| 190 |
+
Calculate the size of the job.
|
| 191 |
+
|
| 192 |
+
Expects the job file to be in a folder structure as defined by
|
| 193 |
+
`haddock3-bm`.
|
| 194 |
+
|
| 195 |
+
The size of the jobs is defined by the number of carbon-alpha lines
|
| 196 |
+
in the `target.pdb` file.
|
| 197 |
+
"""
|
| 198 |
+
target_pdb = Path(job_path.parents[1], "input", "target.pdb")
|
| 199 |
+
lines = target_pdb.read_text().split(os.linesep)
|
| 200 |
+
size = sum(1 for line in lines if line[11:16].strip() == "CA")
|
| 201 |
+
return size
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def filter_by_status(job_list: list[Job], status: str = "AVAILABLE") -> list[Job]:
|
| 205 |
+
"""
|
| 206 |
+
Filter jobs by their status.
|
| 207 |
+
|
| 208 |
+
Only jobs with `status` are accepted.
|
| 209 |
+
|
| 210 |
+
Parameters
|
| 211 |
+
----------
|
| 212 |
+
job_list : list of Job objects.
|
| 213 |
+
|
| 214 |
+
Returns
|
| 215 |
+
-------
|
| 216 |
+
list
|
| 217 |
+
The list with the `Job`s with matching `status`.
|
| 218 |
+
"""
|
| 219 |
+
jobs = [j for j in job_list if j.get_status() == status]
|
| 220 |
+
print(f"Number of {status} jobs: {len(jobs)}.")
|
| 221 |
+
return jobs
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
# command-line client helper functions
|
| 225 |
+
# load_args, cli, maincli
|
| 226 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 227 |
+
"""Load argument parser args."""
|
| 228 |
+
return ap.parse_args()
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 232 |
+
"""Command-line interface entry point."""
|
| 233 |
+
cmd = load_args(ap)
|
| 234 |
+
main(**vars(cmd))
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def maincli() -> None:
|
| 238 |
+
"""Execute main client."""
|
| 239 |
+
cli(ap, main)
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def main(
|
| 243 |
+
benchmark_path: Path,
|
| 244 |
+
job_limit: int = 10,
|
| 245 |
+
manager: str = "slurm",
|
| 246 |
+
restart: bool = False,
|
| 247 |
+
sort_first: bool = False,
|
| 248 |
+
) -> None:
|
| 249 |
+
"""
|
| 250 |
+
Execute the benchmark daemon.
|
| 251 |
+
|
| 252 |
+
The parameters defined here are the same as defined in the client
|
| 253 |
+
arguments.
|
| 254 |
+
|
| 255 |
+
This is the main function of the client. If you want to run the
|
| 256 |
+
daemon withOUT using the command line and instead importing its
|
| 257 |
+
functionalities and setting it up from another pythong script, you
|
| 258 |
+
should import this function.
|
| 259 |
+
|
| 260 |
+
>>> from haddock.clis.cli_dmn import main
|
| 261 |
+
|
| 262 |
+
Parameters
|
| 263 |
+
----------
|
| 264 |
+
benchmark_path : pathlib.Path
|
| 265 |
+
The path of the benchmark folder as created by the `haddock3-bm`
|
| 266 |
+
interface.
|
| 267 |
+
|
| 268 |
+
job_limit : int
|
| 269 |
+
The max number of jobs to send to the queue.
|
| 270 |
+
|
| 271 |
+
manager : str
|
| 272 |
+
A key to the `workload_manager_launch` dictionary. Selects the queue
|
| 273 |
+
management system.
|
| 274 |
+
|
| 275 |
+
restart : bool
|
| 276 |
+
Whether to restart the `RUNNING` jobs that might have been halted
|
| 277 |
+
in previous daemon runs. Defaults to False.
|
| 278 |
+
|
| 279 |
+
sort_first : bool
|
| 280 |
+
Whether to sort jobs by their size in ascending manner. That is,
|
| 281 |
+
the sorted jobs first. Defaults to False, the longer first.
|
| 282 |
+
"""
|
| 283 |
+
# lists of all the job files in the benchmark_path folder
|
| 284 |
+
job_list = list(benchmark_path.glob("*/jobs/*.job"))
|
| 285 |
+
|
| 286 |
+
# breaks if no jobs are found
|
| 287 |
+
if not job_list:
|
| 288 |
+
sys.exit("+ ERROR! No jobs found in folder: {str(benchmark_path)!r}")
|
| 289 |
+
|
| 290 |
+
# sorts the job list
|
| 291 |
+
job_list.sort(key=calc_size, reverse=not (sort_first)) # noqa: E275
|
| 292 |
+
|
| 293 |
+
# create the job objects according to the queue managing systme
|
| 294 |
+
_jobsys = workload_manager_launch[manager]
|
| 295 |
+
jobs = [Job(j, _jobsys) for j in job_list]
|
| 296 |
+
|
| 297 |
+
# restart previously (halted) `RUNNING` jobs - if selected.
|
| 298 |
+
if restart:
|
| 299 |
+
running_jobs = filter_by_status(jobs, status="RUNNING")
|
| 300 |
+
for _job in running_jobs:
|
| 301 |
+
_job.restart()
|
| 302 |
+
|
| 303 |
+
# Lists the available jobs (those with status `AVAILABLE`)
|
| 304 |
+
available_jobs = filter_by_status(jobs)
|
| 305 |
+
|
| 306 |
+
# runs the daemon loop, only if there are available jobs :-)
|
| 307 |
+
while available_jobs:
|
| 308 |
+
# get the number of available queue slots according to the
|
| 309 |
+
# job limit parameter
|
| 310 |
+
#
|
| 311 |
+
# 0 is added to avoid going to negative values in case a job
|
| 312 |
+
# had been manually submitted.
|
| 313 |
+
empty_slots = max(0, job_limit - get_current_jobs())
|
| 314 |
+
print("empty slots: ", empty_slots)
|
| 315 |
+
|
| 316 |
+
# send jobs if there are empty slots
|
| 317 |
+
for i in range(empty_slots):
|
| 318 |
+
available_jobs[i].submit()
|
| 319 |
+
time.sleep(5)
|
| 320 |
+
|
| 321 |
+
# chill before repeating the process.
|
| 322 |
+
print("chilling for 120 seconds...")
|
| 323 |
+
time.sleep(120)
|
| 324 |
+
|
| 325 |
+
# refreshes the available_jobs list
|
| 326 |
+
available_jobs = filter_by_status(jobs)
|
| 327 |
+
|
| 328 |
+
# done
|
| 329 |
+
return
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
if __name__ == "__main__":
|
| 333 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_mpi.py
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
MPI-wrapper for executing pickled CNSJobs created by libmpi.
|
| 3 |
+
|
| 4 |
+
This was developed for use of lbimpi but it might be useful in some specific
|
| 5 |
+
scenario as a cli.
|
| 6 |
+
|
| 7 |
+
For more information please refer to the README.md in the examples folder.
|
| 8 |
+
|
| 9 |
+
Usage::
|
| 10 |
+
|
| 11 |
+
haddock3-mpitask -h
|
| 12 |
+
haddock3-mpitask tasks.pkl
|
| 13 |
+
"""
|
| 14 |
+
|
| 15 |
+
import argparse
|
| 16 |
+
import pickle
|
| 17 |
+
import sys
|
| 18 |
+
|
| 19 |
+
from haddock.core.typing import (
|
| 20 |
+
AnyT,
|
| 21 |
+
ArgumentParser,
|
| 22 |
+
Callable,
|
| 23 |
+
FilePath,
|
| 24 |
+
Namespace,
|
| 25 |
+
)
|
| 26 |
+
from haddock.libs.libsubprocess import CNSJob
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
# Note! ########################################################################################
|
| 30 |
+
# It's important to not define `MPI` and `COMM` directly but to use the `get_mpi`
|
| 31 |
+
# function to ensure that the MPI module is only loaded when needed.
|
| 32 |
+
# This is important for testing purposes, and this CLI should further be refactored to not use
|
| 33 |
+
# global variables.
|
| 34 |
+
MPI = None
|
| 35 |
+
COMM = None
|
| 36 |
+
# Note! ########################################################################################
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def get_mpi():
|
| 40 |
+
"""Lazy load MPI and COMM."""
|
| 41 |
+
global MPI, COMM
|
| 42 |
+
if MPI is None:
|
| 43 |
+
try:
|
| 44 |
+
from mpi4py import MPI as _MPI
|
| 45 |
+
|
| 46 |
+
MPI = _MPI
|
| 47 |
+
COMM = MPI.COMM_WORLD
|
| 48 |
+
except ImportError as e:
|
| 49 |
+
_msg = (
|
| 50 |
+
f"{e} - To run this cli you must have mpi4py and "
|
| 51 |
+
"OpenMPI installed in the system"
|
| 52 |
+
)
|
| 53 |
+
sys.exit(_msg)
|
| 54 |
+
return MPI, COMM
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def split_tasks(task_l: list[AnyT], n: int) -> list[list[AnyT]]:
|
| 58 |
+
"""Split tasks into equal lenght chunks."""
|
| 59 |
+
return [task_l[_i::n] for _i in range(n)]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
# ========================================================================#
|
| 63 |
+
# helper functions to enhance flexibility and modularity of the CLIs
|
| 64 |
+
|
| 65 |
+
ap = argparse.ArgumentParser(
|
| 66 |
+
prog="MPI-wrapper for executing pickled CNSJobs created by libmpi",
|
| 67 |
+
description=__doc__,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
ap.add_argument(
|
| 71 |
+
"pickled_tasks",
|
| 72 |
+
help="The input pickled tasks path",
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def _ap() -> ArgumentParser:
|
| 77 |
+
return ap
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 81 |
+
"""Load argument parser args."""
|
| 82 |
+
return ap.parse_args()
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 86 |
+
"""Command-line interface entry point."""
|
| 87 |
+
cmd = load_args(ap)
|
| 88 |
+
main(**vars(cmd))
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def maincli() -> None:
|
| 92 |
+
"""Execute main client."""
|
| 93 |
+
cli(ap, main)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
# ========================================================================#
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def main(pickled_tasks: FilePath) -> None:
|
| 100 |
+
"""Execute the tasks."""
|
| 101 |
+
MPI, COMM = get_mpi()
|
| 102 |
+
if COMM.rank == 0:
|
| 103 |
+
with open(pickled_tasks, "rb") as pkl:
|
| 104 |
+
tasks = pickle.load(pkl)
|
| 105 |
+
mpi_jobs = split_tasks(tasks, COMM.size)
|
| 106 |
+
else:
|
| 107 |
+
mpi_jobs = None
|
| 108 |
+
|
| 109 |
+
jobs: list[CNSJob] = COMM.scatter(mpi_jobs, root=0)
|
| 110 |
+
|
| 111 |
+
results: list[FilePath] = []
|
| 112 |
+
for job in jobs:
|
| 113 |
+
job.run()
|
| 114 |
+
# check if the job has an input file
|
| 115 |
+
if hasattr(job, "input_file"):
|
| 116 |
+
results.append(job.input_file)
|
| 117 |
+
|
| 118 |
+
# COMM.Barrier()
|
| 119 |
+
# results = MPI.COMM_WORLD.gather(results, root=0)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
if __name__ == "__main__":
|
| 123 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_pp.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 |
+
logic implemented in the :py:mod:`haddock.gear.preprocessing`. See
|
| 6 |
+
documentation pages for more details.
|
| 7 |
+
|
| 8 |
+
You can use the `--dry` option to report on the performed changes
|
| 9 |
+
without actually performing the changes.
|
| 10 |
+
|
| 11 |
+
Corrected PDBs are saved to new files named after the `--suffix` option.
|
| 12 |
+
Original PDBs are never overwritten, unless `--suffix` is given an empty
|
| 13 |
+
string.
|
| 14 |
+
|
| 15 |
+
You can pass multiple PDB files to the command-line.
|
| 16 |
+
|
| 17 |
+
Usage::
|
| 18 |
+
|
| 19 |
+
haddock-pp file1.pdb file2.pdb
|
| 20 |
+
haddock-pp file1.pdb file2.pdb --suffix _new
|
| 21 |
+
haddock-pp file1.pdb file2.pdb --dry
|
| 22 |
+
"""
|
| 23 |
+
import argparse
|
| 24 |
+
import sys
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
|
| 27 |
+
from haddock import log
|
| 28 |
+
from haddock.core.typing import (
|
| 29 |
+
ArgumentParser,
|
| 30 |
+
Callable,
|
| 31 |
+
FilePath,
|
| 32 |
+
Namespace,
|
| 33 |
+
Optional,
|
| 34 |
+
)
|
| 35 |
+
from haddock.gear.preprocessing import process_pdbs, read_additional_residues
|
| 36 |
+
from haddock.libs.libcli import add_output_dir_arg
|
| 37 |
+
from haddock.libs.libio import add_suffix_to_files, save_lines_to_files
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
SUFFIX_DEFAULT = "_processed"
|
| 41 |
+
|
| 42 |
+
ap = argparse.ArgumentParser(
|
| 43 |
+
description=__doc__,
|
| 44 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
ap.add_argument(
|
| 48 |
+
"pdb_files",
|
| 49 |
+
help="Input PDB files.",
|
| 50 |
+
nargs="+",
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
ap.add_argument(
|
| 54 |
+
"-d",
|
| 55 |
+
"--dry",
|
| 56 |
+
help="Perform a dry run. Informs changes without modifying files.",
|
| 57 |
+
action="store_true",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
ap.add_argument(
|
| 61 |
+
"-t",
|
| 62 |
+
"--topfile",
|
| 63 |
+
help="Additional .top files.",
|
| 64 |
+
nargs="*",
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
ap.add_argument(
|
| 68 |
+
"-s",
|
| 69 |
+
"--suffix",
|
| 70 |
+
help=f"Suffix to output files. Defaults to {SUFFIX_DEFAULT!r}",
|
| 71 |
+
default=SUFFIX_DEFAULT,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
add_output_dir_arg(ap)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# client helper functions
|
| 78 |
+
def _ap() -> ArgumentParser:
|
| 79 |
+
return ap
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 83 |
+
"""Load argument parser args."""
|
| 84 |
+
return ap.parse_args()
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 88 |
+
"""Command-line interface entry point."""
|
| 89 |
+
cmd = vars(load_args(ap))
|
| 90 |
+
# I use this `pop` structure to maintain the unpacking argument in
|
| 91 |
+
# the `main` function because I foresee the `main` to be used from
|
| 92 |
+
# other parts of the software(s)
|
| 93 |
+
main(*cmd.pop("pdb_files"), **cmd)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def maincli() -> None:
|
| 97 |
+
"""Execute main client."""
|
| 98 |
+
cli(ap, main)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def main(
|
| 102 |
+
*pdb_files: FilePath,
|
| 103 |
+
dry: bool = False,
|
| 104 |
+
output_directory: Optional[FilePath] = None,
|
| 105 |
+
suffix: str = SUFFIX_DEFAULT,
|
| 106 |
+
topfile: Optional[FilePath] = None,
|
| 107 |
+
) -> None:
|
| 108 |
+
"""
|
| 109 |
+
Process PDB files.
|
| 110 |
+
|
| 111 |
+
Parameters
|
| 112 |
+
----------
|
| 113 |
+
dry : bool
|
| 114 |
+
Whether to perform a dry test only.
|
| 115 |
+
|
| 116 |
+
output_directory : str or ``pathlib.Path``
|
| 117 |
+
The directory where to save the output. Defaults to the current
|
| 118 |
+
working directory.
|
| 119 |
+
|
| 120 |
+
suffix : str
|
| 121 |
+
The suffix to append to the new files. Will be added before the
|
| 122 |
+
file extension. Original extension will be kept.
|
| 123 |
+
|
| 124 |
+
topfile : str or ``pathlib.Path``
|
| 125 |
+
The path to an additional HADDOCK3 topology file.
|
| 126 |
+
"""
|
| 127 |
+
log.info("Starting processing PDB files.")
|
| 128 |
+
log.info(f"Total number of PDB files: {len(pdb_files)}")
|
| 129 |
+
|
| 130 |
+
if dry:
|
| 131 |
+
log.info(
|
| 132 |
+
"You selected the `--dry` option. No new files will be created. "
|
| 133 |
+
"A report of the changes that would be performed in the PDB files "
|
| 134 |
+
"will be printed."
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
new_residues = read_additional_residues(topfile) if topfile else None
|
| 138 |
+
|
| 139 |
+
log.info("Processing the PDB files... " "This may take a bit if there are many.")
|
| 140 |
+
|
| 141 |
+
processed_pdbs = process_pdbs(
|
| 142 |
+
*pdb_files,
|
| 143 |
+
dry=dry,
|
| 144 |
+
user_supported_residues=new_residues,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
if dry:
|
| 148 |
+
log.info("Everything done. Exiting...")
|
| 149 |
+
sys.exit(0)
|
| 150 |
+
|
| 151 |
+
log.info("Finished processing PDBs. Saving to disk...")
|
| 152 |
+
if output_directory is None:
|
| 153 |
+
output_directory = Path.cwd()
|
| 154 |
+
else:
|
| 155 |
+
output_directory = Path(output_directory)
|
| 156 |
+
log.info("Output dir: {!r}".format(str(output_directory)))
|
| 157 |
+
output_directory.mkdir(parents=True, exist_ok=True)
|
| 158 |
+
|
| 159 |
+
pdb_names = (Path(output_directory, Path(pdb).name) for pdb in pdb_files)
|
| 160 |
+
out_files = add_suffix_to_files(pdb_names, suffix)
|
| 161 |
+
save_lines_to_files(out_files, processed_pdbs)
|
| 162 |
+
|
| 163 |
+
log.info("Everything done. Exiting...")
|
| 164 |
+
return
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
if __name__ == "__main__":
|
| 168 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_re.py
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
HADDOCK 3.0 CLI for interactive tasks.
|
| 3 |
+
"""
|
| 4 |
+
import argparse
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
|
| 8 |
+
from haddock.clis.re.clustfcc import add_clustfcc_arguments, reclustfcc
|
| 9 |
+
from haddock.clis.re.clustrmsd import add_clustrmsd_arguments, reclustrmsd
|
| 10 |
+
from haddock.clis.re.score import add_rescore_arguments, rescore
|
| 11 |
+
|
| 12 |
+
# Command line interface parser
|
| 13 |
+
ap = argparse.ArgumentParser(
|
| 14 |
+
prog="haddock3-re",
|
| 15 |
+
description=__doc__,
|
| 16 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
subparsers = ap.add_subparsers(title='subcommands',
|
| 20 |
+
help='valid subcommands',
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# score subcommand
|
| 24 |
+
rescore_subcommand = subparsers.add_parser('score')
|
| 25 |
+
rescore_subcommand.set_defaults(func=rescore)
|
| 26 |
+
rescore_subcommand = add_rescore_arguments(rescore_subcommand)
|
| 27 |
+
# clustrmsd subcommand
|
| 28 |
+
clustrmsd_subcommand = subparsers.add_parser('clustrmsd')
|
| 29 |
+
clustrmsd_subcommand.set_defaults(func=reclustrmsd)
|
| 30 |
+
clustrmsd_subcommand = add_clustrmsd_arguments(clustrmsd_subcommand)
|
| 31 |
+
# clustfcc subcommand
|
| 32 |
+
clustfcc_subcommand = subparsers.add_parser('clustfcc')
|
| 33 |
+
clustfcc_subcommand.set_defaults(func=reclustfcc)
|
| 34 |
+
clustfcc_subcommand = add_clustfcc_arguments(clustfcc_subcommand)
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _ap():
|
| 38 |
+
return ap
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def load_args(ap):
|
| 42 |
+
"""Load argument parser args."""
|
| 43 |
+
return ap.parse_args()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def maincli():
|
| 47 |
+
"""Execute main client."""
|
| 48 |
+
args = ap.parse_args()
|
| 49 |
+
cmd = vars(load_args(ap))
|
| 50 |
+
if "func" not in cmd.keys():
|
| 51 |
+
sys.stderr.write(f"Error: no subcommand given.{os.linesep}")
|
| 52 |
+
ap.print_help()
|
| 53 |
+
sys.exit(1)
|
| 54 |
+
else:
|
| 55 |
+
cmd.pop("func")
|
| 56 |
+
args.func(**cmd)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
sys.exit(maincli())
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_restraints.py
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
HADDOCK3 CLI for restraints-related tasks.
|
| 3 |
+
|
| 4 |
+
DISCLAIMER: these scripts have been ported from old code and are not
|
| 5 |
+
optimized for code quality and performance. They are provided as a convenience
|
| 6 |
+
for the user.
|
| 7 |
+
|
| 8 |
+
USAGE::
|
| 9 |
+
|
| 10 |
+
haddock3-restraints <TASK_NAME> <TASK_ARGS>
|
| 11 |
+
|
| 12 |
+
For the list of available tasks, run::
|
| 13 |
+
|
| 14 |
+
haddock3-restraints -h
|
| 15 |
+
|
| 16 |
+
For the list of arguments for a given task, run::
|
| 17 |
+
|
| 18 |
+
haddock3-restraints <TASK_NAME> -h
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
import argparse
|
| 22 |
+
import sys
|
| 23 |
+
|
| 24 |
+
from haddock import log
|
| 25 |
+
from haddock.clis.restraints.active_passive_to_ambig import (
|
| 26 |
+
actpass_to_ambig,
|
| 27 |
+
add_actpass_to_ambig_arguments,
|
| 28 |
+
)
|
| 29 |
+
from haddock.clis.restraints.calc_accessibility import (
|
| 30 |
+
add_calc_accessibility_arguments,
|
| 31 |
+
calc_accessibility,
|
| 32 |
+
)
|
| 33 |
+
from haddock.clis.restraints.passive_from_active import (
|
| 34 |
+
add_pass_from_act_arguments,
|
| 35 |
+
passive_from_active,
|
| 36 |
+
)
|
| 37 |
+
from haddock.clis.restraints.restrain_bodies import (
|
| 38 |
+
add_restrain_bodies_arguments,
|
| 39 |
+
restrain_bodies,
|
| 40 |
+
)
|
| 41 |
+
from haddock.clis.restraints.validate_tbl import (
|
| 42 |
+
add_validate_tbl_arguments,
|
| 43 |
+
validate_tbl,
|
| 44 |
+
)
|
| 45 |
+
from haddock.clis.restraints.z_surface_restraints import (
|
| 46 |
+
add_z_surf_restraints_arguments,
|
| 47 |
+
gen_z_surface_restraints,
|
| 48 |
+
)
|
| 49 |
+
from haddock.clis.restraints.random_removal import (
|
| 50 |
+
add_rand_removal_arguments,
|
| 51 |
+
main as random_removal,
|
| 52 |
+
)
|
| 53 |
+
from haddock.clis.restraints.restrain_ligand import (
|
| 54 |
+
add_restrain_ligand_arguments,
|
| 55 |
+
main as restrain_ligand,
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
# Command line interface parser
|
| 59 |
+
ap = argparse.ArgumentParser(
|
| 60 |
+
prog="haddock3-restraints",
|
| 61 |
+
description=__doc__,
|
| 62 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
subparsers = ap.add_subparsers(
|
| 66 |
+
title="subcommands",
|
| 67 |
+
description="valid subcommands",
|
| 68 |
+
help="additional help",
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# restrain_bodies subcommand
|
| 72 |
+
restrain_bodies_subcommand = subparsers.add_parser("restrain_bodies")
|
| 73 |
+
restrain_bodies_subcommand.set_defaults(func=restrain_bodies)
|
| 74 |
+
restrain_bodies_subcommand = add_restrain_bodies_arguments(restrain_bodies_subcommand)
|
| 75 |
+
|
| 76 |
+
# passive_from_active subcommand
|
| 77 |
+
pass_from_act_subcommand = subparsers.add_parser("passive_from_active")
|
| 78 |
+
pass_from_act_subcommand.set_defaults(func=passive_from_active)
|
| 79 |
+
pass_from_act_subcommand = add_pass_from_act_arguments(pass_from_act_subcommand)
|
| 80 |
+
|
| 81 |
+
# validate_tbl subcommand
|
| 82 |
+
validate_tbl_subcommand = subparsers.add_parser("validate_tbl")
|
| 83 |
+
validate_tbl_subcommand.set_defaults(func=validate_tbl)
|
| 84 |
+
validate_tbl_subcommand = add_validate_tbl_arguments(validate_tbl_subcommand)
|
| 85 |
+
|
| 86 |
+
# active_passive_to_ambig subcommand
|
| 87 |
+
actpass_to_ambig_subcommand = subparsers.add_parser("active_passive_to_ambig")
|
| 88 |
+
actpass_to_ambig_subcommand.set_defaults(func=actpass_to_ambig)
|
| 89 |
+
actpass_to_ambig_subcommand = add_actpass_to_ambig_arguments(
|
| 90 |
+
actpass_to_ambig_subcommand
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# calc_accessibility subcommand
|
| 94 |
+
calc_accessibility_subcommand = subparsers.add_parser("calc_accessibility")
|
| 95 |
+
calc_accessibility_subcommand.set_defaults(func=calc_accessibility)
|
| 96 |
+
calc_accessibility_subcommand = add_calc_accessibility_arguments(
|
| 97 |
+
calc_accessibility_subcommand
|
| 98 |
+
)
|
| 99 |
+
|
| 100 |
+
# z_surface_restraints subcommand
|
| 101 |
+
z_surface_restraints_subcommand = subparsers.add_parser("z_surface_restraints")
|
| 102 |
+
z_surface_restraints_subcommand.set_defaults(func=gen_z_surface_restraints)
|
| 103 |
+
z_surface_restraints_subcommand = add_z_surf_restraints_arguments(
|
| 104 |
+
z_surface_restraints_subcommand
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
# random_removal subcommand
|
| 108 |
+
restraints_random_removal_subcommand = subparsers.add_parser("random_removal")
|
| 109 |
+
restraints_random_removal_subcommand.set_defaults(func=random_removal)
|
| 110 |
+
restraints_random_removal_subcommand = add_rand_removal_arguments(
|
| 111 |
+
restraints_random_removal_subcommand
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# restrain_ligand subcommand
|
| 115 |
+
restraints_restrain_ligand_subcommand = subparsers.add_parser("restrain_ligand")
|
| 116 |
+
restraints_restrain_ligand_subcommand.set_defaults(func=restrain_ligand)
|
| 117 |
+
restraints_restrain_ligand_subcommand = add_restrain_ligand_arguments(
|
| 118 |
+
restraints_restrain_ligand_subcommand
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def _ap():
|
| 123 |
+
return ap
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def load_args(ap):
|
| 127 |
+
"""Load argument parser args."""
|
| 128 |
+
return ap.parse_args()
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def maincli():
|
| 132 |
+
"""Execute main client."""
|
| 133 |
+
args = ap.parse_args()
|
| 134 |
+
cmd = vars(load_args(ap))
|
| 135 |
+
try:
|
| 136 |
+
cmd.pop("func")
|
| 137 |
+
except KeyError:
|
| 138 |
+
sys.exit(ap.print_help())
|
| 139 |
+
args.func(**cmd)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
if __name__ == "__main__":
|
| 143 |
+
sys.exit(maincli())
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_score.py
ADDED
|
@@ -0,0 +1,300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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
A simple tool to calculate the HADDOCK-score of a complex.
|
| 3 |
+
|
| 4 |
+
You can pass to the command-line any parameter accepted by the `emscoring`
|
| 5 |
+
module. For this, use the ``-p`` option writing the name of the parameters
|
| 6 |
+
followed by the desired value. Write booleans with capital letter.
|
| 7 |
+
|
| 8 |
+
Use the ``haddock3-cfg`` command-line to obtain the list of parameters for
|
| 9 |
+
the ``emscoring`` module.
|
| 10 |
+
|
| 11 |
+
Usage::
|
| 12 |
+
|
| 13 |
+
haddock3-score complex.pdb
|
| 14 |
+
haddock3-score complex.pdb -p nemsteps 50
|
| 15 |
+
haddock3-score complex.pdb -p nemsteps 50 w_air 1
|
| 16 |
+
haddock3-score complex.pdb -p nemsteps 50 w_air 1 electflag True
|
| 17 |
+
|
| 18 |
+
"""
|
| 19 |
+
import argparse
|
| 20 |
+
import sys
|
| 21 |
+
import tempfile
|
| 22 |
+
|
| 23 |
+
from haddock.core.typing import (
|
| 24 |
+
Any,
|
| 25 |
+
ArgumentParser,
|
| 26 |
+
Callable,
|
| 27 |
+
FilePath,
|
| 28 |
+
Namespace,
|
| 29 |
+
)
|
| 30 |
+
from haddock.libs.libcli import _ParamsToDict
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
ap = argparse.ArgumentParser(
|
| 34 |
+
prog="haddock3-score",
|
| 35 |
+
description=__doc__,
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
ap.add_argument("pdb_file", help="Input PDB file")
|
| 39 |
+
|
| 40 |
+
ap.add_argument(
|
| 41 |
+
"--run_dir",
|
| 42 |
+
default="haddock-score-client",
|
| 43 |
+
type=str,
|
| 44 |
+
required=False,
|
| 45 |
+
help="Run directory name.",
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
ap.add_argument(
|
| 49 |
+
"--full",
|
| 50 |
+
action="store_true",
|
| 51 |
+
help="Print all energy components",
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
ap.add_argument(
|
| 55 |
+
"--outputpdb",
|
| 56 |
+
action="store_true",
|
| 57 |
+
help="Save the output PDB file (minimized structure)",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
ap.add_argument(
|
| 61 |
+
"--outputpsf",
|
| 62 |
+
action="store_true",
|
| 63 |
+
help="Save the output PSF file (topology)",
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
ap.add_argument(
|
| 67 |
+
"-k" "--keep-all",
|
| 68 |
+
dest="keep_all",
|
| 69 |
+
action="store_true",
|
| 70 |
+
help="Keep the whole run folder.",
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
ap.add_argument(
|
| 74 |
+
"-p",
|
| 75 |
+
"--other-params",
|
| 76 |
+
dest="other_params",
|
| 77 |
+
help=(
|
| 78 |
+
"Any other parameter of the `emscoring` module. "
|
| 79 |
+
"For example: -p nemsteps 1000. You can give any number of "
|
| 80 |
+
"parameters."
|
| 81 |
+
),
|
| 82 |
+
action=_ParamsToDict,
|
| 83 |
+
default={},
|
| 84 |
+
nargs="*",
|
| 85 |
+
)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _ap() -> ArgumentParser:
|
| 89 |
+
return ap
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 93 |
+
"""Load argument parser args."""
|
| 94 |
+
return ap.parse_args()
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 98 |
+
"""Command-line interface entry point."""
|
| 99 |
+
cmd = vars(load_args(ap))
|
| 100 |
+
kwargs = cmd.pop("other_params")
|
| 101 |
+
main(**cmd, **kwargs)
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
def maincli() -> None:
|
| 105 |
+
"""Execute main client."""
|
| 106 |
+
cli(ap, main)
|
| 107 |
+
|
| 108 |
+
|
| 109 |
+
def main(
|
| 110 |
+
pdb_file: FilePath,
|
| 111 |
+
run_dir: FilePath,
|
| 112 |
+
full: bool = False,
|
| 113 |
+
outputpdb: bool = False,
|
| 114 |
+
outputpsf: bool = False,
|
| 115 |
+
keep_all: bool = False,
|
| 116 |
+
**kwargs: Any,
|
| 117 |
+
) -> None:
|
| 118 |
+
"""
|
| 119 |
+
Calculate the score of a complex using the ``emscoring`` module.
|
| 120 |
+
|
| 121 |
+
Parameters
|
| 122 |
+
----------
|
| 123 |
+
pdb_file : str or pathlib.Path
|
| 124 |
+
The path to the PDB containing the complex.
|
| 125 |
+
|
| 126 |
+
full : bool
|
| 127 |
+
Print all energy components.
|
| 128 |
+
|
| 129 |
+
outputpdb : bool
|
| 130 |
+
Save the PDB file resulting from the scoring calculation.
|
| 131 |
+
|
| 132 |
+
outputpsf : bool
|
| 133 |
+
Save the PSF file resulting from the scoring calculation; this
|
| 134 |
+
is the CNS topology created before running the calculation.
|
| 135 |
+
|
| 136 |
+
keep_all : bool
|
| 137 |
+
Keep the whole temporary run folder. ``haddock3-score`` creates
|
| 138 |
+
a temporary run folder where the calculations are performed. If
|
| 139 |
+
``keep_all`` is True, this folder is **not** deleted after when
|
| 140 |
+
the calculation finishes.
|
| 141 |
+
|
| 142 |
+
kwargs : any
|
| 143 |
+
Any additional arguments that will be passed to the ``emscoring``
|
| 144 |
+
module.
|
| 145 |
+
"""
|
| 146 |
+
import os
|
| 147 |
+
import logging
|
| 148 |
+
import shutil
|
| 149 |
+
from contextlib import suppress
|
| 150 |
+
from pathlib import Path
|
| 151 |
+
|
| 152 |
+
from haddock import log, EmptyPath
|
| 153 |
+
from haddock.gear.haddockmodel import HaddockModel
|
| 154 |
+
from haddock.gear.yaml2cfg import read_from_yaml_config
|
| 155 |
+
from haddock.gear.zerofill import zero_fill
|
| 156 |
+
from haddock.libs.libio import working_directory
|
| 157 |
+
from haddock.libs.libworkflow import WorkflowManager
|
| 158 |
+
from haddock.modules.scoring.emscoring import DEFAULT_CONFIG
|
| 159 |
+
|
| 160 |
+
log.setLevel(logging.ERROR)
|
| 161 |
+
|
| 162 |
+
input_pdb = Path(pdb_file).resolve()
|
| 163 |
+
if not input_pdb.exists():
|
| 164 |
+
sys.exit(f"* ERROR * Input PDB file {str(input_pdb)!r} does not exist")
|
| 165 |
+
|
| 166 |
+
# config all parameters are correctly spelled.
|
| 167 |
+
default_emscoring = read_from_yaml_config(DEFAULT_CONFIG)
|
| 168 |
+
ems_dict = default_emscoring.copy()
|
| 169 |
+
n_warnings = 0
|
| 170 |
+
for param, value in kwargs.items():
|
| 171 |
+
# Check if the parameter name is in the emscoring module ones
|
| 172 |
+
if param not in default_emscoring:
|
| 173 |
+
sys.exit(
|
| 174 |
+
f"* ERROR * Parameter {param!r} is not a "
|
| 175 |
+
f"valid `emscoring` parameter.{os.linesep}"
|
| 176 |
+
"Valid emscoring parameters are: "
|
| 177 |
+
f"{', '.join(sorted(default_emscoring))}"
|
| 178 |
+
)
|
| 179 |
+
# Compare the user-given value to the default one
|
| 180 |
+
if value != default_emscoring[param]:
|
| 181 |
+
print(
|
| 182 |
+
f"* ATTENTION * Value ({value}) of parameter {param} "
|
| 183 |
+
f"different from default ({default_emscoring[param]})"
|
| 184 |
+
)
|
| 185 |
+
# get the type of default value
|
| 186 |
+
default_type = type(default_emscoring[param])
|
| 187 |
+
# cast the value to the same type
|
| 188 |
+
if default_type == bool:
|
| 189 |
+
if value.lower() not in ["true", "false"]:
|
| 190 |
+
sys.exit(f"* ERROR * Boolean parameter {param} should be True or False")
|
| 191 |
+
value = value.lower() == "true"
|
| 192 |
+
elif param.endswith("_fname"):
|
| 193 |
+
value = EmptyPath() if str(value) == "" else Path(value).resolve()
|
| 194 |
+
else:
|
| 195 |
+
value = default_type(value)
|
| 196 |
+
ems_dict[param] = value
|
| 197 |
+
n_warnings += 1
|
| 198 |
+
if n_warnings != 0:
|
| 199 |
+
print(
|
| 200 |
+
"* ATTENTION * Non-default parameter values were used. "
|
| 201 |
+
"They should be properly reported if the output "
|
| 202 |
+
"data are used for publication."
|
| 203 |
+
)
|
| 204 |
+
print(f"used emscoring parameters: {ems_dict}")
|
| 205 |
+
|
| 206 |
+
# create run directory
|
| 207 |
+
run_dir = Path(run_dir)
|
| 208 |
+
with suppress(FileNotFoundError):
|
| 209 |
+
shutil.rmtree(run_dir)
|
| 210 |
+
run_dir.mkdir()
|
| 211 |
+
zero_fill.set_zerofill_number(2)
|
| 212 |
+
|
| 213 |
+
# create temporary file
|
| 214 |
+
with tempfile.NamedTemporaryFile(prefix=input_pdb.stem, suffix=".pdb") as tmp:
|
| 215 |
+
|
| 216 |
+
# create a copy of the input pdb
|
| 217 |
+
input_pdb_copy = Path(tmp.name)
|
| 218 |
+
shutil.copy(input_pdb, input_pdb_copy)
|
| 219 |
+
|
| 220 |
+
# Setting up a full workflow set of parameters
|
| 221 |
+
workflow_params = {
|
| 222 |
+
"topoaa": {
|
| 223 |
+
"molecules": [input_pdb_copy],
|
| 224 |
+
"ligand_param_fname": ems_dict["ligand_param_fname"],
|
| 225 |
+
"ligand_top_fname": ems_dict["ligand_top_fname"],
|
| 226 |
+
},
|
| 227 |
+
"emscoring": ems_dict,
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
print("> starting calculations...")
|
| 231 |
+
|
| 232 |
+
# run workflow
|
| 233 |
+
with working_directory(run_dir):
|
| 234 |
+
workflow = WorkflowManager(
|
| 235 |
+
workflow_params=workflow_params,
|
| 236 |
+
start=0,
|
| 237 |
+
run_dir=run_dir,
|
| 238 |
+
)
|
| 239 |
+
workflow.run()
|
| 240 |
+
|
| 241 |
+
# Build expected pdb filepath
|
| 242 |
+
minimized_mol = Path(run_dir, "1_emscoring", "emscoring_1.pdb")
|
| 243 |
+
haddock_score_component_dic = HaddockModel(minimized_mol).energies
|
| 244 |
+
|
| 245 |
+
vdw = haddock_score_component_dic["vdw"]
|
| 246 |
+
elec = haddock_score_component_dic["elec"]
|
| 247 |
+
desolv = haddock_score_component_dic["desolv"]
|
| 248 |
+
air = haddock_score_component_dic["air"]
|
| 249 |
+
bsa = haddock_score_component_dic["bsa"]
|
| 250 |
+
|
| 251 |
+
# Compute the haddock score
|
| 252 |
+
# emscoring is equivalent to itw
|
| 253 |
+
haddock_score_itw = (
|
| 254 |
+
ems_dict["w_vdw"] * vdw
|
| 255 |
+
+ ems_dict["w_elec"] * elec
|
| 256 |
+
+ ems_dict["w_desolv"] * desolv
|
| 257 |
+
+ ems_dict["w_air"] * air
|
| 258 |
+
+ ems_dict["w_bsa"] * bsa
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
print(
|
| 262 |
+
"> HADDOCK-score ="
|
| 263 |
+
f" ({ems_dict['w_vdw']} * vdw)"
|
| 264 |
+
f" + ({ems_dict['w_elec']} * elec)"
|
| 265 |
+
f" + ({ems_dict['w_desolv']} * desolv)"
|
| 266 |
+
f" + ({ems_dict['w_air']} * air)"
|
| 267 |
+
f" + ({ems_dict['w_bsa']} * bsa)"
|
| 268 |
+
)
|
| 269 |
+
print(f"> HADDOCK-score (emscoring) = {haddock_score_itw:.4f}")
|
| 270 |
+
|
| 271 |
+
if full:
|
| 272 |
+
print(f"> vdw={vdw},elec={elec},desolv={desolv},air={air},bsa={bsa}")
|
| 273 |
+
|
| 274 |
+
if outputpdb:
|
| 275 |
+
outputpdb_name = Path(f"{input_pdb.stem}_hs.pdb")
|
| 276 |
+
print(f"> writing {outputpdb_name}")
|
| 277 |
+
shutil.copy(
|
| 278 |
+
Path(run_dir, "1_emscoring", "emscoring_1.pdb"),
|
| 279 |
+
outputpdb_name,
|
| 280 |
+
)
|
| 281 |
+
|
| 282 |
+
if outputpsf:
|
| 283 |
+
outputpsf_name = Path(f"{input_pdb.stem}_hs.psf")
|
| 284 |
+
print(f"> writing {outputpsf_name}")
|
| 285 |
+
shutil.copy(
|
| 286 |
+
Path(run_dir, "0_topoaa", f"{input_pdb_copy.stem}_haddock.psf"),
|
| 287 |
+
outputpsf_name,
|
| 288 |
+
)
|
| 289 |
+
|
| 290 |
+
if not keep_all:
|
| 291 |
+
shutil.rmtree(run_dir)
|
| 292 |
+
else:
|
| 293 |
+
print(
|
| 294 |
+
'The folder where the calculations were performed was kept.'
|
| 295 |
+
f' See folder: {run_dir}'
|
| 296 |
+
)
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
if __name__ == "__main__":
|
| 300 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_traceback.py
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Traces back PDB files from a HADDOCK run directory.
|
| 3 |
+
|
| 4 |
+
Given an input run directory, haddock3-traceback traces back each model to the
|
| 5 |
+
initial input molecules used, providing the rank of each intermediate model.
|
| 6 |
+
|
| 7 |
+
USAGE::
|
| 8 |
+
|
| 9 |
+
haddock3-traceback -r <run_dir>
|
| 10 |
+
|
| 11 |
+
"""
|
| 12 |
+
import argparse
|
| 13 |
+
import sys
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import pandas as pd
|
| 18 |
+
|
| 19 |
+
from haddock import log
|
| 20 |
+
from haddock.core.typing import Any, FilePath
|
| 21 |
+
from haddock.libs import libcli
|
| 22 |
+
from haddock.libs.libontology import ModuleIO, PDBFile
|
| 23 |
+
from haddock.libs.libplots import make_traceback_plot
|
| 24 |
+
from haddock.modules import get_module_steps_folders
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
TRACK_FOLDER = "traceback" # name of the traceback folder
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def get_steps_without_pdbs(run_dir, all_steps):
|
| 31 |
+
"""
|
| 32 |
+
Get the modules that do not produce PDB files.
|
| 33 |
+
|
| 34 |
+
Parameters
|
| 35 |
+
----------
|
| 36 |
+
run_dir : str or pathlib.Path
|
| 37 |
+
Path to the run directory.
|
| 38 |
+
|
| 39 |
+
all_steps : list
|
| 40 |
+
List of all the steps in the run directory.
|
| 41 |
+
|
| 42 |
+
Returns
|
| 43 |
+
-------
|
| 44 |
+
steps_without_pdbs : list
|
| 45 |
+
List of steps that did not produce PDB files.
|
| 46 |
+
"""
|
| 47 |
+
steps_without_pdbs = []
|
| 48 |
+
for step in all_steps:
|
| 49 |
+
if step.endswith("topoaa"):
|
| 50 |
+
steps_without_pdbs.append(step)
|
| 51 |
+
else:
|
| 52 |
+
step_dir = Path(run_dir, step)
|
| 53 |
+
if step_dir.is_dir():
|
| 54 |
+
pdbs = list(step_dir.glob("*.pdb*"))
|
| 55 |
+
if len(pdbs) == 0:
|
| 56 |
+
steps_without_pdbs.append(step)
|
| 57 |
+
return steps_without_pdbs
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def get_ori_names(n: int, pdbfile: PDBFile, max_topo_len: int) -> tuple[list, int]:
|
| 61 |
+
"""
|
| 62 |
+
Get the original name(s) of the PDB file.
|
| 63 |
+
|
| 64 |
+
Parameters
|
| 65 |
+
----------
|
| 66 |
+
n : int
|
| 67 |
+
Step number.
|
| 68 |
+
pdbfile : PDBFile
|
| 69 |
+
PDBFile object.
|
| 70 |
+
max_topo_len : int
|
| 71 |
+
Maximum length of the topologies found so far.
|
| 72 |
+
|
| 73 |
+
Returns
|
| 74 |
+
-------
|
| 75 |
+
ori_names : list
|
| 76 |
+
List of original names.
|
| 77 |
+
max_topo_len : int
|
| 78 |
+
Maximum length of the topologies found so far.
|
| 79 |
+
"""
|
| 80 |
+
if n != 0: # not the first step, ori_name should be defined
|
| 81 |
+
ori_names = [pdbfile.ori_name]
|
| 82 |
+
else: # first step, we get topology files instead of ori_name
|
| 83 |
+
# topology can either be a list of topologies or a single
|
| 84 |
+
# topology
|
| 85 |
+
if isinstance(pdbfile.topology, list):
|
| 86 |
+
ori_names = [el.file_name for el in pdbfile.topology]
|
| 87 |
+
if len(pdbfile.topology) > max_topo_len:
|
| 88 |
+
max_topo_len = len(pdbfile.topology)
|
| 89 |
+
else:
|
| 90 |
+
ori_names = [pdbfile.topology.file_name] # type: ignore
|
| 91 |
+
max_topo_len = 1
|
| 92 |
+
return ori_names, max_topo_len
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def traceback_dataframe(
|
| 96 |
+
data_dict: dict, rank_dict: dict, sel_step: list, max_topo_len: int
|
| 97 |
+
) -> pd.DataFrame:
|
| 98 |
+
"""
|
| 99 |
+
Create traceback dataframe by combining together ranks and data.
|
| 100 |
+
|
| 101 |
+
Parameters
|
| 102 |
+
----------
|
| 103 |
+
data_dict : dict
|
| 104 |
+
Dictionary containing the data to be traced back.
|
| 105 |
+
rank_dict : dict
|
| 106 |
+
Dictionary containing the ranks of the data to be traced back.
|
| 107 |
+
sel_step : list
|
| 108 |
+
List of selected steps.
|
| 109 |
+
max_topo_len : int
|
| 110 |
+
Maximum length of the topologies.
|
| 111 |
+
|
| 112 |
+
Returns
|
| 113 |
+
-------
|
| 114 |
+
df_ord : pandas.DataFrame
|
| 115 |
+
Dataframe containing the traceback data.
|
| 116 |
+
"""
|
| 117 |
+
# get last step of the workflow
|
| 118 |
+
last_step = sel_step[-1]
|
| 119 |
+
# data dict to dataframe
|
| 120 |
+
df_data = pd.DataFrame.from_dict(data_dict, orient="index")
|
| 121 |
+
df_data.reset_index(inplace=True)
|
| 122 |
+
# assign columns
|
| 123 |
+
data_cols = [el for el in reversed(sel_step)]
|
| 124 |
+
data_cols.extend([f"00_topo{i+1}" for i in range(max_topo_len)])
|
| 125 |
+
df_data.columns = data_cols
|
| 126 |
+
|
| 127 |
+
# same for the rank_dict
|
| 128 |
+
df_ranks = pd.DataFrame.from_dict(rank_dict, orient="index")
|
| 129 |
+
df_ranks.reset_index(inplace=True)
|
| 130 |
+
ranks_col = [last_step] # the key to merge the dataframes
|
| 131 |
+
ranks_col.extend([f"{el}_rank" for el in reversed(sel_step)])
|
| 132 |
+
df_ranks.columns = ranks_col
|
| 133 |
+
|
| 134 |
+
# merging the data and ranks dataframes
|
| 135 |
+
df_merged = pd.merge(df_data, df_ranks, on=last_step)
|
| 136 |
+
ordered_cols = sorted(df_merged.columns)
|
| 137 |
+
df_ord = df_merged[ordered_cols]
|
| 138 |
+
# last thing: substituting unk records with - in the last step
|
| 139 |
+
unk_records = df_ord[f"{last_step}"].str.startswith("unk")
|
| 140 |
+
df_ord.loc[unk_records, last_step] = "-"
|
| 141 |
+
return df_ord
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def order_traceback_df(df_output, sel_step):
|
| 145 |
+
"""
|
| 146 |
+
Order the traceback dataframe. Each step is ordered by rank.
|
| 147 |
+
|
| 148 |
+
Parameters
|
| 149 |
+
----------
|
| 150 |
+
df_output : pandas.DataFrame
|
| 151 |
+
Dataframe containing the traceback data.
|
| 152 |
+
|
| 153 |
+
sel_step : list
|
| 154 |
+
List of selected steps.
|
| 155 |
+
|
| 156 |
+
Returns
|
| 157 |
+
-------
|
| 158 |
+
df_output : pandas.DataFrame
|
| 159 |
+
Dataframe containing the ordered traceback data.
|
| 160 |
+
"""
|
| 161 |
+
# loop over sel_step in reverse order
|
| 162 |
+
sorted_list = []
|
| 163 |
+
indexes = []
|
| 164 |
+
for n in range(len(sel_step) - 1, -1, -1):
|
| 165 |
+
rank_col = sel_step[n] + "_rank"
|
| 166 |
+
# take only models with a rank
|
| 167 |
+
df_last = df_output[df_output[rank_col] != "-"]
|
| 168 |
+
# remove from df_last the indexes that are already in the dataframe
|
| 169 |
+
df_last = df_last[~df_last.index.isin(indexes)]
|
| 170 |
+
# sorting the dataframe by rank
|
| 171 |
+
sorted_df_last = df_last.sort_values(by=rank_col)
|
| 172 |
+
sorted_list.append(sorted_df_last)
|
| 173 |
+
# concat the current indexes with the previous ones
|
| 174 |
+
indexes = sorted_df_last.index.tolist() + indexes
|
| 175 |
+
df_output = pd.concat(sorted_list)
|
| 176 |
+
return df_output
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def subset_traceback(traceback_df: pd.DataFrame, cons_filename: Path) -> pd.DataFrame:
|
| 180 |
+
"""
|
| 181 |
+
Generate a subset the traceback dataframe with the top 40 models.
|
| 182 |
+
|
| 183 |
+
Parameters
|
| 184 |
+
----------
|
| 185 |
+
traceback_df : pandas.DataFrame
|
| 186 |
+
Dataframe containing the traceback data.
|
| 187 |
+
|
| 188 |
+
cons_filename : pathlib.Path
|
| 189 |
+
name of the consensus file.
|
| 190 |
+
|
| 191 |
+
Returns
|
| 192 |
+
-------
|
| 193 |
+
rank_data_subset : pandas.DataFrame
|
| 194 |
+
Dataframe containing the subset of the traceback data.
|
| 195 |
+
"""
|
| 196 |
+
red_traceback_df = traceback_df.head(40)
|
| 197 |
+
rank_data = red_traceback_df.filter(regex='rank$')
|
| 198 |
+
# get the last column: this will define the name of the models
|
| 199 |
+
last_column = red_traceback_df.columns[-2]
|
| 200 |
+
last_column_data = red_traceback_df[last_column]
|
| 201 |
+
# concat the ranks with the model name
|
| 202 |
+
rank_data = pd.concat([last_column_data, rank_data], axis=1)
|
| 203 |
+
# the rank of the last column must be defined
|
| 204 |
+
last_column_rank = last_column + "_rank"
|
| 205 |
+
# copy avoids SettingWithCopyWarning
|
| 206 |
+
rank_data_subset = rank_data[rank_data[last_column_rank] != '-'].copy()
|
| 207 |
+
rank_columns = rank_data_subset.columns[1:].tolist()
|
| 208 |
+
rank_data_subset[rank_columns] = rank_data_subset[rank_columns].apply(pd.to_numeric, errors='coerce')
|
| 209 |
+
rank_data_subset = rank_data_subset.sort_values(by=last_column_rank, ascending=True)
|
| 210 |
+
|
| 211 |
+
# rename the columns
|
| 212 |
+
rank_data_subset.columns = ["Model"] + rank_columns
|
| 213 |
+
# sum the ranks
|
| 214 |
+
rank_data_subset["Sum-of-Ranks"] = rank_data_subset[rank_columns].sum(axis=1)
|
| 215 |
+
rank_data_subset.to_csv(cons_filename, index=False, sep="\t")
|
| 216 |
+
return rank_data_subset
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
# Command line interface parser
|
| 220 |
+
ap = argparse.ArgumentParser(
|
| 221 |
+
prog="haddock3-traceback",
|
| 222 |
+
description=__doc__,
|
| 223 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
libcli.add_rundir_arg(ap)
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def load_args(ap):
|
| 230 |
+
"""Load argument parser args."""
|
| 231 |
+
return ap.parse_args()
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def cli(ap, main):
|
| 235 |
+
"""Command-line interface entry point."""
|
| 236 |
+
cmd = vars(load_args(ap))
|
| 237 |
+
main(**cmd)
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def maincli():
|
| 241 |
+
"""Execute main client."""
|
| 242 |
+
cli(ap, main)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
def main(run_dir: FilePath, offline: bool = False) -> None:
|
| 246 |
+
"""
|
| 247 |
+
Traceback CLI.
|
| 248 |
+
|
| 249 |
+
Parameters
|
| 250 |
+
----------
|
| 251 |
+
run_dir : str or Path
|
| 252 |
+
Path to the original run directory.
|
| 253 |
+
"""
|
| 254 |
+
log.level = 20
|
| 255 |
+
log.info(f"Running haddock3-traceback on {run_dir}")
|
| 256 |
+
|
| 257 |
+
# Reading steps
|
| 258 |
+
log.info("Reading input run directory")
|
| 259 |
+
# get the module folders from the run_dir input
|
| 260 |
+
all_steps = get_module_steps_folders(Path(run_dir))
|
| 261 |
+
log.info(f"All_steps: {', '.join(all_steps)}")
|
| 262 |
+
ana_modules = get_steps_without_pdbs(run_dir, all_steps)
|
| 263 |
+
log.info(f"Modules not to be analysed: {', '.join(ana_modules)}")
|
| 264 |
+
sel_step = [st for st in all_steps if st not in ana_modules]
|
| 265 |
+
# check if there are steps to traceback
|
| 266 |
+
if len(sel_step) == 0:
|
| 267 |
+
log.info("No steps to trace back. Exiting.")
|
| 268 |
+
return
|
| 269 |
+
else:
|
| 270 |
+
log.info(f"Steps to trace back: {', '.join(sel_step)}")
|
| 271 |
+
|
| 272 |
+
# creating traceback folder
|
| 273 |
+
outdir = Path(run_dir, TRACK_FOLDER)
|
| 274 |
+
try:
|
| 275 |
+
outdir.mkdir(exist_ok=False)
|
| 276 |
+
log.info(f"Created directory: {str(outdir.resolve())}")
|
| 277 |
+
except FileExistsError:
|
| 278 |
+
log.warning(f"Directory {str(outdir.resolve())} already exists.")
|
| 279 |
+
|
| 280 |
+
data_dict: dict[Any, Any] = {}
|
| 281 |
+
rank_dict: dict[Any, Any] = {}
|
| 282 |
+
unk_idx, max_topo_len = 0, 0
|
| 283 |
+
# this cycle goes through the steps in reverse order
|
| 284 |
+
for n in range(len(sel_step) - 1, -1, -1):
|
| 285 |
+
log.info(f"Tracing back step {sel_step[n]}")
|
| 286 |
+
# correcting names in the dictionary. The ori_name must be complemented
|
| 287 |
+
# with the step folder name
|
| 288 |
+
for key in data_dict.keys():
|
| 289 |
+
if data_dict[key][-1] != "-":
|
| 290 |
+
data_dict[key][-1] = f"../{sel_step[n]}/{data_dict[key][-1]}"
|
| 291 |
+
|
| 292 |
+
delta = len(sel_step) - n - 1 # how many steps have we gone back?
|
| 293 |
+
# loading the .json file
|
| 294 |
+
json_path = Path(run_dir, sel_step[n], "io.json")
|
| 295 |
+
io = ModuleIO()
|
| 296 |
+
io.load(json_path)
|
| 297 |
+
# list all the values in the data_dict
|
| 298 |
+
ls_values = [x for val in data_dict.values() for x in val]
|
| 299 |
+
# getting and sorting the ranks for the current step folder
|
| 300 |
+
ranks = [pdbfile.score for pdbfile in io.output]
|
| 301 |
+
ranks_argsort = np.argsort(ranks)
|
| 302 |
+
|
| 303 |
+
# iterating through the pdbfiles to fill data_dict and rank_dict
|
| 304 |
+
for i, pdbfile in enumerate(io.output):
|
| 305 |
+
rank = np.where(ranks_argsort == i)[0][0] + 1
|
| 306 |
+
# getting the original names
|
| 307 |
+
ori_names, max_topo_len = get_ori_names(n, pdbfile, max_topo_len)
|
| 308 |
+
if n != len(sel_step) - 1:
|
| 309 |
+
if str(pdbfile.rel_path) not in ls_values:
|
| 310 |
+
# this is the first step in which the pdbfile appears.
|
| 311 |
+
# This means that it was discarded for the subsequent steps
|
| 312 |
+
# We need to add the pdbfile to the data_dict
|
| 313 |
+
keys = [f"unk{unk_idx}"]
|
| 314 |
+
data_dict[keys[0]] = ["-" for el in range(delta - 1)]
|
| 315 |
+
data_dict[keys[0]].append(str(pdbfile.rel_path))
|
| 316 |
+
rank_dict[keys[0]] = ["-" for el in range(delta)]
|
| 317 |
+
unk_idx += 1
|
| 318 |
+
else:
|
| 319 |
+
# we've already seen this pdb before.
|
| 320 |
+
idxs = [i for i, el in enumerate(ls_values) if el==str(pdbfile.rel_path)]
|
| 321 |
+
keys = [list(data_dict.keys())[idx // delta] for idx in idxs]
|
| 322 |
+
|
| 323 |
+
# assignment
|
| 324 |
+
for el in ori_names:
|
| 325 |
+
for key in keys:
|
| 326 |
+
data_dict[key].append(el)
|
| 327 |
+
for key in keys:
|
| 328 |
+
rank_dict[key].append(rank)
|
| 329 |
+
else: # last step of the workflow
|
| 330 |
+
data_dict[str(pdbfile.rel_path)] = [on for on in ori_names]
|
| 331 |
+
rank_dict[str(pdbfile.rel_path)] = [rank]
|
| 332 |
+
|
| 333 |
+
# print(f"rank_dict {rank_dict}")
|
| 334 |
+
# print(f"data_dict {data_dict}, maxtopo {max_topo_len}")
|
| 335 |
+
|
| 336 |
+
# stripping away relative paths
|
| 337 |
+
final_data_dict = {}
|
| 338 |
+
for key in data_dict.keys():
|
| 339 |
+
new_key = key.split("/")[-1]
|
| 340 |
+
final_data_dict[new_key] = [el.split("/")[-1] for el in data_dict[key]]
|
| 341 |
+
final_rank_dict = {}
|
| 342 |
+
for key in rank_dict.keys():
|
| 343 |
+
new_key = key.split("/")[-1]
|
| 344 |
+
final_rank_dict[new_key] = rank_dict[key]
|
| 345 |
+
# dumping the data into a dataframe
|
| 346 |
+
df_output = traceback_dataframe(
|
| 347 |
+
final_data_dict, final_rank_dict, sel_step, max_topo_len
|
| 348 |
+
)
|
| 349 |
+
|
| 350 |
+
# ordering the dataframe
|
| 351 |
+
df_output = order_traceback_df(df_output, sel_step)
|
| 352 |
+
# dumping the dataframe
|
| 353 |
+
track_filename = Path(run_dir, TRACK_FOLDER, "traceback.tsv")
|
| 354 |
+
log.info(
|
| 355 |
+
f"Output dataframe {track_filename} " f"created with shape {df_output.shape}"
|
| 356 |
+
)
|
| 357 |
+
df_output.to_csv(track_filename, sep="\t", index=False)
|
| 358 |
+
|
| 359 |
+
# taking (and writing) a subset of the dataframe
|
| 360 |
+
consensus_filename = Path(run_dir, TRACK_FOLDER, "consensus.tsv")
|
| 361 |
+
rank_data_subset = subset_traceback(df_output, consensus_filename)
|
| 362 |
+
|
| 363 |
+
# plotting the traceback dataframe
|
| 364 |
+
plot_filename = Path(run_dir, TRACK_FOLDER, "traceback.html")
|
| 365 |
+
make_traceback_plot(rank_data_subset, plot_filename, offline=offline)
|
| 366 |
+
return
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
if __name__ == "__main__":
|
| 370 |
+
sys.exit(maincli())
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/cli_unpack.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Unpack the output of an HADDOCK3 run directory.
|
| 4 |
+
|
| 5 |
+
The unpack process performs file unpacking and file decompressing
|
| 6 |
+
operations. File with extension `seed` and `con` are unpacked from
|
| 7 |
+
their `.tgz` files. While files with `.pdb.gz` and `.psf.gz` extension
|
| 8 |
+
are uncompressed. If `--all` is given, unpack also `.inp.gz` and
|
| 9 |
+
`.out.gz` files.
|
| 10 |
+
|
| 11 |
+
This CLI performs the opposite operations as the ``haddock3-clean``
|
| 12 |
+
command-line.
|
| 13 |
+
|
| 14 |
+
The <run_directory> can either be a whole HADDOCK3 run folder or a
|
| 15 |
+
specific folder of the workflow step. <ncores> defined the number of
|
| 16 |
+
threads to use.
|
| 17 |
+
|
| 18 |
+
Usage::
|
| 19 |
+
|
| 20 |
+
haddock3-unpack -h
|
| 21 |
+
haddock3-unpack -r <run_directory>
|
| 22 |
+
haddock3-unpack run1
|
| 23 |
+
haddock3-unpack run1/1_rigidbody
|
| 24 |
+
haddock3-unpack run1 -n # uses all cores
|
| 25 |
+
haddock3-unpack run1 -n 2 # uses 2 cores
|
| 26 |
+
haddock3-unpack run1 -n 2 -a
|
| 27 |
+
haddock3-unpack run1 -n 2 --all
|
| 28 |
+
"""
|
| 29 |
+
import argparse
|
| 30 |
+
import sys
|
| 31 |
+
|
| 32 |
+
from haddock.core.typing import (
|
| 33 |
+
ArgumentParser,
|
| 34 |
+
Callable,
|
| 35 |
+
FilePath,
|
| 36 |
+
Namespace,
|
| 37 |
+
Optional,
|
| 38 |
+
)
|
| 39 |
+
from haddock.libs import libcli
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Command line interface parser
|
| 43 |
+
ap = argparse.ArgumentParser(
|
| 44 |
+
description=__doc__,
|
| 45 |
+
formatter_class=argparse.RawDescriptionHelpFormatter,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
libcli.add_rundir_arg(ap)
|
| 49 |
+
|
| 50 |
+
ap.add_argument(
|
| 51 |
+
"--all",
|
| 52 |
+
"-a",
|
| 53 |
+
dest="dec_all",
|
| 54 |
+
help="Unpack all files (includes `.inp` and `.out`).",
|
| 55 |
+
action="store_true",
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
libcli.add_ncores_arg(ap)
|
| 59 |
+
libcli.add_version_arg(ap)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _ap() -> ArgumentParser:
|
| 63 |
+
return ap
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def load_args(ap: ArgumentParser) -> Namespace:
|
| 67 |
+
"""Load argument parser args."""
|
| 68 |
+
return ap.parse_args()
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def cli(ap: ArgumentParser, main: Callable[..., None]) -> None:
|
| 72 |
+
"""Command-line interface entry point."""
|
| 73 |
+
cmd = load_args(ap)
|
| 74 |
+
main(**vars(cmd))
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def maincli() -> None:
|
| 78 |
+
"""Execute main client."""
|
| 79 |
+
cli(ap, main)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def main(run_dir: FilePath, ncores: Optional[int] = 1, dec_all: bool = False) -> None:
|
| 83 |
+
"""
|
| 84 |
+
Unpack a HADDOCK3 run directory step folders.
|
| 85 |
+
|
| 86 |
+
Usually, this concerns uncompressing and unpacking files.
|
| 87 |
+
|
| 88 |
+
It performs the oposity function as
|
| 89 |
+
:py:func:`haddock.clis.cli_clean.main`.
|
| 90 |
+
|
| 91 |
+
Parameters
|
| 92 |
+
----------
|
| 93 |
+
run_dir : str or :external:py:class:`pathlib.Path`.
|
| 94 |
+
The path to the run directory or to a folder of a specific step
|
| 95 |
+
of the workflow.
|
| 96 |
+
|
| 97 |
+
ncores : int, or None
|
| 98 |
+
The number of cores to use. If ``None``, use all possible threads.
|
| 99 |
+
Defaults to 1.
|
| 100 |
+
|
| 101 |
+
See Also
|
| 102 |
+
--------
|
| 103 |
+
`haddock.gear.clean_steps`
|
| 104 |
+
"""
|
| 105 |
+
# anti-pattern to speed up CLI initiation
|
| 106 |
+
from pathlib import Path
|
| 107 |
+
|
| 108 |
+
from haddock import log
|
| 109 |
+
from haddock.gear.clean_steps import unpack_compressed_and_archived_files
|
| 110 |
+
from haddock.libs.libtimer import log_time
|
| 111 |
+
from haddock.libs.libutil import parse_ncores
|
| 112 |
+
from haddock.modules import get_module_steps_folders, is_step_folder
|
| 113 |
+
|
| 114 |
+
log.info(f"Unpacking {str(run_dir)!r} folder")
|
| 115 |
+
ncores = parse_ncores(ncores)
|
| 116 |
+
|
| 117 |
+
if is_step_folder(run_dir):
|
| 118 |
+
with log_time("unpacking took"):
|
| 119 |
+
unpack_compressed_and_archived_files(
|
| 120 |
+
[run_dir],
|
| 121 |
+
ncores,
|
| 122 |
+
dec_all=dec_all,
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
else:
|
| 126 |
+
step_folders = [Path(run_dir, p) for p in get_module_steps_folders(run_dir)]
|
| 127 |
+
with log_time("unpacking took"):
|
| 128 |
+
unpack_compressed_and_archived_files(
|
| 129 |
+
step_folders,
|
| 130 |
+
ncores,
|
| 131 |
+
dec_all=dec_all,
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
return
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
if __name__ == "__main__":
|
| 138 |
+
sys.exit(maincli()) # type: ignore
|
.venv_haddock/lib/python3.12/site-packages/haddock/clis/wrapper_haddock_restraints.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import sys
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
from importlib.resources import files
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main():
|
| 9 |
+
|
| 10 |
+
binary = Path(files("haddock").joinpath("bin/haddock-restraints")) # type: ignore
|
| 11 |
+
sys.argv[0] = str(binary) # Replace argv[0] with actual binary path
|
| 12 |
+
|
| 13 |
+
# Execute the binary
|
| 14 |
+
import subprocess
|
| 15 |
+
|
| 16 |
+
sys.exit(subprocess.run([str(binary)] + sys.argv[1:]).returncode)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
if __name__ == "__main__":
|
| 20 |
+
main()
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/__init__.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Core haddock3 functionalities.
|
| 3 |
+
"""
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/cns_paths.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Path to CNS-related files.
|
| 3 |
+
|
| 4 |
+
Most paths are defined by dictionaries that gather several related
|
| 5 |
+
paths. Here, instead of defining the dictionaries with static paths, we
|
| 6 |
+
have functions that create those dict-containing paths dynamically. The
|
| 7 |
+
default values are defined by:
|
| 8 |
+
|
| 9 |
+
- axis
|
| 10 |
+
- tensors
|
| 11 |
+
- translation_vectors
|
| 12 |
+
- water_box
|
| 13 |
+
|
| 14 |
+
But you can re-use the functions to create new dictionaries with updated
|
| 15 |
+
paths. This is useful for those cases when the `cns/` folder is moved
|
| 16 |
+
to a different folder.
|
| 17 |
+
"""
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
from haddock import toppar_path
|
| 21 |
+
from haddock.core.typing import FilePath
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
# exact file names as present in the cns/ scripts folder
|
| 25 |
+
LINK_FILE = "protein-allhdg5-4-noter.link"
|
| 26 |
+
SCATTER_LIB = "scatter.lib"
|
| 27 |
+
INITIAL_POSITIONS_DIR = "initial_positions"
|
| 28 |
+
|
| 29 |
+
PROTEIN_LINK_FILES = {
|
| 30 |
+
"NH3+,COO-": "protein-allhdg5-4.link",
|
| 31 |
+
"NH,COO-": "protein-allhdg5-4-noNter.link",
|
| 32 |
+
"NH3+,CO": "protein-allhdg5-4-noCter.link",
|
| 33 |
+
"NH,CO": LINK_FILE,
|
| 34 |
+
}
|
| 35 |
+
NUCL_LINK_FILES = {
|
| 36 |
+
"5'Phosphate": "dna-rna-pho-1.3.link",
|
| 37 |
+
"5'OH": "dna-rna-1.3.link",
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
# default prepared paths
|
| 41 |
+
link_file = Path(toppar_path, LINK_FILE)
|
| 42 |
+
scatter_lib = Path(toppar_path, SCATTER_LIB)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def get_translation_vectors(path: FilePath) -> dict[str, Path]:
|
| 46 |
+
"""
|
| 47 |
+
Generate paths for translation vectors.
|
| 48 |
+
|
| 49 |
+
Parameters
|
| 50 |
+
----------
|
| 51 |
+
path : pathlib.Path
|
| 52 |
+
If absolute, paths will be absolute, if relative paths will be
|
| 53 |
+
relative. Adds the INITIAL_POSITIONS_DIR path before the file
|
| 54 |
+
name.
|
| 55 |
+
"""
|
| 56 |
+
translation_vectors: dict[str, Path] = {}
|
| 57 |
+
for i in range(51):
|
| 58 |
+
_s = f'trans_vector_{i}'
|
| 59 |
+
_p = Path(path, INITIAL_POSITIONS_DIR, _s)
|
| 60 |
+
translation_vectors[_s] = _p
|
| 61 |
+
|
| 62 |
+
return translation_vectors
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def get_tensors(path: FilePath) -> dict[str, Path]:
|
| 66 |
+
"""Generate paths for tensors."""
|
| 67 |
+
tensors = {
|
| 68 |
+
"tensor_psf": Path(path, "tensor.psf"),
|
| 69 |
+
"tensor_pdb": Path(path, "tensor.pdb"),
|
| 70 |
+
"tensor_para_psf": Path(path, "tensor_para.psf"),
|
| 71 |
+
"tensor_para_pdb": Path(path, "tensor_para.pdb"),
|
| 72 |
+
"tensor_dani_psf": Path(path, "tensor_dani.psf"),
|
| 73 |
+
"tensor_dani_pdb": Path(path, "tensor_dani.pdb"),
|
| 74 |
+
}
|
| 75 |
+
return tensors
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def get_axis(path: FilePath) -> dict[str, Path]:
|
| 79 |
+
"""Generate paths for axis."""
|
| 80 |
+
axis = {
|
| 81 |
+
"top_axis": Path(path, "top_axis.pro"),
|
| 82 |
+
"par_axis": Path(path, "par_axis.pro"),
|
| 83 |
+
"top_axis_dani": Path(path, "top_axis_dani.pro"),
|
| 84 |
+
}
|
| 85 |
+
return axis
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def get_water_box(path: FilePath) -> dict[str, Path]:
|
| 89 |
+
"""Generate paths for water box."""
|
| 90 |
+
water_box = {
|
| 91 |
+
"boxtyp20": Path(path, "boxtyp20.pdb"),
|
| 92 |
+
}
|
| 93 |
+
return water_box
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
axis = get_axis(toppar_path)
|
| 97 |
+
tensors = get_tensors(toppar_path)
|
| 98 |
+
translation_vectors = get_translation_vectors(toppar_path)
|
| 99 |
+
water_box = get_water_box(toppar_path)
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/defaults.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""All default parameters used by the framework."""
|
| 2 |
+
|
| 3 |
+
import string
|
| 4 |
+
from importlib.resources import files
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import yaml
|
| 8 |
+
|
| 9 |
+
from haddock import core_path
|
| 10 |
+
from haddock.libs.libutil import get_cns_executable, get_prodrg_exec
|
| 11 |
+
|
| 12 |
+
cns_exec, cns_exec_linux = get_cns_executable()
|
| 13 |
+
prodrg_exec, prodrg_param = get_prodrg_exec()
|
| 14 |
+
|
| 15 |
+
CONTACT_FCC_EXEC = Path(files("haddock").joinpath("bin/contact_fcc")) # type: ignore
|
| 16 |
+
FAST_RMSDMATRIX_EXEC = Path(files("haddock").joinpath("bin/fast-rmsdmatrix")) # type: ignore
|
| 17 |
+
|
| 18 |
+
MODULE_PATH_NAME = "step_"
|
| 19 |
+
"""
|
| 20 |
+
Module input and generated data will be stored in folder starting by
|
| 21 |
+
this prefix"""
|
| 22 |
+
|
| 23 |
+
MODULE_IO_FILE = "io.json"
|
| 24 |
+
"""Default name for exchange module information file"""
|
| 25 |
+
|
| 26 |
+
MAX_NUM_MODULES = 10000
|
| 27 |
+
"""Temptative number of max allowed number of modules to execute"""
|
| 28 |
+
|
| 29 |
+
valid_run_dir_chars = string.ascii_letters + string.digits + "._-/\\"
|
| 30 |
+
|
| 31 |
+
RUNDIR = "run_dir"
|
| 32 |
+
"""Default run directory name."""
|
| 33 |
+
|
| 34 |
+
INTERACTIVE_RE_SUFFIX = "interactive"
|
| 35 |
+
"""Suffix added to interactive haddock3-re runs."""
|
| 36 |
+
|
| 37 |
+
MODULE_DEFAULT_YAML = "defaults.yaml"
|
| 38 |
+
"""Default name of the yaml default parameters file."""
|
| 39 |
+
|
| 40 |
+
CNS_MODULES = ["rigidbody", "flexref", "emscoring", "mdscoring", "mdref", "emref"]
|
| 41 |
+
"""List of CNS modules available in HADDOCK3."""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
with open(Path(core_path, "mandatory.yaml"), "r") as fin:
|
| 45 |
+
_ycfg = yaml.safe_load(fin)
|
| 46 |
+
max_molecules_allowed = _ycfg["molecules"]["maxitems"]
|
| 47 |
+
del _ycfg
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/exceptions.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""HADDOCK library custom errors."""
|
| 2 |
+
|
| 3 |
+
from os import linesep
|
| 4 |
+
|
| 5 |
+
from haddock.core.typing import FilePath
|
| 6 |
+
|
| 7 |
+
class HaddockError(Exception):
|
| 8 |
+
"""Error in HADDOCK3."""
|
| 9 |
+
|
| 10 |
+
pass
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class ConfigurationError(HaddockError):
|
| 14 |
+
"""Error in the configuration file."""
|
| 15 |
+
|
| 16 |
+
pass
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class ModuleError(HaddockError):
|
| 20 |
+
"""Error in a HADDOCK3 module."""
|
| 21 |
+
|
| 22 |
+
pass
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class StepError(HaddockError):
|
| 26 |
+
"""Error in a HADDOCK3 workflow step."""
|
| 27 |
+
|
| 28 |
+
pass
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class JobRunningError(HaddockError):
|
| 32 |
+
"""General job running error."""
|
| 33 |
+
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class CNSRunningError(HaddockError):
|
| 38 |
+
"""CNS run error."""
|
| 39 |
+
|
| 40 |
+
pass
|
| 41 |
+
|
| 42 |
+
class KnownCNSError(CNSRunningError):
|
| 43 |
+
"""Detected CNS output error."""
|
| 44 |
+
|
| 45 |
+
def __init__(self, cns_message: str, hint: str, filepath: FilePath):
|
| 46 |
+
self.cns_error = cns_message
|
| 47 |
+
self.hint = hint
|
| 48 |
+
self.filepath = filepath
|
| 49 |
+
|
| 50 |
+
def __str__(self) -> str:
|
| 51 |
+
"""Generate custom string representation of this exception."""
|
| 52 |
+
full_msg = (
|
| 53 |
+
f"A CNS error occured: `{self.cns_error}`.{linesep}"
|
| 54 |
+
f"Here is a hint on how to solve it:{linesep}{self.hint}"
|
| 55 |
+
)
|
| 56 |
+
return full_msg
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
class HaddockModuleError(HaddockError):
|
| 60 |
+
"""General error in a HADDOCK3 module."""
|
| 61 |
+
|
| 62 |
+
pass
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
class ThirdPartyIntallationError(HaddockModuleError):
|
| 66 |
+
"""General error when a third party module is not properly installed."""
|
| 67 |
+
|
| 68 |
+
pass
|
| 69 |
+
|
| 70 |
+
class SetupError(HaddockError):
|
| 71 |
+
"""Set up error."""
|
| 72 |
+
|
| 73 |
+
pass
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
class HaddockTermination(HaddockError):
|
| 77 |
+
"""Terminates HADDOCK."""
|
| 78 |
+
|
| 79 |
+
pass
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/mandatory.yaml
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
run_dir:
|
| 2 |
+
type: dir
|
| 3 |
+
title: Run directory
|
| 4 |
+
short: Folder to store the HADDOCK3 run
|
| 5 |
+
long: The new folder that will be created to save the HADDOCK3 run
|
| 6 |
+
explevel: easy
|
| 7 |
+
molecules:
|
| 8 |
+
type: list
|
| 9 |
+
accept:
|
| 10 |
+
- ".pdb"
|
| 11 |
+
minitems: 1
|
| 12 |
+
maxitems: 20
|
| 13 |
+
title: Input Molecules
|
| 14 |
+
short: The input molecules that will be used for docking.
|
| 15 |
+
long:
|
| 16 |
+
Molecules must be provided in PDB format. These PDB files can be
|
| 17 |
+
single molecules or ensembles using the MODEL/ENDMDL statements.
|
| 18 |
+
explevel: easy
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/optional.yaml
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
preprocess:
|
| 2 |
+
default: false
|
| 3 |
+
type: boolean
|
| 4 |
+
title: Tries to correct input PDBs
|
| 5 |
+
short: If true, evaluates and tries to correct the input PDB before the
|
| 6 |
+
workflow.
|
| 7 |
+
long: HADDOCK3 checks and processes the input PDB files to ensure they
|
| 8 |
+
all comply with HADDOCK3's requirements. These checks concerns, for example,
|
| 9 |
+
residue numbering, compatibility of chain IDs, and many others. You can see
|
| 10 |
+
all checks performs in the live issue
|
| 11 |
+
https://github.com/haddocking/haddock3/issues/143. If set to false, no
|
| 12 |
+
checks are performed and HADDOCK3 directly uses the original input PDBs.
|
| 13 |
+
explevel: easy
|
| 14 |
+
postprocess:
|
| 15 |
+
default: true
|
| 16 |
+
type: boolean
|
| 17 |
+
title: Executes haddock3-analyse on the CAPRI folders at the end of the run
|
| 18 |
+
short: If true, executes haddock3-analyse on the CAPRI folders at the end of
|
| 19 |
+
the workflow
|
| 20 |
+
long: haddock3-analyse is a cli (see https://github.com/haddocking/haddock3/blob/main/src/haddock/clis/cli_analyse.py)
|
| 21 |
+
used to plot the results of a HADDOCK3 workflow. If this option, this command
|
| 22 |
+
is automatically executed at the end of the workflow (on the caprieval folders).
|
| 23 |
+
explevel: easy
|
| 24 |
+
gen_archive:
|
| 25 |
+
default: false
|
| 26 |
+
type: boolean
|
| 27 |
+
title: Generates an archive of the run and of the analysis.
|
| 28 |
+
short: If true, executes haddock3-analyse in self_contained mode and generates
|
| 29 |
+
archives of the run_directory and of the analysis in two separated tgz files.
|
| 30 |
+
long: If true, executes haddock3-analyse in self_contained mode and generates
|
| 31 |
+
archives of the run_directory and of the analysis in two separated tgz files.
|
| 32 |
+
explevel: easy
|
.venv_haddock/lib/python3.12/site-packages/haddock/core/supported_molecules.py
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
HADDOCK 3 supported residues.
|
| 3 |
+
|
| 4 |
+
The HADDOCK3 supported residues are defined by the different ``.top``
|
| 5 |
+
files in the ``cns/toppar`` source folder. This module will automatically
|
| 6 |
+
retrieve any new residue added to the ``.top`` defined in the folder and
|
| 7 |
+
add it to the variables here.
|
| 8 |
+
|
| 9 |
+
If a new ``.top`` file is added in the folder, that must be added here
|
| 10 |
+
inside the :py:func:`read_supported_residues` function, because file retrieve is
|
| 11 |
+
not done automatically on purpose.
|
| 12 |
+
|
| 13 |
+
``.top`` files considered here:
|
| 14 |
+
|
| 15 |
+
* ``carbohydrate.top``
|
| 16 |
+
* ``dna-rna-CG-MARTINI-2-1p.top``
|
| 17 |
+
* ``dna-rna-allatom-hj-opls-1.3.top``
|
| 18 |
+
* ``fragment_probes.top``
|
| 19 |
+
* ``hemes-allhdg.top``
|
| 20 |
+
* ``ion.top``
|
| 21 |
+
* ``protein-CG-Martini-2-2.top``
|
| 22 |
+
* ``protein-CG-Martini.top``
|
| 23 |
+
* ``protein-allhdg5-4.top``
|
| 24 |
+
* ``solvent-allhdg5-4.top``
|
| 25 |
+
* ``shape.top``
|
| 26 |
+
* ``cofactors.top``
|
| 27 |
+
|
| 28 |
+
DNA-related files are all concatenated into a single DNA-supported
|
| 29 |
+
residues datastructure. The same occurs for protein residues (natural or
|
| 30 |
+
modified).
|
| 31 |
+
|
| 32 |
+
You can import from this module the different sets containing the
|
| 33 |
+
supported residue names:
|
| 34 |
+
|
| 35 |
+
* :py:data:`supported_aminoacids_resnames`
|
| 36 |
+
* :py:data:`supported_carbo_resnames`
|
| 37 |
+
* :py:data:`supported_fragments_resnames`
|
| 38 |
+
* :py:data:`supported_hemes_resnames`
|
| 39 |
+
* :py:data:`supported_single_ions_resnames`
|
| 40 |
+
* :py:data:`supported_single_ions_elements`
|
| 41 |
+
* :py:data:`supported_single_ions_atoms`
|
| 42 |
+
* :py:data:`supported_multiatom_ions_resnames`
|
| 43 |
+
* :py:data:`supported_nucleic_resnames`
|
| 44 |
+
* :py:data:`supported_solvents_resnames`
|
| 45 |
+
* :py:data:`supported_shape`
|
| 46 |
+
* :py:data:`supported_cofactors_resnames`
|
| 47 |
+
|
| 48 |
+
* :py:data:`supported_ATOM` (contains residues and nucleic acids)
|
| 49 |
+
* :py:data:`supported_HETATM` (everything not contained in ATOM)
|
| 50 |
+
"""
|
| 51 |
+
import itertools as it
|
| 52 |
+
import re
|
| 53 |
+
import string
|
| 54 |
+
from copy import copy
|
| 55 |
+
from pathlib import Path
|
| 56 |
+
|
| 57 |
+
from haddock import toppar_path
|
| 58 |
+
from haddock.core.typing import FilePath, Iterable
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
class CNSTopologyResidue:
|
| 62 |
+
"""CNS topology residue."""
|
| 63 |
+
|
| 64 |
+
def __init__(self, resname: str, charge: float,
|
| 65 |
+
atoms: Iterable[str]) -> None:
|
| 66 |
+
"""
|
| 67 |
+
CNS topology residue.
|
| 68 |
+
|
| 69 |
+
This is not an actual topology. It is a namespace storing the
|
| 70 |
+
basic parameters defined in CNS residue topologies.
|
| 71 |
+
|
| 72 |
+
So far, this is used by the
|
| 73 |
+
:py:module:`haddock.gear.preprocessing` step; but this class can
|
| 74 |
+
be extended with additional parameters if needed.
|
| 75 |
+
|
| 76 |
+
Parameters
|
| 77 |
+
----------
|
| 78 |
+
resname : str
|
| 79 |
+
The name of the residue.
|
| 80 |
+
|
| 81 |
+
charge : float
|
| 82 |
+
The charge of the residue. The charge will be round to two
|
| 83 |
+
decimal places.
|
| 84 |
+
|
| 85 |
+
atoms : list-like
|
| 86 |
+
The list of atom names. Will be converted to a tuple.
|
| 87 |
+
"""
|
| 88 |
+
self._resname = resname
|
| 89 |
+
self._charge = round(charge, 2)
|
| 90 |
+
self._atoms = tuple(atoms)
|
| 91 |
+
return
|
| 92 |
+
|
| 93 |
+
def __repr__(self) -> str:
|
| 94 |
+
return str(self)
|
| 95 |
+
|
| 96 |
+
def __str__(self) -> str:
|
| 97 |
+
return (
|
| 98 |
+
f"{self.__class__.__name__}({self.resname!r}, "
|
| 99 |
+
f"{self.charge!r}, {self.atoms!r})"
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
@property
|
| 103 |
+
def resname(self) -> str:
|
| 104 |
+
"""Residue name."""
|
| 105 |
+
return self._resname
|
| 106 |
+
|
| 107 |
+
@property
|
| 108 |
+
def charge(self) -> float:
|
| 109 |
+
"""Residue total charge."""
|
| 110 |
+
return self._charge
|
| 111 |
+
|
| 112 |
+
@property
|
| 113 |
+
def atoms(self) -> tuple[str, ...]:
|
| 114 |
+
"""Tuple of residue atoms."""
|
| 115 |
+
return self._atoms
|
| 116 |
+
|
| 117 |
+
@property
|
| 118 |
+
def elements(self) -> tuple[str, ...]:
|
| 119 |
+
"""
|
| 120 |
+
List of elements for all atoms composing the molecule.
|
| 121 |
+
|
| 122 |
+
This list is ordered the same as ``atoms``.
|
| 123 |
+
|
| 124 |
+
By default ``elements`` is not defined and must be injected manually.
|
| 125 |
+
|
| 126 |
+
See Also
|
| 127 |
+
--------
|
| 128 |
+
* :py:func:`get_ion_element_from_atoms`
|
| 129 |
+
"""
|
| 130 |
+
try:
|
| 131 |
+
return self._elements
|
| 132 |
+
except AttributeError as err:
|
| 133 |
+
emsg = "`elements` is not defined."
|
| 134 |
+
raise AttributeError(emsg) from err
|
| 135 |
+
|
| 136 |
+
@elements.setter
|
| 137 |
+
def elements(self, elements: tuple[str, ...]) -> None:
|
| 138 |
+
self._elements = elements
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def get_ion_element_from_atoms(atoms: Iterable[str]) -> tuple[str, ...]:
|
| 142 |
+
"""
|
| 143 |
+
Generate the element name from the atom name for single atom ions.
|
| 144 |
+
|
| 145 |
+
Examples
|
| 146 |
+
--------
|
| 147 |
+
>>> get_ion_element_from_atoms(["ZN+2", "CU+2", "NI"])
|
| 148 |
+
("ZN", "CU", "NI")
|
| 149 |
+
|
| 150 |
+
Parameters
|
| 151 |
+
----------
|
| 152 |
+
atom : list
|
| 153 |
+
A list of atom names.
|
| 154 |
+
"""
|
| 155 |
+
ele = (a.rstrip(string.digits + "+-") for a in atoms)
|
| 156 |
+
return tuple(ele)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def read_residues_from_top_file(topfile: FilePath) -> list[CNSTopologyResidue]:
|
| 160 |
+
"""
|
| 161 |
+
Read the residues defined in CNS topology file.
|
| 162 |
+
|
| 163 |
+
This is a general implementation to read the basic information from
|
| 164 |
+
the CNS topology files. This basic information is the information
|
| 165 |
+
needed to help the the :py:mod:`haddock.gear.preprocessing` step
|
| 166 |
+
in identifying the supported residues and correctly format their PDB
|
| 167 |
+
lines.
|
| 168 |
+
|
| 169 |
+
Parameters
|
| 170 |
+
----------
|
| 171 |
+
topfile : str or :external:py:class:`pathlib.Path`
|
| 172 |
+
Path to the topology file.
|
| 173 |
+
|
| 174 |
+
Returns
|
| 175 |
+
-------
|
| 176 |
+
list
|
| 177 |
+
List of :class:`CNSTopologyResidue` objects.
|
| 178 |
+
Each object has information on the residue name, the atoms,
|
| 179 |
+
and the total charge of the residue.
|
| 180 |
+
|
| 181 |
+
See Also
|
| 182 |
+
--------
|
| 183 |
+
* :py:func:`haddock.gear.preprocessing.read_additional_residues`
|
| 184 |
+
"""
|
| 185 |
+
# just to avoid identention with with
|
| 186 |
+
fin = open(topfile, 'r')
|
| 187 |
+
lines = fin.readlines()
|
| 188 |
+
fin.close()
|
| 189 |
+
return _read_residues_from_top_file(lines)
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def _read_residues_from_top_file(
|
| 193 |
+
lines: Iterable[str]) -> list[CNSTopologyResidue]:
|
| 194 |
+
# regular expression to parse information from atom lines
|
| 195 |
+
atom_regex = (
|
| 196 |
+
r"^ATOM +([A-Z0-9\'\+\-]{1,4}) +.* +(?:charge|CHARGE|CHARge) *= *"
|
| 197 |
+
r"([\-|+]?\d+.?\d*).*(?:END|end).*$"
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
# helper variables for the for-loop
|
| 201 |
+
atoms: list[str] = []
|
| 202 |
+
charges: list[str] = []
|
| 203 |
+
residues: list[CNSTopologyResidue] = []
|
| 204 |
+
in_residue: bool = False
|
| 205 |
+
|
| 206 |
+
# all lines are striped before looping
|
| 207 |
+
for line in map(str.strip, lines): # it is important to strip spaces
|
| 208 |
+
if line.startswith(('RESI', 'residue')):
|
| 209 |
+
in_residue = True # defines we start a new residue
|
| 210 |
+
|
| 211 |
+
# extracts the resname from the residue line
|
| 212 |
+
resname = line.split()[1]
|
| 213 |
+
|
| 214 |
+
# ensures there is no bug when changing residues
|
| 215 |
+
# before starting a new residue `atoms` and `charges` should be
|
| 216 |
+
# empty
|
| 217 |
+
if atoms or charges:
|
| 218 |
+
emsg = \
|
| 219 |
+
"Starting a new residue without emptying the previous one."
|
| 220 |
+
raise ValueError(emsg)
|
| 221 |
+
|
| 222 |
+
elif line.startswith('ATOM'):
|
| 223 |
+
aname, acharge = re.findall(atom_regex, line)[0]
|
| 224 |
+
atoms.append(aname)
|
| 225 |
+
charges.append(acharge)
|
| 226 |
+
|
| 227 |
+
elif line.startswith(("end", "END")) and in_residue:
|
| 228 |
+
|
| 229 |
+
# the total charge of the residue
|
| 230 |
+
total_charge = sum(map(float, charges))
|
| 231 |
+
# need to be a copy to avoid unexpected referencing from the list
|
| 232 |
+
_atoms = copy(atoms)
|
| 233 |
+
|
| 234 |
+
resi = CNSTopologyResidue(resname, total_charge, _atoms)
|
| 235 |
+
residues.append(resi)
|
| 236 |
+
|
| 237 |
+
# clear help variables
|
| 238 |
+
charges.clear()
|
| 239 |
+
atoms.clear()
|
| 240 |
+
in_residue = False
|
| 241 |
+
|
| 242 |
+
return residues
|
| 243 |
+
|
| 244 |
+
|
| 245 |
+
# what we will need to inspect if the residues are allowed or not are
|
| 246 |
+
# the residue names. So it is nice to have a function that retrieve them
|
| 247 |
+
# from the respective named tuples.
|
| 248 |
+
def get_resnames(
|
| 249 |
+
group: Iterable[CNSTopologyResidue]) -> dict[str, CNSTopologyResidue]:
|
| 250 |
+
"""
|
| 251 |
+
Make a set of residue names.
|
| 252 |
+
|
| 253 |
+
Elements of the group must have a `resname` attribute.
|
| 254 |
+
|
| 255 |
+
Parameters
|
| 256 |
+
----------
|
| 257 |
+
group : list of :py:class:`CNSTopologyResidue`
|
| 258 |
+
|
| 259 |
+
Returns
|
| 260 |
+
-------
|
| 261 |
+
dict
|
| 262 |
+
Dict of residue name and residue pairs.
|
| 263 |
+
"""
|
| 264 |
+
return {i.resname: i for i in group}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
# this function is necessary because of the `self_contained` option
|
| 268 |
+
# where the topology files are not defined in the haddock3 code but in
|
| 269 |
+
# the run folder
|
| 270 |
+
def read_supported_residues(
|
| 271 |
+
source_path: FilePath) -> tuple[dict[str, CNSTopologyResidue], ...]:
|
| 272 |
+
"""
|
| 273 |
+
Read supported residues from a folder containing ``.top`` files.
|
| 274 |
+
|
| 275 |
+
The function expects the ``source_path`` to have the required files.
|
| 276 |
+
|
| 277 |
+
Expected files are:
|
| 278 |
+
|
| 279 |
+
* ``carbohydrate.top``
|
| 280 |
+
* ``dna-rna-CG-MARTINI-2-1p.top``
|
| 281 |
+
* ``dna-rna-allatom-hj-opls-1.3.top``
|
| 282 |
+
* ``fragment_probes.top``
|
| 283 |
+
* ``hemes-allhdg.top``
|
| 284 |
+
* ``ion.top``
|
| 285 |
+
* ``protein-CG-Martini-2-2.top``
|
| 286 |
+
* ``protein-CG-Martini.top``
|
| 287 |
+
* ``protein-allhdg5-4.top``
|
| 288 |
+
* ``solvent-allhdg5-4.top``
|
| 289 |
+
* ``shape.top``
|
| 290 |
+
* ``cofactors.top``
|
| 291 |
+
|
| 292 |
+
You need to edit this function to account for any additional
|
| 293 |
+
``.top`` file that is added to the ``source_path`` on top of the
|
| 294 |
+
above ones. Otherwise, read the residues manually using
|
| 295 |
+
:py:func:`read_residues_from_top_file` and :py:func:`get_resnames`
|
| 296 |
+
and add them to the relevant set, or have them as a new set.
|
| 297 |
+
|
| 298 |
+
Returns
|
| 299 |
+
-------
|
| 300 |
+
tuple
|
| 301 |
+
A tuple of the residue names supported by HADDOCK3.
|
| 302 |
+
"""
|
| 303 |
+
# paths to the `.top` files
|
| 304 |
+
carbo_top = Path(source_path, "carbohydrate.top")
|
| 305 |
+
dna_rna_all_top = Path(source_path, "dna-rna-allatom-hj-opls-1.3.top")
|
| 306 |
+
dna_rna_martini_top = Path(source_path, "dna-rna-CG-MARTINI-2-1p.top")
|
| 307 |
+
fragment_top = Path(source_path, "fragment_probes.top")
|
| 308 |
+
hemes_top = Path(source_path, "hemes-allhdg.top")
|
| 309 |
+
ions_top = Path(source_path, "ion.top")
|
| 310 |
+
protein_5_4_top = Path(source_path, "protein-allhdg5-4.top")
|
| 311 |
+
protein_martini_2_top = Path(source_path, "protein-CG-Martini-2-2.top")
|
| 312 |
+
protein_martini_top = Path(source_path, "protein-CG-Martini.top")
|
| 313 |
+
solvent_top = Path(source_path, "solvent-allhdg5-4.top")
|
| 314 |
+
shape_top = Path(source_path, "shape.top")
|
| 315 |
+
cofactors_top = Path(source_path, "cofactors.top")
|
| 316 |
+
|
| 317 |
+
# supported Residues (tuple of namedtuples)
|
| 318 |
+
supported_carbohydrates = read_residues_from_top_file(carbo_top)
|
| 319 |
+
|
| 320 |
+
_1 = read_residues_from_top_file(dna_rna_all_top)
|
| 321 |
+
_2 = read_residues_from_top_file(dna_rna_martini_top)
|
| 322 |
+
supported_nucleic = set(it.chain(_1, _2))
|
| 323 |
+
|
| 324 |
+
supported_fragments = read_residues_from_top_file(fragment_top)
|
| 325 |
+
|
| 326 |
+
supported_hemes = read_residues_from_top_file(hemes_top)
|
| 327 |
+
|
| 328 |
+
# all ions are defined here
|
| 329 |
+
supported_ions = read_residues_from_top_file(ions_top)
|
| 330 |
+
|
| 331 |
+
# separates both kinds of ions
|
| 332 |
+
supported_single_ions = \
|
| 333 |
+
tuple(ion for ion in supported_ions if len(ion.atoms) == 1)
|
| 334 |
+
supported_multiatom_ions = \
|
| 335 |
+
tuple(ion for ion in supported_ions if len(ion.atoms) > 1)
|
| 336 |
+
|
| 337 |
+
_l0 = len(supported_ions)
|
| 338 |
+
_l1 = len(supported_single_ions)
|
| 339 |
+
_l2 = len(supported_multiatom_ions)
|
| 340 |
+
if _l0 != _l1 + _l2:
|
| 341 |
+
emsg = (
|
| 342 |
+
"Ions were not parsed correctly. Some atoms were left out "
|
| 343 |
+
"when parsing single atom and multiatom ions."
|
| 344 |
+
)
|
| 345 |
+
raise ValueError(emsg)
|
| 346 |
+
|
| 347 |
+
_1 = read_residues_from_top_file(protein_5_4_top)
|
| 348 |
+
_2 = read_residues_from_top_file(protein_martini_2_top)
|
| 349 |
+
_3 = read_residues_from_top_file(protein_martini_top)
|
| 350 |
+
supported_aminoacids = set(it.chain(_1, _2, _3))
|
| 351 |
+
|
| 352 |
+
supported_solvents = read_residues_from_top_file(solvent_top)
|
| 353 |
+
supported_shape = read_residues_from_top_file(shape_top)
|
| 354 |
+
supported_cofactors = read_residues_from_top_file(cofactors_top)
|
| 355 |
+
|
| 356 |
+
# supported resnames
|
| 357 |
+
supported_carbo_resnames = get_resnames(supported_carbohydrates)
|
| 358 |
+
supported_nucleic_resnames = get_resnames(supported_nucleic)
|
| 359 |
+
supported_fragments_resnames = get_resnames(supported_fragments)
|
| 360 |
+
supported_hemes_resnames = get_resnames(supported_hemes)
|
| 361 |
+
supported_single_ions_resnames = get_resnames(supported_single_ions)
|
| 362 |
+
supported_multiatom_ions_resnames = get_resnames(supported_multiatom_ions)
|
| 363 |
+
supported_aminoacids_resnames = get_resnames(supported_aminoacids)
|
| 364 |
+
supported_solvents_resnames = get_resnames(supported_solvents)
|
| 365 |
+
supported_shape_resnames = get_resnames(supported_shape)
|
| 366 |
+
supported_cofactors_resnames = get_resnames(supported_cofactors)
|
| 367 |
+
|
| 368 |
+
# other attributes
|
| 369 |
+
for ion in supported_single_ions:
|
| 370 |
+
ion.elements = get_ion_element_from_atoms(ion.atoms)
|
| 371 |
+
|
| 372 |
+
supported_ions_elements = \
|
| 373 |
+
{ion.elements[0]: ion for ion in supported_single_ions}
|
| 374 |
+
|
| 375 |
+
supported_ions_atoms = {ion.atoms[0]: ion for ion in supported_ions}
|
| 376 |
+
|
| 377 |
+
return (
|
| 378 |
+
supported_carbo_resnames,
|
| 379 |
+
supported_nucleic_resnames,
|
| 380 |
+
supported_fragments_resnames,
|
| 381 |
+
supported_hemes_resnames,
|
| 382 |
+
supported_single_ions_resnames,
|
| 383 |
+
supported_ions_elements,
|
| 384 |
+
supported_ions_atoms,
|
| 385 |
+
supported_multiatom_ions_resnames,
|
| 386 |
+
supported_aminoacids_resnames,
|
| 387 |
+
supported_solvents_resnames,
|
| 388 |
+
supported_shape_resnames,
|
| 389 |
+
supported_cofactors_resnames,
|
| 390 |
+
)
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
# reads and assigns the supported molecules variables to this module
|
| 394 |
+
_supported_carbo_resnames, \
|
| 395 |
+
_supported_nucleic_resnames, \
|
| 396 |
+
_supported_fragments_resnames, \
|
| 397 |
+
_supported_hemes_resnames, \
|
| 398 |
+
_supported_single_ions_resnames, \
|
| 399 |
+
_supported_single_ions_elements, \
|
| 400 |
+
_supported_single_ions_atoms, \
|
| 401 |
+
_supported_multiatom_ions_resnames, \
|
| 402 |
+
_supported_aminoacids_resnames, \
|
| 403 |
+
_supported_solvents_resnames, \
|
| 404 |
+
_supported_shape_resnames, \
|
| 405 |
+
_supported_cofactors_resnames = read_supported_residues(toppar_path)
|
| 406 |
+
|
| 407 |
+
# render docstrings
|
| 408 |
+
supported_carbo_resnames = set(_supported_carbo_resnames)
|
| 409 |
+
"""Supported carbohydrate residues names."""
|
| 410 |
+
|
| 411 |
+
supported_nucleic_resnames = set(_supported_nucleic_resnames)
|
| 412 |
+
"""Supported nucleic acid residue names."""
|
| 413 |
+
|
| 414 |
+
supported_fragments_resnames = set(_supported_fragments_resnames)
|
| 415 |
+
"""Supported fragments residue names."""
|
| 416 |
+
|
| 417 |
+
supported_hemes_resnames = set(_supported_hemes_resnames)
|
| 418 |
+
"""Supported Hemes."""
|
| 419 |
+
|
| 420 |
+
supported_single_ions_resnames_map = _supported_single_ions_resnames
|
| 421 |
+
"""Supported single ion resname mapping."""
|
| 422 |
+
|
| 423 |
+
supported_single_ions_elements_map = _supported_single_ions_elements
|
| 424 |
+
"""Supported single ions elements mapping."""
|
| 425 |
+
|
| 426 |
+
supported_single_ions_atoms_map = _supported_single_ions_atoms
|
| 427 |
+
"""Supported single ion atom names mapping."""
|
| 428 |
+
|
| 429 |
+
supported_single_ions_resnames = set(_supported_single_ions_resnames)
|
| 430 |
+
"""Supported single residue names."""
|
| 431 |
+
|
| 432 |
+
supported_single_ions_elements = set(_supported_single_ions_elements)
|
| 433 |
+
"""Supported single ions elements."""
|
| 434 |
+
|
| 435 |
+
supported_single_ions_atoms = set(_supported_single_ions_atoms)
|
| 436 |
+
"""Supported single ion atom names."""
|
| 437 |
+
|
| 438 |
+
supported_multiatom_ions_resnames = set(_supported_multiatom_ions_resnames)
|
| 439 |
+
"""Supported multiatom ions residue names."""
|
| 440 |
+
|
| 441 |
+
supported_aminoacids_resnames = set(_supported_aminoacids_resnames)
|
| 442 |
+
"""Supported amino acids residue names."""
|
| 443 |
+
|
| 444 |
+
supported_solvents_resnames = set(_supported_solvents_resnames)
|
| 445 |
+
"""Supported solvents."""
|
| 446 |
+
|
| 447 |
+
supported_shape_resnames = set(_supported_shape_resnames)
|
| 448 |
+
"""Supported shape."""
|
| 449 |
+
|
| 450 |
+
supported_cofactors_resnames = set(_supported_cofactors_resnames)
|
| 451 |
+
"""Supported cofactors."""
|
| 452 |
+
|
| 453 |
+
#
|
| 454 |
+
# Residues that must be set as ATOM
|
| 455 |
+
supported_ATOM = set(it.chain(
|
| 456 |
+
supported_nucleic_resnames,
|
| 457 |
+
supported_aminoacids_resnames,
|
| 458 |
+
supported_shape_resnames,
|
| 459 |
+
))
|
| 460 |
+
"""
|
| 461 |
+
Supported ``ATOM`` residues.
|
| 462 |
+
|
| 463 |
+
These residues must be defined as ``ATOM`` records
|
| 464 |
+
in PDB files for HADDOCK3.
|
| 465 |
+
"""
|
| 466 |
+
|
| 467 |
+
# non-ion residue names
|
| 468 |
+
supported_non_ions = set(it.chain(
|
| 469 |
+
supported_ATOM,
|
| 470 |
+
supported_carbo_resnames,
|
| 471 |
+
supported_fragments_resnames,
|
| 472 |
+
supported_hemes_resnames,
|
| 473 |
+
supported_solvents_resnames,
|
| 474 |
+
supported_shape_resnames,
|
| 475 |
+
supported_cofactors_resnames,
|
| 476 |
+
))
|
| 477 |
+
|
| 478 |
+
# Residues that must be set as HETATM
|
| 479 |
+
supported_HETATM = set(it.chain(
|
| 480 |
+
supported_carbo_resnames,
|
| 481 |
+
supported_fragments_resnames,
|
| 482 |
+
supported_hemes_resnames,
|
| 483 |
+
supported_single_ions_resnames,
|
| 484 |
+
supported_multiatom_ions_resnames,
|
| 485 |
+
supported_solvents_resnames,
|
| 486 |
+
supported_cofactors_resnames,
|
| 487 |
+
))
|
| 488 |
+
"""
|
| 489 |
+
Supported ``HETATM`` residues.
|
| 490 |
+
|
| 491 |
+
These residues must be defined as ``HETATM`` records
|
| 492 |
+
in PDB files for HADDOCK3.
|
| 493 |
+
"""
|
| 494 |
+
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Useful type aliases and type variables for type-hints support.
|
| 3 |
+
|
| 4 |
+
Visit [PEP 484 Type Hints](https://peps.python.org/pep-0484/) for more help.
|
| 5 |
+
|
| 6 |
+
Variables endswith `T` are TypeVars for generic function signatures.
|
| 7 |
+
They are defined to
|
| 8 |
+
|
| 9 |
+
- accept constraint types(Any type when no type is given)
|
| 10 |
+
- accept any subclass by using keyword `bound`
|
| 11 |
+
- be parameter of Generic and subclass of Generic,
|
| 12 |
+
espacially for invariant Collections(list,sequence and so on).
|
| 13 |
+
- show more than once in generic functions to indicates that
|
| 14 |
+
these types are exactly same.
|
| 15 |
+
|
| 16 |
+
Don't import other classes, type aliases or type variables defined
|
| 17 |
+
in `haddock` into this module.
|
| 18 |
+
This may lead to circular import problem.
|
| 19 |
+
"""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
from argparse import ArgumentParser, Namespace
|
| 23 |
+
from logging import FileHandler, Handler, StreamHandler
|
| 24 |
+
from pathlib import Path
|
| 25 |
+
from typing import (
|
| 26 |
+
Any,
|
| 27 |
+
Callable,
|
| 28 |
+
Container,
|
| 29 |
+
Generator,
|
| 30 |
+
Generic,
|
| 31 |
+
Iterable,
|
| 32 |
+
Iterator,
|
| 33 |
+
Literal,
|
| 34 |
+
Mapping,
|
| 35 |
+
MutableMapping,
|
| 36 |
+
Optional,
|
| 37 |
+
Protocol,
|
| 38 |
+
Sequence,
|
| 39 |
+
Sized,
|
| 40 |
+
SupportsInt,
|
| 41 |
+
TextIO,
|
| 42 |
+
Type,
|
| 43 |
+
TypedDict,
|
| 44 |
+
TypeVar,
|
| 45 |
+
Union,
|
| 46 |
+
runtime_checkable,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
from numpy import float64
|
| 50 |
+
from numpy.typing import NDArray
|
| 51 |
+
from pandas import DataFrame
|
| 52 |
+
from pandas.core.groupby.generic import DataFrameGroupBy
|
| 53 |
+
from plotly.graph_objects import Figure
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
AnyT = TypeVar('AnyT')
|
| 57 |
+
"""Arbitrary type for generic function signatures."""
|
| 58 |
+
|
| 59 |
+
PT = TypeVar('PT')
|
| 60 |
+
"""
|
| 61 |
+
Arbitrary parameter type for generic `Callable` signatures.
|
| 62 |
+
|
| 63 |
+
For py3.11+, `ParamSpec` and `Concatenate` may be more explict
|
| 64 |
+
while making signatures longer.
|
| 65 |
+
"""
|
| 66 |
+
|
| 67 |
+
# Literals
|
| 68 |
+
ImgFormat = Literal["png", "pdf", "svg", "jpeg", "webp"]
|
| 69 |
+
"""Supported image formats by plotly."""
|
| 70 |
+
|
| 71 |
+
ExpertLevel = Literal["all", "easy", "expert", "guru"]
|
| 72 |
+
"""The expertise level of the parameters.`hidden` not inclued."""
|
| 73 |
+
|
| 74 |
+
LogLevel = Literal["INFO", "DEBUG", "ERROR", "WARNING", "CRITICAL"]
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
# Protocols
|
| 78 |
+
@runtime_checkable
|
| 79 |
+
class SupportsAdd(Protocol):
|
| 80 |
+
"""
|
| 81 |
+
An ABC with one abstract method __add__.
|
| 82 |
+
|
| 83 |
+
Can be used in `isinstance` and `issubclass`.
|
| 84 |
+
|
| 85 |
+
Assuming that the operands and the result's types
|
| 86 |
+
are same for most common situations.
|
| 87 |
+
|
| 88 |
+
Examples
|
| 89 |
+
--------
|
| 90 |
+
|
| 91 |
+
>>> isinstance(int, SupportsAdd)
|
| 92 |
+
True
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
__slots__ = ()
|
| 96 |
+
|
| 97 |
+
def __add__(self: AnyT, other: AnyT, /) -> AnyT:
|
| 98 |
+
raise NotImplementedError()
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
SupportsAddT = TypeVar("SupportsAddT", bound=SupportsAdd)
|
| 102 |
+
"""TypeVar of SupportsAdd for Generic type check."""
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@runtime_checkable
|
| 106 |
+
class SupportsRun(Protocol):
|
| 107 |
+
"""
|
| 108 |
+
An ABC with one abstract method run().
|
| 109 |
+
|
| 110 |
+
Can be used in `isinstance` and `issubclass`.
|
| 111 |
+
|
| 112 |
+
Examples
|
| 113 |
+
--------
|
| 114 |
+
|
| 115 |
+
>>> from multiprocessing import Process
|
| 116 |
+
>>> isinstance(Process, SupportsRun)
|
| 117 |
+
True
|
| 118 |
+
"""
|
| 119 |
+
|
| 120 |
+
__slots__ = ()
|
| 121 |
+
|
| 122 |
+
def run(self) -> Any:
|
| 123 |
+
"""Do something."""
|
| 124 |
+
raise NotImplementedError()
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
SupportsRunT = TypeVar("SupportsRunT", bound=SupportsRun)
|
| 128 |
+
"""TypeVar of SupportsRun for Generic type check."""
|
| 129 |
+
|
| 130 |
+
# other type alias and type variables
|
| 131 |
+
NDFloat = NDArray[float64]
|
| 132 |
+
|
| 133 |
+
FilePath = Union[str, Path]
|
| 134 |
+
|
| 135 |
+
FilePathT = TypeVar("FilePathT", bound=FilePath)
|
| 136 |
+
"""
|
| 137 |
+
Generic type variable for file paths.
|
| 138 |
+
|
| 139 |
+
If the first annotated variable is str,
|
| 140 |
+
the second annotated variable will be str instead of Path,vice versa.
|
| 141 |
+
"""
|
| 142 |
+
|
| 143 |
+
LineIterSource = Union[Iterable[str], FilePath]
|
| 144 |
+
"""An Object who can generate lines in some way."""
|
| 145 |
+
|
| 146 |
+
ParamMap = MutableMapping[str, Any]
|
| 147 |
+
"""
|
| 148 |
+
A mutable mapping object contains parameters generated from config
|
| 149 |
+
files or functions.
|
| 150 |
+
|
| 151 |
+
The keys are always `str`.
|
| 152 |
+
"""
|
| 153 |
+
|
| 154 |
+
ParamMapT = TypeVar('ParamMapT', bound=ParamMap)
|
| 155 |
+
"""
|
| 156 |
+
Generic type of `MutableMapping[str, Any]` for generic function sigunature.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
ParamDict = dict[str, Any]
|
| 160 |
+
"""
|
| 161 |
+
A dict contains parameters generated from config files or functions.
|
| 162 |
+
|
| 163 |
+
The keys are always `str`.
|
| 164 |
+
|
| 165 |
+
Can be called like `dict` and returns a python `dict`.
|
| 166 |
+
|
| 167 |
+
Examples
|
| 168 |
+
--------
|
| 169 |
+
|
| 170 |
+
>>> ParamDict(a=1) == {'a':1}
|
| 171 |
+
True
|
| 172 |
+
|
| 173 |
+
>>> ParamDict({'a':1}) == {'a':1}
|
| 174 |
+
True
|
| 175 |
+
|
| 176 |
+
>>> ParamDict().setdefault('a', 1)
|
| 177 |
+
1
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
ParamDictT = TypeVar('ParamDictT', bound=ParamDict)
|
| 181 |
+
"""
|
| 182 |
+
Generic type of `dict[str, Any]` for generic function sigunature.
|
| 183 |
+
"""
|
| 184 |
+
|
| 185 |
+
ModuleParams = dict[str, ParamDict]
|
| 186 |
+
"""A dict contains modules' parameters."""
|
| 187 |
+
|
| 188 |
+
AtomsDict = dict[str, list[str]]
|
| 189 |
+
"""
|
| 190 |
+
A dict contains all kinds of residues' atom type infomations
|
| 191 |
+
(including non-standard residue and atom type).
|
| 192 |
+
|
| 193 |
+
Key is residue name, value is a list of the residue's atom types.
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
StreamHandlerT = TypeVar('StreamHandlerT',
|
| 197 |
+
bound=Union[StreamHandler, FileHandler])
|
.venv_haddock/lib/python3.12/site-packages/haddock/deps/contact_fcc.cpp
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#include <algorithm>
|
| 2 |
+
#include <cstdio>
|
| 3 |
+
#include <cstring>
|
| 4 |
+
#include <string>
|
| 5 |
+
#include <map>
|
| 6 |
+
#include <set>
|
| 7 |
+
#include <vector>
|
| 8 |
+
#include <cmath>
|
| 9 |
+
#include <stdio.h>
|
| 10 |
+
#include <stdlib.h>
|
| 11 |
+
|
| 12 |
+
using namespace std;
|
| 13 |
+
|
| 14 |
+
struct Coor3f {
|
| 15 |
+
float x;
|
| 16 |
+
float y;
|
| 17 |
+
float z;
|
| 18 |
+
};
|
| 19 |
+
|
| 20 |
+
struct Residue {
|
| 21 |
+
int nr;
|
| 22 |
+
vector<Coor3f> coor;
|
| 23 |
+
vector<string> atom;
|
| 24 |
+
int seg;
|
| 25 |
+
};
|
| 26 |
+
|
| 27 |
+
vector<Residue> res;
|
| 28 |
+
|
| 29 |
+
bool seg_sorter (Residue res_a, Residue res_b) {
|
| 30 |
+
int segA = res_a.seg;
|
| 31 |
+
int segB = res_b.seg;
|
| 32 |
+
return (segA < segB);
|
| 33 |
+
};
|
| 34 |
+
|
| 35 |
+
int main(int argc, char *argv[]) {
|
| 36 |
+
char buf[2000];
|
| 37 |
+
|
| 38 |
+
if (argc < 3) {
|
| 39 |
+
fprintf(stderr,"ERROR: Too few arguments\n");
|
| 40 |
+
fprintf(stderr, "Usage: contact <pdb file> <cutoff>\n");
|
| 41 |
+
return 1;
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
char *filename = argv[1];
|
| 45 |
+
float cutoff = atof(argv[2]);
|
| 46 |
+
|
| 47 |
+
if (cutoff < 0 || cutoff > 100) {
|
| 48 |
+
fprintf(stderr,"ERROR: Cutoff out of range\n");
|
| 49 |
+
fprintf(stderr, "Usage: contact <pdb file> <cutoff>\n");
|
| 50 |
+
return 1;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
FILE *fil = fopen(filename, "r");
|
| 54 |
+
if (fil == NULL) {
|
| 55 |
+
fprintf(stderr, "ERROR: PDB file %s does not exist\n", filename);
|
| 56 |
+
return 1;
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
int currnr = -99999;
|
| 60 |
+
char currseg;
|
| 61 |
+
int segid = 0;
|
| 62 |
+
|
| 63 |
+
set<int> nonconv;
|
| 64 |
+
while (!feof(fil)) {
|
| 65 |
+
char code[10];
|
| 66 |
+
char atom[5];
|
| 67 |
+
if (!fgets(buf, 2000, fil)) break;
|
| 68 |
+
sscanf(buf, "%s %*d %s", code, atom);
|
| 69 |
+
|
| 70 |
+
// Ignore HETATM and hydrogens
|
| 71 |
+
if (!strncmp(code,"ATOM", 4) && ( atom[0] != 'H' && !( isdigit(atom[0]) && atom[1] == 'H' ) ) ) {
|
| 72 |
+
int nr = atoi(buf + 22);
|
| 73 |
+
char seg = buf[72];
|
| 74 |
+
if (seg != currseg) {
|
| 75 |
+
currseg = seg;
|
| 76 |
+
segid++;
|
| 77 |
+
}
|
| 78 |
+
if (nr != currnr) {
|
| 79 |
+
Residue r;
|
| 80 |
+
r.nr = nr+10000;
|
| 81 |
+
r.seg = segid;
|
| 82 |
+
res.push_back(r);
|
| 83 |
+
currnr = r.nr;
|
| 84 |
+
}
|
| 85 |
+
Residue &rcurr = res[res.size() -1];
|
| 86 |
+
Coor3f ccoor;
|
| 87 |
+
ccoor.x = atof(buf+27);
|
| 88 |
+
ccoor.y = atof(buf+38);
|
| 89 |
+
ccoor.z = atof(buf+46);
|
| 90 |
+
rcurr.coor.push_back(ccoor);
|
| 91 |
+
string atom2(atom);
|
| 92 |
+
rcurr.atom.push_back(atom2);
|
| 93 |
+
}
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
if (!res.size()) {fprintf(stderr, "ERROR: PDB file %s contains no residues\n", filename); return 1;}
|
| 97 |
+
|
| 98 |
+
// Sort the residues by segment to avoid random chain ordering problems
|
| 99 |
+
sort (res.begin(), res.end(), seg_sorter);
|
| 100 |
+
|
| 101 |
+
double cutoffsq = cutoff * cutoff;
|
| 102 |
+
|
| 103 |
+
for (int n = 0; n < res.size(); n++) {
|
| 104 |
+
vector<Coor3f> &c1 = res[n].coor;
|
| 105 |
+
int seg1 = res[n].seg;
|
| 106 |
+
for (int nn = n + 1; nn < res.size(); nn++) {
|
| 107 |
+
int seg2 = res[nn].seg;
|
| 108 |
+
if (seg1 == seg2) continue;
|
| 109 |
+
vector<Coor3f> &c2 = res[nn].coor;
|
| 110 |
+
for (int i = 0; i < res[n].coor.size(); i++) {
|
| 111 |
+
for (int ii = 0; ii < res[nn].coor.size(); ii++) {
|
| 112 |
+
double currdissq =
|
| 113 |
+
(c1[i].x - c2[ii].x) * (c1[i].x - c2[ii].x) +
|
| 114 |
+
(c1[i].y - c2[ii].y) * (c1[i].y - c2[ii].y) +
|
| 115 |
+
(c1[i].z - c2[ii].z) * (c1[i].z - c2[ii].z);
|
| 116 |
+
if (currdissq < cutoffsq) {
|
| 117 |
+
printf ("%d%d%d%d\n", res[n].nr, res[n].seg, res[nn].nr, res[nn].seg);
|
| 118 |
+
}
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
}
|
| 123 |
+
fclose(fil);
|
| 124 |
+
}
|
.venv_haddock/lib/python3.12/site-packages/haddock/deps/fast-rmsdmatrix.c
ADDED
|
@@ -0,0 +1,883 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#define _GNU_SOURCE
|
| 2 |
+
#include <stdio.h>
|
| 3 |
+
#include <stdlib.h>
|
| 4 |
+
#include <string.h>
|
| 5 |
+
#include <math.h>
|
| 6 |
+
#include <time.h>
|
| 7 |
+
#include <sys/types.h>
|
| 8 |
+
#include <unistd.h>
|
| 9 |
+
#include <limits.h>
|
| 10 |
+
#include <stdbool.h>
|
| 11 |
+
|
| 12 |
+
typedef struct traj{
|
| 13 |
+
int frames; /*!< number of frames in the trajectory */
|
| 14 |
+
double **traj_coords; /*!< 2D array of xyz coordinates */
|
| 15 |
+
int n_at; /*!< number of atoms in the atomistic structure */
|
| 16 |
+
int pairs; /*!< number of possible pairs of structures */
|
| 17 |
+
}traj;
|
| 18 |
+
|
| 19 |
+
typedef struct alignments{
|
| 20 |
+
double *rmsd_mat; /*!< condensed pairwise RMSD matrix */
|
| 21 |
+
double **coms; /*!< array of centers of mass */
|
| 22 |
+
int *ref_structs; /*!< array of reference structures */
|
| 23 |
+
int *mod_structs; /*!< array of model structures */
|
| 24 |
+
}alignments;
|
| 25 |
+
|
| 26 |
+
void failed(char message[]) {
|
| 27 |
+
printf("\n FAILED *** %s ***\n \n", message);
|
| 28 |
+
exit(1);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
struct arguments;
|
| 32 |
+
|
| 33 |
+
void zero_vec_d(double *a, int dim) {
|
| 34 |
+
|
| 35 |
+
int i;
|
| 36 |
+
for (i = 0; i < dim; i++) {
|
| 37 |
+
a[i] = 0;
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
int *i1t(int n1) {
|
| 42 |
+
int *p, *a;
|
| 43 |
+
int i;
|
| 44 |
+
if ((p = (int *) malloc((size_t) n1 * sizeof(int))) == NULL)
|
| 45 |
+
failed("i1t: failed");
|
| 46 |
+
for (i = 0, a = p; i < n1; i++)
|
| 47 |
+
*a++ = 0;
|
| 48 |
+
return p;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
double *d1t(int n1) {
|
| 52 |
+
double *p, *a;
|
| 53 |
+
int i;
|
| 54 |
+
if ((p = (double *) malloc((size_t) n1 * sizeof(double))) == NULL)
|
| 55 |
+
failed("d1t: failed n1 ");
|
| 56 |
+
for (i = 0, a = p; i < n1; i++)
|
| 57 |
+
*a++ = 0;
|
| 58 |
+
return p;
|
| 59 |
+
}
|
| 60 |
+
|
| 61 |
+
double **d2t(int n1, int n2) {
|
| 62 |
+
double **p, *a;
|
| 63 |
+
int i;
|
| 64 |
+
if ((p = (double **) malloc((size_t) n1 * sizeof(double *))) == NULL)
|
| 65 |
+
failed("d2t: failed n1");
|
| 66 |
+
if ((p[0] = (double *) malloc((size_t) n1 * n2 * sizeof(double))) == NULL)
|
| 67 |
+
failed("d2t: failed n2");
|
| 68 |
+
for (i = 0; i < n1 - 1; i++)
|
| 69 |
+
p[i + 1] = p[i] + n2;
|
| 70 |
+
for (i = 0, a = p[0]; i < n1 * n2; i++)
|
| 71 |
+
*a++ = 0;
|
| 72 |
+
return p;
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
void free_d2t(double **p) {
|
| 76 |
+
|
| 77 |
+
free(p[0]);
|
| 78 |
+
free(p);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
void free_d1t(double *p) {
|
| 82 |
+
|
| 83 |
+
free(p);
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
double scal_d(double *a, double *b, int dim) {
|
| 87 |
+
|
| 88 |
+
int i;
|
| 89 |
+
double temp;
|
| 90 |
+
|
| 91 |
+
temp = 0.0;
|
| 92 |
+
for (i = 0; i < dim; i++) {
|
| 93 |
+
temp += a[i] * b[i];
|
| 94 |
+
}
|
| 95 |
+
return (temp);
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
double norm_d(double *a, int dim) {
|
| 99 |
+
|
| 100 |
+
return (sqrt(scal_d(a, a, dim)));
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
void normalize_d(double *a, int dim) {
|
| 104 |
+
int i;
|
| 105 |
+
double temp;
|
| 106 |
+
|
| 107 |
+
temp = norm_d(a, dim);
|
| 108 |
+
for (i = 0; i < dim; i++) {
|
| 109 |
+
a[i] = a[i] / temp;
|
| 110 |
+
}
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
void vecprod_d(double *a, double *b, double *c) {
|
| 114 |
+
|
| 115 |
+
c[0] = a[1] * b[2] - a[2] * b[1];
|
| 116 |
+
c[1] = a[2] * b[0] - a[0] * b[2];
|
| 117 |
+
c[2] = a[0] * b[1] - a[1] * b[0];
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
void myjacobi(double a[][3], int n, double *d, double v[][3], int *nrot) {
|
| 121 |
+
|
| 122 |
+
int j, iq, ip, i;
|
| 123 |
+
double tresh, theta, tau, t, sm, s, h, g, c;
|
| 124 |
+
double b[3], z[3];
|
| 125 |
+
|
| 126 |
+
#define ROTATE(a, i, j, k, l) g=a[i][j];h=a[k][l];a[i][j]=g-s*(h+g*tau);a[k][l]=h+s*(g-h*tau);
|
| 127 |
+
|
| 128 |
+
for (ip = 0; ip <= (n - 1); ip++) {
|
| 129 |
+
for (iq = 0; iq <= (n - 1); iq++)
|
| 130 |
+
v[ip][iq] = 0.0;
|
| 131 |
+
v[ip][ip] = 1.0;
|
| 132 |
+
}
|
| 133 |
+
for (ip = 0; ip <= (n - 1); ip++) {
|
| 134 |
+
b[ip] = d[ip] = a[ip][ip];
|
| 135 |
+
z[ip] = 0.0;
|
| 136 |
+
}
|
| 137 |
+
*nrot = 0;
|
| 138 |
+
for (i = 1; i <= 500; i++) {
|
| 139 |
+
sm = 0.0;
|
| 140 |
+
for (ip = 0; ip <= n - 2; ip++) {
|
| 141 |
+
for (iq = ip + 1; iq <= (n - 1); iq++)
|
| 142 |
+
sm += fabs(a[ip][iq]);
|
| 143 |
+
}
|
| 144 |
+
if (sm == 0.0) {
|
| 145 |
+
return;
|
| 146 |
+
}
|
| 147 |
+
if (i < 4)
|
| 148 |
+
tresh = 0.2 * sm / (n * n);
|
| 149 |
+
else
|
| 150 |
+
tresh = 0.0;
|
| 151 |
+
for (ip = 0; ip <= n - 2; ip++) {
|
| 152 |
+
for (iq = ip + 1; iq <= (n - 1); iq++) {
|
| 153 |
+
g = 100.0 * fabs(a[ip][iq]);
|
| 154 |
+
if (i > 4 && (fabs((fabs(d[ip]) + g) - fabs(d[ip])) < 1.0e-6)
|
| 155 |
+
&& (fabs((fabs(d[iq]) + g) - fabs(d[iq])) < 1.0e-6))
|
| 156 |
+
a[ip][iq] = 0.0;
|
| 157 |
+
else if (fabs(a[ip][iq]) > tresh) {
|
| 158 |
+
h = d[iq] - d[ip];
|
| 159 |
+
if (fabs((fabs(h) + g) - fabs(h)) < 1.0e-6)
|
| 160 |
+
t = (a[ip][iq]) / h;
|
| 161 |
+
else {
|
| 162 |
+
theta = 0.5 * h / (a[ip][iq]);
|
| 163 |
+
t = 1.0 / (fabs(theta) + sqrt(1.0 + theta * theta));
|
| 164 |
+
if (theta < 0.0)
|
| 165 |
+
t = -t;
|
| 166 |
+
}
|
| 167 |
+
c = 1.0 / sqrt(1 + t * t);
|
| 168 |
+
s = t * c;
|
| 169 |
+
tau = s / (1.0 + c);
|
| 170 |
+
h = t * a[ip][iq];
|
| 171 |
+
z[ip] -= h;
|
| 172 |
+
z[iq] += h;
|
| 173 |
+
d[ip] -= h;
|
| 174 |
+
d[iq] += h;
|
| 175 |
+
a[ip][iq] = 0.0;
|
| 176 |
+
for (j = 0; j <= ip - 1; j++) {
|
| 177 |
+
ROTATE (a, j, ip, j, iq)
|
| 178 |
+
}
|
| 179 |
+
for (j = ip + 1; j <= iq - 1; j++) {
|
| 180 |
+
ROTATE (a, ip, j, j, iq)
|
| 181 |
+
}
|
| 182 |
+
for (j = iq + 1; j <= (n - 1); j++) {
|
| 183 |
+
ROTATE (a, ip, j, iq, j)
|
| 184 |
+
}
|
| 185 |
+
for (j = 0; j <= (n - 1); j++) {
|
| 186 |
+
ROTATE (v, j, ip, j, iq)
|
| 187 |
+
}
|
| 188 |
+
++(*nrot);
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
}
|
| 192 |
+
for (ip = 0; ip <= (n - 1); ip++) {
|
| 193 |
+
b[ip] += z[ip];
|
| 194 |
+
d[ip] = b[ip];
|
| 195 |
+
z[ip] = 0.0;
|
| 196 |
+
}
|
| 197 |
+
}
|
| 198 |
+
printf("Too many iterations in routine JACOBI %lf\n", sm);
|
| 199 |
+
/* exit (1); */
|
| 200 |
+
#undef ROTATE
|
| 201 |
+
}
|
| 202 |
+
|
| 203 |
+
int columns(char* string){
|
| 204 |
+
/**
|
| 205 |
+
* routine that returns the number of columns for each row inside the file chosen.
|
| 206 |
+
*
|
| 207 |
+
* Parameter
|
| 208 |
+
* ----------
|
| 209 |
+
*
|
| 210 |
+
* `string` : string token in account
|
| 211 |
+
*/
|
| 212 |
+
|
| 213 |
+
int counter = 0;
|
| 214 |
+
|
| 215 |
+
while(string){
|
| 216 |
+
counter++;
|
| 217 |
+
string = strtok(NULL, " \t\v\r\n");
|
| 218 |
+
}
|
| 219 |
+
return counter;
|
| 220 |
+
}
|
| 221 |
+
|
| 222 |
+
int n_rows (FILE *f){
|
| 223 |
+
/**
|
| 224 |
+
* routine that returns the number of rows in a file. It counts correctly this number even if the last row does not present \n
|
| 225 |
+
*
|
| 226 |
+
* Parameter
|
| 227 |
+
* ----------
|
| 228 |
+
*
|
| 229 |
+
* `f` : FILE structure that represents the file opened.
|
| 230 |
+
*/
|
| 231 |
+
|
| 232 |
+
size_t rows_i = 0, n = 0;
|
| 233 |
+
char *buf = NULL;
|
| 234 |
+
|
| 235 |
+
fseek(f, 0, SEEK_SET);
|
| 236 |
+
|
| 237 |
+
while(getline(&buf, &n, f) != -1) rows_i++;
|
| 238 |
+
|
| 239 |
+
free(buf);
|
| 240 |
+
|
| 241 |
+
return rows_i;
|
| 242 |
+
}
|
| 243 |
+
|
| 244 |
+
int get_pair(int nmodels, int idx, int ij_arr[2]){
|
| 245 |
+
if (nmodels < 0 || idx < 0){
|
| 246 |
+
printf("get_pair cannot accept negative numbers");
|
| 247 |
+
printf("Input is %d , %d", nmodels, idx);
|
| 248 |
+
exit(EXIT_FAILURE);
|
| 249 |
+
}
|
| 250 |
+
// solve the second degree equation
|
| 251 |
+
int b = 1 - (2 * nmodels);
|
| 252 |
+
int i = (-b - sqrt(b * b - 8 * idx)) / 2;
|
| 253 |
+
int j = idx + i * (b + i + 2) / 2 + 1;
|
| 254 |
+
ij_arr[0] = i;
|
| 255 |
+
ij_arr[1] = j;
|
| 256 |
+
return 0;
|
| 257 |
+
}
|
| 258 |
+
|
| 259 |
+
double optimal_alignment(double **x, double **y, int cgnum, double u[][3]) {
|
| 260 |
+
/**
|
| 261 |
+
* routine that computes the Kabsch alignment and the rmsd between two configurations
|
| 262 |
+
*
|
| 263 |
+
*
|
| 264 |
+
* Parameters
|
| 265 |
+
* ----------
|
| 266 |
+
*
|
| 267 |
+
* `x`, `y` : CG structures
|
| 268 |
+
*
|
| 269 |
+
* `cgnum` : length of CG mapping
|
| 270 |
+
*
|
| 271 |
+
* `u` : rotation matrix
|
| 272 |
+
*/
|
| 273 |
+
void myjacobi(double a[][3], int n, double *d, double v[][3], int *nrot);
|
| 274 |
+
int i, j, k, sign[3], order[3], nrot;
|
| 275 |
+
double e, e0;
|
| 276 |
+
double r[3][3], rt[3][3], temp; //, **x, **y;
|
| 277 |
+
double a[3][3], eval[3], evec[3][3];
|
| 278 |
+
double eigenvalues[3], eigenvectors[3][3], b[3][3];
|
| 279 |
+
int speak = 1;
|
| 280 |
+
|
| 281 |
+
e0 = 0.0;
|
| 282 |
+
for (i = 0; i < cgnum; i++) {
|
| 283 |
+
e0 += 0.5 * norm_d(x[i], 3) * norm_d(x[i], 3);
|
| 284 |
+
e0 += 0.5 * norm_d(y[i], 3) * norm_d(y[i], 3);
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
for (i = 0; i < 3; i++) {
|
| 288 |
+
for (j = 0; j < 3; j++) {
|
| 289 |
+
r[i][j] = 0.0;
|
| 290 |
+
for (k = 0; k < cgnum; k++) {
|
| 291 |
+
r[i][j] += y[k][i] * x[k][j];
|
| 292 |
+
}
|
| 293 |
+
rt[j][i] = r[i][j];
|
| 294 |
+
}
|
| 295 |
+
}
|
| 296 |
+
|
| 297 |
+
if (isnan(e0) == 1) printf("Found a NaN in Kabsch alignment at checkpoint 1\n");
|
| 298 |
+
|
| 299 |
+
for (i = 0; i < 3; i++) {
|
| 300 |
+
for (j = 0; j < 3; j++) {
|
| 301 |
+
a[i][j] = 0;
|
| 302 |
+
for (k = 0; k < 3; k++) {
|
| 303 |
+
a[i][j] += rt[i][k] * r[k][j];
|
| 304 |
+
}
|
| 305 |
+
}
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
myjacobi(a, 3, eval, evec, &nrot);
|
| 309 |
+
/* we add small quantities in order to remove potentially dangerous degeneracies */
|
| 310 |
+
if (isnan(eval[0]) == 1) printf("Found a NaN in Kabsch alignment at checkpoint 2\n");
|
| 311 |
+
if (isnan(eval[1]) == 1) printf("Found a NaN in Kabsch alignment at checkpoint 3\n");
|
| 312 |
+
if (isnan(eval[2]) == 1) printf("Found a NaN in Kabsch alignment at checkpoint 4\n");
|
| 313 |
+
|
| 314 |
+
eval[0] += 0.0000000000000001;
|
| 315 |
+
eval[1] += 0.00000000000000001;
|
| 316 |
+
eval[2] += 0.00000000000000002;
|
| 317 |
+
|
| 318 |
+
if ((eval[0] < eval[1]) && (eval[0] < eval[2])) {
|
| 319 |
+
order[0] = 1;
|
| 320 |
+
order[1] = 2;
|
| 321 |
+
order[2] = 0;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
if ((eval[1] < eval[0]) && (eval[1] < eval[2])) {
|
| 325 |
+
order[0] = 0;
|
| 326 |
+
order[1] = 2;
|
| 327 |
+
order[2] = 1;
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
if ((eval[2] < eval[0]) && (eval[2] < eval[1])) {
|
| 331 |
+
order[0] = 0;
|
| 332 |
+
order[1] = 1;
|
| 333 |
+
order[2] = 2;
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
for (i = 0; i < 3; i++) {
|
| 337 |
+
eigenvalues[i] = eval[order[i]];
|
| 338 |
+
for (j = 0; j < 3; j++) {
|
| 339 |
+
eigenvectors[i][j] = evec[j][order[i]];
|
| 340 |
+
}
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
normalize_d(eigenvectors[0], 3);
|
| 344 |
+
normalize_d(eigenvectors[1], 3);
|
| 345 |
+
vecprod_d(eigenvectors[0], eigenvectors[1], eigenvectors[2]);
|
| 346 |
+
normalize_d(eigenvectors[2], 3);
|
| 347 |
+
|
| 348 |
+
for (i = 0; i < 2; i++) {
|
| 349 |
+
for (j = 0; j < 3; j++) {
|
| 350 |
+
b[i][j] = 0;
|
| 351 |
+
for (k = 0; k < 3; k++) {
|
| 352 |
+
b[i][j] += r[j][k] * eigenvectors[i][k];
|
| 353 |
+
}
|
| 354 |
+
}
|
| 355 |
+
normalize_d(b[i], 3);
|
| 356 |
+
}
|
| 357 |
+
|
| 358 |
+
vecprod_d(b[0], b[1], b[2]);
|
| 359 |
+
normalize_d(b[2], 3);
|
| 360 |
+
|
| 361 |
+
temp = 0.0;
|
| 362 |
+
for (i = 0; i < 3; i++) {
|
| 363 |
+
for (j = 0; j < 3; j++) {
|
| 364 |
+
temp += b[2][i] * r[i][j] * eigenvectors[2][j];
|
| 365 |
+
}
|
| 366 |
+
}
|
| 367 |
+
sign[2] = +1;
|
| 368 |
+
if (temp < 0)
|
| 369 |
+
sign[2] = -1;
|
| 370 |
+
sign[0] = sign[1] = 1;
|
| 371 |
+
|
| 372 |
+
if (fabs(eigenvalues[2]) < 0.0000001) {
|
| 373 |
+
e = e0 - sqrt(eigenvalues[0]) - sqrt(eigenvalues[1]);
|
| 374 |
+
} else {
|
| 375 |
+
e = e0 - sqrt(eigenvalues[0]) - sqrt(eigenvalues[1]) - sign[2] * sqrt(eigenvalues[2]);
|
| 376 |
+
}
|
| 377 |
+
|
| 378 |
+
if (isnan(e) == 1) {
|
| 379 |
+
printf("Found a NaN in Kabsch alignment at checkpoint 5 | \n");
|
| 380 |
+
printf("e %lf e0 %lf e1 %lf e2 %lf e3 %lf\n", e, e0, eigenvalues[0], eigenvalues[1], eigenvalues[2]);
|
| 381 |
+
}
|
| 382 |
+
/********************/
|
| 383 |
+
e = 2.0 * e / cgnum;
|
| 384 |
+
if (e < 0.0) {
|
| 385 |
+
if (fabs(e) < 1.0e-3) {
|
| 386 |
+
if (speak == 1) {
|
| 387 |
+
//printf("Warning. In Kabsch alignment found slightly negative value of e (%e). Identical structures? Setting it to 0.000001.\n",
|
| 388 |
+
// e);
|
| 389 |
+
e = 0.000001;
|
| 390 |
+
}
|
| 391 |
+
}
|
| 392 |
+
/* occasionally, when dealing with two practically identical configurations
|
| 393 |
+
the value of e may be slightly negative due to the small offsets and roundoff errors.
|
| 394 |
+
In this case we set it equal to zero. */
|
| 395 |
+
else {
|
| 396 |
+
FILE *fe;
|
| 397 |
+
fe = fopen("error.dat", "w");
|
| 398 |
+
fprintf(fe, "Error. In Kabsch alignment found negative value of e: (%lf)\n", e);
|
| 399 |
+
printf("Error. In Kabsch alignment found negative value of e: (%lf)\n", e);
|
| 400 |
+
fclose(fe);
|
| 401 |
+
exit(EXIT_FAILURE);
|
| 402 |
+
}
|
| 403 |
+
}
|
| 404 |
+
e = sqrt(e);
|
| 405 |
+
if (isnan(e) == 1) printf("Found a NaN in Kabsch alignment at checkpoint 6\n");
|
| 406 |
+
/********************/
|
| 407 |
+
// filling rotation_matrix
|
| 408 |
+
for (i = 0; i < 3; i++) {
|
| 409 |
+
for (j = 0; j < 3; j++) {
|
| 410 |
+
u[i][j] = 0.0;
|
| 411 |
+
for (k = 0; k < 3; k++) {
|
| 412 |
+
u[i][j] += b[k][i] * eigenvectors[k][j];
|
| 413 |
+
}
|
| 414 |
+
}
|
| 415 |
+
}
|
| 416 |
+
return (e);
|
| 417 |
+
}
|
| 418 |
+
|
| 419 |
+
void cycle_ilrmsd(traj *Trajectory, traj *Ligand_Trajectory, alignments *align, int start_pair[2]) {
|
| 420 |
+
/**
|
| 421 |
+
* routine that cycles over pairs of frames in a trajectory, aligning on the receptor
|
| 422 |
+
* and computing the interface ligand rmsd
|
| 423 |
+
*
|
| 424 |
+
* Parameters
|
| 425 |
+
* ----------
|
| 426 |
+
*
|
| 427 |
+
* `Trajectory` : traj object
|
| 428 |
+
*
|
| 429 |
+
* `align` : alignments object
|
| 430 |
+
*
|
| 431 |
+
* `start_pair` : pair of structures to begin with
|
| 432 |
+
*/
|
| 433 |
+
int n;
|
| 434 |
+
int i, j;
|
| 435 |
+
double **x, **y, **xlig, **ylig, **ylig_rot;
|
| 436 |
+
double u[3][3], cm1[3], cm2[3];
|
| 437 |
+
int rot_idx;
|
| 438 |
+
// allocating vectors
|
| 439 |
+
x = d2t(Trajectory->n_at, 3);
|
| 440 |
+
xlig = d2t(Ligand_Trajectory->n_at, 3);
|
| 441 |
+
y = d2t(Trajectory->n_at, 3);
|
| 442 |
+
ylig = d2t(Ligand_Trajectory->n_at, 3);
|
| 443 |
+
ylig_rot = d2t(Ligand_Trajectory->n_at, 3);
|
| 444 |
+
int ref = start_pair[0];
|
| 445 |
+
int mod = start_pair[1];
|
| 446 |
+
int old_ref = ref - 1;
|
| 447 |
+
|
| 448 |
+
for (n = 0; n < Trajectory->pairs; n++) {
|
| 449 |
+
if (ref != old_ref) {
|
| 450 |
+
// recalculate com and translate structure
|
| 451 |
+
zero_vec_d(cm1, 3);
|
| 452 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 453 |
+
for (j = 0; j < 3; j++) {
|
| 454 |
+
cm1[j] += Trajectory->traj_coords[ref][i * 3 + j] / Trajectory->n_at;
|
| 455 |
+
}
|
| 456 |
+
}
|
| 457 |
+
// filling structure
|
| 458 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 459 |
+
for (j = 0; j < 3; j++) {
|
| 460 |
+
x[i][j] = Trajectory->traj_coords[ref][i * 3 + j] - cm1[j];
|
| 461 |
+
}
|
| 462 |
+
}
|
| 463 |
+
// now the ligand
|
| 464 |
+
for (i = 0; i < Ligand_Trajectory->n_at; i++) {
|
| 465 |
+
for (j = 0; j < 3; j++) {
|
| 466 |
+
xlig[i][j] = Ligand_Trajectory->traj_coords[ref][i * 3 + j] - cm1[j];
|
| 467 |
+
}
|
| 468 |
+
}
|
| 469 |
+
old_ref += 1;
|
| 470 |
+
}
|
| 471 |
+
|
| 472 |
+
// second structure
|
| 473 |
+
zero_vec_d(cm2, 3);
|
| 474 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 475 |
+
for (j = 0; j < 3; j++) {
|
| 476 |
+
cm2[j] += Trajectory->traj_coords[mod][i * 3 + j] / Trajectory->n_at;
|
| 477 |
+
}
|
| 478 |
+
}
|
| 479 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 480 |
+
for (j = 0; j < 3; j++) {
|
| 481 |
+
y[i][j] = Trajectory->traj_coords[mod][i * 3 + j] - cm2[j];
|
| 482 |
+
}
|
| 483 |
+
}
|
| 484 |
+
// now ylig
|
| 485 |
+
for (i = 0; i < Ligand_Trajectory->n_at; i++) {
|
| 486 |
+
for (j = 0; j < 3; j++) {
|
| 487 |
+
ylig[i][j] = Ligand_Trajectory->traj_coords[mod][i * 3 + j] - cm2[j];
|
| 488 |
+
}
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
// Alignment AND RMSD computation
|
| 492 |
+
align->rmsd_mat[n] = optimal_alignment(x, y, Trajectory->n_at, u);
|
| 493 |
+
align->ref_structs[n] = ref + 1;
|
| 494 |
+
align->mod_structs[n] = mod + 1;
|
| 495 |
+
|
| 496 |
+
// now correcting the coordinates of the ligand
|
| 497 |
+
for (i = 0; i < Ligand_Trajectory->n_at; i++) {
|
| 498 |
+
for (j = 0; j < 3; j++) {
|
| 499 |
+
ylig_rot[i][j] = 0.0;
|
| 500 |
+
for (rot_idx = 0; rot_idx < 3; rot_idx++) {
|
| 501 |
+
ylig_rot[i][j] += u[rot_idx][j] * ylig[i][rot_idx];
|
| 502 |
+
}
|
| 503 |
+
}
|
| 504 |
+
}
|
| 505 |
+
// calculate rmsd between ligands
|
| 506 |
+
double ilrmsd = 0.0;
|
| 507 |
+
double delta;
|
| 508 |
+
for (i = 0; i < Ligand_Trajectory->n_at; i++) {
|
| 509 |
+
for (j = 0; j < 3; j++) {
|
| 510 |
+
delta = ylig_rot[i][j] - xlig[i][j];
|
| 511 |
+
ilrmsd += delta * delta;
|
| 512 |
+
}
|
| 513 |
+
}
|
| 514 |
+
|
| 515 |
+
ilrmsd = sqrt(ilrmsd / Ligand_Trajectory->n_at);
|
| 516 |
+
// the value before was the receptor interface rmsd, now let's change it to the ligand interface rmsd
|
| 517 |
+
align->rmsd_mat[n] = ilrmsd;
|
| 518 |
+
|
| 519 |
+
// update idx
|
| 520 |
+
if (mod == Trajectory->frames - 1) {
|
| 521 |
+
ref += 1;
|
| 522 |
+
mod = ref + 1;
|
| 523 |
+
}
|
| 524 |
+
else {
|
| 525 |
+
mod += 1;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
}
|
| 529 |
+
free_d2t(x);
|
| 530 |
+
free_d2t(y);
|
| 531 |
+
free_d2t(xlig);
|
| 532 |
+
free_d2t(ylig);
|
| 533 |
+
free_d2t(ylig_rot);
|
| 534 |
+
}
|
| 535 |
+
|
| 536 |
+
void cycle_rmsd(traj *Trajectory, alignments *align, int start_pair[2]) {
|
| 537 |
+
/**
|
| 538 |
+
* routine that cycles over all pairs of frames in a trajectory, calling `optimal_alignment`
|
| 539 |
+
*
|
| 540 |
+
* Parameters
|
| 541 |
+
* ----------
|
| 542 |
+
*
|
| 543 |
+
* `Trajectory` : traj object
|
| 544 |
+
*
|
| 545 |
+
* `align` : alignments object
|
| 546 |
+
*
|
| 547 |
+
* `start_pair` : pair of structures to begin with
|
| 548 |
+
*/
|
| 549 |
+
int n;
|
| 550 |
+
int i, j;
|
| 551 |
+
double **x, **y;
|
| 552 |
+
double u[3][3], cm1[3], cm2[3];
|
| 553 |
+
printf("calculating rotation matrices..\n");
|
| 554 |
+
// allocating vectors
|
| 555 |
+
x = d2t(Trajectory->n_at, 3);
|
| 556 |
+
y = d2t(Trajectory->n_at, 3);
|
| 557 |
+
int ref = start_pair[0];
|
| 558 |
+
int mod = start_pair[1];
|
| 559 |
+
int old_ref = ref - 1;
|
| 560 |
+
//for (n = 0; n < Trajectory->frames; n++) {
|
| 561 |
+
for (n = 0; n < Trajectory->pairs; n++) {
|
| 562 |
+
if (ref != old_ref) {
|
| 563 |
+
// recalculate com and translate structure
|
| 564 |
+
|
| 565 |
+
zero_vec_d(cm1, 3);
|
| 566 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 567 |
+
for (j = 0; j < 3; j++) {
|
| 568 |
+
cm1[j] += Trajectory->traj_coords[ref][i * 3 + j] / Trajectory->n_at;
|
| 569 |
+
}
|
| 570 |
+
}
|
| 571 |
+
// filling structure
|
| 572 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 573 |
+
for (j = 0; j < 3; j++) {
|
| 574 |
+
x[i][j] = Trajectory->traj_coords[ref][i * 3 + j] - cm1[j];
|
| 575 |
+
}
|
| 576 |
+
}
|
| 577 |
+
old_ref += 1;
|
| 578 |
+
}
|
| 579 |
+
// second structure
|
| 580 |
+
zero_vec_d(cm2, 3);
|
| 581 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 582 |
+
for (j = 0; j < 3; j++) {
|
| 583 |
+
cm2[j] += Trajectory->traj_coords[mod][i * 3 + j] / Trajectory->n_at;
|
| 584 |
+
}
|
| 585 |
+
}
|
| 586 |
+
for (i = 0; i < Trajectory->n_at; i++) {
|
| 587 |
+
for (j = 0; j < 3; j++) {
|
| 588 |
+
y[i][j] = Trajectory->traj_coords[mod][i * 3 + j] - cm2[j];
|
| 589 |
+
}
|
| 590 |
+
}
|
| 591 |
+
// Alignment AND RMSD computation
|
| 592 |
+
align->rmsd_mat[n] = optimal_alignment(x, y, Trajectory->n_at, u);
|
| 593 |
+
align->ref_structs[n] = ref + 1;
|
| 594 |
+
align->mod_structs[n] = mod + 1;
|
| 595 |
+
|
| 596 |
+
// update idx
|
| 597 |
+
if (mod == Trajectory->frames - 1) {
|
| 598 |
+
ref += 1;
|
| 599 |
+
mod = ref + 1;
|
| 600 |
+
}
|
| 601 |
+
else {
|
| 602 |
+
mod += 1;
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
}
|
| 606 |
+
free_d2t(x);
|
| 607 |
+
free_d2t(y);
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
void read_TrajectoryFile(char *TrajFileName, traj *Trajectory){
|
| 611 |
+
/**
|
| 612 |
+
* routine that reads the input xyz coordinate file
|
| 613 |
+
*
|
| 614 |
+
* Parameters
|
| 615 |
+
* ----------
|
| 616 |
+
*
|
| 617 |
+
* `TrajFileName` : trajectory filename
|
| 618 |
+
*
|
| 619 |
+
* `Trajectory` : traj object
|
| 620 |
+
*/
|
| 621 |
+
|
| 622 |
+
FILE *ft; // trajectory file;
|
| 623 |
+
FILE *fe; // declaring error file;
|
| 624 |
+
|
| 625 |
+
int rows_i, cols_i, i, p, frame_idx, j, count;
|
| 626 |
+
size_t line_buf_size = 0;
|
| 627 |
+
|
| 628 |
+
char *token;
|
| 629 |
+
char *token_arr[100]; //*string, *line;
|
| 630 |
+
char *string = NULL;
|
| 631 |
+
char *line;
|
| 632 |
+
|
| 633 |
+
/* Opening and check if it exist and if it is empty */
|
| 634 |
+
ft = fopen(TrajFileName, "r");
|
| 635 |
+
printf("Reading Trajectory FILE %s\n", TrajFileName);
|
| 636 |
+
|
| 637 |
+
//check_empty_file(ft, TrajFileName);
|
| 638 |
+
|
| 639 |
+
rows_i = n_rows(ft); // Number of rows in trajectory file "ft".
|
| 640 |
+
fseek(ft, 0, SEEK_SET);
|
| 641 |
+
|
| 642 |
+
line = (char *) malloc (200); // Allocate char line with size (lenght) = 200;
|
| 643 |
+
// We are sure that the lenght of each line is less than 200
|
| 644 |
+
|
| 645 |
+
/* Initialize the 2D-array Trajectory->traj_coords[][] */
|
| 646 |
+
for(i = 0; i < Trajectory->frames; i++){
|
| 647 |
+
for(j = 0; j < Trajectory->n_at; j++){
|
| 648 |
+
Trajectory->traj_coords[i][3 * j + 0] = 0.0;
|
| 649 |
+
Trajectory->traj_coords[i][3 * j + 1] = 0.0;
|
| 650 |
+
Trajectory->traj_coords[i][3 * j + 2] = 0.0;
|
| 651 |
+
}
|
| 652 |
+
}
|
| 653 |
+
|
| 654 |
+
/* Checking for empty rows;
|
| 655 |
+
* Checking that there are ONLY rows with one column and three columns
|
| 656 |
+
* Checking that the rows with one column correspond to an integer number i.e. the number of atoms;
|
| 657 |
+
* Checking that the rows with three columns are float corresponding to x,y,z trajectory coordinate. */
|
| 658 |
+
|
| 659 |
+
frame_idx = 0; // Initialize frame index to 0
|
| 660 |
+
p = 0; // Initialize counter "p" to 0
|
| 661 |
+
|
| 662 |
+
for(i=0; i<rows_i; i++){
|
| 663 |
+
if(p>=3*Trajectory->n_at) // p increases from 0 to 3*atomnum i.e. p=[0;3*230) i.e. p = [0;689]
|
| 664 |
+
p = 0;
|
| 665 |
+
|
| 666 |
+
getline(&string, &line_buf_size, ft); // Reading entire line;
|
| 667 |
+
|
| 668 |
+
strcpy(line, string); // Copying "string" in "line"; we need it in case of three columns.
|
| 669 |
+
|
| 670 |
+
//if( i != (Trajectory->n_at + 2)*(frame_idx-1) + 1) // Checking for empty rows except for the 2nd row of each frame representing the title
|
| 671 |
+
// check_empty_rows(string); // that could also be an empty string
|
| 672 |
+
|
| 673 |
+
token = strtok(string, " \t\v\r\n"); // Splitting the string-line in columns separated by spaces, tabs, or \n or \v or \r
|
| 674 |
+
|
| 675 |
+
cols_i = columns(token); // Counting the number of columns in each row of file.
|
| 676 |
+
|
| 677 |
+
|
| 678 |
+
if(i!=(Trajectory->n_at + 2)*(frame_idx-1) + 1){ // exclude the 2nd row of each frame
|
| 679 |
+
|
| 680 |
+
if(cols_i == 1){
|
| 681 |
+
|
| 682 |
+
if(i != (Trajectory->n_at + 2)*frame_idx) {
|
| 683 |
+
printf("Error. The %dth frame contains a different number of rows. Each frame must have %d rows\n", frame_idx+1, Trajectory->n_at + 2);
|
| 684 |
+
exit(EXIT_FAILURE);
|
| 685 |
+
}
|
| 686 |
+
else{
|
| 687 |
+
frame_idx++;
|
| 688 |
+
if(frame_idx>Trajectory->frames){
|
| 689 |
+
fe = fopen("error.dat", "w");
|
| 690 |
+
fprintf(fe, "Error. The number of trajectory frames is higher than the declared one in parameter file (%d).\nAborting\n", Trajectory->frames);
|
| 691 |
+
fclose(fe);
|
| 692 |
+
printf("Error. The number of trajectory frames is higher than the declared one in parameter file (%d).\nAborting\n", Trajectory->frames);
|
| 693 |
+
exit(EXIT_FAILURE);
|
| 694 |
+
}
|
| 695 |
+
//check_int_string(string, i, TrajFileName); // Checking that each row is an INTEGER number.
|
| 696 |
+
if(atoi(string) != Trajectory->n_at){
|
| 697 |
+
fe = fopen("error.dat","w");
|
| 698 |
+
fprintf(fe,"Error. The number of atoms at %dth row has length (%d) different from atomnum(%d). Aborting\n",\
|
| 699 |
+
i+1,atoi(string),Trajectory->n_at);
|
| 700 |
+
printf("Error. The number of atoms at %dth row has length (%d) different from atomnum(%d). Aborting\n",\
|
| 701 |
+
i+1,atoi(string),Trajectory->n_at);
|
| 702 |
+
fclose(fe);
|
| 703 |
+
exit(EXIT_FAILURE);
|
| 704 |
+
}
|
| 705 |
+
}
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
if(cols_i == 2){
|
| 709 |
+
|
| 710 |
+
if(i != (Trajectory->n_at + 2)*frame_idx + 1){
|
| 711 |
+
fe = fopen("error.dat", "w");
|
| 712 |
+
fprintf(fe,"Error. Each row must not contain 2 columns (except the title in the 2nd row of each frame that can contain N columns).\n\
|
| 713 |
+
ONLY 1 or 4 columns are allowed in Trajectory (%dth row has 2 columns)\n", i+1);
|
| 714 |
+
|
| 715 |
+
printf("Error. Each row must not contain 2 columns (except the title in the 2nd row of each frame that can contain N columns)\n\
|
| 716 |
+
ONLY 1 or 4 columns are allowed in Trajectory (%dth row has 2 columns.\n", i+1);
|
| 717 |
+
fclose(fe);
|
| 718 |
+
exit(EXIT_FAILURE);
|
| 719 |
+
}
|
| 720 |
+
}
|
| 721 |
+
|
| 722 |
+
if(cols_i == 3){
|
| 723 |
+
|
| 724 |
+
if(i != (Trajectory->n_at + 2)*frame_idx + 1){
|
| 725 |
+
fe = fopen("error.dat", "w");
|
| 726 |
+
fprintf(fe,"Error. Each row must not contain 3 columns (except the title in the 2nd row of each frame that can contain N columns). \
|
| 727 |
+
ONLY 1 or 4 columns are allowed in Trajectory (%dth row has 3 columns)\n", i+1);
|
| 728 |
+
|
| 729 |
+
printf("Error. Each row must not contain 3 columns (except the title in the 2nd row of each frame that can contain N columns) \
|
| 730 |
+
ONLY 1 or 4 columns are allowed in Trajectory (%dth row has 3 columns.\n", i+1);
|
| 731 |
+
fclose(fe);
|
| 732 |
+
exit(EXIT_FAILURE);
|
| 733 |
+
}
|
| 734 |
+
}
|
| 735 |
+
|
| 736 |
+
if(cols_i == 4){
|
| 737 |
+
if(i != (Trajectory->n_at + 2)*frame_idx){
|
| 738 |
+
token_arr[0] = strtok(line, " \t\v\r\n");
|
| 739 |
+
|
| 740 |
+
count = 0;
|
| 741 |
+
while(token_arr[count]){
|
| 742 |
+
count++;
|
| 743 |
+
token_arr[count] = strtok(NULL, " \t\v\r\n");
|
| 744 |
+
}
|
| 745 |
+
|
| 746 |
+
for (j=1; j <= count-1 ; j++){
|
| 747 |
+
//check_float_string(token_arr[j], i, TrajFileName); // Checking that each row is an FLOAT number.
|
| 748 |
+
Trajectory->traj_coords[frame_idx-1][p] = atof(token_arr[j]); // Assigning each float-string to traj_coords[i][j] 2D-array
|
| 749 |
+
p++;
|
| 750 |
+
}
|
| 751 |
+
|
| 752 |
+
}
|
| 753 |
+
|
| 754 |
+
else{
|
| 755 |
+
printf("Error. Each row of the frame (except the 1st row containing the number of atoms and the 2nd row containing the title),\n\
|
| 756 |
+
must contain 4 columns corresponding to at_name, x, y, and z coodinates. Check also if there is one extra row in %dth frame\n",
|
| 757 |
+
frame_idx);
|
| 758 |
+
exit(EXIT_FAILURE);
|
| 759 |
+
}
|
| 760 |
+
}
|
| 761 |
+
|
| 762 |
+
if(cols_i > 4 ){
|
| 763 |
+
if(i != (Trajectory->n_at + 2)*frame_idx){
|
| 764 |
+
fe = fopen("error.dat","w");
|
| 765 |
+
fprintf(fe, "Error. The maximum number of columns allowed is 4. The %dth row of your file contains %d columns\n", i+1, cols_i);
|
| 766 |
+
printf("Error. The maximum number of columns allowed is 4. The %dth row of your file contains %d columns\n", i+1, cols_i);
|
| 767 |
+
fclose(fe);
|
| 768 |
+
exit(EXIT_FAILURE);
|
| 769 |
+
}
|
| 770 |
+
}
|
| 771 |
+
}
|
| 772 |
+
|
| 773 |
+
} // END FOR LOOP
|
| 774 |
+
|
| 775 |
+
free(string);
|
| 776 |
+
//free(token);
|
| 777 |
+
free(line);
|
| 778 |
+
fclose(ft);// Close trajectory file.
|
| 779 |
+
// 1st check: frame_idx must be = frames
|
| 780 |
+
if (frame_idx != Trajectory->frames) {
|
| 781 |
+
fe = fopen("error.dat", "w");
|
| 782 |
+
fprintf(fe, "Error. Frames completed: %d, while declared frames in parameter file are %d. Trajectory incomplete.\nAborting\n",frame_idx,\
|
| 783 |
+
Trajectory->frames);
|
| 784 |
+
fclose(fe);
|
| 785 |
+
printf("Error. Frames completed: %d, while declared frames in parameter file are %d. Trajectory incomplete.\nAborting\n",frame_idx,\
|
| 786 |
+
Trajectory->frames);
|
| 787 |
+
exit(EXIT_FAILURE);
|
| 788 |
+
}
|
| 789 |
+
|
| 790 |
+
// final check: frame_idx corresponds with what we expect but the number of row is not the same => It means that
|
| 791 |
+
// the frame completed are frame_idx - 1
|
| 792 |
+
else{
|
| 793 |
+
if(rows_i != (Trajectory->n_at + 2)*Trajectory->frames){
|
| 794 |
+
fe = fopen("error.dat", "w");
|
| 795 |
+
fprintf(fe,"Error. Total number of rows: %d, while expected number of rows are %d. Trajectory incomplete.\nAborting\n",rows_i,\
|
| 796 |
+
(Trajectory->n_at + 2)*Trajectory->frames);
|
| 797 |
+
fclose(fe);
|
| 798 |
+
printf("Error. Total number of rows: %d, while expected number of rows are %d. Trajectory incomplete.\nAborting\n", rows_i,\
|
| 799 |
+
(Trajectory->n_at + 2)*Trajectory->frames);
|
| 800 |
+
exit(EXIT_FAILURE);
|
| 801 |
+
}
|
| 802 |
+
}
|
| 803 |
+
}
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
int main(int argc, char *argv[]) {
|
| 807 |
+
/**
|
| 808 |
+
* main file of the program
|
| 809 |
+
*/
|
| 810 |
+
time_t seconds;
|
| 811 |
+
time_t seconds_ref = time(NULL);
|
| 812 |
+
printf("Starting program at %s\n", ctime(&seconds_ref));
|
| 813 |
+
|
| 814 |
+
printf("input trajectory %s\n", argv[1]);
|
| 815 |
+
printf("core index is %s\n", argv[2]);
|
| 816 |
+
printf("number of pairs is %s\n", argv[3]);
|
| 817 |
+
printf("starting pair is %s-%s\n", argv[4], argv[5]);
|
| 818 |
+
traj *Trajectory = malloc (sizeof(traj));
|
| 819 |
+
|
| 820 |
+
int npairs = atoi(argv[3]);
|
| 821 |
+
int start_pair[2];
|
| 822 |
+
start_pair[0] = atoi(argv[4]);
|
| 823 |
+
start_pair[1] = atoi(argv[5]);
|
| 824 |
+
|
| 825 |
+
int rec_frames = atoi(argv[6]);
|
| 826 |
+
int rec_atomnum = atoi(argv[7]);
|
| 827 |
+
|
| 828 |
+
Trajectory->frames = rec_frames;
|
| 829 |
+
Trajectory->n_at = rec_atomnum;
|
| 830 |
+
Trajectory->traj_coords = d2t(rec_frames, 3 * rec_atomnum);
|
| 831 |
+
Trajectory->pairs = npairs;
|
| 832 |
+
|
| 833 |
+
printf("frames = %d\n", Trajectory->frames);
|
| 834 |
+
printf("overall pairs = %d\n", Trajectory->pairs);
|
| 835 |
+
|
| 836 |
+
// read trajectory
|
| 837 |
+
read_TrajectoryFile(argv[1], Trajectory);
|
| 838 |
+
alignments *align = malloc (sizeof(alignments));
|
| 839 |
+
align->rmsd_mat = d1t(Trajectory->pairs);
|
| 840 |
+
align->ref_structs = i1t(Trajectory->pairs);
|
| 841 |
+
align->mod_structs = i1t(Trajectory->pairs);
|
| 842 |
+
align->coms = d2t(rec_frames, 3);
|
| 843 |
+
|
| 844 |
+
char out_filename[100];
|
| 845 |
+
if (argc == 10){
|
| 846 |
+
// if there are arguments 8 to 10, it is the ligand trajectory, frames and atomnum
|
| 847 |
+
traj *Ligand_Trajectory = malloc (sizeof(traj));
|
| 848 |
+
printf("loading ligand data\n");
|
| 849 |
+
|
| 850 |
+
int ligand_atomnum = atoi(argv[9]);
|
| 851 |
+
Ligand_Trajectory->frames = rec_frames;
|
| 852 |
+
Ligand_Trajectory->n_at = ligand_atomnum;
|
| 853 |
+
Ligand_Trajectory->traj_coords = d2t(rec_frames, 3 * ligand_atomnum);
|
| 854 |
+
read_TrajectoryFile(argv[8], Ligand_Trajectory);
|
| 855 |
+
cycle_ilrmsd(Trajectory, Ligand_Trajectory, align, start_pair);
|
| 856 |
+
sprintf(out_filename, "ilrmsd_%s.matrix", argv[2]);
|
| 857 |
+
}
|
| 858 |
+
else{
|
| 859 |
+
cycle_rmsd(Trajectory, align, start_pair);
|
| 860 |
+
sprintf(out_filename, "rmsd_%s.matrix", argv[2]);
|
| 861 |
+
}
|
| 862 |
+
// write the rmsd matrix
|
| 863 |
+
int i;
|
| 864 |
+
// check if file exists
|
| 865 |
+
if (access(out_filename, F_OK) != -1){
|
| 866 |
+
printf("Warning: file %s already exists.\n", out_filename);
|
| 867 |
+
}
|
| 868 |
+
// write to file
|
| 869 |
+
FILE *frmsd;
|
| 870 |
+
frmsd = fopen(out_filename, "w");
|
| 871 |
+
for (i = 0; i < Trajectory->pairs; i++){
|
| 872 |
+
fprintf(frmsd, "%d %d %.3lf\n",align->ref_structs[i],align->mod_structs[i],align->rmsd_mat[i]);
|
| 873 |
+
}
|
| 874 |
+
|
| 875 |
+
seconds = time(NULL);
|
| 876 |
+
printf("\nOverall execution time: %ld seconds\n", seconds-seconds_ref);
|
| 877 |
+
free_d2t(align->coms);
|
| 878 |
+
free_d1t(align->rmsd_mat);
|
| 879 |
+
free(align);
|
| 880 |
+
free_d2t(Trajectory->traj_coords);
|
| 881 |
+
free(Trajectory);
|
| 882 |
+
return 0;
|
| 883 |
+
}
|
.venv_haddock/lib/python3.12/site-packages/haddock/fcc/__init__.py
ADDED
|
File without changes
|
.venv_haddock/lib/python3.12/site-packages/haddock/fcc/calc_fcc_matrix.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: UTF-8 -*-
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Calculates a matrix of fraction of common contacts between two or more structures.
|
| 6 |
+
|
| 7 |
+
Authors:
|
| 8 |
+
RODRIGUES Joao
|
| 9 |
+
TRELLET Mikael
|
| 10 |
+
MELQUIOND Adrien
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
# Contact Parsing routines
|
| 15 |
+
def parse_contact_file(f_list, ignore_chain):
|
| 16 |
+
"""Parses a list of contact files."""
|
| 17 |
+
|
| 18 |
+
if ignore_chain:
|
| 19 |
+
contacts = [
|
| 20 |
+
[int(l[0:5] + l[6:-1]) for l in open(f)] for f in f_list if f.strip()
|
| 21 |
+
]
|
| 22 |
+
else:
|
| 23 |
+
contacts = [set([int(l) for l in open(f)]) for f in f_list if f.strip()]
|
| 24 |
+
|
| 25 |
+
return contacts
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
# FCC Calculation Routine
|
| 29 |
+
def calculate_fcc(listA, listB):
|
| 30 |
+
"""
|
| 31 |
+
Calculates the fraction of common elements between two lists
|
| 32 |
+
taking into account chain IDs
|
| 33 |
+
"""
|
| 34 |
+
|
| 35 |
+
cc = len(listA.intersection(listB))
|
| 36 |
+
cc_v = len(listB.intersection(listA))
|
| 37 |
+
|
| 38 |
+
return (cc, cc_v)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def calculate_fcc_nc(listA, listB):
|
| 42 |
+
"""
|
| 43 |
+
Calculates the fraction of common elements between two lists
|
| 44 |
+
not taking into account chain IDs. Much Slower.
|
| 45 |
+
"""
|
| 46 |
+
|
| 47 |
+
largest, smallest = sorted([listA, listB], key=len)
|
| 48 |
+
ncommon = len([ele for ele in largest if ele in smallest])
|
| 49 |
+
return (ncommon, ncommon)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
# Matrix Calculation
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def calculate_pairwise_matrix(contacts, ignore_chain):
|
| 56 |
+
"""Calculates a matrix of pairwise fraction of common contacts (FCC).
|
| 57 |
+
Outputs numeric indexes.
|
| 58 |
+
|
| 59 |
+
contacts: list_of_unique_pairs_of_residues [set/list]
|
| 60 |
+
|
| 61 |
+
Returns pairwise matrix as an iterator, each entry in the form:
|
| 62 |
+
FCC(cplx_1/cplx_2) FCC(cplx_2/cplx_1)
|
| 63 |
+
"""
|
| 64 |
+
|
| 65 |
+
contact_lengths = []
|
| 66 |
+
for c in contacts:
|
| 67 |
+
try:
|
| 68 |
+
ic = 1.0 / len(c)
|
| 69 |
+
except ZeroDivisionError:
|
| 70 |
+
ic = 0
|
| 71 |
+
contact_lengths.append(ic)
|
| 72 |
+
|
| 73 |
+
if ignore_chain:
|
| 74 |
+
calc_fcc = calculate_fcc_nc
|
| 75 |
+
else:
|
| 76 |
+
calc_fcc = calculate_fcc
|
| 77 |
+
|
| 78 |
+
for i in range(len(contacts)):
|
| 79 |
+
|
| 80 |
+
for k in range(i + 1, len(contacts)):
|
| 81 |
+
cc, cc_v = calc_fcc(contacts[i], contacts[k])
|
| 82 |
+
fcc, fcc_v = cc * contact_lengths[i], cc * contact_lengths[k]
|
| 83 |
+
yield (i + 1, k + 1, fcc, fcc_v)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _output_fcc(output, values, f_buffer):
|
| 87 |
+
|
| 88 |
+
buf = []
|
| 89 |
+
for i in values:
|
| 90 |
+
buf.append(i)
|
| 91 |
+
if len(buf) == f_buffer:
|
| 92 |
+
output(
|
| 93 |
+
"".join(["%s %s %1.3f %1.3f\n" % (i[0], i[1], i[2], i[3]) for i in buf])
|
| 94 |
+
)
|
| 95 |
+
buf = []
|
| 96 |
+
output("".join(["%s %s %1.3f %1.3f\n" % (i[0], i[1], i[2], i[3]) for i in buf]))
|
.venv_haddock/lib/python3.12/site-packages/haddock/fcc/cluster_fcc.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
# -*- coding: UTF-8 -*-
|
| 3 |
+
|
| 4 |
+
"""
|
| 5 |
+
Asymmetric Taylor-Butina Disjoint Clustering Algorithm.
|
| 6 |
+
|
| 7 |
+
Authors:
|
| 8 |
+
RODRIGUES Joao
|
| 9 |
+
TRELLET Mikael
|
| 10 |
+
MELQUIOND Adrien
|
| 11 |
+
"""
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
class Element(object):
|
| 15 |
+
"""Defines a 'clusterable' Element"""
|
| 16 |
+
|
| 17 |
+
__slots__ = ["name", "cluster", "neighbors"]
|
| 18 |
+
|
| 19 |
+
def __init__(self, name):
|
| 20 |
+
self.name = name
|
| 21 |
+
self.cluster = 0
|
| 22 |
+
self.neighbors = set()
|
| 23 |
+
|
| 24 |
+
def add_neighbor(self, neighbor):
|
| 25 |
+
"""Adds another element to the neighbor list"""
|
| 26 |
+
self.neighbors.add(neighbor)
|
| 27 |
+
|
| 28 |
+
def assign_cluster(self, clust_id):
|
| 29 |
+
"""Assigns the Element to Cluster. 0 if unclustered"""
|
| 30 |
+
self.cluster = clust_id
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class Cluster(object):
|
| 34 |
+
"""Defines a Cluster. A Cluster is created with a name and a center (Element class)"""
|
| 35 |
+
|
| 36 |
+
__slots__ = ["name", "center", "members"]
|
| 37 |
+
|
| 38 |
+
def __init__(self, name, center):
|
| 39 |
+
|
| 40 |
+
self.name = name
|
| 41 |
+
self.center = center
|
| 42 |
+
|
| 43 |
+
self.members = []
|
| 44 |
+
|
| 45 |
+
self.populate()
|
| 46 |
+
|
| 47 |
+
def __len__(self):
|
| 48 |
+
return len(self.members) + 1 # +1 Center
|
| 49 |
+
|
| 50 |
+
def populate(self):
|
| 51 |
+
"""
|
| 52 |
+
Populates the Cluster member list through the
|
| 53 |
+
neighbor list of its center.
|
| 54 |
+
"""
|
| 55 |
+
|
| 56 |
+
name = self.name
|
| 57 |
+
# Assign center
|
| 58 |
+
ctr = self.center
|
| 59 |
+
ctr.assign_cluster(name)
|
| 60 |
+
|
| 61 |
+
mlist = self.members
|
| 62 |
+
# Assign members
|
| 63 |
+
ctr_nlist = (n for n in ctr.neighbors if not n.cluster)
|
| 64 |
+
for e in ctr_nlist:
|
| 65 |
+
mlist.append(e)
|
| 66 |
+
e.assign_cluster(name)
|
| 67 |
+
|
| 68 |
+
def add_member(self, element):
|
| 69 |
+
"""
|
| 70 |
+
Adds one single element to the cluster.
|
| 71 |
+
"""
|
| 72 |
+
l = self.members
|
| 73 |
+
l.append(element)
|
| 74 |
+
element.assign_cluster(self.name)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def read_matrix(path, cutoff, strictness):
|
| 78 |
+
"""
|
| 79 |
+
Reads in a four column matrix (1 2 0.123 0.456\n)
|
| 80 |
+
and creates an dictionary of Elements.
|
| 81 |
+
|
| 82 |
+
The strictness factor is a <float> that multiplies by the cutoff
|
| 83 |
+
to produce a new cutoff for the second half of the matrix. Used to
|
| 84 |
+
allow some variability while keeping very small interfaces from clustering
|
| 85 |
+
with anything remotely similar.
|
| 86 |
+
"""
|
| 87 |
+
|
| 88 |
+
cutoff = float(cutoff)
|
| 89 |
+
partner_cutoff = float(cutoff) * float(strictness)
|
| 90 |
+
|
| 91 |
+
elements = {}
|
| 92 |
+
|
| 93 |
+
f = open(path, "r")
|
| 94 |
+
for line in f:
|
| 95 |
+
ref, mobi, dRM, dMR = line.split()
|
| 96 |
+
ref = int(ref)
|
| 97 |
+
mobi = int(mobi)
|
| 98 |
+
dRM = float(dRM)
|
| 99 |
+
dMR = float(dMR)
|
| 100 |
+
|
| 101 |
+
# Create or Retrieve Elements
|
| 102 |
+
if ref not in elements:
|
| 103 |
+
r = Element(ref)
|
| 104 |
+
elements[ref] = r
|
| 105 |
+
else:
|
| 106 |
+
r = elements[ref]
|
| 107 |
+
|
| 108 |
+
if mobi not in elements:
|
| 109 |
+
m = Element(mobi)
|
| 110 |
+
elements[mobi] = m
|
| 111 |
+
else:
|
| 112 |
+
m = elements[mobi]
|
| 113 |
+
|
| 114 |
+
# Assign neighbors
|
| 115 |
+
if dRM >= cutoff and dMR >= partner_cutoff:
|
| 116 |
+
r.add_neighbor(m)
|
| 117 |
+
if dMR >= cutoff and dRM >= partner_cutoff:
|
| 118 |
+
m.add_neighbor(r)
|
| 119 |
+
|
| 120 |
+
f.close()
|
| 121 |
+
|
| 122 |
+
return elements
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def remove_true_singletons(element_pool):
|
| 126 |
+
"""Removes from the pool elements without any neighbor"""
|
| 127 |
+
|
| 128 |
+
ep = element_pool
|
| 129 |
+
|
| 130 |
+
ts = set([e for e in ep if not ep[e].neighbors])
|
| 131 |
+
|
| 132 |
+
# Remove ts from everybody's neighbor list
|
| 133 |
+
ts_e = set(ep[e] for e in ts)
|
| 134 |
+
for e in element_pool:
|
| 135 |
+
ep[e].neighbors = ep[e].neighbors.difference(ts_e)
|
| 136 |
+
|
| 137 |
+
# Remove ts from pool
|
| 138 |
+
for e in ts:
|
| 139 |
+
del ep[e]
|
| 140 |
+
|
| 141 |
+
return (ts, ep)
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def cluster_elements(element_pool, threshold):
|
| 145 |
+
"""
|
| 146 |
+
Groups Elements within a given threshold
|
| 147 |
+
together in the same cluster.
|
| 148 |
+
"""
|
| 149 |
+
|
| 150 |
+
clusters = []
|
| 151 |
+
threshold -= 1 # Account for center
|
| 152 |
+
ep = element_pool
|
| 153 |
+
cn = 1 # Cluster Number
|
| 154 |
+
while 1:
|
| 155 |
+
# Clusterable elements
|
| 156 |
+
ce = [e for e in ep if not ep[e].cluster]
|
| 157 |
+
if not ce: # No more elements to cluster
|
| 158 |
+
break
|
| 159 |
+
|
| 160 |
+
# Select Cluster Center
|
| 161 |
+
# Element with largest neighbor list
|
| 162 |
+
ctr_nlist, ctr = sorted(
|
| 163 |
+
[(len([se for se in ep[e].neighbors if not se.cluster]), e) for e in ce]
|
| 164 |
+
)[-1]
|
| 165 |
+
|
| 166 |
+
# Cluster until length of remaining elements lists are above threshold
|
| 167 |
+
if ctr_nlist < threshold:
|
| 168 |
+
break
|
| 169 |
+
|
| 170 |
+
# Create Cluster
|
| 171 |
+
c = Cluster(cn, ep[ctr])
|
| 172 |
+
cn += 1
|
| 173 |
+
clusters.append(c)
|
| 174 |
+
|
| 175 |
+
return (ep, clusters)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def output_clusters(handle, clusters):
|
| 179 |
+
"""Outputs the cluster name, center, and members."""
|
| 180 |
+
|
| 181 |
+
write = handle.write
|
| 182 |
+
|
| 183 |
+
for c in clusters:
|
| 184 |
+
write("Cluster %s -> %s " % (c.name, c.center.name))
|
| 185 |
+
for m in sorted(c.members, key=lambda k: k.name):
|
| 186 |
+
write("%s " % m.name)
|
| 187 |
+
write("\n")
|
.venv_haddock/lib/python3.12/site-packages/haddock/gear/__init__.py
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Contain modules to address specific implementation ideas.
|
| 3 |
+
|
| 4 |
+
Each python module in this package should encapsulate all specific logic
|
| 5 |
+
regarding on implementation idea. For example, you wish to defined the
|
| 6 |
+
whole logic referring to the preparation steps before the run.
|
| 7 |
+
"""
|