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