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