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