1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
21 DEFAULT_COLOR = 'orange'
23 DEFAULT_STYLE = 'plot'
27 self.color = DEFAULT_COLOR
29 self.style = DEFAULT_STYLE
38 self.has_multipliers = False
44 def get_pretty_value(self, column, value):
45 if self.has_multipliers and self.has_results():
46 multiplier = self.multipliers[column]
47 decimals = self.decimals[column]
48 return prettyformat.pretty_format(value, '', decimals, multiplier, True)
51 #def get_fit_result(self):
52 #if not(self.has_multipliers):
53 #self.set_multipliers()
55 #sResult = 'Contour length ['+prettyformat.get_prefix(self.multiplierContourLength) + 'm]' + self.separator
56 #sResult += prettyformat.pretty_format(self.contourLength[0], '', self.decimals, self.multiplierContourLength, True) + '\n'
57 #sResult += 'Persistence length ['+prettyformat.get_prefix(self.multiplierPersistenceLength) + 'm]' + self.separator
58 #sResult += prettyformat.pretty_format(self.persistenceLength[0], '', self.decimals, self.multiplierPersistenceLength, True) + '\n'
59 #sResult += 'Rupture force ['+prettyformat.get_prefix(self.multiplierRuptureForce) + 'N]' + self.separator
60 #sResult += prettyformat.pretty_format(self.ruptureForces[0], '', self.decimals, self.multiplierRuptureForce, True) + '\n'
61 #sResult += 'Loading rate ['+prettyformat.get_prefix(self.multiplierSlope) + 'N/m]' + self.separator
62 #sResult += prettyformat.pretty_format(self.slopes[0], '', self.decimals, self.multiplierSlope, True)+'\n'
63 #sResult += 'Sigma contour ['+prettyformat.get_prefix(self.multiplierContourLength) + 'm]' + self.separator
64 #sResult += prettyformat.pretty_format(self.contourLengthSigma[0], '', self.decimals, self.multiplierContourLength, True) + '\n'
65 #sResult += 'Sigma persistence ['+prettyformat.get_prefix(self.multiplierPersistenceLength) + 'm]' + self.separator
66 #sResult += prettyformat.pretty_format(self.persistenceLengthSigma[0], '', self.decimals, self.multiplierPersistenceLength, True)
70 #def get_fit_results(self, index):
71 #if index >= 0 and index < len(self.contourLength):
72 #if not(self.has_multipliers):
73 #self.set_multipliers()
74 #sLine = prettyformat.pretty_format(self.contourLength[index], '', self.decimals, self.multiplierContourLength, True) + self.separator
75 #sLine += prettyformat.pretty_format(self.persistenceLength[index], '', self.decimals, self.multiplierPersistenceLength, True) + self.separator
76 #sLine += prettyformat.pretty_format(self.ruptureForces[index], '', self.decimals, self.multiplierRuptureForce, True) + self.separator
77 #sLine += prettyformat.pretty_format(self.slopes[index], '', self.decimals, self.multiplierSlope, True) + self.separator
78 #sLine += prettyformat.pretty_format(self.contourLengthSigma[index], '', self.decimals, self.multiplierContourLength, True) + self.separator
79 #sLine += prettyformat.pretty_format(self.persistenceLengthSigma[index], '', self.decimals, self.multiplierPersistenceLength, True)
85 def has_results(self):
88 def header_as_list(self):
90 if self.has_results():
91 if not self.has_multipliers:
92 self.set_multipliers()
93 for column in self.columns:
94 #result will contain the results dictionary for 'column'
95 #result = self.results[0][0][column]
96 #result[1] contains the unit
97 unit_str = ''.join([prettyformat.get_prefix(self.multipliers[column]), self.units[column]])
98 header_str = ''.join([column, ' [', unit_str, ']'])
99 header.append(header_str)
102 #def header_as_str(self):
103 #if self.has_results():
104 #if not self.has_multipliers:
105 #self.set_multipliers()
107 #for column in self.columns:
108 ##result will contain the results dictionary for 'column'
109 #result = self.results[0][0][column]
110 ##result[1] contains the unit
111 #unit_str = ''.join([prettyformat.get_prefix(self.multipliers[column]), result[1]])
112 #header_str = ''.join([header_str, result_str, ' [', unit_str, ']', self.separator])
117 def set_decimal(self, column, decimal=DEFAULT_DECIMAL):
118 if self.decimals.has_key(name):
119 self.decimals[name] = decimal
121 def set_decimals(self, decimals=DEFAULT_DECIMAL):
123 #set default value if necessary
124 decimals = DEFAULT_DECIMAL
125 for column in self.columns:
126 self.decimals[column] = decimals
128 def set_multipliers(self, index=0):
129 if self.has_results():
130 if index >= 0 and index < len(self.results):
131 for column in self.columns:
132 #result will contain the results dictionary at 'index'
133 result = self.results[index][0]
134 #in position 0 of the result we find the value
135 self.multipliers[column] = prettyformat.get_multiplier(result[column][0])
136 self.has_multipliers = True
138 self.has_multipliers = False
141 class ResultsWLC(Results):
143 Results.__init__(self)
144 self.columns = ['Contour length', 'sigma contour length', 'Persistence length', 'sigma persistence length', 'Rupture force', 'Loading rate']
145 self.units['Contour length'] = 'm'
146 self.units['sigma contour length'] = 'm'
147 self.units['Persistence length'] = 'm'
148 self.units['sigma persistence length'] = 'm'
149 self.units['Rupture force'] = 'N'
150 self.units['Loading rate'] = 'N/m'
153 def set_multipliers(self, index=0):
154 if self.has_results():
155 if index >= 0 and index < len(self.results):
156 for column in self.columns:
157 #result will contain the results dictionary at 'index'
158 result = self.results[index].result
159 #in position 0 of the result we find the value
160 if column == 'sigma contour length':
161 self.multipliers[column] = self.multipliers['Contour length']
162 elif column == 'sigma persistence length':
163 self.multipliers[column] = self.multipliers['Persistence length']
165 self.multipliers[column] = prettyformat.get_multiplier(result[column])
166 self.has_multipliers = True
168 self.has_multipliers = False