bindview 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bindview/__init__.py +88 -0
- bindview/__main__.py +6 -0
- bindview/align.py +493 -0
- bindview/arrange.js +347 -0
- bindview/arrange.py +248 -0
- bindview/backends.py +290 -0
- bindview/basepairs.py +1711 -0
- bindview/chains.py +264 -0
- bindview/chem.py +57 -0
- bindview/clearance.py +123 -0
- bindview/cli.py +990 -0
- bindview/compare.py +1854 -0
- bindview/confidence.py +531 -0
- bindview/consensus.py +303 -0
- bindview/covalent.py +220 -0
- bindview/depict.py +790 -0
- bindview/detect.py +378 -0
- bindview/diagram.py +1891 -0
- bindview/distance_table.py +589 -0
- bindview/ensemble.py +787 -0
- bindview/errors.py +47 -0
- bindview/exposure.py +207 -0
- bindview/features.py +179 -0
- bindview/fingerprint.py +469 -0
- bindview/fragments.py +304 -0
- bindview/geometry.py +482 -0
- bindview/graph.py +611 -0
- bindview/graphbuild.py +431 -0
- bindview/interactions.py +418 -0
- bindview/interactive.py +334 -0
- bindview/interface.py +1329 -0
- bindview/ions.py +155 -0
- bindview/layout/__init__.py +15 -0
- bindview/layout/body.py +421 -0
- bindview/layout/engine.py +1084 -0
- bindview/layout/field.py +261 -0
- bindview/ligand.py +583 -0
- bindview/near.py +67 -0
- bindview/options.py +92 -0
- bindview/pae.py +991 -0
- bindview/peptide.py +610 -0
- bindview/plane.py +320 -0
- bindview/polymer.py +678 -0
- bindview/py.typed +0 -0
- bindview/report.py +1407 -0
- bindview/residues.py +296 -0
- bindview/resolve.py +493 -0
- bindview/scene.py +239 -0
- bindview/solvent.py +254 -0
- bindview/structure.py +1145 -0
- bindview/styles/__init__.py +2 -0
- bindview/styles/absence.py +180 -0
- bindview/styles/base.py +2128 -0
- bindview/styles/closeup.py +146 -0
- bindview/styles/detailed.py +690 -0
- bindview/styles/ligand_draw.py +289 -0
- bindview/styles/mixed.py +70 -0
- bindview/styles/polymer_draw.py +354 -0
- bindview/styles/rings.py +75 -0
- bindview/styles/schematic.py +311 -0
- bindview/styles/summary.py +147 -0
- bindview/svg.py +310 -0
- bindview/textmetrics.py +64 -0
- bindview/theme.py +317 -0
- bindview-0.1.0.dist-info/METADATA +270 -0
- bindview-0.1.0.dist-info/RECORD +70 -0
- bindview-0.1.0.dist-info/WHEEL +4 -0
- bindview-0.1.0.dist-info/entry_points.txt +2 -0
- bindview-0.1.0.dist-info/licenses/LICENSE +21 -0
- bindview-0.1.0.dist-info/licenses/NOTICE +48 -0
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
"""Residues that another protein does not have: ``render(absent=[702, 705, ...], absent_label="AR-V7")``.
|
|
2
|
+
|
|
3
|
+
One ligand, one pocket and two proteins. The figure is of the protein that was modelled; the mask names the residues
|
|
4
|
+
that the other one (a splice isoform, a construct, an orthologue) lacks, and the figure marks those of them that
|
|
5
|
+
touch the ligand, with their contacts. Nothing is computed for the other protein and nothing moves: the figure is
|
|
6
|
+
the one without the mask, with a stroke of a marker pen under what is lost (``absent_style="marked"``), or with
|
|
7
|
+
what is lost set back (``"faint"``). The sentence under the key counts them.
|
|
8
|
+
|
|
9
|
+
This is not what :meth:`bindview.Ensemble.diagram` calls absent, which is a contact that other models make and the
|
|
10
|
+
one shown does not. In the figure's data the two are told apart: ``data-absent`` is that, ``data-absent-from`` this.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
import math
|
|
16
|
+
import numbers
|
|
17
|
+
from typing import TYPE_CHECKING, Any, Sequence
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from ..depict import Depiction
|
|
22
|
+
from ..geometry import Point
|
|
23
|
+
from ..scene import Circle, Group, Item, Line, Paint, Polyline, Rect
|
|
24
|
+
|
|
25
|
+
if TYPE_CHECKING:
|
|
26
|
+
from .base import RenderOptions, ResidueGroup
|
|
27
|
+
|
|
28
|
+
__all__ = ["ABSENT_STYLES", "MARKER", "OPACITY", "FROM", "absent_option", "mark_groups", "Absence", "absence",
|
|
29
|
+
"from_whom", "said_of", "legend_text", "marker_group", "stroke", "under", "skeleton", "plate", "disc", "UNDER"]
|
|
30
|
+
|
|
31
|
+
ABSENT_STYLES = ("marked", "faint")
|
|
32
|
+
#: The colour of the marker pen (a token, :data:`bindview.theme.EXTRAS`), how strong it is, and how wide a stroke is
|
|
33
|
+
#: in widths of a contact's line.
|
|
34
|
+
MARKER = "absent"
|
|
35
|
+
OPACITY = 0.55
|
|
36
|
+
_WIDE = 6.6
|
|
37
|
+
#: ... and under the atoms of a residue, in bond lengths of its drawing.
|
|
38
|
+
UNDER = 0.5
|
|
39
|
+
#: What the groups of such a residue and of its contacts say.
|
|
40
|
+
FROM = "absent-from"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _refused(name: Any) -> ValueError:
|
|
44
|
+
return ValueError(f"absent names residues by their number or name, not {name!r}")
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _named(name: Any) -> "str | None":
|
|
48
|
+
"""One entry of ``absent`` as a name; None for a gap in a column of numbers (NaN)."""
|
|
49
|
+
if isinstance(name, (bool, np.bool_, bytes, bytearray)):
|
|
50
|
+
raise _refused(name)
|
|
51
|
+
if isinstance(name, numbers.Integral):
|
|
52
|
+
return str(int(name))
|
|
53
|
+
if isinstance(name, numbers.Real): # (of Python or of NumPy: a column of numbers is of floats)
|
|
54
|
+
number = float(name)
|
|
55
|
+
if math.isnan(number):
|
|
56
|
+
return None
|
|
57
|
+
if not number.is_integer():
|
|
58
|
+
raise _refused(name)
|
|
59
|
+
return str(int(number))
|
|
60
|
+
return str(name).strip()
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def absent_option(value: Any) -> "tuple[str, ...] | None":
|
|
64
|
+
"""``absent`` as it is kept: None, or the names in a fixed order (none of them: nothing is absent)."""
|
|
65
|
+
if value is None:
|
|
66
|
+
return None
|
|
67
|
+
if isinstance(value, (str, bytes, bytearray, numbers.Real, np.bool_)): # one residue
|
|
68
|
+
name = _named(value)
|
|
69
|
+
if name is None:
|
|
70
|
+
raise _refused(value)
|
|
71
|
+
return (name,)
|
|
72
|
+
return tuple(sorted({name for name in map(_named, value) if name is not None}))
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def mark_groups(groups: "Sequence[ResidueGroup]", options: "RenderOptions") -> None:
|
|
76
|
+
"""Say of each residue whether the other protein lacks it."""
|
|
77
|
+
if options.absent is None:
|
|
78
|
+
return
|
|
79
|
+
from .base import residue_names
|
|
80
|
+
|
|
81
|
+
names = {n.lower() for n in options.absent}
|
|
82
|
+
for grp in groups:
|
|
83
|
+
grp.lost = any(n.lower() in names for n in residue_names(grp))
|
|
84
|
+
grp.faint = grp.lost and options.absent_style == "faint"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class Absence:
|
|
88
|
+
"""Which of a figure's contact residues the other protein lacks."""
|
|
89
|
+
|
|
90
|
+
def __init__(self, groups: "Sequence[ResidueGroup]", label: "str | None") -> None:
|
|
91
|
+
seen: "dict[tuple, ResidueGroup]" = {}
|
|
92
|
+
for grp in groups:
|
|
93
|
+
# (A predicted water is no contact, nor is one that only other models of an ensemble make.)
|
|
94
|
+
if any(not r.record.predicted and not r.absent for r in grp.interactions):
|
|
95
|
+
seen.setdefault(grp.key, grp)
|
|
96
|
+
self.label = label
|
|
97
|
+
self.absent = [g.ident for g in seen.values() if g.lost]
|
|
98
|
+
self.present = [g.ident for g in seen.values() if not g.lost]
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def sentence(self) -> str:
|
|
102
|
+
n, k = len(self.absent) + len(self.present), len(self.absent)
|
|
103
|
+
whose = f"absent from {from_whom(self.label)}."
|
|
104
|
+
if n == 1:
|
|
105
|
+
return f"The only contact residue is {'' if k else 'not '}{whose}"
|
|
106
|
+
if not k:
|
|
107
|
+
return f"None of the {n} contact residues is {whose}"
|
|
108
|
+
if k == n:
|
|
109
|
+
return f"All {n} contact residues are {whose}"
|
|
110
|
+
return f"{k} of {n} contact residues {'is' if k == 1 else 'are'} {whose}"
|
|
111
|
+
|
|
112
|
+
def as_dict(self) -> "dict[str, Any]":
|
|
113
|
+
return {"from": self.label, "contact_residues": len(self.absent) + len(self.present),
|
|
114
|
+
"absent": list(self.absent), "present": list(self.present)}
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def absence(groups: "Sequence[ResidueGroup]", options: "RenderOptions") -> "Absence | None":
|
|
118
|
+
"""The mask as it falls on the residues of a figure, where one was asked for."""
|
|
119
|
+
return None if options.absent is None else Absence(groups, options.absent_label)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def from_whom(label: "str | None") -> str:
|
|
123
|
+
return label or "the other protein"
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def said_of(options: "RenderOptions") -> str:
|
|
127
|
+
"""The value of ``data-absent-from``."""
|
|
128
|
+
return options.absent_label or "true"
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def legend_text(options: "RenderOptions") -> str:
|
|
132
|
+
"""What the key calls them."""
|
|
133
|
+
whose = f"bsent from {from_whom(options.absent_label)}"
|
|
134
|
+
return f"Faint: a{whose}" if options.absent_style == "faint" else f"A{whose}"
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
# ---------------------------------------------------------------------------
|
|
138
|
+
# The marker pen
|
|
139
|
+
# ---------------------------------------------------------------------------
|
|
140
|
+
|
|
141
|
+
def marker_group(grp: "ResidueGroup", options: "RenderOptions") -> Group:
|
|
142
|
+
"""What is marked of one residue, in one group behind everything: as strong as one stroke wherever two meet. It is
|
|
143
|
+
no part of what the page is sized by (a mark at the edge lies in the margin), so that the figure with the mask
|
|
144
|
+
lies on its page where the one without it does."""
|
|
145
|
+
return Group("absence", opacity=OPACITY, data={"residue": grp.ident, FROM: said_of(options)}, bounded=False)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def stroke(points: "Sequence[Point]", line_width: float, wide: float = _WIDE) -> Item:
|
|
149
|
+
"""Along a line, or along a run of points."""
|
|
150
|
+
paint = Paint(stroke=MARKER, width=wide * line_width, cap="round", join="round")
|
|
151
|
+
if len(points) == 2:
|
|
152
|
+
(x1, y1), (x2, y2) = points
|
|
153
|
+
return Line(x1, y1, x2, y2, paint)
|
|
154
|
+
return Polyline(tuple(points), paint)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def under(items: "Sequence[Item]", line_width: float) -> "list[Item]":
|
|
158
|
+
"""Under the ticks of a hydrophobic contact."""
|
|
159
|
+
return [stroke([(it.x1, it.y1), (it.x2, it.y2)], line_width, 0.55 * _WIDE) for it in items if isinstance(it, Line)]
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def skeleton(dep: Depiction, width: float) -> "list[Item]":
|
|
163
|
+
"""Under the atoms and bonds that are drawn of a residue."""
|
|
164
|
+
out: list[Item] = []
|
|
165
|
+
for bond in dep.bonds:
|
|
166
|
+
a, b = dep.atoms[bond.a], dep.atoms[bond.b]
|
|
167
|
+
out.append(Line(a.x, a.y, b.x, b.y, Paint(stroke=MARKER, width=width, cap="round")))
|
|
168
|
+
if not dep.bonds:
|
|
169
|
+
out.extend(Circle(a.x, a.y, width / 2.0, Paint(fill=MARKER)) for a in dep.atoms)
|
|
170
|
+
return out
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def plate(x: float, y: float, width: float, height: float) -> Rect:
|
|
174
|
+
"""Under a name that is centred at ``x``, ``y``."""
|
|
175
|
+
return Rect(x - width / 2.0 - 4.0, y - height / 2.0 - 3.5, width + 8.0, height + 7.0, Paint(fill=MARKER), rx=4.5)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def disc(x: float, y: float, radius: float) -> Circle:
|
|
179
|
+
"""Around a bubble or a ring."""
|
|
180
|
+
return Circle(x, y, radius + 5.0, Paint(fill=MARKER))
|