1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 """Module containing all of the RelaxError objects."""
25
26
27
28 try:
29 from bz2 import BZ2File
30 bz2 = True
31 except ImportError:
32 bz2 = False
33 from re import match, search
34 import sys
35 import time
36
37
38 from lib import ansi
39 from lib.compat import pickle
40 from lib.text.string import human_readable_list
41
42
43
44 SAVE_ERROR_STATE = False
45
46
47 ARRAY = 'a list or numpy array'
48 ARRAY_FLOAT = 'a list or numpy array of floats'
49 ARRAY_INT = 'a list or numpy array of integers'
50 ARRAY_NUM = 'a list or numpy array of numbers'
51 BIN = 'a binary number (0 or 1)'
52 BOOL = 'a Boolean (True or False)'
53 INT = 'an integer'
54 FILE = 'a file object'
55 FLOAT = 'a floating point number'
56 FUNC = 'a function'
57 LIST = 'a list'
58 LIST_BOOL = 'a list of Booleans'
59 LIST_FLOAT = 'a list of floating point numbers'
60 LIST_INT = 'a list of integers'
61 LIST_NUM = 'a list of numbers'
62 LIST_STR = 'a list of strings'
63 LIST_VAL = 'a list of values'
64 MATRIX_FLOAT = 'a matrix of floating point numbers'
65 NONE = 'None'
66 NUMPY_FLOAT = 'a numpy array of floats'
67 NUMPY_INT = 'a numpy array of integers'
68 NUMPY_NUM = 'a numpy array of numbers'
69 NUM = 'a number'
70 TUPLE = 'a tuple'
71 TUPLE_FLOAT = 'a tuple of floating point numbers'
72 TUPLE_INT = 'a tuple of integers'
73 TUPLE_NUM = 'a tuple of numbers'
74 TUPLE_STR = 'a tuple of strings'
75 STR = 'a string'
76 VAL = 'a value'
77
78
80 """Save the program state, for debugging purposes."""
81
82
83 try:
84 from data_store import Relax_data_store; ds = Relax_data_store()
85
86
87 except ImportError:
88 return
89
90
91 now = time.localtime()
92 file_name = "relax_state_%i%02i%02i_%02i%02i%02i" % (now[0], now[1], now[2], now[3], now[4], now[5])
93
94
95 if bz2:
96 sys.stderr.write("\nStoring the relax state in the file '%s.bz2'.\n\n" % file_name)
97 file = BZ2File(file_name+'.bz2', 'w')
98 else:
99 sys.stderr.write("\nStoring the relax state in the file '%s'.\n\n" % file_name)
100 file = open(file_name, 'w')
101
102
103 pickle.dump(ds, file, 1)
104
105
106 file.close()
107
108
109 -def list_to_text(data):
110 """Convert the given Python list to a text representation.
111
112 @param data: The list of Python objects.
113 @type data: list
114 @return: The English text version of the list.
115 @rtype: str
116 """
117
118
119 text = ''
120
121
122 for i in range(len(data)):
123
124 text += repr(data[i])
125
126
127 if i < len(data) - 2:
128 text += ', '
129
130
131 if i == len(data) - 2:
132 text += ' and '
133
134
135 return text
136
137
138
139
140
142 """The base class for all RelaxErrors."""
143
156
157
159 """The base class for all the argument related RelaxErrors."""
160
161
162 simple_types = []
163
164
165 list_types = []
166
167
168 - def __init__(self, name, value, size=None, dim=None, rank=None, can_be_none=False):
169 """A default initialisation and error message formatting method.
170
171 @param name: The name of the argument.
172 @type name: str
173 @param value: The argument's value.
174 @type value: anything
175 @keyword size: The fixed size for list types.
176 @type size: int or None
177 @keyword dim: The expected dimensionality of the argument.
178 @type dim: tuple of (int or None)
179 @keyword rank: The rank for list or array types.
180 @type rank: int or None
181 @keyword can_be_none: A flag specifying if the argument can be None. This will tag the text ', or None' to the end of the RelaxError.
182 @type can_be_none: bool
183 """
184
185
186 value_str = repr(value)
187 if search("^array", value_str):
188 value_str = value_str.replace("\n", "")
189 value_str = ''.join(value_str.split())
190
191
192 self.text = "The %s argument %s must be " % (name, value_str)
193
194
195 all_types = []
196
197
198 for i in range(len(self.simple_types)):
199 all_types.append(self.simple_types[i])
200
201
202 for i in range(len(self.list_types)):
203
204 supp_list = []
205 if size != None:
206 supp_list.append("size %s" % repr(size))
207 if rank != None:
208 supp_list.append("rank %i" % rank)
209 if dim != None:
210 supp_list.append("dimensionality %s" % repr(dim))
211
212
213 if len(supp_list):
214 all_types.append("%s of %s" % (self.list_types[i], human_readable_list(supp_list, conjunction="or")))
215 else:
216 all_types.append("%s" % self.list_types[i])
217
218
219 if can_be_none:
220 all_types.append('None')
221
222
223 if len(all_types) > 1:
224 self.text = self.text + "either "
225
226
227 self.text += human_readable_list(all_types, conjunction="or")
228
229
230 self.text = self.text + "."
231
232
233
234
235
239
240
241
242
243
246 self.text = "The %s module '%s' cannot be found. Please check that it is installed." % (desc, name)
247
248
249
250
251
254 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/."
255
257
258 save_state()
259
260
261 return ("RelaxError: " + self.text + "\n")
262
263
264
265
266
267
270 if fn_name:
271 self.text = "The %s function has not yet been implemented for the current data pipe." % fn_name
272 else:
273 self.text = "This has not yet been implemented for the current data pipe."
274
275
276
277
278
279
282 self.text = "The program " + repr(name) + " cannot be found."
283
284
285
288 self.text = "The binary executable file " + repr(name) + " does not exist."
289
290
291
294 self.text = "The binary executable file " + repr(name) + " is not executable."
295
296
297
300 self.text = "The binary executable file " + repr(name) + " is not located within the system path."
301
302
303
306 self.text = "Execution of the program " + name + " has failed."
307
308
309
310
311
312
315 if pipe != None:
316 self.text = "PDB data corresponding to the data pipe " + repr(pipe) + " already exists."
317 else:
318 self.text = "PDB data already exists."
319
320
323 if pipe != None:
324 self.text = "No PDB file has been loaded for the data pipe " + repr(pipe) + "."
325 else:
326 self.text = "No PDB file has been loaded."
327
328
331 self.text = "The PDB file " + repr(name) + " could not be loaded properly, no molecular chains could be extracted."
332
333
336 if spin_id != None:
337 self.text = "The multiple unit XH bond vectors for the spin '%s' - this is not supported by the current data pipe type." % spin_id
338 else:
339 self.text = "The multiple unit XH bond vectors per spin - this is not supported by the current data pipe type."
340
341
344 if pipe:
345 self.text = "No unit vectors have been calculated for the data pipe '%s'" % pipe
346 else:
347 self.text = "No unit vectors have been calculated."
348
349
352 self.text = "No peptide or nucleotide chains can be found within the PDB file."
353
354
355
356
357
358
361 if spin_id != None:
362 self.text = "The type of nucleus for the spin '%s' has not yet been set." % spin_id
363 else:
364 self.text = "The type of nucleus has not yet been set."
365
366
369 if spin_id != None:
370 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
371 else:
372 self.text = "The nuclear isotope type has not yet been set. Please use the spin.isotope user function to set the type."
373
374
375
376
377
378
379
380
381
382
385 self.text = "The " + name + " argument " + repr(value) + " is invalid."
386
387
390 self.text = "The " + name + " argument " + repr(value) + " is neither "
391 for i in range(len(list)-1):
392 self.text = self.text + repr(list[i]) + ', '
393 self.text = self.text + 'nor ' + repr(list[-1]) + "."
394
395
398 self.text = "The " + name + " argument must be of length " + repr(len) + "."
399
400
403 self.text = "The " + name + " argument has not been supplied."
404
405
408 self.text = "The %s argument of '%s' must be None."
409
410
411
412
413
414
417
420
421
424
425
428
431
432
435
438
439
442
445
446
449
452
453
456
459
460
461
462
463
464
467
470
471
474
477
478
479
480
481
482
483
486
487
490
491
494
495
498
499
502
506
507
510
514
515
518
521
522
525
526
529
530
534
535
538
542
543
546
550
551
554
555
558
559
562
563
564
565
566
567
571
572
576
577
581
585
586
590
594
595
599
603
604
608
609
613
617
618
622
626
627
631
635
636
640
644
645
646
647
648
649
652
656
657
660
664
665
666
667
668
669
673
674
678
682
683
684
685
686
687
690
693
694
695
696
697
698
699
702 if pipe == None:
703 self.text = "The sequence data does not exist."
704 else:
705 self.text = "The sequence data for the data pipe " + repr(pipe) + " does not exist."
706
707
710 if pipe == None:
711 self.text = "The sequence data already exists."
712 else:
713 self.text = "The sequence data for the data pipe " + repr(pipe) + " already exists."
714
715
718 self.text = "The sequences for the data pipes " + repr(pipe1) + " and " + repr(pipe2) + " are not the same."
719
720
723 self.text = "The number of molecules do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
724
725
728 self.text = "The number of residues do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
729
730
733 self.text = "The number of spins do not match between pipes '%s' and '%s'." % (pipe1, pipe2)
734
735
738 if id == '':
739 self.text = "The empty molecule ID corresponds to more than a single molecule in the current data pipe."
740 else:
741 self.text = "The molecule ID '%s' corresponds to more than a single molecule in the current data pipe." % id
742
743
746 if id == '':
747 self.text = "The empty residue ID corresponds to more than a single residue in the current data pipe."
748 else:
749 self.text = "The residue ID '%s' corresponds to more than a single residue in the current data pipe." % id
750
751
754 if id_list != None and id == '':
755 self.text = "The empty spin ID corresponds to multiple spins, including %s." % list_to_text(id_list)
756 elif id_list == None and id == '':
757 self.text = "The empty spin ID corresponds to more than a single spin in the current data pipe."
758 elif id_list != None:
759 self.text = "The spin ID '%s' corresponds to multiple spins, including %s." % (id, list_to_text(id_list))
760 else:
761 self.text = "The spin ID '%s' corresponds to more than a single spin in the current data pipe." % id
762
763
766 if name == None:
767 self.text = "The residue '" + repr(number) + "' cannot be found in the sequence."
768 else:
769 self.text = "The residue '" + repr(number) + " " + name + "' cannot be found in the sequence."
770
771
774 if pipe == None:
775 self.text = "The spin '%s' does not exist." % id
776 else:
777 self.text = "The spin '%s' does not exist in the '%s' data pipe." % (id, pipe)
778
779
781 - def __init__(self, line, problem=None):
782 if problem == None:
783 self.text = "The sequence data in the line %s is invalid." % line
784 else:
785 self.text = "The sequence data in the line %s is invalid, %s." % (line, problem)
786
787
790 self.text = "The spin information for the spin " + repr(spin_id) + " has not yet been loaded, please use the structure.load_spins user function."
791
792
793
794
795
796
798 - def __init__(self, spin_id1=None, spin_id2=None, pipe=None):
799 if spin_id1 and pipe:
800 self.text = "The interatomic data between the spins '%s' and '%s' for the data pipe '%s' does not exist." % (spin_id1, spin_id2, pipe)
801 elif spin_id1:
802 self.text = "The interatomic data between the spins '%s' and '%s' does not exist." % (spin_id1, spin_id2)
803 elif pipe:
804 self.text = "The interatomic data for the data pipe '%s' does not exist." % pipe
805 else:
806 self.text = "The interatomic data does not exist."
807
808
811 if pipe == None:
812 self.text = "The interatomic data already exists."
813 else:
814 self.text = "The interatomic data for the data pipe " + repr(pipe) + " already exists."
815
816
819 self.text = "The interatomic data is inconsistent between the data pipes '%s' and '%s'." % (pipe1, pipe2)
820
821
822
823
824
825
826
827 -class RelaxNoDomainError(BaseError):
828 - def __init__(self, id=None):
829 if id == None:
830 self.text = "No domains are defined."
831 else:
832 self.text = "The domain '%s' is not defined." % id
833
834
835
836
837
838
839
841 - def __init__(self, pipe_name=None, id=None):
842 self.text = "No spectrometer frequency information"
843 if id != None:
844 self.text += " for the '%s' experiment ID" % id
845 self.text += " is present"
846 if pipe_name != None:
847 self.text += " in the '%s' data pipe" % pipe_name
848 self.text += "."
849
850
851
852
853
854
855
858 if spectrum_id == None:
859 self.text = "No peak intensity data has been loaded."
860 else:
861 self.text = "Peak intensity data for the '%s' spectrum ID does not exist."
862
863
866 self.text = "Spectral data corresponding to the ID string '%s' does not exist." % spectrum_id
867
868
871 self.text = "Spectral data corresponding to the ID string '%s' already exists." % spectrum_id
872
873
874
875
876
877
880 self.text = "Relaxation data corresponding to the ID string '%s' does not exist." % ri_id
881
882
885 self.text = "Relaxation data corresponding to the ID string '%s' already exists." % ri_id
886
887
888
889
890
891
894 self.text = "No J coupling data exists."
895
896
899 self.text = "J coupling data already exists."
900
901
902
903
904
905
907 - def __init__(self, align_id, pipe=None):
908 if pipe != None:
909 self.text = "The alignment ID string '%s' is missing from the data pipe '%s'." % (align_id, pipe)
910 else:
911 self.text = "The alignment ID string '%s' is missing." % align_id
912
913
916 self.text = "Alignment data corresponding to the ID string '%s' already exists." % align_id
917
918
921 if id:
922 self.text = "RDC data corresponding to the identification string " + repr(id) + " does not exist."
923 else:
924 self.text = "No RDC data exists."
925
926
929 self.text = "RDC data corresponding to the identification string " + repr(id) + " already exists."
930
931
934 if id:
935 self.text = "PCS data corresponding to the identification string " + repr(id) + " does not exist."
936 else:
937 self.text = "No PCS data exists."
938
939
942 self.text = "PCS data corresponding to the identification string " + repr(id) + " already exists."
943
944
945
946
947
948
951 self.text = "Model-free data corresponding to the data pipe " + repr(pipe) + " already exists."
952
953
954
955
956
957
960 self.text = "The " + tensor_type + " tensor data already exists."
961
962
964 - def __init__(self, tensor_type, tensor_label=None):
965 if not tensor_label:
966 self.text = "No " + tensor_type + " tensor data exists."
967 else:
968 self.text = "No " + tensor_type + " tensor data exists for the tensor " + repr(tensor_label) + "."
969
970
971
972
973
974
977 if name == None:
978 self.text = "The directory " + repr(dir) + " does not exist."
979 else:
980 self.text = "The " + name + " directory " + repr(dir) + " does not exist."
981
982
984 - def __init__(self, name, file_name=None):
985 if file_name == None:
986 self.text = "The file " + repr(name) + " does not exist."
987 else:
988 self.text = "The " + name + " file " + repr(file_name) + " does not exist."
989
990
993 self.text = "The file contains no data."
994
995
998 self.text = "The file " + repr(file_name) + " already exists. Set the " + flag + " to True to overwrite."
999
1000
1003 self.text = "The format of the data is invalid."
1004
1005
1006
1007
1008
1009
1012 self.text = "The data pipe bundle '%s' already exists." % bundle
1013
1014
1017 if bundle != None:
1018 self.text = "The data pipe bundle '%s' has not been created yet." % bundle
1019 else:
1020 self.text = "No data pipe bundles currently exist. Please use the pipe.bundle user function first."
1021
1022
1025 self.text = "The data pipe " + repr(pipe) + " already exists."
1026
1027
1030 if pipe != None:
1031 self.text = "The data pipe " + repr(pipe) + " has not been created yet."
1032 else:
1033 self.text = "No data pipes currently exist. Please use the pipe.create user function first."
1034
1035
1036
1037
1038
1039
1042 self.text = "The selection of molecules is not allowed."
1043
1044
1047 self.text = "The selection of residues is not allowed."
1048
1049
1052 self.text = "The selection of spin systems is not allowed."
1053
1054
1057 self.text = "The spin system must be specified."
1058
1059
1060
1061
1062
1063
1064
1067 self.text = "This function is not available for " + string + "."
1068
1069
1072 if name != None:
1073 self.text = "The " + name + " model already exists."
1074 else:
1075 self.text = "The model already exists."
1076
1077
1078
1081 if name != None:
1082 self.text = "The specific " + name + " model has not been selected or set up."
1083 else:
1084 self.text = "The specific model has not been selected or set up."
1085
1086
1087
1088
1089
1090
1093 self.text = "The " + name + " argument " + repr(value) + " is not valid regular expression."
1094
1095
1096
1097
1098
1099
1101 - def __init__(self, name, param_type=None):
1102 if param_type != None:
1103 self.text = "The " + name + " parameter, " + repr(param_type) + ", cannot be set."
1104 else:
1105 self.text = "The " + name + " parameter cannot be set."
1106
1107
1109 - def __init__(self, data_type, pipe=None):
1110 if pipe != None:
1111 self.text = "The data type " + repr(data_type) + " already exists for the data pipe " + repr(pipe) + "."
1112 else:
1113 self.text = "The data type " + repr(data_type) + " already exists."
1114
1115
1117 - def __init__(self, name, spin_id=None, spin_id2=None):
1118 if spin_id2 != None:
1119 self.text = "The %s value has not yet been set for spins '%s' and '%s'." % (name, spin_id, spin_id2)
1120 elif spin_id != None:
1121 self.text = "The %s value has not yet been set for spin '%s'." % (name, spin_id)
1122 else:
1123 self.text = "The " + repr(name) + " value has not yet been set."
1124
1125
1128 self.text = "The data type " + repr(name) + " is unknown."
1129
1130
1132 - def __init__(self, name, param_type=None):
1133 if param_type != None:
1134 self.text = "The " + name + " parameter, " + repr(param_type) + ", is unknown."
1135 else:
1136 self.text = "The " + name + " parameter is unknown."
1137
1138
1141 self.text = "The " + repr(name) + " argument " + repr(data) + " represents an unknown parameter combination."
1142
1143
1144
1145
1146
1147
1150 if pipe:
1151 self.text = "Simulations for the data pipe " + repr(pipe) + " have not been setup."
1152 else:
1153 self.text = "Simulations have not been setup."
1154
1155
1156
1157
1158
1159
1162 self.text = "The style " + repr(style) + " is unknown."
1163
1164
1165
1166
1167
1168
1171 self.text = "The colour " + repr(colour) + " is invalid."
1172
1173
1174
1175
1176
1177
1180 self.text = "The invalid " + name + " floating point value of infinity has occurred."
1181
1182
1185 self.text = "The invalid " + name + " floating point value of NaN (Not a Number) has occurred."
1186
1187
1188
1189
1190
1191
1194 self.text = "The " + name + " data structure cannot be recreated from the XML elements as the structure is not empty."
1195
1196
1197
1198
1199
1200
1201
1222
1223
1224 AllRelaxErrors = tuple(all_errors(dir()))
1225