Module relax_errors
[hide private]
[frames] | no frames]

Source Code for Module relax_errors

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