Beispiel #1
0
    def plot(self, which):
        """
        Make a plot of one of the fitting results.  The argument is the name
        of the fit.  Alternatively, which can be in integer denoting
        the place in the list of models.

        For example, for the SCF tests, the names are "feff6",
        "noSCF", or "withSCF_N" where N is the radius of the
        self-consistency cluster.  1 is always "feff6", 2 is always
        "noSCF", 3+ are the "withSCF" calculations in order of
        increasing radius.
        """
        if isinstance(which, int):
            which = self.models[which-1]
        if which in self.models:
            dsets = getattr(getattr(self, which), 'datasets')
            dset = dsets[0]
            offset = 0.8 * max(dset.data.chir_mag)
            _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=6,
                     xlabel=r'$R \rm\,(\AA)$', label='data', color='blue',
                     ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                     title='Fit to '+self.material+ ' using '+which, show_legend=True, _larch=self._larch)
            _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', color='red', _larch=self._larch)
            _plot(dset.data.r,  dset.data.chir_re, label='', color='blue', _larch=self._larch)
            _plot(dset.model.r, dset.model.chir_re, label='', color='red', _larch=self._larch)
        else:
            raise Exception("%s is not one of the feff models for the %s test" % (which, self.test))
Beispiel #2
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, 'baseline', which))
    #endif

    print '>>>>>> %s' % folder

    data = read_xdi(join(self.path, 'Copper.chik'), _larch=self._larch)

    gds = Group(amp    = Parameter(1,     vary=True),
                enot   = Parameter(1e-7,  vary=True),
                thetad = Parameter(500,   vary=True),
                temp   = Parameter(10,    vary=False),
                alpha  = Parameter(1e-7,  vary=True),
                ss1    = Parameter(0.003, vary=True),
                _larch=self._larch  )

    paths = list()
    for index in range(1,14):
        nnnn = realpath(join(folder, "feff%4.4d.dat" % index))
        if not exists(nnnn):
            continue
        #end if
        if index > 1:
            sigsqr = 'sigma2_debye(temp, thetad)' 
        else:
            sigsqr = 'ss1'
        #end if
        paths.append(feffpath(nnnn,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = sigsqr,
                              deltar = 'alpha*reff', _larch=self._larch))
    #end for

    trans = feffit_transform(kmin=3, kmax=16, kw=(2,1,3), dk=1, window='hanning', rmin=1.7, rmax=5.1, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8, win=2,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', win=2, _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', win=2, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', win=2, _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #3
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    dmt = read_xdi(join(self.path, 'dmt.chik'), _larch=self._larch)
    mmt = read_xdi(join(self.path, 'mmt.chik'), _larch=self._larch)

    gds = Group(amp=Parameter(0.9, vary=True, _larch=self._larch),
                enot=Parameter(1e-7, vary=True, _larch=self._larch),
                delr_c=Parameter(1e-7, vary=True, _larch=self._larch),
                ss_c=Parameter(0.003, vary=True, _larch=self._larch),
                delr_cl=Parameter(1e-7, vary=True, _larch=self._larch),
                ss_cl=Parameter(0.003, vary=True, _larch=self._larch),
                _larch=self._larch)

    paths_dmt = list()
    paths_dmt.append(
        feffpath(realpath(join(folder, "feff0001.dat")),
                 degen=2,
                 s02='amp',
                 e0='enot',
                 sigma2='ss_c',
                 deltar='delr_c',
                 _larch=self._larch))
    paths_dmt.append(
        feffpath(realpath(join(folder, "feff0002.dat")),
                 degen=2,
                 s02='amp',
                 e0='enot',
                 sigma2='ss_cl',
                 deltar='delr_cl',
                 _larch=self._larch))
    paths_mmt = list()
    paths_mmt.append(
        feffpath(realpath(join(folder, "feff0001.dat")),
                 degen=1,
                 s02='amp',
                 e0='enot',
                 sigma2='ss_c',
                 deltar='delr_c',
                 _larch=self._larch))
    paths_mmt.append(
        feffpath(realpath(join(folder, "feff0002.dat")),
                 degen=3,
                 s02='amp',
                 e0='enot',
                 sigma2='ss_cl',
                 deltar='delr_cl',
                 _larch=self._larch))

    trans = feffit_transform(kmin=3,
                             kmax=13,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.25,
                             rmax=3,
                             _larch=self._larch)
    dset = [
        feffit_dataset(data=dmt,
                       pathlist=paths_dmt,
                       transform=trans,
                       _larch=self._larch),
        feffit_dataset(data=mmt,
                       pathlist=paths_mmt,
                       transform=trans,
                       _larch=self._larch)
    ]
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset[0].data.chir_mag) / 2
        _newplot(dset[0].data.r,
                 dset[0].data.chir_mag + offset,
                 xmax=5,
                 win=1,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='dimethyltin',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset[0].model.r,
              dset[0].model.chir_mag + offset,
              label='fit',
              win=1,
              _larch=self._larch)
        _plot(dset[0].data.r,
              dset[0].data.chir_re,
              label='dimethyltin',
              win=1,
              _larch=self._larch)
        _plot(dset[0].model.r,
              dset[0].model.chir_re,
              label='fit',
              win=1,
              _larch=self._larch)

        _plot(dset[1].data.r,
              dset[1].data.chir_mag + 7 * offset,
              label='monomethyltin',
              win=1,
              _larch=self._larch)
        _plot(dset[1].model.r,
              dset[1].model.chir_mag + 7 * offset,
              label='fit',
              win=1,
              _larch=self._larch)
        _plot(dset[1].data.r,
              dset[1].data.chir_re + 6 * offset,
              label='monomethyltin',
              win=1,
              _larch=self._larch)
        _plot(dset[1].model.r,
              dset[1].model.chir_re + 6 * offset,
              label='fit',
              win=1,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells = '_1st'

    write_ascii(join(self.folder, fittest, "fit_" + which + ".k"),
                dset.data[0].k,
                dset.data[0].chi,
                dset.model[0].chi,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_" + which + ".r"),
                dset.data[0].r,
                dset.data[0].chir_mag,
                dset.model[0].chir_mag,
                dset.data[0].chir_re,
                dset.model[0].chir_re,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_' + which + '.gp'), 'w') as inp:
        inp.write(
            renderer.render_path(
                'plot.mustache',  # gnuplot mustache file
                {
                    'material': 'methyltin',
                    'model': which,
                    'fittest': fittest,
                    'shells': shells,
                    'kmin': 3,
                    'kmax': 13,
                    'rmin': 1.25,
                    'rmax': 3,
                    'offset': 1,
                }))

    return fit
Beispiel #4
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    else:
        folder = self.baseline
    #end if

    data = read_xdi(join(self.path, 'bromoadamantane.chik'),
                    _larch=self._larch)

    gds = Group(amp=Parameter(1.021, vary=True, _larch=self._larch),
                enot=Parameter(4.01, vary=True, _larch=self._larch),
                delr=Parameter(-0.007, vary=True, _larch=self._larch),
                brc=Parameter(expr='1.9521+delr', _larch=self._larch),
                ss=Parameter(0.003, vary=True, _larch=self._larch),
                phir=Parameter(109.29960 * 3.141592653589793 / 180,
                               vary=False,
                               _larch=self._larch),
                cc=Parameter(1.53780, vary=False, _larch=self._larch),
                tanbeta=Parameter(expr='(brc+cc)*tan(phir/2) / (brc-cc)',
                                  _larch=self._larch),
                beta=Parameter(expr='atan(tanbeta)', _larch=self._larch),
                brc2=Parameter(expr='(brc-cc)*cos(phir/2)/cos(beta)',
                               _larch=self._larch),
                drh=Parameter(0.04, vary=True, _larch=self._larch),
                ssh=Parameter(0.005, vary=True, _larch=self._larch),
                ss2=Parameter(expr='ss*(brc2/brc)**2', _larch=self._larch),
                c3=Parameter(-0.0007, vary=True, _larch=self._larch),
                _larch=self._larch)

    paths = list()
    paths.append(
        feffpath(realpath(join(folder, "feff0001.dat")),
                 s02='amp',
                 e0='enot',
                 sigma2='ss',
                 deltar='delr',
                 third='c3',
                 _larch=self._larch))
    paths.append(
        feffpath(realpath(join(folder, "feff0002.dat")),
                 s02='amp',
                 e0='enot',
                 sigma2='ss2',
                 deltar='brc2-2.8565',
                 _larch=self._larch))
    paths.append(
        feffpath(realpath(join(folder, "feff0003.dat")),
                 s02='amp',
                 e0='enot',
                 sigma2='ssh',
                 deltar='drh',
                 _larch=self._larch))
    paths.append(
        feffpath(realpath(join(folder, "feff0004.dat")),
                 s02='amp',
                 e0='enot',
                 sigma2='(ss+ss2)/2',
                 deltar='(brc+brc2+cc)/2 - 3.173',
                 _larch=self._larch))
    paths.append(
        feffpath(realpath(join(folder, "feff0005.dat")),
                 s02='amp',
                 e0='enot',
                 sigma2='(ss+ss2)/2',
                 deltar='(brc+brc2+cc)/2 - 3.173',
                 _larch=self._larch))

    trans = feffit_transform(kmin=2.5,
                             kmax=13,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.25,
                             rmax=3,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 win=2,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              win=2,
              _larch=self._larch)
        _plot(dset.data.r,
              dset.data.chir_re,
              label='data',
              win=2,
              _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              win=2,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #5
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'Copper.chik'), _larch=self._larch)

    gds = Group(amp=Parameter(1, vary=True, _larch=self._larch),
                enot=Parameter(1e-7, vary=True, _larch=self._larch),
                ss1=Parameter(0.003, vary=True, _larch=self._larch),
                _larch=self._larch)

    if firstshell:
        gds.delr = Parameter(1e-7, vary=True, _larch=self._larch)
        dr1param = 'delr'
    else:
        gds.thetad = Parameter(500, vary=True, _larch=self._larch)
        gds.temp = Parameter(10, vary=False, _larch=self._larch)
        gds.alpha = Parameter(1e-7, vary=True, _larch=self._larch)
        dr1param = 'alpha*reff'

    imax = 16
    if firstshell: imax = 2
    paths = list()
    for index in range(1, imax):
        nnnn = realpath(join(folder, "feff%4.4d.dat" % index))
        if not exists(nnnn):
            continue
        #end if
        if index > 1:
            sigsqr = 'sigma2_debye(temp, thetad)'
        else:
            sigsqr = 'ss1'
        #end if
        paths.append(
            feffpath(nnnn,
                     s02='amp',
                     e0='enot',
                     sigma2=sigsqr,
                     deltar=dr1param,
                     _larch=self._larch))
    #end for

    rx = 5.0
    if firstshell: rx = 2.8

    trans = feffit_transform(kmin=3,
                             kmax=15,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1,
                             rmax=rx,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              _larch=self._larch)
        _plot(dset.data.r, dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells = '_1st'

    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".k"),
                dset.data.k,
                dset.data.chi,
                dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".r"),
                dset.data.r,
                dset.data.chir_mag,
                dset.model.chir_mag,
                dset.data.chir_re,
                dset.model.chir_re,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_' + which + shells + '.gp'),
              'w') as inp:
        inp.write(
            renderer.render_path(
                'plot.mustache',  # gnuplot mustache file
                {
                    'material': 'Copper',
                    'model': which,
                    'fittest': fittest,
                    'shells': shells,
                    'kmin': 3,
                    'kmax': 15,
                    'rmin': 1,
                    'rmax': rx,
                    'offset': 2,
                }))

    return fit
