Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/haddock/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,14 @@ def confirm_installation(self):
"""
return

def export_output_models(self, faulty_tolerance=0):
def export_io_models(self, faulty_tolerance=0):
"""
Export output to the ModuleIO interface.
Export input/output to the ModuleIO interface.

Modules that generate PDBs that other models should take as input,
should export those PDBs registries through the ModuleIO interface.
Modules that do not perform any operation on PDB files should have
input = output.

This function implements a common interface for all modules requiring
this feature.
This function implements a common interface for all modules.

Parameters
----------
Expand All @@ -260,6 +259,9 @@ def export_output_models(self, faulty_tolerance=0):
"""
assert self.output_models, "`self.output_models` cannot be empty."
io = ModuleIO()
# add the input models
io.add(self.previous_io.output, "i")
# add the output models
io.add(self.output_models, "o")
faulty = io.check_faulty()
if faulty > faulty_tolerance:
Expand Down
4 changes: 2 additions & 2 deletions src/haddock/modules/_template_cat/_template_mod/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ def _run(self):

# final section
self.output_models = list_of_created_models
self.export_output_models()
self.export_io_models()
# in case your module considers possible tolerance for generated models,
# you can use:
# self.export_output_models(faulty_tolerance=self.params["tolerance"])
# self.export_io_models(faulty_tolerance=self.params["tolerance"])


# Finally, the haddock module's class inherit from BaseHaddockModule. It is
Expand Down
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/caprieval/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,4 @@ def _run(self):
# Send models to the next step,
# no operation is done on them
self.output_models = models
self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/clustfcc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ def _run(self):
log.warning('No clusters were found')
self.output_models = models_to_cluster

self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/clustrmsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def _run(self):
with open(output_fname, 'w') as out_fh:
out_fh.write(output_str)

self.export_output_models()
self.export_io_models()
# sending matrix to next step of the workflow
matrix_io = ModuleIO()
matrix_io.add(self.matrix_json.input[0])
Expand Down
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/rmsdmatrix/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _run(self):

# Sending models to the next step of the workflow
self.output_models = models
self.export_output_models()
self.export_io_models()
# Sending matrix path to the next step of the workflow
matrix_io = ModuleIO()
rmsd_matrix_file = RMSDFile(
Expand Down
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/seletop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ def _run(self):

# select the models based on the parameter
self.output_models = models_to_select[:self.params['select']]
self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/analysis/seletopclusts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,4 @@ def _run(self):
model.path = str(Path(self.path).resolve())

self.output_models = models_to_export
self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/refinement/emref/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ def _run(self):
haddock_score = haddock_model.calc_haddock_score(**weights)
pdb.score = haddock_score

self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/refinement/flexref/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ def _run(self):
pdb.score = haddock_score

# Save module information
self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/refinement/mdref/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,4 @@ def _run(self):
pdb.score = haddock_score

# Save module information
self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/sampling/gdock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ def _run(self):
pdb.topology = topologies
self.output_models.append(pdb)

self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/sampling/lightdock/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,4 @@ def _run(self):
path=self.path))

self.output_models = models
self.export_output_models()
self.export_io_models()
2 changes: 1 addition & 1 deletion src/haddock/modules/sampling/rigidbody/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,4 @@ def _run(self):
haddock_score = haddock_model.calc_haddock_score(**weights)
model.score = haddock_score

self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/scoring/emscoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ def _run(self):
self.log(f"Saving output to {output_fname}")
self.output(output_fname)

self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/scoring/mdscoring/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ def _run(self):
self.log(f"Saving output to {output_fname}")
self.output(output_fname)

self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
2 changes: 1 addition & 1 deletion src/haddock/modules/topology/topoaa/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,4 +247,4 @@ def _run(self):

# Save module information
self.output_models = list(expected.values())
self.export_output_models(faulty_tolerance=self.params["tolerance"])
self.export_io_models(faulty_tolerance=self.params["tolerance"])
38 changes: 32 additions & 6 deletions tests/test_module_clustfcc.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

import pytest

from haddock.libs.libontology import PDBFile
from haddock.libs.libontology import ModuleIO, PDBFile
from haddock.modules.analysis.clustfcc import DEFAULT_CONFIG as clustfcc_pars
from haddock.modules.analysis.clustfcc import HaddockModule

from . import golden_data


@pytest.fixture
def protprot_input_list():
def prot_input_list():
"""Prot-prot input."""
return [
PDBFile(Path(golden_data, "protprot_complex_1.pdb"), path=golden_data),
Expand All @@ -34,14 +34,19 @@ def output_list():
]


def test_clustfcc_output_existence(protprot_input_list, output_list):
"""Test clustfcc output."""
fcc_module = HaddockModule(
@pytest.fixture
def fcc_module():
"""Clustfcc module."""
return HaddockModule(
order=1,
path=Path("1_emscoring"),
initial_params=clustfcc_pars
)
fcc_module.previous_io.output = protprot_input_list


def test_clustfcc_output_existence(fcc_module, prot_input_list, output_list):
"""Test clustfcc output."""
fcc_module.previous_io.output = prot_input_list

fcc_module._run()

Expand Down Expand Up @@ -95,3 +100,24 @@ def test_cluster_out(output_list):
assert expected_output == observed_output

remove_clustfcc_files(output_list)


def test_io_json(fcc_module, prot_input_list):
"""Test the correct creation of the io.json file."""
# set the input and output models
fcc_module.previous_io.output = prot_input_list
fcc_module.output_models = prot_input_list

# export models
fcc_module.export_io_models()

assert Path("io.json").exists()

# check the content of io.json
io = ModuleIO()
io.load("io.json")
assert io.input[0].file_name == prot_input_list[0].file_name
assert io.output[1].file_name == prot_input_list[1].file_name

# remove io.json file
os.unlink(Path("io.json"))