3 from __future__
import print_function
4 import matplotlib.pyplot
11 """Class that produces analysis-related output, and is able to parse the
12 output of a file produced by the Statistics class.
16 """adds a new entry to the hierarchy by parsing a title entry"""
17 if lineno == len(self.correspondences):
18 self.correspondences.append([])
19 entryno, cat, name = el.split(
':')
20 entryno = int(entryno) - 1
21 if len(self.correspondences[lineno]) == entryno:
22 self.correspondences[lineno].append((cat, name))
24 self.correspondences[lineno][entryno] = (cat, name)
25 h.create_entry(cat, name)
28 """adds data point to hierarchy"""
29 cat, name = self.correspondences[lineno][colno]
37 h.add_data(cat, name, data)
40 """reads a *_stats.txt file and returns variables present in it"""
43 self.correspondences = []
44 for line
in open(statfile):
45 if line.startswith(
'*'):
48 if not tokens[0][1].isdigit():
50 lineno = int(tokens[0][1:]) - 1
51 if line.startswith(
'#'):
56 return self.correspondences
59 """reads an AMBER mden file and returns variables present in it"""
62 self.correspondences = []
64 for line
in open(statfile):
66 lineno = int(tokens[0][1:])
70 for i, el
in enumerate(tokens[1:]):
71 self.
create_entry(h, lineno,
'%d:global:%s' % (i + 1, el))
72 return self.correspondences
75 """reads an AMBER mden file and returns a History instance"""
80 self.correspondences = []
81 for line
in open(statfile):
83 lineno = int(tokens[0][1:])
84 if lineno < oldnum
and read_title:
88 for i, el
in enumerate(tokens[1:]):
89 self.
create_entry(h, lineno,
'%d:global:%s' % (i + 1, el))
92 for i, el
in enumerate(tokens[1:]):
98 """reads a *_stats.txt file and returns a History instance"""
102 self.correspondences = []
103 for line
in open(statfile):
104 if line.startswith(
'*'):
106 tokens = line.split()
107 if not tokens[0][1].isdigit():
109 lineno = int(tokens[0][1:]) - 1
110 if line.startswith(
'#'):
112 for el
in tokens[1:]:
118 for i, el
in enumerate(tokens[1:]):
123 def plot(self, h, *datums, **kwargs):
124 """plots datum (cat,name) from hierarchy h, optionnally specifying a
125 range. To plot multiple data at the same time, add them sequentially.
126 Takes x axis from the 'step' entry of the first datum. TODO.
128 data = [array(h.get_data(cat, name), dtype=float)
129 for (cat, name)
in datums]
130 x = h.get_data(datums[0][0],
'step')
132 for i
in range(len(data)):
133 toplot.extend([x, data[i]])
134 matplotlib.pyplot.plot(*data, **kwargs)
135 matplotlib.pyplot.grid(
True)
136 matplotlib.pyplot.legend()
137 matplotlib.pyplot.show()
140 """plots histogram of datum (cat,name) from hierarchy h, optionnally
141 specifying a range. To plot multiple data at the same time, add them
144 data = [array(h.get_data(*dat), dtype=float)
146 matplotlib.pyplot.hist(*data, **kwargs)
147 matplotlib.pyplot.grid(
True)
148 matplotlib.pyplot.legend()
149 matplotlib.pyplot.show()
151 def dump(self, h, dest, *args):
152 """"dump float data from history h to file dest.
153 args can be either strings corresponding to categories, or tuples
154 corresponding to entries of a certain category. Only one counter will be
155 output for the whole dump, it corresponds to the counter of the first
156 entry's category. You can always specify additional counters if needed.
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, optionnally 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, optionnally specifying a range.