3 import matplotlib.pyplot
10 """Class that produces analysis-related output, and is able to parse the
11 output of a file produced by the Statistics class.
15 """adds a new entry to the hierarchy by parsing a title entry"""
16 if lineno == len(self.correspondences):
17 self.correspondences.append([])
18 entryno, cat, name = el.split(
':')
19 entryno = int(entryno) - 1
20 if len(self.correspondences[lineno]) == entryno:
21 self.correspondences[lineno].append((cat, name))
23 self.correspondences[lineno][entryno] = (cat, name)
24 h.create_entry(cat, name)
27 """adds data point to hierarchy"""
28 cat, name = self.correspondences[lineno][colno]
36 h.add_data(cat, name, data)
39 """reads a *_stats.txt file and returns variables present in it"""
42 self.correspondences = []
43 for line
in open(statfile):
44 if line.startswith(
'*'):
47 if not tokens[0][1].isdigit():
49 lineno = int(tokens[0][1:]) - 1
50 if line.startswith(
'#'):
55 return self.correspondences
58 """reads an AMBER mden file and returns variables present in it"""
61 self.correspondences = []
63 for line
in open(statfile):
65 lineno = int(tokens[0][1:])
69 for i, el
in enumerate(tokens[1:]):
70 self.
create_entry(h, lineno,
'%d:global:%s' % (i + 1, el))
71 return self.correspondences
74 """reads an AMBER mden file and returns a History instance"""
79 self.correspondences = []
80 for line
in open(statfile):
82 lineno = int(tokens[0][1:])
83 if lineno < oldnum
and read_title:
87 for i, el
in enumerate(tokens[1:]):
88 self.
create_entry(h, lineno,
'%d:global:%s' % (i + 1, el))
91 for i, el
in enumerate(tokens[1:]):
97 """reads a *_stats.txt file and returns a History instance"""
101 self.correspondences = []
102 for line
in open(statfile):
103 if line.startswith(
'*'):
105 tokens = line.split()
106 if not tokens[0][1].isdigit():
108 lineno = int(tokens[0][1:]) - 1
109 if line.startswith(
'#'):
111 for el
in tokens[1:]:
117 for i, el
in enumerate(tokens[1:]):
122 def plot(self, h, *datums, **kwargs):
123 """plots datum (cat,name) from hierarchy h, optionally specifying a
124 range. To plot multiple data at the same time, add them sequentially.
125 Takes x axis from the 'step' entry of the first datum. TODO.
127 data = [np.array(h.get_data(cat, name), dtype=float)
128 for (cat, name)
in datums]
129 x = h.get_data(datums[0][0],
'step')
131 for i
in range(len(data)):
132 toplot.extend([x, data[i]])
133 matplotlib.pyplot.plot(*data, **kwargs)
134 matplotlib.pyplot.grid(
True)
135 matplotlib.pyplot.legend()
136 matplotlib.pyplot.show()
139 """plots histogram of datum (cat,name) from hierarchy h, optionally
140 specifying a range. To plot multiple data at the same time, add them
143 data = [np.array(h.get_data(*dat), dtype=float)
145 matplotlib.pyplot.hist(*data, **kwargs)
146 matplotlib.pyplot.grid(
True)
147 matplotlib.pyplot.legend()
148 matplotlib.pyplot.show()
150 def dump(self, h, dest, *args):
151 """"dump float data from history h to file dest.
152 args can be either strings corresponding to categories, or tuples
153 corresponding to entries of a certain category. Only one counter will
154 be output for the whole dump, it corresponds to the counter of the
155 first entry's category. You can always specify additional counters
162 if isinstance(arg, str):
164 ent = h.get_entries(arg)[1:]
166 cats.extend([arg] * len(ent))
172 steps = h.get_data(cats[0],
'step')
174 fl.write(
"# %s:step\t" % cats[0])
175 fl.write(
'\t'.join([
'%s:%s' % (i, j)
for (i, j)
in zip(cats, names)]))
177 data = [h.get_data(i, j)
for (i, j)
in zip(cats, names)]
178 for i, st
in enumerate(steps):
179 fl.write(
"%10d\t" % st)
181 fl.write(
'%10f\t' % j[i])
186 if __name__ ==
'__main__':
190 h = a.read_stats(sys.argv[1])
192 matplotlib.pyplot.ion()
def add_data
adds data point to hierarchy
def read_stats
reads a *_stats.txt file and returns a History instance
def dump
"dump float data from history h to file dest.
def read_AMBER_stats
reads an AMBER mden file and returns a History instance
def create_entry
adds a new entry to the hierarchy by parsing a title entry
Classes to store output from replicas.
def read_variables
reads a *_stats.txt file and returns variables present in it
def plot
plots datum (cat,name) from hierarchy h, optionally specifying a range.
Class that produces analysis-related output, and is able to parse the output of a file produced by th...
def read_AMBER_variables
reads an AMBER mden file and returns variables present in it
def histogram
plots histogram of datum (cat,name) from hierarchy h, optionally specifying a range.