Пример #1
0
def get_xdilib():
    """make initial connection to XDI dll"""
    global XDILIB
    if XDILIB is None:
        XDILIB = get_dll('xdifile')
        XDILIB.XDI_errorstring.restype   = c_char_p
    return XDILIB
Пример #2
0
def get_xdilib():
    """make initial connection to XDI dll"""
    global XDILIB
    if XDILIB is None:
        XDILIB = get_dll('xdifile')
        XDILIB.XDI_errorstring.restype = c_char_p
    return XDILIB
Пример #3
0
 def __init__(self, phase_file=None, title=''):
     global F8LIB
     if F8LIB is None:
         try:
             F8LIB = get_dll('feff8lpath')
         except:
             pass
     self.reset(phase_file=phase_file, title=title)
Пример #4
0
 def __init__(self, phase_file=None, title=''):
     global F8LIB
     if F8LIB is None:
         try:
             F8LIB = get_dll('feff8lpath')
         except:
             pass
     self.reset(phase_file=phase_file, title=title)
Пример #5
0
def initializeLarchPlugin(_larch=None):
    """initialize F8LIB"""
    if _larch is not None:
        global F8LIB
        if F8LIB is None:
            try:
                F8LIB = get_dll('feff8lpath')
            except:
                pass
Пример #6
0
def sigma2_debye(t, theta, path=None, _larch=None):
    """calculate sigma2 for a Feff Path wih the correlated Debye model

    sigma2 = sigma2_debye(t, theta, path=None)

    Parameters:
    -----------
      t        sample temperature (in K)
      theta    Debye temperature (in K)
      path     FeffPath to cacluate sigma2 for [None]

    if path is None, the 'current path'
    (_sys.paramGroup._feffdat) is used.
    """
    global FEFF6LIB
    if FEFF6LIB is None:
        FEFF6LIB = get_dll('feff6')
        FEFF6LIB.sigma2_debye.restype = ctypes.c_double

    if path is None:
        try:
            path = _larch.symtable._sys.paramGroup
        except:
            pass
    try:
        fdat = path._feffdat
    except:
        return 0.00
    if theta < 1.e-5: theta = 1.e-5
    if t < 1.e-5: t = 1.e-5

    npts = len(fdat.geom)
    nat  = ctypes.pointer(ctypes.c_int(npts))
    t    = ctypes.pointer(ctypes.c_double(t))
    th   = ctypes.pointer(ctypes.c_double(theta))
    rs   = ctypes.pointer(ctypes.c_double(fdat.rnorman))
    ax   = (npts*ctypes.c_double)()
    ay   = (npts*ctypes.c_double)()
    az   = (npts*ctypes.c_double)()
    am   = (npts*ctypes.c_double)()
    for i, dat in enumerate(fdat.geom):
        s, iz, ip, x, y, z =  dat
        ax[i], ay[i], az[i], am[i] = x, y, z, atomic_mass(iz, _larch=_larch)

    return FEFF6LIB.sigma2_debye(nat, t, th, rs, ax, ay, az, am)
Пример #7
0
def sigma2_correldebye(natoms, tk, theta, rnorm, x, y, z, atwt):
    """
    internal sigma2 calc for a Feff Path wih the correlated Debye model

    these routines come courtesy of jj rehr and si zabinsky.

    Arguments:
      natoms  *int, lengths for x, y, z, atwt        [in]
      tk      *double, sample temperature (K)        [in]
      theta   *double, Debye temperature (K)         [in]
      rnorm   *double, Norman radius (Ang)           [in]
      x       *double, array of x coord (Ang)        [in]
      y       *double, array of y coord (Ang)        [in]
      x       *double, array of z coord (Ang)        [in]
      atwt    *double, array of atomic_weight (amu)  [in]

   Returns:
      sig2_cordby  double, calculated sigma2
    """
    global FEFF6LIB
    if FEFF6LIB is None:
        FEFF6LIB = get_dll('feff6')
        FEFF6LIB.sigma2_debye.restype = ctypes.c_double

    na = ctypes.pointer(ctypes.c_int(natoms))
    t = ctypes.pointer(ctypes.c_double(tk))
    th = ctypes.pointer(ctypes.c_double(theta))
    rs = ctypes.pointer(ctypes.c_double(rnorm))

    ax = (natoms * ctypes.c_double)()
    ay = (natoms * ctypes.c_double)()
    az = (natoms * ctypes.c_double)()
    am = (natoms * ctypes.c_double)()

    for i in range(natoms):
        ax[i], ay[i], az[i], am[i] = x[i], y[i], z[i], atwt[i]

    return FEFF6LIB.sigma2_debye(na, t, th, rs, ax, ay, az, am)
