コード例 #1
0
ファイル: bravias.py プロジェクト: yns11/tst
def ferraris_and_ivaldi(ubi, tol=0.001):
    """
    Acta Cryst (1983) A39 595-596

    Determine the multiplicities of vectors in a computed powder pattern
    Match these to multiplicities according to lattice types
    ... appeals to powder person
    Tolerance is for grouping vector lengths.
    """
    cpar = ubitocellpars(ubi)
    cell = unitcell(cp)
    dlim = cell.ds(array([7, 7, 7]))
    u.makerings(dlim, tol)
    mult = [len(cell.ringhkls[d]) for d in cell.ringds]
    mx = max(mult)
    mn = min(mult)
    cases = {
        (2, 2): fi_triclinic,
        (4, 2): fi_monoclinic,
        (8, 2): fi_orthorhombic,
        (12, 2): fi_rhombohedral,
        (16, 2): fi_tetragonal,
        (24, 2): fi_hexagonal,
        (48, 2): fi_cubic
    }
コード例 #2
0
ファイル: indexer.py プロジェクト: mkutsal/ImageD11
 def setcell(self):
     """ Sets the unit cell parameters for indexing """
     cp = [
         self.transformpars.get("cell_%s" % (s))
         for s in "_a _b _c alpha beta gamma".split()
     ]
     self.unitcell = unitcell.unitcell(
         cp, self.transformpars.get("cell_lattice_[P,A,B,C,I,F,R]"))
コード例 #3
0
def makehexagonal( ubi ):
    """ Finds a nearby hexagonal cell """
    cp = indexing.ubitocellpars( ubi )
    a = (cp[0]+cp[1])/2
    cell = unitcell( (a,a,cp[2],90,90,120),"P")
    u = indexing.ubitoU( ubi )
    ub = np.dot( u, cell.B )
    return np.linalg.inv( ub )
コード例 #4
0
ファイル: forwards_project.py プロジェクト: mkutsal/ImageD11
def forwards_project( gr,
                      pars,
                      detector_size,
                      spatial,
                      dsmax,
                      gid):
    latt = "P"
    for k in pars.parameters.keys():
        if k.startswith("cell_lattice"):
            latt = pars.get(k)
    cell = unitcell.unitcell( indexing.ubitocellpars( gr.ubi ), latt )
    ds_hkl = cell.gethkls( dsmax )
    hkls = np.array( [ x[1] for x in ds_hkl] )
    gvecs = np.dot( gr.ub, hkls.T )
    wvln, wedge, chi = [ pars.get(x) for x in "wavelength", "wedge", "chi" ]
    tth, (eta1, eta2), (omega1, omega2) = transform.uncompute_g_vectors(
        gvecs, wvln, wedge=wedge, chi=chi)
    osign = float(pars.get("omegasign"))
    if osign != 1:
        print("# Flipping omegasign %f"%(osign))
        np.multiply( omega1, osign, omega1 )
        np.multiply( omega2, osign, omega2 )
    pars.set( "t_x", gr.translation[0] )
    pars.set( "t_y", gr.translation[1] )
    pars.set( "t_z", gr.translation[2] )
    fc1, sc1 = transform.compute_xyz_from_tth_eta(tth, eta1, omega1,
                                                  **pars.parameters)
    fc2, sc2 = transform.compute_xyz_from_tth_eta(tth, eta2, omega2,
                                                  **pars.parameters)
    # Now make a single list of output stuff:
    alltth = np.concatenate( (tth, tth))
    alleta = np.concatenate( (eta1, eta2) )
    allsc =  np.concatenate( (sc1, sc2) )
    allfc =  np.concatenate( (fc1, fc2) )
    sraw = np.zeros(allsc.shape)
    fraw = np.zeros(allsc.shape)
    for i,(s,f) in enumerate(zip( allsc, allfc )):
        sraw[i], fraw[i] = spatial.distort( s, f )
    allomega = np.concatenate( (omega1, omega2) )
    allhkls =  np.concatenate( (hkls, hkls) )
    order = np.argsort( allomega )
    # output ?
    # omega in range
    # peak in detector
    #  etc
    fmt = " % -4d % -3d % -3d % -3d % 8.4f % 7.2f % 8.2f % 8.2f % 8.2f % 8.2f % 8.2f"
    strs = []
    for i in order:
        s, f, o = sraw[i], fraw[i], allomega[i]
        if alltth[i] == 0:
            continue
        if inscan(  s, f, o, detector_size):
            line = fmt%(gid,allhkls[i][0],allhkls[i][1],allhkls[i][2],
                        alltth[i], alleta[i], allomega[i], allsc[i], allfc[i],
                        sraw[i], fraw[i] )
            strs.append( (allomega[i], line) ) # to be omega sortable
    return strs
