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