def test(): length_grid = np.logspace(-0.5, 1.5, 11).round(3) angle_grid = np.linspace(10, 179, 11).round() #all_ops = find_all_niggli_ops(length_grid, angle_grid) #niggli_op_table.clear() #niggli_op_table.update(all_ops) for latname in bravais_names: if latname in ['MCL', 'MCLC', 'TRI']: continue latcls = bravais_lattices[latname] if latcls.ndim != 3: continue print('Check', latname) maxerr = 0.0 for lat in lattice_loop(latcls, length_grid, angle_grid): cell = lat.tocell() from ase.lattice import identify_lattice out_lat, op = identify_lattice(cell, eps=2e-4) # Some lattices represent simpler lattices, # e.g. TET(a, a) is cubic. What we need to check is that # the cell parameters are the same. cellpar = cell.cellpar() outcellpar = out_lat.tocell().cellpar() err = np.abs(outcellpar - cellpar).max() maxerr = max(err, maxerr) if lat.name != out_lat.name: print(repr(lat), '-->', repr(out_lat)) assert err < 1e-8, (err, repr(lat), repr(out_lat)) print(' OK. Maxerr={}'.format(maxerr))
def bandpath( self, path: str = None, npoints: int = None, *, density: float = None, special_points: Mapping[str, Sequence[float]] = None, eps: float = 2e-4, pbc: Union[bool, Sequence[bool]] = True) -> "ase.dft.kpoints.BandPath": """Build a :class:`~ase.dft.kpoints.BandPath` for this cell. If special points are None, determine the Bravais lattice of this cell and return a suitable Brillouin zone path with standard special points. If special special points are given, interpolate the path directly from the available data. Parameters: path: string String of special point names defining the path, e.g. 'GXL'. npoints: int Number of points in total. Note that at least one point is added for each special point in the path. density: float density of kpoints along the path in Å⁻¹. special_points: dict Dictionary mapping special points to scaled kpoint coordinates. For example ``{'G': [0, 0, 0], 'X': [1, 0, 0]}``. eps: float Tolerance for determining Bravais lattice. pbc: three bools Whether cell is periodic in each direction. Normally not necessary. If cell has three nonzero cell vectors, use e.g. pbc=[1, 1, 0] to request a 2D bandpath nevertheless. Example ------- >>> cell = Cell.fromcellpar([4, 4, 4, 60, 60, 60]) >>> cell.bandpath('GXW', npoints=20) BandPath(path='GXW', cell=[3x3], special_points={GKLUWX}, kpts=[20x3]) """ # TODO: Combine with the rotation transformation from bandpath() cell = self.uncomplete(pbc) if special_points is None: from ase.lattice import identify_lattice lat, op = identify_lattice(cell, eps=eps) bandpath = lat.bandpath(path, npoints=npoints, density=density) return bandpath.transform(op) else: from ase.dft.kpoints import BandPath, resolve_custom_points path = resolve_custom_points(path, special_points, eps=eps) bandpath = BandPath(cell, path=path, special_points=special_points) return bandpath.interpolate(npoints=npoints, density=density)
def test_lattice(lat): cell = lat.tocell() def check(lat1): print('check', repr(lat), '-->', repr(lat1)) err = np.abs(cell.cellpar() - lat1.cellpar()).max() assert err < 1e-5, err check(get_lattice_from_canonical_cell(cell)) if lat.name == 'TRI': # The TRI lattices generally permute (the ones we produce as # all_variants() are reduced to a form with smaller # orthogonality defect) which might be desirable but would # trigger an error in this test. return stdcell, op = identify_lattice(cell, 1e-4) check(stdcell) rcell, op = cell.niggli_reduce() stdcell, op = identify_lattice(rcell, 1e-4) check(stdcell)
def bandpath(self, path=None, npoints=None, density=None, special_points=None, eps=2e-4): """Build a :class:`~ase.dft.kpoints.BandPath` for this cell. If special points are None, determine the Bravais lattice of this cell and return a suitable Brillouin zone path with standard special points. If special special points are given, interpolate the path directly from the available data. Parameters: path: string String of special point names defining the path, e.g. 'GXL'. npoints: int Number of points in total. Note that at least one point is added for each special point in the path. density: float density of kpoints along the path in Å⁻¹. special_points: dict Dictionary mapping special points to scaled kpoint coordinates. For example ``{'G': [0, 0, 0], 'X': [1, 0, 0]}``. eps: float Tolerance for determining Bravais lattice. Example ------- >>> cell = Cell.fromcellpar([4, 4, 4, 60, 60, 60]) >>> cell.bandpath('GXW', npoints=20) BandPath(path='GXW', cell=[3x3], special_points={GKLUWX}, kpts=[20x3]) """ # TODO: Combine with the rotation transformation from bandpath() if special_points is None: from ase.lattice import identify_lattice lat, op = identify_lattice(self, eps=eps) path = lat.bandpath(path, npoints=npoints, density=density) return path.transform(op) else: from ase.dft.kpoints import BandPath, resolve_custom_points path = resolve_custom_points(path, special_points, eps=eps) path = BandPath(self, path=path, special_points=special_points) return path.interpolate(npoints=npoints, density=density)
def get_bravais_lattice(self, eps=2e-4, *, pbc=True): """Return :class:`~ase.lattice.BravaisLattice` for this cell: >>> cell = Cell.fromcellpar([4, 4, 4, 60, 60, 60]) >>> print(cell.get_bravais_lattice()) FCC(a=5.65685) .. note:: The Bravais lattice object follows the AFlow conventions. ``cell.get_bravais_lattice().tocell()`` may differ from the original cell by a permutation or other operation which maps it to the AFlow convention. For example, the orthorhombic lattice enforces a < b < c. To build a bandpath for a particular cell, use :meth:`ase.cell.Cell.bandpath` instead of this method. This maps the kpoints back to the original input cell. """ from ase.lattice import identify_lattice pbc = self.any(1) & pbc2pbc(pbc) lat, op = identify_lattice(self, eps=eps, pbc=pbc) return lat
Niggli-reduce them and recognize them as well.""" import numpy as np from ase.lattice import (get_lattice_from_canonical_cell, all_variants, identify_lattice) for lat in all_variants(): if lat.ndim == 2: break cell = lat.tocell() def check(lat1): print('check', repr(lat), '-->', repr(lat1)) err = np.abs(cell.cellpar() - lat1.cellpar()).max() assert err < 1e-5, err check(get_lattice_from_canonical_cell(cell)) if lat.name == 'TRI': # The TRI lattices generally permute (the ones we produce as # all_variants() are reduced to a form with smaller # orthogonality defect) which might be desirable but would # trigger an error in this test. continue stdcell, op = identify_lattice(cell, 1e-4) check(stdcell) rcell, op = cell.niggli_reduce() stdcell, op = identify_lattice(rcell, 1e-4) check(stdcell)