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 This file is part of the U{BMRB library<https://gna.org/projects/bmrblib>}.
26
27 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://gna.org/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.
28 """
29
30
31 __version__ = 'trunk'
32
33
34 __all__ = ['base_classes',
35 'misc',
36 'nmr_star_dict',
37 'nmr_star_dict_v2_1',
38 'nmr_star_dict_v3_1']
39
40
41 from os import F_OK, access
42 from re import search
43 import sys
44
45
46 from bmrblib.nmr_star_dict_v2_1 import NMR_STAR_v2_1
47 from bmrblib.nmr_star_dict_v3_1 import NMR_STAR_v3_1
48 from bmrblib.version import Star_version
49
50
52 """Initialise the NMR-STAR object.
53
54 @param title: The title of the NMR-STAR data.
55 @type title: str
56 @param file_path: The full file path.
57 @type file_path: str
58 @keyword version: The NMR-STAR version to use.
59 @type version: str
60 @return: The NMR-STAR python object.
61 @rtype: class instance
62 """
63
64
65 if not version and access(file_path, F_OK):
66 version = determine_version(file_path)
67
68
69 if not version:
70 version = '3.1'
71
72
73 star_version = Star_version()
74 star_version.set_version(version)
75
76
77 sys.stdout.write("NMR-STAR version %s\n" % star_version.version)
78
79
80 if star_version.major == 3:
81 star = NMR_STAR_v3_1('relax_model_free_results', file_path)
82 elif star_version.major == 2:
83 star = NMR_STAR_v2_1('relax_model_free_results', file_path)
84 else:
85 raise NameError("The NMR-STAR version %s is unknown." % star_version.version)
86
87
88 return star
89
90
92 """Determine the version of the given NMR-STAR file.
93
94 @param file_path: The full file path.
95 @type file_path: str
96 @return: The NMR-STAR version number.
97 @rtype: str
98 """
99
100
101 file = open(file_path)
102 lines = file.readlines()
103 file.close()
104
105
106 for line in lines:
107
108 if search('\.NMR_STAR_version', line) or search('_NMR_STAR_version', line):
109
110 row = line.split()
111
112
113 return row[1]
114