1   
   2   
   3   
   4   
   5   
   6   
   7   
   8   
   9   
  10   
  11   
  12   
  13   
  14   
  15   
  16   
  17   
  18   
  19   
  20   
  21   
  22   
  23  """Module containing all of the RelaxError objects.""" 
  24   
  25   
  26   
  27  try: 
  28      from bz2 import BZ2File 
  29      bz2 = True 
  30  except ImportError: 
  31      bz2 = False 
  32  from re import match 
  33  import sys 
  34  import time 
  35   
  36   
  37  from compat import pickle 
  38  import ansi 
  39   
  40   
  41   
  42  BIN = 'a binary number (0 or 1)' 
  43  BOOL = 'a Boolean (True or False)' 
  44  INT = 'an integer' 
  45  FILE = 'a file object' 
  46  FLOAT = 'a floating point number' 
  47  FUNC = 'a function' 
  48  LIST = 'a list' 
  49  LIST_FLOAT = 'a list of floating point numbers' 
  50  LIST_INT = 'a list of integers' 
  51  LIST_NUM = 'a list of numbers' 
  52  LIST_STR = 'a list of strings' 
  53  LIST_VAL = 'a list of values' 
  54  MATRIX_FLOAT = 'a matrix of floating point numbers' 
  55  NONE = 'None' 
  56  NUM = 'a number' 
  57  TUPLE = 'a tuple' 
  58  TUPLE_FLOAT = 'a tuple of floating point numbers' 
  59  TUPLE_INT = 'a tuple of integers' 
  60  TUPLE_NUM = 'a tuple of numbers' 
  61  TUPLE_STR = 'a tuple of strings' 
  62  STR = 'a string' 
  63  VAL = 'a value' 
  64   
  65   
  67      """Save the program state, for debugging purposes.""" 
  68   
  69       
  70      try: 
  71          from data import Relax_data_store; ds = Relax_data_store() 
  72   
  73       
  74      except ImportError: 
  75          return 
  76   
  77       
  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       
  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       
  90      pickle.dump(ds, file, 1) 
  91   
  92       
  93      file.close() 
   94   
  95   
  96 -def list_to_text(data): 
   97      """Convert the given Python list to a text representation. 
  98   
  99      @param data:    The list of Python objects. 
 100      @type data:     list 
 101      @return:        The English text version of the list. 
 102      @rtype:         str 
 103      """ 
 104   
 105       
 106      text = '' 
 107   
 108       
 109      for i in range(len(data)): 
 110           
 111          text += repr(data[i]) 
 112   
 113           
 114          if i < len(data) - 2: 
 115              text += ', ' 
 116   
 117           
 118          if i == len(data) - 2: 
 119              text += ' and ' 
 120   
 121       
 122      return text 
  123   
 124   
 125   
 126   
 127   
 129      """The base class for all RelaxErrors.""" 
 130   
  144   
 145   
 147      """The base class for all the argument related RelaxErrors.""" 
 148   
 149       
 150      simple_types = [] 
 151   
 152       
 153      list_types = [] 
 154   
 155   
 156 -    def __init__(self, name, value, size=None): 
  157          """A default initialisation and error message formatting method.""" 
 158   
 159           
 160          self.text = "The %s argument '%s' must be " % (name, value) 
 161   
 162           
 163          if size != None: 
 164              for i in range(len(self.list_types)): 
 165                  self.list_types[i] = self.list_types[i] + " of size %s" % repr(size) 
 166   
 167           
 168          all_types = self.simple_types + self.list_types 
 169   
 170           
 171          if len(all_types) > 1: 
 172              self.text = self.text + "either " 
 173   
 174           
 175          for i in range(len(all_types)): 
 176               
 177              if i > 0: 
 178                   
 179                  if i == len(all_types)-1: 
 180                      self.text = self.text + ", or " 
 181   
 182                   
 183                  else: 
 184                      self.text = self.text + ", " 
 185   
 186               
 187              self.text = self.text + all_types[i] 
 188   
 189           
 190          self.text = self.text + "." 
   191   
 192   
 193   
 194   
 195   
 199   
 200   
 201   
 202   
 203   
 206          self.text = "The %s module '%s' cannot be found.  Please check that it is installed." % (desc, name) 
   207   
 208   
 209   
 210   
 211   
 214          self.text = "Impossible to be here, please re-run relax with the '--debug' flag and summit a bug report at https://web.archive.org/web/https://gna.org/projects/relax/." 
  215   
 217           
 218          save_state() 
 219   
 220           
 221          return ("RelaxError: " + self.text + "\n") 
   222   
 223   
 224   
 225   
 226   
 227   
 230          if fn_name: 
 231              self.text = "The %s function has not yet been implemented for the current data pipe." % fn_name 
 232          else: 
 233              self.text = "This has not yet been implemented for the current data pipe." 
   234   
 235   
 236   
 237   
 238   
 239   
 242          self.text = "The program " + repr(name) + " cannot be found." 
   243   
 244   
 245   
 248          self.text = "The binary executable file " + repr(name) + " does not exist." 
   249   
 250   
 251   
 254          self.text = "The binary executable file " + repr(name) + " is not executable." 
   255   
 256   
 257   
 260          self.text = "The binary executable file " + repr(name) + " is not located within the system path." 
   261   
 262   
 263   
 266          self.text = "Execution of the program " + name + " has failed." 
   267   
 268   
 269   
 270   
 271   
 272   
 275          if pipe != None: 
 276              self.text = "PDB data corresponding to the data pipe " + repr(pipe) + " already exists." 
 277          else: 
 278              self.text = "PDB data already exists." 
   279   
 280   
 283          if pipe != None: 
 284              self.text = "No PDB file has been loaded for the data pipe " + repr(pipe) + "." 
 285          else: 
 286              self.text = "No PDB file has been loaded." 
   287   
 288   
 291          self.text = "The PDB file " + repr(name) + " could not be loaded properly, no molecular chains could be extracted." 
   292   
 293   
 296          if spin_id != None: 
 297              self.text = "The multiple unit XH bond vectors for the spin '%s' - this is not supported by the current data pipe type." % spin_id 
 298          else: 
 299              self.text = "The multiple unit XH bond vectors per spin - this is not supported by the current data pipe type." 
   300   
 301   
 304          if pipe: 
 305              self.text = "No unit vectors have been calculated for the data pipe '%s'" % pipe 
 306          else: 
 307              self.text = "No unit vectors have been calculated." 
   308   
 309   
 312          self.text = "No peptide or nucleotide chains can be found within the PDB file." 
   313   
 314   
 315   
 316   
 317   
 318   
 321          if spin_id != None: 
 322              self.text = "The type of nucleus for the spin '%s' has not yet been set." % spin_id 
 323          else: 
 324              self.text = "The type of nucleus has not yet been set." 
   325   
 326   
 329          if spin_id != None: 
 330              self.text = "The nuclear isotope type for the spin '%s' has not yet been set.  Please use the spin.isotope user function to set the type." % spin_id 
 331          else: 
 332              self.text = "The nuclear isotope type has not yet been set.  Please use the spin.isotope user function to set the type." 
   333   
 334   
 335   
 336   
 337   
 338   
 339   
 340   
 341   
 342   
 345          self.text = "The " + name + " argument " + repr(value) + " is invalid." 
   346   
 347   
 350          self.text = "The " + name + " argument " + repr(value) + " is neither " 
 351          for i in range(len(list)-1): 
 352              self.text = self.text + repr(list[i]) + ', ' 
 353          self.text = self.text + 'nor ' + repr(list[-1]) + "." 
   354   
 355   
 358          self.text = "The " + name + " argument must be of length " + repr(len) + "." 
   359   
 360   
 363          self.text = "The " + name + " argument has not been supplied." 
   364   
 365   
 368          self.text = "The %s argument of '%s' must be None." 
   369   
 370   
 371   
 372   
 373   
 374   
 377   
 378   
 381   
 382   
 385   
 388   
 389   
 392   
 395   
 396   
 399   
 402   
 403   
 406   
 409   
 410   
 413   
 416   
 417   
 418   
 419   
 420   
 421   
 424   
 427   
 428   
 431   
 434   
 435   
 436   
 437   
 438   
 439   
 440   
 443   
 447   
 448   
 451   
 454   
 455   
 458   
 459   
 462   
 463   
 467   
 468   
 471   
 475   
 476   
 479   
 483   
 484   
 485   
 486   
 487   
 488   
 492   
 493   
 497   
 498   
 502   
 506   
 507   
 511   
 515   
 516   
 520   
 521   
 525   
 529   
 530   
 534   
 538   
 539   
 543   
 547   
 548   
 549   
 550   
 551   
 552   
 555   
 559   
 560   
 563   
 564   
 565   
 566   
 567   
 568   
 572   
 573   
 577   
 581   
 582   
 583   
 584   
 585   
 586   
 589   
 592   
 593   
 594   
 595   
 596   
 597   
 598   
 601          if pipe == None: 
 602              self.text = "The sequence data does not exist." 
 603          else: 
 604              self.text = "The sequence data for the data pipe " + repr(pipe) + " does not exist." 
   605   
 606   
 609          if pipe == None: 
 610              self.text = "The sequence data already exists." 
 611          else: 
 612              self.text = "The sequence data for the data pipe " + repr(pipe) + " already exists." 
   613   
 614   
 617          self.text = "The sequences for the data pipes " + repr(pipe1) + " and " + repr(pipe2) + " are not the same." 
   618   
 619   
 622          self.text = "The number of molecules do not match between pipes '%s' and '%s'." % (pipe1, pipe2) 
   623   
 624   
 627          self.text = "The number of residues do not match between pipes '%s' and '%s'." % (pipe1, pipe2) 
   628   
 629   
 632          self.text = "The number of spins do not match between pipes '%s' and '%s'." % (pipe1, pipe2) 
   633   
 634   
 637          if id == '': 
 638              self.text = "The empty molecule ID corresponds to more than a single molecule in the current data pipe." 
 639          else: 
 640              self.text = "The molecule ID '%s' corresponds to more than a single molecule in the current data pipe." % id 
   641   
 642   
 645          if id == '': 
 646              self.text = "The empty residue ID corresponds to more than a single residue in the current data pipe." 
 647          else: 
 648              self.text = "The residue ID '%s' corresponds to more than a single residue in the current data pipe." % id 
   649   
 650   
 653          if id_list != None and id == '': 
 654              self.text = "The empty spin ID corresponds to multiple spins, including %s." % list_to_text(id_list) 
 655          elif id_list == None and id == '': 
 656              self.text = "The empty spin ID corresponds to more than a single spin in the current data pipe." 
 657          elif id_list != None: 
 658              self.text = "The spin ID '%s' corresponds to multiple spins, including %s." % (id, list_to_text(id_list)) 
 659          else: 
 660              self.text = "The spin ID '%s' corresponds to more than a single spin in the current data pipe." % id 
   661   
 662   
 665          if name == None: 
 666              self.text = "The residue '" + repr(number) + "' cannot be found in the sequence." 
 667          else: 
 668              self.text = "The residue '" + repr(number) + " " + name + "' cannot be found in the sequence." 
   669   
 670   
 673          if pipe == None: 
 674              self.text = "The spin '%s' does not exist." % id 
 675          else: 
 676              self.text = "The spin '%s' does not exist in the '%s' data pipe." % (id, pipe) 
   677   
 678   
 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   
 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   
 693   
 694   
 695   
 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   
 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   
 718          self.text = "The interatomic data is inconsistent between the data pipes '%s' and '%s'." % (pipe1, pipe2) 
   719   
 720   
 721   
 722   
 723   
 724   
 725   
 728          self.text = "Spectral data corresponding to the ID string '%s' does not exist." % spectrum_id 
   729   
 730   
 733          self.text = "Spectral data corresponding to the ID string '%s' already exists." % spectrum_id 
   734   
 735   
 736   
 737   
 738   
 739   
 742          self.text = "Relaxation data corresponding to the ID string '%s' does not exist." % ri_id 
   743   
 744   
 747          self.text = "Relaxation data corresponding to the ID string '%s' already exists." % ri_id 
   748   
 749   
 750   
 751   
 752   
 753   
 755 -    def __init__(self, align_id, pipe=None): 
  756          if pipe != None: 
 757              self.text = "The alignment ID string '%s' is missing from the data pipe '%s'." % (align_id, pipe) 
 758          else: 
 759              self.text = "The alignment ID string '%s' is missing." % align_id 
   760   
 761   
 764          self.text = "Alignment data corresponding to the ID string '%s' already exists." % align_id 
   765   
 766   
 769          if id: 
 770              self.text = "RDC data corresponding to the identification string " + repr(id) + " does not exist." 
 771          else: 
 772              self.text = "No RDC data exists." 
   773   
 774   
 777          self.text = "RDC data corresponding to the identification string " + repr(id) + " already exists." 
   778   
 779   
 782          if id: 
 783              self.text = "PCS data corresponding to the identification string " + repr(id) + " does not exist." 
 784          else: 
 785              self.text = "No PCS data exists." 
   786   
 787   
 790          self.text = "PCS data corresponding to the identification string " + repr(id) + " already exists." 
   791   
 792   
 793   
 794   
 795   
 796   
 799          self.text = "Model-free data corresponding to the data pipe " + repr(pipe) + " already exists." 
   800   
 801   
 802   
 803   
 804   
 805   
 808          self.text = "The " + tensor_type + " tensor data already exists." 
   809   
 810   
 812 -    def __init__(self, tensor_type, tensor_label=None): 
  813          if not tensor_label: 
 814              self.text = "No " + tensor_type + " tensor data exists." 
 815          else: 
 816              self.text = "No " + tensor_type + " tensor data exists for the tensor " + repr(tensor_label) + "." 
   817   
 818   
 819   
 820   
 821   
 822   
 825          if name == None: 
 826              self.text = "The directory " + repr(dir) + " does not exist." 
 827          else: 
 828              self.text = "The " + name + " directory " + repr(dir) + " does not exist." 
   829   
 830   
 832 -    def __init__(self, name, file_name=None): 
  833          if file_name == None: 
 834              self.text = "The file " + repr(name) + " does not exist." 
 835          else: 
 836              self.text = "The " + name + " file " + repr(file_name) + " does not exist." 
   837   
 838   
 841          self.text = "The file contains no data." 
   842   
 843   
 846          self.text = "The file " + repr(file_name) + " already exists.  Set the " + flag + " to True to overwrite." 
   847   
 848   
 851          self.text = "The format of the data is invalid." 
   852   
 853   
 854   
 855   
 856   
 857   
 860          self.text = "The data pipe bundle '%s' already exists." % bundle 
   861   
 862   
 865          if bundle != None: 
 866              self.text = "The data pipe bundle '%s' has not been created yet." % bundle 
 867          else: 
 868              self.text = "No data pipe bundles currently exist.  Please use the pipe.bundle user function first." 
   869   
 870   
 873          self.text = "The data pipe " + repr(pipe) + " already exists." 
   874   
 875   
 878          if pipe != None: 
 879              self.text = "The data pipe " + repr(pipe) + " has not been created yet." 
 880          else: 
 881              self.text = "No data pipes currently exist.  Please use the pipe.create user function first." 
   882   
 883   
 884   
 885   
 886   
 887   
 890          self.text = "The selection of molecules is not allowed." 
   891   
 892   
 895          self.text = "The selection of residues is not allowed." 
   896   
 897   
 900          self.text = "The selection of spin systems is not allowed." 
   901   
 902   
 905          self.text = "The spin system must be specified." 
   906   
 907   
 908   
 909   
 910   
 911   
 912   
 915          self.text = "This function is not available for " + string + "." 
   916   
 917   
 920          if name != None: 
 921              self.text = "The " + name + " model already exists." 
 922          else: 
 923              self.text = "The model already exists." 
   924   
 925   
 926   
 929          if name != None: 
 930              self.text = "The specific " + name + " model has not been selected or set up." 
 931          else: 
 932              self.text = "The specific model has not been selected or set up." 
   933   
 934   
 935   
 936   
 937   
 938   
 941          self.text = "The " + name + " argument " + repr(value) + " is not valid regular expression." 
   942   
 943   
 944   
 945   
 946   
 947   
 949 -    def __init__(self, name, param_type=None): 
  950          if param_type != None: 
 951              self.text = "The " + name + " parameter, " + repr(param_type) + ", cannot be set." 
 952          else: 
 953              self.text = "The " + name + " parameter cannot be set." 
   954   
 955   
 957 -    def __init__(self, data_type, pipe=None): 
  958          if pipe != None: 
 959              self.text = "The data type " + repr(data_type) + " already exists for the data pipe " + repr(pipe) + "." 
 960          else: 
 961              self.text = "The data type " + repr(data_type) + " already exists." 
   962   
 963   
 965 -    def __init__(self, name, spin_id=None, spin_id2=None): 
  966          if spin_id2 != None: 
 967              self.text = "The %s value has not yet been set for spins '%s' and '%s'." % (name, spin_id, spin_id2) 
 968          elif spin_id != None: 
 969              self.text = "The %s value has not yet been set for spin '%s'." % (name, spin_id) 
 970          else: 
 971              self.text = "The " + repr(name) + " value has not yet been set." 
   972   
 973   
 976          self.text = "The data type " + repr(name) + " is unknown." 
   977   
 978   
 980 -    def __init__(self, name, param_type=None): 
  981          if param_type != None: 
 982              self.text = "The " + name + " parameter, " + repr(param_type) + ", is unknown." 
 983          else: 
 984              self.text = "The " + name + " parameter is unknown." 
   985   
 986   
 989          self.text = "The " + repr(name) + " argument " + repr(data) + " represents an unknown parameter combination." 
   990   
 991   
 992   
 993   
 994   
 995   
 998          if pipe: 
 999              self.text = "Simulations for the data pipe " + repr(pipe) + " have not been setup." 
