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
bindview/cli.py
ADDED
|
@@ -0,0 +1,990 @@
|
|
|
1
|
+
"""Command line interface.
|
|
2
|
+
|
|
3
|
+
bindview render model.cif --ligand LIG_B --smiles-from meta.json -o out.svg
|
|
4
|
+
bindview compare case_a/ case_b/ -o difference.svg # two ligands: difference view
|
|
5
|
+
bindview compare series/*/ -o consensus.svg --fingerprints fp.csv
|
|
6
|
+
bindview fingerprint series/*/ --form wide > fp.csv
|
|
7
|
+
bindview report model.cif -o report.html # looks what the input is, and draws that
|
|
8
|
+
bindview basepairs model.pdb --chains A B --pairs pairs.json # two strands and their base pairs
|
|
9
|
+
|
|
10
|
+
Exit status: 0 when a figure was produced for a valid or empty complex; 3 when
|
|
11
|
+
it is not readable at the size asked for (``render`` and ``compare`` still write
|
|
12
|
+
a summary figure unless ``--on-unreadable none``, ``basepairs`` the figure
|
|
13
|
+
itself); 2 on an error, which is one line on standard error.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
import argparse
|
|
19
|
+
import json
|
|
20
|
+
import math
|
|
21
|
+
import re
|
|
22
|
+
import sys
|
|
23
|
+
from contextlib import contextmanager
|
|
24
|
+
from pathlib import Path
|
|
25
|
+
from typing import Any, Callable, Iterator, Sequence
|
|
26
|
+
|
|
27
|
+
from . import __version__
|
|
28
|
+
from .compare import VIEWS, Comparison
|
|
29
|
+
from .diagram import DISTANCES, STYLES, Diagram
|
|
30
|
+
from .theme import SCHEMES
|
|
31
|
+
from .errors import BindviewError
|
|
32
|
+
from .graph import Graph
|
|
33
|
+
from .interactions import Interaction, load_interactions
|
|
34
|
+
from .residues import ATOM_LABELS
|
|
35
|
+
from .styles.absence import ABSENT_STYLES
|
|
36
|
+
from .styles.base import LINES, LININGS, RESIDUE_FORMS, SOLVENT_MARKS
|
|
37
|
+
|
|
38
|
+
__all__ = ["main", "build_parser"]
|
|
39
|
+
|
|
40
|
+
_SIBLING_TABLES = ("interactions.tsv", "interactions.csv")
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class _Help(argparse.RawDescriptionHelpFormatter):
|
|
44
|
+
"""Descriptions and examples as written (they are wrapped by hand); options in a wider column."""
|
|
45
|
+
|
|
46
|
+
def __init__(self, prog: str) -> None:
|
|
47
|
+
super().__init__(prog, max_help_position=32)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _command(sub: Any, name: str, summary: str, usage: str, description: str, examples: str) -> argparse.ArgumentParser:
|
|
51
|
+
return sub.add_parser(name, help=summary, usage=usage, description=description,
|
|
52
|
+
epilog="examples:\n" + examples, formatter_class=_Help)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
_EXIT = "\n\nexit status: 0 a figure was written; 3 it is not readable at the size asked for; 2 an error."
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def _from(least: float, above: bool = False, whole: bool = False) -> "Callable[[str], Any]":
|
|
59
|
+
"""The type of an argument that is a number from ``least`` up (``above``: and not ``least`` itself): what is
|
|
60
|
+
no number, not finite or too small is refused by the parser, which names the argument."""
|
|
61
|
+
kind = ("a whole number " if whole else "a number ") + (f"above {least:g}" if above else f"from {least:g} up")
|
|
62
|
+
|
|
63
|
+
def parse(text: str) -> Any:
|
|
64
|
+
try:
|
|
65
|
+
value = int(text) if whole else float(text)
|
|
66
|
+
except ValueError:
|
|
67
|
+
value = math.nan
|
|
68
|
+
if not math.isfinite(value) or value < least or (above and value == least):
|
|
69
|
+
raise argparse.ArgumentTypeError(f"{text!r} is not {kind}")
|
|
70
|
+
return value
|
|
71
|
+
|
|
72
|
+
return parse
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def build_parser() -> argparse.ArgumentParser:
|
|
76
|
+
p = argparse.ArgumentParser(
|
|
77
|
+
prog="bindview", formatter_class=_Help,
|
|
78
|
+
description="Figures of molecular interactions, as SVG.",
|
|
79
|
+
epilog="'bindview COMMAND --help' lists the options of a command; docs/manual.md shows how they are used.")
|
|
80
|
+
p.add_argument("--version", action="version", version=f"bindview {__version__}")
|
|
81
|
+
sub = p.add_subparsers(dest="command", required=True, title="commands", metavar="COMMAND")
|
|
82
|
+
|
|
83
|
+
# -- render ---------------------------------------------------------------------------------------
|
|
84
|
+
r = _command(
|
|
85
|
+
sub, "render", "draw one ligand in its pocket", "bindview render STRUCTURE --ligand LIGAND [options]",
|
|
86
|
+
"Draw the contacts of one ligand in a structure file as an SVG figure.\n\n"
|
|
87
|
+
"The contacts come from a table you give (--interactions), from interactions.tsv beside the\n"
|
|
88
|
+
"structure, or from PLIP, which is optional and GPL-2.0 (pip install \"bindview[plip]\", or\n"
|
|
89
|
+
"pip install \".[plip]\" in a clone of the repository)." + _EXIT,
|
|
90
|
+
" bindview render model.cif --ligand LIG_B --smiles \"CC(=O)Nc1ccc(O)cc1\" -o figure.svg\n"
|
|
91
|
+
" bindview render model.cif --ligand B:1 --interactions contacts.tsv --style schematic\n"
|
|
92
|
+
" bindview render frame.pdb --ligand LIG --interactions md.tsv --ensemble \"1,000 frames\" \\\n"
|
|
93
|
+
" --bare --notes-file caption.txt")
|
|
94
|
+
a = r.add_argument_group("input")
|
|
95
|
+
a.add_argument("structure", metavar="STRUCTURE", help="mmCIF or PDB file")
|
|
96
|
+
a.add_argument("--ligand", required=True,
|
|
97
|
+
help="a residue name (LIG_B), chain:number (B:1), chain:name:number, or a peptide chain by its "
|
|
98
|
+
"name (P)")
|
|
99
|
+
one = a.add_mutually_exclusive_group()
|
|
100
|
+
one.add_argument("--smiles", help="the ligand's SMILES: it gives the bond orders")
|
|
101
|
+
one.add_argument("--smiles-from", metavar="JSON",
|
|
102
|
+
help="a JSON file with 'smiles' or 'ligand.smiles' (also looked for beside the structure)")
|
|
103
|
+
a.add_argument("--ligand-as", choices=("auto", "atoms", "chain"), default="auto",
|
|
104
|
+
help="the ligand as atoms or as a chain of its residues (auto: a chain from 8 amino acids up)")
|
|
105
|
+
a.add_argument("--no-ionize", action="store_true", help="draw acids as the SMILES writes them, not deprotonated")
|
|
106
|
+
k = r.add_argument_group("contacts")
|
|
107
|
+
k.add_argument("--interactions", metavar="TABLE",
|
|
108
|
+
help="a table of contacts (.tsv/.csv); default: interactions.tsv beside the structure, else PLIP")
|
|
109
|
+
k.add_argument("--detect", action="store_true", help="find the contacts with PLIP even where a table lies beside")
|
|
110
|
+
k.add_argument("--distances-only", action="store_true",
|
|
111
|
+
help="make the table from the distances of the heavy atoms: nothing else is needed, and it is cruder "
|
|
112
|
+
"than PLIP")
|
|
113
|
+
k.add_argument("--ensemble", metavar="TEXT",
|
|
114
|
+
help="what the table's 'occupancy' column is a share of, for the key (e.g. '1,000 frames')")
|
|
115
|
+
k.add_argument("--covalent", action="store_true",
|
|
116
|
+
help="look for covalent bonds between the ligand and a residue, as the file declares them and by "
|
|
117
|
+
"distance, and draw them")
|
|
118
|
+
k.add_argument("--ions", action="store_true",
|
|
119
|
+
help="draw an ion that the model has between the ligand and the protein as the bridge it is")
|
|
120
|
+
k.add_argument("--pae", metavar="FILE", action="append",
|
|
121
|
+
help="predicted aligned error: AlphaFold 3's confidences.json(.gz) or Boltz's pae_*.npz; each contact "
|
|
122
|
+
"stands on a glow in the colour of its own; repeat it for several draws of one model")
|
|
123
|
+
k.add_argument("--solvent-sites", action="store_true",
|
|
124
|
+
help="predict water sites that could bridge ligand and protein, drawn as predicted")
|
|
125
|
+
k.add_argument("--solvent-mark", choices=SOLVENT_MARKS, default="glow",
|
|
126
|
+
help="a predicted water on a glow, in a filled box with a heavy border, or in a thin broken "
|
|
127
|
+
"outline")
|
|
128
|
+
_confidence_arguments(r)
|
|
129
|
+
d = r.add_argument_group("what is drawn")
|
|
130
|
+
d.add_argument("--style", choices=STYLES, default="detailed",
|
|
131
|
+
help="residues with the atoms that make the contacts (default), or as bubbles")
|
|
132
|
+
d.add_argument("--detail", choices=("box", "backbone", "sidechain", "atoms"), default=None,
|
|
133
|
+
help="how much is drawn of a residue that makes a directional contact")
|
|
134
|
+
d.add_argument("--distances", choices=("auto", "all", "none"), default="auto",
|
|
135
|
+
help="which contact lines carry their distance")
|
|
136
|
+
d.add_argument("--atom-labels", choices=ATOM_LABELS, default="elements",
|
|
137
|
+
help="on an atom of a residue the letter of its element (N, O), or its name in the file (NZ, OE1)")
|
|
138
|
+
d.add_argument("--show-chain", choices=("auto", "always", "never"), default="auto",
|
|
139
|
+
help="name residues with their chain")
|
|
140
|
+
d.add_argument("--absent", metavar="RESIDUES",
|
|
141
|
+
help="residues that another protein (a splice isoform) does not have: 702,705-712,A:744; those in "
|
|
142
|
+
"contact with the ligand are marked, and the figure counts them")
|
|
143
|
+
d.add_argument("--absent-label", metavar="NAME", help="that protein's name (AR-V7)")
|
|
144
|
+
d.add_argument("--absent-style", choices=ABSENT_STYLES, default="marked",
|
|
145
|
+
help="mark them with a stroke of a marker pen, or set them back")
|
|
146
|
+
d.add_argument("--burial", action=argparse.BooleanOptionalAction, default=True,
|
|
147
|
+
help="the ligand's buried fraction under the title (on by default)")
|
|
148
|
+
_look_arguments(r)
|
|
149
|
+
t = r.add_argument_group("page and text")
|
|
150
|
+
t.add_argument("--title")
|
|
151
|
+
t.add_argument("--subtitle", metavar="TEXT")
|
|
152
|
+
_bare_argument(t)
|
|
153
|
+
t.add_argument("--no-legend", action="store_true", help="leave the key off")
|
|
154
|
+
t.add_argument("--no-notes", action="store_true", help="leave off the notes on the ligand's own quirks")
|
|
155
|
+
t.add_argument("--scoped-css", action="store_true",
|
|
156
|
+
help="with --theme auto: the colours are declared for figures in these colours alone, for a page that "
|
|
157
|
+
"has figures in others beside it")
|
|
158
|
+
t.add_argument("--no-background", action="store_true", help="a transparent background")
|
|
159
|
+
t.add_argument("--width-mm", type=_from(0, above=True), default=180.0, metavar="MM",
|
|
160
|
+
help="the width the figure has to be readable at (180)")
|
|
161
|
+
t.add_argument("--min-font-pt", type=_from(0), default=5.0, metavar="PT",
|
|
162
|
+
help="the smallest text allowed at that width (5)")
|
|
163
|
+
t.add_argument("--bond-length", type=_from(0, above=True), metavar="UNITS",
|
|
164
|
+
help="a fixed bond length instead of the largest that fits")
|
|
165
|
+
t.add_argument("--on-unreadable", choices=("summary", "render", "none"), default="summary",
|
|
166
|
+
help="what is drawn where the figure is not readable at that width (a per-residue summary)")
|
|
167
|
+
t.add_argument("--effort", choices=("full", "quick"), default="full",
|
|
168
|
+
help="quick: a peptide drawn as a chain that is far too crowded is given up early")
|
|
169
|
+
o = r.add_argument_group("output")
|
|
170
|
+
o.add_argument("-o", "--output", metavar="SVG", help="the figure (default: <structure>.<style>.svg)")
|
|
171
|
+
_output_arguments(o)
|
|
172
|
+
o.add_argument("--layout", metavar="JSON",
|
|
173
|
+
help="draw from a graph written by --graph, as it is or with nodes moved")
|
|
174
|
+
o.add_argument("--arrange", action="store_true",
|
|
175
|
+
help="arrange the figure by hand in a browser first (drag, turn, flip), then draw it")
|
|
176
|
+
o.add_argument("--arrange-page", metavar="HTML", help="write the page to arrange it as one file, and no figure")
|
|
177
|
+
o.add_argument("-q", "--quiet", action="store_true", help="print nothing but --json")
|
|
178
|
+
plainer = _plainer_arguments(r)
|
|
179
|
+
plainer.add_argument("--occupancy-style", choices=("steps", "continuous"), default="steps",
|
|
180
|
+
help="continuous: occupancy by line weight alone, with no share written")
|
|
181
|
+
plainer.add_argument("--occupancy-labels", choices=("all", "partial"), default="all",
|
|
182
|
+
help="partial: no share on a contact that is made in all, and none under a name")
|
|
183
|
+
|
|
184
|
+
# -- interface ------------------------------------------------------------------------------------
|
|
185
|
+
i = _command(
|
|
186
|
+
sub, "interface", "draw the contacts between two chains",
|
|
187
|
+
"bindview interface STRUCTURE --between A B [options]",
|
|
188
|
+
"Draw the contacts between two chains, or between parts of a complex: the residues of one as\n"
|
|
189
|
+
"a column of boxes (or each where it lies, --layout plane), those of the other around them.\n"
|
|
190
|
+
"Three participants in a row (MHC, peptide, receptor) are drawn around the middle one.\n\n"
|
|
191
|
+
"Without --contacts, PLIP (optional, GPL-2.0) finds the contacts." + _EXIT,
|
|
192
|
+
" bindview interface model.cif --between A B --pae confidences.json -o interface.svg\n"
|
|
193
|
+
" bindview interface model.cif --between H+L C --layout auto --detail sidechain\n"
|
|
194
|
+
" bindview interface model_0.cif --between A B --pae pae_model_0.npz --ipsae")
|
|
195
|
+
a = i.add_argument_group("input")
|
|
196
|
+
a.add_argument("structure", metavar="STRUCTURE", help="mmCIF or PDB file")
|
|
197
|
+
a.add_argument("--between", nargs="+", required=True, metavar="CHAINS",
|
|
198
|
+
help="the participants, each one or more chains: A B, or A C D+E, or receptor=D+E")
|
|
199
|
+
a.add_argument("--spine", help="the participant drawn as the column (default: the one that touches all others; "
|
|
200
|
+
"of two, the smaller side)")
|
|
201
|
+
a.add_argument("--site", metavar="CHAIN:NUMBER", help="only the site around this residue")
|
|
202
|
+
a.add_argument("--radius", type=float, default=8.0, metavar="A", help="... within this many angstrom of it (8)")
|
|
203
|
+
a.add_argument("--max-residues", type=_from(1, whole=True), default=30, metavar="N",
|
|
204
|
+
help="the most residues of the column; a larger interface is narrowed to a site (30)")
|
|
205
|
+
k = i.add_argument_group("contacts and confidence")
|
|
206
|
+
k.add_argument("--contacts", metavar="TSV",
|
|
207
|
+
help="a table of contacts with residues and atoms of both sides (docs/reference.md); "
|
|
208
|
+
"default: PLIP")
|
|
209
|
+
k.add_argument("--pae", metavar="FILE", action="append",
|
|
210
|
+
help="predicted aligned error: AlphaFold 3's confidences.json(.gz), Boltz's pae_*.npz, or the "
|
|
211
|
+
"AlphaFold database's predicted_aligned_error file of an entry; repeat it for several "
|
|
212
|
+
"draws of one model")
|
|
213
|
+
k.add_argument("--ipsae", nargs="?", const=True, default=False, type=float, metavar="CUTOFF",
|
|
214
|
+
help="also work out ipSAE from --pae, with this PAE cut-off (10 angstrom)")
|
|
215
|
+
k.add_argument("--model-confidence", metavar="JSON",
|
|
216
|
+
help="ipTM: AlphaFold 3's summary_confidences.json or Boltz's confidence_*.json")
|
|
217
|
+
k.add_argument("--pae-colors", action="store_true",
|
|
218
|
+
help="the predicted aligned error of a contact as a glow behind its line, not as a number on it")
|
|
219
|
+
d = i.add_argument_group("layout")
|
|
220
|
+
d.add_argument("--layout", choices=("column", "auto", "plane"), default="column",
|
|
221
|
+
help="a column (default); a plane, each box where its residue lies; or let a rule choose")
|
|
222
|
+
d.add_argument("--order", choices=("auto", "sequence", "interface"), default="auto",
|
|
223
|
+
help="the order of the column: of the sequence, along the interface, or (auto) the one in which "
|
|
224
|
+
"the contacts of each partner residue are spread over fewer boxes")
|
|
225
|
+
d.add_argument("--detail", choices=("box", "backbone", "sidechain", "atoms"), default=None,
|
|
226
|
+
help="how much is drawn of a residue that makes a directional contact, on both sides")
|
|
227
|
+
d.add_argument("--style", choices=("detailed", "schematic"), default="detailed")
|
|
228
|
+
_look_arguments(i)
|
|
229
|
+
t = i.add_argument_group("page and text")
|
|
230
|
+
t.add_argument("--title")
|
|
231
|
+
_bare_argument(t)
|
|
232
|
+
o = i.add_argument_group("output")
|
|
233
|
+
o.add_argument("-o", "--output", metavar="SVG", help="the figure (default: <structure>.interface.<style>.svg)")
|
|
234
|
+
_output_arguments(o)
|
|
235
|
+
o.add_argument("-q", "--quiet", action="store_true", help="print nothing but --json")
|
|
236
|
+
_plainer_arguments(i)
|
|
237
|
+
|
|
238
|
+
# -- basepairs ------------------------------------------------------------------------------------
|
|
239
|
+
bp = _command(
|
|
240
|
+
sub, "basepairs", "draw two strands of RNA or DNA and their base pairs",
|
|
241
|
+
"bindview basepairs STRUCTURE --chains A B [options]",
|
|
242
|
+
"Draw two nucleic-acid chains as their secondary structures facing each other: which\n"
|
|
243
|
+
"nucleotides pair across, by which edges, where on each strand's own fold, what stacks\n"
|
|
244
|
+
"across, and a ligand between them with its contacts.\n\n"
|
|
245
|
+
"The pairs are read, not detected: RNApolis's annotator JSON, RNA 3D Hub's FR3D tables, or the\n"
|
|
246
|
+
"PDB's own annotation in a deposited mmCIF. Without --pairs, the structure's own annotation is\n"
|
|
247
|
+
"used where it has one, else a stand-in from bindview's plain distance table, without a family\n"
|
|
248
|
+
"(docs/manual.md)." + _EXIT,
|
|
249
|
+
" annotator -j pairs.json model.pdb # RNApolis, in an environment of its own\n"
|
|
250
|
+
" bindview basepairs model.pdb --chains A B --pairs pairs.json --ligand BGD -o pairs.svg\n"
|
|
251
|
+
" bindview basepairs 1xpf.cif --chains A B --theme auto --interactive\n"
|
|
252
|
+
" bindview basepairs model.pdb --chains A B --dot-bracket A='(((((((....)))))))' --family cWW")
|
|
253
|
+
a = bp.add_argument_group("input")
|
|
254
|
+
a.add_argument("structure", metavar="STRUCTURE", help="mmCIF or PDB file")
|
|
255
|
+
a.add_argument("--chains", nargs=2, required=True, metavar="CHAIN", help="the two strands")
|
|
256
|
+
k = bp.add_argument_group("pairs and stacks")
|
|
257
|
+
k.add_argument("--pairs", action="append", default=[], metavar="FILE",
|
|
258
|
+
help="RNApolis's JSON (.json), an FR3D table (.csv) or a deposited mmCIF with the PDB's "
|
|
259
|
+
"annotation (repeatable; their pairs are added together)")
|
|
260
|
+
k.add_argument("--stacks", action="append", default=[], metavar="FILE",
|
|
261
|
+
help="RNApolis's JSON or FR3D's stacking table (default: those of an RNApolis --pairs, "
|
|
262
|
+
"else the plain table's)")
|
|
263
|
+
k.add_argument("--dot-bracket", action="append", default=[], metavar="CHAIN=STRUCTURE",
|
|
264
|
+
help="a strand's own pairs as a dot-bracket, one character a nucleotide (repeatable)")
|
|
265
|
+
k.add_argument("--family", metavar="FAMILY", help="the family of the pairs of --dot-bracket (cWW); none by default")
|
|
266
|
+
k.add_argument("--no-contacts", action="store_true",
|
|
267
|
+
help="no plain distance table: no stand-in pairs, no stacks from it, no other hydrogen bonds")
|
|
268
|
+
g = bp.add_argument_group("a ligand beside the pairs")
|
|
269
|
+
g.add_argument("--ligand", metavar="RESIDUE", help="a residue that is no part of the two chains: BGD, or C:1")
|
|
270
|
+
g.add_argument("--ligand-contacts", metavar="TSV", help="its contacts (PLIP's table, say); default: the plain table")
|
|
271
|
+
g.add_argument("--ligand-smiles", metavar="SMILES", help="its bond orders, for the plain table")
|
|
272
|
+
g.add_argument("--ligand-name", metavar="TEXT", help="the word in its box (default: the residue name)")
|
|
273
|
+
lk = bp.add_argument_group("look")
|
|
274
|
+
lk.add_argument("--theme", choices=("light", "dark", "auto"), default="light",
|
|
275
|
+
help="auto: one file with both palettes, following the reader's setting")
|
|
276
|
+
lk.add_argument("--colors", choices=tuple(SCHEMES), default="standard", help="the colour scheme")
|
|
277
|
+
lk.add_argument("--interactive", action="store_true",
|
|
278
|
+
help="in a browser, a nucleotide and its pairs stand out under the pointer (no script)")
|
|
279
|
+
t = bp.add_argument_group("page and text")
|
|
280
|
+
t.add_argument("--title")
|
|
281
|
+
t.add_argument("--no-legend", action="store_true", help="no key under the drawing")
|
|
282
|
+
t.add_argument("--no-caption", action="store_true",
|
|
283
|
+
help="no line saying where the pairs came from: it stays in the file's description, in --json "
|
|
284
|
+
"and in --notes-file")
|
|
285
|
+
t.add_argument("--step", type=_from(0, above=True), default=24.0, metavar="PX",
|
|
286
|
+
help="the distance of two neighbours (24)")
|
|
287
|
+
t.add_argument("--width-mm", type=_from(0, above=True), default=180.0, metavar="MM",
|
|
288
|
+
help="the width the figure has to be readable at (180)")
|
|
289
|
+
t.add_argument("--min-font-pt", type=_from(0), default=5.0, metavar="PT",
|
|
290
|
+
help="the smallest text allowed at that width (5)")
|
|
291
|
+
o = bp.add_argument_group("output")
|
|
292
|
+
o.add_argument("-o", "--output", metavar="SVG", help="the figure (default: <structure>.basepairs.svg)")
|
|
293
|
+
_output_arguments(o)
|
|
294
|
+
o.add_argument("--from-graph", metavar="JSON", help="draw from a graph written by --graph, its nodes moved")
|
|
295
|
+
o.add_argument("-q", "--quiet", action="store_true", help="print nothing but --json")
|
|
296
|
+
|
|
297
|
+
# -- compare --------------------------------------------------------------------------------------
|
|
298
|
+
members = ("a structure file, or a folder holding model.cif or model.cif.gz (with interactions.tsv and "
|
|
299
|
+
"meta.json, if there)")
|
|
300
|
+
c = _command(
|
|
301
|
+
sub, "compare", "compare ligands of one pocket", "bindview compare MEMBER MEMBER [MEMBER ...] [options]",
|
|
302
|
+
"Draw several ligands of one pocket against one frame of residues: two ligands give a\n"
|
|
303
|
+
"difference view, more a consensus view." + _EXIT,
|
|
304
|
+
" bindview compare case_a/ case_b/ -o difference.svg\n"
|
|
305
|
+
" bindview compare series/*/ -o consensus.svg --fingerprints fingerprints.csv")
|
|
306
|
+
a = c.add_argument_group("input")
|
|
307
|
+
a.add_argument("members", nargs="+", metavar="MEMBER", help=members)
|
|
308
|
+
a.add_argument("--ligand", help="the ligand residue in every structure (default: meta.json's "
|
|
309
|
+
"ligand.residue_name_in_cif)")
|
|
310
|
+
a.add_argument("--plddt", choices=("auto", "bfactor", "bfactor01", "off"), default="auto",
|
|
311
|
+
help="where pLDDT comes from (see 'bindview render --help')")
|
|
312
|
+
a.add_argument("--untrusted", action="append", default=[], metavar="NAME",
|
|
313
|
+
help="mark this ligand's model as not to be trusted (repeatable)")
|
|
314
|
+
d = c.add_argument_group("what is drawn")
|
|
315
|
+
d.add_argument("--view", choices=("auto",) + VIEWS, default="auto")
|
|
316
|
+
d.add_argument("--min-ligands", type=int, default=1, metavar="N",
|
|
317
|
+
help="consensus view: leave out residues contacted by fewer ligands")
|
|
318
|
+
d.add_argument("--no-thumbnails", action="store_true", help="consensus view: no drawing of each single ligand")
|
|
319
|
+
d.add_argument("--burial", action=argparse.BooleanOptionalAction, default=True,
|
|
320
|
+
help="each ligand's buried fraction in the figure (on by default)")
|
|
321
|
+
d.add_argument("--theme", choices=("light", "dark", "auto"), default="light")
|
|
322
|
+
d.add_argument("--colors", choices=tuple(SCHEMES), default="standard", help="the colour scheme")
|
|
323
|
+
t = c.add_argument_group("page and text")
|
|
324
|
+
t.add_argument("--title")
|
|
325
|
+
t.add_argument("--subtitle", metavar="TEXT")
|
|
326
|
+
t.add_argument("--width-mm", type=_from(0, above=True), default=180.0, metavar="MM",
|
|
327
|
+
help="the width the figure has to be readable at (180)")
|
|
328
|
+
t.add_argument("--min-font-pt", type=_from(0), default=5.0, metavar="PT",
|
|
329
|
+
help="the smallest text allowed at that width (5)")
|
|
330
|
+
t.add_argument("--on-unreadable", choices=("summary", "render", "none"), default="summary",
|
|
331
|
+
help="what is drawn where the figure is not readable at that width")
|
|
332
|
+
o = c.add_argument_group("output")
|
|
333
|
+
o.add_argument("-o", "--output", metavar="SVG", default="comparison.svg", help="the figure (comparison.svg)")
|
|
334
|
+
o.add_argument("--fingerprints", metavar="CSV", help="also write the fingerprints (long form)")
|
|
335
|
+
o.add_argument("--json", action="store_true", help="print status, alignment and classification as JSON")
|
|
336
|
+
o.add_argument("--graph", metavar="JSON", help="also write the figure as a graph of nodes and contacts")
|
|
337
|
+
o.add_argument("-q", "--quiet", action="store_true", help="print nothing but --json")
|
|
338
|
+
|
|
339
|
+
# -- fingerprint ----------------------------------------------------------------------------------
|
|
340
|
+
f = _command(
|
|
341
|
+
sub, "fingerprint", "write interaction fingerprints as CSV", "bindview fingerprint MEMBER [MEMBER ...] [options]",
|
|
342
|
+
"One row per contact (long form) or per ligand (wide form): residue and kind of contact, in a\n"
|
|
343
|
+
"fixed order of columns.",
|
|
344
|
+
" bindview fingerprint series/*/ --form wide -o fingerprints.csv")
|
|
345
|
+
f.add_argument("members", nargs="+", metavar="MEMBER", help=members)
|
|
346
|
+
f.add_argument("--ligand", help="the ligand residue in every structure")
|
|
347
|
+
f.add_argument("--form", choices=("long", "wide"), default="long",
|
|
348
|
+
help="long: one row per contact, lossless; wide: one row per ligand, one column per contact")
|
|
349
|
+
f.add_argument("--counts", action="store_true", help="wide form: counts of records instead of 1/0")
|
|
350
|
+
f.add_argument("-o", "--output", metavar="CSV", help="the file (default: standard output)")
|
|
351
|
+
f.add_argument("--plddt", choices=("auto", "bfactor", "bfactor01", "off"), default="auto",
|
|
352
|
+
help="where pLDDT comes from (see 'bindview render --help')")
|
|
353
|
+
f.add_argument("-q", "--quiet", action="store_true")
|
|
354
|
+
|
|
355
|
+
# -- report ---------------------------------------------------------------------------------------
|
|
356
|
+
rp = _command(
|
|
357
|
+
sub, "report", "look at an input, draw what it holds, write one page", "bindview report INPUT [options]",
|
|
358
|
+
"Look at a model, or a folder that holds one, and say what it holds: a small molecule in a\n"
|
|
359
|
+
"pocket, a peptide, an interface, an ensemble. Draw the figure for each, under the call that\n"
|
|
360
|
+
"drew it, and then its views: the same figure in the other style, with pLDDT in AlphaFold's\n"
|
|
361
|
+
"colours where the model has it, and as a figure that answers the pointer. List what was\n"
|
|
362
|
+
"found and not drawn.\n\n"
|
|
363
|
+
"Contacts of a small molecule come from a table beside the model, else from PLIP where it is\n"
|
|
364
|
+
"installed (optional, GPL-2.0), else from a table of heavy atoms, which is cruder than PLIP.",
|
|
365
|
+
" bindview report model.cif -o report.html\n"
|
|
366
|
+
" bindview report series/ -o series.html\n"
|
|
367
|
+
" bindview report screen/ --each -o screen.html\n"
|
|
368
|
+
" bindview report model.cif --domain N=A:28-124 --domain ZP=A:126-269")
|
|
369
|
+
rp.add_argument("input", metavar="INPUT", help="a model (mmCIF or PDB, gzipped or not), or a folder that holds one")
|
|
370
|
+
rp.add_argument("-o", "--output", metavar="HTML", help="the page (default: <input>.report.html beside the input)")
|
|
371
|
+
rp.add_argument("--smiles", action="append", default=[], metavar="NAME=SMILES",
|
|
372
|
+
help="the SMILES of a residue by its name, for its bond orders (repeatable)")
|
|
373
|
+
rp.add_argument("--domain", action="append", default=[], metavar="NAME=CHAIN:FROM-TO",
|
|
374
|
+
help="a part of a chain by its first and last residue; two or more: the interface between them")
|
|
375
|
+
rp.add_argument("--look", action="store_true", help="say what the input holds and draw nothing")
|
|
376
|
+
rp.add_argument("--each", action="store_true",
|
|
377
|
+
help="a folder of different inputs: a page for each, and an index of them as a page and a CSV")
|
|
378
|
+
rp.add_argument("--one-view", action="store_true",
|
|
379
|
+
help="each figure alone: not also in the other style, in pLDDT colours and interactive")
|
|
380
|
+
rp.add_argument("-q", "--quiet", action="store_true")
|
|
381
|
+
return p
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
def _look_arguments(r: argparse.ArgumentParser) -> None:
|
|
385
|
+
"""How a figure looks: its colours, and whether it answers the pointer."""
|
|
386
|
+
g = r.add_argument_group("look")
|
|
387
|
+
g.add_argument("--theme", choices=("light", "dark", "auto"), default="light",
|
|
388
|
+
help="auto: one file with both palettes, following the reader's setting")
|
|
389
|
+
g.add_argument("--colors", choices=tuple(SCHEMES), default="standard",
|
|
390
|
+
help="the colour scheme: standard, or contrast (residue classes further apart)")
|
|
391
|
+
c = g.add_mutually_exclusive_group()
|
|
392
|
+
c.add_argument("--plddt-colors", action="store_true",
|
|
393
|
+
help="pLDDT in AlphaFold's four colours behind the atoms, instead of by line weight")
|
|
394
|
+
c.add_argument("--plddt-bonds", action="store_true", help="the same four colours, as the colours of the bonds")
|
|
395
|
+
g.add_argument("--interactive", action="store_true",
|
|
396
|
+
help="in a browser, a residue and its contacts stand out under the pointer (no script)")
|
|
397
|
+
g.add_argument("--charge-halos", action=argparse.BooleanOptionalAction, default=False,
|
|
398
|
+
help="shade the charged group that a salt bridge or pi-cation contact is made with (not shaded "
|
|
399
|
+
"by default)")
|
|
400
|
+
s = r.add_argument_group("the settings of a style, one by one",
|
|
401
|
+
"Each is the style's own unless it is given here (docs/reference.md).")
|
|
402
|
+
s.add_argument("--residues", nargs="+", metavar="HOW", default=None,
|
|
403
|
+
help="atoms, bubbles or names; or residue by residue: Met743=atoms Gln712=atoms '*=bubbles'")
|
|
404
|
+
s.add_argument("--lines", choices=tuple(LINES), default=None, help="the colours and dashes of the contact lines")
|
|
405
|
+
s.add_argument("--exposure", action=argparse.BooleanOptionalAction, default=None,
|
|
406
|
+
help="grey halos behind the ligand's atoms that are open to solvent")
|
|
407
|
+
s.add_argument("--lining", choices=LININGS, default=None,
|
|
408
|
+
help="the wall of the pocket: a stretch for each contact in the colour of what makes it "
|
|
409
|
+
"(contacts: the schematic style's own), the class of the nearest residue (nearest), or "
|
|
410
|
+
"none")
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def _plainer_arguments(r: argparse.ArgumentParser) -> Any:
|
|
414
|
+
"""The options that each draw one thing more plainly than a figure does by itself; last in the help."""
|
|
415
|
+
b = r.add_argument_group("one thing drawn more plainly",
|
|
416
|
+
"Each leaves off one refinement of the drawing; the figure is otherwise the same.")
|
|
417
|
+
b.add_argument("--no-break-lines", action="store_true",
|
|
418
|
+
help="draw a contact's line whole where it runs over a word that is not its own")
|
|
419
|
+
b.add_argument("--no-charge-key", action="store_true", help="leave the charged-group shading out of the key")
|
|
420
|
+
b.add_argument("--no-plddt-by-atom", action="store_true", help="draw a residue's atoms at the residue's pLDDT")
|
|
421
|
+
return b
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
def _residues_given(given: "list[str] | None") -> Any:
|
|
425
|
+
"""``--residues``: one word for all, or residue=how for some."""
|
|
426
|
+
if given is None:
|
|
427
|
+
return None
|
|
428
|
+
if len(given) == 1 and given[0] in RESIDUE_FORMS:
|
|
429
|
+
return given[0]
|
|
430
|
+
table = {}
|
|
431
|
+
for item in given:
|
|
432
|
+
name, sep, how = item.partition("=")
|
|
433
|
+
if not sep or not name:
|
|
434
|
+
raise BindviewError(f"--residues {item}: one word ({', '.join(RESIDUE_FORMS)}) for all, or "
|
|
435
|
+
"RESIDUE=HOW for each that is named")
|
|
436
|
+
table[name] = how
|
|
437
|
+
for how in table.values():
|
|
438
|
+
if how not in RESIDUE_FORMS:
|
|
439
|
+
raise BindviewError(f"--residues: {how!r} is not one of {', '.join(RESIDUE_FORMS)}")
|
|
440
|
+
return table
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
def _style_settings(args: argparse.Namespace) -> dict[str, Any]:
|
|
444
|
+
return dict(residues=_residues_given(args.residues), lines=args.lines, exposure=args.exposure,
|
|
445
|
+
lining=args.lining)
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
def _absent_given(text: "str | None") -> "list[str] | None":
|
|
449
|
+
"""``702,705-712,A:744`` as the names of the residues (a range is of numbers, with or without its chain).
|
|
450
|
+
Nothing at all (``""``) is the other protein that lacks none; a list that only looks empty is an error."""
|
|
451
|
+
if text is None:
|
|
452
|
+
return None
|
|
453
|
+
if not text.strip():
|
|
454
|
+
return []
|
|
455
|
+
out: list[str] = []
|
|
456
|
+
for part in (p.strip() for p in text.split(",")):
|
|
457
|
+
if not part:
|
|
458
|
+
raise BindviewError(f"--absent {text}: an empty name between its commas; write the residues as "
|
|
459
|
+
"702,705-712,A:744")
|
|
460
|
+
span = re.fullmatch(r"(?:([^:]+):)?(\d+)-(\d+)", part)
|
|
461
|
+
if span is None:
|
|
462
|
+
out.append(part)
|
|
463
|
+
continue
|
|
464
|
+
chain = f"{span[1]}:" if span[1] else ""
|
|
465
|
+
if int(span[2]) > int(span[3]):
|
|
466
|
+
raise BindviewError(f"--absent {text}: the range {part} runs backwards and holds no residue; "
|
|
467
|
+
f"write it as {chain}{span[3]}-{span[2]}")
|
|
468
|
+
out += [f"{chain}{n}" for n in range(int(span[2]), int(span[3]) + 1)]
|
|
469
|
+
return out
|
|
470
|
+
|
|
471
|
+
|
|
472
|
+
def _bare_argument(t: Any) -> None:
|
|
473
|
+
t.add_argument("--bare", action="store_true",
|
|
474
|
+
help="the drawing and its key only: no confidence line, warning or notes (they are in --json "
|
|
475
|
+
"and --notes-file)")
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
def _output_arguments(o: Any) -> None:
|
|
479
|
+
o.add_argument("--json", action="store_true", help="print status, warnings, notes and measures as JSON")
|
|
480
|
+
o.add_argument("--notes-file", metavar="TXT",
|
|
481
|
+
help="write the figure's notes, one a line: the words a caption needs (see --bare)")
|
|
482
|
+
o.add_argument("--graph", metavar="JSON",
|
|
483
|
+
help="also write the figure as a graph of nodes and contacts (docs/graph-schema.md)")
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
def _confidence_arguments(r: argparse.ArgumentParser) -> None:
|
|
487
|
+
c = r.add_argument_group(
|
|
488
|
+
"model confidence",
|
|
489
|
+
"For predicted models. pLDDT is read from the B-factor column only where the file declares it\n"
|
|
490
|
+
"(_ma_qa_metric) or you say it is, with --plddt; it is never guessed from the values.")
|
|
491
|
+
c.add_argument("--plddt", choices=("auto", "bfactor", "bfactor01", "off"), default="auto",
|
|
492
|
+
help="auto: where the file declares it; bfactor, bfactor01: you say it is pLDDT on 0-100, "
|
|
493
|
+
"on 0-1; off: none")
|
|
494
|
+
c.add_argument("--model-confidence", metavar="JSON",
|
|
495
|
+
help="ipTM and pTM: AlphaFold 3's summary_confidences.json (found beside <job>_model.cif)")
|
|
496
|
+
c.add_argument("--untrusted", action="store_true", help="mark the figure as from a model not to be read as a result")
|
|
497
|
+
c.add_argument("--flag", metavar="TEXT", help="your verdict on the model, printed on the figure (e.g. 'grade C')")
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
def _confidence_kwargs(args: argparse.Namespace) -> dict[str, Any]:
|
|
501
|
+
return dict(plddt=None if args.plddt == "off" else args.plddt,
|
|
502
|
+
model_confidence=args.model_confidence or "auto",
|
|
503
|
+
trusted=False if args.untrusted else None, flag=args.flag)
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
@contextmanager
|
|
507
|
+
def _reading(what: str, path: "str | Path") -> "Iterator[None]":
|
|
508
|
+
"""Whatever a file that is read fails with is said with the file's name."""
|
|
509
|
+
try:
|
|
510
|
+
yield
|
|
511
|
+
except BindviewError as exc: # (the reader's own words, which name no file)
|
|
512
|
+
if str(path) in str(exc):
|
|
513
|
+
raise
|
|
514
|
+
raise BindviewError(f"{what} {path}: {exc}") from exc
|
|
515
|
+
except UnicodeDecodeError as exc:
|
|
516
|
+
raise BindviewError(f"{what} {path} is not text in UTF-8: {exc}") from exc
|
|
517
|
+
except OSError as exc:
|
|
518
|
+
raise BindviewError(f"cannot read {what} {path}: {exc.strerror or exc}") from exc
|
|
519
|
+
except ValueError as exc: # (a JSON file that is none)
|
|
520
|
+
raise BindviewError(f"cannot read {what} {path}: {exc}") from exc
|
|
521
|
+
|
|
522
|
+
|
|
523
|
+
def _stem(path: Path) -> str:
|
|
524
|
+
"""The name of a model file without its suffixes: ``model`` of ``model.cif.gz``."""
|
|
525
|
+
return path.name.removesuffix(".gz").rsplit(".", 1)[0]
|
|
526
|
+
|
|
527
|
+
|
|
528
|
+
def _folder_there(option: str, path: "str | Path | None") -> None:
|
|
529
|
+
"""A file that this module writes when the figure is made has a folder to go into: asked before it is made."""
|
|
530
|
+
if path and not Path(path).parent.is_dir():
|
|
531
|
+
raise BindviewError(f"{option} {path}: there is no folder {Path(path).parent} to write it into")
|
|
532
|
+
|
|
533
|
+
|
|
534
|
+
def _write(option: str, path: "str | Path", text: str) -> None:
|
|
535
|
+
try:
|
|
536
|
+
Path(path).write_text(text, encoding="utf-8")
|
|
537
|
+
except OSError as exc:
|
|
538
|
+
raise BindviewError(f"{option}: cannot write {path}: {exc.strerror or exc}") from exc
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
def _write_notes(args: argparse.Namespace, result: Any, say) -> None:
|
|
542
|
+
"""``--notes-file``: the figure's notes, one a line, whether they are drawn or left off."""
|
|
543
|
+
if args.notes_file:
|
|
544
|
+
_write("--notes-file", args.notes_file, "".join(note + "\n" for note in result.notes))
|
|
545
|
+
say(f"notes -> {args.notes_file}")
|
|
546
|
+
|
|
547
|
+
|
|
548
|
+
def _smiles_from(path_text: str, structure: Path) -> str:
|
|
549
|
+
path = Path(path_text)
|
|
550
|
+
if not path.exists() and (structure.parent / path_text).exists():
|
|
551
|
+
path = structure.parent / path_text
|
|
552
|
+
try:
|
|
553
|
+
data = json.loads(path.read_text(encoding="utf-8"))
|
|
554
|
+
except OSError as exc:
|
|
555
|
+
raise BindviewError(f"cannot read {path}: {exc}") from exc
|
|
556
|
+
except UnicodeDecodeError as exc:
|
|
557
|
+
raise BindviewError(f"{path} is not text in UTF-8: {exc}") from exc
|
|
558
|
+
except json.JSONDecodeError as exc:
|
|
559
|
+
raise BindviewError(f"{path} is not valid JSON: {exc}") from exc
|
|
560
|
+
for getter in (lambda d: d["ligand"]["smiles"], lambda d: d["smiles"]):
|
|
561
|
+
try:
|
|
562
|
+
value = getter(data)
|
|
563
|
+
except (KeyError, TypeError):
|
|
564
|
+
continue
|
|
565
|
+
if isinstance(value, str) and value.strip():
|
|
566
|
+
return value.strip()
|
|
567
|
+
raise BindviewError(f"{path} has no 'smiles' or 'ligand.smiles' entry")
|
|
568
|
+
|
|
569
|
+
|
|
570
|
+
def _interactions(args: argparse.Namespace, structure: Path, say) -> "list[Interaction] | str | None":
|
|
571
|
+
if getattr(args, "distances_only", False):
|
|
572
|
+
say("interactions: from the distances of the heavy atoms")
|
|
573
|
+
return DISTANCES
|
|
574
|
+
if args.interactions:
|
|
575
|
+
say(f"interactions: {args.interactions}")
|
|
576
|
+
with _reading("the table of contacts", args.interactions):
|
|
577
|
+
return load_interactions(args.interactions)
|
|
578
|
+
if not args.detect:
|
|
579
|
+
for name in _SIBLING_TABLES:
|
|
580
|
+
cand = structure.parent / name
|
|
581
|
+
if cand.exists():
|
|
582
|
+
say(f"interactions: {cand} (found next to the structure)")
|
|
583
|
+
with _reading("the table of contacts", cand):
|
|
584
|
+
return load_interactions(cand)
|
|
585
|
+
say("interactions: detecting with PLIP")
|
|
586
|
+
return None
|
|
587
|
+
|
|
588
|
+
|
|
589
|
+
def _render(args: argparse.Namespace) -> int:
|
|
590
|
+
def say(msg: str) -> None:
|
|
591
|
+
if not args.quiet:
|
|
592
|
+
print(msg, file=sys.stderr)
|
|
593
|
+
|
|
594
|
+
absent = _absent_given(args.absent) # (a list that is wrong is said before anything is read)
|
|
595
|
+
_folder_there("--notes-file", args.notes_file)
|
|
596
|
+
structure = Path(args.structure)
|
|
597
|
+
smiles = args.smiles
|
|
598
|
+
if args.smiles_from:
|
|
599
|
+
smiles = _smiles_from(args.smiles_from, structure)
|
|
600
|
+
records = _interactions(args, structure, say)
|
|
601
|
+
dia = Diagram.from_structure(structure, args.ligand, smiles=smiles, interactions=records,
|
|
602
|
+
ionize_acids=not args.no_ionize, ensemble=args.ensemble,
|
|
603
|
+
ligand_as=args.ligand_as, detail=args.detail, covalent=args.covalent, ions=args.ions,
|
|
604
|
+
pae=None if not args.pae else args.pae[0] if len(args.pae) == 1 else args.pae,
|
|
605
|
+
**_confidence_kwargs(args))
|
|
606
|
+
out = Path(args.output) if args.output else structure.with_name(f"{_stem(structure)}.{args.style}.svg")
|
|
607
|
+
options: dict[str, Any] = dict(
|
|
608
|
+
title=args.title, subtitle=args.subtitle, legend=not args.no_legend, notes=not args.no_notes,
|
|
609
|
+
distance_labels=args.distances, show_chain=args.show_chain, figure_width_mm=args.width_mm,
|
|
610
|
+
min_font_pt=args.min_font_pt, bond_length=args.bond_length, on_unreadable=args.on_unreadable, effort=args.effort,
|
|
611
|
+
background=not args.no_background, burial=args.burial, solvent_sites=args.solvent_sites,
|
|
612
|
+
colors=args.colors, plddt_colors="bonds" if args.plddt_bonds else args.plddt_colors, interactive=args.interactive,
|
|
613
|
+
break_lines=not args.no_break_lines, charge_halos=args.charge_halos,
|
|
614
|
+
charge_key=not args.no_charge_key, plddt_by_atom=not args.no_plddt_by_atom,
|
|
615
|
+
occupancy_style=args.occupancy_style, occupancy_labels=args.occupancy_labels, bare=args.bare,
|
|
616
|
+
solvent_mark=args.solvent_mark, absent=absent, absent_label=args.absent_label,
|
|
617
|
+
absent_style=args.absent_style, atom_labels=args.atom_labels, stylesheet="scoped" if args.scoped_css else "inline",
|
|
618
|
+
**_style_settings(args))
|
|
619
|
+
given = Graph.from_json(Path(args.layout)) if args.layout else None
|
|
620
|
+
if args.arrange_page:
|
|
621
|
+
made = dia.arrange(args.arrange_page, style=args.style, theme=args.theme, graph=given, **options)
|
|
622
|
+
say(f"wrote {made}")
|
|
623
|
+
return 0
|
|
624
|
+
if args.arrange:
|
|
625
|
+
given = dia.arrange(style=args.style, theme=args.theme, graph=given, **options) # type: ignore[assignment]
|
|
626
|
+
if given is None:
|
|
627
|
+
raise BindviewError("the page was not done: nothing is drawn")
|
|
628
|
+
options["on_unreadable"] = "render" # a layout made by hand is drawn as it was left
|
|
629
|
+
result = dia.render_svg(out, style=args.style, theme=args.theme, graph=given, **options)
|
|
630
|
+
if args.graph:
|
|
631
|
+
if result.graph is None:
|
|
632
|
+
say(f"no graph written: the result is a {result.figure} figure, which has no nodes")
|
|
633
|
+
else:
|
|
634
|
+
result.graph.to_json(args.graph)
|
|
635
|
+
say(f"graph -> {args.graph}")
|
|
636
|
+
|
|
637
|
+
q = result.quality
|
|
638
|
+
summary: dict[str, Any] = {
|
|
639
|
+
"status": result.status, "figure": result.figure, "output": str(result.path) if result.path else None,
|
|
640
|
+
"style": result.style, "theme": result.theme, "n_interactions": dia.n_interactions,
|
|
641
|
+
"n_unresolved": len(dia.unresolved), "warnings": result.warnings, "notes": result.notes,
|
|
642
|
+
"confidence": result.confidence,
|
|
643
|
+
"burial": result.burial, **result.data,
|
|
644
|
+
"quality": None if q is None else {
|
|
645
|
+
"width": round(q.width, 2), "height": round(q.height, 2), "bond_length": q.bond_length,
|
|
646
|
+
"n_residues": q.n_residues, "overlaps": q.overlaps, "unplaced": q.unplaced,
|
|
647
|
+
"line_crossings": q.line_crossings, "bond_crossings": q.bond_crossings,
|
|
648
|
+
"max_stretch": round(q.max_stretch, 3), "min_font_pt": round(q.min_font_pt, 2),
|
|
649
|
+
# (No width at all where the text asked for is larger than the figure's own: null, not a number.)
|
|
650
|
+
"required_width_mm": None if math.isinf(q.required_width_mm) else round(q.required_width_mm, 1),
|
|
651
|
+
"readable": q.readable},
|
|
652
|
+
}
|
|
653
|
+
_write_notes(args, result, say)
|
|
654
|
+
if args.json:
|
|
655
|
+
json.dump(summary, sys.stdout, indent=2)
|
|
656
|
+
sys.stdout.write("\n")
|
|
657
|
+
where = f" -> {result.path}" if result.path else " (no figure written)"
|
|
658
|
+
say(f"{result.status}: {result.figure}{where}")
|
|
659
|
+
for w in result.warnings:
|
|
660
|
+
say(f" note: {w}")
|
|
661
|
+
return 3 if result.status == "unreadable" else 0
|
|
662
|
+
|
|
663
|
+
|
|
664
|
+
#: The model in a folder that is a member of a comparison, unless its meta.json names another file.
|
|
665
|
+
_MODEL_NAMES = ("model.cif", "model.cif.gz", "model.pdb", "model.pdb.gz")
|
|
666
|
+
|
|
667
|
+
|
|
668
|
+
def _member(text: str, args: argparse.Namespace, say) -> tuple[str, Diagram]:
|
|
669
|
+
"""Build one ligand of a set from a structure file or a case directory."""
|
|
670
|
+
path = Path(text)
|
|
671
|
+
meta: dict[str, Any] = {}
|
|
672
|
+
meta_file = (path if path.is_dir() else path.parent) / "meta.json"
|
|
673
|
+
if meta_file.exists():
|
|
674
|
+
try:
|
|
675
|
+
meta = json.loads(meta_file.read_text(encoding="utf-8"))
|
|
676
|
+
except (OSError, ValueError) as exc: # (not there, not text in UTF-8, not JSON)
|
|
677
|
+
raise BindviewError(f"cannot read {meta_file}: {exc}") from exc
|
|
678
|
+
structure = path
|
|
679
|
+
if path.is_dir():
|
|
680
|
+
named = meta.get("source", {}).get("file") if isinstance(meta.get("source"), dict) else None
|
|
681
|
+
names = ([named] if named else []) + list(_MODEL_NAMES)
|
|
682
|
+
structure = next((path / n for n in names if (path / n).exists()), path / names[0])
|
|
683
|
+
if not structure.exists():
|
|
684
|
+
raise BindviewError(f"no structure at {structure}")
|
|
685
|
+
lig: dict[str, Any] = meta["ligand"] if isinstance(meta.get("ligand"), dict) else {}
|
|
686
|
+
ligand = args.ligand or lig.get("residue_name_in_cif")
|
|
687
|
+
if not ligand:
|
|
688
|
+
raise BindviewError(f"{structure}: say which residue is the ligand with --ligand")
|
|
689
|
+
table = next((structure.parent / n for n in _SIBLING_TABLES if (structure.parent / n).exists()), None)
|
|
690
|
+
name = lig.get("name") or (path.name if path.is_dir() else _stem(structure))
|
|
691
|
+
untrusted = name in getattr(args, "untrusted", [])
|
|
692
|
+
records = None
|
|
693
|
+
if table is not None:
|
|
694
|
+
with _reading("the table of contacts", table):
|
|
695
|
+
records = load_interactions(table)
|
|
696
|
+
dia = Diagram.from_structure(structure, ligand, smiles=lig.get("smiles") or meta.get("smiles"),
|
|
697
|
+
interactions=records, name=name,
|
|
698
|
+
plddt=None if args.plddt == "off" else args.plddt,
|
|
699
|
+
trusted=False if untrusted else None)
|
|
700
|
+
say(f"{name}: {dia.n_interactions} interactions" + ("" if table is not None else " (detected)"))
|
|
701
|
+
return name, dia
|
|
702
|
+
|
|
703
|
+
|
|
704
|
+
def _compare(args: argparse.Namespace) -> int:
|
|
705
|
+
def say(msg: str) -> None:
|
|
706
|
+
if not args.quiet:
|
|
707
|
+
print(msg, file=sys.stderr)
|
|
708
|
+
|
|
709
|
+
if len(args.members) < 2:
|
|
710
|
+
raise BindviewError("a comparison needs at least two ligands")
|
|
711
|
+
built = [_member(m, args, say) for m in args.members]
|
|
712
|
+
unknown = [n for n in args.untrusted if n not in [b[0] for b in built]]
|
|
713
|
+
if unknown:
|
|
714
|
+
raise BindviewError(f"--untrusted names no ligand of the set: {', '.join(unknown)}")
|
|
715
|
+
cmp_ = Comparison([d for _, d in built], [n for n, _ in built])
|
|
716
|
+
result = cmp_.render_svg(args.output, view=args.view, theme=args.theme, title=args.title,
|
|
717
|
+
subtitle=args.subtitle, min_ligands=args.min_ligands,
|
|
718
|
+
thumbnails=not args.no_thumbnails, figure_width_mm=args.width_mm,
|
|
719
|
+
min_font_pt=args.min_font_pt, on_unreadable=args.on_unreadable, burial=args.burial,
|
|
720
|
+
colors=args.colors)
|
|
721
|
+
if args.fingerprints:
|
|
722
|
+
cmp_.table.to_csv(args.fingerprints)
|
|
723
|
+
say(f"fingerprints -> {args.fingerprints}")
|
|
724
|
+
if args.graph and result.graph is not None:
|
|
725
|
+
result.graph.to_json(args.graph)
|
|
726
|
+
say(f"graph -> {args.graph}")
|
|
727
|
+
if args.json:
|
|
728
|
+
json.dump({"status": result.status, "figure": result.figure, "view": result.style,
|
|
729
|
+
"output": str(result.path) if result.path else None, "warnings": result.warnings,
|
|
730
|
+
"confidence": result.confidence, "burial": result.burial, **result.data}, sys.stdout, indent=2)
|
|
731
|
+
sys.stdout.write("\n")
|
|
732
|
+
say(cmp_.core.describe())
|
|
733
|
+
where = f" -> {result.path}" if result.path else " (no figure written)"
|
|
734
|
+
say(f"{result.status}: {result.figure}{where}")
|
|
735
|
+
for w in result.warnings:
|
|
736
|
+
say(f" note: {w}")
|
|
737
|
+
return 3 if result.status == "unreadable" else 0
|
|
738
|
+
|
|
739
|
+
|
|
740
|
+
def _fingerprint(args: argparse.Namespace) -> int:
|
|
741
|
+
def say(msg: str) -> None:
|
|
742
|
+
if not args.quiet:
|
|
743
|
+
print(msg, file=sys.stderr)
|
|
744
|
+
|
|
745
|
+
from .fingerprint import FingerprintTable
|
|
746
|
+
|
|
747
|
+
built = [_member(m, args, say) for m in args.members]
|
|
748
|
+
table = FingerprintTable([d.fingerprint(n) for n, d in built])
|
|
749
|
+
text = table.to_csv(args.output, form=args.form, counts=args.counts)
|
|
750
|
+
if not args.output:
|
|
751
|
+
sys.stdout.write(text)
|
|
752
|
+
else:
|
|
753
|
+
say(f"{len(built)} fingerprint(s), {len(table.columns)} columns -> {args.output}")
|
|
754
|
+
return 0
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
def _interface(args: argparse.Namespace) -> int:
|
|
758
|
+
from .interface import Interface, load_interface_contacts
|
|
759
|
+
|
|
760
|
+
def say(msg: str) -> None:
|
|
761
|
+
if not args.quiet:
|
|
762
|
+
print(msg, file=sys.stderr)
|
|
763
|
+
|
|
764
|
+
_folder_there("--notes-file", args.notes_file)
|
|
765
|
+
structure = Path(args.structure)
|
|
766
|
+
contacts = None
|
|
767
|
+
if args.contacts:
|
|
768
|
+
with _reading("the table of contacts", args.contacts):
|
|
769
|
+
contacts = load_interface_contacts(args.contacts)
|
|
770
|
+
say(f"contacts: {args.contacts}" if args.contacts else "contacts: detecting with PLIP (peptide mode)")
|
|
771
|
+
face = Interface(structure, args.between, contacts, spine=args.spine, site=args.site, radius=args.radius,
|
|
772
|
+
max_residues=args.max_residues, order=args.order,
|
|
773
|
+
pae=None if not args.pae else args.pae[0] if len(args.pae) == 1 else args.pae,
|
|
774
|
+
layout=args.layout, detail=args.detail, ipsae=args.ipsae,
|
|
775
|
+
model_confidence=args.model_confidence or "auto")
|
|
776
|
+
out = Path(args.output) if args.output else structure.with_name(f"{_stem(structure)}.interface.{args.style}.svg")
|
|
777
|
+
result = face.render_svg(out, style=args.style, theme=args.theme, title=args.title, colors=args.colors,
|
|
778
|
+
plddt_colors="bonds" if args.plddt_bonds else args.plddt_colors, interactive=args.interactive,
|
|
779
|
+
break_lines=not args.no_break_lines, charge_halos=args.charge_halos,
|
|
780
|
+
charge_key=not args.no_charge_key, plddt_by_atom=not args.no_plddt_by_atom,
|
|
781
|
+
bare=args.bare, pae_colors=True if args.pae_colors else None, **_style_settings(args))
|
|
782
|
+
_write_notes(args, result, say)
|
|
783
|
+
if args.graph and result.graph is not None:
|
|
784
|
+
result.graph.to_json(args.graph)
|
|
785
|
+
say(f"graph -> {args.graph}")
|
|
786
|
+
site = face.site
|
|
787
|
+
say(f"spine: {face.spine.name}; {len(site.residues)} of {site.of_residues} residues at the interface, "
|
|
788
|
+
f"{site.contacts} of {site.of_contacts} contacts ({site.rule})")
|
|
789
|
+
drawn = result.data.get("interface", {})
|
|
790
|
+
if drawn.get("layout_rule"):
|
|
791
|
+
say(f"layout: {drawn['layout_rule']}")
|
|
792
|
+
for s in face.ipsae:
|
|
793
|
+
say(f"ipSAE (PAE below {s.cutoff:g} angstrom): {s.forward:.2f} aligned on {s.first} and scored over "
|
|
794
|
+
f"{s.second}, {s.backward:.2f} the reverse")
|
|
795
|
+
if args.json:
|
|
796
|
+
json.dump({"status": result.status, "figure": result.figure, "output": str(result.path) if result.path
|
|
797
|
+
else None, "warnings": result.warnings, "notes": result.notes, **result.data}, sys.stdout,
|
|
798
|
+
indent=2)
|
|
799
|
+
sys.stdout.write("\n")
|
|
800
|
+
say(f"{result.status}: {result.figure}" + (f" -> {result.path}" if result.path else " (no figure written)"))
|
|
801
|
+
for w in result.warnings:
|
|
802
|
+
say(f" note: {w}")
|
|
803
|
+
return 3 if result.status == "unreadable" else 0
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
def _read_pairs(path: Path) -> list:
|
|
807
|
+
from .basepairs import read_fr3d_pairs, read_mmcif_pairs, read_rnapolis_pairs
|
|
808
|
+
|
|
809
|
+
name = path.name.lower()
|
|
810
|
+
with _reading("the pairs of", path):
|
|
811
|
+
if name.endswith(".json"):
|
|
812
|
+
return read_rnapolis_pairs(path)
|
|
813
|
+
if name.endswith(".csv"):
|
|
814
|
+
return read_fr3d_pairs(path)
|
|
815
|
+
return read_mmcif_pairs(path)
|
|
816
|
+
|
|
817
|
+
|
|
818
|
+
def _read_stacks(path: Path) -> list:
|
|
819
|
+
from .basepairs import read_fr3d_stacks, read_rnapolis_stacks
|
|
820
|
+
|
|
821
|
+
with _reading("the stacks of", path):
|
|
822
|
+
return read_rnapolis_stacks(path) if path.name.lower().endswith(".json") else read_fr3d_stacks(path)
|
|
823
|
+
|
|
824
|
+
|
|
825
|
+
def _basepairs(args: argparse.Namespace) -> int:
|
|
826
|
+
from .basepairs import (BasePairs, pairs_from_contacts, pairs_from_dot_bracket, pairs_within_from_table,
|
|
827
|
+
read_mmcif_pairs)
|
|
828
|
+
from .distance_table import interface_contacts
|
|
829
|
+
from .structure import read_structure
|
|
830
|
+
|
|
831
|
+
def say(msg: str) -> None:
|
|
832
|
+
if not args.quiet:
|
|
833
|
+
print(msg, file=sys.stderr)
|
|
834
|
+
|
|
835
|
+
_folder_there("--notes-file", args.notes_file)
|
|
836
|
+
structure = Path(args.structure)
|
|
837
|
+
model = read_structure(structure)
|
|
838
|
+
a, b = args.chains
|
|
839
|
+
contacts = [] if args.no_contacts else interface_contacts(model, [a], [b], stacking=True)
|
|
840
|
+
pairs = [p for f in args.pairs for p in _read_pairs(Path(f))]
|
|
841
|
+
said = [f"pairs: {', '.join(args.pairs)}"] if args.pairs else []
|
|
842
|
+
bracketed = set()
|
|
843
|
+
for spec in args.dot_bracket:
|
|
844
|
+
chain, sep, text = spec.partition("=")
|
|
845
|
+
if not sep:
|
|
846
|
+
raise BindviewError(f"--dot-bracket {spec!r}: write it as CHAIN=STRUCTURE")
|
|
847
|
+
pairs += pairs_from_dot_bracket(model, chain.strip(), text.strip(), family=args.family)
|
|
848
|
+
bracketed.add(chain.strip())
|
|
849
|
+
said.append(f"pairs within {chain.strip()}: the dot-bracket")
|
|
850
|
+
if not args.pairs:
|
|
851
|
+
own = read_mmcif_pairs(structure) if structure.name.lower().endswith((".cif", ".cif.gz", ".mmcif")) else []
|
|
852
|
+
if own:
|
|
853
|
+
pairs += own
|
|
854
|
+
said.append("pairs: the PDB's annotation in the file")
|
|
855
|
+
elif not args.no_contacts:
|
|
856
|
+
pairs += pairs_from_contacts(contacts)[0]
|
|
857
|
+
for chain in (a, b):
|
|
858
|
+
if chain not in bracketed:
|
|
859
|
+
pairs += pairs_within_from_table(model, chain)
|
|
860
|
+
said.append("pairs" + (" across" if bracketed else "") + ": the plain distance table's stand-in, "
|
|
861
|
+
"without a family")
|
|
862
|
+
from_json = [f for f in args.pairs if f.lower().endswith(".json")]
|
|
863
|
+
stack_files = args.stacks or from_json # left out: an RNApolis --pairs has them
|
|
864
|
+
stacks = [st for f in stack_files for st in _read_stacks(Path(f))] if stack_files else None
|
|
865
|
+
figure = BasePairs(model, [a, b], pairs, stacks=stacks, contacts=contacts, ligand=args.ligand,
|
|
866
|
+
ligand_contacts=args.ligand_contacts, ligand_name=args.ligand_name,
|
|
867
|
+
ligand_smiles=args.ligand_smiles)
|
|
868
|
+
graph = Graph.from_json(Path(args.from_graph)) if args.from_graph else None
|
|
869
|
+
out = Path(args.output) if args.output else structure.with_name(f"{_stem(structure)}.basepairs.svg")
|
|
870
|
+
result = figure.render_svg(out, theme=args.theme, colors=args.colors, title=args.title,
|
|
871
|
+
legend=not args.no_legend, caption=not args.no_caption, step=args.step,
|
|
872
|
+
figure_width_mm=args.width_mm, min_font_pt=args.min_font_pt,
|
|
873
|
+
interactive=args.interactive, graph=graph)
|
|
874
|
+
for line in said:
|
|
875
|
+
say(line)
|
|
876
|
+
_write_notes(args, result, say)
|
|
877
|
+
if args.graph and result.graph is not None:
|
|
878
|
+
result.graph.to_json(args.graph)
|
|
879
|
+
say(f"graph -> {args.graph}")
|
|
880
|
+
say(f"{result.data['pairs_across']} pairs across, {result.data['pairs_within']} within, "
|
|
881
|
+
f"{result.data['stacks']} stacks ({result.data['layout']})")
|
|
882
|
+
unreadable = result.status == "unreadable"
|
|
883
|
+
status = result.status
|
|
884
|
+
if args.json:
|
|
885
|
+
json.dump({"status": status, "figure": "basepairs", "output": str(result.path) if result.path
|
|
886
|
+
else None, "warnings": result.warnings, "notes": result.notes, **result.data}, sys.stdout,
|
|
887
|
+
indent=2)
|
|
888
|
+
sys.stdout.write("\n")
|
|
889
|
+
say(f"{status}: base pairs" + (f" -> {result.path}" if result.path else " (no figure written)"))
|
|
890
|
+
for w in result.warnings:
|
|
891
|
+
say(f" note: {w}")
|
|
892
|
+
return 3 if unreadable else 0
|
|
893
|
+
|
|
894
|
+
|
|
895
|
+
def _report(args: argparse.Namespace) -> int:
|
|
896
|
+
from .report import survey, write_each
|
|
897
|
+
|
|
898
|
+
def say(msg: str) -> None:
|
|
899
|
+
if not args.quiet:
|
|
900
|
+
print(msg, file=sys.stderr)
|
|
901
|
+
|
|
902
|
+
given: dict[str, str] = {}
|
|
903
|
+
for item in args.smiles:
|
|
904
|
+
name, sep, smiles = item.partition("=")
|
|
905
|
+
if not (sep and name and smiles):
|
|
906
|
+
raise BindviewError(f"--smiles takes NAME=SMILES, not {item!r}")
|
|
907
|
+
given[name] = smiles
|
|
908
|
+
parts: list[tuple[str, str, int, int]] = []
|
|
909
|
+
for item in args.domain:
|
|
910
|
+
name, sep, where = item.partition("=")
|
|
911
|
+
chain, colon, span = where.partition(":")
|
|
912
|
+
ends = re.fullmatch(r"(-?[0-9]+)-(-?[0-9]+)", span) # (a residue number may be negative: -5-10)
|
|
913
|
+
if not (sep and colon and name and chain and ends):
|
|
914
|
+
raise BindviewError(f"--domain takes NAME=CHAIN:FROM-TO, not {item!r}")
|
|
915
|
+
parts.append((name, chain, int(ends[1]), int(ends[2])))
|
|
916
|
+
if len(parts) == 1:
|
|
917
|
+
raise BindviewError("one --domain names one part: an interface is between two")
|
|
918
|
+
if args.each:
|
|
919
|
+
if args.look or parts:
|
|
920
|
+
raise BindviewError("--each draws every input of a folder: not with --look or --domain")
|
|
921
|
+
say(f"{args.input}: a page for each input")
|
|
922
|
+
rows, index = write_each(args.input, args.output, given, views=not args.one_view, say=say)
|
|
923
|
+
drawn = sum(1 for r in rows if r.first is not None)
|
|
924
|
+
say(f"{drawn} of {len(rows)} inputs have a figure; index -> {index} and {index.with_suffix('.csv')}")
|
|
925
|
+
return 0
|
|
926
|
+
source = Path(args.input)
|
|
927
|
+
out = Path(args.output) if args.output else source.parent / (
|
|
928
|
+
(_stem(source) if source.is_file() else source.name) + ".report.html")
|
|
929
|
+
if not args.look:
|
|
930
|
+
_folder_there("-o", args.output) # (without -o the page goes beside the input)
|
|
931
|
+
found = survey(args.input, given, parts or None)
|
|
932
|
+
if found.kind == "series":
|
|
933
|
+
say(f"{args.input}: a series of {len(found.members)} ligands on one protein: "
|
|
934
|
+
+ ", ".join(m.name for m in found.members))
|
|
935
|
+
say(f"{args.input}: " + ", ".join(
|
|
936
|
+
f"chain {c.name}: {c.what if c.kind else 'no polymer'}" + (f" of {c.residues}" if c.residues else "")
|
|
937
|
+
for c in found.found.chains))
|
|
938
|
+
say(" other residues: " + (", ".join(f"{c.name} x{c.copies} ({c.kind}, {c.heavy} heavy atom{'s' if c.heavy != 1 else ''})"
|
|
939
|
+
for c in found.found.candidates) or "none")
|
|
940
|
+
+ f"; waters: {found.found.waters}; models in the file: {found.models_in_file}")
|
|
941
|
+
if not args.look:
|
|
942
|
+
found.draw(views=not args.one_view)
|
|
943
|
+
for track in found.tracks:
|
|
944
|
+
say(f" {track.kind}: {track.title}: " + (track.status or "to draw")
|
|
945
|
+
+ (", in the schematic style: the detailed one is not readable" if track.schematic else ""))
|
|
946
|
+
for what, why in found.left:
|
|
947
|
+
say(f" no figure: {what}: {why}")
|
|
948
|
+
if args.look:
|
|
949
|
+
return 0
|
|
950
|
+
_write("-o", out, found.html())
|
|
951
|
+
say(f"report -> {out}")
|
|
952
|
+
return 0
|
|
953
|
+
|
|
954
|
+
|
|
955
|
+
def _said(exc: Exception) -> str:
|
|
956
|
+
"""An exception that is no BindviewError, as a message."""
|
|
957
|
+
if isinstance(exc, UnicodeDecodeError):
|
|
958
|
+
return f"a file that was read is not text in UTF-8: {exc}"
|
|
959
|
+
if isinstance(exc, OSError) and exc.filename is not None:
|
|
960
|
+
return f"{exc.strerror or type(exc).__name__}: {exc.filename}"
|
|
961
|
+
return str(exc) or type(exc).__name__
|
|
962
|
+
|
|
963
|
+
|
|
964
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
965
|
+
args = build_parser().parse_args(argv)
|
|
966
|
+
try:
|
|
967
|
+
if args.command == "render":
|
|
968
|
+
return _render(args)
|
|
969
|
+
if args.command == "interface":
|
|
970
|
+
return _interface(args)
|
|
971
|
+
if args.command == "basepairs":
|
|
972
|
+
return _basepairs(args)
|
|
973
|
+
if args.command == "compare":
|
|
974
|
+
return _compare(args)
|
|
975
|
+
if args.command == "fingerprint":
|
|
976
|
+
return _fingerprint(args)
|
|
977
|
+
return _report(args) # (the parser takes no other command)
|
|
978
|
+
except BindviewError as exc:
|
|
979
|
+
print(f"bindview: error: {exc}", file=sys.stderr)
|
|
980
|
+
return 2
|
|
981
|
+
except (OSError, ValueError) as exc:
|
|
982
|
+
# What a wrong input raises where nothing made it a BindviewError: a file that cannot be read or written, one
|
|
983
|
+
# that is not text (UnicodeDecodeError is a ValueError), a value that the library refuses. A mistake of the
|
|
984
|
+
# program is none of these as a rule (TypeError, KeyError, IndexError), and keeps its traceback.
|
|
985
|
+
print(f"bindview: error: {_said(exc)}", file=sys.stderr)
|
|
986
|
+
return 2
|
|
987
|
+
|
|
988
|
+
|
|
989
|
+
if __name__ == "__main__": # pragma: no cover
|
|
990
|
+
raise SystemExit(main())
|