Skip to content

Commit

Permalink
refactored check for chain combinations
Browse files Browse the repository at this point in the history
  • Loading branch information
mgiulini committed Dec 10, 2024
1 parent 0a4f4a8 commit 01ad5f4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
16 changes: 3 additions & 13 deletions src/haddock/libs/libcns.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from haddock.libs.libfunc import false, true
from haddock.libs.libmath import RandomNumberGenerator
from haddock.libs.libontology import PDBFile
from haddock.libs.libpdb import check_combination_chains
from haddock.libs.libutil import transform_to_list


Expand Down Expand Up @@ -335,25 +336,14 @@ def prepare_cns_input(
# prepare chain/seg IDs
segid_str = ""
if native_segid:
chainid_list: list[str] = []
if isinstance(input_element, (list, tuple)):
for pdb in input_element:

segids, chains = libpdb.identify_chainseg(pdb.rel_path, sort=False)

chainsegs = sorted(list(set(segids) | set(chains)))
# check if any of chainsegs is already in chainid_list
if not identifier.endswith("scoring"):
if any(chainseg in chainid_list for chainseg in chainsegs):
raise ValueError(
f"Chain/seg IDs are not unique for pdbs {input_element}."
)
chainid_list.extend(chainsegs)
chainid_list = check_combination_chains(input_element)

for i, _chainseg in enumerate(chainid_list, start=1):
segid_str += write_eval_line(f"prot_segid_{i}", _chainseg)

else:
chainid_list: list[str] = []
segids, chains = libpdb.identify_chainseg(
input_element.rel_path, sort=False
)
Expand Down
17 changes: 16 additions & 1 deletion src/haddock/libs/libpdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
Optional,
Union,
)
from haddock.libs.libio import working_directory
from haddock.libs.libio import working_directory, PDBFile
from haddock.libs.libutil import get_result_or_same_in_list, sort_numbered_paths


Expand Down Expand Up @@ -296,3 +296,18 @@ def read_RECORD_section(

read_chainids = partial(read_RECORD_section, section_slice=slc_chainid, func=list) # noqa: E501
read_segids = partial(read_RECORD_section, section_slice=slc_segid, func=list)


def check_combination_chains(combination: list[PDBFile]) -> list[str]:
"""Check if chain IDs are unique for each pdb in combination."""
chainid_list: list[str] = []
for pdb in combination:
segids, chains = identify_chainseg(pdb.rel_path, sort=False)
chainsegs = sorted(list(set(segids) | set(chains)))
# check if any of chainsegs is already in chainid_list
if any(chainseg in chainid_list for chainseg in chainsegs):
raise ValueError(
f"Chain/seg IDs are not unique for pdbs {combination}."
)
chainid_list.extend(chainsegs)
return chainid_list
2 changes: 2 additions & 0 deletions src/haddock/modules/sampling/rigidbody/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from haddock.libs.libcns import prepare_cns_input
from haddock.libs.libontology import PDBFile
from haddock.libs.libparallel import GenericTask, Scheduler
from haddock.libs.libpdb import check_combination_chains
from haddock.libs.libsubprocess import CNSJob
from haddock.modules import get_engine
from haddock.modules.base_cns_module import BaseCNSModule
Expand Down Expand Up @@ -132,6 +133,7 @@ def prepare_cns_input_parallel(
_l = []
idx = 1
for combination in models_to_dock:
check_combination_chains(combination)
for _ in range(sampling_factor):
ambig_fname = (
ambig_fnames[idx - 1]
Expand Down

0 comments on commit 01ad5f4

Please sign in to comment.