From e72847887405568a28e8bb695dea88b964c02867 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Sun, 11 Aug 2024 17:19:24 +0900 Subject: [PATCH 1/5] Minor updates following phonopy update --- phono3py/cui/create_force_constants.py | 8 ++++---- phono3py/cui/create_force_sets.py | 20 +++++++++++--------- phono3py/cui/phono3py_script.py | 4 ++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/phono3py/cui/create_force_constants.py b/phono3py/cui/create_force_constants.py index 8ac34d9f..c4a41cd3 100644 --- a/phono3py/cui/create_force_constants.py +++ b/phono3py/cui/create_force_constants.py @@ -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) @@ -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) @@ -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 @@ -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 diff --git a/phono3py/cui/create_force_sets.py b/phono3py/cui/create_force_sets.py index 38bfe428..57c69570 100644 --- a/phono3py/cui/create_force_sets.py +++ b/phono3py/cui/create_force_sets.py @@ -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) @@ -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) @@ -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: @@ -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}") @@ -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, @@ -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}") @@ -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, diff --git a/phono3py/cui/phono3py_script.py b/phono3py/cui/phono3py_script.py index b0bc4821..4ac0fe75 100644 --- a/phono3py/cui/phono3py_script.py +++ b/phono3py/cui/phono3py_script.py @@ -114,7 +114,7 @@ def print_phono3py(): | .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, | |_| |_| |___/ """ ) - print_version(__version__) + print_version(__version__, package_name="phono3py") print_time() @@ -264,7 +264,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, From 56d27b076897b731acfb17aa000928f848e606ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Aug 2024 23:08:53 +0000 Subject: [PATCH 2/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.5.6 → v0.5.7](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.6...v0.5.7) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dd851ddb..47dd1f49 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: exclude: ^example/AlN-LDA/ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.6 + rev: v0.5.7 hooks: - id: ruff args: [ "--fix", "--show-fixes" ] From f2b3718435727021e656b1f41fa3abf09886711e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 19 Aug 2024 23:09:18 +0000 Subject: [PATCH 3/5] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/astral-sh/ruff-pre-commit: v0.5.7 → v0.6.1](https://github.com/astral-sh/ruff-pre-commit/compare/v0.5.7...v0.6.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 47dd1f49..84862979 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,7 +11,7 @@ repos: exclude: ^example/AlN-LDA/ - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.7 + rev: v0.6.1 hooks: - id: ruff args: [ "--fix", "--show-fixes" ] From e058270b6f9366d0248216dc17d769b092dbd8ff Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 23 Aug 2024 11:30:14 +0900 Subject: [PATCH 4/5] Update to follow phonopy update for spglib v2.5 --- phono3py/cui/phono3py_script.py | 5 ++- phono3py/phonon/grid.py | 62 ++++++++++++++++++++------------- phono3py/phonon3/interaction.py | 10 +++--- test/phonon/test_grid.py | 4 +-- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/phono3py/cui/phono3py_script.py b/phono3py/cui/phono3py_script.py index 4ac0fe75..943b9311 100644 --- a/phono3py/cui/phono3py_script.py +++ b/phono3py/cui/phono3py_script.py @@ -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) diff --git a/phono3py/phonon/grid.py b/phono3py/phonon/grid.py index a3407b96..1aa34fc6 100644 --- a/phono3py/phonon/grid.py +++ b/phono3py/phonon/grid.py @@ -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 @@ -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, @@ -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 @@ -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 @@ -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( @@ -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, @@ -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 @@ -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", @@ -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( @@ -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, @@ -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, @@ -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 ) diff --git a/phono3py/phonon3/interaction.py b/phono3py/phonon3/interaction.py index 6461fc0c..6bf486f7 100644 --- a/phono3py/phonon3/interaction.py +++ b/phono3py/phonon3/interaction.py @@ -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, ) @@ -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 @@ -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, :] diff --git a/test/phonon/test_grid.py b/test/phonon/test_grid.py index a770d047..a43646f0 100644 --- a/test/phonon/test_grid.py +++ b/test/phonon/test_grid.py @@ -2425,7 +2425,7 @@ def test_GridMatrix_with_grid_matrix(ph_nacl: Phonopy): np.testing.assert_array_equal(gm.grid_matrix, mesh) np.testing.assert_array_equal(gm.D_diag, [9, 18, 18]) - tmat = ph_nacl.primitive_symmetry.dataset["transformation_matrix"] + tmat = ph_nacl.primitive_symmetry.dataset.transformation_matrix gm = GridMatrix(mesh, ph_nacl.primitive.cell, transformation_matrix=tmat) np.testing.assert_array_equal(gm.grid_matrix, mesh) np.testing.assert_array_equal(gm.D_diag, [9, 18, 18]) @@ -2439,7 +2439,7 @@ def test_GridMatrix_with_transformation_matrix(ph_nacl: Phonopy): """ mesh = 50.0 - tmat = ph_nacl.primitive_symmetry.dataset["transformation_matrix"] + tmat = ph_nacl.primitive_symmetry.dataset.transformation_matrix gm = GridMatrix( mesh, ph_nacl.primitive.cell, From b49f55d306fe71fee4fef32770b676e4d2121f78 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Fri, 23 Aug 2024 22:22:28 +0900 Subject: [PATCH 5/5] Set version 3.4 --- doc/changelog.md | 4 ++++ get_nanoversion.sh | 17 ----------------- phono3py/version.py | 2 +- pyproject.toml | 2 +- 4 files changed, 6 insertions(+), 19 deletions(-) delete mode 100755 get_nanoversion.sh diff --git a/doc/changelog.md b/doc/changelog.md index 661b84f6..b703de32 100644 --- a/doc/changelog.md +++ b/doc/changelog.md @@ -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. diff --git a/get_nanoversion.sh b/get_nanoversion.sh deleted file mode 100755 index 5a17025d..00000000 --- a/get_nanoversion.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -br=`git rev-parse HEAD` -echo $br -read o u f <<< `git remote -v |grep origin |grep fetch` -echo "Repo: $o $u $br" -git describe --tags --dirty -TD=`mktemp -d` -WD=`pwd` -git branch -git clone $u $TD -cd $TD -git checkout $br -echo $u $br -git describe --tags --dirty | sed -e 's/\([.0-9]*\)-\(.*\)-g.*/\2/' -e 's/^[vr]//g' -e 's/rc-//g' > $WD/__nanoversion__.txt -cd $WD -rm -rf "$TD" diff --git a/phono3py/version.py b/phono3py/version.py index d279b99a..cb1c9419 100644 --- a/phono3py/version.py +++ b/phono3py/version.py @@ -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" diff --git a/pyproject.toml b/pyproject.toml index 6447ea50..c9709b36 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" }