1 from os import mkdir
2 from re import match
3 from string import split
4 import sys
5
8 "Class containing the file operations"
9
10 self.mf = mf
11
12
14 "Initialise the log file."
15
16 self.mf.log = open('log.stage' + self.mf.data.stage, 'w')
17 self.mf.log.write(title)
18
19
21 "Open the file 'file' and return all the data."
22
23 file = open(file_name, 'r')
24 lines = file.readlines()
25 data = []
26 i = 0
27 for line in lines:
28 if i != 0:
29 j = i - 1
30 row = split(line)
31 data.append([])
32 data[j].append(row[0])
33 data[j].append(row[1])
34 for k in range(len(row)):
35 if k > 1:
36 data[j].append(float(row[k]))
37 i = i + 1
38 return data
39
40
42 "Create the given directory, or exit if the directory exists."
43
44 if self.mf.debug:
45 self.mf.log.write("Making directory " + dir + "\n")
46 try:
47 mkdir(dir)
48 except OSError:
49 print "Directory ./" + dir + " already exists, quitting program.\n"
50 sys.exit()
51
52
54 "Attempt to read the file, or quit the program if it does not exist."
55
56 try:
57 open(file_name, 'r')
58 except IOError:
59 sys.stdout.write(message)
60 sys.stdout.write("The file '" + file_name + "' does not exist, quitting program.\n\n\n")
61 sys.exit()
62 file = open(file_name, 'r')
63 return file
64
65
67 """Open the relaxation data in the file 'file' and return all the data.
68
69 It is assumed that the file has four columns separated by whitespace. The columns should be:
70 0 - Residue numbers
71 1 - Residue names
72 2 - R1, R2, or NOE values
73 3 - The errors
74 """
75
76 lines = open(file, 'r')
77 lines = lines.readlines()
78 data = []
79 i = 0
80 for line in lines:
81 if i != 0:
82 j = i - 1
83 row = split(line)
84 data.append([])
85 data[j].append(row[0])
86 data[j].append(row[1])
87 data[j].append(float(row[2]))
88 data[j].append(float(row[3]))
89 i = i + 1
90 return data
91