Trees | Indices | Help |
|
---|
|
1 ############################################################################### 2 # # 3 # Copyright (C) 2003, 2004 Edward d'Auvergne # 4 # # 5 # This file is part of the program relax. # 6 # # 7 # relax is free software; you can redistribute it and/or modify # 8 # it under the terms of the GNU General Public License as published by # 9 # the Free Software Foundation; either version 2 of the License, or # 10 # (at your option) any later version. # 11 # # 12 # relax is distributed in the hope that it will be useful, # 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of # 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # 15 # GNU General Public License for more details. # 16 # # 17 # You should have received a copy of the GNU General Public License # 18 # along with relax; if not, write to the Free Software # 19 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # 20 # # 21 ############################################################################### 22 23 from os import F_OK, access 24 from re import compile, match 25 2633429 """Base class containing functions for the manipulation of residue selection.""" 30 31 self.relax = relax32 3335 """Function for the reversal of residue selection.""" 36 37 # Create the list of runs. 38 self.runs = self.relax.generic.runs.list_of_runs(run) 39 40 # Loop over the runs. 41 for self.run in self.runs: 42 # Test if the run exists. 43 if not self.run in self.relax.data.run_names: 44 raise RelaxNoRunError, self.run 45 46 # Test if sequence data is loaded. 47 if not len(self.relax.data.res[self.run]): 48 raise RelaxNoSequenceError, self.run 49 50 # Loop over the sequence and reverse the selection flag. 51 for i in xrange(len(self.relax.data.res[self.run])): 52 # Remap the data structure 'self.relax.data.res[self.run][i]'. 53 data = self.relax.data.res[self.run][i] 54 55 # Reverse the selection. 56 if data.select: 57 data.select = 0 58 else: 59 data.select = 160 6163 """Function for selecting all residues.""" 64 65 # Create the list of runs. 66 self.runs = self.relax.generic.runs.list_of_runs(run) 67 68 # Loop over the runs. 69 for self.run in self.runs: 70 # Test if the run exists. 71 if not self.run in self.relax.data.run_names: 72 raise RelaxNoRunError, self.run 73 74 # Test if sequence data is loaded. 75 if not len(self.relax.data.res[self.run]): 76 raise RelaxNoSequenceError, self.run 77 78 # Loop over the sequence and set the selection flag to 1. 79 for i in xrange(len(self.relax.data.res[self.run])): 80 self.relax.data.res[self.run][i].select = 181 8284 """Function for selecting the residues contained in a file.""" 85 86 # Extract the data from the file. 87 file_data = self.relax.IO.extract_data(file, dir) 88 89 # Strip the data. 90 file_data = self.relax.IO.strip(file_data) 91 92 # Create the list of residues to select. 93 select = [] 94 for i in xrange(len(file_data)): 95 try: 96 select.append(int(file_data[i][0])) 97 except: 98 raise RelaxError, "Improperly formatted file." 99 100 # Create the list of runs. 101 self.runs = self.relax.generic.runs.list_of_runs(run) 102 103 # Loop over the runs. 104 no_match = 1 105 for self.run in self.runs: 106 # Test if the run exists. 107 if not self.run in self.relax.data.run_names: 108 raise RelaxNoRunError, self.run 109 110 # Test if sequence data is loaded. 111 if not len(self.relax.data.res[self.run]): 112 raise RelaxNoSequenceError, self.run 113 114 # Loop over the sequence. 115 for i in xrange(len(self.relax.data.res[self.run])): 116 # Remap the data structure 'self.relax.data.res[self.run][i]'. 117 data = self.relax.data.res[self.run][i] 118 119 # Unselect all residues. 120 if change_all: 121 data.select = 0 122 123 # Select the residue if it is in the list select. 124 if data.num in select: 125 data.select = 1 126 127 # Match flag. 128 no_match = 0 129 130 # No residue matched. 131 if no_match: 132 print "No residues match."133 134136 """Function for selecting specific residues.""" 137 138 # Test if the residue number is a valid regular expression. 139 if type(num) == str: 140 try: 141 compile(num) 142 except: 143 raise RelaxRegExpError, ('residue number', num) 144 145 # Test if the residue name is a valid regular expression. 146 if name: 147 try: 148 compile(name) 149 except: 150 raise RelaxRegExpError, ('residue name', name) 151 152 # Create the list of runs. 153 self.runs = self.relax.generic.runs.list_of_runs(run) 154 155 # Loop over the runs. 156 no_match = 1 157 for self.run in self.runs: 158 # Test if the run exists. 159 if not self.run in self.relax.data.run_names: 160 raise RelaxNoRunError, self.run 161 162 # Test if sequence data is loaded. 163 if not len(self.relax.data.res[self.run]): 164 raise RelaxNoSequenceError, self.run 165 166 # Loop over the sequence. 167 for i in xrange(len(self.relax.data.res[self.run])): 168 # Remap the data structure 'self.relax.data.res[self.run][i]'. 169 data = self.relax.data.res[self.run][i] 170 171 # Unselect all residues. 172 if change_all: 173 data.select = 0 174 175 # Skip the residue if there is no match to 'num'. 176 if type(num) == int: 177 if not data.num == num: 178 continue 179 elif type(num) == str: 180 if not match(num, `data.num`): 181 continue 182 183 # Skip the residue if there is no match to 'name'. 184 if name != None: 185 if not match(name, data.name): 186 continue 187 188 # Select the residue. 189 data.select = 1 190 191 # Match flag. 192 no_match = 0 193 194 # No residue matched. 195 if no_match: 196 print "No residues match."197 198200 """Function for unselecting all residues.""" 201 202 # Create the list of runs. 203 self.runs = self.relax.generic.runs.list_of_runs(run) 204 205 # Loop over the runs. 206 for self.run in self.runs: 207 # Test if the run exists. 208 if not self.run in self.relax.data.run_names: 209 raise RelaxNoRunError, self.run 210 211 # Test if sequence data is loaded. 212 if not len(self.relax.data.res[self.run]): 213 raise RelaxNoSequenceError, self.run 214 215 # Loop over the sequence and set the selection flag to 0. 216 for i in xrange(len(self.relax.data.res[self.run])): 217 self.relax.data.res[self.run][i].select = 0218 219221 """Function for unselecting the residues contained in a file.""" 222 223 # Extract the data from the file. 224 file_data = self.relax.IO.extract_data(file, dir) 225 226 # Strip the data. 227 file_data = self.relax.IO.strip(file_data) 228 229 # Create the list of residues to unselect. 230 unselect = [] 231 for i in xrange(len(file_data)): 232 try: 233 unselect.append(int(file_data[i][0])) 234 except: 235 raise RelaxError, "Improperly formatted file." 236 237 # Create the list of runs. 238 self.runs = self.relax.generic.runs.list_of_runs(run) 239 240 # Loop over the runs. 241 no_match = 1 242 for self.run in self.runs: 243 # Test if the run exists. 244 if not self.run in self.relax.data.run_names: 245 raise RelaxNoRunError, self.run 246 247 # Test if sequence data is loaded. 248 if not len(self.relax.data.res[self.run]): 249 raise RelaxNoSequenceError, self.run 250 251 # Loop over the sequence. 252 for i in xrange(len(self.relax.data.res[self.run])): 253 # Remap the data structure 'self.relax.data.res[self.run][i]'. 254 data = self.relax.data.res[self.run][i] 255 256 # Select all residues. 257 if change_all: 258 data.select = 1 259 260 # Unselect the residue if it is in the list unselect. 261 if data.num in unselect: 262 data.select = 0 263 264 # Match flag. 265 no_match = 0 266 267 # No residue matched. 268 if no_match: 269 print "No residues match."270 271273 """Function for unselecting specific residues.""" 274 275 # Test if the residue number is a valid regular expression. 276 if type(num) == str: 277 try: 278 compile(num) 279 except: 280 raise RelaxRegExpError, ('residue number', num) 281 282 # Test if the residue name is a valid regular expression. 283 if name: 284 try: 285 compile(name) 286 except: 287 raise RelaxRegExpError, ('residue name', name) 288 289 # Create the list of runs. 290 self.runs = self.relax.generic.runs.list_of_runs(run) 291 292 # Loop over the runs. 293 no_match = 1 294 for self.run in self.runs: 295 # Test if the run exists. 296 if not self.run in self.relax.data.run_names: 297 raise RelaxNoRunError, self.run 298 299 # Test if sequence data is loaded. 300 if not len(self.relax.data.res[self.run]): 301 raise RelaxNoSequenceError, self.run 302 303 # Loop over the sequence. 304 for i in xrange(len(self.relax.data.res[self.run])): 305 # Remap the data structure 'self.relax.data.res[self.run][i]'. 306 data = self.relax.data.res[self.run][i] 307 308 # Select all residues. 309 if change_all: 310 data.select = 1 311 312 # Skip the residue if there is no match to 'num'. 313 if type(num) == int: 314 if not data.num == num: 315 continue 316 if type(num) == str: 317 if not match(num, `data.num`): 318 continue 319 320 # Skip the residue if there is no match to 'name'. 321 if name != None: 322 if not match(name, data.name): 323 continue 324 325 # Unselect the residue. 326 data.select = 0 327 328 # Match flag. 329 no_match = 0 330 331 # No residue matched. 332 if no_match: 333 print "No residues match."
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Wed Apr 10 13:58:38 2013 | http://epydoc.sourceforge.net |