servalcat 0.4.99__cp38-cp38-macosx_10_14_x86_64.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.

Files changed (45) hide show
  1. servalcat/__init__.py +10 -0
  2. servalcat/__main__.py +120 -0
  3. servalcat/ext.cpython-38-darwin.so +0 -0
  4. servalcat/refine/__init__.py +0 -0
  5. servalcat/refine/cgsolve.py +100 -0
  6. servalcat/refine/refine.py +906 -0
  7. servalcat/refine/refine_geom.py +233 -0
  8. servalcat/refine/refine_spa.py +366 -0
  9. servalcat/refine/refine_xtal.py +281 -0
  10. servalcat/refine/spa.py +144 -0
  11. servalcat/refine/xtal.py +276 -0
  12. servalcat/refmac/__init__.py +0 -0
  13. servalcat/refmac/exte.py +182 -0
  14. servalcat/refmac/refmac_keywords.py +639 -0
  15. servalcat/refmac/refmac_wrapper.py +395 -0
  16. servalcat/spa/__init__.py +0 -0
  17. servalcat/spa/fofc.py +479 -0
  18. servalcat/spa/fsc.py +385 -0
  19. servalcat/spa/localcc.py +188 -0
  20. servalcat/spa/realspcc_from_var.py +128 -0
  21. servalcat/spa/run_refmac.py +977 -0
  22. servalcat/spa/shift_maps.py +293 -0
  23. servalcat/spa/shiftback.py +137 -0
  24. servalcat/spa/translate.py +129 -0
  25. servalcat/utils/__init__.py +35 -0
  26. servalcat/utils/commands.py +1547 -0
  27. servalcat/utils/fileio.py +744 -0
  28. servalcat/utils/generate_operators.py +296 -0
  29. servalcat/utils/hkl.py +714 -0
  30. servalcat/utils/logger.py +140 -0
  31. servalcat/utils/maps.py +345 -0
  32. servalcat/utils/model.py +782 -0
  33. servalcat/utils/refmac.py +760 -0
  34. servalcat/utils/restraints.py +781 -0
  35. servalcat/utils/symmetry.py +295 -0
  36. servalcat/xtal/__init__.py +0 -0
  37. servalcat/xtal/french_wilson.py +258 -0
  38. servalcat/xtal/run_refmac_small.py +240 -0
  39. servalcat/xtal/sigmaa.py +1644 -0
  40. servalcat/xtal/twin.py +121 -0
  41. servalcat-0.4.99.dist-info/METADATA +55 -0
  42. servalcat-0.4.99.dist-info/RECORD +45 -0
  43. servalcat-0.4.99.dist-info/WHEEL +5 -0
  44. servalcat-0.4.99.dist-info/entry_points.txt +4 -0
  45. servalcat-0.4.99.dist-info/licenses/LICENSE +373 -0
