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 pos != None and not force and hasattr(cdp, 'paramagnetic_centre'):
69 raise RelaxError("The paramagnetic centre has already been set to the coordinates " + repr(cdp.paramagnetic_centre) + ".")
70
71
72 if fix:
73 print("The paramagnetic centre position will be fixed during optimisation.")
74 else:
75 print("The paramagnetic centre position will be optimised.")
76 cdp.paramag_centre_fixed = fix
77
78
79 if pos != None:
80 centre = array(pos)
81 num_pos = 1
82 full_pos_list = []
83
84
85 elif atom_id:
86
87 centre = zeros(3, float64)
88 full_pos_list = []
89 num_pos = 0
90 for spin, spin_id in spin_loop(atom_id, pipe=pipe, return_id=True):
91
92 if not hasattr(spin, 'pos'):
93 continue
94
95
96 if isinstance(spin.pos[0], float) or isinstance(spin.pos[0], float64):
97 pos_list = [spin.pos]
98 else:
99 pos_list = spin.pos
100
101
102 for pos in pos_list:
103 full_pos_list.append(pos)
104 centre = centre + array(pos)
105 num_pos = num_pos + 1
106
107
108 if not num_pos:
109 raise RelaxError("No positional information could be found for the spin '%s'." % atom_id)
110
111
112 else:
113 return
114
115
116 centre = centre / float(num_pos)
117
118
119 if verbosity:
120 print("Paramagnetic centres located at:")
121 for pos in full_pos_list:
122 print(" [%8.3f, %8.3f, %8.3f]" % (pos[0], pos[1], pos[2]))
123 print("\nAverage paramagnetic centre located at:")
124 print(" [%8.3f, %8.3f, %8.3f]" % (centre[0], centre[1], centre[2]))
125
126
127 if ave_pos:
128 if verbosity:
129 print("\nUsing the average paramagnetic position.")
130 cdp.paramagnetic_centre = centre
131 else:
132 if verbosity:
133 print("\nUsing all paramagnetic positions.")
134 cdp.paramagnetic_centre = full_pos_list
135