mirror of https://github.com/phonopy/phono3py.git
Enabled cutoff-pair-distance with comapct fc
This commit is contained in:
parent
225e2f14b6
commit
7e8e4b7a03
|
@ -78,7 +78,7 @@ def load(
|
|||
store_dense_svecs=True,
|
||||
symprec=1e-5,
|
||||
log_level=0,
|
||||
):
|
||||
) -> Phono3py:
|
||||
"""Create Phono3py instance from parameters and/or input files.
|
||||
|
||||
"phono3py_yaml"-like file is parsed unless crystal structure information
|
||||
|
|
|
@ -84,7 +84,7 @@ def get_fc3(
|
|||
disp_dataset,
|
||||
fc2,
|
||||
symmetry,
|
||||
is_compact_fc=is_compact_fc,
|
||||
is_compact_fc=(is_compact_fc and "cutoff_distance" not in disp_dataset),
|
||||
verbose=verbose,
|
||||
)
|
||||
if verbose:
|
||||
|
@ -95,7 +95,7 @@ def get_fc3(
|
|||
lattice = supercell.cell.T
|
||||
permutations = symmetry.atomic_permutations
|
||||
|
||||
if is_compact_fc:
|
||||
if is_compact_fc and "cutoff_distance" not in disp_dataset:
|
||||
s2p_map = primitive.s2p_map
|
||||
p2s_map = primitive.p2s_map
|
||||
p2p_map = primitive.p2p_map
|
||||
|
@ -124,9 +124,6 @@ def get_fc3(
|
|||
"Cutting-off fc3 (cut-off distance: %f)"
|
||||
% disp_dataset["cutoff_distance"]
|
||||
)
|
||||
if is_compact_fc:
|
||||
print("cutoff_fc3 doesn't support compact-fc3 yet.")
|
||||
raise ValueError
|
||||
_cutoff_fc3_for_cutoff_pairs(
|
||||
fc3, supercell, disp_dataset, symmetry, verbose=verbose
|
||||
)
|
||||
|
@ -134,6 +131,11 @@ def get_fc3(
|
|||
if is_compact_fc:
|
||||
p2s_map = primitive.p2s_map
|
||||
fc2 = np.array(fc2[p2s_map], dtype="double", order="C")
|
||||
if "cutoff_distance" in disp_dataset:
|
||||
fc3_shape = (len(p2s_map), fc3.shape[1], fc3.shape[2])
|
||||
fc3_cfc = np.zeros(fc3_shape, dtype="double", order="C")
|
||||
fc3_cfc = fc3[p2s_map]
|
||||
fc3 = fc3_cfc
|
||||
|
||||
return fc2, fc3
|
||||
|
||||
|
@ -278,7 +280,7 @@ def set_translational_invariance_fc3(fc3):
|
|||
_set_translational_invariance_fc3_per_index(fc3, index=i)
|
||||
|
||||
|
||||
def set_translational_invariance_compact_fc3(fc3, primitive):
|
||||
def set_translational_invariance_compact_fc3(fc3, primitive: Primitive):
|
||||
"""Enforce translational symmetry to compact fc3."""
|
||||
try:
|
||||
import phono3py._phono3py as phono3c
|
||||
|
|
|
@ -227,7 +227,7 @@ def nacl_pbe_compact_fc(request):
|
|||
|
||||
@pytest.fixture(scope="session")
|
||||
def nacl_pbe_cutoff_fc3(request):
|
||||
"""Return Phono3py instance of NaCl 2x2x2.
|
||||
"""Return Phono3py instance of NaCl 2x2x2 with cutoff-pair-distance.
|
||||
|
||||
* cutoff pair with 5
|
||||
|
||||
|
@ -253,7 +253,57 @@ def nacl_pbe_cutoff_fc3(request):
|
|||
second_atoms["forces"] = forces[count]
|
||||
count += 1
|
||||
ph3.dataset = dataset
|
||||
ph3.produce_fc3(symmetrize_fc3r=True)
|
||||
ph3.produce_fc3()
|
||||
# ph3.produce_fc3(symmetrize_fc3r=True)
|
||||
return ph3
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def nacl_pbe_cutoff_fc3_all_forces(request):
|
||||
"""Return Phono3py instance of NaCl 2x2x2 with cutoff-pair-distance.
|
||||
|
||||
* cutoff pair with 5
|
||||
* All forces are set.
|
||||
|
||||
"""
|
||||
yaml_filename = os.path.join(current_dir, "phono3py_params_NaCl222.yaml.xz")
|
||||
enable_v2 = request.config.getoption("--v1")
|
||||
ph3 = phono3py.load(
|
||||
yaml_filename,
|
||||
store_dense_gp_map=enable_v2,
|
||||
store_dense_svecs=enable_v2,
|
||||
produce_fc=False,
|
||||
log_level=1,
|
||||
)
|
||||
forces = ph3.forces
|
||||
ph3.generate_displacements(cutoff_pair_distance=5)
|
||||
ph3.forces = forces
|
||||
ph3.produce_fc3()
|
||||
return ph3
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def nacl_pbe_cutoff_fc3_compact_fc(request):
|
||||
"""Return Phono3py instance of NaCl 2x2x2 with cutoff-pair-distance.
|
||||
|
||||
* cutoff pair with 5
|
||||
* All forces are set.
|
||||
* Compact FC
|
||||
|
||||
"""
|
||||
yaml_filename = os.path.join(current_dir, "phono3py_params_NaCl222.yaml.xz")
|
||||
enable_v2 = request.config.getoption("--v1")
|
||||
ph3 = phono3py.load(
|
||||
yaml_filename,
|
||||
store_dense_gp_map=enable_v2,
|
||||
store_dense_svecs=enable_v2,
|
||||
produce_fc=False,
|
||||
log_level=1,
|
||||
)
|
||||
forces = ph3.forces
|
||||
ph3.generate_displacements(cutoff_pair_distance=5)
|
||||
ph3.forces = forces
|
||||
ph3.produce_fc3(is_compact_fc=True)
|
||||
return ph3
|
||||
|
||||
|
||||
|
|
|
@ -1,18 +1,55 @@
|
|||
"""Tests for fc3."""
|
||||
import numpy as np
|
||||
|
||||
from phono3py import Phono3py
|
||||
from phono3py.phonon3.fc3 import cutoff_fc3_by_zero
|
||||
|
||||
|
||||
def test_cutoff_fc3(nacl_pbe_cutoff_fc3, nacl_pbe):
|
||||
"""Test for cutoff pair option."""
|
||||
def test_cutoff_fc3(nacl_pbe_cutoff_fc3: Phono3py, nacl_pbe: Phono3py):
|
||||
"""Test for cutoff-pair-distance option.
|
||||
|
||||
Only supercell forces that satisfy specified cutoff pairs are set in
|
||||
dataset preparation.
|
||||
|
||||
"""
|
||||
fc3_cut = nacl_pbe_cutoff_fc3.fc3
|
||||
fc3 = nacl_pbe.fc3
|
||||
abs_delta = np.abs(fc3_cut - fc3).sum()
|
||||
assert np.abs(1894.2058837 - abs_delta) < 1e-3
|
||||
|
||||
assert fc3.shape == (64, 64, 64, 3, 3, 3)
|
||||
assert np.abs(1901.0248613 - abs_delta) < 1e-3
|
||||
|
||||
|
||||
def test_cutoff_fc3_zero(nacl_pbe):
|
||||
def test_cutoff_fc3_all_forces(
|
||||
nacl_pbe_cutoff_fc3: Phono3py, nacl_pbe_cutoff_fc3_all_forces: Phono3py
|
||||
):
|
||||
"""Test for cutoff-pair-distance option with all forces are set.
|
||||
|
||||
By definition, displacement datasets are kept unchanged when
|
||||
cutoff-pair-distance is specified.
|
||||
|
||||
This test checkes only supercell forces that satisfy specified cutoff pairs
|
||||
are chosen properly.
|
||||
|
||||
"""
|
||||
fc3_cut = nacl_pbe_cutoff_fc3.fc3
|
||||
fc3_cut_all_forces = nacl_pbe_cutoff_fc3_all_forces.fc3
|
||||
np.testing.assert_allclose(fc3_cut, fc3_cut_all_forces, atol=1e-8)
|
||||
|
||||
|
||||
def test_cutoff_fc3_compact_fc(
|
||||
nacl_pbe_cutoff_fc3_compact_fc: Phono3py, nacl_pbe_cutoff_fc3: Phono3py
|
||||
):
|
||||
"""Test for cutoff-pair-distance option with compact-fc."""
|
||||
fc3_cfc = nacl_pbe_cutoff_fc3_compact_fc.fc3
|
||||
fc3_full = nacl_pbe_cutoff_fc3.fc3
|
||||
p2s_map = nacl_pbe_cutoff_fc3.primitive.p2s_map
|
||||
assert fc3_cfc.shape == (2, 64, 64, 3, 3, 3)
|
||||
assert fc3_full.shape == (64, 64, 64, 3, 3, 3)
|
||||
np.testing.assert_allclose(fc3_cfc, fc3_full[p2s_map], atol=1e-8)
|
||||
|
||||
|
||||
def test_cutoff_fc3_zero(nacl_pbe: Phono3py):
|
||||
"""Test for abrupt cut of fc3 by distance."""
|
||||
ph = nacl_pbe
|
||||
fc3 = ph.fc3.copy()
|
||||
|
@ -21,7 +58,7 @@ def test_cutoff_fc3_zero(nacl_pbe):
|
|||
assert np.abs(5259.2234163 - abs_delta) < 1e-3
|
||||
|
||||
|
||||
def test_cutoff_fc3_zero_compact_fc(nacl_pbe_compact_fc):
|
||||
def test_cutoff_fc3_zero_compact_fc(nacl_pbe_compact_fc: Phono3py):
|
||||
"""Test for abrupt cut of fc3 by distance."""
|
||||
ph = nacl_pbe_compact_fc
|
||||
fc3 = ph.fc3.copy()
|
||||
|
@ -30,7 +67,7 @@ def test_cutoff_fc3_zero_compact_fc(nacl_pbe_compact_fc):
|
|||
assert np.abs(164.359250 - abs_delta) < 1e-3
|
||||
|
||||
|
||||
def test_fc3(si_pbesol_111):
|
||||
def test_fc3(si_pbesol_111: Phono3py):
|
||||
"""Test fc3 with Si PBEsol 1x1x1."""
|
||||
ph = si_pbesol_111
|
||||
fc3_ref = [
|
||||
|
@ -54,7 +91,7 @@ def test_fc3(si_pbesol_111):
|
|||
|
||||
|
||||
# @pytest.mark.skipif(not FC_CALCULATOR_ALM_AVAILABLE, reason="not found ALM package")
|
||||
def test_fc3_alm(si_pbesol_111_alm):
|
||||
def test_fc3_alm(si_pbesol_111_alm: Phono3py):
|
||||
"""Test fc3 with Si PBEsol 1x1x1 calcualted using ALM."""
|
||||
ph = si_pbesol_111_alm
|
||||
fc3_ref = [
|
||||
|
|
Loading…
Reference in New Issue