1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Module for NOESY related operations."""
24
25
26 from re import search
27 from warnings import warn
28
29
30 from lib.errors import RelaxError, RelaxNoSequenceError
31 from lib.io import open_read_file
32 from lib.software import xplor
33 from lib.warnings import RelaxWarning
34 from pipe_control import pipes
35 from pipe_control.mol_res_spin import exists_mol_res_spin_data, return_spin, tokenise
36
37
57
58
59 -def parse_noe_restraints(lines, proton1_col=None, proton2_col=None, lower_col=None, upper_col=None, sep=None):
60 """Parse and return the NOE restraints from the generic formatted file.
61
62 @param lines: The file, or file fragment, split into lines.
63 @type lines: list of str
64 @keyword proton1_col: The column containing the first proton of the NOE or ROE cross peak.
65 @type proton1_col: None or int
66 @keyword proton2_col: The column containing the second proton of the NOE or ROE cross peak.
67 @type proton2_col: None or int
68 @keyword lower_col: The column containing the lower NOE bound.
69 @type lower_col: None or int
70 @keyword upper_col: The column containing the upper NOE bound.
71 @type upper_col: None or int
72 @keyword sep: The column separator (the default is white space).
73 @type sep: None or str
74 @return: The NOE restraint list in the format of two atom identification strings
75 and the lower and upper restraints.
76 @rtype: list of lists of [str, str, float, float]
77 """
78
79
80 if proton1_col == None:
81 warn(RelaxWarning("The proton1_col argument has not been supplied, defaulting to column 1."))
82 proton1_col = 1
83 if proton2_col == None:
84 warn(RelaxWarning("The proton2_col argument has not been supplied, defaulting to column 2."))
85 proton2_col = 2
86 if lower_col == None:
87 warn(RelaxWarning("The lower_col argument has not been supplied, defaulting to column 3."))
88 lower_col = 3
89 if upper_col == None:
90 warn(RelaxWarning("The upper_col argument has not been supplied, defaulting to column 4."))
91 upper_col = 4
92
93
94 data = []
95 for line in lines:
96
97 row = line.split(sep)
98
99
100 if len(row) < 4:
101 continue
102 try:
103 tokenise(row[proton1_col-1])
104 except RelaxError:
105 continue
106
107
108 data.append([row[proton1_col-1], row[proton2_col-1], float(row[lower_col-1]), float(row[upper_col-1])])
109
110
111 return data
112
113
114 -def read_restraints(file=None, dir=None, proton1_col=None, proton2_col=None, lower_col=None, upper_col=None, sep=None):
115 """Load NOESY or ROESY constraint information from file.
116
117 If the input file is a pre-formatted Xplor file, the column number and separator arguments will
118 be ignored.
119
120
121 @keyword file: The name of the file containing the relaxation data.
122 @type file: str
123 @keyword dir: The directory where the file is located.
124 @type dir: None or str
125 @keyword proton1_col: The column containing the first proton of the NOE or ROE cross peak.
126 @type proton1_col: None or int
127 @keyword proton2_col: The column containing the second proton of the NOE or ROE cross peak.
128 @type proton2_col: None or int
129 @keyword lower_col: The column containing the lower NOE bound.
130 @type lower_col: None or int
131 @keyword upper_col: The column containing the upper NOE bound.
132 @type upper_col: None or int
133 @keyword sep: The column separator (the default is white space).
134 @type sep: None or str
135 """
136
137
138 pipes.test()
139
140
141 if not exists_mol_res_spin_data():
142 raise RelaxNoSequenceError
143
144
145 file = open_read_file(file_name=file, dir=dir)
146 lines = file.readlines()
147 file.close()
148
149
150 format = __file_format(lines)
151
152
153 if format == 'xplor':
154 noe_restraints = xplor.parse_noe_restraints(lines)
155 elif format == 'generic':
156 noe_restraints = parse_noe_restraints(lines, proton1_col=proton1_col, proton2_col=proton2_col, lower_col=lower_col, upper_col=upper_col, sep=sep)
157
158
159 for i in range(len(noe_restraints)):
160
161 for j in range(2):
162
163 if isinstance(noe_restraints[i][j], str):
164 continue
165
166
167 pseudo_name = None
168 for k in range(len(noe_restraints[i][j])):
169
170 spin = return_spin(noe_restraints[i][j][k])
171
172
173 if pseudo_name and pseudo_name != spin.pseudo_name:
174 raise RelaxError("The pseudoatom names '%s' and '%s' do not match." % (pseudo_name, spin.pseudo_name))
175
176
177 pseudo_name = spin.pseudo_name
178
179
180 if not pseudo_name:
181 raise RelaxError("Cannot find the pseudoatom corresponding to the atoms in %s." % noe_restraints[i][j])
182
183
184 noe_restraints[i][j] = pseudo_name
185
186
187 cdp.noe_restraints = noe_restraints
188
189
190 for restraint in cdp.noe_restraints:
191 if not return_spin(restraint[0]):
192 raise RelaxError("The spin container corresponding to '%s' cannot be found." % restraint[0])
193 if not return_spin(restraint[1]):
194 raise RelaxError("The spin container corresponding to '%s' cannot be found." % restraint[1])
195