Ejemplo n.º 1
0
def check_single(name, cell):
    c = Cell(cell)
    lattice, _ = c.bravais()
    name1 = lattice.name.lower()
    ok = name.split('@')[0] == name1
    print(name, '-->', name1, 'OK' if ok else 'ERR', c.cellpar())
    assert ok
Ejemplo n.º 2
0
 def check(f, *args, **kwargs):
     axis = kwargs.pop('axis', 0)
     try:
         cell = f(*args, **kwargs).tocell()
     except UnconventionalLattice:
         return None
     mycellpar = Cell(cell).cellpar()
     #for iperm in range(3):
     permutation = (np.arange(-3, 0) + axis) % 3
     mycellpar = mycellpar.reshape(2, 3)[:, permutation].ravel()
     if np.allclose(mycellpar, cellpar):
         # Return bravais function as well as the bravais parameters
         # that would reproduce the cell
         d = dict(zip(f.parameters, args))
         d.update(kwargs)
         #if axis:
         #    d['cycle'] = axis
         return f, d
Ejemplo n.º 3
0
    def _variant_name(self, a, b, c, alpha, beta, gamma):
        c = Cell.new([a, b, c, alpha, beta, gamma])
        icellpar = Cell(c.reciprocal()).cellpar()
        kangles = kalpha, kbeta, kgamma = icellpar[3:]

        eps = self._eps
        if abs(kgamma - 90) < eps:
            if kalpha > 90 and kbeta > 90:
                var = '2a'
            elif kalpha < 90 and kbeta < 90:
                var = '2b'
            else:
                # Is this possible?  Maybe due to epsilon
                assert 0, 'unexpected combination of angles'
        elif all(kangles > 90):  # and kgamma < min(kalpha, kbeta):
            var = '1a'
        elif all(kangles < 90):  # and kgamma > max(kalpha, kbeta):
            var = '1b'
        else:
            raise UnconventionalLattice(
                'Reciprocal lattice has unexpected angles: kalpha={}, '
                'kbeta={}, kgamma={}'.format(kalpha, kbeta, kgamma))
        return 'TRI' + var
Ejemplo n.º 4
0
    def _variant_name(self, a, b, c, alpha):
        #from ase.geometry.cell import mclc
        # okay, this is a bit hacky

        # We need the same parameters here as when determining the points.
        # Right now we just repeat the code:
        check_mcl(a, b, c, alpha)

        a2 = a * a
        b2 = b * b
        cosa = np.cos(alpha * _degrees)
        sina = np.sin(alpha * _degrees)
        sina2 = sina**2

        cell = self.tocell()
        lengths_angles = Cell(cell.reciprocal()).cellpar()

        kgamma = lengths_angles[-1]

        eps = self._eps
        # We should not compare angles in degrees versus lengths with
        # the same precision.
        if abs(kgamma - 90) < eps:
            variant = 2
        elif kgamma > 90:
            variant = 1
        elif kgamma < 90:
            num = b * cosa / c + b2 * sina2 / a2
            if abs(num - 1) < eps:
                variant = 4
            elif num < 1:
                variant = 3
            else:
                variant = 5
        variant = 'MCLC' + str(variant)
        return variant
Ejemplo n.º 5
0
 def get_tri(kcellpar):
     # We build the TRI lattices from cellpars of reciprocal cell
     icell = Cell.fromcellpar(kcellpar)
     cellpar = Cell(4 * icell.reciprocal()).cellpar()
     return TRI(*cellpar)
Ejemplo n.º 6
0
 def tocell(self, cycle=0):
     cell = self._cell(**self._parameters)
     if cycle:
         index = (np.arange(3) + cycle) % 3
         cell = cell[index]
     return Cell(cell)
Ejemplo n.º 7
0
def check(name, cell):
    cell = Cell(cell).array
    #cell = Cell(cell).array
    # Check all three positive permutations:
    check_single(name + '@012', cell[[0, 1, 2]])