def plotkk(self): """ Make a quick-n-dirty plot of the output of the KK transform. """ if not HASPLOT: return _newplot(self.energy, self.f2, _larch=self._larch, label='$f_2$', xlabel='Energy (eV)', ylabel='scattering factors', show_legend=True, legend_loc='lr') _plot(self.energy, self.fpp, _larch=self._larch, label="$f''(E)$") _plot(self.energy, self.f1, _larch=self._larch, label='$f_1$') _plot(self.energy, self.fp, _larch=self._larch, label="$f'(E)$")
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 lam : test the mean free path caps : test the central atom phase shift red_fact: 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_error("You have not yet run the test Feff calculation") return if not self.available(nnnn): print_error("Path %d was not saved from the test Feff calculation" % nnnn) return how = 'wrapper' if use_wrapper else 'executables' nnnndat = "feff%4.4d.dat" % nnnn blpath = feffpath(join(self.baseline, nnnndat), _larch=self._larch) if use_wrapper: # make the feffNNNN.dat file on the fly self.sp.phase_file = 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.calculate_xafs() finally: chdir(owd) n3nndat = "feff%4.4d.dat" % nnnn trpath = feffpath(join(self.testrun, n3nndat), _larch=self._larch) else: # the feffNNNN.dat file was made by the monolithic feff run trpath = feffpath(join(self.testrun, nnnndat), _larch=self._larch) 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 = np.sin(getattr(blpath._feffdat, 'pha_feff')) # + np.random.uniform(0,1,size=1) testrun_2 = np.sin(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 = np.sin(getattr(blpath._feffdat, 'pha')) testrun_1 = np.sin(getattr(trpath._feffdat, 'pha')) ylabel = 'total phase shift' label = 'phase' elif part=='lam': baseline_1 = getattr(blpath._feffdat, 'lam') testrun_1 = getattr(trpath._feffdat, 'lam') ylabel = 'mean free path' label = 'lambda' elif part=='phc': baseline_1 = getattr(blpath._feffdat, 'real_phc') testrun_1 = getattr(trpath._feffdat, 'real_phc') ylabel = 'central atom phase shift' label = 'phc' elif part=='red_fact': 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_error("Unknown choice of parts \"%s\"\nmust be one of (feff|amp|phase|lam|phc|red_fact|rep)\nusing feff" % part) part = 'feff' baseline_1 = getattr(blpath._feffdat, 'mag_feff') testrun_1 = getattr(trpath._feffdat, 'mag_feff') baseline_2 = np.sin(getattr(blpath._feffdat, 'pha_feff')) testrun_2 = np.sin(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_warn("\nComparing %s of %s (%s) (using %s)" % (label, nnnndat, "with SCF" if self.doscf else "without SCF", how)) self.print_geometry(blpath) print_warn("%s: %f v %f " % (blpath, sum(baseline_1**2) , sum(testrun_1**2))) if self.verbose: print label + " R-factor = " + test_text("%.9g" % self.rfactor, (self.rfactor < self.epsilon)) if part=='feff': self.rfactor_2 = sum((baseline_2 - testrun_2)**2) / sum(baseline_2**2) if self.verbose: print(" -- ",self.epsilon, sum((baseline_2 - testrun_2)**2), sum(baseline_2**2)) print "phase R-factor = " + test_text("%.9g" % self.rfactor_2, self.rfactor_2 < self.epsilon) 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 WRAPPER_AVAILABLE: self.sp.reset() if part=='feff': return self.rfactor < self.epsilon and self.rfactor_2 < self.epsilon else: return self.rfactor < self.epsilon