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