1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from math import pi
24 from os import getcwd
25
26
27 from lib.errors import RelaxNoPdbError, RelaxNoSequenceError, RelaxNoVectorsError
28 from lib.io import get_file_path, open_write_file
29 from lib.structure.internal.object import Internal
30 from lib.structure.represent.rotor import rotor_pdb
31 from pipe_control import pipes
32 from pipe_control.interatomic import interatomic_loop
33 from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_spin
34 from pipe_control.structure.mass import pipe_centre_of_mass
35 from status import Status; status = Status()
36
37
38 -def create_rotor_pdb(file=None, dir=None, rotor_angle=None, axis=None, axis_pt=True, centre=None, span=2e-9, blade_length=5e-10, force=False, staggered=False):
39 """Create a PDB representation of a rotor motional model.
40
41 @keyword file: The name of the PDB file to create.
42 @type file: str
43 @keyword dir: The name of the directory to place the PDB file into.
44 @type dir: str
45 @keyword rotor_angle: The angle of the rotor motion in degrees.
46 @type rotor_angle: float
47 @keyword axis: The vector defining the rotor axis.
48 @type axis: numpy rank-1, 3D array
49 @keyword axis_pt: A point lying anywhere on the rotor axis. This is used to define the position of the axis in 3D space.
50 @type axis_pt: numpy rank-1, 3D array
51 @keyword centre: The central point of the representation. If this point is not on the rotor axis, then the closest point on the axis will be used for the centre.
52 @type centre: numpy rank-1, 3D array
53 @keyword span: The distance from the central point to the rotor blades (meters).
54 @type span: float
55 @keyword blade_length: The length of the representative rotor blades.
56 @type blade_length: float
57 @keyword force: A flag which if set will overwrite any pre-existing file.
58 @type force: bool
59 @keyword staggered: A flag which if True will cause the rotor blades to be staggered. This is used to avoid blade overlap.
60 @type staggered: bool
61 """
62
63
64 pipes.test()
65
66
67 rotor_angle = rotor_angle / 360.0 * 2.0 * pi
68
69
70 structure = Internal()
71
72
73 rotor_pdb(structure=structure, rotor_angle=rotor_angle, axis=axis, axis_pt=axis_pt, centre=centre, span=span, blade_length=blade_length, staggered=staggered)
74
75
76 print("\nGenerating the PDB file.")
77
78
79 tensor_pdb_file = open_write_file(file, dir, force=force)
80
81
82 structure.write_pdb(tensor_pdb_file)
83
84
85 tensor_pdb_file.close()
86
87
88 if not hasattr(cdp, 'result_files'):
89 cdp.result_files = []
90 if dir == None:
91 dir = getcwd()
92 cdp.result_files.append(['rotor_pdb', 'Rotor PDB', get_file_path(file, dir)])
93 status.observers.result_file.notify()
94
95
97 """Create a PDB representation of the vector distribution.
98
99 @keyword length: The length to set the vectors to in the PDB file.
100 @type length: float
101 @keyword symmetry: The symmetry flag which if set will create a second PDB chain 'B' which is the same as chain 'A' but with the vectors reversed.
102 @type symmetry: bool
103 @keyword file: The name of the PDB file to create.
104 @type file: str
105 @keyword dir: The name of the directory to place the PDB file into.
106 @type dir: str
107 @keyword force: Flag which if set will overwrite any pre-existing file.
108 @type force: bool
109 """
110
111
112 pipes.test()
113
114
115 if not hasattr(cdp, 'structure') or not cdp.structure.num_models() > 0:
116 raise RelaxNoPdbError
117
118
119 if not exists_mol_res_spin_data():
120 raise RelaxNoSequenceError
121
122
123 vectors = False
124 for interatom in interatomic_loop():
125 if hasattr(interatom, 'vector'):
126 vectors = True
127 break
128 if not vectors:
129 raise RelaxNoVectorsError
130
131
132
133
134
135
136 structure = Internal()
137
138
139 structure.add_molecule(name='vector_dist')
140
141
142 mol = structure.structural_data[0].mol[0]
143
144
145 res_num = 1
146 atom_num = 1
147
148
149
150
151
152
153 R = pipe_centre_of_mass()
154
155
156 res_num = res_num + 1
157
158
159
160
161
162
163 for interatom in interatomic_loop():
164
165 spin1 = return_spin(interatom.spin_id1)
166 spin2 = return_spin(interatom.spin_id2)
167
168
169 if not spin1.select or not spin2.select:
170 continue
171
172
173 if not hasattr(interatom, 'vector'):
174 continue
175
176
177 vector = interatom.vector * length * 1e10
178
179
180 mol.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin1.name, res_name=spin1._res_name, chain_id='A', res_num=spin1._res_num, pos=R, segment_id=None, element=spin1.element)
181
182
183 mol.atom_add(pdb_record='ATOM', atom_num=atom_num+1, atom_name=spin2.name, res_name=spin2._res_name, chain_id='A', res_num=spin2._res_num, pos=R+vector, segment_id=None, element=spin2.element)
184
185
186 mol.atom_connect(index1=atom_num-1, index2=atom_num)
187
188
189 atom_num = atom_num + 2
190
191
192 if symmetry:
193
194 for interatom in interatomic_loop():
195
196 spin1 = return_spin(interatom.spin_id1)
197 spin2 = return_spin(interatom.spin_id2)
198
199
200 if not spin1.select or not spin2.select:
201 continue
202
203
204 if not hasattr(interatom, 'vector'):
205 continue
206
207
208 vector = interatom.vector * length * 1e10
209
210
211 mol.atom_add(pdb_record='ATOM', atom_num=atom_num, atom_name=spin1.name, res_name=spin1._res_name, chain_id='B', res_num=spin1._res_num, pos=R, segment_id=None, element=spin1.element)
212
213
214 mol.atom_add(pdb_record='ATOM', atom_num=atom_num+1, atom_name=spin2.name, res_name=spin2._res_name, chain_id='B', res_num=spin2._res_num, pos=R-vector, segment_id=None, element=spin2.element)
215
216
217 mol.atom_connect(index1=atom_num-1, index2=atom_num)
218
219
220 atom_num = atom_num + 2
221
222
223
224
225
226
227 print("\nGenerating the PDB file.")
228
229
230 tensor_pdb_file = open_write_file(file, dir, force=force)
231
232
233 structure.write_pdb(tensor_pdb_file)
234
235
236 tensor_pdb_file.close()
237
238
239 if not hasattr(cdp, 'result_files'):
240 cdp.result_files = []
241 if dir == None:
242 dir = getcwd()
243 cdp.result_files.append(['vector_dist_pdb', 'Vector distribution PDB', get_file_path(file, dir)])
244 status.observers.result_file.notify()
245