Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Aug 23, 2024
2 parents b828d78 + 372f7ca commit 20d7c86
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 67 deletions.
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.5.6
rev: v0.6.1
hooks:
- id: ruff
args: [ "--fix", "--show-fixes" ]
Expand Down
4 changes: 4 additions & 0 deletions doc/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Change Log

## Aug-23-2024: Version 3.4

- Update for spglib v2.5 and for following the change in phonopy.

## Aug-8-2024: Version 3.3.4

- Fix of command line user interface.
Expand Down
17 changes: 0 additions & 17 deletions get_nanoversion.sh

This file was deleted.

8 changes: 4 additions & 4 deletions phono3py/cui/create_force_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def _read_phono3py_fc3(phono3py: Phono3py, symmetrize_fc3r, input_filename, log_
filename = "fc3.hdf5"
else:
filename = "fc3." + input_filename + ".hdf5"
file_exists(filename, log_level)
file_exists(filename, log_level=log_level)
if log_level:
print('Reading fc3 from "%s".' % filename)

Expand Down Expand Up @@ -380,7 +380,7 @@ def _read_phono3py_fc2(phono3py, symmetrize_fc2, input_filename, log_level):
filename = "fc2.hdf5"
else:
filename = "fc2." + input_filename + ".hdf5"
file_exists(filename, log_level)
file_exists(filename, log_level=log_level)
if log_level:
print('Reading fc2 from "%s".' % filename)

Expand Down Expand Up @@ -494,7 +494,7 @@ def _read_dataset_fc3(
sys.exit(1)
except FileNotFoundError as e:
# from _get_type2_dataset
file_exists(e.filename, log_level)
file_exists(e.filename, log_level=log_level)

if use_pypolymlp:
phono3py.mlp_dataset = dataset
Expand Down Expand Up @@ -672,7 +672,7 @@ def _read_dataset_fc2(
print_error()
sys.exit(1)
except FileNotFoundError as e:
file_exists(e.filename, log_level)
file_exists(e.filename, log_level=log_level)

if phono3py.phonon_supercell_matrix is not None:
phono3py.phonon_dataset = dataset
Expand Down
20 changes: 11 additions & 9 deletions phono3py/cui/create_force_sets.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def create_FORCES_FC3_and_FORCES_FC2(
]
if cell_filename is not None:
disp_filename_candidates.insert(0, cell_filename)
disp_filenames = files_exist(disp_filename_candidates, log_level, is_any=True)
disp_filenames = files_exist(
disp_filename_candidates, log_level=log_level, is_any=True
)
disp_filename = disp_filenames[0]
ph3py_yaml = Phono3pyYaml(settings={"force_sets": True})
ph3py_yaml.read(disp_filename)
Expand Down Expand Up @@ -152,7 +154,7 @@ def create_FORCES_FC3_and_FORCES_FC2(
def create_FORCES_FC2_from_FORCE_SETS(log_level):
"""Convert FORCE_SETS to FORCES_FC2."""
filename = "FORCE_SETS"
file_exists(filename, log_level)
file_exists(filename, log_level=log_level)
disp_dataset = parse_FORCE_SETS(filename=filename)
write_FORCES_FC2(disp_dataset)

Expand Down Expand Up @@ -189,8 +191,8 @@ def create_FORCE_SETS_from_FORCES_FCx(
len_first_line = get_length_of_first_line(f)

if len_first_line == 3:
file_exists(disp_filename, log_level)
file_exists(forces_filename, log_level)
file_exists(disp_filename, log_level=log_level)
file_exists(forces_filename, log_level=log_level)
ph3yml = Phono3pyYaml()
ph3yml.read(disp_filename)
if phonon_smat is None:
Expand Down Expand Up @@ -242,7 +244,7 @@ def _get_force_sets_fc2(

force_filenames = settings.create_forces_fc2
for filename in force_filenames:
file_exists(filename, log_level)
file_exists(filename, log_level=log_level)

if log_level > 0:
print(f" Number of displacements: {num_disps}")
Expand All @@ -258,7 +260,7 @@ def _get_force_sets_fc2(

if settings.subtract_forces:
force_filename = settings.subtract_forces
file_exists(force_filename, log_level)
file_exists(force_filename, log_level=log_level)
calc_dataset_zero = get_calc_dataset(
interface_mode,
num_atoms,
Expand Down Expand Up @@ -301,13 +303,13 @@ def _get_force_sets_fc3(
raise RuntimeError("FC3 displacement dataset is broken.")

if settings.create_forces_fc3_file:
file_exists(settings.create_forces_fc3_file, log_level)
file_exists(settings.create_forces_fc3_file, log_level=log_level)
force_filenames = [x.strip() for x in open(settings.create_forces_fc3_file)]
else:
force_filenames = settings.create_forces_fc3

for filename in force_filenames:
file_exists(filename, log_level)
file_exists(filename, log_level=log_level)

if log_level > 0:
print(f" Number of displacements: {num_disps}")
Expand All @@ -326,7 +328,7 @@ def _get_force_sets_fc3(

if settings.subtract_forces:
force_filename = settings.subtract_forces
file_exists(force_filename, log_level)
file_exists(force_filename, log_level=log_level)
calc_dataset = get_calc_dataset(
interface_mode,
num_atoms,
Expand Down
9 changes: 6 additions & 3 deletions phono3py/cui/phono3py_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def print_phono3py():
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|_| |_| |___/ """
)
print_version(__version__)
print_version(__version__, package_name="phono3py")
print_time()


Expand Down Expand Up @@ -244,7 +244,10 @@ def start_phono3py(**argparse_control) -> tuple[argparse.Namespace, int]:
print("Python version %d.%d.%d" % sys.version_info[:3])
import spglib

print("Spglib version %d.%d.%d" % spglib.get_version())
try: # spglib.get_version() is deprecated.
print(f"Spglib version {spglib.spg_get_version()}")
except AttributeError:
print("Spglib version %d.%d.%d" % spglib.get_version())

if deprecated:
show_deprecated_option_warnings(deprecated)
Expand All @@ -264,7 +267,7 @@ def read_phono3py_settings(args, argparse_control, log_level):
load_phono3py_yaml = argparse_control.get("load_phono3py_yaml", False)

if len(args.filename) > 0:
file_exists(args.filename[0], log_level)
file_exists(args.filename[0], log_level=log_level)
if load_phono3py_yaml:
phono3py_conf_parser = Phono3pyConfParser(
filename=args.conf_filename,
Expand Down
62 changes: 38 additions & 24 deletions phono3py/phonon/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@

import warnings
from collections.abc import Sequence

try:
from spglib import SpglibDataset
except ImportError:
from types import SimpleNamespace as SpglibDataset


from typing import Optional, Union

import numpy as np
Expand Down Expand Up @@ -137,7 +144,7 @@ def __init__(
mesh: Union[int, float, Sequence, np.ndarray],
reciprocal_lattice=None,
lattice=None,
symmetry_dataset: Optional[dict] = None,
symmetry_dataset: Optional[Union[SpglibDataset]] = None,
transformation_matrix: Optional[Union[Sequence, np.ndarray]] = None,
is_shift: Optional[Union[list, np.ndarray]] = None,
is_time_reversal: bool = True,
Expand All @@ -156,9 +163,10 @@ def __init__(
lattice : array_like
Direct primitive basis vectors given as row vectors shape=(3, 3),
dtype='double', order='C'
symmetry_dataset : dict, optional
symmetry_dataset : SpglibDataset, optional
Symmetry dataset (Symmetry.dataset) searched for the primitive cell
corresponding to ``reciprocal_lattice`` or ``lattice``.
corresponding to ``reciprocal_lattice`` or ``lattice``. For spglib <
v2.5, SimpleNamespace is used instead of SpglibDataset.
transformation_matrix : array_like, optional
Transformation matrix equivalent to ``transformation_matrix`` in
spglib-dataset. This is only used when ``use_grg=True`` and
Expand Down Expand Up @@ -384,7 +392,7 @@ def reciprocal_operations(self):
return self._reciprocal_operations

@property
def symmetry_dataset(self):
def symmetry_dataset(self) -> SpglibDataset:
"""Return Symmetry.dataset."""
return self._symmetry_dataset

Expand Down Expand Up @@ -472,7 +480,7 @@ def _set_rotations(self):
direct_rotations = np.eye(3, dtype="int_", order="C").reshape(1, 3, 3)
else:
direct_rotations = np.array(
self._symmetry_dataset["rotations"], dtype="int_", order="C"
self._symmetry_dataset.rotations, dtype="int_", order="C"
)
rec_rotations = np.zeros((48, 3, 3), dtype="int_", order="C")
num_rec_rot = recgrid.reciprocal_rotations(
Expand Down Expand Up @@ -530,7 +538,7 @@ def __init__(
self,
mesh: Union[int, float, Sequence, np.ndarray],
lattice: Union[Sequence, np.ndarray],
symmetry_dataset: Optional[dict] = None,
symmetry_dataset: Optional[SpglibDataset] = None,
transformation_matrix: Optional[Union[list, np.ndarray]] = None,
use_grg: bool = True,
force_SNF: bool = False,
Expand All @@ -547,9 +555,10 @@ def __init__(
lattice : array_like
Primitive basis vectors in direct space given as row vectors.
shape=(3, 3), dtype='double', order='C'
symmetry_dataset : dict, optional
symmetry_dataset : SpglibDataset, optional
Symmetry dataset of spglib (Symmetry.dataset) of primitive cell that
has `lattice`. Default is None.
has `lattice`. Default is None. For spglib <
v2.5, SimpleNamespace is used instead of SpglibDataset.
transformation_matrix : array_like, optional
Transformation matrix equivalent to ``transformation_matrix`` in
spglib-dataset. This is only used when ``use_grg=True`` and
Expand Down Expand Up @@ -627,7 +636,7 @@ def _set_mesh_numbers(
self,
mesh: Union[int, float, Sequence, np.ndarray],
use_grg: bool = False,
symmetry_dataset: Optional[dict] = None,
symmetry_dataset: Optional[SpglibDataset] = None,
transformation_matrix: Optional[Union[list, np.ndarray]] = None,
force_SNF=False,
coordinates="reciprocal",
Expand Down Expand Up @@ -673,7 +682,7 @@ def _set_mesh_numbers(
self._D_diag = length2mesh(length, self._lattice)
else:
self._D_diag = length2mesh(
length, self._lattice, rotations=symmetry_dataset["rotations"]
length, self._lattice, rotations=symmetry_dataset.rotations
)
if num_values == 9:
self._run_grg(
Expand Down Expand Up @@ -703,7 +712,7 @@ def _run_grg(
sym_dataset = symmetry_dataset
else: # transformation_matrix is not None
sym_dataset = self._get_mock_symmetry_dataset(transformation_matrix)
if is_primitive_cell(sym_dataset["rotations"]):
if is_primitive_cell(sym_dataset.rotations):
self._set_GRG_mesh(
sym_dataset,
length=length,
Expand Down Expand Up @@ -742,18 +751,23 @@ def _get_mock_symmetry_dataset(self, transformation_matrix) -> dict:
"be equal to or larger than 1."
)
raise RuntimeError(msg)
sym_dataset = {
"rotations": np.eye(3, dtype="intc", order="C").reshape(1, 3, 3),
"transformation_matrix": transformation_matrix,
"std_lattice": self._lattice,
"std_types": np.array([1], dtype="intc"),
"number": 1,
}

from types import SimpleNamespace

sym_dataset = SimpleNamespace(
**{
"rotations": np.eye(3, dtype="intc", order="C").reshape(1, 3, 3),
"transformation_matrix": transformation_matrix,
"std_lattice": self._lattice,
"std_types": np.array([1], dtype="intc"),
"number": 1,
}
)
return sym_dataset

def _set_GRG_mesh(
self,
sym_dataset: dict,
sym_dataset: SpglibDataset,
length: Optional[float] = None,
grid_matrix=None,
force_SNF=False,
Expand Down Expand Up @@ -807,22 +821,22 @@ def _get_grid_matrix(
`reciprocal` (default) or `direct`.
"""
tmat = sym_dataset["transformation_matrix"]
tmat = sym_dataset.transformation_matrix
conv_lat = np.dot(np.linalg.inv(tmat).T, self._lattice)

# GRG is wanted to be generated with respect to std_lattice if possible.
if _can_use_std_lattice(
conv_lat,
tmat,
sym_dataset["std_lattice"],
sym_dataset["rotations"],
sym_dataset.std_lattice,
sym_dataset.rotations,
):
conv_lat = sym_dataset["std_lattice"]
conv_lat = sym_dataset.std_lattice
tmat = np.dot(self._lattice, np.linalg.inv(conv_lat)).T

if coordinates == "direct":
num_cells = int(np.prod(length2mesh(length, conv_lat)))
max_num_atoms = num_cells * len(sym_dataset["std_types"])
max_num_atoms = num_cells * len(sym_dataset.std_types)
conv_mesh_numbers = estimate_supercell_matrix(
sym_dataset, max_num_atoms=max_num_atoms, max_iter=200
)
Expand Down
10 changes: 5 additions & 5 deletions phono3py/phonon3/interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ def run_phonon_solver_with_eigvec_rotation(self):
# perms.shape = (len(spg_ops), len(primitive)), dtype='intc'
perms = compute_all_sg_permutations(
self._primitive.scaled_positions,
self._bz_grid.symmetry_dataset["rotations"],
self._bz_grid.symmetry_dataset["translations"],
self._bz_grid.symmetry_dataset.rotations,
self._bz_grid.symmetry_dataset.translations,
np.array(self._primitive.cell.T, dtype="double", order="C"),
symprec=self._symprec,
)
Expand Down Expand Up @@ -821,13 +821,13 @@ def _get_reciprocal_rotations_in_space_group_operations(self):
"""
d2r_map = []
for r in self._bz_grid.symmetry_dataset["rotations"]:
for r in self._bz_grid.symmetry_dataset.rotations:
for i, rec_r in enumerate(self._bz_grid.reciprocal_operations):
if (rec_r.T == r).all():
d2r_map.append(i)
break

assert len(d2r_map) == len(self._bz_grid.symmetry_dataset["rotations"])
assert len(d2r_map) == len(self._bz_grid.symmetry_dataset.rotations)

return d2r_map

Expand All @@ -838,7 +838,7 @@ def _rotate_eigvecs(self, orig_gp, bzgp, r_cart, perm, t_i):
"""
Rq = np.dot(self._bz_grid.QDinv, self._bz_grid.addresses[bzgp])
tau = self._bz_grid.symmetry_dataset["translations"][t_i]
tau = self._bz_grid.symmetry_dataset.translations[t_i]
phase_factor = np.exp(-2j * np.pi * np.dot(Rq, tau))
self._phonon_done[bzgp] = 1
self._frequencies[bzgp, :] = self._frequencies[orig_gp, :]
Expand Down
2 changes: 1 addition & 1 deletion phono3py/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.

__version__ = "3.3.4"
__version__ = "3.4.0"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"matplotlib>=2.2.2",
"h5py>=3.0",
"spglib>=2.3",
"phonopy>=2.26,<2.27",
"phonopy>=2.27,<2.28",
]
license = { file = "LICENSE" }

Expand Down
Loading

0 comments on commit 20d7c86

Please sign in to comment.