Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cli score fix #783

Merged
merged 3 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions integration_tests/test_cli_score.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import tempfile
from pathlib import Path

from tests import golden_data
from haddock.clis import cli_score

import io
from contextlib import redirect_stdout
import os
from . import has_cns

@has_cns
def test_cli_score():
"""Test the haddock3-score CLI."""
pdb_f = Path(golden_data, "protprot_complex_1.pdb")
# tempdir
with tempfile.TemporaryDirectory(dir=".") as tmpdir:
# parsing
f = io.StringIO()
with redirect_stdout(f):
cli_score.main(pdb_f, tmpdir, full=True, keep_all=False)
out = f.getvalue().split(os.linesep)
assert out[-3].startswith("> HADDOCK-score (emscoring) = ")
assert out[-2].startswith("> vdw")

# now changing some weitght
f = io.StringIO()
with redirect_stdout(f):
cli_score.main(pdb_f, tmpdir, full=True, keep_all=False, w_vdw=0.5)
out = f.getvalue().split(os.linesep)
assert out[3].startswith("> HADDOCK-score = (0.5 * vdw) + ")
44 changes: 29 additions & 15 deletions src/haddock/clis/cli_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"""
import argparse
import sys
import tempfile

from haddock.core.typing import (
Any,
Expand Down Expand Up @@ -74,7 +75,7 @@
"--other-params",
dest="other_params",
help=(
"Any other parameter of the `emscoring` module."
"Any other parameter of the `emscoring` module. "
"For example: -p nemsteps 1000. You can give any number of "
"parameters."
),
Expand Down Expand Up @@ -174,6 +175,10 @@ def main(
print(
f"* ATTENTION * Value ({value}) of parameter {param} different from default ({default_emscoring[param]})"
) # noqa:E501
# get the type of default value
default_type = type(default_emscoring[param])
# convert the value to the same type
value = default_type(value)
ems_dict[param] = value
n_warnings += 1

Expand All @@ -182,27 +187,36 @@ def main(
"* ATTENTION * Non-default parameter values were used. They should be properly reported if the output data are used for publication."
) # noqa:E501

params = {
"topoaa": {"molecules": [input_pdb]},
"emscoring": ems_dict,
}

print("> starting calculations...")

# create run directory
run_dir = Path(run_dir)
with suppress(FileNotFoundError):
shutil.rmtree(run_dir)
run_dir.mkdir()
zero_fill.set_zerofill_number(2)

with working_directory(run_dir):
workflow = WorkflowManager(
workflow_params=params,
start=0,
run_dir=run_dir,
)
# create temporary file
with tempfile.NamedTemporaryFile(prefix=input_pdb.stem, suffix=".pdb") as tmp:

# create a copy of the input pdb
input_pdb_copy = Path(tmp.name)
shutil.copy(input_pdb, input_pdb_copy)

params = {
"topoaa": {"molecules": [input_pdb_copy]},
"emscoring": ems_dict,
}

print("> starting calculations...")

# run workflow
with working_directory(run_dir):
workflow = WorkflowManager(
workflow_params=params,
start=0,
run_dir=run_dir,
)

workflow.run()
workflow.run()

minimized_mol = Path(run_dir, "1_emscoring", "emscoring_1.pdb")
haddock_score_component_dic = HaddockModel(minimized_mol).energies
Expand Down
32 changes: 0 additions & 32 deletions tests/test_cli_score.py

This file was deleted.