10 def _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)
109 """ DockQ result object
111 def __init__(self, Fnat, Fnonnat, native_contacts, model_contacts, iRMS,
113 self.
_Fnat_Fnat = Fnat
117 self.
_iRMS_iRMS = iRMS
118 self.
_LRMS_LRMS = LRMS
123 """ DockQ - Fnat output
125 :type: :class:`float`
127 return self.
_Fnat_Fnat
131 """ DockQ - Fnonnat output
133 :type: :class:`float`
139 """ DockQ - number native contacts
147 """ DockQ - number model contacts
155 """ DockQ - iRMS output
157 :type: :class:`float`
159 return self.
_iRMS_iRMS
163 """ DockQ - LMRS output
165 :type: :class:`float`
167 return self.
_LRMS_LRMS
171 """ DockQ - DockQ output
173 :type: :class:`float`
178 """ Returns JSON serializable summary
180 return {
"Fnat": self.
FnatFnat,
181 "Fnonnat": self.
FnonnatFnonnat,
184 "iRMS": self.
iRMSiRMS,
185 "LRMS": self.
LRMSLRMS,
186 "DockQ": self.
DockQDockQ}
190 """ Static constructor from raw DockQ output
192 :param output: Raw output from DockQ executable
193 :type output: :class:`str`
194 :returns: Object of type :class:`DockQResult`
198 native_contacts =
None
199 model_contacts =
None
204 for line
in output.splitlines():
205 if line.startswith(
'*'):
207 if line.startswith(
"Fnat"):
208 Fnat = float(line.split()[1])
209 native_contacts = int(line.split()[5])
210 elif line.startswith(
"Fnonnat"):
211 Fnonnat = float(line.split()[1])
212 model_contacts = int(line.split()[5])
213 elif line.startswith(
"iRMS"):
214 iRMS = float(line.split()[1])
215 elif line.startswith(
"LRMS"):
216 LRMS = float(line.split()[1])
217 elif line.startswith(
"DockQ"):
218 DockQ = float(line.split()[1])
220 return DockQResult(Fnat, Fnonnat, native_contacts, model_contacts,
224 def 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())
def native_contacts(self)
def FromDockQOutput(output)
def __init__(self, Fnat, Fnonnat, native_contacts, model_contacts, iRMS, LRMS, DockQ)
def DockQ(dockq_exec, mdl, ref, mdl_ch1, mdl_ch2, ref_ch1, ref_ch2)