Beispiel #6
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    else:
        folder = self.baseline

    data = read_xdi(join(self.path, 'NiO.chik'), _larch=self._larch)
    if hasattr(data, 'wavenumber'):
        data.k = data.wavenumber

    gds = Group(
        amp=Parameter(1, vary=True, _larch=self._larch),
        enot=Parameter(0.01, vary=True, _larch=self._larch),
        alpha=Parameter(0.0001, vary=True, _larch=self._larch),
        sso=Parameter(0.003, vary=True, _larch=self._larch),
        ssni=Parameter(0.003, vary=True, _larch=self._larch),
        sso2=Parameter(0.003, vary=True, _larch=self._larch),
        #sso3   = Parameter(0.003,  vary=True, _larch=self._larch),
        ssni2=Parameter(0.003, vary=True, _larch=self._larch),
        #ssni3  = Parameter(0.003,  vary=True, _larch=self._larch),
        #ssni4  = Parameter(0.003,  vary=True, _larch=self._larch),
        _larch=self._larch)

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # 1st shell O SS
            s02='amp',
            e0='enot',
            sigma2='sso',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0002.dat")),  # 2nd shell Ni SS
            s02='amp',
            e0='enot',
            sigma2='ssni',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0003.dat")),  # O-O triangle
            s02='amp',
            e0='enot',
            sigma2='1.5*sso',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0004.dat")),  # O-Ni triangle
            s02='amp',
            e0='enot',
            sigma2='sso+ssni',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0005.dat")),  # 3rd shell O SS
            s02='amp',
            e0='enot',
            sigma2='sso2',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0006.dat")),  # 4th shell Ni SS
            s02='amp',
            e0='enot',
            sigma2='ssni2',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0007.dat")),  # O-O non-forward linear
            s02='amp',
            e0='enot',
            sigma2='sso*2',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0008.dat")),  # O-Ni forward scattering
            s02='amp',
            e0='enot',
            sigma2='ssni2',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder,
                          "feff0009.dat")),  # O-O forward through absorber
            s02='amp',
            e0='enot',
            sigma2='sso*2',
            deltar='alpha*reff',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0010.dat")),  # O-Ni-O double forward
            s02='amp',
            e0='enot',
            sigma2='ssni2',
            deltar='alpha*reff',
            _larch=self._larch))

    trans = feffit_transform(kmin=3,
                             kmax=15.938,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.5,
                             rmax=4.2,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = 0.6 * max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 win=2,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              win=2,
              _larch=self._larch)
        _plot(dset.data.r,
              dset.data.chir_re,
              label='data',
              win=2,
              _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              win=2,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #7
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'NiO.chik'), _larch=self._larch)
    if hasattr(data, 'wavenumber'):
        data.k = data.wavenumber

    gds = Group(amp    = Parameter(1,      vary=True, _larch=self._larch),
                enot   = Parameter(1e-7,   vary=True, _larch=self._larch),
                sso    = Parameter(0.003,  vary=True, _larch=self._larch), _larch=self._larch  )

    if firstshell:
        gds.delr   = Parameter(1e-7,   vary=True, _larch=self._larch)
        dr1param   = 'delr'
    else:
        gds.alpha  = Parameter(1e-7,   vary=True, _larch=self._larch)
        gds.ssni   = Parameter(0.003,  vary=True, _larch=self._larch)
        gds.sso2   = Parameter(0.003,  vary=True, _larch=self._larch)
        #gds.sso3   = Parameter(0.003,  vary=True, _larch=self._larch)
        gds.ssni2  = Parameter(0.003,  vary=True, _larch=self._larch)
        #gds.ssni3  = Parameter(0.003,  vary=True, _larch=self._larch)
        #gds.ssni4  = Parameter(0.003,  vary=True, _larch=self._larch)
        dr1param   = 'alpha*reff'

    paths = list() 
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")), # 1st shell O SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso',
                          deltar = dr1param, _larch=self._larch))
    if not firstshell:
        paths.append(feffpath(realpath(join(folder, "feff0002.dat")), # 2nd shell Ni SS
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ssni',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0003.dat")), # O-O triangle
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '1.5*sso',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0004.dat")), # O-Ni triangle
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'sso+ssni/2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0005.dat")), # 3rd shell O SS
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'sso2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0006.dat")), # 4th shell Ni SS
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ssni2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0007.dat")), # O-O non-forward linear
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'sso*2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0008.dat")), # O-Ni forward scattering
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ssni2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0009.dat")), # O-O forward through absorber
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'sso*2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0011.dat")), # O-Ni-O double forward
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ssni2',
                              deltar = 'alpha*reff', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0010.dat")), # O-O rattle (the order of 10 and 11 is different in Demeter's pathfinder!)
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'sso*4',
                              deltar = 'alpha*reff', _larch=self._larch))

    rx  = 4.2
    if firstshell: rx  = 1.95

    trans = feffit_transform(kmin=3, kmax=15.938, kw=(2,1,3), dk=1, window='hanning', rmin=1.0, rmax=rx, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = 0.6*max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest,'fit_'+which+shells+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'NiO',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 15.938,
                                         'rmin': 1.0,
                                         'rmax': rx,
                                         'offset': 1,
                                     } ))

    return fit