1000          else: 
1001              self.text = "Simulations have not been setup." 
  1002   
1003   
1004   
1005   
1006   
1007   
1010          self.text = "The style " + repr(style) + " is unknown." 
  1011   
1012   
1013   
1014   
1015   
1016   
1019          self.text = "The colour " + repr(colour) + " is invalid." 
  1020   
1021   
1022   
1023   
1024   
1025   
1028          self.text = "The invalid " + name + " floating point value of infinity has occurred." 
  1029   
1030   
1033          self.text = "The invalid " + name + " floating point value of NaN (Not a Number) has occurred." 
  1034   
1035   
1036   
1037   
1038   
1039   
1042          self.text = "The " + name + " data structure cannot be recreated from the XML elements as the structure is not empty." 
  1043   
1044   
1045   
1046   
1047   
1048   
1049   
1051      """Function for returning all the RelaxErrors to allow the AllRelaxError object to be created.""" 
1052   
1053       
1054      list = [] 
1055   
1056       
1057      for name in names: 
1058           
1059          object = globals()[name] 
1060   
1061           
1062          if not (isinstance(object, type(RelaxError)) or isinstance(object, type(type))) or not match('Relax', name): 
1063              continue 
1064   
1065           
1066          list.append(object) 
1067   
1068       
1069      return list 
 1070   
1071   
1072  AllRelaxErrors = tuple(all_errors(dir())) 
1073