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.
Files changed (70) hide show
  1. bindview/__init__.py +88 -0
  2. bindview/__main__.py +6 -0
  3. bindview/align.py +493 -0
  4. bindview/arrange.js +347 -0
  5. bindview/arrange.py +248 -0
  6. bindview/backends.py +290 -0
  7. bindview/basepairs.py +1711 -0
  8. bindview/chains.py +264 -0
  9. bindview/chem.py +57 -0
  10. bindview/clearance.py +123 -0
  11. bindview/cli.py +990 -0
  12. bindview/compare.py +1854 -0
  13. bindview/confidence.py +531 -0
  14. bindview/consensus.py +303 -0
  15. bindview/covalent.py +220 -0
  16. bindview/depict.py +790 -0
  17. bindview/detect.py +378 -0
  18. bindview/diagram.py +1891 -0
  19. bindview/distance_table.py +589 -0
  20. bindview/ensemble.py +787 -0
  21. bindview/errors.py +47 -0
  22. bindview/exposure.py +207 -0
  23. bindview/features.py +179 -0
  24. bindview/fingerprint.py +469 -0
  25. bindview/fragments.py +304 -0
  26. bindview/geometry.py +482 -0
  27. bindview/graph.py +611 -0
  28. bindview/graphbuild.py +431 -0
  29. bindview/interactions.py +418 -0
  30. bindview/interactive.py +334 -0
  31. bindview/interface.py +1329 -0
  32. bindview/ions.py +155 -0
  33. bindview/layout/__init__.py +15 -0
  34. bindview/layout/body.py +421 -0
  35. bindview/layout/engine.py +1084 -0
  36. bindview/layout/field.py +261 -0
  37. bindview/ligand.py +583 -0
  38. bindview/near.py +67 -0
  39. bindview/options.py +92 -0
  40. bindview/pae.py +991 -0
  41. bindview/peptide.py +610 -0
  42. bindview/plane.py +320 -0
  43. bindview/polymer.py +678 -0
  44. bindview/py.typed +0 -0
  45. bindview/report.py +1407 -0
  46. bindview/residues.py +296 -0
  47. bindview/resolve.py +493 -0
  48. bindview/scene.py +239 -0
  49. bindview/solvent.py +254 -0
  50. bindview/structure.py +1145 -0
  51. bindview/styles/__init__.py +2 -0
  52. bindview/styles/absence.py +180 -0
  53. bindview/styles/base.py +2128 -0
  54. bindview/styles/closeup.py +146 -0
  55. bindview/styles/detailed.py +690 -0
  56. bindview/styles/ligand_draw.py +289 -0
  57. bindview/styles/mixed.py +70 -0
  58. bindview/styles/polymer_draw.py +354 -0
  59. bindview/styles/rings.py +75 -0
  60. bindview/styles/schematic.py +311 -0
  61. bindview/styles/summary.py +147 -0
  62. bindview/svg.py +310 -0
  63. bindview/textmetrics.py +64 -0
  64. bindview/theme.py +317 -0
  65. bindview-0.1.0.dist-info/METADATA +270 -0
  66. bindview-0.1.0.dist-info/RECORD +70 -0
  67. bindview-0.1.0.dist-info/WHEEL +4 -0
  68. bindview-0.1.0.dist-info/entry_points.txt +2 -0
  69. bindview-0.1.0.dist-info/licenses/LICENSE +21 -0
  70. bindview-0.1.0.dist-info/licenses/NOTICE +48 -0