Beispiel #8
0
    def compare(self, nnnn=1, part='feff', use_wrapper=False, _larch=None):
        """
        Compare a feffNNNN.dat file from the testrun with the same file
        from the baseline calculation

            group.compare(N, part, use_wrapper)

        where N is the path index, part is one of 
            feff    :      test the magnitude AND phase of F_eff (default)
            amp     :      test the total amplitude of the path
            phase   :      test the total phase of the path
            lambda  :      test the mean free path
            caps    :      test the central atom phase shift
            redfact :      test the reduction factor
            rep     :      test the real part of the complex wavenumber

        and use_wrapper is True if the test is to use the python interface to
        the feffpath library or False if the test is to use the feffrunner and
        the Feff executables.  (Currently, only feffrunner is working...)

        Sets self.rfactor (and self.rfactor_2).

        """
        if self._larch is None:
            raise Warning("cannot do path comparison -- larch broken?")

        if not self.feffran:
            print colored("You have not yet run the test Feff calculation",
                          'magenta',
                          attrs=['bold'])
            return

        if not self.available(nnnn):
            print colored(
                "Path %d was not saved from the test Feff calculation" % nnnn,
                'magenta',
                attrs=['bold'])
            return

        how = 'wrapper' if use_wrapper else 'executables'
        nnnndat = "feff%4.4d.dat" % nnnn

        blpath = feffpath(join(self.baseline, nnnndat))
        if use_wrapper and self.wrapper_available:  # make the f3ffNNNN.dat file on the fly
            self.sp.phpad = join(self.testrun, 'phase.pad')
            self.sp.nnnn = True
            self.sp.index = nnnn
            self.sp.verbose = self.verbose
            self.__snarf_geometry(nnnn)
            owd = getcwd()
            try:
                chdir(self.testrun)
                self.sp.make()
            finally:
                chdir(owd)
            n3nndat = "f3ff%4.4d.dat" % nnnn
            trpath = feffpath(join(self.testrun, n3nndat))
        else:  # the feffNNNN.dat file was made by the monolithic feff run
            trpath = feffpath(join(self.testrun, nnnndat))

        if part == 'feff':
            baseline_1 = getattr(blpath._feffdat,
                                 'mag_feff')  # + np.random.uniform(0,1,size=1)
            testrun_1 = getattr(trpath._feffdat, 'mag_feff')
            baseline_2 = getattr(blpath._feffdat,
                                 'pha_feff')  # + np.random.uniform(0,1,size=1)
            testrun_2 = getattr(trpath._feffdat, 'pha_feff')
            ylabel = 'magnitude and phase'
            label = 'magnitude'
        elif part == 'amp':
            baseline_1 = getattr(blpath._feffdat, 'amp')
            testrun_1 = getattr(trpath._feffdat, 'amp')
            ylabel = 'total amplitude'
            label = 'amplitude'
        elif part == 'phase':
            baseline_1 = getattr(blpath._feffdat, 'pha')
            testrun_1 = getattr(trpath._feffdat, 'pha')
            ylabel = 'total phase shift'
            label = 'phase'
        elif part == 'lambda':
            baseline_1 = getattr(blpath._feffdat, 'lam')
            testrun_1 = getattr(trpath._feffdat, 'lam')
            ylabel = 'mean free path'
            label = 'MFP'
        elif part == 'caps':
            baseline_1 = getattr(blpath._feffdat, 'real_phc')
            testrun_1 = getattr(trpath._feffdat, 'real_phc')
            ylabel = 'central atom phase shift'
            label = 'CAPS'
        elif part == 'redfact':
            baseline_1 = getattr(blpath._feffdat, 'red_fact')
            testrun_1 = getattr(trpath._feffdat, 'red_fact')
            ylabel = 'reduction factor'
            label = 'reduction factor'
        elif part == 'rep':
            baseline_1 = getattr(blpath._feffdat, 'rep')
            testrun_1 = getattr(trpath._feffdat, 'rep')
            ylabel = 'real part of p(k)'
            label = 'Re[p(k)]'
        else:
            if self.verbose:
                print colored(
                    "Unknown choice of parts \"%s\"\nmust be one of (feff|amp|phase|lambda|caps|redfact|rep)\nusing feff"
                    % part,
                    'magenta',
                    attrs=['bold'])
            part = 'feff'
            baseline_1 = getattr(blpath._feffdat, 'mag_feff')
            testrun_1 = getattr(trpath._feffdat, 'mag_feff')
            baseline_2 = getattr(blpath._feffdat, 'pha_feff')
            testrun_2 = getattr(trpath._feffdat, 'pha_feff')
            ylabel = 'magnitude and phase'
            label = 'magnitude'

        self.rfactor_2 = 0
        self.rfactor = sum((baseline_1 - testrun_1)**2) / sum(baseline_1**2)
        if self.verbose:
            print colored("\nComparing %s of %s (%s) (using %s)" %
                          (label, nnnndat,
                           "with SCF" if self.doscf else "without SCF", how),
                          'yellow',
                          attrs=['bold'])
            self.print_geometry(blpath)

        if self.verbose:
            print label + " R-factor = " + colored(
                "%.3f" % self.rfactor,
                'green' if self.rfactor < self.epsilon else 'magenta',
                attrs=['bold'])
        if part == 'feff':
            self.rfactor_2 = sum(
                (testrun_2 - testrun_2)**2) / sum(baseline_2**2)
            if self.verbose:
                color = 'green' if self.rfactor_2 < self.epsilon else 'magenta'
                print "phase R-factor = " + colored(
                    "%.3f" % self.rfactor_2, color, attrs=['bold'])
        if self.verbose: print ""

        if self.doplot:
            _newplot(blpath._feffdat.k,
                     baseline_1,
                     _larch=self._larch,
                     label=label + ' of baseline',
                     xlabel='wavenumber $\AA^{-1}$',
                     ylabel=ylabel,
                     title=nnnndat,
                     show_legend=True,
                     legend_loc='best')
            _plot(trpath._feffdat.k,
                  testrun_1,
                  _larch=self._larch,
                  label=label + ' of test run')
            if part == 'feff':
                _plot(blpath._feffdat.k,
                      np.gradient(baseline_2),
                      _larch=self._larch,
                      label='grad(phase of baseline)')
                _plot(trpath._feffdat.k,
                      np.gradient(testrun_2),
                      _larch=self._larch,
                      label='grad(phase of test run)')

        if use_wrapper and self.wrapper_available:
            unlink(join(self.testrun, n3nndat))
            self.sp.clear()

        if part == 'feff':
            return self.rfactor < self.epsilon and self.rfactor_2 < self.epsilon
        else:
            return self.rfactor < self.epsilon
Beispiel #9
0
def do_fit(self, which):

    if which == "testrun":
        folder = self.testrun
    else:
        folder = self.baseline

    data = read_xdi(join(self.path, "UO2.chik"), _larch=self._larch)

    gds = Group(
        amp=Parameter(1, vary=True, _larch=self._larch),
        enot=Parameter(0.01, vary=True, _larch=self._larch),
        sso=Parameter(0.003, vary=True, _larch=self._larch),
        ssu=Parameter(0.003, vary=True, _larch=self._larch),
        sso2=Parameter(0.003, vary=True, _larch=self._larch),
        dro=Parameter(0.0001, vary=True, _larch=self._larch),
        dru=Parameter(0.0001, vary=True, _larch=self._larch),
        dro2=Parameter(0.0001, vary=True, _larch=self._larch),
        nu=Parameter(12, vary=True, _larch=self._larch),
        no2=Parameter(expr="2*nu", _larch=self._larch),
        _larch=self._larch,
    )

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # 1st shell O SS
            s02="amp",
            e0="enot",
            sigma2="sso",
            deltar="dro",
            _larch=self._larch,
        )
    )
    # paths.append(feffpath(realpath(join(folder, "feff0002.dat")), # triangle in first shell
    #                       s02    = 'amp',
    #                       e0     = 'enot',
    #                       sigma2 = 'sso*1.5',
    #                       deltar = 'dro*(1+sqrt(2))/2', _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0003.dat")),  # 2nd shell U SS
            degen=1,
            s02="amp*nu",
            e0="enot",
            sigma2="ssu",
            deltar="dru",
            _larch=self._larch,
        )
    )
    # paths.append(feffpath(realpath(join(folder, "feff0004.dat")), # 1st shell, longer triangle
    #                       s02    = 'amp',
    #                       e0     = 'enot',
    #                       sigma2 = '2*sso',
    #                       deltar = '2*dro', _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0006.dat")),  # 3rd shell O SS
            degen=1,
            s02="amp*no2",
            # s02    = 'amp*nu*2',
            e0="enot",
            sigma2="sso2",
            deltar="dro2",
            _larch=self._larch,
        )
    )
    paths.append(
        feffpath(
            realpath(join(folder, "feff0007.dat")),  # 1st shell, non-forward linear through absorber
            s02="amp",
            e0="enot",
            sigma2="sso2",
            deltar="dro2",
            _larch=self._larch,
        )
    )
    paths.append(
        feffpath(
            realpath(join(folder, "feff0008.dat")),  # 1st shell forward through absorber
            s02="amp",
            e0="enot",
            sigma2="2*sso",
            deltar="2*dro",
            _larch=self._larch,
        )
    )
    paths.append(
        feffpath(
            realpath(join(folder, "feff0009.dat")),  # rattle in 1st shell
            s02="amp",
            e0="enot",
            sigma2="2*sso",
            deltar="2*dro",
            _larch=self._larch,
        )
    )

    trans = feffit_transform(
        kmin=3, kmax=11, kw=(2, 1, 3), dk=1, window="hanning", rmin=1.25, rmax=4.3, _larch=self._larch
    )
    dset = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(
            dset.data.r,
            dset.data.chir_mag + offset,
            xmax=8,
            win=2,
            xlabel=r"$R \rm\,(\AA)$",
            label="data",
            ylabel=r"$|\chi(R)| \rm\,(\AA^{-3})$",
            title="Fit to " + self.folder,
            show_legend=True,
            _larch=self._larch,
        )
        _plot(dset.model.r, dset.model.chir_mag + offset, label="fit", win=2, _larch=self._larch)
        _plot(dset.data.r, dset.data.chir_re, label="data", win=2, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label="fit", win=2, _larch=self._larch)
    # end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    # end if

    return fit
