Added tests of smallest vectors and cutoff fc3

This commit is contained in:
Atsushi Togo 2021-07-09 23:08:34 +09:00
parent 35ac91ee6a
commit 7e0ce3a603
3 changed files with 78 additions and 0 deletions

View File

@ -75,6 +75,27 @@ def nacl_pbe():
return phono3py.load(yaml_filename, log_level=1)
@pytest.fixture(scope='session')
def nacl_pbe_cutoff_fc3():
yaml_filename = os.path.join(current_dir,
"phono3py_params_NaCl222.yaml.xz")
ph3 = phono3py.load(yaml_filename, log_level=1)
forces = ph3.forces
ph3.generate_displacements(cutoff_pair_distance=5)
dataset = ph3.dataset
dataset['first_atoms'][0]['forces'] = forces[0]
dataset['first_atoms'][1]['forces'] = forces[0]
count = 2
for first_atoms in dataset['first_atoms']:
for second_atoms in first_atoms['second_atoms']:
assert second_atoms['id'] == count + 1
second_atoms['forces'] = forces[count]
count += 1
ph3.dataset = dataset
ph3.produce_fc3(symmetrize_fc3r=True)
return ph3
@pytest.fixture(scope='session')
def aln_lda():
yaml_filename = os.path.join(current_dir,

View File

@ -1,5 +1,22 @@
import phono3py
import numpy as np
from phono3py.phonon3.displacement_fc3 import get_equivalent_smallest_vectors
distances_NaCl = [
0.0000000, 5.6903015, 5.6903015, 8.0473015, 5.6903015,
8.0473015, 8.0473015, 9.8558913, 4.0236508, 6.9691675,
4.0236508, 6.9691675, 4.0236508, 6.9691675, 4.0236508,
6.9691675, 4.0236508, 4.0236508, 6.9691675, 6.9691675,
4.0236508, 4.0236508, 6.9691675, 6.9691675, 4.0236508,
4.0236508, 4.0236508, 4.0236508, 6.9691675, 6.9691675,
6.9691675, 6.9691675, 4.9279456, 4.9279456, 4.9279456,
4.9279456, 4.9279456, 4.9279456, 4.9279456, 4.9279456,
2.8451507, 2.8451507, 6.3619505, 6.3619505, 6.3619505,
6.3619505, 8.5354522, 8.5354522, 2.8451507, 6.3619505,
2.8451507, 6.3619505, 6.3619505, 8.5354522, 6.3619505,
8.5354522, 2.8451507, 6.3619505, 6.3619505, 8.5354522,
2.8451507, 6.3619505, 6.3619505, 8.5354522]
def test_agno2(agno2_cell):
@ -39,3 +56,26 @@ def test_nacl_pbe(nacl_pbe):
# print("".join(["%d, " % i for i in np.array(pairs).ravel()]))
np.testing.assert_equal(pairs_ref, np.array(pairs).ravel())
def test_get_equivalent_smallest_vectors(nacl_pbe):
ph = nacl_pbe
distances = []
for i in range(len(ph.supercell)):
vec = get_equivalent_smallest_vectors(
i, 0, ph.supercell, 1e-5)
if vec.ndim == 2:
vec = vec[0]
distances.append(np.linalg.norm(np.dot(vec, ph.supercell.cell)))
# _show(distances)
np.testing.assert_allclose(distances_NaCl, distances, rtol=0, atol=1e-6)
def _show(vals):
for i, v in enumerate(vals):
print("%.7f, " % v, end="")
if (i + 1) % 5 == 0:
print("")

17
test/phonon3/test_fc3.py Normal file
View File

@ -0,0 +1,17 @@
import numpy as np
from phono3py.phonon3.fc3 import cutoff_fc3_by_zero
def test_cutoff_fc3(nacl_pbe_cutoff_fc3, nacl_pbe):
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
def test_cutoff_fc3_zero(nacl_pbe):
ph = nacl_pbe
fc3 = ph.fc3.copy()
cutoff_fc3_by_zero(fc3, ph.supercell, 5)
abs_delta = np.abs(ph.fc3 - fc3).sum()
assert np.abs(5259.2234163 - abs_delta) < 1e-3