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