Beispiel #10
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    firstshell = False          # no 1st shell fit for this material

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'uranyl.chik'), _larch=self._larch)

    gds = Group(amp    = Parameter(1,      vary=True,  _larch=self._larch),
                enot   = Parameter(1e-7,   vary=True,  _larch=self._larch),
                #enot   = Parameter(1e-7,   vary=True,  _larch=self._larch, min=0, max=13),
                enoteq = Parameter(expr= 'enot',     _larch=self._larch),
                deloax = Parameter(1e-7,   vary=True,  _larch=self._larch),
                deloeq = Parameter(1e-7,   vary=True,  _larch=self._larch),
                sigoax = Parameter(0.003,  vary=True,  _larch=self._larch),
                sigoeq = Parameter(0.003,  vary=True,  _larch=self._larch),
                nax    = Parameter(2.0,    vary=False, _larch=self._larch),
                neq    = Parameter(6,      vary=False, _larch=self._larch), #, min=0, max=12),
                _larch=self._larch  )

    paths = list() 
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")), # axial oxygen
                          degen  = 1,
                          s02    = 'amp*nax',
                          e0     = 'enot',
                          sigma2 = 'sigoax',
                          deltar = 'deloax', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0003.dat")), # equatorial oxygen
                          degen  = 1,
                          s02    = 'amp*neq',
                          e0     = 'enoteq',
                          sigma2 = 'sigoeq',
                          deltar = 'deloeq', _larch=self._larch))

    paths.append(feffpath(realpath(join(folder, "feff0008.dat")), # axial oxygen, rattle
                          degen  = 1,
                          s02    = 'amp*nax',
                          e0     = 'enot',
                          sigma2 = 'sigoax*4',
                          deltar = 'deloax*2', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0009.dat")), # axial oxygen, non-forward
                          degen  = 1,
                          s02    = 'amp*nax',
                          e0     = 'enot',
                          sigma2 = 'sigoax',
                          deltar = 'deloax*2', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0010.dat")), # axial oxygen, forward
                          degen  = 1,
                          s02    = 'amp*nax',
                          e0     = 'enot',
                          sigma2 = 'sigoax',
                          deltar = 'deloax*2', _larch=self._larch))




    trans = feffit_transform(kmin=3, kmax=11, kw=(2,1,3), dk=1, window='hanning', rmin=1.0, rmax=3.2, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8, win=2,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', win=2, _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', win=2, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', win=2, _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_'+which+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'uranyl',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 11,
                                         'rmin': 1.0,
                                         'rmax': 3.2,
                                         'offset': 1,
                                     } ))

    return fit
