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