def check_symmetry(phonon, optional_structure_info): # Assumed that primitive cell is the cell that user is interested in. print(_get_symmetry_yaml(phonon.primitive, phonon.primitive_symmetry, phonon.version)) if phonon.unitcell.magnetic_moments is None: base_fname = get_default_cell_filename(phonon.calculator) symprec = phonon.primitive_symmetry.get_symmetry_tolerance() (bravais_lattice, bravais_pos, bravais_numbers) = spglib.refine_cell(phonon.primitive, symprec) bravais = PhonopyAtoms(numbers=bravais_numbers, scaled_positions=bravais_pos, cell=bravais_lattice) filename = 'B' + base_fname print("# Symmetrized conventional unit cell is written into %s." % filename) trans_mat = guess_primitive_matrix(bravais, symprec=symprec) primitive = get_primitive(bravais, trans_mat, symprec=symprec) write_crystal_structure( filename, bravais, interface_mode=phonon.calculator, optional_structure_info=optional_structure_info) filename = 'P' + base_fname print("# Symmetrized primitive is written into %s." % filename) write_crystal_structure( filename, primitive, interface_mode=phonon.calculator, optional_structure_info=optional_structure_info)
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 = guess_primitive_matrix(unitcell, symprec=symprec) 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
def _guess_primitive_matrix(self): return guess_primitive_matrix(self._unitcell_ideal, symprec=self._symprec)