Beispiel #11
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    else:
        folder = self.baseline

    data = read_xdi(join(self.path, 'NiO.chik'), _larch=self._larch)
    if hasattr(data, 'wavenumber'):
        data.k = data.wavenumber

    gds = Group(amp    = Parameter(1,      vary=True, _larch=self._larch),
                enot   = Parameter(0.01,   vary=True, _larch=self._larch),
                alpha  = Parameter(0.0001, vary=True, _larch=self._larch),
                sso    = Parameter(0.003,  vary=True, _larch=self._larch),
                ssni   = Parameter(0.003,  vary=True, _larch=self._larch),
                sso2   = Parameter(0.003,  vary=True, _larch=self._larch),
                #sso3   = Parameter(0.003,  vary=True, _larch=self._larch),
                ssni2  = Parameter(0.003,  vary=True, _larch=self._larch),
                #ssni3  = Parameter(0.003,  vary=True, _larch=self._larch),
                #ssni4  = Parameter(0.003,  vary=True, _larch=self._larch),
                _larch=self._larch  )

    paths = list() 
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")), # 1st shell O SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0002.dat")), # 2nd shell Ni SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ssni',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0003.dat")), # O-O triangle
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = '1.5*sso',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0004.dat")), # O-Ni triangle
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso+ssni',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0005.dat")), # 3rd shell O SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso2',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0006.dat")), # 4th shell Ni SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ssni2',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0007.dat")), # O-O non-forward linear
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso*2',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0008.dat")), # O-Ni forward scattering
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ssni2',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0009.dat")), # O-O forward through absorber
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso*2',
                          deltar = 'alpha*reff', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0010.dat")), # O-Ni-O double forward
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ssni2',
                          deltar = 'alpha*reff', _larch=self._larch))


    trans = feffit_transform(kmin=3, kmax=15.938, kw=(2,1,3), dk=1, window='hanning', rmin=1.5, rmax=4.2, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = 0.6*max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8, win=2,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', win=2, _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', win=2, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', win=2, _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #12
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    else:
        folder = self.baseline

    data = read_xdi(join(self.path, 'UO2.chik'), _larch=self._larch)

    gds = Group(amp=Parameter(1, vary=True, _larch=self._larch),
                enot=Parameter(0.01, vary=True, _larch=self._larch),
                sso=Parameter(0.003, vary=True, _larch=self._larch),
                ssu=Parameter(0.003, vary=True, _larch=self._larch),
                sso2=Parameter(0.003, vary=True, _larch=self._larch),
                dro=Parameter(0.0001, vary=True, _larch=self._larch),
                dru=Parameter(0.0001, vary=True, _larch=self._larch),
                dro2=Parameter(0.0001, vary=True, _larch=self._larch),
                nu=Parameter(12, vary=True, _larch=self._larch),
                no2=Parameter(expr='2*nu', _larch=self._larch),
                _larch=self._larch)

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # 1st shell O SS
            s02='amp',
            e0='enot',
            sigma2='sso',
            deltar='dro',
            _larch=self._larch))
    # paths.append(feffpath(realpath(join(folder, "feff0002.dat")), # triangle in first shell
    #                       s02    = 'amp',
    #                       e0     = 'enot',
    #                       sigma2 = 'sso*1.5',
    #                       deltar = 'dro*(1+sqrt(2))/2', _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0003.dat")),  # 2nd shell U SS
            degen=1,
            s02='amp*nu',
            e0='enot',
            sigma2='ssu',
            deltar='dru',
            _larch=self._larch))
    # paths.append(feffpath(realpath(join(folder, "feff0004.dat")), # 1st shell, longer triangle
    #                       s02    = 'amp',
    #                       e0     = 'enot',
    #                       sigma2 = '2*sso',
    #                       deltar = '2*dro', _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0006.dat")),  # 3rd shell O SS
            degen=1,
            s02='amp*no2',
            #s02    = 'amp*nu*2',
            e0='enot',
            sigma2='sso2',
            deltar='dro2',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0007.dat")
                     ),  # 1st shell, non-forward linear through absorber
            s02='amp',
            e0='enot',
            sigma2='sso2',
            deltar='dro2',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(
                folder, "feff0008.dat")),  # 1st shell forward through absorber
            s02='amp',
            e0='enot',
            sigma2='2*sso',
            deltar='2*dro',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0009.dat")),  # rattle in 1st shell
            s02='amp',
            e0='enot',
            sigma2='2*sso',
            deltar='2*dro',
            _larch=self._larch))

    trans = feffit_transform(kmin=3,
                             kmax=11,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.25,
                             rmax=4.3,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 win=2,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              win=2,
              _larch=self._larch)
        _plot(dset.data.r,
              dset.data.chir_re,
              label='data',
              win=2,
              _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              win=2,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #13
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    firstshell = False  # no 1st shell fit for this material

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'uranyl.chik'), _larch=self._larch)

    gds = Group(
        amp=Parameter(1, vary=True, _larch=self._larch),
        enot=Parameter(1e-7, vary=True, _larch=self._larch),
        #enot   = Parameter(1e-7,   vary=True,  _larch=self._larch, min=0, max=13),
        enoteq=Parameter(expr='enot', _larch=self._larch),
        deloax=Parameter(1e-7, vary=True, _larch=self._larch),
        deloeq=Parameter(1e-7, vary=True, _larch=self._larch),
        sigoax=Parameter(0.003, vary=True, _larch=self._larch),
        sigoeq=Parameter(0.003, vary=True, _larch=self._larch),
        nax=Parameter(2.0, vary=False, _larch=self._larch),
        neq=Parameter(6, vary=False, _larch=self._larch),  #, min=0, max=12),
        _larch=self._larch)

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # axial oxygen
            degen=1,
            s02='amp*nax',
            e0='enot',
            sigma2='sigoax',
            deltar='deloax',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0003.dat")),  # equatorial oxygen
            degen=1,
            s02='amp*neq',
            e0='enoteq',
            sigma2='sigoeq',
            deltar='deloeq',
            _larch=self._larch))

    paths.append(
        feffpath(
            realpath(join(folder, "feff0008.dat")),  # axial oxygen, rattle
            degen=1,
            s02='amp*nax',
            e0='enot',
            sigma2='sigoax*4',
            deltar='deloax*2',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder,
                          "feff0009.dat")),  # axial oxygen, non-forward
            degen=1,
            s02='amp*nax',
            e0='enot',
            sigma2='sigoax',
            deltar='deloax*2',
            _larch=self._larch))
    paths.append(
        feffpath(
            realpath(join(folder, "feff0010.dat")),  # axial oxygen, forward
            degen=1,
            s02='amp*nax',
            e0='enot',
            sigma2='sigoax',
            deltar='deloax*2',
            _larch=self._larch))

    trans = feffit_transform(kmin=3,
                             kmax=11,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.0,
                             rmax=3.2,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 win=2,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              win=2,
              _larch=self._larch)
        _plot(dset.data.r,
              dset.data.chir_re,
              label='data',
              win=2,
              _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              win=2,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells = '_1st'

    write_ascii(join(self.folder, fittest, "fit_" + which + ".k"),
                dset.data.k,
                dset.data.chi,
                dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_" + which + ".r"),
                dset.data.r,
                dset.data.chir_mag,
                dset.model.chir_mag,
                dset.data.chir_re,
                dset.model.chir_re,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_' + which + '.gp'), 'w') as inp:
        inp.write(
            renderer.render_path(
                'plot.mustache',  # gnuplot mustache file
                {
                    'material': 'uranyl',
                    'model': which,
                    'fittest': fittest,
                    'shells': shells,
                    'kmin': 3,
                    'kmax': 11,
                    'rmin': 1.0,
                    'rmax': 3.2,
                    'offset': 1,
                }))

    return fit
Beispiel #14
0
    def compare(self, nnnn=1, part='feff', use_wrapper=False, _larch=None):
        """
        compare a feffNNNN.dat file from the testrun with the same file from the baseline calculation

            group.compare(N, part, use_wrapper)

        where N is the path index, part is one of 
            feff    :      test the magnitude AND phase of F_eff (default)
            amp     :      test the total amplitude of the path
            phase   :      test the total phase of the path
            lambda  :      test the mean free path
            caps    :      test the central atom phase shift
            redfact :      test the reduction factor
            rep     :      test the real part of the complex wavenumber

        and use_wrapper is True if the test is to use the python interface to the feffpath library
        or False if the test is to use the monolithic feff.

        """
        if self._larch is None:
            raise Warning("cannot do path comparison -- larch broken?")
            
        if not self.feffran:
            print colored("You have not yet run the test Feff calculation", 'magenta', attrs=['bold'])
            return
            
        if not self.available(nnnn):
            print colored("Path %d was not saved from the test Feff calculation" % nnnn, 'magenta', attrs=['bold'])
            return
            
        how='monolithic'
        if use_wrapper: how = 'wrapper'
        nnnndat = "feff%4.4d.dat" % nnnn
        
        blpath = feffpath(join(self.baseline, nnnndat))
        if use_wrapper and self.wrapper_available: # make the f3ffNNNN.dat file on the fly
            self.sp.phpad=join(self.testrun, 'phase.pad')
            self.sp.nnnn=True
            self.sp.index=nnnn
            self.sp.verbose=self.verbose
            self.snarf_geometry(nnnn)
            here = getcwd()
            chdir(self.testrun)
            self.sp.make()
            chdir(here)
            n3nndat = "f3ff%4.4d.dat" % nnnn
            trpath = feffpath(join(self.testrun,  n3nndat))
        else:                   # the feffNNNN.dat file was made by the monolithic feff run
            trpath = feffpath(join(self.testrun,  nnnndat))
        
        if part=='feff':
            baseline_1 = getattr(blpath._feffdat, 'mag_feff') # + np.random.uniform(0,1,size=1)
            testrun_1  = getattr(trpath._feffdat, 'mag_feff')
            baseline_2 = getattr(blpath._feffdat, 'pha_feff') # + np.random.uniform(0,1,size=1)
            testrun_2  = getattr(trpath._feffdat, 'pha_feff')
            ylabel     = 'magnitude and phase'
            label      = 'magnitude' 
        elif part=='amp':
            baseline_1 = getattr(blpath._feffdat, 'amp')
            testrun_1  = getattr(trpath._feffdat, 'amp')
            ylabel     = 'total amplitude'
            label      = 'amplitude' 
        elif part=='phase':
            baseline_1 = getattr(blpath._feffdat, 'pha')
            testrun_1  = getattr(trpath._feffdat, 'pha')
            ylabel     = 'total phase shift'
            label      = 'phase' 
        elif part=='lambda':
            baseline_1 = getattr(blpath._feffdat, 'lam')
            testrun_1  = getattr(trpath._feffdat, 'lam')
            ylabel     = 'mean free path'
            label      = 'MFP' 
        elif part=='caps':
            baseline_1 = getattr(blpath._feffdat, 'real_phc')
            testrun_1  = getattr(trpath._feffdat, 'real_phc')
            ylabel     = 'central atom phase shift'
            label      = 'CAPS' 
        elif part=='redfact':
            baseline_1 = getattr(blpath._feffdat, 'red_fact')
            testrun_1  = getattr(trpath._feffdat, 'red_fact')
            ylabel     = 'reduction factor'
            label      = 'reduction factor'
        elif part=='rep':
            baseline_1 = getattr(blpath._feffdat, 'rep')
            testrun_1  = getattr(trpath._feffdat, 'rep')
            ylabel     = 'real part of p(k)'
            label      = 'Re[p(k)]'
        else:
            if self.verbose: print colored("Unknown choice of parts \"%s\"\nmust be one of (feff|amp|phase|lambda|caps|redfact|rep)\nusing feff" % part,
                                           'magenta', attrs=['bold'])
            part       = 'feff'
            baseline_1 = getattr(blpath._feffdat, 'mag_feff')
            testrun_1  = getattr(trpath._feffdat, 'mag_feff')
            baseline_2 = getattr(blpath._feffdat, 'pha_feff')
            testrun_2  = getattr(trpath._feffdat, 'pha_feff')
            ylabel     = 'magnitude and phase'
            label      = 'magnitude' 
            
            
        scf="without SCF"
        if self.doscf: scf="with SCF"
        
        self.rfactor_2 = 0
        self.rfactor = sum((baseline_1 - testrun_1)**2) / sum(baseline_1**2)
        if self.verbose: 
            print colored("\nComparing %s of %s (%s) (%s)" % (label, nnnndat, scf, how), 'yellow', attrs=['bold'])
            self.geometry(blpath)
            
        if self.verbose: 
            color = 'green'  if self.rfactor < self.epsilon else 'magenta'
            print label + " R-factor = " + colored("%.3f" % self.rfactor, color, attrs=['bold'])
        if part=='feff':
            self.rfactor_2 = sum((testrun_2 - testrun_2)**2) / sum(baseline_2**2)
            if self.verbose: 
                color = 'green'  if self.rfactor_2 < self.epsilon else 'magenta'
                print "phase R-factor = " + colored("%.3f" % self.rfactor_2, color, attrs=['bold'])
        if self.verbose: print ""
        
        if self.doplot:
            _newplot(blpath._feffdat.k, baseline_1, _larch=self._larch, label=label+' of baseline',
                     xlabel='wavenumber $\AA^{-1}$', ylabel=ylabel, title=nnnndat, show_legend=True, legend_loc='best')
            _plot   (trpath._feffdat.k, testrun_1,  _larch=self._larch, label=label+' of test run')
            if part=='feff':
                _plot(blpath._feffdat.k, np.gradient(baseline_2), _larch=self._larch, label='grad(phase of baseline)')
                _plot(trpath._feffdat.k, np.gradient(testrun_2),  _larch=self._larch, label='grad(phase of test run)')
                
        if use_wrapper and self.wrapper_available:
            unlink(join(self.testrun,  n3nndat))
            self.sp.clear()

        if part=='feff':
            return self.rfactor < self.epsilon and self.rfactor_2 < self.epsilon
        else:
            return self.rfactor < self.epsilon
Beispiel #15
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'Copper.chik'), _larch=self._larch)

    gds = Group(amp    = Parameter(1,     vary=True,  _larch=self._larch),
                enot   = Parameter(1e-7,  vary=True,  _larch=self._larch),
                ss1    = Parameter(0.003, vary=True,  _larch=self._larch), _larch=self._larch  )

    if firstshell:
        gds.delr   = Parameter(1e-7,   vary=True, _larch=self._larch)
        dr1param   = 'delr'
    else:
        gds.thetad = Parameter(500,   vary=True,  _larch=self._larch)
        gds.temp   = Parameter(10,    vary=False, _larch=self._larch)
        gds.alpha  = Parameter(1e-7,  vary=True,  _larch=self._larch)
        dr1param   = 'alpha*reff'

    imax = 16
    if firstshell: imax = 2
    paths = list()
    for index in range(1,imax):
        nnnn = realpath(join(folder, "feff%4.4d.dat" % index))
        if not exists(nnnn):
            continue
        #end if
        if index > 1:
            sigsqr = 'sigma2_debye(temp, thetad)' 
        else:
            sigsqr = 'ss1'
        #end if
        paths.append(feffpath(nnnn,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = sigsqr,
                              deltar = dr1param, _larch=self._larch))
    #end for

    rx  = 5.0
    if firstshell: rx  = 2.8

    trans = feffit_transform(kmin=3, kmax=15, kw=(2,1,3), dk=1, window='hanning', rmin=1, rmax=rx, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_'+which+shells+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'Copper',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 15,
                                         'rmin': 1,
                                         'rmax': rx,
                                         'offset': 2,
                                     } ))

    return fit
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    else:
        folder = self.baseline
    #end if

    data = read_xdi(join(self.path, 'bromoadamantane.chik'), _larch=self._larch)

    gds = Group(amp     = Parameter(1.021,     vary=False, _larch=self._larch),
                enot    = Parameter(4.01,      vary=True,  _larch=self._larch),
                delr    = Parameter(-0.007,    vary=True,  _larch=self._larch),
                brc     = Parameter(expr = '1.9521+delr',  _larch=self._larch),
                ss      = Parameter(0.003,     vary=True,  _larch=self._larch),
                phir    = Parameter(109.29960 * 3.141592653589793 / 180,   vary=False, _larch=self._larch),
                cc      = Parameter(1.53780,   vary=False, _larch=self._larch),
                tanbeta = Parameter(expr = '(brc+cc)*tan(phir/2) / (brc-cc)', _larch=self._larch),
                beta    = Parameter(expr = 'atan(tanbeta)', _larch=self._larch),
                brc2    = Parameter(expr = '(brc-cc)*cos(phir/2)/cos(beta)', _larch=self._larch),
                drh     = Parameter(0.04,      vary=True,  _larch=self._larch),
                ssh     = Parameter(0.005,     vary=True,  _larch=self._larch),
                ss2     = Parameter(expr = 'ss*(brc2/brc)**2', _larch=self._larch),
                c3      = Parameter(-0.0007,   vary=True,  _larch=self._larch),
                _larch=self._larch  )

    paths = list()
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ss',
                          deltar = 'delr',
                          third  = 'c3', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0002.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ss2',
                          deltar = 'brc2-2.8565', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0003.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ssh',
                          deltar = 'drh', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0004.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = '(ss+ss2)/2',
                          deltar = '(brc+brc2+cc)/2 - 3.173', _larch=self._larch))
    paths.append(feffpath(realpath(join(folder, "feff0005.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = '(ss+ss2)/2',
                          deltar = '(brc+brc2+cc)/2 - 3.173', _larch=self._larch))


    trans = feffit_transform(kmin=3, kmax=13, kw=(2,1,3), dk=1, window='hanning', rmin=1.25, rmax=3, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8, win=2,
                 xlabel=r'$R \rm\,(\AA)$', label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', win=2, _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', win=2, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', win=2, _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #17
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    dmt = read_xdi(join(self.path, 'dmt.chik'), _larch=self._larch)
    mmt = read_xdi(join(self.path, 'mmt.chik'), _larch=self._larch)

    gds = Group(amp     = Parameter(0.9,       vary=True,  _larch=self._larch),
                enot    = Parameter(1e-7,      vary=True,  _larch=self._larch),
                delr_c  = Parameter(1e-7,      vary=True,  _larch=self._larch),
                ss_c    = Parameter(0.003,     vary=True,  _larch=self._larch),
                delr_cl = Parameter(1e-7,      vary=True,  _larch=self._larch),
                ss_cl   = Parameter(0.003,     vary=True,  _larch=self._larch),
                _larch=self._larch  )

    paths_dmt = list()
    paths_dmt.append(feffpath(realpath(join(folder, "feff0001.dat")),
                              degen  = 2,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ss_c',
                              deltar = 'delr_c', _larch=self._larch))
    paths_dmt.append(feffpath(realpath(join(folder, "feff0002.dat")),
                              degen  = 2,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ss_cl',
                              deltar = 'delr_cl', _larch=self._larch))
    paths_mmt = list()
    paths_mmt.append(feffpath(realpath(join(folder, "feff0001.dat")),
                              degen  = 1,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ss_c',
                              deltar = 'delr_c', _larch=self._larch))
    paths_mmt.append(feffpath(realpath(join(folder, "feff0002.dat")),
                              degen  = 3,
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ss_cl',
                              deltar = 'delr_cl', _larch=self._larch))


    trans = feffit_transform(kmin=3, kmax=13, kw=(2,1,3), dk=1, window='hanning', rmin=1.25, rmax=3, _larch=self._larch)
    dset  = [feffit_dataset(data=dmt, pathlist=paths_dmt, transform=trans, _larch=self._larch),
             feffit_dataset(data=mmt, pathlist=paths_mmt, transform=trans, _larch=self._larch)]
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset[0].data.chir_mag)/2
        _newplot(dset[0].data.r,  dset[0].data.chir_mag+offset, xmax=5, win=1,
                 xlabel=r'$R \rm\,(\AA)$', label='dimethyltin',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset[0].model.r, dset[0].model.chir_mag+offset,   label='fit',  win=1, _larch=self._larch)
        _plot(dset[0].data.r,  dset[0].data.chir_re,            label='dimethyltin', win=1, _larch=self._larch)
        _plot(dset[0].model.r, dset[0].model.chir_re,           label='fit',  win=1, _larch=self._larch)

        _plot(dset[1].data.r,  dset[1].data.chir_mag+7*offset,  label='monomethyltin', win=1, _larch=self._larch)
        _plot(dset[1].model.r, dset[1].model.chir_mag+7*offset, label='fit',  win=1, _larch=self._larch)
        _plot(dset[1].data.r,  dset[1].data.chir_re+6*offset,   label='monomethyltin', win=1, _larch=self._larch)
        _plot(dset[1].model.r, dset[1].model.chir_re+6*offset,  label='fit',  win=1, _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+".k"), dset.data[0].k, dset.data[0].chi, dset.model[0].chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+".r"), dset.data[0].r, dset.data[0].chir_mag, dset.model[0].chir_mag,
                dset.data[0].chir_re, dset.model[0].chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_'+which+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'methyltin',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 13,
                                         'rmin': 1.25,
                                         'rmax': 3,
                                         'offset': 1,
                                     } ))

    return fit
