Пример #1
0
 def test_only_symmetrize(self):
     borns, epsilon = symmetrize_borns_and_epsilon(
         self.borns,
         self.epsilon,
         self.cell)
     np.testing.assert_allclose(borns, self.borns)
     np.testing.assert_allclose(epsilon, self.epsilon)
Пример #2
0
def test_symmetrize_borns_and_epsilon_tio2(ph_tio2):
    nac_params = ph_tio2.nac_params
    borns, epsilon = symmetrize_borns_and_epsilon(nac_params['born'],
                                                  nac_params['dielectric'],
                                                  ph_tio2.primitive)
    # np.testing.assert_allclose(borns, nac_params['born'], atol=1e-8)
    np.testing.assert_allclose(epsilon, nac_params['dielectric'], atol=1e-8)
Пример #3
0
def test_symmetrize_borns_and_epsilon_tio2(ph_tio2):
    """Test symmetrization of Born charges and dielectric tensors by TiO2."""
    nac_params = ph_tio2.nac_params
    borns, epsilon = symmetrize_borns_and_epsilon(nac_params["born"],
                                                  nac_params["dielectric"],
                                                  ph_tio2.primitive)
    # np.testing.assert_allclose(borns, nac_params['born'], atol=1e-8)
    np.testing.assert_allclose(epsilon, nac_params["dielectric"], atol=1e-8)
Пример #4
0
def test_symmetrize_borns_and_epsilon_nacl(ph_nacl):
    """Test symmetrization of Born charges and dielectric tensors by NaCl."""
    nac_params = ph_nacl.nac_params
    borns, epsilon = symmetrize_borns_and_epsilon(nac_params["born"],
                                                  nac_params["dielectric"],
                                                  ph_nacl.primitive)
    np.testing.assert_allclose(borns, nac_params["born"], atol=1e-8)
    np.testing.assert_allclose(epsilon, nac_params["dielectric"], atol=1e-8)
Пример #5
0
 def test_with_pmat_and_smat(self):
     borns, epsilon = symmetrize_borns_and_epsilon(
         self.borns,
         self.epsilon,
         self.cell,
         primitive_matrix=self.pmat,
         supercell_matrix=self.smat)
     np.testing.assert_allclose(borns, self.borns[self.idx])
     np.testing.assert_allclose(epsilon, self.epsilon)
Пример #6
0
def test_with_pmat_and_smat(ph_nacl):
    pcell = ph_nacl.primitive
    scell = ph_nacl.supercell
    idx = [scell.u2u_map[i] for i in scell.s2u_map[pcell.p2s_map]]
    uborns, uepsilon = _get_nac_params_in_unitcell(ph_nacl)
    borns, epsilon = symmetrize_borns_and_epsilon(
        uborns,
        uepsilon,
        ph_nacl.unitcell,
        primitive_matrix=ph_nacl.primitive_matrix,
        supercell_matrix=ph_nacl.supercell_matrix)
    np.testing.assert_allclose(borns, uborns[idx], atol=1e-8)
    np.testing.assert_allclose(epsilon, uepsilon, atol=1e-8)
Пример #7
0
    def test_with_pcell(self):
        idx2 = _get_mapping_between_cells(self.pcell, self.pcell)

        np.testing.assert_array_equal(
            idx2, np.arange(self.pcell.get_number_of_atoms()))

        borns, epsilon = symmetrize_borns_and_epsilon(
            self.borns,
            self.epsilon,
            self.cell,
            primitive=self.pcell)
        np.testing.assert_allclose(borns, self.borns[self.idx][idx2])
        np.testing.assert_allclose(epsilon, self.epsilon)
Пример #8
0
def test_with_pcell(ph_nacl):
    pcell = ph_nacl.primitive
    scell = ph_nacl.supercell
    idx = [scell.u2u_map[i] for i in scell.s2u_map[pcell.p2s_map]]
    idx2 = _get_mapping_between_cells(pcell, pcell)
    np.testing.assert_array_equal(idx2, np.arange(len(pcell)))

    uborns, uepsilon = _get_nac_params_in_unitcell(ph_nacl)
    borns, epsilon = symmetrize_borns_and_epsilon(uborns,
                                                  uepsilon,
                                                  ph_nacl.unitcell,
                                                  primitive=pcell)
    np.testing.assert_allclose(borns, uborns[idx][idx2], atol=1e-8)
    np.testing.assert_allclose(epsilon, uepsilon, atol=1e-8)