Пример #8
0
def sigma2_correldebye(natoms, tk, theta, rnorm, x, y, z, atwt):
    """
    internal sigma2 calc for a Feff Path wih the correlated Debye model

    these routines come courtesy of jj rehr and si zabinsky.

    Arguments:
      natoms  *int, lengths for x, y, z, atwt        [in]
      tk      *double, sample temperature (K)        [in]
      theta   *double, Debye temperature (K)         [in]
      rnorm   *double, Norman radius (Ang)           [in]
      x       *double, array of x coord (Ang)        [in]
      y       *double, array of y coord (Ang)        [in]
      x       *double, array of z coord (Ang)        [in]
      atwt    *double, array of atomic_weight (amu)  [in]

   Returns:
      sig2_cordby  double, calculated sigma2
    """
    global FEFF6LIB
    if FEFF6LIB is None:
        FEFF6LIB = get_dll('feff6')
        FEFF6LIB.sigma2_debye.restype = ctypes.c_double

    na = ctypes.pointer(ctypes.c_int(natoms))
    t  = ctypes.pointer(ctypes.c_double(tk))
    th = ctypes.pointer(ctypes.c_double(theta))
    rs = ctypes.pointer(ctypes.c_double(rnorm))

    ax = (natoms*ctypes.c_double)()
    ay = (natoms*ctypes.c_double)()
    az = (natoms*ctypes.c_double)()
    am = (natoms*ctypes.c_double)()

    for i in range(natoms):
        ax[i], ay[i], az[i], am[i] = x[i], y[i], z[i], atwt[i]

    return FEFF6LIB.sigma2_debye(na, t, th, rs, ax, ay, az, am)
Пример #9
0
def f1f2(z, energies, width=None, edge=None):
    """Return anomalous scattering factors f1, f2 from Cromer-Liberman

    Look-up and return f1, f2 for an element and array of energies
    from Cromer-Liberman (Cowan-Brennan implementation)

    Parameters
    ----------
    z:         atomic number of element
    energies:  array of x-ray energies (in eV)
    width:     width used to convolve values with lorentzian profile
    edge:      x-ray edge ('K', 'L3', etc) used to lookup energy
               width for convolution.

    Returns:
    ---------
    f1, f2:    anomalous scattering factors

    """
    global CLLIB
    if CLLIB is None:
        CLLIB = get_dll('cldata')

    en = as_ndarray(energies)

    if not isinstance(z, int):
        z  = atomic_number(z)
        if z is None:
            return None

    if z > 92:
        print( 'Cromer-Liberman data not available for Z>92')
        return

    if edge is not None or width is not None:
        natwid = core_width(element=z, edge=edge)
        if width is None and natwid not in (None, []):
            width = natwid

    if width is not None: # will convolve!
        e_extra = int(width*80.0)
        estep = (en[1:] - en[:-1]).min()
        emin = min(en) - e_extra
        emax = max(en) + e_extra

        npts = 1 + abs(emax-emin+estep*0.02)/abs(estep)
        en   = np.linspace(emin, emax, int(npts))
        nk   = int(e_extra / estep)
        sig  = width/2.0
        lor  = (1./(1 + ((np.arange(2*nk+1)-nk*1.0)/sig)**2))/(np.pi*sig)
        scale = lor.sum()

    # create ctypes pointers for the C function
    npts   = len(en)
    p_z    = ctypes.pointer(ctypes.c_int(int(z)))
    p_npts = ctypes.pointer(ctypes.c_int(npts))
    p_en   = (npts*ctypes.c_double)()
    p_f1   = (npts*ctypes.c_double)()
    p_f2   = (npts*ctypes.c_double)()

    for i in range(npts):
        p_en[i] = en[i]

    nout = CLLIB.f1f2(p_z, p_npts, p_en, p_f1, p_f2)
    f1 = np.array([i for i in p_f1[:]])
    f2 = np.array([i for i in p_f2[:]])
    if width is not None: # do the convolution
        f1 = np.interp(energies, en, convolve(f1, lor)[nk:-nk])/scale
        f2 = np.interp(energies, en, convolve(f2, lor)[nk:-nk])/scale
    return (f1, f2)
