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 containing the 'select' user function class."""
25 __docformat__ = 'plaintext'
26
27
28 from base_class import User_fn_class, _build_doc
29 import arg_check
30 from generic_fns import selection
31
32
33 boolean_doc = ["Boolean operators", """
34 The boolean operator can be used to change how spin systems are selected. The allowed values are: 'OR', 'NOR', 'AND', 'NAND', 'XOR', 'XNOR'. The following table details how the selections will occur for the different boolean operators.
35 __________________________________________________________
36 | | | | | | | | | | |
37 | Spin system | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
38 |____________________|___|___|___|___|___|___|___|___|___|
39 | | | | | | | | | | |
40 | Original selection | 0 | 1 | 1 | 1 | 1 | 0 | 1 | 0 | 1 |
41 | | | | | | | | | | |
42 | New selection | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 |
43 | | | | | | | | | | |
44 | OR | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 1 |
45 | | | | | | | | | | |
46 | NOR | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
47 | | | | | | | | | | |
48 | AND | 0 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
49 | | | | | | | | | | |
50 | NAND | 1 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 |
51 | | | | | | | | | | |
52 | XOR | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
53 | | | | | | | | | | |
54 | XNOR | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 0 |
55 |____________________|___|___|___|___|___|___|___|___|___|
56 """, """
57 The boolean operator can be used to change how spin systems are selected. The allowed values are: 'OR', 'NOR', 'AND', 'NAND', 'XOR', 'XNOR'. The following details how the selections will occur for the different boolean operators:
58
59 Spin system: 1 2 3 4 5 6 7 8 9
60 Original selection: 0 1 1 1 1 0 1 0 1
61 New selection: 0 1 1 1 1 1 0 0 0
62 OR: 0 1 1 1 1 1 1 0 1
63 NOR: 1 0 0 0 0 0 0 1 0
64 AND: 0 1 1 1 1 0 0 0 0
65 NAND: 1 0 0 0 0 1 1 1 1
66 XOR: 0 0 0 0 0 1 1 0 1
67 XNOR: 1 1 1 1 1 0 0 1 0
68 """
69 ]
70
71
73 """Class for selecting spins."""
74
76
77 if self._exec_info.intro:
78 text = self._exec_info.ps3 + "select.all()"
79 print(text)
80
81
82 selection.sel_all()
83
84
85 all._doc_title = "Select all spins."
86 all._doc_desc = """
87 This will select all spins, irregardless of their current state.
88 """
89 all._doc_examples = """
90 To select all spins, simply type:
91
92 relax> select.all()
93 """
94 _build_doc(all)
95
96
97 - def read(self, file=None, dir=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):
98
99 if self._exec_info.intro:
100 text = self._exec_info.ps3 + "select.read("
101 text = text + "file=" + repr(file)
102 text = text + ", dir=" + repr(dir)
103 text = text + ", spin_id_col=" + repr(spin_id_col)
104 text = text + ", mol_name_col=" + repr(mol_name_col)
105 text = text + ", res_num_col=" + repr(res_num_col)
106 text = text + ", res_name_col=" + repr(res_name_col)
107 text = text + ", spin_num_col=" + repr(spin_num_col)
108 text = text + ", spin_name_col=" + repr(spin_name_col)
109 text = text + ", sep=" + repr(sep)
110 text = text + ", spin_id=" + repr(spin_id)
111 text = text + ", boolean=" + repr(boolean)
112 text = text + ", change_all=" + repr(change_all) + ")"
113 print(text)
114
115
116 arg_check.is_str_or_inst(file, 'file name')
117 arg_check.is_str(dir, 'directory name', can_be_none=True)
118 arg_check.is_int(spin_id_col, 'spin ID string column', can_be_none=True)
119 arg_check.is_int(mol_name_col, 'molecule name column', can_be_none=True)
120 arg_check.is_int(res_num_col, 'residue number column', can_be_none=True)
121 arg_check.is_int(res_name_col, 'residue name column', can_be_none=True)
122 arg_check.is_int(spin_num_col, 'spin number column', can_be_none=True)
123 arg_check.is_int(spin_name_col, 'spin name column', can_be_none=True)
124 arg_check.is_str(sep, 'column separator', can_be_none=True)
125 arg_check.is_str(spin_id, 'spin ID string', can_be_none=True)
126 arg_check.is_str(boolean, 'boolean operator')
127 arg_check.is_bool(change_all, 'change all')
128
129
130 selection.sel_read(file=file, dir=dir, 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, boolean=boolean, change_all=change_all)
131
132
133 read._doc_title = "Select the spins contained in a file."
134 read._doc_title_short = "Selecting spins from file."
135 read._doc_args = [
136 ["file", "The name of the file containing the list of spins to select."],
137 ["dir", "The directory where the file is located."],
138 ["spin_id_col", "The spin ID string column (an alternative to the mol, res, and spin name and number columns)."],
139 ["mol_name_col", "The molecule name column (alternative to the spin_id_col)."],
140 ["res_num_col", "The residue number column (alternative to the spin_id_col)."],
141 ["res_name_col", "The residue name column (alternative to the spin_id_col)."],
142 ["spin_num_col", "The spin number column (alternative to the spin_id_col)."],
143 ["spin_name_col", "The spin name column (alternative to the spin_id_col)."],
144 ["data_col", "The RDC data column."],
145 ["error_col", "The experimental error column."],
146 ["sep", "The column separator (the default is white space)."],
147 ["spin_id", "The spin ID string to restrict the loading of data to certain spin subsets."],
148 ["boolean", "The boolean operator specifying how spins should be selected."],
149 ["change_all", "A flag specifying if all other spins should be changed."]
150 ]
151 read._doc_desc = """
152 The spin system can be identified in the file using two different formats. The first is the spin ID string column which can include the molecule name, the residue name and number, and the spin name and number. Alternatively the molecule name, residue number, residue name, spin number and/or spin name columns can be supplied allowing this information to be in separate columns. Note that the numbering of columns starts at one. The spin ID string can be used to restrict the reading to certain spin types, for example only 15N spins when only residue information is in the file.
153
154 Empty lines and lines beginning with a hash are ignored.
155
156 The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way. Setting this to True will cause all spins not specified in the file to be deselected.
157 """
158 read._doc_examples = """
159 To select all residues listed with residue numbers in the first column of the file
160 'isolated_peaks', type one of:
161
162 relax> select.read('isolated_peaks', res_num_col=1)
163 relax> select.read(file='isolated_peaks', res_num_col=1)
164
165 To select the spins in the second column of the relaxation data file 'r1.600' while
166 deselecting all other spins, for example type:
167
168 relax> select.read('r1.600', spin_num_col=2, change_all=True)
169 relax> select.read(file='r1.600', spin_num_col=2, change_all=True)
170 """
171 read._doc_additional = [boolean_doc]
172 _build_doc(read)
173
174
176
177 if self._exec_info.intro:
178 text = self._exec_info.ps3 + "select.reverse("
179 text = text + "spin_id=" + repr(spin_id) + ")"
180 print(text)
181
182
183 arg_check.is_str(spin_id, 'spin ID string', can_be_none=True)
184
185
186 selection.reverse(spin_id=spin_id)
187
188
189 reverse._doc_title = "Reversal of the spin selection for the given spins."
190 reverse._doc_title_short = "Spin selection reversal."
191 reverse._doc_args = [
192 ["spin_id", "The spin ID string."]
193 ]
194 reverse._doc_desc = """
195 By supplying the spin ID string, a subset of spins can have their selection status reversed.
196 """
197 reverse._doc_examples = """
198 To select all currently deselected spins and deselect those which are selected type:
199
200 relax> select.reverse()
201 """
202 _build_doc(reverse)
203
204
205 - def spin(self, spin_id=None, boolean='OR', change_all=False):
206
207 if self._exec_info.intro:
208 text = self._exec_info.ps3 + "select.spin("
209 text = text + "spin_id=" + repr(spin_id)
210 text = text + ", boolean=" + repr(boolean)
211 text = text + ", change_all=" + repr(change_all) + ")"
212 print(text)
213
214
215 arg_check.is_str(spin_id, 'spin ID string', can_be_none=True)
216 arg_check.is_str(boolean, 'boolean operator')
217 arg_check.is_bool(change_all, 'change all')
218
219
220 selection.sel_spin(spin_id=spin_id, boolean=boolean, change_all=change_all)
221
222
223 spin._doc_title = "Select specific spins."
224 spin._doc_args = [
225 ["spin_id", "The spin ID string."],
226 ["boolean", "The boolean operator specifying how spins should be selected."],
227 ["change_all", "A flag specifying if all other spins should be changed."]
228 ]
229 spin._doc_desc = """
230 The 'change all' flag default is False meaning that all spins currently either selected or deselected will remain that way. Setting this to True will cause all spins not specified by the spin ID string to be selected.
231 """
232 spin._doc_examples = """
233 To select only glycines and alanines, assuming they have been loaded with the names GLY and
234 ALA, type one of:
235
236 relax> select.spin(spin_id=':GLY|:ALA')
237
238 To select residue 5 CYS in addition to the currently selected residues, type one of:
239
240 relax> select.spin(':5')
241 relax> select.spin(':5&:CYS')
242 relax> select.spin(spin_id=':5&:CYS')
243 """
244 spin._doc_additional = [boolean_doc]
245 _build_doc(spin)
246