Skip to content

Commit

Permalink
Merge branch 'develop' into publish-gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Nov 12, 2024
2 parents c0d6e15 + ff7be8c commit 7623be1
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 90 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/phono3py-pytest-conda-numpy2.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
exclude: ^example/AlN-LDA/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.3
hooks:
- id: ruff
args: [ "--fix", "--show-fixes" ]
Expand Down
2 changes: 1 addition & 1 deletion doc/random-displacements.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(random-displacements)=
# Force constants calculation with randan displacements of atoms
# Force constants calculation with random displacements of atoms

Random displacements and corresponding forces in supercells can be employed as a
displacement-force dataset for computing force constants. This requires an
Expand Down
39 changes: 13 additions & 26 deletions phono3py/api_phono3py.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
get_random_displacements_dataset,
)
from phonopy.harmonic.dynamical_matrix import DynamicalMatrix
from phonopy.harmonic.force_constants import get_fc2 as get_phonopy_fc2
from phonopy.harmonic.force_constants import (
set_permutation_symmetry,
set_translational_invariance,
Expand All @@ -74,7 +73,6 @@
guess_primitive_matrix,
shape_supercell_matrix,
)
from phonopy.structure.dataset import get_displacements_and_forces
from phonopy.structure.symmetry import Symmetry
from phonopy.units import VaspToTHz

Expand Down Expand Up @@ -1540,30 +1538,19 @@ def produce_fc2(
else:
p2s_map = None

if fc_calculator is not None:
disps, forces = get_displacements_and_forces(disp_dataset)
self._fc2 = get_fc2(
self._phonon_supercell,
self._phonon_primitive,
disps,
forces,
fc_calculator=fc_calculator,
fc_calculator_options=fc_calculator_options,
atom_list=p2s_map,
symmetry=self._phonon_supercell_symmetry,
symprec=self._symprec,
log_level=self._log_level,
)
else:
if "displacements" in disp_dataset:
msg = "fc_calculator to solve fc2 has to be set."
raise RuntimeError(msg)
self._fc2 = get_phonopy_fc2(
self._phonon_supercell,
self._phonon_supercell_symmetry,
disp_dataset,
atom_list=p2s_map,
)
self._fc2 = get_fc2(
self._phonon_supercell,
self._phonon_primitive,
disp_dataset,
fc_calculator=fc_calculator,
fc_calculator_options=fc_calculator_options,
atom_list=p2s_map,
symmetry=self._phonon_supercell_symmetry,
symprec=self._symprec,
log_level=self._log_level,
)

if fc_calculator is None or fc_calculator == "traditional":
if symmetrize_fc2:
if is_compact_fc:
symmetrize_compact_force_constants(
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ dynamic = ["version"]
readme = { file = "README.md", content-type = "text/markdown" }
description = "This is the phono3py module."
authors = [{ name = "Atsushi Togo", email = "[email protected]" }]
requires-python = ">=3.8"
requires-python = ">=3.9"
dependencies = [
"numpy>=1.17.0",
"scipy",
"PyYAML>=5.3",
"matplotlib>=2.2.2",
"h5py>=3.0",
"spglib>=2.3",
"phonopy>=2.29,<2.30",
"phonopy>=2.30,<2.31",
]
license = { file = "LICENSE" }

Expand Down
2 changes: 1 addition & 1 deletion test/other/test_isotope.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def test_Phono3pyIsotope_grg(si_pbesol_grg, lang):
iso.grid.grid_matrix, [[-15, 15, 15], [15, -15, 15], [15, 15, -15]]
)
iso.run([23, 103], lang=lang)
np.testing.assert_allclose(si_pbesol_grg_iso, iso.gamma[0], atol=2e-3)
np.testing.assert_allclose(si_pbesol_grg_iso, iso.gamma[0], atol=3e-3)


@pytest.mark.parametrize("lang", ["C", "Py"])
Expand Down
8 changes: 5 additions & 3 deletions test/sscha/test_sscha.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ def get_supercell_phonon(ph3):
return SupercellPhonon(supercell, fc2, frequency_factor_to_THz=factor)


def mass_sand(matrix, mass):
def mass_sand(matrix: np.ndarray, mass: np.ndarray) -> np.ndarray:
"""Calculate mass sandwich."""
return ((matrix * mass).T * mass).T


def mass_inv(matrix, mass):
def mass_inv(matrix: np.ndarray, mass: np.ndarray, tol: float = 1e-5) -> np.ndarray:
"""Calculate inverse mass sandwich."""
bare = mass_sand(matrix, mass)
inv_bare = np.linalg.pinv(bare)
eigvals, eigvecs = np.linalg.eigh(bare)
inv_eigvals = [1 / x if x > tol else 0 for x in eigvals]
inv_bare = (eigvecs * inv_eigvals) @ eigvecs.T
return mass_sand(inv_bare, mass)


Expand Down

0 comments on commit 7623be1

Please sign in to comment.