From 55b36a4777b39aaf3748e8b50f8ca4051f13132f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Wed, 11 Aug 2010 09:30:28 -0400 Subject: [PATCH] Update ModelFitters in polymer_fit.py to match new diag/scale interpretation. --- hooke/plugin/polymer_fit.py | 115 +++++++++++++++--------------------- 1 file changed, 48 insertions(+), 67 deletions(-) diff --git a/hooke/plugin/polymer_fit.py b/hooke/plugin/polymer_fit.py index 88058a6..f4afb2a 100644 --- a/hooke/plugin/polymer_fit.py +++ b/hooke/plugin/polymer_fit.py @@ -233,21 +233,21 @@ class FJC (ModelFitter): ... } >>> model = FJC(d_data, info=info, rescale=True) >>> outqueue = Queue() - >>> Lp,a = model.fit(outqueue=outqueue) + >>> L,a = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Lp) # doctest: +ELLIPSIS - 3.500...e-08 - >>> a # doctest: +ELLIPSIS - 2.499...e-10 + >>> print L + 3.5e-08 + >>> print a + 2.5e-10 Fit the example data with a one-parameter fit (`L`). We introduce some error in our fixed Kuhn length for fun. >>> info['Kuhn length (m)'] = 2*a >>> model = FJC(d_data, info=info, rescale=True) - >>> Lp = model.fit(outqueue=outqueue) + >>> L = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Lp) # doctest: +ELLIPSIS + >>> print L # doctest: +ELLIPSIS 3.199...e-08 """ def Lp(self, L): @@ -339,6 +339,15 @@ class FJC (ModelFitter): self._model_data[:] = FJC_fn(x_data, T, L, a) return self._model_data + def fit(self, *args, **kwargs): + params = super(FJC, self).fit(*args, **kwargs) + if is_iterable(params): + params[0] = self.L(params[0]) # convert Lp -> L + params[1] = abs(params[1]) # take the absolute value of `a` + else: # params is a float + params = self.L(params) # convert Lp -> L + return params + def guess_initial_params(self, outqueue=None): """Guess initial fitting parameters. @@ -362,22 +371,6 @@ class FJC (ModelFitter): return [Lp] return [Lp, a] - def guess_scale(self, params, outqueue=None): - """Guess parameter scales. - - Returns - ------- - Lp_scale : float - A guess at the reparameterized contour length scale in meters. - a_scale : float (optional) - A guess at the Kuhn length in meters. If the length of - `params` is less than 2, `a_scale` is not returned. - """ - Lp_scale = 1.0 - if len(params) == 1: - return [Lp_scale] - return [Lp_scale] + [x/10.0 for x in params[1:]] - def inverse_FJC_PEG_fn(F_data, T=300, N=1, k=150., Lp=3.58e-10, Lh=2.8e-10, dG=3., a=7e-10): """Inverse poly(ethylene-glycol) adjusted extended FJC model. @@ -503,21 +496,21 @@ class FJC_PEG (ModelFitter): ... } >>> model = FJC_PEG(d_data, info=info, rescale=True) >>> outqueue = Queue() - >>> Nr,a = model.fit(outqueue=outqueue) + >>> N,a = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Nr) # doctest: +ELLIPSIS - 122.999... - >>> a # doctest: +ELLIPSIS - 6.999...e-10 + >>> print N + 123.0 + >>> print a + 7e-10 Fit the example data with a one-parameter fit (`N`). We introduce some error in our fixed Kuhn length for fun. >>> info['Kuhn length (m)'] = 2*kwargs['a'] >>> model = FJC_PEG(d_data, info=info, rescale=True) - >>> Nr = model.fit(outqueue=outqueue) + >>> N = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Nr) # doctest: +ELLIPSIS + >>> print N # doctest: +ELLIPSIS 96.931... """ def Lr(self, L): @@ -619,6 +612,15 @@ class FJC_PEG (ModelFitter): self._model_data[:] = FJC_PEG_fn(x_data, N=N, a=a, **kwargs) return self._model_data + def fit(self, *args, **kwargs): + params = super(FJC_PEG, self).fit(*args, **kwargs) + if is_iterable(params): + params[0] = self.L(params[0]) # convert Nr -> N + params[1] = abs(params[1]) # take the absolute value of `a` + else: # params is a float + params = self.L(params) # convert Nr -> N + return params + def guess_initial_params(self, outqueue=None): """Guess initial fitting parameters. @@ -646,19 +648,6 @@ class FJC_PEG (ModelFitter): return [Nr] return [Nr, a] - def guess_scale(self, params, outqueue=None): - """Guess parameter scales. - - Returns - ------- - N_scale : float - A guess at the section count scale in meters. - a_scale : float (optional) - A guess at the Kuhn length in meters. If the length of - `params` is less than 2, `a_scale` is not returned. - """ - return [x/10.0 for x in params] - def WLC_fn(x_data, T, L, p): """The worm like chain interpolation model. @@ -726,21 +715,21 @@ class WLC (ModelFitter): ... } >>> model = WLC(d_data, info=info, rescale=True) >>> outqueue = Queue() - >>> Lp,p = model.fit(outqueue=outqueue) + >>> L,p = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Lp) # doctest: +ELLIPSIS - 3.500...e-08 - >>> p # doctest: +ELLIPSIS - 2.500...e-10 + >>> print L + 3.5e-08 + >>> print p + 2.5e-10 Fit the example data with a one-parameter fit (`L`). We introduce some error in our fixed persistence length for fun. >>> info['persistence length (m)'] = 2*p >>> model = WLC(d_data, info=info, rescale=True) - >>> Lp = model.fit(outqueue=outqueue) + >>> L = model.fit(outqueue=outqueue) >>> fit_info = outqueue.get(block=False) - >>> model.L(Lp) # doctest: +ELLIPSIS + >>> print L # doctest: +ELLIPSIS 3.318...e-08 """ def Lp(self, L): @@ -832,6 +821,15 @@ class WLC (ModelFitter): self._model_data[:] = WLC_fn(x_data, T, L, p) return self._model_data + def fit(self, *args, **kwargs): + params = super(WLC, self).fit(*args, **kwargs) + if is_iterable(params): + params[0] = self.L(params[0]) # convert Lp -> L + params[1] = abs(params[1]) # take the absolute value of `p` + else: # params is a float + params = self.L(params) # convert Lp -> L + return params + def guess_initial_params(self, outqueue=None): """Guess initial fitting parameters. @@ -856,23 +854,6 @@ class WLC (ModelFitter): return [Lp] return [Lp, p] - def guess_scale(self, params, outqueue=None): - """Guess parameter scales. - - Returns - ------- - Lp_scale : float - A guess at the reparameterized contour length scale in meters. - p_scale : float (optional) - A guess at the persistence length in meters. If the - length of `params` is less than 2, `p_scale` is not - returned. - """ - Lp_scale = 1.0 - if len(params) == 1: - return [Lp_scale] - return [Lp_scale] + [x/10.0 for x in params[1:]] - class PolymerFitPlugin (Plugin): """Polymer model (WLC, FJC, etc.) fitting. -- 2.26.2