mirror of https://github.com/phonopy/phono3py.git
Merge branch 'develop'
This commit is contained in:
commit
20d7c86621
|
@ -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" ]
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -114,7 +114,7 @@ def print_phono3py():
|
|||
| .__/|_| |_|\___/|_| |_|\___/____/| .__/ \__, |
|
||||
|_| |_| |___/ """
|
||||
)
|
||||
print_version(__version__)
|
||||
print_version(__version__, package_name="phono3py")
|
||||
print_time()
|
||||
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
|
|
@ -38,6 +38,13 @@ from __future__ import annotations
|
|||
|
||||
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 @@ class BZGrid:
|
|||
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 @@ class BZGrid:
|
|||
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 @@ class BZGrid:
|
|||
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 @@ class BZGrid:
|
|||
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 @@ class GridMatrix:
|
|||
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 @@ class GridMatrix:
|
|||
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 @@ class GridMatrix:
|
|||
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 @@ class GridMatrix:
|
|||
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 @@ class GridMatrix:
|
|||
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 @@ class GridMatrix:
|
|||
"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 @@ class GridMatrix:
|
|||
`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
|
||||
)
|
||||
|
|
|
@ -772,8 +772,8 @@ class Interaction:
|
|||
# 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 @@ class Interaction:
|
|||
|
||||
"""
|
||||
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 @@ class Interaction:
|
|||
|
||||
"""
|
||||
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, :]
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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" }
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue