1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for the manipulation of paramagnetic data."""
24
25
26 from numpy import array, float64, zeros
27
28
29 from lib.errors import RelaxError
30 from pipe_control import pipes
31 from pipe_control.pipes import check_pipe
32 from pipe_control.mol_res_spin import spin_loop
33
34
35 -def centre(pos=None, atom_id=None, pipe=None, verbosity=1, fix=True, ave_pos=False, force=False):
36 """Specify the atom in the loaded structure corresponding to the paramagnetic centre.
37
38 @keyword pos: The atomic position. If set, the atom_id string will be ignored.
39 @type pos: list of float
40 @keyword atom_id: The atom identification string.
41 @type atom_id: str
42 @keyword pipe: An alternative data pipe to extract the paramagnetic centre from.
43 @type pipe: None or str
44 @keyword verbosity: The amount of information to print out. The bigger the number, the more information.
45 @type verbosity: int
46 @keyword fix: A flag which if False causes the paramagnetic centre to be optimised during minimisation.
47 @type fix: bool
48 @keyword ave_pos: A flag which if True causes the atomic positions from multiple models to be averaged.
49 @type ave_pos: bool
50 @keyword force: A flag which if True will cause the current paramagnetic centre to be overwritten.
51 @type force: bool
52 """
53
54
55 if pipe == None:
56 pipe = pipes.cdp_name()
57
58
59 check_pipe(pipe)
60
61
62 source_dp = pipes.get_pipe(pipe)
63
64
65 if pos != None and not force and hasattr(cdp, 'paramagnetic_centre'):
66 raise RelaxError("The paramagnetic centre has already been set to the coordinates " + repr(cdp.paramagnetic_centre) + ".")
67
68
69 if fix:
70 print("The paramagnetic centre position will be fixed during optimisation.")
71 else:
72 print("The paramagnetic centre position will be optimised.")
73 cdp.paramag_centre_fixed = fix
74
75
76 if pos != None:
77 centre = array(pos)
78 num_pos = 1
79 full_pos_list = []
80
81
82 elif atom_id:
83
84 centre = zeros(3, float64)
85 full_pos_list = []
86 num_pos = 0
87 for spin, spin_id in spin_loop(atom_id, pipe=pipe, return_id=True):
88
89 if not hasattr(spin, 'pos'):
90 continue
91
92
93 if isinstance(spin.pos[0], float) or isinstance(spin.pos[0], float64):
94 pos_list = [spin.pos]
95 else:
96 pos_list = spin.pos
97
98
99 for pos in pos_list:
100 full_pos_list.append(pos)
101 centre = centre + array(pos)
102 num_pos = num_pos + 1
103
104
105 if not num_pos:
106 raise RelaxError("No positional information could be found for the spin '%s'." % atom_id)
107
108
109 else:
110 return
111
112
113 centre = centre / float(num_pos)
114
115
116 if verbosity:
117 print("Paramagnetic centres located at:")
118 for pos in full_pos_list:
119 print(" [%8.3f, %8.3f, %8.3f]" % (pos[0], pos[1], pos[2]))
120 print("\nAverage paramagnetic centre located at:")
121 print(" [%8.3f, %8.3f, %8.3f]" % (centre[0], centre[1], centre[2]))
122
123
124 if ave_pos:
125 if verbosity:
126 print("\nUsing the average paramagnetic position.")
127 cdp.paramagnetic_centre = centre
128 else:
129 if verbosity:
130 print("\nUsing all paramagnetic positions.")
131 cdp.paramagnetic_centre = full_pos_list
132