def _projected_2Dcoords(cls, geometry, xyz=None, xaxis="x", yaxis="y"): """ Moves the 3D positions of the atoms to a 2D supspace. In this way, we can plot the structure from the "point of view" that we want. NOTE: If xaxis/yaxis is one of {"a", "b", "c", "1", "2", "3"} the function doesn't project the coordinates in the direction of the lattice vector. The fractional coordinates, taking in consideration the three lattice vectors, are returned instead. Parameters ------------ geometry: sisl.Geometry the geometry for which you want the projected coords xyz: array-like of shape (natoms, 3), optional the 3D coordinates that we want to project. otherwise they are taken from the geometry. xaxis: {"x", "y", "z", "a", "b", "c"} or array-like of shape 3, optional the direction to be displayed along the X axis. yaxis: {"x", "y", "z", "a", "b", "c"} or array-like of shape 3, optional the direction to be displayed along the X axis. Returns ---------- np.ndarray of shape (2, natoms) the 2D coordinates of the geometry, with all positions projected into the plane defined by xaxis and yaxis. """ if xyz is None: xyz = geometry.xyz try: all_lattice_vecs = len( set([xaxis, yaxis]).intersection(["a", "b", "c"])) == 2 except Exception: # If set fails it is because xaxis/yaxis is unhashable, which means it # is a numpy array all_lattice_vecs = False if all_lattice_vecs: coord_indices = ["abc".index(ax) for ax in (xaxis, yaxis)] icell = cell_invert(geometry.cell) else: # Get the directions that these axes represent xaxis = cls._direction(xaxis, geometry.cell) yaxis = cls._direction(yaxis, geometry.cell) fake_cell = np.array( [xaxis, yaxis, np.cross(xaxis, yaxis)], dtype=np.float64) icell = cell_invert(fake_cell) coord_indices = [0, 1] return np.dot(xyz, icell.T)[..., coord_indices]
def __init__(self, sc, atol=1.e-5, offset=(0., 0., 0.), foffset=(0., 0., 0.)): if isinstance(sc, SuperCellChild): sc = sc.sc elif not isinstance(sc, SuperCell): sc = SuperCell(sc) # Unit-cell to fractionalize self._cell = sc.cell.copy() # lengths of lattice vectors self._length = sc.length.copy().reshape(1, 3) # inverse cell (for fractional coordinate calculations) self._icell = cell_invert(self._cell) # absolute tolerance [Ang] self._atol = atol # offset of coordinates before calculating the fractional coordinates self._offset = _a.arrayd(offset).reshape(1, 3) # fractional offset before comparing to the integer part of the fractional coordinate self._foffset = _a.arrayd(foffset).reshape(1, 3) super().__init__( f"fracsite(atol={self._atol}, offset={self._offset}, foffset={self._foffset})" )