1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 """Module containing functions for handling NMRView files."""
26
27
28
29 from warnings import warn
30
31
32 from lib.errors import RelaxError
33 from lib.io import strip
34 from lib.warnings import RelaxWarning
35
36
37 -def read_list(peak_list=None, file_data=None, int_col=None):
38 """Extract the peak intensity information from the NMRView peak intensity file.
39
40 @keyword peak_list: The peak list object to place all data into.
41 @type peak_list: lib.spectrum.objects.Peak_list instance
42 @keyword file_data: The data extracted from the file converted into a list of lists.
43 @type file_data: list of lists of str
44 @keyword int_col: The column containing the peak intensity data. The default is 16 for intensities. Setting the int_col argument to 15 will use the volumes (or evolumes). For a non-standard formatted file, use a different value.
45 @type int_col: int
46 @raises RelaxError: When the expected peak intensity is not a float.
47 """
48
49
50 num = 6
51 print("Number of header lines: %s" % num)
52
53
54 file_data = file_data[num:]
55
56
57 file_data = strip(file_data)
58
59
60 w2_col = 2
61 w1_col = 9
62
63
64 if int_col == None:
65 int_col = 16
66 if int_col == 16:
67 print('Using peak heights.')
68 if int_col == 15:
69 print('Using peak volumes (or evolumes).')
70
71
72 for line in file_data:
73
74 if line[1] == '{}':
75 warn(RelaxWarning("The assignment '%s' is unknown, skipping this peak." % line[1]))
76 continue
77
78
79 res_num = ''
80 try:
81 res_num = line[1].strip('{')
82 res_num = res_num.strip('}')
83 res_num = res_num.split('.')
84 res_num = int(res_num[0])
85 except ValueError:
86 raise RelaxError("Improperly formatted NMRView file, cannot process the assignment '%s'." % line[1])
87
88
89 name2 = ''
90 if line[1]!='{}':
91 name2 = line[1].strip('{')
92 name2 = name2.strip('}')
93 name2 = name2.split('.')
94 name2 = name2[1]
95 name1 = ''
96 if line[8]!='{}':
97 name1 = line[8].strip('{')
98 name1 = name1.strip('}')
99 name1 = name1.split('.')
100 name1 = name1[1]
101
102
103 w1 = None
104 w2 = None
105 if w1_col != None:
106 try:
107 w1 = float(line[w1_col])
108 except ValueError:
109 raise RelaxError("The chemical shift from the line %s is invalid." % line)
110 if w2_col != None:
111 try:
112 w2 = float(line[w2_col])
113 except ValueError:
114 raise RelaxError("The chemical shift from the line %s is invalid." % line)
115
116
117 try:
118 intensity = float(line[int_col])
119 except ValueError:
120 raise RelaxError("The peak intensity value " + repr(intensity) + " from the line " + repr(line) + " is invalid.")
121
122
123 peak_list.add(res_nums=[res_num, res_num], spin_names=[name1, name2], shifts=[w1, w2], intensity=intensity)
124