Beispiel #18
0
def do_fit(self, which):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, 'baseline', which))
    #endif

    print '>>>>>> %s' % folder

    data = read_xdi(join(self.path, 'Copper.chik'), _larch=self._larch)

    gds = Group(amp=Parameter(1, vary=True),
                enot=Parameter(1e-7, vary=True),
                thetad=Parameter(500, vary=True),
                temp=Parameter(10, vary=False),
                alpha=Parameter(1e-7, vary=True),
                ss1=Parameter(0.003, vary=True),
                _larch=self._larch)

    paths = list()
    for index in range(1, 14):
        nnnn = realpath(join(folder, "feff%4.4d.dat" % index))
        if not exists(nnnn):
            continue
        #end if
        if index > 1:
            sigsqr = 'sigma2_debye(temp, thetad)'
        else:
            sigsqr = 'ss1'
        #end if
        paths.append(
            feffpath(nnnn,
                     s02='amp',
                     e0='enot',
                     sigma2=sigsqr,
                     deltar='alpha*reff',
                     _larch=self._larch))
    #end for

    trans = feffit_transform(kmin=3,
                             kmax=16,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.7,
                             rmax=5.1,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 win=2,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              win=2,
              _larch=self._larch)
        _plot(dset.data.r,
              dset.data.chir_re,
              label='data',
              win=2,
              _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              win=2,
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    return fit
Beispiel #19
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'UO2.chik'), _larch=self._larch)

    gds = Group(amp    = Parameter(1,      vary=True, _larch=self._larch),
                enot   = Parameter(1e-7,   vary=True, _larch=self._larch),
                sso    = Parameter(0.003,  vary=True, _larch=self._larch),
                dro    = Parameter(1e-7,   vary=True, _larch=self._larch), _larch=self._larch  )

    if not firstshell:
        gds.ssu    = Parameter(0.003,  vary=True, _larch=self._larch)
        gds.sso2   = Parameter(0.003,  vary=True, _larch=self._larch)
        gds.dru    = Parameter(1e-7,   vary=True, _larch=self._larch)
        gds.dro2   = Parameter(1e-7,   vary=True, _larch=self._larch)
        gds.nu     = Parameter(12,     vary=True, _larch=self._larch)
        gds.no2    = Parameter(expr='2*nu',       _larch=self._larch)

    paths = list() 
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")), # 1st shell O SS
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'sso',
                          deltar = 'dro', _larch=self._larch))

    if not firstshell:
        # paths.append(feffpath(realpath(join(folder, "feff0002.dat")), # triangle in first shell
        #                       s02    = 'amp',
        #                       e0     = 'enot',
        #                       sigma2 = 'sso*(1+sqrt(3))**2',
        #                       deltar = 'dro*(1+sqrt(3))/2', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0003.dat")), # 2nd shell U SS
                              degen  = 1,
                              s02    = 'amp*nu',
                              e0     = 'enot',
                              sigma2 = 'ssu',
                              deltar = 'dru', _larch=self._larch))
        # paths.append(feffpath(realpath(join(folder, "feff0004.dat")), # 1st shell, longer triangle
        #                       s02    = 'amp',
        #                       e0     = 'enot',
        #                       sigma2 = 'sso*(1+sqrt(2/3))**2',
        #                       deltar = '(1+sqrt(2/3))*dro', _larch=self._larch))
        # paths.append(feffpath(realpath(join(folder, "feff0005.dat")), # 1st shell, longer U-O-U triangle
        #                       degen  = 1,
        #                       s02    = 'amp*nu',
        #                       e0     = 'enot',
        #                       sigma2 = 'sso*ssu/2',
        #                       deltar = '(1+sqrt(2/3))*dro', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0006.dat")), # 3rd shell O SS
                              degen  = 1,
                              s02    = 'amp*no2',
                              e0     = 'enot',
                              sigma2 = 'sso2',
                              deltar = 'dro2', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0007.dat")), # 1st shell, non-forward linear through absorber
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '2*sso2',
                              deltar = '2*dro2', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0008.dat")), # 1st shell forward through absorber
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '2*sso',
                              deltar = '2*dro', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0009.dat")), # rattle in 1st shell
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '2*sso',
                              deltar = '2*dro', _larch=self._larch))

    rx  = 4.3
    if firstshell: rx  = 2.5

    trans = feffit_transform(kmin=3, kmax=11, kw=(2,1,3), dk=1, window='hanning', rmin=1.25, rmax=rx, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_'+which+shells+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'UO2',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 11,
                                         'rmin': 1.25,
                                         'rmax': rx,
                                         'offset': 0.75,
                                     } ))

    return fit
