def _set_grid_matrix_by_std_primitive_cell(self, cell, length): """Grid generating matrix based on standeardized primitive cell.""" tmat = self._sym_dataset["transformation_matrix"] centring = self._sym_dataset["international"][0] pmat = get_primitive_matrix_by_centring(centring) conv_lat = np.dot(np.linalg.inv(tmat).T, cell.cell) num_cells = np.prod(length2mesh(length, conv_lat)) self._mesh_numbers = estimate_supercell_matrix( self._sym_dataset, max_num_atoms=num_cells * len(self._sym_dataset["std_types"]), ) inv_pmat = np.linalg.inv(pmat) inv_pmat_int = np.rint(inv_pmat).astype(int) assert (np.abs(inv_pmat - inv_pmat_int) < 1e-5).all() # transpose in reciprocal space self._grid_matrix = np.array((inv_pmat_int * self._mesh_numbers).T, dtype="int_", order="C") # From input lattice to the primitive lattice in real space self._transformation_matrix = np.array(np.dot(np.linalg.inv(tmat), pmat), dtype="double", order="C")
def _get_primitive_matrix(pmat, unitcell, symprec): if type(pmat) is str and pmat in ('F', 'I', 'A', 'C', 'R', 'auto'): if pmat == 'auto': _pmat = pmat else: _pmat = get_primitive_matrix_by_centring(pmat) elif pmat is None: _pmat = None elif len(np.ravel(pmat)) == 9: matrix = np.reshape(pmat, (3, 3)) if matrix.dtype.kind in ('i', 'u', 'f'): det = np.linalg.det(matrix) if symprec < det and det < 1 + symprec: _pmat = matrix else: msg = ("Determinant of primitive_matrix has to be larger " "than 0") raise RuntimeError(msg) else: msg = ("primitive_matrix has to be a 3x3 matrix, None, 'auto', " "'F', 'I', 'A', 'C', or 'R'") raise RuntimeError(msg) return _pmat