Пример #10
0
import h5py
import Image
import sqlalchemy
import wx
import ctypes
import ctypes.util

import scipy.io.netcdf
from scipy.io.netcdf import netcdf_file
import scipy.constants

loadlib =  ctypes.windll.LoadLibrary

# larch library bits...
from larch.larchlib import get_dll
cllib = get_dll('cldata')

# matplotlib, wxmplot
matplotlib.use('WXAgg')
mpl_data_files = matplotlib.get_py2exe_datafiles()
import wxmplot

# epics
import epics
ca = epics.ca.initialize_libca()

extra_files = ['inno_setup.iss', 'license.txt', 'readme.txt']

def gen_style(title):
    if title.endswith('.py'):
        title = title[:-3]
Пример #11
0
def f1f2(z, energies, width=None, edge=None, _larch=None):
    """Return anomalous scattering factors f1, f2 from Cromer-Liberman

    Look-up and return f1, f2 for an element and array of energies
    from Cromer-Liberman (Cowan-Brennan implementation)

    Parameters
    ----------
    z:         atomic number of element
    energies:  array of x-ray energies (in eV)
    width:     width used to convolve values with lorentzian profile
    edge:      x-ray edge ('K', 'L3', etc) used to lookup energy
               width for convolution.

    Returns:
    ---------
    f1, f2:    anomalous scattering factors

    """
    global CLLIB
    if CLLIB is None:
        CLLIB = get_dll('cldata')

    en = as_ndarray(energies)

    if not isinstance(z, int):
        z  = atomic_number(z, _larch=_larch)
        if z is None:
            return None

    if z > 92:
        print( 'Cromer-Liberman data not available for Z>92')
        return

    if edge is not None or width is not None and _larch is not None:
        natwid = core_width(element=z, edge=edge, _larch=_larch)
        if width is None and natwid not in (None, []):
            width = natwid

    if width is not None: # will convolve!
        e_extra = int(width*80.0)
        estep = (en[1:] - en[:-1]).min()
        emin = min(en) - e_extra
        emax = max(en) + e_extra

        npts = 1 + abs(emax-emin+estep*0.02)/abs(estep)
        en   = np.linspace(emin, emax, npts)
        nk   = int(e_extra / estep)
        sig  = width/2.0
        lor  = (1./(1 + ((np.arange(2*nk+1)-nk*1.0)/sig)**2))/(np.pi*sig)
        scale = lor.sum()

    # create ctypes pointers for the C function
    npts   = len(en)
    p_z    = ctypes.pointer(ctypes.c_int(int(z)))
    p_npts = ctypes.pointer(ctypes.c_int(npts))
    p_en   = (npts*ctypes.c_double)()
    p_f1   = (npts*ctypes.c_double)()
    p_f2   = (npts*ctypes.c_double)()

    for i in range(npts):
        p_en[i] = en[i]

    nout = CLLIB.f1f2(p_z, p_npts, p_en, p_f1, p_f2)
    f1 = np.array([i for i in p_f1[:]])
    f2 = np.array([i for i in p_f2[:]])
    if width is not None: # do the convolution
        f1 = np.interp(energies, en, convolve(f1, lor)[nk:-nk])/scale
        f2 = np.interp(energies, en, convolve(f2, lor)[nk:-nk])/scale
    return (f1, f2)
Пример #12
0
import h5py
import Image
import sqlalchemy
import wx
import ctypes
import ctypes.util

import scipy.io.netcdf
from scipy.io.netcdf import netcdf_file
import scipy.constants

loadlib = ctypes.windll.LoadLibrary

# larch library bits...
from larch.larchlib import get_dll
cllib = get_dll('cldata')

# matplotlib, wxmplot
matplotlib.use('WXAgg')
mpl_data_files = matplotlib.get_py2exe_datafiles()
import wxmplot

# epics
import epics
ca = epics.ca.initialize_libca()

extra_files = ['inno_setup.iss', 'license.txt', 'readme.txt']


def gen_style(title):
    if title.endswith('.py'):