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/residues.py
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
"""Standard amino-acid and nucleotide knowledge: topology, residue classes, rings, charged groups.
|
|
2
|
+
|
|
3
|
+
The templates are written out by hand (atom names in SMILES order) rather than
|
|
4
|
+
taken from a component dictionary so that the core needs no data files and no
|
|
5
|
+
network. Only the 20 standard residues and the eight standard nucleotides of RNA
|
|
6
|
+
and DNA are covered; anything else is drawn as a bare labelled atom, which is
|
|
7
|
+
always correct if less informative.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
from dataclasses import dataclass
|
|
13
|
+
from functools import lru_cache
|
|
14
|
+
from typing import Iterable
|
|
15
|
+
|
|
16
|
+
from .exposure import WATER_NAMES
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"ResidueTemplate", "template_for", "residue_class", "BACKBONE",
|
|
20
|
+
"aromatic_rings", "charged_groups", "can_donate", "can_accept", "canonical_resname", "format_residue_label",
|
|
21
|
+
"PHOSPHATE", "TAIL", "SUGAR", "NUCLEOTIDE_BACKBONE", "is_nucleotide", "canonical_atom", "given_atom",
|
|
22
|
+
"is_backbone_atom", "element_of", "written", "ATOM_LABELS",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
BACKBONE = ("N", "CA", "C", "O")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True)
|
|
29
|
+
class ResidueTemplate:
|
|
30
|
+
name: str
|
|
31
|
+
smiles: str
|
|
32
|
+
atoms: tuple[str, ...]
|
|
33
|
+
kind: str = "amino" # or "nucleotide"
|
|
34
|
+
|
|
35
|
+
@property
|
|
36
|
+
def sidechain(self) -> tuple[str, ...]:
|
|
37
|
+
return tuple(a for a in self.atoms if a not in BACKBONE)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# SMILES atom order == ``atoms`` order. Backbone is written N, CA, C, O first.
|
|
41
|
+
_TEMPLATES: dict[str, ResidueTemplate] = {
|
|
42
|
+
t.name: t for t in (
|
|
43
|
+
ResidueTemplate("ALA", "NC(C=O)C", ("N", "CA", "C", "O", "CB")),
|
|
44
|
+
ResidueTemplate("ARG", "NC(C=O)CCCNC(N)=N", ("N", "CA", "C", "O", "CB", "CG", "CD", "NE", "CZ", "NH1", "NH2")),
|
|
45
|
+
ResidueTemplate("ASN", "NC(C=O)CC(=O)N", ("N", "CA", "C", "O", "CB", "CG", "OD1", "ND2")),
|
|
46
|
+
ResidueTemplate("ASP", "NC(C=O)CC(=O)O", ("N", "CA", "C", "O", "CB", "CG", "OD1", "OD2")),
|
|
47
|
+
ResidueTemplate("CYS", "NC(C=O)CS", ("N", "CA", "C", "O", "CB", "SG")),
|
|
48
|
+
ResidueTemplate("GLN", "NC(C=O)CCC(=O)N", ("N", "CA", "C", "O", "CB", "CG", "CD", "OE1", "NE2")),
|
|
49
|
+
ResidueTemplate("GLU", "NC(C=O)CCC(=O)O", ("N", "CA", "C", "O", "CB", "CG", "CD", "OE1", "OE2")),
|
|
50
|
+
ResidueTemplate("GLY", "NCC=O", ("N", "CA", "C", "O")),
|
|
51
|
+
ResidueTemplate("HIS", "NC(C=O)Cc1[nH]cnc1", ("N", "CA", "C", "O", "CB", "CG", "ND1", "CE1", "NE2", "CD2")),
|
|
52
|
+
ResidueTemplate("ILE", "NC(C=O)C(CC)C", ("N", "CA", "C", "O", "CB", "CG1", "CD1", "CG2")),
|
|
53
|
+
ResidueTemplate("LEU", "NC(C=O)CC(C)C", ("N", "CA", "C", "O", "CB", "CG", "CD1", "CD2")),
|
|
54
|
+
ResidueTemplate("LYS", "NC(C=O)CCCCN", ("N", "CA", "C", "O", "CB", "CG", "CD", "CE", "NZ")),
|
|
55
|
+
ResidueTemplate("MET", "NC(C=O)CCSC", ("N", "CA", "C", "O", "CB", "CG", "SD", "CE")),
|
|
56
|
+
ResidueTemplate("PHE", "NC(C=O)Cc1ccccc1", ("N", "CA", "C", "O", "CB", "CG", "CD1", "CE1", "CZ", "CE2", "CD2")),
|
|
57
|
+
ResidueTemplate("PRO", "N1C(C=O)CCC1", ("N", "CA", "C", "O", "CB", "CG", "CD")),
|
|
58
|
+
ResidueTemplate("SER", "NC(C=O)CO", ("N", "CA", "C", "O", "CB", "OG")),
|
|
59
|
+
ResidueTemplate("THR", "NC(C=O)C(O)C", ("N", "CA", "C", "O", "CB", "OG1", "CG2")),
|
|
60
|
+
ResidueTemplate("TRP", "NC(C=O)Cc1c[nH]c2ccccc12",
|
|
61
|
+
("N", "CA", "C", "O", "CB", "CG", "CD1", "NE1", "CE2", "CZ2", "CH2", "CZ3", "CE3", "CD2")),
|
|
62
|
+
ResidueTemplate("TYR", "NC(C=O)Cc1ccc(O)cc1",
|
|
63
|
+
("N", "CA", "C", "O", "CB", "CG", "CD1", "CE1", "CZ", "OH", "CE2", "CD2")),
|
|
64
|
+
ResidueTemplate("VAL", "NC(C=O)C(C)C", ("N", "CA", "C", "O", "CB", "CG1", "CG2")),
|
|
65
|
+
)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
# -- nucleotides ---------------------------------------------------------------
|
|
69
|
+
# A nucleotide in a chain: its phosphate, the C5' and O5' that lead from it to the sugar, the sugar, and
|
|
70
|
+
# the base. The glycosidic carbon C1' is to it what the alpha carbon is to an amino acid: where the base,
|
|
71
|
+
# its "side chain", leaves the backbone of sugar and phosphate.
|
|
72
|
+
PHOSPHATE = ("P", "OP1", "OP2")
|
|
73
|
+
TAIL = ("C5'", "O5'")
|
|
74
|
+
SUGAR = ("C1'", "C2'", "O2'", "C3'", "O3'", "C4'", "O4'")
|
|
75
|
+
NUCLEOTIDE_BACKBONE = PHOSPHATE + TAIL + SUGAR
|
|
76
|
+
|
|
77
|
+
# A base as it hangs on C1': its SMILES (ring closures 2 and 3; the sugar has 1) and its atoms in that order.
|
|
78
|
+
_BASES = {
|
|
79
|
+
"A": ("n2cnc3c(N)ncnc32", ("N9", "C8", "N7", "C5", "C6", "N6", "N1", "C2", "N3", "C4")),
|
|
80
|
+
"G": ("n2cnc3c(=O)[nH]c(N)nc32", ("N9", "C8", "N7", "C5", "C6", "O6", "N1", "C2", "N2", "N3", "C4")),
|
|
81
|
+
"C": ("n2c(=O)nc(N)cc2", ("N1", "C2", "O2", "N3", "C4", "N4", "C5", "C6")),
|
|
82
|
+
"U": ("n2c(=O)[nH]c(=O)cc2", ("N1", "C2", "O2", "N3", "C4", "O4", "C5", "C6")),
|
|
83
|
+
"T": ("n2c(=O)[nH]c(=O)c(C)c2", ("N1", "C2", "O2", "N3", "C4", "O4", "C5", "C7", "C6")),
|
|
84
|
+
}
|
|
85
|
+
_PURINE = (("N9", "C8", "N7", "C5", "C4"), ("C4", "C5", "C6", "N1", "C2", "N3"))
|
|
86
|
+
_PYRIMIDINE = (("N1", "C2", "N3", "C4", "C5", "C6"),)
|
|
87
|
+
#: The standard nucleotides by residue name, with the base each carries: RNA, then DNA.
|
|
88
|
+
_NUCLEOTIDES = {"A": "A", "C": "C", "G": "G", "U": "U", "DA": "A", "DC": "C", "DG": "G", "DT": "T"}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _nucleotide(name: str) -> ResidueTemplate:
|
|
92
|
+
"""The template of a nucleotide: phosphate, C5', sugar with the base on it (a ribose, or without O2')."""
|
|
93
|
+
smiles, atoms = _BASES[_NUCLEOTIDES[name]]
|
|
94
|
+
head = ("P", "OP1", "OP2", "O5'", "C5'", "C4'", "O4'", "C1'")
|
|
95
|
+
if name.startswith("D"):
|
|
96
|
+
return ResidueTemplate(name, f"P(=O)(O)OCC1OC({smiles})CC1O", head + atoms + ("C2'", "C3'", "O3'"), "nucleotide")
|
|
97
|
+
return ResidueTemplate(name, f"P(=O)(O)OCC1OC({smiles})C(O)C1O", head + atoms + ("C2'", "O2'", "C3'", "O3'"),
|
|
98
|
+
"nucleotide")
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# The nucleotides have a table of their own: ``_TEMPLATES`` holds the twenty amino acids and nothing else.
|
|
102
|
+
_NUCLEOTIDE_TEMPLATES = {name: _nucleotide(name) for name in _NUCLEOTIDES}
|
|
103
|
+
|
|
104
|
+
# Protonation / naming variants written by modelling packages.
|
|
105
|
+
_ALIASES = {
|
|
106
|
+
"HID": "HIS", "HIE": "HIS", "HIP": "HIS", "HSD": "HIS", "HSE": "HIS", "HSP": "HIS",
|
|
107
|
+
"CYX": "CYS", "CYM": "CYS", "ASH": "ASP", "GLH": "GLU", "LYN": "LYS", "ARN": "ARG",
|
|
108
|
+
}
|
|
109
|
+
# A nucleotide as force fields name it: with R for RNA, and with 5 or 3 where it ends a chain.
|
|
110
|
+
_ALIASES.update({alias: base for base in "ACGU"
|
|
111
|
+
for alias in (f"R{base}", f"{base}5", f"{base}3", f"R{base}5", f"R{base}3")})
|
|
112
|
+
_ALIASES.update({alias: f"D{base}" for base in "ACGT" for alias in (f"D{base}5", f"D{base}3")})
|
|
113
|
+
# An atom of a nucleotide as older files name it.
|
|
114
|
+
_ATOM_ALIASES = {"O1P": "OP1", "O2P": "OP2", "C5M": "C7"}
|
|
115
|
+
|
|
116
|
+
_CLASS = {
|
|
117
|
+
"ALA": "hydrophobic", "VAL": "hydrophobic", "LEU": "hydrophobic", "ILE": "hydrophobic",
|
|
118
|
+
"MET": "hydrophobic", "PHE": "hydrophobic", "TRP": "hydrophobic", "TYR": "hydrophobic",
|
|
119
|
+
"PRO": "hydrophobic", "CYS": "hydrophobic",
|
|
120
|
+
"SER": "polar", "THR": "polar", "ASN": "polar", "GLN": "polar", "HIS": "polar",
|
|
121
|
+
"ARG": "positive", "LYS": "positive",
|
|
122
|
+
"ASP": "negative", "GLU": "negative",
|
|
123
|
+
"GLY": "glycine",
|
|
124
|
+
}
|
|
125
|
+
_CLASS.update({name: "water" for name in WATER_NAMES})
|
|
126
|
+
_CLASS.update({name: "nucleotide" for name in _NUCLEOTIDES})
|
|
127
|
+
|
|
128
|
+
_RINGS = {
|
|
129
|
+
"PHE": (("CG", "CD1", "CE1", "CZ", "CE2", "CD2"),),
|
|
130
|
+
"TYR": (("CG", "CD1", "CE1", "CZ", "CE2", "CD2"),),
|
|
131
|
+
"TRP": (("CG", "CD1", "NE1", "CE2", "CD2"), ("CD2", "CE2", "CZ2", "CH2", "CZ3", "CE3")),
|
|
132
|
+
"HIS": (("CG", "ND1", "CE1", "NE2", "CD2"),),
|
|
133
|
+
}
|
|
134
|
+
_RINGS.update({name: _PURINE if base in "AG" else _PYRIMIDINE for name, base in _NUCLEOTIDES.items()})
|
|
135
|
+
|
|
136
|
+
# Charge centres follow the common detector convention (PLIP): the centroid of
|
|
137
|
+
# the side-chain nitrogens / oxygens.
|
|
138
|
+
_POSITIVE = {"ARG": ("NE", "NH1", "NH2"), "LYS": ("NZ",), "HIS": ("ND1", "NE2")}
|
|
139
|
+
_NEGATIVE: dict[str, tuple[str, ...]] = {"ASP": ("OD1", "OD2"), "GLU": ("OE1", "OE2")}
|
|
140
|
+
# The phosphate of a nucleotide, under the names a file may give its two free oxygens.
|
|
141
|
+
_NEGATIVE.update({name: ("P", "OP1", "OP2", "O1P", "O2P") for name in _NUCLEOTIDES})
|
|
142
|
+
|
|
143
|
+
# Atoms that carry a hydrogen in the standard protonation state.
|
|
144
|
+
_DONORS = {
|
|
145
|
+
"ARG": {"NE", "NH1", "NH2"}, "ASN": {"ND2"}, "GLN": {"NE2"}, "HIS": {"ND1", "NE2"},
|
|
146
|
+
"LYS": {"NZ"}, "SER": {"OG"}, "THR": {"OG1"}, "TYR": {"OH"}, "TRP": {"NE1"}, "CYS": {"SG"},
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
_DONORS.update({name: {"A": {"N6"}, "G": {"N1", "N2"}, "C": {"N4"}, "U": {"N3"}, "T": {"N3"}}[base]
|
|
150
|
+
| (set() if name.startswith("D") else {"O2'"}) for name, base in _NUCLEOTIDES.items()})
|
|
151
|
+
|
|
152
|
+
# Nitrogens that take a hydrogen bond: a ring nitrogen of histidine (which of the two carries the hydrogen
|
|
153
|
+
# a structure does not say), and the ring nitrogens of a base that carry none and are not bound to the sugar.
|
|
154
|
+
_ACCEPTOR_N: dict[str, set[str]] = {"HIS": {"ND1", "NE2"}}
|
|
155
|
+
_ACCEPTOR_N.update({name: {"A": {"N1", "N3", "N7"}, "G": {"N3", "N7"}, "C": {"N3"}, "U": set(), "T": set()}[base]
|
|
156
|
+
for name, base in _NUCLEOTIDES.items()})
|
|
157
|
+
|
|
158
|
+
_METAL_RESIDUES = {
|
|
159
|
+
"ZN", "MG", "MN", "CA", "FE", "FE2", "CU", "CU1", "NI", "CO", "NA", "K", "CD", "HG",
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def canonical_resname(name: str) -> str:
|
|
164
|
+
up = name.upper()
|
|
165
|
+
return _ALIASES.get(up, up)
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def template_for(resname: str) -> ResidueTemplate | None:
|
|
169
|
+
name = canonical_resname(resname)
|
|
170
|
+
return _TEMPLATES.get(name) or _NUCLEOTIDE_TEMPLATES.get(name)
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def is_nucleotide(resname: str) -> bool:
|
|
174
|
+
t = template_for(resname)
|
|
175
|
+
return t is not None and t.kind == "nucleotide"
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def canonical_atom(resname: str, atom: str) -> str:
|
|
179
|
+
"""The name the templates have for an atom. Of a nucleotide the current one (``OP1`` for ``O1P``,
|
|
180
|
+
``C1'`` for ``C1*``, ``C7`` for ``C5M``); any other atom as it is."""
|
|
181
|
+
if not is_nucleotide(resname):
|
|
182
|
+
return atom
|
|
183
|
+
name = atom.replace("*", "'")
|
|
184
|
+
return _ATOM_ALIASES.get(name, name)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def given_atom(name: str, like: "Iterable[str]") -> str:
|
|
188
|
+
"""A nucleotide's atom, named by the templates, under the name a file would give it that names its
|
|
189
|
+
atoms as ``like``: ``O1P`` where those say ``O1P`` or ``O2P`` (or ``C5M``), a star where they write
|
|
190
|
+
the prime as a star. The names of a figure's contacts say which file it is."""
|
|
191
|
+
like = tuple(like)
|
|
192
|
+
if any(n.replace("*", "'") in _ATOM_ALIASES for n in like):
|
|
193
|
+
name = {new: old for old, new in _ATOM_ALIASES.items()}.get(name, name)
|
|
194
|
+
return name.replace("'", "*") if any("*" in n for n in like) else name
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
#: What is written on an atom that is drawn of a residue (``RenderOptions.atom_labels``).
|
|
198
|
+
ATOM_LABELS = ("elements", "names")
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
def element_of(name: str) -> str:
|
|
202
|
+
"""The element of an atom of a standard residue, by its name: N of ``NZ``, O of ``OG1`` and ``O5'``, S of ``SD``."""
|
|
203
|
+
return "".join(ch for ch in name if ch.isalpha())[:1]
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
def written(name: str, labels: str = "names") -> str:
|
|
207
|
+
"""What a figure writes on an atom of a standard residue: its name in the structure file, or its element."""
|
|
208
|
+
return name if labels == "names" else element_of(name)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def is_backbone_atom(resname: str, atom: str) -> bool:
|
|
212
|
+
"""Is this an atom of the backbone and not of the side chain: N, CA, C, O and OXT of an amino acid,
|
|
213
|
+
the sugar and the phosphate of a nucleotide (whose base is its side chain)."""
|
|
214
|
+
if is_nucleotide(resname):
|
|
215
|
+
return canonical_atom(resname, atom) in NUCLEOTIDE_BACKBONE
|
|
216
|
+
return atom in BACKBONE + ("OXT",)
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
def residue_class(resname: str) -> str:
|
|
220
|
+
"""One of ``hydrophobic``, ``polar``, ``positive``, ``negative``, ``glycine``,
|
|
221
|
+
``nucleotide``, ``water``, ``metal`` or ``other``."""
|
|
222
|
+
up = canonical_resname(resname)
|
|
223
|
+
if up in _CLASS:
|
|
224
|
+
return _CLASS[up]
|
|
225
|
+
if up in _METAL_RESIDUES:
|
|
226
|
+
return "metal"
|
|
227
|
+
return "other"
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
def aromatic_rings(resname: str) -> tuple[tuple[str, ...], ...]:
|
|
231
|
+
return _RINGS.get(canonical_resname(resname), ())
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def charged_groups(resname: str) -> list[tuple[int, tuple[str, ...]]]:
|
|
235
|
+
"""``[(sign, atom_names)]`` for the residue's side-chain charge centres."""
|
|
236
|
+
up = canonical_resname(resname)
|
|
237
|
+
out: list[tuple[int, tuple[str, ...]]] = []
|
|
238
|
+
if up in _POSITIVE:
|
|
239
|
+
out.append((+1, _POSITIVE[up]))
|
|
240
|
+
if up in _NEGATIVE:
|
|
241
|
+
out.append((-1, _NEGATIVE[up]))
|
|
242
|
+
return out
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def can_donate(resname: str, atom: str) -> bool | None:
|
|
246
|
+
"""Whether a protein atom can donate an H-bond in the standard protonation state.
|
|
247
|
+
|
|
248
|
+
``None`` when the residue is not a standard amino acid or nucleotide (unknown), and for
|
|
249
|
+
the two oxygens of a nucleotide that carry a hydrogen only where a chain ends.
|
|
250
|
+
"""
|
|
251
|
+
up = canonical_resname(resname)
|
|
252
|
+
if up in _NUCLEOTIDE_TEMPLATES:
|
|
253
|
+
name = canonical_atom(up, atom)
|
|
254
|
+
return None if name in ("O3'", "O5'") else name in _DONORS.get(up, set())
|
|
255
|
+
if up not in _TEMPLATES:
|
|
256
|
+
return None
|
|
257
|
+
if atom == "N":
|
|
258
|
+
return up != "PRO"
|
|
259
|
+
return atom in _DONORS.get(up, set())
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
def can_accept(resname: str, atom: str, element: str) -> bool | None:
|
|
263
|
+
"""Whether a protein atom can take an H-bond: an oxygen, or a nitrogen with a free lone pair.
|
|
264
|
+
|
|
265
|
+
``None`` when the residue is not a standard amino acid or nucleotide (unknown).
|
|
266
|
+
"""
|
|
267
|
+
up = canonical_resname(resname)
|
|
268
|
+
if up not in _TEMPLATES and up not in _NUCLEOTIDE_TEMPLATES:
|
|
269
|
+
return None
|
|
270
|
+
if element.upper() == "O":
|
|
271
|
+
return True
|
|
272
|
+
return canonical_atom(up, atom) in _ACCEPTOR_N.get(up, set())
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
def format_residue_label(resname: str, number: int, icode: str = "", chain: str | None = None) -> str:
|
|
276
|
+
"""``Gln712`` or, with a chain, ``Gln712(A)`` -- the LigPlot convention. A nucleotide keeps its
|
|
277
|
+
capitals and is named as the templates name it: ``G7``, ``DA12``."""
|
|
278
|
+
name = canonical_resname(resname) if is_nucleotide(resname) else resname.capitalize()
|
|
279
|
+
base = f"{name}{number}{icode}"
|
|
280
|
+
return f"{base}({chain})" if chain else base
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@lru_cache(maxsize=None)
|
|
284
|
+
def template_bonds(resname: str) -> tuple[tuple[str, str, int], ...]:
|
|
285
|
+
"""Bonds of a residue template as ``(atom, atom, order)`` (aromatic kekulized)."""
|
|
286
|
+
from rdkit import Chem
|
|
287
|
+
|
|
288
|
+
t = template_for(resname)
|
|
289
|
+
if t is None:
|
|
290
|
+
return ()
|
|
291
|
+
mol = Chem.MolFromSmiles(t.smiles)
|
|
292
|
+
Chem.Kekulize(mol, clearAromaticFlags=True)
|
|
293
|
+
out = []
|
|
294
|
+
for b in mol.GetBonds():
|
|
295
|
+
out.append((t.atoms[b.GetBeginAtomIdx()], t.atoms[b.GetEndAtomIdx()], int(b.GetBondTypeAsDouble())))
|
|
296
|
+
return tuple(out)
|