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 selecting and deselecting spins."""
25
26
27 from warnings import warn
28
29
30 from generic_fns.mol_res_spin import exists_mol_res_spin_data, generate_spin_id_data_array, return_spin, spin_loop
31 from generic_fns import pipes
32 from relax_errors import RelaxError, RelaxNoSequenceError
33 from relax_io import read_spin_data
34 from relax_warnings import RelaxNoSpinWarning
35
36
53
54
55 -def desel_read(file=None, dir=None, file_data=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, boolean='AND', change_all=False):
56 """Deselect the spins contained in the given file.
57
58 @keyword file: The name of the file to open.
59 @type file: str
60 @keyword dir: The directory containing the file (defaults to the current
61 directory if None).
62 @type dir: str or None
63 @keyword file_data: An alternative opening a file, if the data already exists in the
64 correct format. The format is a list of lists where the first
65 index corresponds to the row and the second the column.
66 @type file_data: list of lists
67 @keyword spin_id_col: The column containing the spin ID strings. If supplied, the
68 mol_name_col, res_name_col, res_num_col, spin_name_col, and
69 spin_num_col arguments must be none.
70 @type spin_id_col: int or None
71 @keyword mol_name_col: The column containing the molecule name information. If
72 supplied, spin_id_col must be None.
73 @type mol_name_col: int or None
74 @keyword res_name_col: The column containing the residue name information. If
75 supplied, spin_id_col must be None.
76 @type res_name_col: int or None
77 @keyword res_num_col: The column containing the residue number information. If
78 supplied, spin_id_col must be None.
79 @type res_num_col: int or None
80 @keyword spin_name_col: The column containing the spin name information. If supplied,
81 spin_id_col must be None.
82 @type spin_name_col: int or None
83 @keyword spin_num_col: The column containing the spin number information. If supplied,
84 spin_id_col must be None.
85 @type spin_num_col: int or None
86 @keyword sep: The column separator which, if None, defaults to whitespace.
87 @type sep: str or None
88 @keyword spin_id: The spin ID string used to restrict data loading to a subset of
89 all spins.
90 @type spin_id: None or str
91 @param boolean: The boolean operator used to deselect the spin systems with. It
92 can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'.
93 This will be ignored if the change_all flag is set.
94 @type boolean: str
95 @keyword change_all: A flag which if True will cause all spins not specified in the
96 file to be selected. Only the boolean operator 'AND' is
97 compatible with this flag set to True (all others will be
98 ignored).
99 @type change_all: bool
100 @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists.
101 @raises RelaxError: If the boolean operator is unknown.
102 """
103
104
105 pipes.test()
106
107
108 if not exists_mol_res_spin_data():
109 raise RelaxNoSequenceError
110
111
112 if change_all:
113 for spin in spin_loop():
114 spin.select = True
115
116
117 for id in read_spin_data(file=file, dir=dir, file_data=file_data, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id):
118
119 spin = return_spin(id)
120
121
122 if spin == None:
123 warn(RelaxNoSpinWarning(id))
124 continue
125
126
127 if change_all:
128 spin.select = False
129
130
131 else:
132 if boolean == 'OR':
133 spin.select = spin.select or False
134 elif boolean == 'NOR':
135 spin.select = not (spin.select or False)
136 elif boolean == 'AND':
137 spin.select = spin.select and False
138 elif boolean == 'NAND':
139 spin.select = not (spin.select and False)
140 elif boolean == 'XOR':
141 spin.select = not (spin.select and False) and (spin.select or False)
142 elif boolean == 'XNOR':
143 spin.select = (spin.select and False) or not (spin.select or False)
144 else:
145 raise RelaxError("Unknown boolean operator " + repr(boolean))
146
147
148 -def desel_spin(spin_id=None, boolean='AND', change_all=False):
149 """Deselect specific spins.
150
151 @keyword spin_id: The spin identification string.
152 @type spin_id: str or None
153 @param boolean: The boolean operator used to deselect the spin systems with. It
154 can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'.
155 This will be ignored if the change_all flag is set.
156 @type boolean: str
157 @keyword change_all: A flag which if True will cause all spins not specified in the
158 file to be selected. Only the boolean operator 'AND' is
159 compatible with this flag set to True (all others will be
160 ignored).
161 @type change_all: bool
162 @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists.
163 @raises RelaxError: If the boolean operator is unknown.
164 """
165
166
167 pipes.test()
168
169
170 if not exists_mol_res_spin_data():
171 raise RelaxNoSequenceError
172
173
174 if change_all:
175 for spin in spin_loop():
176 spin.select = True
177
178
179 for spin in spin_loop(spin_id):
180
181 if change_all:
182 spin.select = False
183
184
185 else:
186 if boolean == 'OR':
187 spin.select = spin.select or False
188 elif boolean == 'NOR':
189 spin.select = not (spin.select or False)
190 elif boolean == 'AND':
191 spin.select = spin.select and False
192 elif boolean == 'NAND':
193 spin.select = not (spin.select and False)
194 elif boolean == 'XOR':
195 spin.select = not (spin.select and False) and (spin.select or False)
196 elif boolean == 'XNOR':
197 spin.select = (spin.select and False) or not (spin.select or False)
198 else:
199 raise RelaxError("Unknown boolean operator " + repr(boolean))
200
201
203 """Query if the molecule is selected.
204
205 @keyword selection: The molecule ID string.
206 @type selection: str
207 """
208
209
210 select = False
211 for spin in spin_loop(selection):
212 if spin.select:
213 select = True
214 break
215
216
217 return select
218
219
221 """Query if the residue is selected.
222
223 @keyword selection: The residue ID string.
224 @type selection: str
225 """
226
227
228 select = False
229 for spin in spin_loop(selection):
230 if spin.select:
231 select = True
232 break
233
234
235 return select
236
237
239 """Query if the spin is selected.
240
241 @keyword selection: The molecule ID string.
242 @type selection: str
243 """
244
245
246 spin = return_spin(selection)
247
248
249 return spin.select
250
251
274
275
292
293
294 -def sel_read(file=None, dir=None, file_data=None, spin_id_col=None, mol_name_col=None, res_num_col=None, res_name_col=None, spin_num_col=None, spin_name_col=None, sep=None, spin_id=None, boolean='OR', change_all=False):
295 """Select the spins contained in the given file.
296
297 @keyword file: The name of the file to open.
298 @type file: str
299 @keyword dir: The directory containing the file (defaults to the current
300 directory if None).
301 @type dir: str or None
302 @keyword file_data: An alternative opening a file, if the data already exists in the
303 correct format. The format is a list of lists where the first
304 index corresponds to the row and the second the column.
305 @type file_data: list of lists
306 @keyword spin_id_col: The column containing the spin ID strings. If supplied, the
307 mol_name_col, res_name_col, res_num_col, spin_name_col, and
308 spin_num_col arguments must be none.
309 @type spin_id_col: int or None
310 @keyword mol_name_col: The column containing the molecule name information. If
311 supplied, spin_id_col must be None.
312 @type mol_name_col: int or None
313 @keyword res_name_col: The column containing the residue name information. If
314 supplied, spin_id_col must be None.
315 @type res_name_col: int or None
316 @keyword res_num_col: The column containing the residue number information. If
317 supplied, spin_id_col must be None.
318 @type res_num_col: int or None
319 @keyword spin_name_col: The column containing the spin name information. If supplied,
320 spin_id_col must be None.
321 @type spin_name_col: int or None
322 @keyword spin_num_col: The column containing the spin number information. If supplied,
323 spin_id_col must be None.
324 @type spin_num_col: int or None
325 @keyword sep: The column separator which, if None, defaults to whitespace.
326 @type sep: str or None
327 @keyword spin_id: The spin ID string used to restrict data loading to a subset of
328 all spins.
329 @type spin_id: None or str
330 @param boolean: The boolean operator used to select the spin systems with. It
331 can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'.
332 This will be ignored if the change_all flag is set.
333 @type boolean: str
334 @keyword change_all: A flag which if True will cause all spins not specified in the
335 file to be deselected. Only the boolean operator 'OR' is
336 compatible with this flag set to True (all others will be
337 ignored).
338 @type change_all: bool
339 @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists.
340 @raises RelaxError: If the boolean operator is unknown.
341 """
342
343
344 pipes.test()
345
346
347 if not exists_mol_res_spin_data():
348 raise RelaxNoSequenceError
349
350
351 if change_all:
352
353 for spin in spin_loop():
354 spin.select = False
355
356
357 for id in read_spin_data(file=file, dir=dir, file_data=file_data, spin_id_col=spin_id_col, mol_name_col=mol_name_col, res_num_col=res_num_col, res_name_col=res_name_col, spin_num_col=spin_num_col, spin_name_col=spin_name_col, sep=sep, spin_id=spin_id):
358
359 spin = return_spin(id)
360
361
362 if spin == None:
363 warn(RelaxNoSpinWarning(id))
364 continue
365
366
367 if change_all:
368 spin.select = True
369
370
371 else:
372 if boolean == 'OR':
373 spin.select = spin.select or True
374 elif boolean == 'NOR':
375 spin.select = not (spin.select or True)
376 elif boolean == 'AND':
377 spin.select = spin.select and True
378 elif boolean == 'NAND':
379 spin.select = not (spin.select and True)
380 elif boolean == 'XOR':
381 spin.select = not (spin.select and True) and (spin.select or True)
382 elif boolean == 'XNOR':
383 spin.select = (spin.select and True) or not (spin.select or True)
384 else:
385 raise RelaxError("Unknown boolean operator " + repr(boolean))
386
387
388 -def sel_spin(spin_id=None, boolean='OR', change_all=False):
389 """Select specific spins.
390
391 @keyword spin_id: The spin identification string.
392 @type spin_id: str or None
393 @param boolean: The boolean operator used to select the spin systems with. It
394 can be one of 'OR', 'NOR', 'AND', 'NAND', 'XOR', or 'XNOR'.
395 This will be ignored if the change_all flag is set.
396 @type boolean: str
397 @keyword change_all: A flag which if True will cause all spins not specified in the
398 file to be deselected. Only the boolean operator 'OR' is
399 compatible with this flag set to True (all others will be
400 ignored).
401 @type change_all: bool
402 @raises RelaxNoSequenceError: If no molecule/residue/spins sequence data exists.
403 @raises RelaxError: If the boolean operator is unknown.
404 """
405
406
407 pipes.test()
408
409
410 if not exists_mol_res_spin_data():
411 raise RelaxNoSequenceError
412
413
414 if change_all:
415
416 for spin in spin_loop():
417 spin.select = False
418
419
420 for spin in spin_loop(spin_id):
421
422 if change_all:
423 spin.select = True
424
425
426 else:
427 if boolean == 'OR':
428 spin.select = spin.select or True
429 elif boolean == 'NOR':
430 spin.select = not (spin.select or True)
431 elif boolean == 'AND':
432 spin.select = spin.select and True
433 elif boolean == 'NAND':
434 spin.select = not (spin.select and True)
435 elif boolean == 'XOR':
436 spin.select = not (spin.select and True) and (spin.select or True)
437 elif boolean == 'XNOR':
438 spin.select = (spin.select and True) or not (spin.select or True)
439 else:
440 raise RelaxError("Unknown boolean operator " + repr(boolean))
441