コード例 #5
0
 def makecell(self):
     p = self.pars.parameters
     c = [
         float(v) for v in [
             p['cell__a'], p['cell__b'], p['cell__c'], p['cell_alpha'],
             p['cell_beta'], p['cell_gamma']
         ]
     ]
     self.cell = unitcell.unitcell(c, p['cell_lattice_[P,A,B,C,I,F,R]'])
     self.cell.makerings(limit=self.ds.max(), tol=self.ds_tol)
コード例 #6
0
 def test_hexagonal(self):
     a,c = self.a, self.c
     cell = unitcell( [ a*1.05, a*1.05, c*0.95, 90., 90.,120.], "P" )
     ub = np.dot( self.U, cell.B )
     h1 = (1,0,0)
     h2 = (0,0,1)
     g1 = np.dot( ub, h1 ) # a calc, wrong 
     g2 = np.dot( ub, h2 ) # c
     ideal = unitcell( [ a, a, c, 90., 90.,120.], "P" )
     ideal.makerings(0.3)
     ideal.orient( 0, g1, 1, g2 )
     gve = np.vstack( (g1 , g2) ).T
     for ubi in ideal.UBIlist:
         ufit = ubi_fit_2pks( ubi, g1, g2 )
         hold = np.dot( ubi, gve )
         drlvold = abs(hold - np.round(hold)).sum()
         hnew = np.dot( ufit, gve )
         drlvnew = abs(hnew - np.round(hnew)).sum()
         self.assertTrue( drlvold > 0 )
         self.assertAlmostEqual( drlvnew, 0 )
コード例 #7
0
ファイル: transformer.py プロジェクト: la-bella/ImageD11
    def addcellpeaks(self, limit=None):
        """
        Adds unit cell predicted peaks for fitting against
        Optional arg limit gives highest angle to use

        Depends on parameters:
            'cell__a','cell__b','cell__c', 'wavelength' # in angstrom
            'cell_alpha','cell_beta','cell_gamma' # in degrees
            'cell_lattice_[P,A,B,C,I,F,R]'
        """
        #
        # Given unit cell, wavelength and distance, compute the radial positions
        # in microns of the unit cell peaks
        #
        pars = self.parameterobj.get_parameters()
        cell = [
            pars[name] for name in [
                'cell__a', 'cell__b', 'cell__c', 'cell_alpha', 'cell_beta',
                'cell_gamma'
            ]
        ]
        lattice = pars['cell_lattice_[P,A,B,C,I,F,R]']
        if "tth" not in self.colfile.titles:
            self.compute_tth_eta()
        # Find last peak in radius
        if limit is None:
            highest = numpy.maximum.reduce(self.getcolumn("tth"))
        else:
            highest = limit
        w = pars['wavelength']
        ds = 2 * numpy.sin(transform.radians(highest) / 2.) / w
        self.dslimit = ds
        self.unitcell = unitcell.unitcell(cell, lattice)
        # If the space group is provided use xfab for generate unique hkls
        if 'cell_sg' in pars:
            self.theorypeaks = self.unitcell.gethkls_xfab(ds, pars['cell_sg'])
            tths = []
            self.theoryds = []
            for i in range(len(self.theorypeaks)):
                tths.append(2 * numpy.arcsin(w * self.theorypeaks[i][0] / 2.))
                self.theoryds.append(self.theorypeaks[i][0])
        else:
            # HO:  I have removed this part as it seems redundant ringds also calls gethkls
            # JPW: It was not redundant. theorypeaks is not defined anywhere else and you
            #      can't write a g-vector file without it.
            self.theorypeaks = self.unitcell.gethkls(ds)
            self.unitcell.makerings(ds)
            self.theoryds = self.unitcell.ringds
            tths = [
                numpy.arcsin(w * dstar / 2) * 2
                for dstar in self.unitcell.ringds
            ]
        self.theorytth = transform.degrees(numpy.array(tths))
