예제 #1
0
파일: solver.py 프로젝트: phonopy/phono3py
def _extract_params(dm):
    svecs, multi = dm.primitive.get_smallest_vectors()
    if dm.primitive.store_dense_svecs:
        _svecs = svecs
        _multi = multi
    else:
        _svecs, _multi = sparse_to_dense_svecs(svecs, multi)

    masses = np.array(dm.primitive.masses, dtype="double")
    rec_lattice = np.array(np.linalg.inv(dm.primitive.cell),
                           dtype="double",
                           order="C")
    positions = np.array(dm.primitive.positions, dtype="double", order="C")
    if dm.is_nac():
        born = dm.born
        nac_factor = dm.nac_factor
        dielectric = dm.dielectric_constant
    else:
        born = None
        nac_factor = 0
        dielectric = None

    return (
        _svecs,
        _multi,
        masses,
        rec_lattice,
        positions,
        born,
        nac_factor,
        dielectric,
    )
예제 #2
0
    def __init__(
        self,
        fc2,
        fc3,
        supercell,
        primitive,
        nac_params=None,
        nac_q_direction=None,
        ion_clamped=False,
        factor=VaspToTHz,
        symprec=1e-5,
    ):
        """Init method."""
        self._fc2 = fc2
        self._fc3 = fc3
        self._scell = supercell
        self._pcell = primitive
        self._ion_clamped = ion_clamped
        self._factor = factor
        self._symprec = symprec
        self._dm = get_dynamical_matrix(
            self._fc2,
            self._scell,
            self._pcell,
            nac_params=nac_params,
            symprec=self._symprec,
        )
        self._nac_q_direction = nac_q_direction

        svecs, multi = self._pcell.get_smallest_vectors()
        if self._pcell.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)

        if self._ion_clamped:
            num_atom_prim = self._pcell.get_number_of_atoms()
            self._X = np.zeros((num_atom_prim, 3, 3, 3), dtype=float)
        else:
            self._X = self._get_X()
        self._dPhidu = self._get_dPhidu()

        self._gruneisen_parameters = None
        self._frequencies = None
        self._qpoints = None
        self._mesh = None
        self._band_paths = None
        self._band_distances = None
        self._run_mode = None
        self._weights = None
예제 #3
0
    def __init__(
        self,
        supercell: PhonopyAtoms,
        primitive: Primitive,
        force_constants,
        decimals=None,
    ):
        """Init method.

        Parameters
        ----------
        supercell : PhonopyAtoms.
            Supercell.
        primitive : Primitive
            Primitive cell.
        force_constants : array_like
            Supercell force constants. Full and compact shapes of arrays are
            supported.
            shape=(supercell atoms, supercell atoms, 3, 3) for full FC.
            shape=(primitive atoms, supercell atoms, 3, 3) for compact FC.
            dtype='double'
        decimals : int, optional, default=None
            Number of decimals. Use like dm.round(decimals).

        """
        self._scell = supercell
        self._pcell = primitive
        self._decimals = decimals
        self._dynamical_matrix = None
        self._force_constants = None
        self._set_force_constants(force_constants)

        self._dtype_complex = "c%d" % (np.dtype("double").itemsize * 2)

        self._p2s_map = np.array(self._pcell.p2s_map, dtype="int_")
        self._s2p_map = np.array(self._pcell.s2p_map, dtype="int_")
        p2p_map = self._pcell.p2p_map
        self._s2pp_map = np.array(
            [p2p_map[self._s2p_map[i]] for i in range(len(self._s2p_map))],
            dtype="int_")
        svecs, multi = self._pcell.get_smallest_vectors()
        if self._pcell.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)
예제 #4
0
    def __init__(self, fc3, primitive, mesh, symprec=1e-5):
        """Init method."""
        self._fc3 = fc3
        self._primitive = primitive
        self._mesh = mesh
        self._symprec = symprec

        self._p2s_map = primitive.p2s_map
        self._s2p_map = primitive.s2p_map
        # Reduce supercell atom index to primitive index
        svecs, multi = self._primitive.get_smallest_vectors()
        if self._primitive.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)
        self._fc3_reciprocal = None
예제 #5
0
    def __init__(self, dynamical_matrix: Union[DynamicalMatrix,
                                               DynamicalMatrixNAC]):
        """Init method.

        Parameters
        ----------
        dynamical_matrix : DynamicalMatrix
            A DynamicalMatrix instance.

        """
        self._dynmat = dynamical_matrix
        self._force_constants = self._dynmat.force_constants
        self._scell = self._dynmat.supercell
        self._pcell = self._dynmat.primitive

        dtype = "int_"
        self._p2s_map = np.array(self._pcell.p2s_map, dtype=dtype)
        self._s2p_map = np.array(self._pcell.s2p_map, dtype=dtype)
        p2p_map = self._pcell.p2p_map
        self._s2pp_map = np.array(
            [p2p_map[self._s2p_map[i]] for i in range(len(self._s2p_map))],
            dtype=dtype)

        svecs, multi = self._pcell.get_smallest_vectors()
        if self._pcell.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)
        # self._svecs, self._multi = self._pcell.get_smallest_vectors()

        self._ddm = None

        # Derivative order=2 can work only within the following conditions:
        # 1. Second derivative of NAC is not considered.
        # 2. Python implementation
        self._derivative_order = None
