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

Source Code for Module lib.errors

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