1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 """Package for interfacing with the U{BioMagResBank<http://www.bmrb.wisc.edu/>}.
24
25 The Biological Magnetic Resonance Data Bank, or BioMagResBank and BMRB for short, is a repository for data from NMR spectroscopy on proteins, peptides, nucleic acids, and other biomolecules. This U{bmrblib library<https://sourceforge.net/projects/bmrblib/>} handles the U{NMR-STAR formatted files<http://www.bmrb.wisc.edu/dictionary/>}, the base format of all BMRB data. It can both read and write NMR-STAR files.
26 """
27
28
29 __version__ = '1.0.2'
30
31
32 __all__ = ['base_classes',
33 'misc',
34 'nmr_star_dict',
35 'nmr_star_dict_v2_1',
36 'nmr_star_dict_v3_1']
37
38
39 from os import F_OK, access
40 from re import search
41 import sys
42
43
44 from bmrblib.nmr_star_dict_v2_1 import NMR_STAR_v2_1
45 from bmrblib.nmr_star_dict_v3_1 import NMR_STAR_v3_1
46 from bmrblib.version import Star_version
47
48
50 """Initialise the NMR-STAR object.
51
52 @param title: The title of the NMR-STAR data.
53 @type title: str
54 @param file_path: The full file path.
55 @type file_path: str
56 @keyword version: The NMR-STAR version to use.
57 @type version: str
58 @return: The NMR-STAR python object.
59 @rtype: class instance
60 """
61
62
63 if not version and access(file_path, F_OK):
64 version = determine_version(file_path)
65
66
67 if not version:
68 version = '3.1'
69
70
71 star_version = Star_version()
72 star_version.set_version(version)
73
74
75 sys.stdout.write("NMR-STAR version %s\n" % star_version.version)
76
77
78 if star_version.major == 3:
79 star = NMR_STAR_v3_1('relax_model_free_results', file_path)
80 elif star_version.major == 2:
81 star = NMR_STAR_v2_1('relax_model_free_results', file_path)
82 else:
83 raise NameError("The NMR-STAR version %s is unknown." % star_version.version)
84
85
86 return star
87
88
90 """Determine the version of the given NMR-STAR file.
91
92 @param file_path: The full file path.
93 @type file_path: str
94 @return: The NMR-STAR version number.
95 @rtype: str
96 """
97
98
99 file = open(file_path)
100 lines = file.readlines()
101 file.close()
102
103
104 for line in lines:
105
106 if search('\.NMR_STAR_version', line) or search('_NMR_STAR_version', line):
107
108 row = line.split()
109
110
111 return row[1]
112