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