File size: 3,806 Bytes
5631464 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 | import shutil
import tempfile
import gzip
from pathlib import Path
import pytest
from haddock.libs.libontology import Format, PDBFile, Persistent
from haddock.modules.refinement.flexref import (
DEFAULT_CONFIG as DEFAULT_FLEXREF_CONFIG,
)
from haddock.modules.refinement.flexref import HaddockModule as FlexrefModule
from integration_tests import GOLDEN_DATA
@pytest.fixture
def flexref_module():
with tempfile.TemporaryDirectory() as tmpdir:
flexref = FlexrefModule(
order=0, path=Path(tmpdir), initial_params=DEFAULT_FLEXREF_CONFIG
)
yield flexref
class MockPreviousIO:
def __init__(self, path):
self.path = path
def retrieve_models(self, crossdock: bool = False):
shutil.copy(
Path(GOLDEN_DATA, "2oob.pdb"),
Path(self.path, "2oob.pdb"),
)
shutil.copy(
Path(GOLDEN_DATA, "2oob_A.psf"),
Path(self.path, "2oob_A.psf"),
)
shutil.copy(
Path(GOLDEN_DATA, "2oob_B.psf"),
Path(self.path, "2oob_B.psf"),
)
model = PDBFile(
file_name="2oob.pdb",
path=self.path,
topology=(
Persistent(
file_name="2oob_A.psf",
path=self.path,
file_type=Format.TOPOLOGY,
),
Persistent(
file_name="2oob_B.psf",
path=self.path,
file_type=Format.TOPOLOGY,
),
),
)
model.seed = 42 # type: ignore
return [model]
def output(self):
return None
def test_flexref_defaults(flexref_module, calc_fnat):
flexref_module.previous_io = MockPreviousIO(path=flexref_module.path)
flexref_module.run()
assert Path(flexref_module.path, "flexref_1.pdb").exists()
fnat = calc_fnat(
model=Path(flexref_module.path, "flexref_1.pdb"),
native=Path(GOLDEN_DATA, "2oob.pdb"),
)
assert fnat == pytest.approx(0.9, abs=0.1)
def test_flexref_fle(flexref_module, calc_fnat):
flexref_module.previous_io = MockPreviousIO(path=flexref_module.path)
flexref_module.params["nfle "] = 1
flexref_module.params["fle_sta_1 "] = 66
flexref_module.params["fle_end_1 "] = 77
flexref_module.params["fle_seg_1 "] = "B"
flexref_module.params["log_level"] = "verbose"
flexref_module.params["debug"] = True
flexref_module.run()
assert Path(flexref_module.path, "flexref_1.pdb").exists()
assert Path(flexref_module.path, "flexref_1.out.gz").exists()
file_content = gzip.open(Path(flexref_module.path, "flexref_1.out.gz"), 'rt').read()
assert '$SAPROTOCOL.TADFACTOR set to 4.00000' in file_content
fnat = calc_fnat(
model=Path(flexref_module.path, "flexref_1.pdb"),
native=Path(GOLDEN_DATA, "2oob.pdb"),
)
assert fnat == pytest.approx(0.9, abs=0.1)
def test_flexref_mutliple_fle(flexref_module, calc_fnat):
flexref_module.previous_io = MockPreviousIO(path=flexref_module.path)
flexref_module.params["nfle "] = 2
flexref_module.params["fle_sta_1 "] = 66
flexref_module.params["fle_end_1 "] = 77
flexref_module.params["fle_seg_1 "] = "B"
flexref_module.params["fle_sta_2 "] = 41
flexref_module.params["fle_end_2 "] = 47
flexref_module.params["fle_seg_2 "] = "B"
flexref_module.params["debug"] = True
flexref_module.run()
assert Path(flexref_module.path, "flexref_1.pdb").exists()
assert Path(flexref_module.path, "flexref_1.out.gz").exists()
fnat = calc_fnat(
model=Path(flexref_module.path, "flexref_1.pdb"),
native=Path(GOLDEN_DATA, "2oob.pdb"),
)
assert fnat == pytest.approx(0.9, abs=0.1)
|