Exemplo n.º 1
0
 def _canonical_from_affine_matrix(self, affine: Array) -> Array:
     if self.unit_cell is None:
         return comparable(affine)
     else:
         return np.vstack((
             comparable(affine[0:self.ndim, 0:self.ndim]),
             comparable_periodic(affine[0:self.ndim, self.ndim]
                                 @ np.linalg.inv(self.unit_cell)),
         ))
Exemplo n.º 2
0
    def _clean_site_offsets(site_offsets, atoms_coord, basis_vectors):
        """Check and convert `site_offsets` init argument."""
        if atoms_coord is not None and site_offsets is not None:
            raise ValueError(
                "atoms_coord is deprecated and replaced by site_offsets, "
                "so both cannot be specified at the same time.")
        if atoms_coord is not None:
            warnings.warn(
                "atoms_coord is deprecated and may be removed in future versions, "
                "please use site_offsets instead",
                FutureWarning,
            )
            site_offsets = atoms_coord

        if site_offsets is None:
            site_offsets = _np.zeros(basis_vectors.shape[0])[None, :]

        site_offsets = _np.asarray(site_offsets)
        fractional_coords = site_offsets @ _np.linalg.inv(basis_vectors)
        fractional_coords_int = comparable_periodic(fractional_coords)
        # Check for duplicates (also across unit cells)
        uniques, idx = _np.unique(fractional_coords_int,
                                  axis=0,
                                  return_index=True)
        if len(site_offsets) != len(uniques):
            site_offsets = site_offsets[idx]
            fractional_coords = fractional_coords[idx]
            fractional_coords_int = fractional_coords_int[idx]
            warnings.warn(
                "Some atom positions are not unique. Duplicates were dropped, and "
                f"now atom positions are {site_offsets}",
                UserWarning,
            )
        # Check if any site is outside primitive cell (may cause KDTree to malfunction)
        if _np.any(fractional_coords_int < comparable(0.0)) or _np.any(
                fractional_coords_int > comparable(1.0)):

            warnings.warn(
                "Some sites were specified outside the primitive unit cell. This may"
                "cause errors in automatic edge finding.",
                UserWarning,
            )
        return site_offsets, fractional_coords
Exemplo n.º 3
0
 def _to_integer_position(self, positions: PositionT) -> Array:
     frac_positions = _np.matmul(positions, self._inv_dims)
     return comparable_periodic(frac_positions, self.pbc)