Skip to content
Merged
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
29 changes: 23 additions & 6 deletions src/haddock/modules/topology/topoaa/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Create and manage CNS all-atom topology."""
import operator
import os
import re
from functools import partial
from pathlib import Path

Expand Down Expand Up @@ -84,12 +86,27 @@ def confirm_installation(cls):
def get_md5(ensemble_f):
"""Get MD5 hash of a multi-model PDB file."""
md5_dic = {}
with open(ensemble_f, 'r') as fh:
for line in fh.readlines():
if line.startswith("REMARK") and "9" in line:
model_num = int(line.split('MODEL')[-1].split()[0])
md5 = line.split()[-1]
md5_dic[model_num] = md5
text = Path(ensemble_f).read_text()
lines = text.split(os.linesep)
REMARK_lines = (line for line in lines if line.startswith('REMARK'))
remd5 = re.compile(r"^[a-f0-9]{32}$")
for line in REMARK_lines:
parts = line.strip().split()

try:
idx = parts.index('MODEL')
except ValueError: # MODEL not in parts, this line can be ignored
continue

# check if there's a md5 hash in line
for part in parts:
group = remd5.fullmatch(part)
if group:
# the model num comes after the MODEL
model_num = int(parts[idx + 1])
md5_dic[model_num] = group.string # md5 hash
break

return md5_dic

def _run(self):
Expand Down