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