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