bindview/theme.py ADDED
@@ -0,0 +1,317 @@
1
+ """Colours and dimensions.
2
+
3
+ Every colour the drawing code uses is a named *token* looked up on a
4
+ :class:`Palette`; no literal colour appears in what a style draws. (One is in
5
+ the rules of a figure that answers the pointer, :mod:`bindview.interactive`: the
6
+ ring around an atom that is pointed at, which is the same in every palette.) A
7
+ theme is a palette plus the dimensional :class:`Metrics`. Two palettes ship
8
+ (``light``, ``dark``); a caller can pass its own.
9
+
10
+ A *colour scheme* is a pair of palettes, one for each theme (:data:`SCHEMES`):
11
+ ``standard``, which is those two, and ``contrast``, whose residue classes are
12
+ further apart for every kind of colour vision. The four colours of the pLDDT bands are AlphaFold's and belong
13
+ to no palette (:data:`PLDDT_COLORS`): they mean the same on every page.
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ from dataclasses import dataclass, field, fields, replace
19
+ from typing import Mapping
20
+
21
+ from .interactions import InteractionType
22
+
23
+ __all__ = ["Palette", "Metrics", "LIGHT", "DARK", "get_palette", "SCHEMES", "scheme",
24
+ "CONTRAST", "CONTRAST_DARK", "EXTRAS", "PLDDT_COLORS", "PLDDT_TEXT", "fixed_tokens"]
25
+
26
+
27
+ @dataclass(frozen=True)
28
+ class Palette:
29
+ """Named colours. Tokens are the attribute names; element and residue-class
30
+ colours live in the two mappings."""
31
+
32
+ name: str
33
+ background: str
34
+ text: str # residue names, captions
35
+ text_muted: str # secondary captions, footnotes
36
+ ligand_bond: str
37
+ ligand_carbon: str # explicit carbon labels on the ligand
38
+ protein_bond: str # the "second colour": residue fragments
39
+ protein_label: str # residue names
40
+ protein_atom: str # atom-name labels on fragments that are not element-coloured
41
+ hbond: str
42
+ hydrophobic: str
43
+ saltbridge: str
44
+ pi_stacking: str
45
+ pi_cation: str
46
+ halogen: str
47
+ metal: str
48
+ water_bridge: str
49
+ coordination: str # intra-ligand metal coordination
50
+ beyond: str # contacts flagged beyond the caller's contact set
51
+ exposure: str # solvent-exposure halo (schematic style)
52
+ warning: str
53
+ panel: str # legend / card background
54
+ panel_border: str
55
+ # Link colours of the schematic style, which follows the Maestro conventions.
56
+ sch_hbond: str = "#c026d3"
57
+ sch_saltbridge: str = "#2563eb"
58
+ sch_pi_stacking: str = "#16a34a"
59
+ sch_pi_cation: str = "#dc2626"
60
+ sch_halogen: str = "#a16207"
61
+ sch_metal: str = "#4b5563"
62
+ sch_water_bridge: str = "#0891b2"
63
+ bubble_text: str = "#1f2933"
64
+ bubble_line: str = "#5b6472"
65
+ elements: Mapping[str, str] = field(default_factory=dict)
66
+ residue_classes: Mapping[str, str] = field(default_factory=dict)
67
+ #: Colours for what few figures hold, by token (``class_nucleotide``). They are not among
68
+ #: :meth:`tokens`: a figure that follows the reader's theme declares every token of its palette, whether
69
+ #: it draws in that colour or not. These are declared by the figures that use them, and by no other.
70
+ extra: Mapping[str, str] = field(default_factory=dict)
71
+
72
+ def element(self, symbol: str, on_protein: bool = False) -> str:
73
+ """The colour of an element's letter: of a carbon, the colour of the bonds it is drawn with."""
74
+ if symbol == "C":
75
+ return self.protein_bond if on_protein else self.ligand_carbon
76
+ return self.elements.get(symbol, self.elements.get("*", self.text))
77
+
78
+ def interaction(self, kind: str) -> str:
79
+ """The colour of a kind of contact, by its name in a table (``"hbond"``, ``"pi_stacking"``)."""
80
+ try:
81
+ return str(getattr(self, InteractionType(kind).value))
82
+ except (ValueError, AttributeError):
83
+ raise ValueError(f"{kind!r} is no kind of contact that a palette has a colour for") from None
84
+
85
+ def element_token(self, symbol: str, on_protein: bool = False) -> str:
86
+ """The colour *token* for an element label (see :meth:`tokens`)."""
87
+ if symbol == "C":
88
+ return "protein_atom" if on_protein else "ligand_carbon"
89
+ return f"element_{symbol}" if symbol in self.elements and symbol != "*" else "element_other"
90
+
91
+ def residue_class(self, cls: str) -> str:
92
+ """The colour of a class of residues."""
93
+ if cls in self.residue_classes:
94
+ return self.residue_classes[cls]
95
+ return self.extra.get(f"class_{cls}", self.residue_classes.get("other", self.panel))
96
+
97
+ def with_(self, **changes: object) -> "Palette":
98
+ """The same palette with some of its colours changed."""
99
+ return replace(self, **changes) # type: ignore[arg-type]
100
+
101
+ def tokens(self) -> dict[str, str]:
102
+ """Flat ``token -> colour`` map (used for CSS-variable output)."""
103
+ out = {f.name: getattr(self, f.name) for f in fields(self)
104
+ if isinstance(getattr(self, f.name), str) and f.name != "name"}
105
+ out.update({f"element_{k}": v for k, v in self.elements.items() if k != "*"})
106
+ out["element_other"] = self.elements.get("*", self.text)
107
+ out.update({f"class_{k}": v for k, v in self.residue_classes.items()})
108
+ return out
109
+
110
+
111
+ LIGHT = Palette(
112
+ name="light",
113
+ background="#ffffff",
114
+ text="#1f2933",
115
+ text_muted="#667085",
116
+ ligand_bond="#1f2933",
117
+ ligand_carbon="#1f2933",
118
+ protein_bond="#6b7a90",
119
+ protein_label="#1f2933",
120
+ protein_atom="#4b5768",
121
+ hbond="#1a9641",
122
+ hydrophobic="#c0392b",
123
+ saltbridge="#7b3fa0",
124
+ pi_stacking="#00838f",
125
+ pi_cation="#d97706",
126
+ halogen="#c2185b",
127
+ metal="#37474f",
128
+ water_bridge="#1e88e5",
129
+ coordination="#8b95a5",
130
+ beyond="#9aa4b2",
131
+ exposure="#c9ced6",
132
+ warning="#b45309",
133
+ panel="#f6f7f9",
134
+ panel_border="#d5dae1",
135
+ elements={
136
+ "N": "#2f5fd0", "O": "#d6332a", "S": "#a67c00", "P": "#d9730d",
137
+ "F": "#2e9e44", "Cl": "#2e9e44", "Br": "#a0522d", "I": "#7b3fbf",
138
+ "B": "#c77c5e", "Se": "#b8860b", "H": "#667085",
139
+ "Fe": "#b5541a", "Co": "#c2417a", "Zn": "#5b6f8a", "Mg": "#3f8f3f", "Mn": "#8a5fb0",
140
+ "Ca": "#4f8f4f", "Cu": "#b06a2c", "Ni": "#3f8a7a", "Na": "#7b5fc0", "K": "#7b5fc0",
141
+ "*": "#5b6472",
142
+ },
143
+ residue_classes={
144
+ "hydrophobic": "#b8dc7a", "polar": "#9fdcee", "positive": "#a9a6f0", "negative": "#f4a98a",
145
+ "glycine": "#ecebd8", "metal": "#b9bec7", "water": "#dfe7f2", "other": "#d9dde3",
146
+ },
147
+ extra={"class_nucleotide": "#f3d477", "absent": "#facc15"},
148
+ )
149
+
150
+ DARK = Palette(
151
+ sch_hbond="#e879f9", sch_saltbridge="#60a5fa", sch_pi_stacking="#4ade80", sch_pi_cation="#f87171",
152
+ sch_halogen="#facc15", sch_metal="#cbd5e1", sch_water_bridge="#22d3ee",
153
+ bubble_text="#f1f5f9", bubble_line="#94a3b8",
154
+ name="dark",
155
+ background="#0f172a",
156
+ text="#e2e8f0",
157
+ text_muted="#94a3b8",
158
+ ligand_bond="#e2e8f0",
159
+ ligand_carbon="#e2e8f0",
160
+ protein_bond="#8fa0b8",
161
+ protein_label="#e2e8f0",
162
+ protein_atom="#a9b6c8",
163
+ hbond="#4ade80",
164
+ hydrophobic="#f87171",
165
+ saltbridge="#c084fc",
166
+ pi_stacking="#22d3ee",
167
+ pi_cation="#fb923c",
168
+ halogen="#f472b6",
169
+ metal="#cbd5e1",
170
+ water_bridge="#60a5fa",
171
+ coordination="#7c8aa0",
172
+ beyond="#64748b",
173
+ exposure="#3b475c",
174
+ warning="#fbbf24",
175
+ panel="#172036",
176
+ panel_border="#2b3956",
177
+ elements={
178
+ "N": "#7aa2f7", "O": "#f7768e", "S": "#e0af68", "P": "#ff9e64",
179
+ "F": "#73daca", "Cl": "#73daca", "Br": "#d19a66", "I": "#bb9af7",
180
+ "B": "#e0a58b", "Se": "#e0af68", "H": "#94a3b8",
181
+ "Fe": "#f0a070", "Co": "#f28cb1", "Zn": "#9fb4d0", "Mg": "#86d086", "Mn": "#c4a3e8",
182
+ "Ca": "#8fd08f", "Cu": "#e0a070", "Ni": "#7fd0c0", "Na": "#b9a3f0", "K": "#b9a3f0",
183
+ "*": "#b6c0cf",
184
+ },
185
+ residue_classes={
186
+ "hydrophobic": "#3f6212", "polar": "#155e75", "positive": "#3730a3", "negative": "#9a3412",
187
+ "glycine": "#57534e", "metal": "#475569", "water": "#334155", "other": "#3b4658",
188
+ },
189
+ extra={"class_nucleotide": "#854d0e", "absent": "#a16207"},
190
+ )
191
+
192
+ # Navy text on white (#0f172a, #475569), with cyan and fuchsia (#0891b2, #d946ef) and the accents beside them
193
+ # (emerald, sky, indigo). What is told apart by colour alone here is the class of a residue, so the five
194
+ # fills were chosen by measurement and not by eye: of the tints of that family, those in which the worst of
195
+ # all pairs is further apart than in the standard palette, for full colour vision and for red-green and
196
+ # blue-yellow colour blindness (docs/reference.md has the numbers). Lines keep the colours of the standard
197
+ # palette: what a line means does not change with the scheme. What is drawn of a residue is no nearer to
198
+ # the colour of any line than the standard's grey is: on white that is a step of the blue, and on the dark
199
+ # ground, where the light blues are the colours of lines, the muted grey.
200
+ CONTRAST = LIGHT.with_(
201
+ name="contrast",
202
+ background="#ffffff", text="#0f172a", text_muted="#475569",
203
+ ligand_bond="#0f172a", ligand_carbon="#0f172a",
204
+ protein_bond="#0369a1", protein_label="#0f172a", protein_atom="#075985",
205
+ coordination="#94a3b8", beyond="#94a3b8", exposure="#cbd5e1",
206
+ panel="#f8fafc", panel_border="#cbd5e1",
207
+ bubble_text="#0f172a", bubble_line="#64748b",
208
+ residue_classes={
209
+ "hydrophobic": "#10b981", "polar": "#67e8f9", "positive": "#a5b4fc", "negative": "#d946ef",
210
+ "glycine": "#f1f5f9", "metal": "#cbd5e1", "water": "#e0f2fe", "other": "#e2e8f0",
211
+ },
212
+ extra={"class_nucleotide": "#fbbf24", "absent": "#facc15"},
213
+ )
214
+
215
+ CONTRAST_DARK = DARK.with_(
216
+ name="contrast-dark",
217
+ background="#0f172a", text="#f8fafc", text_muted="#94a3b8",
218
+ ligand_bond="#f8fafc", ligand_carbon="#f8fafc",
219
+ protein_bond="#94a3b8", protein_label="#f8fafc", protein_atom="#cbd5e1",
220
+ coordination="#64748b", beyond="#64748b", exposure="#334155",
221
+ panel="#1e293b", panel_border="#334155",
222
+ bubble_text="#f8fafc", bubble_line="#94a3b8",
223
+ residue_classes={
224
+ "hydrophobic": "#064e3b", "polar": "#0e7490", "positive": "#3730a3", "negative": "#c026d3",
225
+ "glycine": "#1e293b", "metal": "#475569", "water": "#0c4a6e", "other": "#334155",
226
+ },
227
+ extra={"class_nucleotide": "#b45309", "absent": "#a16207"},
228
+ )
229
+
230
+ #: The colour schemes: for each, the palette of the light theme and that of the dark one.
231
+ SCHEMES: dict[str, tuple[Palette, Palette]] = {
232
+ "standard": (LIGHT, DARK),
233
+ "contrast": (CONTRAST, CONTRAST_DARK),
234
+ }
235
+
236
+ #: What stands for a colour of :attr:`Palette.extra` in a palette of the caller's own that has none by that name.
237
+ EXTRAS: dict[str, str] = {"absent": "#facc15"}
238
+
239
+ #: AlphaFold's colours for the four bands of pLDDT, best first, as its database and viewers draw them.
240
+ #: They are the same in every scheme and theme: a reader knows them from there, and reads them as that.
241
+ PLDDT_COLORS: dict[str, str] = {"very_high": "#0053d6", "confident": "#65cbf3", "low": "#ffdb13",
242
+ "very_low": "#ff7d45"}
243
+ #: The colour of a name that stands on each of them.
244
+ PLDDT_TEXT: dict[str, str] = {"very_high": "#ffffff", "confident": "#1f2933", "low": "#1f2933",
245
+ "very_low": "#1f2933"}
246
+
247
+
248
+ def fixed_tokens() -> dict[str, str]:
249
+ """The tokens that no palette holds, because they are the same in all of them: ``plddt_<band>`` and
250
+ ``plddt_text_<band>``. A figure names them only where it was asked to colour by pLDDT."""
251
+ out = {f"plddt_{band}": colour for band, colour in PLDDT_COLORS.items()}
252
+ out.update({f"plddt_text_{band}": colour for band, colour in PLDDT_TEXT.items()})
253
+ return out
254
+
255
+
256
+ def scheme(colors: str = "standard") -> tuple[Palette, Palette]:
257
+ """The two palettes of a colour scheme, light and dark."""
258
+ try:
259
+ return SCHEMES[str(colors).lower()]
260
+ except KeyError:
261
+ known = ", ".join(repr(k) for k in SCHEMES)
262
+ raise ValueError(f"unknown colours {colors!r}; the schemes are {known}") from None
263
+
264
+
265
+ def get_palette(theme: "str | Palette", colors: str = "standard") -> Palette:
266
+ """The palette of a theme (``"light"`` or ``"dark"``) in a colour scheme. A :class:`Palette` of the
267
+ caller's own is its colours already, and is returned as it is."""
268
+ if isinstance(theme, Palette):
269
+ if str(colors).lower() != "standard":
270
+ raise ValueError(f"a Palette of your own is its colours: leave colors at 'standard', not {colors!r}")
271
+ return theme
272
+ light, dark = scheme(colors)
273
+ name = str(theme).lower()
274
+ if name == "light":
275
+ return light
276
+ if name == "dark":
277
+ return dark
278
+ if name == "auto":
279
+ raise ValueError("the theme 'auto' is a figure with both palettes and no palette itself: ask for 'light' or "
280
+ "'dark' here, or for the two with scheme()")
281
+ raise ValueError(f"unknown theme {theme!r}; use 'light', 'dark', 'auto' or a Palette")
282
+
283
+
284
+ @dataclass(frozen=True)
285
+ class Metrics:
286
+ """Dimensions, in SVG user units (px at natural size). Everything scales
287
+ from ``bond_length``; fonts are absolute because legibility is."""
288
+
289
+ bond_length: float = 30.0
290
+ bond_width: float = 1.7
291
+ double_offset: float = 4.3 # distance between the lines of a double bond
292
+ wedge_width: float = 6.2 # full width of a wedge at its wide end
293
+ hash_spacing: float = 2.7
294
+ label_gap: float = 2.2 # clearance between a bond end and an atom label
295
+ atom_font: float = 13.5
296
+ sub_font: float = 9.5 # hydrogen counts
297
+ charge_font: float = 9.5
298
+ protein_bond_width: float = 1.35
299
+ protein_bond_scale: float = 0.82 # fragment bond length relative to the ligand's
300
+ protein_atom_font: float = 9.5
301
+ residue_font: float = 12.0
302
+ interaction_width: float = 1.35
303
+ distance_font: float = 9.5
304
+ legend_font: float = 10.5
305
+ title_font: float = 13.0
306
+ caption_font: float = 10.5
307
+ lash_length: float = 6.0
308
+ spoke_inner: float = 6.5 # ligand-atom spokes start/end radius
309
+ spoke_outer: float = 11.5
310
+ margin: float = 18.0
311
+ #: A ligand drawn as a chain: centre-to-centre distance of two of its residues, in bond lengths.
312
+ #: A crowded chain is drawn with more (the residues around it need the room), never with less.
313
+ chain_pitch: float = 0.9
314
+
315
+ def with_(self, **changes: float) -> "Metrics":
316
+ """The same dimensions with some of them changed."""
317
+ return replace(self, **changes)
@@ -0,0 +1,270 @@
1
+ Metadata-Version: 2.5
2
+ Name: bindview
3
+ Version: 0.1.0
4
+ Summary: Publication-quality figures of molecular interactions: small molecules, peptides, RNA, DNA and proteins, from one structure to an ensemble.
5
+ Project-URL: Homepage, https://github.com/jakob-steuer/bindview
6
+ Project-URL: Repository, https://github.com/jakob-steuer/bindview
7
+ Project-URL: Issues, https://github.com/jakob-steuer/bindview/issues
8
+ Project-URL: Changelog, https://github.com/jakob-steuer/bindview/blob/main/CHANGELOG.md
9
+ Author: Jakob Steuer
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ License-File: NOTICE
13
+ Keywords: cheminformatics,interaction-diagram,protein-ligand,structural-biology,svg
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
20
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.12
23
+ Requires-Dist: numpy>=2.0
24
+ Requires-Dist: rdkit>=2026.9.1
25
+ Provides-Extra: dev
26
+ Requires-Dist: mypy>=1.8; extra == 'dev'
27
+ Requires-Dist: pytest>=7; extra == 'dev'
28
+ Provides-Extra: plip
29
+ Requires-Dist: plip>=2.3; extra == 'plip'
30
+ Description-Content-Type: text/markdown
31
+
32
+ <h1 align="center">bindview</h1>
33
+
34
+ <p align="center">
35
+ <img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/badges/version.svg" alt="version"> <img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/badges/python.svg" alt="Python">
36
+ <img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/badges/rdkit.svg" alt="RDKit"> <img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/badges/numpy.svg" alt="NumPy">
37
+ <img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/badges/licence.svg" alt="licence">
38
+ </p>
39
+
40
+ <p align="center">
41
+ <b>Publication-quality figures of molecular interactions:<br>small molecules, peptides, RNA, DNA and proteins, from one structure to an ensemble.</b><br>
42
+ A structure in, one SVG out. Python and command line.
43
+ </p>
44
+
45
+ <p align="center">
46
+ <a href="#install">Install</a> · <a href="#quick-start">Quick start</a> · <a href="#figures">Figures</a> ·
47
+ <a href="https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md">Manual</a> · <a href="https://github.com/jakob-steuer/bindview/blob/main/docs/api.md">API</a> · <a href="https://github.com/jakob-steuer/bindview/blob/main/docs/reference.md">Reference</a>
48
+ </p>
49
+
50
+ - **Every contact ends on what makes it**: a halogen bond on its fluorine, stacking on the ring, a salt bridge at the charged group.
51
+ - **Honest about the model**: pLDDT, PAE and shares of an ensemble are drawn into the figure, or stay out when the file does not declare them.
52
+ - **Legible or refused**: nothing overlaps, and the smallest text is checked against the page you print on.
53
+ - **Yours to change**: every place, colour and setting; by its words, or by dragging in a browser.
54
+
55
+ ## Install
56
+
57
+ ```bash
58
+ git clone https://github.com/jakob-steuer/bindview && cd bindview
59
+ pip install . # RDKit and NumPy, nothing else
60
+ ```
61
+
62
+ Python 3.12 or newer, tested on 3.12 on macOS and Linux. Detecting contacts with [PLIP](https://github.com/pharmai/plip)
63
+ is optional and GPL-2.0 (`pip install ".[plip]"`). Without it, bindview makes a plain table of contacts itself, or
64
+ draws the one you give it.
65
+
66
+ ## Quick start
67
+
68
+ ```python
69
+ from bindview import Diagram
70
+
71
+ dia = Diagram.from_structure(
72
+ "testdata/egfr_osimertinib/model.cif.gz", ligand="YY3", # a residue name, "chain:number", or a peptide's chain
73
+ smiles="Cn1cc(c2c1cccc2)c3ccnc(n3)Nc4cc(c(cc4OC)N(C)CCN(C)C)NC(=O)C=C",
74
+ interactions="distances", # or a table, a list of records, or None to detect with PLIP
75
+ covalent=True) # the bond to Cys797 that the file declares
76
+ dia.render_svg("osimertinib.svg")
77
+ ```
78
+
79
+ The same from the command line:
80
+
81
+ ```bash
82
+ bindview render testdata/egfr_osimertinib/model.cif.gz --ligand YY3 --distances-only --covalent -o osimertinib.svg \
83
+ --smiles "Cn1cc(c2c1cccc2)c3ccnc(n3)Nc4cc(c(cc4OC)N(C)CCN(C)C)NC(=O)C=C"
84
+ ```
85
+
86
+ Not sure what is in a file? `bindview report testdata/kit_imatinib -o report.html` looks, draws every figure the input
87
+ has, and prints the call under each.
88
+
89
+ ## Figures
90
+
91
+ The code under each picture draws it from the root of the repository (here without its words: `bare=True`). A figure
92
+ of the library, opened by a click, answers the pointer. `case` reads a folder of [`testdata`](https://github.com/jakob-steuer/bindview/blob/main/testdata): a PDB entry,
93
+ its ligand's SMILES, and the contacts that PLIP found.
94
+
95
+ <!-- runs -->
96
+ ```python
97
+ import json, sys
98
+ from bindview import (BasePairs, Comparison, Diagram, Interface, Structure, read_rnapolis_pairs,
99
+ read_rnapolis_stacks, read_structure)
100
+ from bindview.distance_table import interface_contacts
101
+
102
+ def case(slug, model=None, interactions=None, **options):
103
+ folder = f"testdata/{slug}"
104
+ lig = json.load(open(f"{folder}/meta.json"))["ligand"]
105
+ return Diagram.from_structure(model or f"{folder}/model.cif.gz", lig["residue_name_in_cif"], lig["smiles"],
106
+ interactions or f"{folder}/interactions.tsv", name=lig["name"], **options)
107
+ ```
108
+
109
+ ### A ligand in its pocket
110
+
111
+ <table><tr>
112
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/detailed.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/detailed.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/detailed.light.svg" alt="imatinib in c-Kit, with the atoms that make the contacts"></picture></a><br><b>Detailed</b><br><sub>the atoms that make the contacts</sub></td>
113
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/schematic.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/schematic.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/schematic.light.svg" alt="the same with residues as bubbles"></picture></a><br><b>Schematic</b><br><sub>residues as bubbles, the pocket lined by its contacts</sub></td>
114
+ </tr></table>
115
+
116
+ <!-- draws: detailed schematic -->
117
+ ```python
118
+ kit = case("kit_imatinib") # imatinib in c-Kit (1T46)
119
+ kit.render()
120
+ kit.render(style="schematic")
121
+ ```
122
+
123
+ ### Confidence of a prediction
124
+
125
+ The repository holds no predicted complex with a ligand: these are two domains of an AlphaFold database model, with
126
+ its own pLDDT and predicted aligned error (PAE).
127
+
128
+ <table><tr>
129
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/pae.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/pae.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/pae.light.svg" alt="contacts between two domains, each with its PAE"></picture></a><br><b>PAE on the contacts</b><br><sub>written from 5 Å; pLDDT by line weight</sub></td>
130
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/plddt.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/plddt.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/plddt.light.svg" alt="the same with residues in the colours of pLDDT"></picture></a><br><b>pLDDT in AlphaFold's colours</b><br><sub>read only where the file declares it</sub></td>
131
+ </tr></table>
132
+
133
+ <!-- draws: pae plddt -->
134
+ ```python
135
+ afdb = "testdata/interface_pae/afdb_tectb" # beta-tectorin, cut between its domains
136
+ model = read_structure(f"{afdb}/model.cif.gz").split("A", {"N": (28, 124), "Z": (126, 269)})
137
+ domains = Interface(model, ["N-terminal domain=N", "ZP domain=Z"], interface_contacts(model, ["N"], ["Z"]),
138
+ pae=f"{afdb}/predicted_aligned_error.json.gz")
139
+ domains.render()
140
+ domains.render(plddt_colors=True)
141
+ ```
142
+
143
+ ### Waters and ions
144
+
145
+ <table><tr>
146
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/water.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/water.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/water.light.svg" alt="a steroid with a predicted water between ligand and protein"></picture></a><br><b>Predicted water</b><br><sub>marked as predicted, in a model without waters</sub></td>
147
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/ion.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/ion.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/ion.light.svg" alt="celecoxib held by a zinc ion and three histidines"></picture></a><br><b>An ion that bridges</b><br><sub>celecoxib on the zinc of carbonic anhydrase II</sub></td>
148
+ </tr></table>
149
+
150
+ <!-- draws: water ion -->
151
+ ```python
152
+ r1881 = read_structure("testdata/ar_r1881/model.cif.gz") # R1881 in the androgen receptor (2AO6)
153
+ dry = Structure([a for a in r1881.atoms if a.resname != "HOH"]) # its crystal waters taken out
154
+ case("ar_r1881", dry, "distances").render(solvent_sites=True)
155
+ case("ca2_celecoxib", ions=True).render() # 1OQ5
156
+ ```
157
+
158
+ ### The pocket in 3D
159
+
160
+ A sketch: [`prototype/ppi_openbook`](https://github.com/jakob-steuer/bindview/blob/main/prototype/ppi_openbook), not part of the package.
161
+
162
+ <table><tr>
163
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/opened.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/opened.svg" alt="c-Kit cut open along imatinib"></a><br><b>Opened like a book</b><br><sub>the ligand, both halves of the pocket, and a flat map</sub></td>
164
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/enclosed.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/enclosed.svg" alt="the pocket of R1881, cut through"></a><br><b>An enclosed ligand</b><br><sub>cut along its own plane</sub></td>
165
+ </tr></table>
166
+
167
+ <!-- draws: opened enclosed -->
168
+ ```python
169
+ sys.path.insert(0, "prototype/ppi_openbook")
170
+ import ligandbook, pocket
171
+
172
+ ligandbook.panels(kit)
173
+ pocket.figure(case("ar_r1881"))
174
+ ```
175
+
176
+ ### Several ligands
177
+
178
+ <table><tr>
179
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/difference.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/difference.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/difference.light.svg" alt="two ligands of the androgen receptor, compared residue by residue"></picture></a><br><b>What differs</b><br><sub>a steroid and bicalutamide on one frame of residues</sub></td>
180
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/several.svg?raw=true"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/several.svg" alt="three steroids in one pocket as sticks"></a><br><b>In 3D (a sketch)</b><br><sub>three corticosteroids in one pocket, and what they share</sub></td>
181
+ </tr></table>
182
+
183
+ <!-- draws: difference several -->
184
+ ```python
185
+ Comparison([case("ar_r1881"), case("ar_bicalutamide")]).render(view="difference")
186
+
187
+ import interact3d
188
+ interact3d.several([case(s) for s in ("gr_dexamethasone", "gr_mometasone", "gr_budesonide")])
189
+ ```
190
+
191
+ ### A trajectory
192
+
193
+ <table><tr>
194
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/trajectory.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/trajectory.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/trajectory.light.svg" alt="a ligand in RNA with the share of the frames on every contact"></picture></a><br><b>One frame, with the shares of all</b><br><sub>each contact with the share of 4,001 frames that make it</sub></td>
195
+ </tr></table>
196
+
197
+ <!-- draws: trajectory -->
198
+ ```python
199
+ sys.path.insert(0, "prototype/md_occupancy") # bindview reads no trajectory: a sketch counts the contacts
200
+ import occupancy
201
+
202
+ md = occupancy.load("testdata/md/riboswitch_bisguanidine/simulation_1.json")
203
+ frames = md.state("all")
204
+ Diagram.from_structure(frames.frame, "BGD", md.smiles, frames.records, ensemble=frames.of).render()
205
+ ```
206
+
207
+ ### RNA and DNA
208
+
209
+ <table><tr>
210
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/rna.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/rna.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/rna.light.svg" alt="a ligand in a riboswitch, with bases and phosphates"></picture></a><br><b>A ligand in RNA</b><br><sub>a riboswitch, down to its bases</sub></td>
211
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/basepairs.live.svg?raw=true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/basepairs.dark.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/basepairs.light.svg" alt="two RNA hairpins with the ligand between them"></picture></a><br><b>Base pairs</b><br><sub>two hairpins, and the ligand between their loops</sub></td>
212
+ </tr></table>
213
+
214
+ <!-- draws: rna basepairs -->
215
+ ```python
216
+ folder = "testdata/nucleic/riboswitch_bisguanidine"
217
+ model = read_structure(f"{folder}/model.pdb")
218
+ smiles = json.load(open(f"{folder}/meta.json"))["ligand"]["smiles"]
219
+ Diagram.from_structure(model, "BGD", smiles, f"{folder}/interactions.tsv").render()
220
+
221
+ found = f"{folder}/basepairs.rnapolis.json"
222
+ BasePairs(model, ["A", "B"], read_rnapolis_pairs(found), stacks=read_rnapolis_stacks(found),
223
+ contacts=interface_contacts(model, ["A"], ["B"], stacking=True),
224
+ ligand="BGD", ligand_contacts=f"{folder}/interactions.tsv").render()
225
+ ```
226
+
227
+ ### Peptides and proteins
228
+
229
+ Sketches. The package itself draws a peptide as a chain of its residues, and two chains with `Interface`.
230
+
231
+ <table><tr>
232
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/groove.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/groove.svg" alt="a peptide in the groove of HLA-A2, opened"></a><br><b>A peptide in its groove</b><br><sub>HLA-A2 with a nonamer (3MRE), opened like a book</sub></td>
233
+ <td width="50%" align="center" valign="top"><a href="https://github.com/jakob-steuer/bindview/blob/main/docs/images/readme/regions.svg"><img src="https://raw.githubusercontent.com/jakob-steuer/bindview/main/docs/images/readme/regions.svg" alt="an antibody on lysozyme, the interface in regions"></a><br><b>An interface in regions</b><br><sub>HyHEL-10 on lysozyme (3D9A), and how its regions are found</sub></td>
234
+ </tr></table>
235
+
236
+ <!-- draws: groove regions -->
237
+ ```python
238
+ import book, openbook, regions
239
+
240
+ openbook.panels(book.load("testdata/mhc_peptide/model.cif.gz", ["A"], ["P"], names=("HLA-A2", "peptide GLCTLVAML")))
241
+ regions.figure(book.load("testdata/fab_lysozyme/model.cif.gz", ["H", "L"], ["C"], names=("HyHEL-10 Fab", "lysozyme")))
242
+ ```
243
+
244
+ Also in the manual: [arranging by hand](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#arranging-by-hand) (`dia.arrange()`),
245
+ [residues a shorter construct lacks](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#residues-an-isoform-lacks),
246
+ [ensembles of models](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#several-models), [a page that drives its figures](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#figures-in-a-web-page),
247
+ [dark mode](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#colours-and-themes), [fingerprints as CSV](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md#several-ligands).
248
+
249
+ ## Where to look
250
+
251
+ | I want to … | |
252
+ |---|---|
253
+ | draw my first figure, pass in contacts, change its look | [Manual](https://github.com/jakob-steuer/bindview/blob/main/docs/manual.md) |
254
+ | see every option and what it does | [API](https://github.com/jakob-steuer/bindview/blob/main/docs/api.md), or `bindview.options()` in Python |
255
+ | know the rules, the thresholds and the limits | [Reference](https://github.com/jakob-steuer/bindview/blob/main/docs/reference.md) |
256
+ | read or write a figure's layout as JSON | [Graph schema](https://github.com/jakob-steuer/bindview/blob/main/docs/graph-schema.md) |
257
+ | draw from the command line | `bindview --help`, `bindview render --help` |
258
+
259
+ ## Good to know
260
+
261
+ - Give the **SMILES** where you can: coordinates alone do not say which bond is double.
262
+ - A figure shows **what the model has**. It cannot know of a missing cofactor, partner chain or water.
263
+ - bindview computes **no score**. Thin lines mean weak support, not weak binding.
264
+ - `result.status` says how it went (`ok`, `empty`, `degraded`, `unreadable`) and `result.warnings` why, in words.
265
+
266
+ ## Licence and citation
267
+
268
+ MIT ([LICENSE](https://github.com/jakob-steuer/bindview/blob/main/LICENSE)). The core imports RDKit and NumPy (both BSD) and nothing else; one module imports PLIP, when
269
+ asked to. The test data are open: each folder says where it is from, and [NOTICE](https://github.com/jakob-steuer/bindview/blob/main/NOTICE) names the work of others
270
+ in the repository. Cite with [CITATION.cff](https://github.com/jakob-steuer/bindview/blob/main/CITATION.cff). Changes: [CHANGELOG.md](https://github.com/jakob-steuer/bindview/blob/main/CHANGELOG.md).