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