def _find_mirror(self, axis): """ Looks for mirror symmetry of specified type about axis. Possible types are "h" or "vd". Horizontal (h) mirrors are perpendicular to the axis while vertical (v) or diagonal (d) mirrors are parallel. v mirrors has atoms lying on the mirror plane while d mirrors do not. """ mirror_type = "" # First test whether the axis itself is the normal to a mirror plane. if self.is_valid_op(SymmOp.reflection(axis)): self.symmops.append(SymmOp.reflection(axis)) mirror_type = "h" else: # Iterate through all pairs of atoms to find mirror for s1, s2 in itertools.combinations(self.centered_mol, 2): if s1.species_and_occu == s2.species_and_occu: normal = s1.coords - s2.coords if np.dot(normal, axis) < self.tol: op = SymmOp.reflection(normal) if self.is_valid_op(op): self.symmops.append(op) if len(self.rot_sym) > 1: mirror_type = "d" for v, r in self.rot_sym: if not np.linalg.norm(v - axis) < self.tol: if np.dot(v, normal) < self.tol: mirror_type = "v" break else: mirror_type = "v" break return mirror_type
def test_reflection(self): normal = np.random.rand(3) origin = np.random.rand(3) refl = SymmOp.reflection(normal, origin) point = np.random.rand(3) newcoord = refl.operate(point) # Distance to the plane should be negatives of each other. self.assertAlmostEqual(np.dot(newcoord - origin, normal), -np.dot(point - origin, normal))