コード例 #8
0
def makedata():
    global wavelength
    global dsmax
    global dsmin
    u = unitcell.unitcell(*rcell(gen))
    o = omat(gen)
    #print dot(o,o.T)
    ub = dot(o, u.B)

    print(u.tostring())
    meancell = pow(u.B[0, 0] * u.B[1, 1] * u.B[2, 2], -1. / 3.)
    if dsmax is None:
        dsmax = 20. / meancell
        dsmin = 5. / meancell

    hkls = u.gethkls(dsmax)
    # print "DSMAX",dsmax, meancell,len(hkls)

    myh = []
    for ds, h in hkls:
        if ds > dsmin:
            g = dot(ub, h)
            #       print h,ds, g, sqrt(dot( g,g))
            myh.append(h)

    myh = array(myh)
    gve = dot(ub, myh.T)
    # set wavelength to make the largest angle be 45 degrees
    if wavelength is None:
        print("set wavelength")
        wavelength = 2 * sin(pi / 8.0) / dsmax
    tth, eta, omega = transform.uncompute_g_vectors(gve, wavelength)
    e0, e1 = eta
    o0, o1 = omega

    gfinal = []

    omax = 5

    for i in range(len(tth)):
        if o0[i] > 0 and o0[i] < omax:
            gfinal.append(gve.T[i])
        if o1[i] > 0 and o1[i] < omax:
            gfinal.append(gve.T[i])
    f = open("ideal.ubi", "a")
    f.write("cell = '" + u.tostring() + "'\n")
    f.write('ub = ' + repr(ub))
    f.write("\nnpks = %d\n" % (len(gfinal)))
    f.close()
    return gfinal
コード例 #9
0
ファイル: ringselect.py プロジェクト: Python3pkg/ImageD11
import sys
from ImageD11.columnfile import *
from ImageD11.unitcell import unitcell
# put parfile, npeaks and tol and this would be general purpose!
c = columnfile(sys.argv[1])
u = unitcell((3.66, 3.66, 3.66, 90, 90, 90), "F")
u.makerings(1.)
print(u.ringds)
tth = [arcsin(0.144088 * d / 2) * 360 / pi for d in u.ringds]
m = abs(c.tth - tth[0]) < 0.1
for t in tth:
    m = m | (abs(c.tth - t) < 0.1)
c.filter(m)
c.writefile(sys.argv[2])
コード例 #10
0
ファイル: Index1DSearch.py プロジェクト: siachilles/ImageD11
#     language: python
#     name: python3
# ---

# Some exploration of the intexing in Joel's code. Orient along a scattering vector and then do a 1D search rotating around that vector. The idea is to get to something which searches all of the places something can be found in orientation space. But avoiding the 3D problem for small datasets.

# %matplotlib inline 
#notebook
import numpy as np, pylab as pl
from ImageD11 import indexing, unitcell, grain, transform, cImageD11
from scipy.spatial.transform import Rotation

# Generate some peaks
h,k,l = [x.ravel() for x in np.mgrid[-4:5,-4:5,-4:5]]

uc = unitcell.unitcell( [7.89, 8.910, 9.1011, 92, 97, 99], "P")

orient = Rotation.from_euler("XYZ",(10,20,31)).as_dcm()
ub = np.dot( orient, uc.B )
ubi = np.linalg.inv( ub )

gcalc = np.dot( ub, (h,k,l) )

modg = np.sqrt(gcalc*gcalc).sum(axis=0)

tth, eta, omega = transform.uncompute_g_vectors( gcalc, 0.3 )

pl.plot(tth, eta[0],".")
pl.plot(tth, eta[1],".")

selected_peak = sp = np.argmin(abs(tth - 4.17))