servalcat/__init__.py ADDED
@@ -0,0 +1,10 @@
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
+
9
+ __version__ = '0.4.99'
10
+ __date__ = '2024-12-04'
servalcat/__main__.py ADDED
@@ -0,0 +1,120 @@
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 argparse
10
+ import sys
11
+ import traceback
12
+ import platform
13
+ import gemmi
14
+ import numpy
15
+ import scipy
16
+ import pandas
17
+ import servalcat.spa.shiftback
18
+ import servalcat.spa.run_refmac
19
+ import servalcat.spa.fsc
20
+ import servalcat.spa.fofc
21
+ import servalcat.spa.shift_maps
22
+ import servalcat.spa.translate
23
+ import servalcat.spa.localcc
24
+ import servalcat.xtal.run_refmac_small
25
+ import servalcat.xtal.sigmaa
26
+ import servalcat.refmac.refmac_wrapper
27
+ import servalcat.xtal.french_wilson
28
+ import servalcat.utils.commands
29
+ import servalcat.refine.refine_geom
30
+ import servalcat.refine.refine_spa
31
+ import servalcat.refine.refine_xtal
32
+
33
+ from servalcat.utils import logger
34
+
35
+ def test_installation():
36
+ import packaging.version
37
+ vers = logger.dependency_versions()
38
+ pandas_ver = packaging.version.parse(vers["pandas"])
39
+ numpy_ver = packaging.version.parse(vers["numpy"])
40
+ msg_unknown = "Unexpected error occurred (related to numpy+pandas). Please report to authors with the result of servalcat -v."
41
+ msg_skip = "If you want to ignore this error, please specify --skip_test."
42
+ ret = True
43
+
44
+ try:
45
+ x = pandas.DataFrame(dict(x=[2j]))
46
+ x.merge(x)
47
+ except TypeError:
48
+ ret = False
49
+ if pandas_ver >= packaging.version.parse("1.3.0") and numpy_ver < packaging.version.parse("1.19.1"):
50
+ print("There is a problem in pandas+numpy. Please update numpy to 1.19.1 or newer (or use pandas < 1.3.0).")
51
+ else:
52
+ print(traceback.format_exc())
53
+ print(msg_unknown)
54
+ except:
55
+ print(traceback.format_exc())
56
+ print(msg_unknown)
57
+ ret = False
58
+
59
+ if not ret:
60
+ print(msg_skip)
61
+
62
+ return ret
63
+ # test_installation()
64
+
65
+ def main():
66
+ parser = argparse.ArgumentParser(prog="servalcat",
67
+ description="A tool for model refinement and map calculation for crystallography and cryo-EM SPA.")
68
+ parser.add_argument("--skip_test", action="store_true", help="Skip installation test")
69
+ parser.add_argument("-v", "--version", action="version",
70
+ version=logger.versions_str())
71
+ parser.add_argument("--logfile", default="servalcat.log")
72
+ subparsers = parser.add_subparsers(dest="command")
73
+
74
+ modules = dict(shiftback=servalcat.spa.shiftback,
75
+ refine_spa=servalcat.spa.run_refmac,
76
+ refine_cx=servalcat.xtal.run_refmac_small,
77
+ fsc=servalcat.spa.fsc,
78
+ fofc=servalcat.spa.fofc,
79
+ trim=servalcat.spa.shift_maps,
80
+ translate=servalcat.spa.translate,
81
+ localcc=servalcat.spa.localcc,
82
+ sigmaa=servalcat.xtal.sigmaa,
83
+ fw=servalcat.xtal.french_wilson,
84
+ #show=servalcat.utils.show,
85
+ util=servalcat.utils.commands,
86
+ refmac5=servalcat.refmac.refmac_wrapper,
87
+ refine_geom=servalcat.refine.refine_geom,
88
+ refine_spa_norefmac=servalcat.refine.refine_spa,
89
+ refine_xtal_norefmac=servalcat.refine.refine_xtal,
90
+ )
91
+
92
+ for n in modules:
93
+ p = subparsers.add_parser(n)
94
+ modules[n].add_arguments(p)
95
+
96
+ args = parser.parse_args()
97
+
98
+ if not args.skip_test and not test_installation():
99
+ return
100
+
101
+ if args.command == "util" and not args.subcommand:
102
+ print("specify subcommand.")
103
+ elif args.command in modules:
104
+ logger.set_file(args.logfile)
105
+ logger.write_header()
106
+ try:
107
+ modules[args.command].main(args)
108
+ except SystemExit as e:
109
+ logger.error(str(e))
110
+ sys.exit(1)
111
+ logger.exit_success()
112
+ logger.close()
113
+ else:
114
+ parser.print_help()
115
+
116
+ # main()
117
+
118
+ if __name__ == "__main__":
119
+ main()
120
+
Binary file
File without changes
@@ -0,0 +1,100 @@
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
+ from servalcat.utils import logger
10
+ import numpy
11
+
12
+ def cgsolve_rm(A, v, M, gamma=0., ncycl=2000, toler=1.e-4):
13
+ gamma_save = None
14
+ step_flag = False
15
+ gamma_flag = False
16
+ conver_flag = False
17
+ #f = numpy.zeros(len(v))
18
+ dv = numpy.zeros(len(v))
19
+ dv_save = numpy.zeros(len(v))
20
+
21
+ # preconditioning
22
+ A = M.T.dot(A).dot(M)
23
+ #print("precond_A=")
24
+ #print(A.toarray())
25
+ v = M.T.dot(v)
26
+
27
+ vnorm = numpy.sqrt(numpy.dot(v, v))
28
+ test_lim = toler * vnorm
29
+ max_gamma_cyc = 500
30
+ step = 0.05
31
+
32
+ for gamma_cyc in range(max_gamma_cyc):
33
+ if gamma_cyc != 0: gamma += step
34
+
35
+ logger.writeln("Trying gamma equal {:.4e}".format(gamma))
36
+ r = v - (A.dot(dv) + gamma * dv)
37
+ rho = [numpy.dot(r, r)]
38
+ if rho[0] < toler:
39
+ break
40
+
41
+ exit_flag = False
42
+ for itr in range(ncycl):
43
+ if itr == 0:
44
+ p = r
45
+ beta = 0.
46
+ else:
47
+ beta = rho[-1] / rho[-2]
48
+ p = r + beta * p
49
+
50
+ f = A.dot(p) + gamma * p
51
+ alpha = rho[-1] / numpy.dot(p, f)
52
+ dv += alpha * p
53
+ if itr%20 == 0:
54
+ r = v - (A.dot(dv) + gamma * dv)
55
+ else:
56
+ r = r - alpha * f
57
+
58
+ rho.append(numpy.dot(r, r))
59
+ #print("rho=", rho)
60
+ if numpy.sqrt(rho[-1]) > 2 * numpy.sqrt(rho[-2]):
61
+ logger.writeln("Not converging with gamma equal {:.4e}".format(gamma))
62
+ step *= 1.05
63
+ break
64
+
65
+ if numpy.sqrt(rho[-1]) < test_lim:
66
+ if not gamma_flag:
67
+ logger.writeln("Convergence reached with no gamma cycles")
68
+ exit_flag = True
69
+ break # goto 120
70
+ elif conver_flag:
71
+ logger.writeln("Convergence reached with gamma equal {:.4e}".format(gamma))
72
+ step *= 1.01
73
+ exit_flag = True
74
+ break # goto 120
75
+ else:
76
+ conver_flag = True
77
+ step_flag = True
78
+ gamma_save = gamma
79
+ dv_save = numpy.copy(dv)
80
+ gamma = max(0, gamma - step/5.)
81
+ step = max(step/1.1, 0.0001)
82
+ logger.writeln("Gamma decreased to {:.4e}".format(gamma))
83
+ exit_flag = True
84
+ break
85
+ # end of inner loop
86
+ if exit_flag: break
87
+
88
+ gamma_flag = True
89
+ if not conver_flag:
90
+ dv[:] = 0.
91
+ else:
92
+ dv = numpy.copy(dv_save)
93
+ gamma = gamma_save
94
+ logger.writeln("Back to gamma equal {:.4e}".format(gamma))
95
+
96
+
97
+ # postconditioning
98
+ dv = M.dot(dv)
99
+ return dv, gamma
100
+ # cgsolve_rm()