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

Source Code for Module lib.errors

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