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 BMRB support."""
25
26
27 from os import F_OK, access
28 import sys
29
30
31 from data import Relax_data_store; ds = Relax_data_store()
32 from data.exp_info import ExpInfo
33 import dep_check
34 from generic_fns import exp_info
35 from generic_fns.mol_res_spin import create_spin, generate_spin_id, return_residue, return_spin
36 from info import Info_box
37 from relax_errors import RelaxError, RelaxFileError, RelaxFileOverwriteError, RelaxNoModuleInstallError, RelaxNoPipeError
38 from relax_io import get_file_path, mkdir_nofail
39 import specific_fns
40 from version import version_full
41
42
59
60
61 -def generate_sequence(N=0, spin_ids=None, spin_nums=None, spin_names=None, res_nums=None, res_names=None, mol_names=None):
62 """Generate the sequence data from the BRMB information.
63
64 @keyword N: The number of spins.
65 @type N: int
66 @keyword spin_ids: The list of spin IDs.
67 @type spin_ids: list of str
68 @keyword spin_nums: The list of spin numbers.
69 @type spin_nums: list of int or None
70 @keyword spin_names: The list of spin names.
71 @type spin_names: list of str or None
72 @keyword res_nums: The list of residue numbers.
73 @type res_nums: list of int or None
74 @keyword res_names: The list of residue names.
75 @type res_names: list of str or None
76 @keyword mol_names: The list of molecule names.
77 @type mol_names: list of str or None
78 """
79
80
81 if not spin_nums:
82 spin_nums = [None] * N
83 if not spin_names:
84 spin_names = [None] * N
85 if not res_nums:
86 res_nums = [None] * N
87 if not res_names:
88 res_names = [None] * N
89 if not mol_names:
90 mol_names = [None] * N
91
92
93 spin_ids = []
94 for i in range(N):
95 spin_ids.append(generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], spin_name=spin_names[i]))
96
97
98 for i in range(N):
99
100 spin = return_spin(spin_ids[i])
101 if spin:
102 continue
103
104
105 if not mol_names:
106 res_id = generate_spin_id(res_num=res_nums[i], res_name=res_names[i])
107 else:
108 res_id = generate_spin_id(mol_name=mol_names[i], res_num=res_nums[i], res_name=res_names[i])
109
110
111 res_cont = return_residue(res_id)
112 if res_cont and len(res_cont.spin) == 1 and res_cont.spin[0].name == None and res_cont.spin[0].num == None:
113
114 res_cont.spin[0].name = spin_names[i]
115 res_cont.spin[0].num = spin_nums[i]
116
117
118 continue
119
120
121 create_spin(spin_num=spin_nums[i], spin_name=spin_names[i], res_num=res_nums[i], res_name=res_names[i], mol_name=mol_names[i])
122
123
125 """Get a listing of all the sample conditions.
126
127 @param star: The NMR-STAR dictionary object.
128 @type star: NMR_STAR instance
129 @return: The list of sample condition names.
130 @rtype: list of str
131 """
132
133
134 sample_conds = []
135
136
137 for data in star.sample_conditions.loop():
138
139 sample_conds.append(data['sf_framecode'])
140
141
142 return sample_conds
143
144
146 """Generate the molecule names list.
147
148 @param data: An element of data from bmrblib.
149 @type data: dict
150 @return: The list of molecule names.
151 @rtype: list of str
152 """
153
154
155 mol_index = []
156 for i in range(N):
157 if 'entity_ids' in data.keys() and data['entity_ids'] != None and data['entity_ids'][i] != None:
158 mol_index.append(int(data['entity_ids'][i]) -1 )
159 else:
160 mol_index = [0]*N
161 mol_names = []
162 for i in range(N):
163 mol_names.append(cdp.mol[mol_index[i]].name)
164
165
166 return mol_names
167
168
170 """Determine the number of spins in the given data.
171
172 @param data: An element of data from bmrblib.
173 @type data: dict
174 @return: The number of spins.
175 @rtype: int
176 """
177
178
179 N = 0
180
181
182 keys = ['data_ids', 'entity_ids', 'res_names', 'res_nums', 's2']
183
184
185 for key in keys:
186 if key in data.keys() and data[key]:
187 N = len(data[key])
188 break
189
190
191 return N
192
193
194 -def read(file=None, directory=None, version=None, sample_conditions=None):
231
232
233 -def write(file=None, directory=None, version='3.1', force=False):
234 """Create a BMRB NMR-STAR formatted file."""
235
236
237 if not dep_check.bmrblib_module:
238 raise RelaxNoModuleInstallError('BMRB library', 'bmrblib')
239
240
241 if not ds.current_pipe:
242 raise RelaxNoPipeError
243
244
245 if directory == 'pipe_name':
246 directory = ds.current_pipe
247
248
249 write_function = specific_fns.setup.get_specific_fn('bmrb_write', ds[ds.current_pipe].pipe_type)
250
251
252 file_path = get_file_path(file, directory)
253
254
255 if access(file_path, F_OK) and not force:
256 raise RelaxFileOverwriteError(file_path, 'force flag')
257
258
259 print("Opening the file '%s' for writing." % file_path)
260
261
262 mkdir_nofail(directory, verbosity=0)
263
264
265 info = Info_box()
266
267
268 for id, key in zip(['relax_ref1', 'relax_ref2'], ['dAuvergneGooley08a', 'dAuvergneGooley08b']):
269
270 bib = info.bib[key]
271
272
273 cdp.exp_info.add_citation(cite_id=id, authors=bib.author2, doi=bib.doi, pubmed_id=bib.pubmed_id, full_citation=bib.cite_short(doi=False, url=False), title=bib.title, status=bib.status, type=bib.type, journal_abbrev=bib.journal, journal_full=bib.journal_full, volume=bib.volume, issue=bib.number, page_first=bib.page_first, page_last=bib.page_last, year=bib.year)
274
275
276 cdp.exp_info.software_setup(name=exp_info.SOFTWARE['relax'].name, version=version_full(), vendor_name=exp_info.SOFTWARE['relax'].authors, url=exp_info.SOFTWARE['relax'].url, cite_ids=['relax_ref1', 'relax_ref2'], tasks=exp_info.SOFTWARE['relax'].tasks)
277
278
279 write_function(file_path, version=version)
280