Beispiel #20
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'BaZrO3.chik'), _larch=self._larch)

    gds = Group(amp    = Parameter(0.95,    vary=True,  _larch=self._larch),
                enot   = Parameter(1e-7,    vary=True,  _larch=self._larch),
                sso    = Parameter(0.003,   vary=True,  _larch=self._larch),
                czr    = Parameter(0.,      vary=False, _larch=self._larch), _larch=self._larch  )

    if firstshell:
        gds.delr   = Parameter(1e-7,    vary=True,  _larch=self._larch)
        dr1param   = 'delr'
    else:
        gds.alpha  = Parameter(0.00001, vary=True,  _larch=self._larch)
        gds.ssba   = Parameter(0.003,   vary=True,  _larch=self._larch)
        gds.sszr   = Parameter(0.003,   vary=True,  _larch=self._larch)
        gds.eba    = Parameter(1e-7,    vary=True,  _larch=self._larch)
        gds.ezr    = Parameter(1e-7,    vary=True,  _larch=self._larch)
        #gds.eba    = Parameter(expr='enot',          _larch=self._larch)
        #gdsezr    = Parameter(expr='enot',         _larch=self._larch)
        gds.sso2   = Parameter(0.003,   vary=True,  _larch=self._larch)
        dr1param   = 'alpha*reff'

    paths = list()
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")),
                          s02    = 'amp',
                          deltar = dr1param,
                          e0     = 'enot',
                          sigma2 = 'sso',
                          _larch=self._larch))
    if not firstshell:
        paths.append(feffpath(realpath(join(folder, "feff0002.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso*1.5',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0003.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'eba',
                              sigma2 = 'ssba',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0004.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'ezr',
                              sigma2 = 'sszr',
                              third  = 'czr',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0005.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso*2',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0006.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = '(enot+ezr)/2',
                              sigma2 = 'sszr',
                              third  = 'czr',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0007.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso*2',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0009.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = '(2*enot+ezr)/3',
                              sigma2 = 'sszr',
                              third  = 'czr',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0008.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso*4',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0011.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = '(enot+eba)/2',
                              sigma2 = 'ssba+sso',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0012.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso2',
                              _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0013.dat")),
                              s02    = 'amp',
                              deltar = 'alpha*reff',
                              e0     = 'enot',
                              sigma2 = 'sso+sso2',
                              _larch=self._larch))

    rx  = 4.5
    if firstshell: rx  = 1.95

    trans = feffit_transform(kmin=3, kmax=14.5, kw=(2,1,3), dk=1, window='hanning', rmin=1.2, rmax=rx, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8,
              xlabel=r'$R \rm\,(\AA)$', label='data',
              ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
              title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_'+which+shells+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'BaZrO3',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 14.5,
                                         'rmin': 1.2,
                                         'rmax': rx,
                                         'offset': 1,
                                     } ))

    return fit
Beispiel #21
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'bromoadamantane.chik'), _larch=self._larch)

    gds = Group(amp     = Parameter(0.9,       vary=True,  _larch=self._larch),
                enot    = Parameter(4.01,      vary=True,  _larch=self._larch),
                delr    = Parameter(1e-7  ,    vary=True,  units='AA',   decimals=3, _larch=self._larch),
                ss      = Parameter(0.003,     vary=True,  units='AA^2', _larch=self._larch),
                c3      = Parameter(1e-7,      vary=False, _larch=self._larch),
                _larch=self._larch  )
    if not firstshell:
        gds.brc     = Parameter(expr = '1.9521+delr',  units='AA',  _larch=self._larch)
        #gds.phir    = Parameter(109.29960 * 3.141592653589793 / 180,   vary=False, _larch=self._larch)
        gds.cc      = Parameter(1.53780,   vary=False, _larch=self._larch)
        #gds.tanbeta = Parameter(expr = '(brc+cc)*tan(phir/2) / (brc-cc)', _larch=self._larch)
        #gds.beta    = Parameter(expr = 'atan(tanbeta)', _larch=self._larch)
        #gds.brc2    = Parameter(expr = '(brc-cc)*cos(phir/2)/cos(beta)',  units='AA', _larch=self._larch)
        gds.drh     = Parameter(0.04,      vary=True,  units='AA', decimals=3, _larch=self._larch)
        gds.ssh     = Parameter(0.005,     vary=True,  units='AA^2', _larch=self._larch)
        gds.ss2     = Parameter(expr = 'ss*(brc2/brc)**2', units ='AA^2', _larch=self._larch)
        gds.drc     = Parameter(0.04,      vary=True,  units='AA', decimals=3, _larch=self._larch)
        gds.brc2    = Parameter(expr = '2.8565+drc',   units='AA', decimals=3, _larch=self._larch)
        
    paths = list()
    paths.append(feffpath(realpath(join(folder, "feff0001.dat")),
                          s02    = 'amp',
                          e0     = 'enot',
                          sigma2 = 'ss',
                          deltar = 'delr',
                          third  = 'c3', _larch=self._larch))

    if not firstshell:
        paths.append(feffpath(realpath(join(folder, "feff0002.dat")),
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ss2',
                              #deltar = 'brc2-2.8565',
                              deltar = 'drc',_larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0003.dat")),
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = 'ssh',
                              deltar = 'drh', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0004.dat")),
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '(ss+ss2)/2',
                              deltar = '(brc+brc2+cc)/2 - 3.173', _larch=self._larch))
        paths.append(feffpath(realpath(join(folder, "feff0005.dat")),
                              s02    = 'amp',
                              e0     = 'enot',
                              sigma2 = '(ss+ss2)/2',
                              deltar = '(brc+brc2+cc)/2 - 3.173', _larch=self._larch))

    rx  = 3
    if firstshell: rx  = 1.83

    trans = feffit_transform(kmin=3, kmax=11, kw=(2,1,3), dk=1, window='hanning', rmin=1, rmax=3, _larch=self._larch)
    dset  = feffit_dataset(data=data, pathlist=paths, transform=trans, _larch=self._larch)
    fit   = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = max(dset.data.chir_mag)
        _newplot(dset.data.r,  dset.data.chir_mag+offset, xmax=8,
                 xlabel=r'$R \rm\,(\AA)$', label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to '+self.folder, show_legend=True, _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_mag+offset, label='fit', _larch=self._larch)
        _plot(dset.data.r,  dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r, dset.model.chir_re, label='fit', _larch=self._larch)
    #end if
    
    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells='_1st'

    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".k"), dset.data.k, dset.data.chi, dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_"+which+shells+".r"), dset.data.r, dset.data.chir_mag, dset.model.chir_mag,
                dset.data.chir_re, dset.model.chir_re, labels="r data_mag fit_mag data_re fit_re", _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest,'fit_'+which+shells+'.gp'), 'w') as inp:
        inp.write(renderer.render_path( 'plot.mustache', # gnuplot mustache file
                                        {'material': 'bromoadamantane',
                                         'model': which,
                                         'fittest': fittest,
                                         'shells': shells,
                                         'kmin': 3,
                                         'kmax': 13,
                                         'rmin': 1,
                                         'rmax': rx,
                                         'offset': 0.2,
                                     } ))

    return fit
