6 Result and Results classes for Hooke.
8 Copyright 2009 by Dr. Rolf Schmidt (Concordia University, Canada)
10 This program is released under the GNU General Public License version 2.
18 DEFAULT_COLOR = 'green'
20 DEFAULT_STYLE = 'scatter'
22 class Result(lib.curve.Curve):
24 lib.curve.Curve.__init__(self)
25 self.color = DEFAULT_COLOR
27 self.style = DEFAULT_STYLE
29 class Results(object):
33 self.has_multipliers = False
39 def get_pretty_value(self, column, value):
40 if self.has_multipliers and self.has_results():
41 multiplier = self.multipliers[column]
42 decimals = self.decimals[column]
43 return prettyformat.pretty_format(value, '', decimals, multiplier, True)
46 def has_results(self):
47 return len(self.results) > 0
49 def get_header_as_list(self):
51 if self.has_results():
52 if not self.has_multipliers:
53 self.set_multipliers()
54 for column in self.columns:
55 unit_str = ''.join([prettyformat.get_prefix(self.multipliers[column]), self.units[column]])
56 header_str = ''.join([column, ' [', unit_str, ']'])
57 header_list.append(header_str)
60 def get_header_as_str(self, separator=None):
62 separator = self.separator
63 return separator.join(map(str, self.get_header_as_list()))
65 def get_result_as_list(self, index=0):
66 if index >= 0 and index < len(self.results):
68 if self.has_results():
69 if not self.has_multipliers:
70 self.set_multipliers()
71 for column in self.columns:
72 result_str = prettyformat.pretty_format(self.results[index].result[column], '', self.decimals[column], self.multipliers[column], True)
73 result_list.append(result_str)
78 def get_result_as_string(self, index=0):
79 results_list = self.get_result_as_list(index)
80 if results_list is not None:
81 return self.separator.join(map(str, results_list))
85 def set_decimal(self, column, decimal=DEFAULT_DECIMAL):
86 if self.decimals.has_key(column):
87 self.decimals[column] = decimal
89 def set_decimals(self, decimals=DEFAULT_DECIMAL):
91 #set default value if necessary
92 decimals = DEFAULT_DECIMAL
93 for column in self.columns:
94 self.decimals[column] = decimals
96 def set_multipliers(self, index=0):
97 if self.has_results():
98 for column in self.columns:
99 #result will contain the results dictionary at 'index'
100 result = self.results[index].result
101 #in position 0 of the result we find the value
102 self.multipliers[column] = prettyformat.get_multiplier(result[column])
103 self.has_multipliers = True
105 self.has_multipliers = False
111 class ResultsFJC(Results):
113 Results.__init__(self)
114 self.columns = ['Contour length', 'sigma contour length', 'Kuhn length', 'sigma Kuhn length', 'Rupture force', 'Slope', 'Loading rate']
115 self.units['Contour length'] = 'm'
116 self.units['sigma contour length'] = 'm'
117 self.units['Kuhn length'] = 'm'
118 self.units['sigma Kuhn length'] = 'm'
119 self.units['Rupture force'] = 'N'
120 self.units['Slope'] = 'N/m'
121 self.units['Loading rate'] = 'N/s'
124 def set_multipliers(self, index=0):
125 if self.has_results():
126 for column in self.columns:
127 #result will contain the results dictionary at 'index'
128 result = self.results[index].result
129 #in position 0 of the result we find the value
130 if column == 'sigma contour length':
131 self.multipliers[column] = self.multipliers['Contour length']
132 elif column == 'sigma Kuhn length':
133 self.multipliers[column] = self.multipliers['Kuhn length']
135 self.multipliers[column] = prettyformat.get_multiplier(result[column])
136 self.has_multipliers = True
138 self.has_multipliers = False
140 class ResultsMultiDistance(Results):
142 Results.__init__(self)
143 self.columns = ['Distance']
144 self.units['Distance'] = 'm'
148 if (self.results) > 0:
149 for result in self.results:
151 reference_peak = result.x
154 for result in self.results:
156 result.result['Distance'] = reference_peak - result.x
157 reference_peak = result.x
159 result.result['Distance'] = nan
162 class ResultsWLC(Results):
164 Results.__init__(self)
165 self.columns = ['Contour length', 'sigma contour length', 'Persistence length', 'sigma persistence length', 'Rupture force', 'Slope', 'Loading rate']
166 self.units['Contour length'] = 'm'
167 self.units['sigma contour length'] = 'm'
168 self.units['Persistence length'] = 'm'
169 self.units['sigma persistence length'] = 'm'
170 self.units['Rupture force'] = 'N'
171 self.units['Slope'] = 'N/m'
172 self.units['Loading rate'] = 'N/s'
175 def set_multipliers(self, index=0):
176 if self.has_results():
177 for column in self.columns:
178 #result will contain the results dictionary at 'index'
179 result = self.results[index].result
180 #in position 0 of the result we find the value
181 if column == 'sigma contour length':
182 self.multipliers[column] = self.multipliers['Contour length']
183 elif column == 'sigma persistence length':
184 self.multipliers[column] = self.multipliers['Persistence length']
186 self.multipliers[column] = prettyformat.get_multiplier(result[column])
187 self.has_multipliers = True
189 self.has_multipliers = False