Пример #9
0
def test_with_pmat_and_smat(ph_nacl):
    """Test Born charges and dielectric tensor symmetrization with pmat and smat."""
    pcell = ph_nacl.primitive
    scell = ph_nacl.supercell
    idx = [scell.u2u_map[i] for i in scell.s2u_map[pcell.p2s_map]]
    uborns, uepsilon = _get_nac_params_in_unitcell(ph_nacl)
    borns, epsilon = symmetrize_borns_and_epsilon(
        uborns,
        uepsilon,
        ph_nacl.unitcell,
        primitive_matrix=ph_nacl.primitive_matrix,
        supercell_matrix=ph_nacl.supercell_matrix,
    )
    np.testing.assert_allclose(borns, uborns[idx], atol=1e-8)
    np.testing.assert_allclose(epsilon, uepsilon, atol=1e-8)
Пример #10
0
def get_nac_params(born_charges, epsilon, nac_structure, **params):
    """Obtain Born effective charges and dielectric constants in primitive cell

    When Born effective charges and dielectric constants are calculated within
    phonopy workchain, those values are calculated in the primitive cell.
    However using immigrant, the cell may not be primitive cell and can be
    unit cell. In this case, conversion of data is necessary. This conversion
    needs information of the structure where those values were calcualted and
    the target primitive cell structure.

    Two kargs parameters
    primitive : StructureData
    symmetry_tolerance : Float

    """
    from phonopy.structure.symmetry import symmetrize_borns_and_epsilon

    borns = born_charges.get_array('born_charges')
    eps = epsilon.get_array('epsilon')

    nac_cell = phonopy_atoms_from_structure(nac_structure)
    kargs = {}
    if 'symmetry_tolerance' in params:
        kargs['symprec'] = params['symmetry_tolerance'].value
    if 'primitive' in params:
        pcell = phonopy_atoms_from_structure(params['primitive'])
        kargs['primitive'] = pcell
    borns_, epsilon_ = symmetrize_borns_and_epsilon(borns, eps, nac_cell,
                                                    **kargs)

    nac_params = DataFactory('array')()
    nac_params.set_array('born_charges', borns_)
    nac_params.set_array('epsilon', epsilon_)
    nac_params.label = 'born_charges & epsilon'

    return nac_params
Пример #11
0
def _get_indep_borns(ucell,
                     borns,
                     epsilon,
                     primitive_matrix=None,
                     supercell_matrix=None,
                     is_symmetry=True,
                     symmetrize_tensors=False,
                     symprec=1e-5):
    """Parse Born effective charges and dielectric constants


     Args:
         ucell (Atoms): Unit cell structure
         borns (np.array): Born effective charges of ucell
         epsilon (np.array): Dielectric constant tensor

     Returns:
         (np.array) Born effective charges of symmetrically independent atoms
             in primitive cell
         (np.array) Dielectric constant
         (np.array) Atomic index mapping table from supercell to primitive cell
             of independent atoms

     Raises:
          AssertionError: Inconsistency of number of atoms or Born effective
              charges.

     Warning:
         Broken symmetry of Born effective charges

     """

    assert len(borns) == ucell.get_number_of_atoms(), \
        "num_atom %d != len(borns) %d" % (ucell.get_number_of_atoms(),
                                          len(borns))

    if symmetrize_tensors:
        borns_, epsilon_ = symmetrize_borns_and_epsilon(
            borns, epsilon, ucell, symprec=symprec, is_symmetry=is_symmetry)

        if (abs(borns - borns_) > 0.1).any():
            lines = [
                "Born effective charge symmetry is largely broken. "
                "Largest different among elements: "
                "%s" % np.amax(abs(borns - borns_))
            ]
            import warnings
            warnings.warn("\n".join(lines))

        borns = borns_
        epsilon = epsilon_

    borns, s_indep_atoms = _extract_independent_borns(
        borns,
        ucell,
        primitive_matrix=primitive_matrix,
        supercell_matrix=supercell_matrix,
        is_symmetry=is_symmetry,
        symprec=symprec)

    return borns, epsilon, s_indep_atoms