예제 #1
0
def GenerateList(dmin, dmax, reflist=None):
    """Generate reflections between dmin, dmax and store in reflist"""
    sample, inst = getSampleInst()
    if not sample:
        return
    rfl = sample.getRefList(reflist)
    if rfl is None:
        session.log.error('Reflection list %s not found', reflist)
        return
    sxtal = SXTalCell.fromabc(sample.a, sample.b, sample.c, sample.alpha,
                              sample.beta, sample.gamma, sample.bravais,
                              sample.laue)
    raw_list = sxtal.dataset(dmin, dmax)
    raw_as_list = raw_list.tolist()
    rfl.clear()
    count = 0
    for r in raw_as_list:
        hkl = tuple(r)
        if inst.isAllowed(hkl):
            rfl.append(tuple(r), None, None)
            count += 1
    session.log.info('Generated %d reflections', count)
예제 #2
0
    def Reorient(self, hkl1, pos1, hkl2, pos2):
        """Calculate orientation matrix from two indexed positions.

        hkl1: index of reflection 1
        pos1: position of reflection 1 (goniometer.position object)
        hkl2: index of reflection 2
        pos2: position of reflection 2
        """
        gmat = self.cell.CMatrix()
        cv_h1 = self.cell.CVector(hkl1)
        cv_h2 = self.cell.CVector(hkl2)

        cv_p1 = np.array(pos1.asC().c)
        cv_p2 = np.array(pos2.asC().c)

        bmat = _norm(complete_matrix(cv_p1, cv_p2))
        amat = _norm(complete_matrix(cv_h1, cv_h2))

        amat_i = np.linalg.inv(amat)
        temp = np.dot(bmat, amat_i)
        omat_t = np.dot(temp, gmat)
        omat = np.transpose(omat_t)
        cell = SXTalCell(omat)
        return cell
예제 #3
0
 def on_setLattice_clicked(self):
     lattice = self.latticeEdit.getValue()
     angles = self.angleEdit.getValue()
     newcell = SXTalCell.fromabc(*(lattice + angles))
     self.cellEdit._reinit(newcell)
예제 #4
0
 def clear(self):
     """Clear experiment-specific information."""
     Sample.clear(self)
     self.cell = SXTalCell.fromabc(5)
     self.peaklists = {}
     self.poslists = {}
예제 #5
0
class SXTalSample(Sample):
    parameters = {
        'cell':
        Param('Unit cell with matrix',
              type=SXTalCellType,
              settable=True,
              mandatory=False,
              default=SXTalCell.fromabc(5)),
        'a':
        Param('a', type=float, category='sample'),
        'b':
        Param('b', type=float, category='sample'),
        'c':
        Param('c', type=float, category='sample'),
        'alpha':
        Param('alpha', type=floatrange(1., 179.), category='sample'),
        'beta':
        Param('beta', type=floatrange(1., 179.), category='sample'),
        'gamma':
        Param('gamma', type=floatrange(1., 179.), category='sample'),
        'rmat':
        Param('rmat',
              type=listof(listof(float)),
              default=None,
              userparam=False),
        'ubmatrix':
        Param('UB matrix (rmat^T)',
              type=listof(listof(float)),
              category='sample'),
        'bravais':
        Param('Bravais lattice',
              type=oneof(*symmetry.Bravais.conditions),
              settable=True,
              default='P',
              category='sample'),
        'laue':
        Param('Laue group',
              type=oneof(*symmetry.symbols),
              settable=True,
              default='1',
              category='sample'),
        'peaklists':
        Param('Lists of peaks for scanning',
              internal=True,
              type=dictof(str, list),
              settable=True),
        'poslists':
        Param('Lists of positions for indexing',
              internal=True,
              type=dictof(str, list),
              settable=True),
    }

    def clear(self):
        """Clear experiment-specific information."""
        Sample.clear(self)
        self.cell = SXTalCell.fromabc(5)
        self.peaklists = {}
        self.poslists = {}

    def new(self, parameters):
        """Accepts several ways to spell new cell params."""
        lattice = parameters.pop('lattice', None)
        if lattice is not None:
            try:
                parameters['a'], parameters['b'], parameters['c'] = lattice
            except Exception:
                self.log.warning('invalid lattice spec ignored, should be '
                                 '[a, b, c]')
        angles = parameters.pop('angles', None)
        if angles is not None:
            try:
                parameters['alpha'], parameters['beta'], \
                    parameters['gamma'] = angles
            except Exception:
                self.log.warning('invalid angles spec ignored, should be '
                                 '[alpha, beta, gamma]')
        a = parameters.pop('a', None)
        if a is None:
            if 'cell' not in parameters:
                self.log.warning('using dummy lattice constant of 5 A')
            a = 5.0
        b = parameters.pop('b', a)
        c = parameters.pop('c', a)
        alpha = parameters.pop('alpha', 90.0)
        beta = parameters.pop('beta', 90.0)
        gamma = parameters.pop('gamma', 90.0)
        # TODO: map spacegroup/bravais/laue with triple-axis
        bravais = parameters.pop('bravais', 'P')
        laue = parameters.pop('laue', '1')
        if 'cell' not in parameters:
            parameters['cell'] = [a, b, c, alpha, beta, gamma, bravais, laue]
        Sample.new(self, parameters)

    def _applyParams(self, number, parameters):
        Sample._applyParams(self, number, parameters)
        if 'cell' in parameters:
            self.cell = parameters['cell']

    def doReadBravais(self):
        return self.cell.bravais.bravais

    def doWriteBravais(self, value):
        self.cell.bravais = symmetry.Bravais(value)

    def doReadLaue(self):
        return self.cell.laue.laue

    def doWriteLaue(self, value):
        self.cell.laue = symmetry.Laue(value)

    def doWriteCell(self, cell):
        params = cell.cellparams()
        self._setROParam('a', params.a)
        self._setROParam('b', params.b)
        self._setROParam('c', params.c)
        self._setROParam('alpha', params.alpha)
        self._setROParam('beta', params.beta)
        self._setROParam('gamma', params.gamma)
        self._setROParam('rmat', cell.rmat.tolist())
        self._setROParam('ubmatrix', cell.rmat.T.tolist())
        self._setROParam('bravais', cell.bravais.bravais)
        self._setROParam('laue', cell.laue.laue)

        self.log.info('New sample cell set. Parameters:')
        self.log.info('a = %8.3f  b = %8.3f  c = %8.3f', params.a, params.b,
                      params.c)
        self.log.info('alpha = %8.3f  beta = %8.3f  gamma = %8.3f',
                      params.alpha, params.beta, params.gamma)
        self.log.info('Bravais: %s  Laue: %s', cell.bravais.bravais,
                      cell.laue.laue)
        self.log.info('UB matrix:')
        for row in cell.rmat.T:
            self.log.info('%8.4f %8.4f %8.4f', *row)
예제 #6
0
 def get_new_cell(p):
     # reconstruct UB matrix
     Umat = Zrot(-p.phi).dot(Yrot(-p.theta)).dot(Xrot(-p.psi))
     Bmat = matrixfromcell(p.a, p.b, p.c, p.alpha, p.beta, p.gamma)
     return SXTalCell(Umat.dot(Bmat).T)
예제 #7
0
 def __init__(self, a, b=None, c=None, alpha=90.0, beta=90.0, gamma=90.0):
     if isinstance(a, SXTalCell):
         self.cell = a
     else:
         self.cell = SXTalCell.fromabc(a, b, c, alpha, beta, gamma)