Beispiel #1
0
 def test_symmetrize_molecule2(self):
     np.random.seed(77)
     distortion = np.random.randn(len(C2H2F2Br2), 3) / 20
     dist_mol = Molecule(C2H2F2Br2.species, C2H2F2Br2.cart_coords + distortion)
     PA1 = PointGroupAnalyzer(C2H2F2Br2, tolerance=0.1)
     self.assertTrue(PA1.get_pointgroup().sch_symbol == "Ci")
     PA2 = PointGroupAnalyzer(dist_mol, tolerance=0.1)
     self.assertTrue(PA2.get_pointgroup().sch_symbol == "C1")
     eq = iterative_symmetrize(dist_mol, tolerance=0.3)
     PA3 = PointGroupAnalyzer(eq["sym_mol"], tolerance=0.1)
     self.assertTrue(PA3.get_pointgroup().sch_symbol == "Ci")
Beispiel #2
0
 def test_symmetrize_molecule2(self):
     np.random.seed(77)
     distortion = np.random.randn(len(C2H2F2Br2), 3) / 20
     dist_mol = Molecule(C2H2F2Br2.species,
                         C2H2F2Br2.cart_coords + distortion)
     PA1 = PointGroupAnalyzer(C2H2F2Br2, tolerance=0.1)
     self.assertTrue(PA1.get_pointgroup().sch_symbol == 'Ci')
     PA2 = PointGroupAnalyzer(dist_mol, tolerance=0.1)
     self.assertTrue(PA2.get_pointgroup().sch_symbol == 'C1')
     eq = iterative_symmetrize(dist_mol, tolerance=0.3)
     PA3 = PointGroupAnalyzer(eq['sym_mol'], tolerance=0.1)
     self.assertTrue(PA3.get_pointgroup().sch_symbol == 'Ci')
    def symmetrize(self, max_n=10, tolerance=0.3, epsilon=1e-3):
        """Returns a symmetrized molecule

        The equivalent atoms obtained via
        :meth:`~Cartesian.get_equivalent_atoms`
        are rotated, mirrored... unto one position.
        Then the average position is calculated.
        The average position is rotated, mirrored... back with the inverse
        of the previous symmetry operations, which gives the
        symmetrized molecule.
        This operation is repeated iteratively ``max_n`` times at maximum
        until the difference between subsequently symmetrized structures is
        smaller than ``epsilon``.

        Args:
            max_n (int): Maximum number of iterations.
            tolerance (float): Tolerance for detecting symmetry.
                Gets passed as Argument into
                :class:`~pymatgen.analyzer.symmetry.PointGroupAnalyzer`.
            epsilon (float): If the elementwise absolute difference of two
                subsequently symmetrized structures is smaller epsilon,
                the iteration stops before ``max_n`` is reached.

        Returns:
            dict: The returned dictionary has three possible keys:

            ``sym_mol``:
            A symmetrized molecule :class:`~Cartesian`

            ``eq_sets``:
            A dictionary of indices mapping to sets of indices,
            each key maps to indices of all equivalent atoms.
            The keys are guaranteed to be not symmetry-equivalent.

            ``sym_ops``:
            Twofold nested dictionary.
            ``operations[i][j]`` gives the symmetry operation
            that maps atom ``i`` unto ``j``.
        """
        from pymatgen.symmetry.analyzer import iterative_symmetrize

        mg_mol = self.get_pymatgen_molecule()
        eq = iterative_symmetrize(mg_mol,
                                  max_n=max_n,
                                  tolerance=tolerance,
                                  epsilon=epsilon)
        self._convert_eq(eq)
        return eq
Beispiel #4
0
    def test_symmetrize_molecule1(self):
        np.random.seed(77)
        distortion = np.random.randn(len(C2H4), 3) / 10
        dist_mol = Molecule(C2H4.species, C2H4.cart_coords + distortion)

        eq = iterative_symmetrize(dist_mol, max_n=100, epsilon=1e-7)
        sym_mol, eq_sets, ops = eq["sym_mol"], eq["eq_sets"], eq["sym_ops"]

        self.assertTrue({0, 1} in eq_sets.values())
        self.assertTrue({2, 3, 4, 5} in eq_sets.values())

        coords = sym_mol.cart_coords
        for i, eq_set in eq_sets.items():
            for j in eq_set:
                rotated = np.dot(ops[i][j], coords[i])
                self.assertTrue(np.allclose(np.dot(ops[i][j], coords[i]), coords[j]))
Beispiel #5
0
    def test_symmetrize_molecule1(self):
        np.random.seed(77)
        distortion = np.random.randn(len(C2H4), 3) / 10
        dist_mol = Molecule(C2H4.species, C2H4.cart_coords + distortion)

        eq = iterative_symmetrize(dist_mol, max_n=100, epsilon=1e-7)
        sym_mol, eq_sets, ops = eq['sym_mol'], eq['eq_sets'], eq['sym_ops']

        self.assertTrue({0, 1} in eq_sets.values())
        self.assertTrue({2, 3, 4, 5} in eq_sets.values())

        coords = sym_mol.cart_coords
        for i, eq_set in eq_sets.items():
            for j in eq_set:
                rotated = np.dot(ops[i][j], coords[i])
                self.assertTrue(
                    np.allclose(np.dot(ops[i][j], coords[i]), coords[j]))