servalcat 0.4.60__cp312-cp312-win_amd64.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.
Potentially problematic release.
This version of servalcat might be problematic. Click here for more details.
- servalcat/__init__.py +10 -0
- servalcat/__main__.py +120 -0
- servalcat/ext.cp312-win_amd64.pyd +0 -0
- servalcat/refine/__init__.py +0 -0
- servalcat/refine/cgsolve.py +100 -0
- servalcat/refine/refine.py +733 -0
- servalcat/refine/refine_geom.py +207 -0
- servalcat/refine/refine_spa.py +327 -0
- servalcat/refine/refine_xtal.py +242 -0
- servalcat/refine/spa.py +132 -0
- servalcat/refine/xtal.py +227 -0
- servalcat/refmac/__init__.py +0 -0
- servalcat/refmac/exte.py +182 -0
- servalcat/refmac/refmac_keywords.py +536 -0
- servalcat/refmac/refmac_wrapper.py +360 -0
- servalcat/spa/__init__.py +0 -0
- servalcat/spa/fofc.py +462 -0
- servalcat/spa/fsc.py +385 -0
- servalcat/spa/localcc.py +188 -0
- servalcat/spa/realspcc_from_var.py +128 -0
- servalcat/spa/run_refmac.py +961 -0
- servalcat/spa/shift_maps.py +293 -0
- servalcat/spa/shiftback.py +137 -0
- servalcat/spa/translate.py +129 -0
- servalcat/utils/__init__.py +35 -0
- servalcat/utils/commands.py +1277 -0
- servalcat/utils/fileio.py +745 -0
- servalcat/utils/generate_operators.py +296 -0
- servalcat/utils/hkl.py +699 -0
- servalcat/utils/logger.py +116 -0
- servalcat/utils/maps.py +340 -0
- servalcat/utils/model.py +774 -0
- servalcat/utils/refmac.py +747 -0
- servalcat/utils/restraints.py +605 -0
- servalcat/utils/symmetry.py +295 -0
- servalcat/xtal/__init__.py +0 -0
- servalcat/xtal/french_wilson.py +250 -0
- servalcat/xtal/run_refmac_small.py +240 -0
- servalcat/xtal/sigmaa.py +1403 -0
- servalcat-0.4.60.dist-info/METADATA +56 -0
- servalcat-0.4.60.dist-info/RECORD +44 -0
- servalcat-0.4.60.dist-info/WHEEL +5 -0
- servalcat-0.4.60.dist-info/entry_points.txt +4 -0
- servalcat-0.4.60.dist-info/licenses/LICENSE +373 -0
servalcat/refmac/exte.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Author: "Keitaro Yamashita, Garib N. Murshudov"
|
|
3
|
+
MRC Laboratory of Molecular Biology
|
|
4
|
+
|
|
5
|
+
This software is released under the
|
|
6
|
+
Mozilla Public License, version 2.0; see LICENSE.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import absolute_import, division, print_function, generators
|
|
9
|
+
import gemmi
|
|
10
|
+
import numpy
|
|
11
|
+
from servalcat.utils import logger
|
|
12
|
+
from servalcat.refmac.refmac_keywords import get_lines, read_exte_line
|
|
13
|
+
from servalcat import ext
|
|
14
|
+
|
|
15
|
+
"""import line_profiler
|
|
16
|
+
profile = line_profiler.LineProfiler()
|
|
17
|
+
import atexit
|
|
18
|
+
atexit.register(profile.print_stats)
|
|
19
|
+
@profile"""
|
|
20
|
+
def read_external_restraints(lines, st, geom):
|
|
21
|
+
# default or current values
|
|
22
|
+
defs = dict(symall_block=False, exclude_self_block=False, type_default=2, alpha_default=1.,
|
|
23
|
+
ext_verbose=False, scale_sigma_dist=1., scale_sigma_angl=1., scale_sigma_tors=1.,
|
|
24
|
+
scale_sigma_chir=1., scale_sigma_plan=1., scale_sigma_inte=1.,
|
|
25
|
+
sigma_min_loc=0., sigma_max_loc=100., ignore_undefined=False, ignore_hydrogens=True,
|
|
26
|
+
dist_max_external=numpy.inf, dist_min_external=-numpy.inf, use_atoms="a", prefix_ch=" ")
|
|
27
|
+
#exte = gemmi.ExternalRestraints(st)
|
|
28
|
+
extypes = dict(dist=ext.Geometry.Bond,
|
|
29
|
+
angl=ext.Geometry.Angle,
|
|
30
|
+
chir=ext.Geometry.Chirality,
|
|
31
|
+
tors=ext.Geometry.Torsion,
|
|
32
|
+
plan=ext.Geometry.Plane,
|
|
33
|
+
inte=ext.Geometry.Interval,
|
|
34
|
+
harm=ext.Geometry.Harmonic,
|
|
35
|
+
spec=ext.Geometry.Special,
|
|
36
|
+
stac=ext.Geometry.Stacking)
|
|
37
|
+
exlists = dict(dist=geom.bonds, angl=geom.angles, tors=geom.torsions,
|
|
38
|
+
chir=geom.chirs, plan=geom.planes, inte=geom.intervals,
|
|
39
|
+
stac=geom.stackings, harm=geom.harmonics, spec=geom.specials)
|
|
40
|
+
num_org = {x: len(exlists[x]) for x in exlists}
|
|
41
|
+
|
|
42
|
+
# XXX There may be duplication (same chain, resi, name, and alt) - we should give error?
|
|
43
|
+
lookup = {(cra.chain.name, cra.residue.seqid.num, cra.residue.seqid.icode,
|
|
44
|
+
cra.atom.name, cra.atom.altloc) : cra.atom for cra in st[0].all()}
|
|
45
|
+
|
|
46
|
+
# TODO main chain / side chain filtering, hydrogen, dist_max_external/dist_min_external
|
|
47
|
+
for l in get_lines(lines):
|
|
48
|
+
r = read_exte_line(l)
|
|
49
|
+
if not r: continue
|
|
50
|
+
defs.update(r["defaults"])
|
|
51
|
+
if "rest_type" not in r: continue
|
|
52
|
+
if r["rest_type"] not in extypes:
|
|
53
|
+
logger.writeln("Warning: unknown external restraint type: {}".format(r["rest_type"]))
|
|
54
|
+
continue
|
|
55
|
+
|
|
56
|
+
atoms = []
|
|
57
|
+
skip = False
|
|
58
|
+
for i, spec in enumerate(r["restr"].get("specs", [])):
|
|
59
|
+
if r["rest_type"] == "stac":
|
|
60
|
+
atoms.append([])
|
|
61
|
+
if "ifirst" in spec:
|
|
62
|
+
for chain in st[0]:
|
|
63
|
+
if chain.name != spec["chain"]: continue
|
|
64
|
+
for res in chain:
|
|
65
|
+
if spec["ifirst"] is not None and res.seqid.num < spec["ifirst"]: continue
|
|
66
|
+
if spec["ilast"] is not None and res.seqid.num > spec["ilast"]: continue
|
|
67
|
+
atoms.extend([a for a in res if spec["atom"] == "*" or a.name == spec["atom"]])
|
|
68
|
+
else:
|
|
69
|
+
for name in spec["names"]: # only same altloc allowed?
|
|
70
|
+
key = (spec["chain"], spec["resi"], spec.get("icode", " "),
|
|
71
|
+
name, spec.get("altloc", "\0"))
|
|
72
|
+
atom = lookup.get(key)
|
|
73
|
+
if atom is None:
|
|
74
|
+
if defs["ignore_undefined"]:
|
|
75
|
+
logger.writeln("Warning: atom not found: {}\n=>{}".format(key, l))
|
|
76
|
+
skip = True
|
|
77
|
+
continue
|
|
78
|
+
raise RuntimeError("Atom not found: {}\n=>{}".format(key, l))
|
|
79
|
+
if r["rest_type"] == "stac":
|
|
80
|
+
atoms[i].append(atom)
|
|
81
|
+
else:
|
|
82
|
+
atoms.append(atom)
|
|
83
|
+
if skip or not atoms:
|
|
84
|
+
continue
|
|
85
|
+
if r["rest_type"] in ("spec", "harm"):
|
|
86
|
+
if r["restr"]["rectype"] == "auto":
|
|
87
|
+
assert r["rest_type"] == "spec"
|
|
88
|
+
atoms = [cra.atom for cra in st[0].all()]
|
|
89
|
+
for atom in atoms:
|
|
90
|
+
ex = extypes[r["rest_type"]](atom)
|
|
91
|
+
if r["rest_type"] == "spec":
|
|
92
|
+
# TODO check if it is on special position. using r["restr"]["toler"]
|
|
93
|
+
ex.sigma_t = r["restr"]["sigma_t"]
|
|
94
|
+
ex.sigma_u =r["restr"]["sigma_u"]
|
|
95
|
+
ex.u_val_incl = r["restr"]["u_val_incl"]
|
|
96
|
+
# ex.trans_t =
|
|
97
|
+
# ex.mat_u =
|
|
98
|
+
else:
|
|
99
|
+
ex.sigma = r["restr"]["sigma_t"]
|
|
100
|
+
exlists[r["rest_type"]].append(ex)
|
|
101
|
+
continue
|
|
102
|
+
elif r["rest_type"] == "plan":
|
|
103
|
+
ex = extypes[r["rest_type"]](atoms)
|
|
104
|
+
else:
|
|
105
|
+
ex = extypes[r["rest_type"]](*atoms)
|
|
106
|
+
if r["rest_type"] in ("dist", "angl", "chir", "tors"):
|
|
107
|
+
value = r["restr"]["value"]
|
|
108
|
+
sigma = r["restr"]["sigma_value"] / defs["scale_sigma_{}".format(r["rest_type"])]
|
|
109
|
+
if r["rest_type"] == "chir":
|
|
110
|
+
ex.value = value
|
|
111
|
+
ex.sigma = sigma
|
|
112
|
+
else:
|
|
113
|
+
if r["rest_type"] == "dist":
|
|
114
|
+
sigma = min(max(sigma, defs["sigma_min_loc"]), defs["sigma_max_loc"])
|
|
115
|
+
vals = (value, sigma, value, sigma) # nucleus
|
|
116
|
+
elif r["rest_type"] == "tors":
|
|
117
|
+
vals = (value, sigma, 1) # period. # Refmac does not seem to read it from instruction
|
|
118
|
+
else:
|
|
119
|
+
vals = (value, sigma)
|
|
120
|
+
ex.values.append(extypes[r["rest_type"]].Value(*vals))
|
|
121
|
+
|
|
122
|
+
if r["rest_type"] == "dist":
|
|
123
|
+
if not (defs["dist_min_external"] < r["restr"]["value"] < defs["dist_max_external"]):
|
|
124
|
+
continue
|
|
125
|
+
if ex.atoms[0].serial > ex.atoms[1].serial:
|
|
126
|
+
ex.atoms = ex.atoms[::-1]
|
|
127
|
+
ex.alpha = r["restr"].get("alpha_in", defs["alpha_default"])
|
|
128
|
+
ex.type = r["restr"].get("itype_in", defs["type_default"])
|
|
129
|
+
symm1 = any([spec.get("symm") for spec in r["restr"]["specs"]]) # is it the intention?
|
|
130
|
+
if r["restr"].get("symm_in", defs["symall_block"]) or symm1:
|
|
131
|
+
asu = gemmi.Asu.Different if defs["exclude_self_block"] else gemmi.Asu.Any
|
|
132
|
+
im = st.cell.find_nearest_image(ex.atoms[0].pos, ex.atoms[1].pos, asu)
|
|
133
|
+
ex.set_image(im)
|
|
134
|
+
#print("dist=", ex.alpha, ex.type, ex.values[-1].value, ex.values[-1].sigma, ex.sym_idx, ex.pbc_shift, ex.atoms)
|
|
135
|
+
elif r["rest_type"] == "angl":
|
|
136
|
+
pass
|
|
137
|
+
#print("angl=", ex.values[-1].value, ex.values[-1].sigma, ex.atoms)
|
|
138
|
+
elif r["rest_type"] == "tors":
|
|
139
|
+
pass
|
|
140
|
+
#print("tors=", ex.values[-1].value, ex.values[-1].sigma, ex.atoms)
|
|
141
|
+
elif r["rest_type"] == "chir":
|
|
142
|
+
#print("chir=", ex.value, ex.sigma, ex.atoms)
|
|
143
|
+
ex.sign = gemmi.ChiralityType.Positive if ex.value > 0 else gemmi.ChiralityType.Negative
|
|
144
|
+
ex.value = abs(ex.value)
|
|
145
|
+
elif r["rest_type"] == "plan":
|
|
146
|
+
ex.sigma = r["restr"]["sigma_value"] / defs["scale_sigma_{}".format(r["rest_type"])]
|
|
147
|
+
#print("plan=", ex.sigma, ex.atoms)
|
|
148
|
+
elif r["rest_type"] == "inte":
|
|
149
|
+
dmin, dmax = r["restr"].get("dmin"), r["restr"].get("dmax")
|
|
150
|
+
smin, smax = r["restr"].get("smin"), r["restr"].get("smax")
|
|
151
|
+
if (smin,smax).count(None) == 2:
|
|
152
|
+
smin = smax = 0.05
|
|
153
|
+
else:
|
|
154
|
+
if smin is None: smin = smax
|
|
155
|
+
if smax is None: smax = smin
|
|
156
|
+
smin /= defs["scale_sigma_inte"]
|
|
157
|
+
smax /= defs["scale_sigma_inte"]
|
|
158
|
+
if (dmin,dmax).count(None) == 1:
|
|
159
|
+
if dmin is None: dmin = dmax
|
|
160
|
+
if dmax is None: dmax = dmin
|
|
161
|
+
ex.dmin = dmin
|
|
162
|
+
ex.dmax = dmax
|
|
163
|
+
ex.smin = smin
|
|
164
|
+
ex.smax = smax
|
|
165
|
+
#print("inte=", ex.dmin, ex.dmax, ex.smin, ex.smax, ex.atoms)
|
|
166
|
+
elif r["rest_type"] == "stac":
|
|
167
|
+
ex.dist = r["restr"]["dist_id"]
|
|
168
|
+
ex.sd_dist = r["restr"]["dist_sd"]
|
|
169
|
+
ex.angle = r["restr"].get("angle_id", 0.)
|
|
170
|
+
ex.sd_angle = r["restr"]["angle_sd"]
|
|
171
|
+
#print("stac=", ex.dist, ex.sd_dist, ex.angle, ex.sd_angle, ex.planes)
|
|
172
|
+
|
|
173
|
+
exlists[r["rest_type"]].append(ex)
|
|
174
|
+
|
|
175
|
+
logger.writeln("External restraints from Refmac instructions")
|
|
176
|
+
labs = dict(dist="distances", angl="angles", tors="torsions",
|
|
177
|
+
chir="chirals", plan="planes", inte="intervals",
|
|
178
|
+
stac="stackings", harm="harmonics", spec="special positions")
|
|
179
|
+
for lab in labs:
|
|
180
|
+
logger.writeln(" Number of {:18s} : {}".format(labs[lab], len(exlists[lab]) - num_org[lab]))
|
|
181
|
+
logger.writeln("")
|
|
182
|
+
# read_external_restraints()
|