def spglib_dataset(s, symprec=1e-5): s = structure(s) fracs = s.frac_coords lattice = s.lattice.matrix types = [x.number for x in s.species] ds = spglib.get_symmetry_dataset((lattice, fracs, types), symprec) if not ds: error = spglib.get_error_message() if error == "no error": error += ". (or so spglib claims...)" raise SpglibError(spglib.get_error_message()) return ds
def throw(cls): error = spglib.get_error_message() if error == "no error": # right... error = "an unspecified Bad Thing happened while calling spglib" raise cls(error)
def symmetry(self, symprec=1e-2, angle_tolerance=-1.0): """ Returns a dictionary containing space-group information. This information is computed from the crystal unit cell. Parameters ---------- symprec : float, optional Symmetry-search distance tolerance in Cartesian coordinates [Angstroms]. angle_tolerance: float, optional Symmetry-search tolerance in degrees. If the value is negative (default), an internally optimized routine is used to judge symmetry. Returns ------- info : dict Dictionary of space-group information. The following keys are available: * ``'international_symbol'``: International Tables of Crystallography space-group symbol (short); * ``'international_full'``: International Tables of Crystallography space-group full symbol; * ``'hall_symbol'`` : Hall symbol; * ``'hm_symbol'`` : Hermann-Mauguin symbol; *``'centering'``: Centering-type ("P", "F", etc.); * ``'pointgroup'`` : International Tables of Crystallography point-group; * ``'international_number'`` : International Tables of Crystallography space-group number (between 1 and 230); * ``'hall_number'`` : Hall number (between 1 and 531). Raises ------ RuntimeError : if symmetry-determination has not succeeded. Notes ----- Note that crystals generated from the Protein Data Bank are often incomplete; in such cases the space-group information will be incorrect. """ dataset = get_symmetry_dataset(cell=self._spglib_cell(), symprec=symprec, angle_tolerance=angle_tolerance) if dataset is None: raise RuntimeError( "[SPGLIB] Symmetry-determination has not found a match.") spg_type = get_spacegroup_type(dataset["hall_number"]) hm_symbol = Hall2HM[dataset["hall"]] # We do not distinguish between base-centered "A", "B", and "C" # "A" and "B" are translated to "C" centering = CenteringType(hm_symbol[0] if hm_symbol[0] not in {"A", "B"} else "C") info = { "international_symbol": dataset["international"], "hall_symbol": dataset["hall"], "hm_symbol": hm_symbol, "centering": centering, "international_number": dataset["number"], "hall_number": dataset["hall_number"], "international_full": spg_type["international_full"], "pointgroup": spg_type["pointgroup_international"], } err_msg = get_error_message() if err_msg != "no error": raise RuntimeError( "[SPGLIB] Symmetry-determination has returned the following error: {err_msg}" ) return info
def spacegroup_info(self, symprec = 1e-2, angle_tolerance = -1.0): """ Returns a dictionary containing space-group information. This information is computed from the crystal unit cell, and is not taken from records if available. Parameters ---------- symprec : float, optional Symmetry-search distance tolerance in Cartesian coordinates [Angstroms]. angle_tolerance: float, optional Symmetry-search tolerance in degrees. If the value is negative (default), an internally optimized routine is used to judge symmetry. Returns ------- info : dict or None Dictionary of space-group information. The following keys are available: * ``'international_symbol'``: International Tables of Crystallography space-group symbol (short); * ``'international_full'``: International Tables of Crystallography space-group full symbol; * ``'hall_symbol'`` : Hall symbol; * ``'pointgroup'`` : International Tables of Crystallography point-group; * ``'international_number'`` : International Tables of Crystallography space-group number (between 1 and 230); * ``'hall_number'`` : Hall number (between 1 and 531). If symmetry-determination has failed, None is returned. Raises ------ RuntimeError : If symmetry-determination has yielded an error. Notes ----- Note that crystals generated from the Protein Data Bank are often incomplete; in such cases the space-group information will be incorrect. """ dataset = get_symmetry_dataset(cell = self._spglib_cell(), symprec = symprec, angle_tolerance = angle_tolerance) if dataset: spg_type = get_spacegroup_type(dataset['hall_number']) info = {'international_symbol': dataset['international'], 'hall_symbol' : dataset['hall'], 'international_number': dataset['number'], 'hall_number' : dataset['hall_number'], 'international_full' : spg_type['international_full'], 'pointgroup' : spg_type['pointgroup_international']} err_msg = get_error_message() if (err_msg != 'no error'): raise RuntimeError('Symmetry-determination has returned the following error: {}'.format(err_msg)) return info return None