10def _Setup(mdl, ref, mdl_ch1, mdl_ch2, ref_ch1, ref_ch2):
11 """ Performs parameter checks and dumps files for DockQ
13 In case of dimeric interfaces the respective chains are selected from
14 mdl/trg, renamed to A/B and dumped to disk.
16 In case of interfaces with more chains involved, we simply select the
17 specified chains and do no renaming before dumping to disk.
19 if isinstance(mdl_ch1, str):
21 if isinstance(mdl_ch2, str):
23 if isinstance(ref_ch1, str):
25 if isinstance(ref_ch2, str):
29 raise RuntimeError(
"mdl_ch1 is empty")
31 raise RuntimeError(
"mdl_ch2 is empty")
33 if len(mdl_ch1) != len(ref_ch1):
34 raise RuntimeError(
"mdl_ch1/ref_ch1 inconsistent in size")
35 if len(mdl_ch2) != len(ref_ch2):
36 raise RuntimeError(
"mdl_ch2/ref_ch2 inconsistent in size")
39 ch = mdl.FindChain(cname)
41 raise RuntimeError(f
"Chain {cname} specified in mdl_ch1 not "
45 ch = mdl.FindChain(cname)
47 raise RuntimeError(f
"Chain {cname} specified in mdl_ch2 not "
51 ch = ref.FindChain(cname)
53 raise RuntimeError(f
"Chain {cname} specified in ref_ch1 not "
57 ch = ref.FindChain(cname)
59 raise RuntimeError(f
"Chain {cname} specified in ref_ch2 not "
62 mdl_to_dump = mdl.CreateFullView()
63 ref_to_dump = ref.CreateFullView()
65 if len(mdl_ch1) == 1
and len(mdl_ch2) == 1:
68 mdl_to_dump = mol.CreateEntityFromView(mdl_to_dump,
True)
69 tmp = mol.CreateEntity()
71 ch1 = mdl_to_dump.FindChain(mdl_ch1[0])
72 ed.InsertChain(
"A", ch1, deep=
True)
73 ch2 = mdl_to_dump.FindChain(mdl_ch2[0])
74 ed.InsertChain(
"B", ch2, deep=
True)
80 ref_to_dump = mol.CreateEntityFromView(ref_to_dump,
True)
81 tmp = mol.CreateEntity()
83 ch1 = ref_to_dump.FindChain(ref_ch1[0])
84 ed.InsertChain(
"A", ch1, deep=
True)
85 ch2 = ref_to_dump.FindChain(ref_ch2[0])
86 ed.InsertChain(
"B", ch2, deep=
True)
92 raise NotImplementedError(
"DockQ computations beyond two interacting "
93 "chains has not been properly tested...")
97 mdl_str = io.EntityToPDBStr(mdl_to_dump)
98 ref_str = io.EntityToPDBStr(ref_to_dump)
100 tmp_dir = tempfile.mkdtemp()
101 with open(os.path.join(tmp_dir,
"mdl.pdb"),
'w')
as fh:
103 with open(os.path.join(tmp_dir,
"ref.pdb"),
'w')
as fh:
106 return (tmp_dir, mdl_ch1, mdl_ch2, ref_ch1, ref_ch2)
224def DockQ(dockq_exec, mdl, ref, mdl_ch1, mdl_ch2, ref_ch1,
226 """ Computes DockQ for specified interface
228 DockQ is available from https://github.com/bjornwallner/DockQ -
229 For this binding to work, DockQ must be properly installed and its
230 dependencies must be available (numpy, Biopython).
232 :param dockq_exec: Path to DockQ.py script from DockQ repository
233 :type dockq_exec: :class:`str`
234 :param mdl: Model structure
235 :type mdl: :class:`ost.mol.EntityView`/:class:`ost.mol.EntityHandle`
236 :param ref: Reference structure, i.e. native structure
237 :type ref: :class:`ost.mol.EntityView`/:class:`ost.mol.EntityHandle`
238 :param mdl_ch1: Specifies chain(s) in model constituting first part of
240 :type mdl_ch1: :class:`str`/:class:`list` of :class:`str`
241 :param mdl_ch2: Specifies chain(s) in model constituting second part of
243 :type mdl_ch2: :class:`str`/:class:`list` of :class:`str`
244 :param ref_ch1: ref equivalent of mdl_ch1
245 :type ref_ch1: :class:`str`/:class:`list` of :class:`str`
246 :param ref_ch2: ref equivalent of mdl_ch2
247 :type ref_ch2: :class:`str`/:class:`list` of :class:`str`
248 :returns: Result object of type :class:`DockQResult`
250 if not os.path.exists(dockq_exec):
251 raise RuntimeError(f
"DockQ executable ({dockq_exec}) does not exist")
253 tmp_dir, mdl_ch1, mdl_ch2, ref_ch1, ref_ch2 = \
254 _Setup(mdl, ref, mdl_ch1, mdl_ch2, ref_ch1, ref_ch2)
256 cmd = [sys.executable, dockq_exec, os.path.join(tmp_dir,
"mdl.pdb"),
257 os.path.join(tmp_dir,
"ref.pdb")]
260 cmd.append(
"-model_chain1")
262 cmd.append(
"-model_chain2")
264 cmd.append(
"-native_chain1")
266 cmd.append(
"-native_chain2")
269 proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
271 shutil.rmtree(tmp_dir)
273 if proc.returncode != 0:
274 raise RuntimeError(
"DockQ run failed - returncode: " + \
275 str(proc.returncode) +
", stderr: " + \
276 proc.stderr.decode() +
", stdout: " + \
277 proc.stdout.decode())
279 if proc.stderr.decode() !=
"":
280 raise RuntimeError(
"DockQ run failed - stderr: " + \
281 proc.stderr.decode() +
", stdout: " + \
282 proc.stdout.decode())
284 return DockQResult.FromDockQOutput(proc.stdout.decode())