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,146 @@
|
|
|
1
|
+
"""What a figure that answers the pointer has beside what it draws: the atoms of a residue that is drawn
|
|
2
|
+
without them, and a place to point at on every atom of the ligand.
|
|
3
|
+
|
|
4
|
+
A bubble (or a name, or an eyelash) says which residue makes a contact and not how. Pointed at, it gives way to
|
|
5
|
+
its residue as the detailed style draws one, in the figure's own lines and with its distances: the part that
|
|
6
|
+
makes the contact and the whole side chain. Each is placed alone, as the engine places a residue beside the
|
|
7
|
+
ligand, as near as may be to where the residue stands in the figure and within the figure's frame. The others
|
|
8
|
+
have stepped far back by then, so it may lie on them; it never lies on the ligand.
|
|
9
|
+
|
|
10
|
+
None of it is drawn: the groups are kept out of the scene (so nothing that is measured of a figure knows them),
|
|
11
|
+
are written last, and are hidden until the style sheet shows one (:mod:`bindview.interactive`).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
from dataclasses import replace
|
|
17
|
+
from typing import Sequence
|
|
18
|
+
|
|
19
|
+
import numpy as np
|
|
20
|
+
|
|
21
|
+
from ..layout import Body, LayoutParams, LigandField, Pose
|
|
22
|
+
from ..layout.engine import _Engine
|
|
23
|
+
from ..scene import Circle, Group, Paint
|
|
24
|
+
from .base import Context, Drawn, ResidueGroup, Settings
|
|
25
|
+
from .detailed import DetailedStyle
|
|
26
|
+
|
|
27
|
+
__all__ = ["closeups", "atom_hits", "MORE", "HIT"]
|
|
28
|
+
|
|
29
|
+
#: The classes of the groups: the atoms of a residue, and a place to point at on an atom of the ligand.
|
|
30
|
+
MORE = "more"
|
|
31
|
+
HIT = "hit"
|
|
32
|
+
#: How much a place costs for each bond length that it is away from where the residue stands in the figure
|
|
33
|
+
#: (a contact's line that is a bond length longer than it is best costs 1).
|
|
34
|
+
_HOME = 1.4
|
|
35
|
+
#: What is drawn of a residue pointed at, where the figure has no level of its own.
|
|
36
|
+
_LEVEL = "sidechain"
|
|
37
|
+
#: How far into the drawing around an atom the pointer reaches it, in bond lengths.
|
|
38
|
+
_HIT_RADIUS = 0.34
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _settings_for(settings: Settings) -> Settings:
|
|
42
|
+
"""The detailed style in the lines of the figure, with its distances."""
|
|
43
|
+
return Settings("atoms", settings.lines, False, "none", True)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def _rename(group: Group) -> Group:
|
|
47
|
+
"""Its parts under names of their own: what reads the residues and the contacts of a figure by their
|
|
48
|
+
class finds each of them once."""
|
|
49
|
+
for item in group.items:
|
|
50
|
+
if isinstance(item, Group):
|
|
51
|
+
if item.cls.split(" ", 1)[0] in ("residue", "interaction", "contact", "absence"):
|
|
52
|
+
item.cls = f"{MORE}-{item.cls}"
|
|
53
|
+
_rename(item)
|
|
54
|
+
return group
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def closeups(ctx: Context, bodies: Sequence[Body], poses: "dict", field: LigandField, params: LayoutParams,
|
|
58
|
+
settings: Settings, frame: "tuple[float, float, float, float]") -> list[Group]:
|
|
59
|
+
"""One hidden group for each residue that is drawn without its atoms and has atoms to show. ``frame`` is
|
|
60
|
+
what the figure's drawing covers."""
|
|
61
|
+
if ctx.dep.units:
|
|
62
|
+
return [] # beside a chain a residue has its place, and no other
|
|
63
|
+
# (The page has a margin on either side of its drawing, and a little room above and below it.)
|
|
64
|
+
m = ctx.metrics
|
|
65
|
+
frame = (frame[0] - 0.7 * m.margin, frame[1] - 6.0, frame[2] + 0.7 * m.margin, frame[3] + 6.0)
|
|
66
|
+
style = DetailedStyle(_settings_for(settings))
|
|
67
|
+
level: "dict[str, str | None]" = {"*": _LEVEL}
|
|
68
|
+
near = replace(ctx, notes=[], detail=level)
|
|
69
|
+
out: list[Group] = []
|
|
70
|
+
for body in bodies:
|
|
71
|
+
pose = poses.get(body.key)
|
|
72
|
+
grp: ResidueGroup = body.payload.group
|
|
73
|
+
if pose is None or body.payload.form == "fragment":
|
|
74
|
+
continue
|
|
75
|
+
drawn = style._fragment_body(near, grp)
|
|
76
|
+
if drawn.kind != "fragment":
|
|
77
|
+
continue # a residue there is no template for: its name is all there is
|
|
78
|
+
place = _seat(field, drawn, params, (pose.x, pose.y), frame)
|
|
79
|
+
if place is None:
|
|
80
|
+
continue
|
|
81
|
+
where, label_t = place
|
|
82
|
+
d = Drawn({"backdrop": [], "halos": [], "interactions": [], "contacts": [], "residues": []})
|
|
83
|
+
style.draw_bodies(near, [drawn], {drawn.key: where}, {drawn.key: label_t}, d)
|
|
84
|
+
group = Group(MORE, data={"residue": grp.ident})
|
|
85
|
+
for layer in ("backdrop", "halos", "interactions", "contacts", "residues"):
|
|
86
|
+
group.extend(d.layers.get(layer, []))
|
|
87
|
+
out.append(_rename(group))
|
|
88
|
+
return out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _seat(field: LigandField, body: Body, params: LayoutParams, home: "tuple[float, float]",
|
|
92
|
+
frame: "tuple[float, float, float, float]") -> "tuple[Pose, tuple[float, ...]] | None":
|
|
93
|
+
engine = _Engine(field, [body], params)
|
|
94
|
+
for wide in (False, True):
|
|
95
|
+
batch = engine._batch(0, wide)
|
|
96
|
+
if not len(batch):
|
|
97
|
+
continue
|
|
98
|
+
geo = batch.geo
|
|
99
|
+
# How far each place reaches beyond the frame.
|
|
100
|
+
r = geo.r[None, :]
|
|
101
|
+
lo = np.minimum(geo.p0, geo.p1)
|
|
102
|
+
hi = np.maximum(geo.p0, geo.p1)
|
|
103
|
+
over = np.maximum.reduce([frame[0] - (lo[..., 0] - r), (hi[..., 0] + r) - frame[2],
|
|
104
|
+
frame[1] - (lo[..., 1] - r), (hi[..., 1] + r) - frame[3]]).max(axis=1)
|
|
105
|
+
inside = over <= 0.5
|
|
106
|
+
if not inside.any() and not wide:
|
|
107
|
+
continue
|
|
108
|
+
away = np.linalg.norm(batch.pos - np.array(home), axis=1) / params.unit
|
|
109
|
+
cost = np.round(batch.base + _HOME * away + np.where(inside, 0.0, 10.0 + np.maximum(over, 0.0)), 9)
|
|
110
|
+
k = int(np.argmin(cost))
|
|
111
|
+
pose = Pose(float(batch.pos[k, 0]), float(batch.pos[k, 1]), float(batch.ang[k]), bool(batch.mir[k]))
|
|
112
|
+
return pose, tuple(float(t) for t in batch.label_t[k])
|
|
113
|
+
return None
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def atom_hits(ctx: Context) -> list[Group]:
|
|
117
|
+
"""A place to point at on every atom of a ligand that is drawn as atoms."""
|
|
118
|
+
if ctx.dep.units:
|
|
119
|
+
return []
|
|
120
|
+
made: "dict[int, list[str]]" = {}
|
|
121
|
+
whose: "dict[int, list[str]]" = {} # an atom: the residues it makes a contact with
|
|
122
|
+
for grp in ctx.groups:
|
|
123
|
+
for r in grp.interactions:
|
|
124
|
+
if r.ligand is not None:
|
|
125
|
+
for i in r.ligand.atoms:
|
|
126
|
+
said = f"{r.type.label.lower()} with {grp.label}"
|
|
127
|
+
if said not in made.setdefault(i, []):
|
|
128
|
+
made[i].append(said)
|
|
129
|
+
if grp.ident not in whose.setdefault(i, []):
|
|
130
|
+
whose[i].append(grp.ident)
|
|
131
|
+
out = []
|
|
132
|
+
for atom in ctx.dep.atoms:
|
|
133
|
+
if atom.idx >= ctx.ligand.n_atoms:
|
|
134
|
+
continue
|
|
135
|
+
name = ctx.ligand.names[atom.idx]
|
|
136
|
+
title = f"{name}: " + (", ".join(made[atom.idx]) if atom.idx in made else "no contact")
|
|
137
|
+
if ctx.confidence is not None and ctx.options.confidence:
|
|
138
|
+
value = ctx.confidence.ligand([name])
|
|
139
|
+
if value is not None:
|
|
140
|
+
title += f"; pLDDT {value:.0f}"
|
|
141
|
+
data = {"atom": name}
|
|
142
|
+
if atom.idx in whose:
|
|
143
|
+
data["residues"] = ",".join(whose[atom.idx])
|
|
144
|
+
out.append(Group(HIT, [Circle(atom.x, atom.y, _HIT_RADIUS * ctx.metrics.bond_length, Paint())],
|
|
145
|
+
data=data, title=title))
|
|
146
|
+
return out
|