예제 #6
0
def test_sparse_to_dense_nacl(ph_nacl: Phonopy):
    """Test for sparse_to_dense_svecs."""
    scell = ph_nacl.supercell
    pcell = ph_nacl.primitive
    pos = scell.scaled_positions

    spairs = ShortestPairs(scell.cell,
                           pos,
                           pos[pcell.p2s_map],
                           store_dense_svecs=False)
    svecs = spairs.shortest_vectors
    multi = spairs.multiplicities

    spairs = ShortestPairs(scell.cell,
                           pos,
                           pos[pcell.p2s_map],
                           store_dense_svecs=True)
    dsvecs = spairs.shortest_vectors
    dmulti = spairs.multiplicities

    _dsvecs, _dmulti = sparse_to_dense_svecs(svecs, multi)

    np.testing.assert_array_equal(dmulti, _dmulti)
    np.testing.assert_allclose(dsvecs, _dsvecs, rtol=0, atol=1e-8)
예제 #7
0
    def __init__(
        self,
        primitive: Primitive,
        bz_grid: BZGrid,
        primitive_symmetry: Symmetry,
        fc3=None,
        band_indices=None,
        constant_averaged_interaction=None,
        frequency_factor_to_THz=VaspToTHz,
        frequency_scale_factor=None,
        unit_conversion=None,
        is_mesh_symmetry=True,
        symmetrize_fc3q=False,
        cutoff_frequency=None,
        lapack_zheev_uplo="L",
    ):
        """Init method."""
        self._primitive = primitive
        self._bz_grid = bz_grid
        self._primitive_symmetry = primitive_symmetry

        self._band_indices = None
        self._set_band_indices(band_indices)
        self._constant_averaged_interaction = constant_averaged_interaction
        self._frequency_factor_to_THz = frequency_factor_to_THz
        self._frequency_scale_factor = frequency_scale_factor

        if fc3 is not None:
            self._set_fc3(fc3)

        # Unit to eV^2
        if unit_conversion is None:
            num_grid = np.prod(self.mesh_numbers)
            self._unit_conversion = ((Hbar * EV)**3 / 36 / 8 * EV**2 /
                                     Angstrom**6 / (2 * np.pi * THz)**3 /
                                     AMU**3 / num_grid / EV**2)
        else:
            self._unit_conversion = unit_conversion
        if cutoff_frequency is None:
            self._cutoff_frequency = 0
        else:
            self._cutoff_frequency = cutoff_frequency
        self._is_mesh_symmetry = is_mesh_symmetry
        self._symmetrize_fc3q = symmetrize_fc3q
        self._lapack_zheev_uplo = lapack_zheev_uplo

        self._symprec = self._primitive_symmetry.tolerance

        self._triplets_at_q = None
        self._weights_at_q = None
        self._triplets_map_at_q = None
        self._ir_map_at_q = None
        self._interaction_strength = None
        self._g_zero = None

        self._phonon_done = None
        self._done_nac_at_gamma = False  # Phonon at Gamma is calculatd with NAC.
        self._frequencies = None
        self._eigenvectors = None
        self._frequencies_at_gamma = None
        self._eigenvectors_at_gamma = None
        self._dm = None
        self._nac_params = None
        self._nac_q_direction = None

        self._band_index_count = 0

        svecs, multi = self._primitive.get_smallest_vectors()
        if self._primitive.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)

        self._masses = np.array(self._primitive.masses, dtype="double")
        self._p2s = np.array(self._primitive.p2s_map, dtype="int_")
        self._s2p = np.array(self._primitive.s2p_map, dtype="int_")
예제 #8
0
    def __init__(
        self,
        primitive,
        supercell,
        eigenvalues=None,
        eigenvectors=None,
        dynamical_matrices=None,
        commensurate_points=None,
        is_full_fc=True,
    ):
        """Init method.

        Parameters
        ----------
        supercell : PhonopyAtoms
            Supercell, not necessarily being an instance of Supercell class.
        primitive : Primitive
            Primitive cell
        is_full_fc : bool
            This controls the matrix shape of calculated force constants.
            True and False give the full and compact force cosntants,
            respectively. The default is True. See more details in Attributes
            section of this class.

        """
        self._pcell = primitive
        self._scell = supercell
        supercell_matrix = np.linalg.inv(self._pcell.primitive_matrix)
        supercell_matrix = np.rint(supercell_matrix).astype("intc")
        if commensurate_points is None:
            self._commensurate_points = get_commensurate_points(
                supercell_matrix)
        else:
            self._commensurate_points = commensurate_points

        svecs, multi = self._pcell.get_smallest_vectors()
        if self._pcell.store_dense_svecs:
            self._svecs = svecs
            self._multi = multi
        else:
            self._svecs, self._multi = sparse_to_dense_svecs(svecs, multi)

        self._dynmat = None
        self._fc = None

        n_s = len(self._scell)
        n_p = len(self._pcell)
        if is_full_fc:
            self._fc_shape = (n_s, n_s, 3, 3)
        else:
            self._fc_shape = (n_p, n_s, 3, 3)

        self._dtype_complex = "c%d" % (np.dtype("double").itemsize * 2)

        if dynamical_matrices is not None or commensurate_points is not None:
            warnings.warn(
                "Instanciation init parameters of dynamical_matrices"
                " and commensurate_points are deprecated. Use "
                "respecitve attributes.",
                DeprecationWarning,
            )

        if eigenvalues is not None or eigenvectors is not None:
            warnings.warn(
                "Instanciation init parameters of eigenvalues and "
                "eigenvectors are deprecated. Use "
                "create_dynamical_matrices method.",
                DeprecationWarning,
            )

        if eigenvalues is not None and eigenvectors is not None:
            self.create_dynamical_matrices(eigenvalues=eigenvalues,
                                           eigenvectors=eigenvectors)
        elif dynamical_matrices is not None:
            self.dynamical_matrices = dynamical_matrices