Beispiel #22
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'NiO.chik'), _larch=self._larch)
    if hasattr(data, 'wavenumber'):
        data.k = data.wavenumber

    gds = Group(amp=Parameter(1, vary=True, _larch=self._larch),
                enot=Parameter(1e-7, vary=True, _larch=self._larch),
                sso=Parameter(0.003, vary=True, _larch=self._larch),
                _larch=self._larch)

    if firstshell:
        gds.delr = Parameter(1e-7, vary=True, _larch=self._larch)
        dr1param = 'delr'
    else:
        gds.alpha = Parameter(1e-7, vary=True, _larch=self._larch)
        gds.ssni = Parameter(0.003, vary=True, _larch=self._larch)
        gds.sso2 = Parameter(0.003, vary=True, _larch=self._larch)
        #gds.sso3   = Parameter(0.003,  vary=True, _larch=self._larch)
        gds.ssni2 = Parameter(0.003, vary=True, _larch=self._larch)
        #gds.ssni3  = Parameter(0.003,  vary=True, _larch=self._larch)
        #gds.ssni4  = Parameter(0.003,  vary=True, _larch=self._larch)
        dr1param = 'alpha*reff'

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # 1st shell O SS
            s02='amp',
            e0='enot',
            sigma2='sso',
            deltar=dr1param,
            _larch=self._larch))
    if not firstshell:
        paths.append(
            feffpath(
                realpath(join(folder, "feff0002.dat")),  # 2nd shell Ni SS
                s02='amp',
                e0='enot',
                sigma2='ssni',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0003.dat")),  # O-O triangle
                s02='amp',
                e0='enot',
                sigma2='1.5*sso',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0004.dat")),  # O-Ni triangle
                s02='amp',
                e0='enot',
                sigma2='sso+ssni/2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0005.dat")),  # 3rd shell O SS
                s02='amp',
                e0='enot',
                sigma2='sso2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0006.dat")),  # 4th shell Ni SS
                s02='amp',
                e0='enot',
                sigma2='ssni2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0007.dat")),  # O-O non-forward linear
                s02='amp',
                e0='enot',
                sigma2='sso*2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0008.dat")),  # O-Ni forward scattering
                s02='amp',
                e0='enot',
                sigma2='ssni2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0009.dat")),  # O-O forward through absorber
                s02='amp',
                e0='enot',
                sigma2='sso*2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0011.dat")),  # O-Ni-O double forward
                s02='amp',
                e0='enot',
                sigma2='ssni2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(
                    join(folder, "feff0010.dat")
                ),  # O-O rattle (the order of 10 and 11 is different in Demeter's pathfinder!)
                s02='amp',
                e0='enot',
                sigma2='sso*4',
                deltar='alpha*reff',
                _larch=self._larch))

    rx = 4.2
    if firstshell: rx = 1.95

    trans = feffit_transform(kmin=3,
                             kmax=15.938,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.0,
                             rmax=rx,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = 0.6 * max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              _larch=self._larch)
        _plot(dset.data.r, dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells = '_1st'

    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".k"),
                dset.data.k,
                dset.data.chi,
                dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".r"),
                dset.data.r,
                dset.data.chir_mag,
                dset.model.chir_mag,
                dset.data.chir_re,
                dset.model.chir_re,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_' + which + shells + '.gp'),
              'w') as inp:
        inp.write(
            renderer.render_path(
                'plot.mustache',  # gnuplot mustache file
                {
                    'material': 'NiO',
                    'model': which,
                    'fittest': fittest,
                    'shells': shells,
                    'kmin': 3,
                    'kmax': 15.938,
                    'rmin': 1.0,
                    'rmax': rx,
                    'offset': 1,
                }))

    return fit
Beispiel #23
0
def do_fit(self, which, firstshell=False, fittest='baseline'):

    if which == 'testrun':
        folder = self.testrun
    elif which == 'baseline':
        folder = self.baseline
    else:
        folder = realpath(join(self.folder, fittest, which))
    #endif

    data = read_xdi(join(self.path, 'FeS2.chik'), _larch=self._larch)

    gds = Group(amp=Parameter(1, vary=True, _larch=self._larch),
                enot=Parameter(1e-7, vary=True, _larch=self._larch),
                ss=Parameter(0.003, vary=True, _larch=self._larch),
                _larch=self._larch)

    if firstshell:
        gds.delr = Parameter(1e-7, vary=True, _larch=self._larch)
        dr1param = 'delr'
    else:
        gds.alpha = Parameter(1e-7, vary=True, _larch=self._larch)
        gds.ss2 = Parameter(0.003, vary=True, _larch=self._larch)
        gds.ss3 = Parameter(expr='ss2', _larch=self._larch)
        gds.ssfe = Parameter(0.003, vary=True, _larch=self._larch)
        dr1param = 'alpha*reff'

    paths = list()
    paths.append(
        feffpath(
            realpath(join(folder, "feff0001.dat")),  # 1st shell S SS
            s02='amp',
            e0='enot',
            sigma2='ss',
            deltar=dr1param,
            _larch=self._larch))
    if not firstshell:
        paths.append(
            feffpath(
                realpath(join(folder, "feff0002.dat")),  # 2nd shell S SS
                s02='amp',
                e0='enot',
                sigma2='ss2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0003.dat")),  # 3rd shell S SS
                s02='amp',
                e0='enot',
                sigma2='ss3',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0004.dat")),  # 4th shell Fe SS
                s02='amp',
                e0='enot',
                sigma2='ssfe',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0005.dat")),  # S-S triangle
                s02='amp',
                e0='enot',
                sigma2='ss*1.5',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0006.dat")),  # S-Fe triangle
                s02='amp',
                e0='enot',
                sigma2='ss/2+ssfe',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0012.dat")),  # S-S non-forward linear
                s02='amp',
                e0='enot',
                sigma2='ss*2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder,
                              "feff0013.dat")),  # S-S forward scattering
                s02='amp',
                e0='enot',
                sigma2='ss*2',
                deltar='alpha*reff',
                _larch=self._larch))
        paths.append(
            feffpath(
                realpath(join(folder, "feff0014.dat")),  # S-S rattle
                s02='amp',
                e0='enot',
                sigma2='ss*4',
                deltar='alpha*reff',
                _larch=self._larch))

    rx = 4.2
    if firstshell: rx = 2.3

    trans = feffit_transform(kmin=3,
                             kmax=12.956,
                             kw=(2, 1, 3),
                             dk=1,
                             window='hanning',
                             rmin=1.2,
                             rmax=rx,
                             _larch=self._larch)
    dset = feffit_dataset(data=data,
                          pathlist=paths,
                          transform=trans,
                          _larch=self._larch)
    fit = feffit(gds, dset, _larch=self._larch)

    if self.doplot:
        offset = 0.6 * max(dset.data.chir_mag)
        _newplot(dset.data.r,
                 dset.data.chir_mag + offset,
                 xmax=8,
                 xlabel=r'$R \rm\,(\AA)$',
                 label='data',
                 ylabel=r'$|\chi(R)| \rm\,(\AA^{-3})$',
                 title='Fit to ' + self.folder,
                 show_legend=True,
                 _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_mag + offset,
              label='fit',
              _larch=self._larch)
        _plot(dset.data.r, dset.data.chir_re, label='data', _larch=self._larch)
        _plot(dset.model.r,
              dset.model.chir_re,
              label='fit',
              _larch=self._larch)
    #end if

    if self.verbose:
        print feffit_report(fit, _larch=self._larch)
    #end if

    shells = ''
    if firstshell: shells = '_1st'

    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".k"),
                dset.data.k,
                dset.data.chi,
                dset.model.chi,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)
    write_ascii(join(self.folder, fittest, "fit_" + which + shells + ".r"),
                dset.data.r,
                dset.data.chir_mag,
                dset.model.chir_mag,
                dset.data.chir_re,
                dset.model.chir_re,
                labels="r data_mag fit_mag data_re fit_re",
                _larch=self._larch)

    renderer = pystache.Renderer()
    with open(join(self.folder, fittest, 'fit_' + which + shells + '.gp'),
              'w') as inp:
        inp.write(
            renderer.render_path(
                'plot.mustache',  # gnuplot mustache file
                {
                    'material': 'FeS2',
                    'model': which,
                    'fittest': fittest,
                    'shells': shells,
                    'kmin': 3,
                    'kmax': 12.956,
                    'rmin': 1.2,
                    'rmax': rx,
                    'offset': 1,
                }))

    return fit