Skip to content

Commit

Permalink
Merge branch 'develop' into rc
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Nov 13, 2024
2 parents 2fe8234 + 1893361 commit ad909a3
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 113 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/phono3py-pytest-conda-numpy2.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/phono3py-pytest-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
Expand Down
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
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

## Nov-13-2024: Version 3.7.0

- Update to follow the change of phonopy's internal functions

## Nov-3-2024: Version 3.6.0

- Maintenance release.
Expand Down
6 changes: 3 additions & 3 deletions doc/command-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ When using `phono3py-load` (see also {ref}`phono3py_load_command`)
This specifies input unit cell filename.

```bash
% phono3py -c POSCAR-unitcell ... (options)
% phono3py -c POSCAR-unitcell [OPTIONS]
```

## Calculator interface
Expand Down Expand Up @@ -193,7 +193,7 @@ created from `FORCES_FC2` and `phono3py_disp.yaml` instead of `FORCES_FC3` and
`phono3py_disp.yaml`.

```bash
% phono3py --cfs --dim-fc2="x x x"
% phono3py --cfs --dim-fc2 4 4 4
```

(sp_option)=
Expand Down Expand Up @@ -283,7 +283,7 @@ order force constants with larger supercell size. The filename is the same as
that created in the usual phono3py run without `--dim-fc2` option.

```bash
% phono3py --dim="2 2 2" --dim_fc2="4 4 4" -c POSCAR-unitcell ... (many options)
% phono3py --dim 2 2 2 --dim_fc2 4 4 4 -c POSCAR-unitcell [OPTIONS]
```

(pa_option)=
Expand Down
4 changes: 2 additions & 2 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@
# built documents.
#
# The short X.Y version.
version = "3.6"
version = "3.7"
# The full version, including alpha/beta/rc tags.
release = "3.6.0"
release = "3.7.0"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
6 changes: 3 additions & 3 deletions doc/cutoff-pair.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

# Force constants calculation with cutoff pair-distance
```{note}
Since usage of this calculation is complicated. It is recommended to try
{ref}`random-displacements` with `--fc-calc-opt "cutoff = VAL"` before trying
this option.
To reduce the computational demands of force constants or lattice thermal
conductivity calculations, it is recommended to try {ref}`pypolymlp-interface`
instead of using the `--cutoff-pair` option.
```

Here the detail of the command option {ref}`--cutoff-pair <cutoff_pair_option>`
Expand Down
39 changes: 27 additions & 12 deletions doc/pypolymlp.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ in the distribution from GitHub or PyPI.
conda-forge (recommended). Otherwise, pypolymlp can be installed from
source-code.

- [symfc](https://github.com/symfc/symfc)

Installed via pip, conda-forge, or source code.

## How to calculate

### Workflow
Expand Down Expand Up @@ -357,14 +353,6 @@ an additional 200 supercells. In total, 400 supercells are created. The forces
for these supercells are then evaluated. Finally, the force constants are
calculated using symfc.

## Convergence with respect to dataset size

In general, increasing the amount of data improves the accuracy of representing
force constants. Therefore, it is recommended to check the convergence of the
target property with respect to the number of supercells in the training
dataset. Lattice thermal conductivity may be a convenient property to monitor
when assessing convergence.

## Parameters for developing MLPs

A few parameters can be specified using the `--mlp-params` option for the
Expand Down Expand Up @@ -401,3 +389,30 @@ For parameter adjustments, it is recommended to consult the
This method provides a straightforward dataset split: the first `ntrain`
supercells from the list are used for training, while the last `ntest`
supercells are reserved for testing.

## Convergence with respect to dataset size

In general, increasing the amount of data improves the accuracy of representing
force constants. Therefore, it is recommended to check the convergence of the
target property with respect to the number of supercells in the training
dataset. Lattice thermal conductivity may be a convenient property to monitor
when assessing convergence.

For example, by preparing an initial set with 100 supercell data, calculations
can then be performed by varying the size of the training dataset while keeping
the test dataset unchanged as follows:

```bash
% phono3py-load --pypolymlp --mlp-params="ntrain=20, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-20
% phono3py-load --pypolymlp --mlp-params="ntrain=40, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-40
% phono3py-load --pypolymlp --mlp-params="ntrain=60, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-60
% phono3py-load --pypolymlp --mlp-params="ntrain=80, ntest=20" --br --mesh 40 phono3py_params.yaml | tee log-80
```

The computed lattice thermal conductivities (LTCs) are plotted against the size
of the training dataset to observe LTC convergence. If the LTC has not
converged, an additional set of supercell data (e.g., forces and energies in
the next 100 supercells) will be computed and included. With this procedure in
mind, it may be convenient to generate a sufficiently large number of supercells
with random displacements in advance, such as 1000 supercells, before starting
the LTC calculation with pypolymlp.
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
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.6.0"
__version__ = "3.7.0"
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 ad909a3

Please sign in to comment.