Package lib :: Module errors
[hide private]
[frames] | no frames]

Source Code for Module lib.errors

   1  ############################################################################### 
   2  #                                                                             # 
   3  # Copyright (C) 2003-2014 Edward d'Auvergne                                   # 
   4  # Copyright (C) 2014 Troels E. Linnet                                         # 
   5  #                                                                             # 
   6  # This file is part of the program relax (http://www.nmr-relax.com).          # 
   7  #                                                                             # 
   8  # This program is free software: you can redistribute it and/or modify        # 
   9  # it under the terms of the GNU General Public License as published by        # 
  10  # the Free Software Foundation, either version 3 of the License, or           # 
  11  # (at your option) any later version.                                         # 
  12  #                                                                             # 
  13  # This program is distributed in the hope that it will be useful,             # 
  14  # but WITHOUT ANY WARRANTY; without even the implied warranty of              # 
  15  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               # 
  16  # GNU General Public License for more details.                                # 
  17  #                                                                             # 
  18  # You should have received a copy of the GNU General Public License           # 
  19  # along with this program.  If not, see <http://www.gnu.org/licenses/>.       # 
  20  #                                                                             # 
  21  ############################################################################### 
  22   
  23  # Module docstring. 
  24  """Module containing all of the RelaxError objects.""" 
  25   
  26   
  27  # Python module imports. 
  28  try: 
  29      from bz2 import BZ2File 
  30      bz2 = True 
  31  except ImportError: 
  32      bz2 = False 
  33  from re import match 
  34  import sys 
  35  import time 
  36   
  37  # relax module imports. 
  38  from lib import ansi 
  39  from lib.compat import pickle 
  40   
  41   
  42  # Module variables for changing the behaviour of the warning system. 
  43  SAVE_ERROR_STATE = False    # If True, then a pickled state file will be saved when a RelaxError occurs. 
  44   
  45  # Text variables. 
  46  BIN = 'a binary number (0 or 1)' 
  47  BOOL = 'a Boolean (True or False)' 
  48  INT = 'an integer' 
  49  FILE = 'a file object' 
  50  FLOAT = 'a floating point number' 
  51  FUNC = 'a function' 
  52  LIST = 'a list' 
  53  LIST_FLOAT = 'a list of floating point numbers' 
  54  LIST_INT = 'a list of integers' 
  55  LIST_NUM = 'a list of numbers' 
  56  LIST_STR = 'a list of strings' 
  57  LIST_VAL = 'a list of values' 
  58  MATRIX_FLOAT = 'a matrix of floating point numbers' 
  59  NONE = 'None' 
  60  NUM = 'a number' 
  61  TUPLE = 'a tuple' 
  62  TUPLE_FLOAT = 'a tuple of floating point numbers' 
  63  TUPLE_INT = 'a tuple of integers' 
  64  TUPLE_NUM = 'a tuple of numbers' 
  65  TUPLE_STR = 'a tuple of strings' 
  66  STR = 'a string' 
  67  VAL = 'a value' 
  68   
  69   
70 -def save_state():
71 """Save the program state, for debugging purposes.""" 72 73 # relax data store singleton import. Must be done here! 74 try: 75 from data_store import Relax_data_store; ds = Relax_data_store() 76 77 # Ok, this is not relax so don't do anything! 78 except ImportError: 79 return 80 81 # Append the date and time to the save file. 82 now = time.localtime() 83 file_name = "relax_state_%i%02i%02i_%02i%02i%02i" % (now[0], now[1], now[2], now[3], now[4], now[5]) 84 85 # Open the file for writing. 86 if bz2: 87 sys.stderr.write("\nStoring the relax state in the file '%s.bz2'.\n\n" % file_name) 88 file = BZ2File(file_name+'.bz2', 'w') 89 else: 90 sys.stderr.write("\nStoring the relax state in the file '%s'.\n\n" % file_name) 91 file = open(file_name, 'w') 92 93 # Pickle the data class and write it to file 94 pickle.dump(ds, file, 1) 95 96 # Close the file. 97 file.close()
98 99
100 -def list_to_text(data):
101 """Convert the given Python list to a text representation. 102 103 @param data: The list of Python objects. 104 @type data: list 105 @return: The English text version of the list. 106 @rtype: str 107 """ 108 109 # Initialise. 110 text = '' 111 112 # Loop over the elements, adding the to the list. 113 for i in range(len(data)): 114 # Add the text. 115 text += repr(data[i]) 116 117 # Comma separators. 118 if i < len(data) - 2: 119 text += ', ' 120 121 # Last separator. 122 if i == len(data) - 2: 123 text += ' and ' 124 125 # Return the text. 126 return text
127 128 129 # Base class for all errors. 130 ############################ 131
132 -class BaseError(Exception):
133 """The base class for all RelaxErrors.""" 134
135 - def __str__(self):
136 """Modify the behaviour of the error system.""" 137 138 # Save the state if the escalate flag is turned on. 139 if SAVE_ERROR_STATE: 140 save_state() 141 142 # Modify the error message to include 'RelaxError' at the start (using coloured text if a TTY). 143 if ansi.enable_control_chars(stream=2): 144 return ("%sRelaxError: %s%s\n" % (ansi.relax_error, self.text, ansi.end)) 145 else: 146 return ("RelaxError: %s\n" % self.text)
147 148
149 -class BaseArgError(BaseError):
150 """The base class for all the argument related RelaxErrors.""" 151 152 # The allowed simple types. 153 simple_types = [] 154 155 # The allowed list types (anything with a size). 156 list_types = [] 157 158
159 - def __init__(self, name, value, size=None):
160 """A default initialisation and error message formatting method.""" 161 162 # The initial part of the message. 163 self.text = "The %s argument '%s' must be " % (name, value) 164 165 # Append the fixed size to the list types. 166 if size != None: 167 for i in range(len(self.list_types)): 168 self.list_types[i] = self.list_types[i] + " of size %s" % repr(size) 169 170 # Combine all elements. 171 all_types = self.simple_types + self.list_types 172 173 # Multiple elements. 174 if len(all_types) > 1: 175 self.text = self.text + "either " 176 177 # Generate the list string. 178 for i in range(len(all_types)): 179 # Separators. 180 if i > 0: 181 # Or. 182 if i == len(all_types)-1: 183 self.text = self.text + ", or " 184 185 # Commas. 186 else: 187 self.text = self.text + ", " 188 189 # Append the text. 190 self.text = self.text + all_types[i] 191 192 # The end. 193 self.text = self.text + "."
194 195 196 # Standard errors. 197 ################## 198
199 -class RelaxError(BaseError):
200 - def __init__(self, text):
201 self.text = text
202 203 204 # Module import errors. 205 ####################### 206
207 -class RelaxNoModuleInstallError(BaseError):
208 - def __init__(self, desc, name):
209 self.text = "The %s module '%s' cannot be found. Please check that it is installed." % (desc, name)
210 211 212 # Fault. 213 ######## 214
215 -class RelaxFault(BaseError):
216 - def __init__(self):
217 self.text = "Impossible to be here, please re-run relax with the '--debug' flag and summit a bug report at https://web.archive.org/web/https://gna.org/projects/relax/."
218
219 - def __str__(self):
220 # Save the program state, no matter what. 221 save_state() 222 223 # Modify the error message to include 'RelaxError' at the start. 224 return ("RelaxError: " + self.text + "\n")
225 226 227 # Code implementation errors. 228 ############################# 229 230 # Not implemented yet.
231 -class RelaxImplementError(BaseError):
232 - def __init__(self, fn_name=None):
233 if fn_name: 234 self.text = "The %s function has not yet been implemented for the current data pipe." % fn_name 235 else: 236 self.text = "This has not yet been implemented for the current data pipe."
237 238 239 # Program errors. 240 ################# 241 242 # Cannot locate the program.
243 -class RelaxProgError(BaseError):
244 - def __init__(self, name):
245 self.text = "The program " + repr(name) + " cannot be found."
246 247 248 # The binary executable file does not exist (full path has been given!).
249 -class RelaxMissingBinaryError(BaseError):
250 - def __init__(self, name):
251 self.text = "The binary executable file " + repr(name) + " does not exist."
252 253 254 # The binary executable file is not executable.
255 -class RelaxNonExecError(BaseError):
256 - def __init__(self, name):
257 self.text = "The binary executable file " + repr(name) + " is not executable."
258 259 260 # The binary executable file is not located within the system path.
261 -class RelaxNoInPathError(BaseError):
262 - def __init__(self, name):
263 self.text = "The binary executable file " + repr(name) + " is not located within the system path."
264 265 266 # Program execution failure.
267 -class RelaxProgFailError(BaseError):
268 - def __init__(self, name):
269 self.text = "Execution of the program " + name + " has failed."
270 271 272 # PDB errors. 273 ############# 274 275 # PDB data corresponding to the data pipe already exists.
276 -class RelaxPdbError(BaseError):
277 - def __init__(self, pipe=None):
278 if pipe != None: 279 self.text = "PDB data corresponding to the data pipe " + repr(pipe) + " already exists." 280 else: 281 self.text = "PDB data already exists."
282 283 # No PDB loaded.
284 -class RelaxNoPdbError(BaseError):
285 - def __init__(self, pipe=None):
286 if pipe != None: 287 self.text = "No PDB file has been loaded for the data pipe " + repr(pipe) + "." 288 else: 289 self.text = "No PDB file has been loaded."
290 291 # Loading error.
292 -class RelaxPdbLoadError(BaseError):
293 - def __init__(self, name):
294 self.text = "The PDB file " + repr(name) + " could not be loaded properly, no molecular chains could be extracted."
295 296 # Multiple unit vectors.
297 -class RelaxMultiVectorError(BaseError):
298 - def __init__(self, spin_id=None):
299 if spin_id != None: 300 self.text = "The multiple unit XH bond vectors for the spin '%s' - this is not supported by the current data pipe type." % spin_id 301 else: 302 self.text = "The multiple unit XH bond vectors per spin - this is not supported by the current data pipe type."
303 304 # No unit vectors.
305 -class RelaxNoVectorsError(BaseError):
306 - def __init__(self, pipe=None):
307 if pipe: 308 self.text = "No unit vectors have been calculated for the data pipe '%s'" % pipe 309 else: 310 self.text = "No unit vectors have been calculated."
311 312 # No chains within the PDB file.
313 -class RelaxNoPdbChainError(BaseError):
314 - def __init__(self):
315 self.text = "No peptide or nucleotide chains can be found within the PDB file."
316 317 318 # Nuclear errors. 319 ################# 320 321 # Nucleus not set.
322 -class RelaxNucleusError(BaseError):
323 - def __init__(self, spin_id=None):
324 if spin_id != None: 325 self.text = "The type of nucleus for the spin '%s' has not yet been set." % spin_id 326 else: 327 self.text = "The type of nucleus has not yet been set."
328 329 # Spin type not set.
330 -class RelaxSpinTypeError(BaseError):
331 - def __init__(self, spin_id=None):
332 if spin_id != None: 333 self.text = "The nuclear isotope type for the spin '%s' has not yet been set. Please use the spin.isotope user function to set the type." % spin_id 334 else: 335 self.text = "The nuclear isotope type has not yet been set. Please use the spin.isotope user function to set the type."
336 337 338 # Argument errors. 339 ################## 340 341 342 # Misc. 343 #~~~~~~ 344 345 # Invalid argument.
346 -class RelaxInvalidError(BaseArgError):
347 - def __init__(self, name, value):
348 self.text = "The " + name + " argument " + repr(value) + " is invalid."
349 350 # Argument not in the list.
351 -class RelaxArgNotInListError(BaseArgError):
352 - def __init__(self, name, value, list):
353 self.text = "The " + name + " argument " + repr(value) + " is neither " 354 for i in range(len(list)-1): 355 self.text = self.text + repr(list[i]) + ', ' 356 self.text = self.text + 'nor ' + repr(list[-1]) + "."
357 358 # Length of the list.
359 -class RelaxLenError(BaseArgError):
360 - def __init__(self, name, len):
361 self.text = "The " + name + " argument must be of length " + repr(len) + "."
362 363 # None.
364 -class RelaxNoneError(BaseArgError):
365 - def __init__(self, name):
366 self.text = "The " + name + " argument has not been supplied."
367 368 # Not None.
369 -class RelaxArgNotNoneError(BaseArgError):
370 - def __init__(self, name, value):
371 self.text = "The %s argument of '%s' must be None."
372 373 374 # Simple types. 375 #~~~~~~~~~~~~~~ 376 377 # Boolean - the values True and False.
378 -class RelaxBoolError(BaseArgError):
379 simple_types = [BOOL]
380 381 # Binary - integers 0 and 1.
382 -class RelaxBinError(BaseArgError):
383 simple_types = [BIN]
384 385 # Float.
386 -class RelaxFloatError(BaseArgError):
387 simple_types = [FLOAT]
388
389 -class RelaxNoneFloatError(BaseArgError):
390 simple_types = [NONE, FLOAT]
391 392 # Number.
393 -class RelaxNumError(BaseArgError):
394 simple_types = [NUM]
395
396 -class RelaxNoneNumError(BaseArgError):
397 simple_types = [NONE, NUM]
398 399 # Function.
400 -class RelaxFunctionError(BaseArgError):
401 simple_types = [FUNC]
402
403 -class RelaxNoneFunctionError(BaseArgError):
404 simple_types = [NONE, FUNC]
405 406 # Integer.
407 -class RelaxIntError(BaseArgError):
408 simple_types = [INT]
409
410 -class RelaxNoneIntError(BaseArgError):
411 simple_types = [NONE, INT]
412 413 # String.
414 -class RelaxStrError(BaseArgError):
415 simple_types = [STR]
416
417 -class RelaxNoneStrError(BaseArgError):
418 simple_types = [NONE, STR]
419 420 421 # Simple mixes. 422 #~~~~~~~~~~~~~~ 423 424 # Integer or string.
425 -class RelaxIntStrError(BaseArgError):
426 simple_types = [INT, STR]
427
428 -class RelaxNoneIntStrError(BaseArgError):
429 simple_types = [NONE, INT, STR]
430 431 # String or file descriptor.
432 -class RelaxStrFileError(BaseArgError):
433 simple_types = [STR, FILE]
434
435 -class RelaxNoneStrFileError(BaseArgError):
436 simple_types = [NONE, STR, FILE]
437 438 439 # List types. 440 #~~~~~~~~~~~~ 441 442 443 # List.
444 -class RelaxListError(BaseArgError):
445 list_types = [LIST]
446
447 -class RelaxNoneListError(BaseArgError):
448 simple_types = [NONE] 449 list_types = [LIST]
450 451 # List of floating point numbers.
452 -class RelaxListFloatError(BaseArgError):
453 list_types = [LIST_FLOAT]
454
455 -class RelaxNoneListFloatError(BaseArgError):
456 list_types = [LIST_FLOAT]
457 458 # List of floating point numbers or strings.
459 -class RelaxListFloatStrError(BaseArgError):
460 list_types = [LIST_FLOAT, LIST_STR]
461 462 # List of integers.
463 -class RelaxListIntError(BaseArgError):
464 list_types = [LIST_INT]
465 466 # List of integers.
467 -class RelaxNoneListIntError(BaseArgError):
468 simple_types = [NONE] 469 list_types = [LIST_INT]
470 471 # List of numbers.
472 -class RelaxListNumError(BaseArgError):
473 list_types = [LIST_NUM]
474
475 -class RelaxNoneListNumError(BaseArgError):
476 simple_types = [NONE] 477 list_types = [LIST_NUM]
478 479 # List of strings.
480 -class RelaxListStrError(BaseArgError):
481 list_types = [LIST_STR]
482
483 -class RelaxNoneListStrError(BaseArgError):
484 simple_types = [NONE] 485 list_types = [LIST_STR]
486 487 488 # Simple or list types. 489 #~~~~~~~~~~~~~~~~~~~~~~ 490 491 # Float or list.
492 -class RelaxNoneFloatListError(BaseArgError):
493 simple_types = [NONE, FLOAT] 494 list_types = [LIST]
495 496 # Float, str, or list.
497 -class RelaxNoneFloatStrListError(BaseArgError):
498 simple_types = [NONE, FLOAT, STR] 499 list_types = [LIST]
500 501 # Integer or list of integers.
502 -class RelaxIntListIntError(BaseArgError):
503 simple_types = [INT] 504 list_types = [LIST_INT]
505
506 -class RelaxNoneIntListIntError(BaseArgError):
507 simple_types = [NONE, INT] 508 list_types = [LIST_INT]
509 510 # Number, string, or list of numbers or strings.
511 -class RelaxNumStrListNumStrError(BaseArgError):
512 simple_types = [NUM, STR] 513 list_types = [LIST_NUM, LIST_STR]
514
515 -class RelaxNoneNumStrListNumStrError(BaseArgError):
516 simple_types = [NONE, NUM, STR] 517 list_types = [LIST_NUM, LIST_STR]
518 519 # String or list.
520 -class RelaxNoneStrListError(BaseArgError):
521 simple_types = [NONE, STR] 522 list_types = [LIST]
523 524 # String or list of numbers.
525 -class RelaxStrListNumError(BaseArgError):
526 simple_types = [STR] 527 list_types = [LIST_NUM]
528
529 -class RelaxNoneStrListNumError(BaseArgError):
530 simple_types = [NONE, STR] 531 list_types = [LIST_NUM]
532 533 # String or list of strings.
534 -class RelaxStrListStrError(BaseArgError):
535 simple_types = [STR] 536 list_types = [LIST_STR]
537
538 -class RelaxNoneStrListStrError(BaseArgError):
539 simple_types = [NONE, STR] 540 list_types = [LIST_STR]
541 542 # Value or list of values.
543 -class RelaxValListValError(BaseArgError):
544 simple_types = [VAL] 545 list_types = [LIST_VAL]
546
547 -class RelaxNoneValListValError(BaseArgError):
548 simple_types = [NONE, VAL] 549 list_types = [LIST_VAL]
550 551 552 # Tuple types. 553 #~~~~~~~~~~~~~ 554 555 # Tuple.
556 -class RelaxTupleError(BaseArgError):
557 list_types = [TUPLE]
558
559 -class RelaxNoneTupleError(BaseArgError):
560 simple_types = [NONE] 561 list_types = [TUPLE]
562 563 # Tuple of numbers.
564 -class RelaxTupleNumError(BaseArgError):
565 list_types = [TUPLE_NUM]
566 567 568 # Simple or tuple types. 569 #~~~~~~~~~~~~~~~~~~~~~~~ 570 571 # Number or tuple.
572 -class RelaxNumTupleError(BaseArgError):
573 simple_types = [NUM] 574 list_types = [TUPLE]
575 576 # Number or tuple of numbers.
577 -class RelaxNumTupleNumError(BaseArgError):
578 simple_types = [NUM] 579 list_types = [TUPLE_NUM]
580
581 -class RelaxNoneNumTupleNumError(BaseArgError):
582 simple_types = [NONE, NUM] 583 list_types = [TUPLE_NUM]
584 585 586 # Matrix types. 587 #~~~~~~~~~~~~~~ 588 589 # Matrix of floating point numbers.
590 -class RelaxMatrixFloatError(BaseArgError):
591 list_types = [MATRIX_FLOAT]
592
593 -class RelaxNoneMatrixFloatError(BaseArgError):
594 list_types = [MATRIX_FLOAT]
595 596 597 598 # Sequence errors. 599 ################## 600 601 # No sequence loaded.
602 -class RelaxNoSequenceError(BaseError):
603 - def __init__(self, pipe=None):
604 if pipe == None: 605 self.text = "The sequence data does not exist." 606 else: 607 self.text = "The sequence data for the data pipe " + repr(pipe) + " does not exist."
608 609 # The sequence already exists.
610 -class RelaxSequenceError(BaseError):
611 - def __init__(self, pipe=None):
612 if pipe == None: 613 self.text = "The sequence data already exists." 614 else: 615 self.text = "The sequence data for the data pipe " + repr(pipe) + " already exists."
616 617 # The two sequences are different.
618 -class RelaxDiffSeqError(BaseError):
619 - def __init__(self, pipe1, pipe2):
620 self.text = "The sequences for the data pipes " + repr(pipe1) + " and " + repr(pipe2) + " are not the same."
621 622 # The number of molecules are different.
623 -class RelaxDiffMolNumError(BaseError):
624 - def __init__(self, pipe1, pipe2):
625 self.text = "The number of molecules do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
626 627 # The number of residues are different.
628 -class RelaxDiffResNumError(BaseError):
629 - def __init__(self, pipe1, pipe2):
630 self.text = "The number of residues do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
631 632 # The number of spins are different.
633 -class RelaxDiffSpinNumError(BaseError):
634 - def __init__(self, pipe1, pipe2):
635 self.text = "The number of spins do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
636 637 # Multiple spins matching the ID.
638 -class RelaxMultiMolIDError(BaseError):
639 - def __init__(self, id):
640 if id == '': 641 self.text = "The empty molecule ID corresponds to more than a single molecule in the current data pipe." 642 else: 643 self.text = "The molecule ID '%s' corresponds to more than a single molecule in the current data pipe." % id
644 645 # Multiple spins matching the ID.
646 -class RelaxMultiResIDError(BaseError):
647 - def __init__(self, id):
648 if id == '': 649 self.text = "The empty residue ID corresponds to more than a single residue in the current data pipe." 650 else: 651 self.text = "The residue ID '%s' corresponds to more than a single residue in the current data pipe." % id
652 653 # Multiple spins matching the ID.
654 -class RelaxMultiSpinIDError(BaseError):
655 - def __init__(self, id, id_list=None):
656 if id_list != None and id == '': 657 self.text = "The empty spin ID corresponds to multiple spins, including %s." % list_to_text(id_list) 658 elif id_list == None and id == '': 659 self.text = "The empty spin ID corresponds to more than a single spin in the current data pipe." 660 elif id_list != None: 661 self.text = "The spin ID '%s' corresponds to multiple spins, including %s." % (id, list_to_text(id_list)) 662 else: 663 self.text = "The spin ID '%s' corresponds to more than a single spin in the current data pipe." % id
664 665 # Cannot find the residue in the sequence.
666 -class RelaxNoResError(BaseError):
667 - def __init__(self, number, name=None):
668 if name == None: 669 self.text = "The residue '" + repr(number) + "' cannot be found in the sequence." 670 else: 671 self.text = "The residue '" + repr(number) + " " + name + "' cannot be found in the sequence."
672 673 # Cannot find the spin in the sequence.
674 -class RelaxNoSpinError(BaseError):
675 - def __init__(self, id, pipe=None):
676 if pipe == None: 677 self.text = "The spin '%s' does not exist." % id 678 else: 679 self.text = "The spin '%s' does not exist in the '%s' data pipe." % (id, pipe)
680 681 # The sequence data is not valid.
682 -class RelaxInvalidSeqError(BaseError):
683 - def __init__(self, line, problem=None):
684 if problem == None: 685 self.text = "The sequence data in the line %s is invalid." % line 686 else: 687 self.text = "The sequence data in the line %s is invalid, %s." % (line, problem)
688 689 # The spins have not been loaded
690 -class RelaxSpinsNotLoadedError(BaseError):
691 - def __init__(self, spin_id):
692 self.text = "The spin information for the spin " + repr(spin_id) + " has not yet been loaded, please use the structure.load_spins user function."
693 694 695 # Interatomic data errors. 696 ########################## 697 698 # No interatomic data.
699 -class RelaxNoInteratomError(BaseError):
700 - def __init__(self, spin_id1=None, spin_id2=None, pipe=None):
701 if spin_id1 and pipe: 702 self.text = "The interatomic data between the spins '%s' and '%s' for the data pipe '%s' does not exist." % (spin_id1, spin_id2, pipe) 703 elif spin_id1: 704 self.text = "The interatomic data between the spins '%s' and '%s' does not exist." % (spin_id1, spin_id2) 705 elif pipe: 706 self.text = "The interatomic data for the data pipe '%s' does not exist." % pipe 707 else: 708 self.text = "The interatomic data does not exist."
709 710 # The interatomic data already exists.
711 -class RelaxInteratomError(BaseError):
712 - def __init__(self, pipe=None):
713 if pipe == None: 714 self.text = "The interatomic data already exists." 715 else: 716 self.text = "The interatomic data for the data pipe " + repr(pipe) + " already exists."
717 718 # Inconsistency in the interatomic data.
719 -class RelaxInteratomInconsistentError(BaseError):
720 - def __init__(self, pipe1, pipe2):
721 self.text = "The interatomic data is inconsistent between the data pipes '%s' and '%s'." % (pipe1, pipe2)
722 723 724 725 # Domain errors. 726 ################ 727 728 # No domain defined.
729 -class RelaxNoDomainError(BaseError):
730 - def __init__(self, id=None):
731 if id == None: 732 self.text = "No domains are defined." 733 else: 734 self.text = "The domain '%s' is not defined." % id
735 736 737 738 # Spectrometer information errors. 739 ################################## 740 741 # No frequency information.
742 -class RelaxNoFrqError(BaseError):
743 - def __init__(self, pipe_name=None, id=None):
744 self.text = "No spectrometer frequency information" 745 if id != None: 746 self.text += " for the '%s' experiment ID" % id 747 self.text += " is present" 748 if pipe_name != None: 749 self.text += " in the '%s' data pipe" % pipe_name 750 self.text += "."
751 752 753 754 # Spectral data errors. 755 ####################### 756 757 # No peak intensity data.
758 -class RelaxNoPeakIntensityError(BaseError):
759 - def __init__(self, spectrum_id=None):
760 if spectrum_id == None: 761 self.text = "No peak intensity data has been loaded." 762 else: 763 self.text = "Peak intensity data for the '%s' spectrum ID does not exist."
764 765 # No spectral data.
766 -class RelaxNoSpectraError(BaseError):
767 - def __init__(self, spectrum_id):
768 self.text = "Spectral data corresponding to the ID string '%s' does not exist." % spectrum_id
769 770 # Spectral data already exists.
771 -class RelaxSpectraError(BaseError):
772 - def __init__(self, spectrum_id):
773 self.text = "Spectral data corresponding to the ID string '%s' already exists." % spectrum_id
774 775 776 # Relaxation data errors. 777 ######################### 778 779 # No relaxation data.
780 -class RelaxNoRiError(BaseError):
781 - def __init__(self, ri_id):
782 self.text = "Relaxation data corresponding to the ID string '%s' does not exist." % ri_id
783 784 # Relaxation data already exists.
785 -class RelaxRiError(BaseError):
786 - def __init__(self, ri_id):
787 self.text = "Relaxation data corresponding to the ID string '%s' already exists." % ri_id
788 789 790 # J coupling errors. 791 #################### 792 793 # No J data.
794 -class RelaxNoJError(BaseError):
795 - def __init__(self):
796 self.text = "No J coupling data exists."
797 798 # J data already exists.
799 -class RelaxJError(BaseError):
800 - def __init__(self):
801 self.text = "J coupling data already exists."
802 803 804 # RDC and PCS data errors. 805 ########################## 806 807 # No alignment data.
808 -class RelaxNoAlignError(BaseError):
809 - def __init__(self, align_id, pipe=None):
810 if pipe != None: 811 self.text = "The alignment ID string '%s' is missing from the data pipe '%s'." % (align_id, pipe) 812 else: 813 self.text = "The alignment ID string '%s' is missing." % align_id
814 815 # Alignment data already exists.
816 -class RelaxAlignError(BaseError):
817 - def __init__(self, align_id):
818 self.text = "Alignment data corresponding to the ID string '%s' already exists." % align_id
819 820 # No RDC data.
821 -class RelaxNoRDCError(BaseError):
822 - def __init__(self, id=None):
823 if id: 824 self.text = "RDC data corresponding to the identification string " + repr(id) + " does not exist." 825 else: 826 self.text = "No RDC data exists."
827 828 # RDC data already exists.
829 -class RelaxRDCError(BaseError):
830 - def __init__(self, id):
831 self.text = "RDC data corresponding to the identification string " + repr(id) + " already exists."
832 833 # No PCS data.
834 -class RelaxNoPCSError(BaseError):
835 - def __init__(self, id=None):
836 if id: 837 self.text = "PCS data corresponding to the identification string " + repr(id) + " does not exist." 838 else: 839 self.text = "No PCS data exists."
840 841 # PCS data already exists.
842 -class RelaxPCSError(BaseError):
843 - def __init__(self, id):
844 self.text = "PCS data corresponding to the identification string " + repr(id) + " already exists."
845 846 847 # Model-free errors. 848 #################### 849 850 # Model-free data already exists.
851 -class RelaxMfError(BaseError):
852 - def __init__(self, pipe):
853 self.text = "Model-free data corresponding to the data pipe " + repr(pipe) + " already exists."
854 855 856 # Tensor errors. 857 ################ 858 859 # Tensor data corresponding to the data pipe already exists.
860 -class RelaxTensorError(BaseError):
861 - def __init__(self, tensor_type):
862 self.text = "The " + tensor_type + " tensor data already exists."
863 864 # No tensor data exists.
865 -class RelaxNoTensorError(BaseError):
866 - def __init__(self, tensor_type, tensor_label=None):
867 if not tensor_label: 868 self.text = "No " + tensor_type + " tensor data exists." 869 else: 870 self.text = "No " + tensor_type + " tensor data exists for the tensor " + repr(tensor_label) + "."
871 872 873 # File errors. 874 ############## 875 876 # No directory.
877 -class RelaxDirError(BaseError):
878 - def __init__(self, name, dir):
879 if name == None: 880 self.text = "The directory " + repr(dir) + " does not exist." 881 else: 882 self.text = "The " + name + " directory " + repr(dir) + " does not exist."
883 884 # No file.
885 -class RelaxFileError(BaseError):
886 - def __init__(self, name, file_name=None):
887 if file_name == None: 888 self.text = "The file " + repr(name) + " does not exist." 889 else: 890 self.text = "The " + name + " file " + repr(file_name) + " does not exist."
891 892 # No data in file.
893 -class RelaxFileEmptyError(BaseError):
894 - def __init__(self):
895 self.text = "The file contains no data."
896 897 # Overwrite file.
898 -class RelaxFileOverwriteError(BaseError):
899 - def __init__(self, file_name, flag):
900 self.text = "The file " + repr(file_name) + " already exists. Set the " + flag + " to True to overwrite."
901 902 # Invalid data format.
903 -class RelaxInvalidDataError(BaseError):
904 - def __init__(self):
905 self.text = "The format of the data is invalid."
906 907 908 # Data pipe errors. 909 ################### 910 911 # The data pipe bundle already exists.
912 -class RelaxBundleError(BaseError):
913 - def __init__(self, bundle):
914 self.text = "The data pipe bundle '%s' already exists." % bundle
915 916 # No data pipe bundles exist.
917 -class RelaxNoBundleError(BaseError):
918 - def __init__(self, bundle=None):
919 if bundle != None: 920 self.text = "The data pipe bundle '%s' has not been created yet." % bundle 921 else: 922 self.text = "No data pipe bundles currently exist. Please use the pipe.bundle user function first."
923 924 # The data pipe already exists.
925 -class RelaxPipeError(BaseError):
926 - def __init__(self, pipe):
927 self.text = "The data pipe " + repr(pipe) + " already exists."
928 929 # No data pipe exists.
930 -class RelaxNoPipeError(BaseError):
931 - def __init__(self, pipe=None):
932 if pipe != None: 933 self.text = "The data pipe " + repr(pipe) + " has not been created yet." 934 else: 935 self.text = "No data pipes currently exist. Please use the pipe.create user function first."
936 937 938 # Spin-Residue-Molecule errors. 939 ############################### 940 941 # Disallow molecule selection.
942 -class RelaxMolSelectDisallowError(BaseError):
943 - def __init__(self):
944 self.text = "The selection of molecules is not allowed."
945 946 # Disallow residue selection.
947 -class RelaxResSelectDisallowError(BaseError):
948 - def __init__(self):
949 self.text = "The selection of residues is not allowed."
950 951 # Disallow spin selection.
952 -class RelaxSpinSelectDisallowError(BaseError):
953 - def __init__(self):
954 self.text = "The selection of spin systems is not allowed."
955 956 # The spin must be specified.
957 -class RelaxNoSpinSpecError(BaseError):
958 - def __init__(self):
959 self.text = "The spin system must be specified."
960 961 962 963 # Setup errors. 964 ############### 965 966 # Cannot setup the functions.
967 -class RelaxFuncSetupError(BaseError):
968 - def __init__(self, string):
969 self.text = "This function is not available for " + string + "."
970 971 # The model already exists.
972 -class RelaxModelError(BaseError):
973 - def __init__(self, name=None):
974 if name != None: 975 self.text = "The " + name + " model already exists." 976 else: 977 self.text = "The model already exists."
978 979 980 # The model has not been setup.
981 -class RelaxNoModelError(BaseError):
982 - def __init__(self, name=None):
983 if name != None: 984 self.text = "The specific " + name + " model has not been selected or set up." 985 else: 986 self.text = "The specific model has not been selected or set up."
987 988 989 # Regular expression errors. 990 ############################ 991 992 # Bad regular expression.
993 -class RelaxRegExpError(BaseError):
994 - def __init__(self, name, value):
995 self.text = "The " + name + " argument " + repr(value) + " is not valid regular expression."
996 997 998 # Data type errors. 999 ################### 1000 1001 # Parameter cannot be set.
1002 -class RelaxParamSetError(BaseError):
1003 - def __init__(self, name, param_type=None):
1004 if param_type != None: 1005 self.text = "The " + name + " parameter, " + repr(param_type) + ", cannot be set." 1006 else: 1007 self.text = "The " + name + " parameter cannot be set."
1008 1009 # Value already exists.
1010 -class RelaxValueError(BaseError):
1011 - def __init__(self, data_type, pipe=None):
1012 if pipe != None: 1013 self.text = "The data type " + repr(data_type) + " already exists for the data pipe " + repr(pipe) + "." 1014 else: 1015 self.text = "The data type " + repr(data_type) + " already exists."
1016 1017 # No data value.
1018 -class RelaxNoValueError(BaseError):
1019 - def __init__(self, name, spin_id=None, spin_id2=None):
1020 if spin_id2 != None: 1021 self.text = "The %s value has not yet been set for spins '%s' and '%s'." % (name, spin_id, spin_id2) 1022 elif spin_id != None: 1023 self.text = "The %s value has not yet been set for spin '%s'." % (name, spin_id) 1024 else: 1025 self.text = "The " + repr(name) + " value has not yet been set."
1026 1027 # Unknown data type.
1028 -class RelaxUnknownDataTypeError(BaseError):
1029 - def __init__(self, name):
1030 self.text = "The data type " + repr(name) + " is unknown."
1031 1032 # Unknown parameter.
1033 -class RelaxUnknownParamError(BaseError):
1034 - def __init__(self, name, param_type=None):
1035 if param_type != None: 1036 self.text = "The " + name + " parameter, " + repr(param_type) + ", is unknown." 1037 else: 1038 self.text = "The " + name + " parameter is unknown."
1039 1040 # Unknown parameter combination.
1041 -class RelaxUnknownParamCombError(BaseError):
1042 - def __init__(self, name, data):
1043 self.text = "The " + repr(name) + " argument " + repr(data) + " represents an unknown parameter combination."
1044 1045 1046 # Simulation errors. 1047 #################### 1048 1049 # No simulations.
1050 -class RelaxNoSimError(BaseError):
1051 - def __init__(self, pipe=None):
1052 if pipe: 1053 self.text = "Simulations for the data pipe " + repr(pipe) + " have not been setup." 1054 else: 1055 self.text = "Simulations have not been setup."
1056 1057 1058 # Style errors. 1059 ############### 1060 1061 # Unknown style.
1062 -class RelaxStyleError(BaseError):
1063 - def __init__(self, style):
1064 self.text = "The style " + repr(style) + " is unknown."
1065 1066 1067 # Colour errors. 1068 ################ 1069 1070 # Invalid colour.
1071 -class RelaxInvalidColourError(BaseError):
1072 - def __init__(self, colour):
1073 self.text = "The colour " + repr(colour) + " is invalid."
1074 1075 1076 # Value errors. 1077 ############### 1078 1079 # Infinity.
1080 -class RelaxInfError(BaseError):
1081 - def __init__(self, name):
1082 self.text = "The invalid " + name + " floating point value of infinity has occurred."
1083 1084 # NaN (Not a Number).
1085 -class RelaxNaNError(BaseError):
1086 - def __init__(self, name):
1087 self.text = "The invalid " + name + " floating point value of NaN (Not a Number) has occurred."
1088 1089 1090 # XML errors. 1091 ############# 1092 1093 # Cannot recreate from the XML - the structure is not empty.
1094 -class RelaxFromXMLNotEmptyError(BaseError):
1095 - def __init__(self, name):
1096 self.text = "The " + name + " data structure cannot be recreated from the XML elements as the structure is not empty."
1097 1098 1099 1100 # An object of all the RelaxErrors. 1101 ################################### 1102 1103 # Function for setting up the AllRelaxErrors object.
1104 -def all_errors(names):
1105 """Function for returning all the RelaxErrors to allow the AllRelaxError object to be created.""" 1106 1107 # Empty list. 1108 list = [] 1109 1110 # Loop over all objects of this module. 1111 for name in names: 1112 # Get the object. 1113 object = globals()[name] 1114 1115 # Skip over all non error class objects. 1116 if not (isinstance(object, type(RelaxError)) or isinstance(object, type(type))) or not match('Relax', name): 1117 continue 1118 1119 # Append to the list. 1120 list.append(object) 1121 1122 # Return the list of RelaxErrors 1123 return list
1124 1125 # Initialise the AllRelaxErrors structure, as a tuple for the except statements, so it can be imported. 1126 AllRelaxErrors = tuple(all_errors(dir())) 1127