mirror of https://github.com/phonopy/phono3py.git
Merge branch 'develop'
This commit is contained in:
commit
7a2b54faa7
|
@ -24,7 +24,7 @@ jobs:
|
|||
run: |
|
||||
conda activate test
|
||||
conda install --yes python=${{ matrix.python-version }}
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest spglib alm cmake c-compiler cxx-compiler "pypolymlp<0.9"
|
||||
- name: Install symfc develop branch
|
||||
run: |
|
||||
conda activate test
|
||||
|
|
|
@ -24,7 +24,7 @@ jobs:
|
|||
run: |
|
||||
conda activate test
|
||||
conda install --yes python=${{ matrix.python-version }}
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest spglib alm cmake c-compiler cxx-compiler "pypolymlp<0.9"
|
||||
- name: Install symfc develop branch
|
||||
run: |
|
||||
conda activate test
|
||||
|
|
|
@ -24,7 +24,7 @@ jobs:
|
|||
run: |
|
||||
conda activate test
|
||||
conda install --yes python=${{ matrix.python-version }}
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler cxx-compiler pypolymlp
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler cxx-compiler "pypolymlp<0.9"
|
||||
- name: Install symfc develop branch
|
||||
run: |
|
||||
conda activate test
|
||||
|
|
|
@ -24,7 +24,7 @@ jobs:
|
|||
run: |
|
||||
conda activate test
|
||||
conda install --yes python=${{ matrix.python-version }}
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp
|
||||
conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest spglib alm cmake c-compiler cxx-compiler "pypolymlp<0.9"
|
||||
- name: Install symfc develop branch
|
||||
run: |
|
||||
conda activate test
|
||||
|
|
|
@ -25,7 +25,7 @@ jobs:
|
|||
run: |
|
||||
conda activate test
|
||||
conda install --yes python=${{ matrix.python-version }}
|
||||
conda install --yes matplotlib-base pyyaml h5py "numpy>=2.1" scipy pytest spglib alm cmake c-compiler cxx-compiler pypolymlp
|
||||
conda install --yes matplotlib-base pyyaml h5py "numpy>=2.1" scipy pytest spglib alm cmake c-compiler cxx-compiler "pypolymlp<0.9"
|
||||
- name: Install dependent packages for python == 3.9
|
||||
if: ${{ matrix.python-version == 3.9 }}
|
||||
run: |
|
||||
|
|
|
@ -11,7 +11,7 @@ repos:
|
|||
exclude: ^example/AlN-LDA/
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.9.4
|
||||
rev: v0.9.7
|
||||
hooks:
|
||||
- id: ruff
|
||||
args: [ "--fix", "--show-fixes" ]
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
# Change Log
|
||||
|
||||
## Mar-1-2025: Version 3.14.1
|
||||
|
||||
- Release to follow the change of phonopy
|
||||
|
||||
## Feb-7-2025: Version 3.14.0
|
||||
|
||||
- Release to follow the change of phonopy
|
||||
|
|
|
@ -60,7 +60,7 @@ copyright = "2015, Atsushi Togo"
|
|||
# The short X.Y version.
|
||||
version = "3.14"
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = "3.14.0"
|
||||
release = "3.14.1"
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
@ -42,12 +42,15 @@ in the distribution from GitHub or PyPI.
|
|||
|
||||
## Requirements
|
||||
|
||||
- [pypolymlp](https://github.com/sekocha/pypolymlp)
|
||||
- [pypolymlp](https://github.com/sekocha/pypolymlp) < 0.9
|
||||
|
||||
For linux (x86-64), a compiled package of pypolymlp can be installed via
|
||||
conda-forge (recommended). Otherwise, pypolymlp can be installed from
|
||||
source-code.
|
||||
|
||||
From pypolymlp 0.9, its file format was changed. This will be taken care of
|
||||
by the future version of phonopy and phono3py.
|
||||
|
||||
## How to calculate
|
||||
|
||||
### Workflow
|
||||
|
|
|
@ -41,7 +41,6 @@ from collections.abc import Sequence
|
|||
from typing import Literal, Optional, Union
|
||||
|
||||
import numpy as np
|
||||
from phonopy.exception import ForceCalculatorRequiredError
|
||||
from phonopy.harmonic.displacement import (
|
||||
directions_to_displacement_dataset,
|
||||
get_least_displacements,
|
||||
|
@ -74,10 +73,10 @@ from phonopy.units import VaspToTHz
|
|||
|
||||
from phono3py.conductivity.direct_solution import get_thermal_conductivity_LBTE
|
||||
from phono3py.conductivity.rta import get_thermal_conductivity_RTA
|
||||
from phono3py.interface.fc_calculator import get_fc3
|
||||
from phono3py.interface.fc_calculator import get_fc3_solver
|
||||
from phono3py.interface.phono3py_yaml import Phono3pyYaml
|
||||
from phono3py.phonon.grid import BZGrid
|
||||
from phono3py.phonon3.dataset import forces_in_dataset, get_displacements_and_forces_fc3
|
||||
from phono3py.phonon3.dataset import forces_in_dataset
|
||||
from phono3py.phonon3.displacement_fc3 import (
|
||||
direction_to_displacement,
|
||||
get_third_order_displacements,
|
||||
|
@ -89,7 +88,6 @@ from phono3py.phonon3.fc3 import (
|
|||
set_translational_invariance_compact_fc3,
|
||||
set_translational_invariance_fc3,
|
||||
)
|
||||
from phono3py.phonon3.fc3 import get_fc3 as get_phono3py_fc3
|
||||
from phono3py.phonon3.imag_self_energy import (
|
||||
get_imag_self_energy,
|
||||
write_imag_self_energy,
|
||||
|
@ -1485,33 +1483,20 @@ class Phono3py:
|
|||
Options for external force constants calculator.
|
||||
|
||||
"""
|
||||
if fc_calculator is not None:
|
||||
disps, forces = get_displacements_and_forces_fc3(self._dataset)
|
||||
fc2, fc3 = get_fc3(
|
||||
self._supercell,
|
||||
self._primitive,
|
||||
disps,
|
||||
forces,
|
||||
fc_calculator=fc_calculator,
|
||||
fc_calculator_options=fc_calculator_options,
|
||||
is_compact_fc=is_compact_fc,
|
||||
symmetry=self._symmetry,
|
||||
log_level=self._log_level,
|
||||
)
|
||||
else:
|
||||
if "displacements" in self._dataset:
|
||||
raise ForceCalculatorRequiredError(
|
||||
"fc_calculator has to be set to produce force constants from this "
|
||||
"dataset."
|
||||
)
|
||||
fc2, fc3 = get_phono3py_fc3(
|
||||
self._supercell,
|
||||
self._primitive,
|
||||
self._dataset,
|
||||
self._symmetry,
|
||||
is_compact_fc=is_compact_fc,
|
||||
verbose=self._log_level,
|
||||
)
|
||||
fc_solver = get_fc3_solver(
|
||||
self._supercell,
|
||||
self._primitive,
|
||||
self._dataset,
|
||||
fc_calculator=fc_calculator,
|
||||
fc_calculator_options=fc_calculator_options,
|
||||
is_compact_fc=is_compact_fc,
|
||||
symmetry=self._symmetry,
|
||||
log_level=self._log_level,
|
||||
)
|
||||
fc2 = fc_solver.force_constants[2]
|
||||
fc3 = fc_solver.force_constants[3]
|
||||
|
||||
if fc_calculator is None or fc_calculator == "traditional":
|
||||
if symmetrize_fc3r:
|
||||
if is_compact_fc:
|
||||
set_translational_invariance_compact_fc3(fc3, self._primitive)
|
||||
|
|
|
@ -39,24 +39,27 @@ from __future__ import annotations
|
|||
from typing import Optional, Union
|
||||
|
||||
import numpy as np
|
||||
from phonopy.interface.fc_calculator import FCSolver
|
||||
from phonopy.interface.symfc import SymfcFCSolver
|
||||
from phonopy.structure.atoms import PhonopyAtoms
|
||||
from phonopy.structure.cells import Primitive
|
||||
from phonopy.structure.symmetry import Symmetry
|
||||
|
||||
from phono3py.phonon3.dataset import get_displacements_and_forces_fc3
|
||||
from phono3py.phonon3.fc3 import get_fc3
|
||||
|
||||
def get_fc3(
|
||||
|
||||
def get_fc3_solver(
|
||||
supercell: PhonopyAtoms,
|
||||
primitive: Primitive,
|
||||
displacements: np.ndarray,
|
||||
forces: np.ndarray,
|
||||
dataset: dict,
|
||||
fc_calculator: Optional[str] = None,
|
||||
fc_calculator_options: Optional[str] = None,
|
||||
is_compact_fc: bool = False,
|
||||
symmetry: Optional[Symmetry] = None,
|
||||
log_level: int = 0,
|
||||
):
|
||||
"""Calculate 2upercell 2nd and 3rd order force constants.
|
||||
) -> FC3Solver:
|
||||
"""Return force constants solver for fc3.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
|
@ -64,59 +67,42 @@ def get_fc3(
|
|||
Supercell
|
||||
primitive : Primitive
|
||||
Primitive cell
|
||||
displacements : array_like
|
||||
Displacements of atoms in supercell.
|
||||
shape=(num_snapshots, num_atoms, 3), dtype='double', order='C'
|
||||
forces : array_like
|
||||
Forces of atoms in supercell.
|
||||
shape=(num_snapshots, num_atoms, 3), dtype='double', order='C'
|
||||
dataset : dict, optional
|
||||
Dataset that contains displacements, forces, and optionally
|
||||
energies. Default is None.
|
||||
fc_calculator : str, optional
|
||||
Currently only 'alm' is supported. Default is None, meaning invoking
|
||||
'alm'.
|
||||
fc_calculator_options : str, optional
|
||||
This is arbitrary string.
|
||||
is_compact_fc : bool, optional
|
||||
If True, force constants are returned in the compact form.
|
||||
symmetry : Symmetry, optional
|
||||
Symmetry of supercell. This is used for the traditional and symfc FC
|
||||
solver. Default is None.
|
||||
log_level : integer or bool, optional
|
||||
Verbosity level. False or 0 means quiet. True or 1 means normal level
|
||||
of log to stdout. 2 gives verbose mode.
|
||||
|
||||
Returns
|
||||
-------
|
||||
(fc2, fc3) : tuple[ndarray]
|
||||
2nd and 3rd order force constants.
|
||||
FC3Solver
|
||||
Force constants solver for fc3.
|
||||
|
||||
"""
|
||||
if fc_calculator == "alm":
|
||||
from phonopy.interface.alm import run_alm
|
||||
|
||||
fc = run_alm(
|
||||
supercell,
|
||||
primitive,
|
||||
displacements,
|
||||
forces,
|
||||
2,
|
||||
options=fc_calculator_options,
|
||||
is_compact_fc=is_compact_fc,
|
||||
log_level=log_level,
|
||||
)
|
||||
return fc[2], fc[3]
|
||||
elif fc_calculator == "symfc":
|
||||
from phonopy.interface.symfc import run_symfc
|
||||
|
||||
fc = run_symfc(
|
||||
supercell,
|
||||
primitive,
|
||||
displacements,
|
||||
forces,
|
||||
orders=[2, 3],
|
||||
is_compact_fc=is_compact_fc,
|
||||
symmetry=symmetry,
|
||||
options=fc_calculator_options,
|
||||
log_level=log_level,
|
||||
)
|
||||
return fc[2], fc[3]
|
||||
else:
|
||||
msg = "Force constants calculator of %s was not found ." % fc_calculator
|
||||
raise RuntimeError(msg)
|
||||
fc_solver_name = fc_calculator if fc_calculator is not None else "traditional"
|
||||
fc_solver = FC3Solver(
|
||||
fc_solver_name,
|
||||
supercell,
|
||||
symmetry=symmetry,
|
||||
dataset=dataset,
|
||||
is_compact_fc=is_compact_fc,
|
||||
primitive=primitive,
|
||||
orders=[2, 3],
|
||||
options=fc_calculator_options,
|
||||
log_level=log_level,
|
||||
)
|
||||
return fc_solver
|
||||
|
||||
|
||||
def extract_fc2_fc3_calculators(
|
||||
|
@ -192,3 +178,70 @@ def estimate_symfc_memory_usage(
|
|||
memsize = basis_size**2 * 3 * 8 / 10**9
|
||||
memsize2 = len(supercell) * 3 * batch_size * basis_size * 8 / 10**9
|
||||
return memsize, memsize2
|
||||
|
||||
|
||||
class FDFC3Solver:
|
||||
"""Finite difference type force constants calculator.
|
||||
|
||||
This is phono3py's traditional force constants calculator.
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
supercell: PhonopyAtoms,
|
||||
primitive: Primitive,
|
||||
symmetry: Symmetry,
|
||||
dataset: dict,
|
||||
is_compact_fc: bool = False,
|
||||
log_level: int = 0, # currently not used
|
||||
):
|
||||
self._fc2, self._fc3 = self._run(
|
||||
supercell,
|
||||
primitive,
|
||||
symmetry,
|
||||
dataset,
|
||||
is_compact_fc,
|
||||
log_level,
|
||||
)
|
||||
|
||||
@property
|
||||
def force_constants(self) -> dict[int, np.ndarray]:
|
||||
"""Return force constants.
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict[int, np.ndarray]
|
||||
Force constants with order as key.
|
||||
|
||||
"""
|
||||
return {2: self._fc2, 3: self._fc3}
|
||||
|
||||
def _run(
|
||||
self,
|
||||
supercell: PhonopyAtoms,
|
||||
primitive: Primitive,
|
||||
symmetry: Symmetry,
|
||||
dataset: dict,
|
||||
is_compact_fc: bool,
|
||||
log_level: int,
|
||||
):
|
||||
return get_fc3(
|
||||
supercell,
|
||||
primitive,
|
||||
dataset,
|
||||
symmetry,
|
||||
is_compact_fc=is_compact_fc,
|
||||
verbose=log_level > 0,
|
||||
)
|
||||
|
||||
|
||||
class FC3Solver(FCSolver):
|
||||
"""Force constants solver for fc3."""
|
||||
|
||||
def _set_traditional_solver(self, solver_class: Optional[type] = FDFC3Solver):
|
||||
return super()._set_traditional_solver(solver_class=solver_class)
|
||||
|
||||
def _get_displacements_and_forces(self):
|
||||
"""Return displacements and forces for fc3."""
|
||||
return get_displacements_and_forces_fc3(self._dataset)
|
||||
|
|
|
@ -40,13 +40,13 @@ import sys
|
|||
import numpy as np
|
||||
from phonopy.harmonic.force_constants import (
|
||||
distribute_force_constants,
|
||||
get_fc2,
|
||||
get_nsym_list_and_s2pp,
|
||||
get_positions_sent_by_rot_inv,
|
||||
get_rotated_displacement,
|
||||
similarity_transformation,
|
||||
solve_force_constants,
|
||||
)
|
||||
from phonopy.interface.fc_calculator import get_fc2
|
||||
from phonopy.structure.atoms import PhonopyAtoms
|
||||
from phonopy.structure.cells import Primitive, compute_all_sg_permutations
|
||||
from phonopy.structure.symmetry import Symmetry
|
||||
|
@ -84,7 +84,13 @@ def get_fc3(
|
|||
"""
|
||||
# fc2 has to be full matrix to compute delta-fc2
|
||||
# p2s_map elements are extracted if is_compact_fc=True at the last part.
|
||||
fc2 = get_fc2(supercell, symmetry, disp_dataset)
|
||||
fc2 = get_fc2(
|
||||
supercell,
|
||||
disp_dataset,
|
||||
primitive=primitive,
|
||||
is_compact_fc=False,
|
||||
symmetry=symmetry,
|
||||
)
|
||||
fc3 = _get_fc3_least_atoms(
|
||||
supercell,
|
||||
primitive,
|
||||
|
|
|
@ -34,4 +34,4 @@
|
|||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
__version__ = "3.14.0"
|
||||
__version__ = "3.14.1"
|
||||
|
|
|
@ -16,7 +16,7 @@ dependencies = [
|
|||
"matplotlib",
|
||||
"h5py",
|
||||
"spglib",
|
||||
"phonopy>=2.37,<2.38",
|
||||
"phonopy>=2.37.1,<2.38",
|
||||
]
|
||||
license = { file = "LICENSE" }
|
||||
|
||||
|
|
Loading…
Reference in New Issue