diff --git a/.github/workflows/phono3py-pytest-conda-mkl-v2.yml b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml new file mode 100644 index 00000000..77e87e6f --- /dev/null +++ b/.github/workflows/phono3py-pytest-conda-mkl-v2.yml @@ -0,0 +1,51 @@ +name: Pytest with mkl and --v2 option + +on: + pull_request: + branches: [ develop ] + push: + branches-ignore: + - publish-gh-pages + - master + - rc + +jobs: + build-linux: + runs-on: ubuntu-latest + defaults: + run: + shell: bash -l {0} + strategy: + matrix: + python-version: ["3.11"] + + steps: + - uses: actions/checkout@v3 + # Use conda-incubator/setup-miniconda for precise control of conda infrastructure + - uses: conda-incubator/setup-miniconda@v2 + with: + miniforge-version: latest + - name: Install dependent packages + run: | + conda activate test + conda install --yes python=${{ matrix.python-version }} + #conda install --yes matplotlib-base pyyaml "libblas=*=*openblas" openblas h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler + - name: Install phonopy develop branch + run: | + conda activate test + git clone --depth 1 https://github.com/phonopy/phonopy.git + cd phonopy + pip install -e . -vvv + cd .. + - name: Install phono3py + run: | + conda activate test + pip install -e . -vvv + - name: Run pytest + run: | + pytest --v2 -v --cov=./ --cov-report=xml test + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + verbose: true diff --git a/test/phonon3/test_imag_self_energy.py b/test/phonon3/test_imag_self_energy.py index bb23a3e1..edae5771 100644 --- a/test/phonon3/test_imag_self_energy.py +++ b/test/phonon3/test_imag_self_energy.py @@ -1879,7 +1879,7 @@ def test_imag_self_energy_nacl_nac_npoints(nacl_pbe: Phono3py): [nacl_pbe.grid.gp_Gamma], [300], num_frequency_points=10 ) - print(",".join([f"{val:.8f}" for val in gammas.ravel()])) + # print(",".join([f"{val:.8f}" for val in gammas.ravel()])) np.testing.assert_allclose( ref_freq_points_nacl_nac, fpoints.ravel(), rtol=0, atol=1e-5 diff --git a/test/phonon3/test_interaction.py b/test/phonon3/test_interaction.py index 3ea907ac..06da2b3b 100644 --- a/test/phonon3/test_interaction.py +++ b/test/phonon3/test_interaction.py @@ -11,187 +11,191 @@ from phono3py import Phono3py from phono3py.phonon3.interaction import Interaction -itr_RTA_Si = [ - 4.522052e-08, - 4.896362e-08, - 4.614211e-08, - 4.744361e-08, - 4.832248e-08, - 4.698535e-08, - 4.597876e-08, - 4.645423e-08, - 4.659572e-08, - 4.730222e-08, -] - -itr_RTA_AlN = [ - 7.456796e-08, - 7.242121e-08, - 7.068141e-08, - 7.059521e-08, - 7.289497e-08, - 7.127172e-08, - 7.082734e-08, - 7.394367e-08, - 7.084351e-08, - 7.083299e-08, - 7.085792e-08, - 7.124150e-08, - 7.048386e-08, - 7.062840e-08, - 7.036795e-08, - 7.043995e-08, - 7.366440e-08, - 7.136803e-08, - 6.988469e-08, - 6.989518e-08, - 7.179516e-08, - 7.038043e-08, - 7.011416e-08, - 7.278196e-08, - 6.999028e-08, - 7.009615e-08, - 7.018236e-08, - 7.025054e-08, - 6.977425e-08, - 6.993095e-08, - 6.962119e-08, - 6.964423e-08, - 7.121739e-08, - 6.939940e-08, - 6.834705e-08, - 6.847351e-08, - 6.977063e-08, - 6.872065e-08, - 6.863218e-08, - 7.055696e-08, - 6.836064e-08, - 6.854052e-08, - 6.864199e-08, - 6.849059e-08, - 6.826958e-08, - 6.837379e-08, - 6.808307e-08, - 6.804480e-08, - 6.961289e-08, - 6.816170e-08, - 6.730028e-08, - 6.746055e-08, - 6.851460e-08, - 6.764892e-08, - 6.754060e-08, - 6.913662e-08, - 6.729303e-08, - 6.736722e-08, - 6.734663e-08, - 6.743441e-08, - 6.713107e-08, - 6.710084e-08, - 6.698233e-08, - 6.694871e-08, -] - -itr_RTA_AlN_r0_ave = [ - 7.451662e-08, - 7.248965e-08, - 7.068341e-08, - 7.038257e-08, - 7.291756e-08, - 7.130737e-08, - 7.073777e-08, - 7.391677e-08, - 7.086006e-08, - 7.077947e-08, - 7.084617e-08, - 7.128499e-08, - 7.036749e-08, - 7.057057e-08, - 7.032233e-08, - 7.041152e-08, - 7.366076e-08, - 7.149180e-08, - 6.992398e-08, - 6.972641e-08, - 7.187472e-08, - 7.046525e-08, - 7.006265e-08, - 7.280888e-08, - 7.005107e-08, - 7.008412e-08, - 7.019342e-08, - 7.034898e-08, - 6.969589e-08, - 6.990595e-08, - 6.961230e-08, - 6.966506e-08, - 7.121203e-08, - 6.954065e-08, - 6.839930e-08, - 6.831861e-08, - 6.986872e-08, - 6.882433e-08, - 6.859035e-08, - 7.059587e-08, - 6.844120e-08, - 6.854220e-08, - 6.865246e-08, - 6.861039e-08, - 6.819986e-08, - 6.835737e-08, - 6.808818e-08, - 6.808952e-08, - 6.954409e-08, - 6.824539e-08, - 6.732596e-08, - 6.726087e-08, - 6.854755e-08, - 6.770693e-08, - 6.745257e-08, - 6.910600e-08, - 6.733516e-08, - 6.731725e-08, - 6.731323e-08, - 6.749548e-08, - 6.700802e-08, - 6.703569e-08, - 6.694826e-08, - 6.694365e-08, -] - @pytest.mark.parametrize("lang", ["C", "Python"]) def test_interaction_RTA_si(si_pbesol: Phono3py, lang: Literal["C", "Python"]): """Test interaction_strength of Si.""" + if si_pbesol._make_r0_average: + ref_itr_RTA_Si = [ + 4.522052e-08, + 4.896362e-08, + 4.614211e-08, + 4.744361e-08, + 4.832248e-08, + 4.698535e-08, + 4.597876e-08, + 4.645423e-08, + 4.659572e-08, + 4.730222e-08, + ] + else: + ref_itr_RTA_Si = [ + 4.522052e-08, + 4.896362e-08, + 4.614211e-08, + 4.744361e-08, + 4.832248e-08, + 4.698535e-08, + 4.597876e-08, + 4.645423e-08, + 4.659572e-08, + 4.730222e-08, + ] + itr = _get_irt(si_pbesol, [4, 4, 4]) itr.set_grid_point(1) itr.run(lang=lang) # _show(itr) # (10, 6, 6, 6) np.testing.assert_allclose( - itr.interaction_strength.sum(axis=(1, 2, 3)), itr_RTA_Si, rtol=0, atol=1e-10 + itr.interaction_strength.sum(axis=(1, 2, 3)), ref_itr_RTA_Si, rtol=0, atol=1e-10 ) def test_interaction_RTA_AlN(aln_lda: Phono3py): """Test interaction_strength of AlN.""" - itr = _get_irt(aln_lda, [7, 7, 7]) - itr.set_grid_point(1) - itr.run() - # _show(itr) - np.testing.assert_allclose( - itr.interaction_strength.sum(axis=(1, 2, 3)), itr_RTA_AlN, rtol=0, atol=1e-10 - ) - + if aln_lda._make_r0_average: + ref_itr_RTA_AlN = [ + 7.456796e-08, + 7.242121e-08, + 7.068141e-08, + 7.059521e-08, + 7.289497e-08, + 7.127172e-08, + 7.082734e-08, + 7.394367e-08, + 7.084351e-08, + 7.083299e-08, + 7.085792e-08, + 7.124150e-08, + 7.048386e-08, + 7.062840e-08, + 7.036795e-08, + 7.043995e-08, + 7.366440e-08, + 7.136803e-08, + 6.988469e-08, + 6.989518e-08, + 7.179516e-08, + 7.038043e-08, + 7.011416e-08, + 7.278196e-08, + 6.999028e-08, + 7.009615e-08, + 7.018236e-08, + 7.025054e-08, + 6.977425e-08, + 6.993095e-08, + 6.962119e-08, + 6.964423e-08, + 7.121739e-08, + 6.939940e-08, + 6.834705e-08, + 6.847351e-08, + 6.977063e-08, + 6.872065e-08, + 6.863218e-08, + 7.055696e-08, + 6.836064e-08, + 6.854052e-08, + 6.864199e-08, + 6.849059e-08, + 6.826958e-08, + 6.837379e-08, + 6.808307e-08, + 6.804480e-08, + 6.961289e-08, + 6.816170e-08, + 6.730028e-08, + 6.746055e-08, + 6.851460e-08, + 6.764892e-08, + 6.754060e-08, + 6.913662e-08, + 6.729303e-08, + 6.736722e-08, + 6.734663e-08, + 6.743441e-08, + 6.713107e-08, + 6.710084e-08, + 6.698233e-08, + 6.694871e-08, + ] + else: + ref_itr_RTA_AlN = [ + 7.456796e-08, + 7.242121e-08, + 7.068141e-08, + 7.059521e-08, + 7.289497e-08, + 7.127172e-08, + 7.082734e-08, + 7.394367e-08, + 7.084351e-08, + 7.083299e-08, + 7.085792e-08, + 7.124150e-08, + 7.048386e-08, + 7.062840e-08, + 7.036795e-08, + 7.043995e-08, + 7.366440e-08, + 7.136803e-08, + 6.988469e-08, + 6.989518e-08, + 7.179516e-08, + 7.038043e-08, + 7.011416e-08, + 7.278196e-08, + 6.999028e-08, + 7.009615e-08, + 7.018236e-08, + 7.025054e-08, + 6.977425e-08, + 6.993095e-08, + 6.962119e-08, + 6.964423e-08, + 7.121739e-08, + 6.939940e-08, + 6.834705e-08, + 6.847351e-08, + 6.977063e-08, + 6.872065e-08, + 6.863218e-08, + 7.055696e-08, + 6.836064e-08, + 6.854052e-08, + 6.864199e-08, + 6.849059e-08, + 6.826958e-08, + 6.837379e-08, + 6.808307e-08, + 6.804480e-08, + 6.961289e-08, + 6.816170e-08, + 6.730028e-08, + 6.746055e-08, + 6.851460e-08, + 6.764892e-08, + 6.754060e-08, + 6.913662e-08, + 6.729303e-08, + 6.736722e-08, + 6.734663e-08, + 6.743441e-08, + 6.713107e-08, + 6.710084e-08, + 6.698233e-08, + 6.694871e-08, + ] -def test_interaction_RTA_AlN_r0_ave(aln_lda: Phono3py): - """Test interaction_strength of AlN.""" - itr = _get_irt(aln_lda, [7, 7, 7], make_r0_average=True) + itr = _get_irt(aln_lda, [7, 7, 7]) itr.set_grid_point(1) itr.run() - # _show(itr) + _show(itr) np.testing.assert_allclose( itr.interaction_strength.sum(axis=(1, 2, 3)), - itr_RTA_AlN_r0_ave, + ref_itr_RTA_AlN, rtol=0, atol=1e-10, ) diff --git a/test/phonon3/test_real_self_energy.py b/test/phonon3/test_real_self_energy.py index b3c2c3fb..c51c37d9 100644 --- a/test/phonon3/test_real_self_energy.py +++ b/test/phonon3/test_real_self_energy.py @@ -4,252 +4,51 @@ from phono3py import Phono3py from phono3py.phonon3.real_self_energy import ImagToReal -si_pbesol_Delta = [ - [-0.0057666, -0.0057666, -0.01639729, -0.14809965, -0.15091765, -0.15091765], - [-0.02078728, -0.02102094, -0.06573269, -0.11432603, -0.1366966, -0.14371315], -] -si_pbesol_Delta_fps = [ - [ - -0.00576660, - -0.00594616, - -0.00840087, - -0.00960344, - -0.00576660, - -0.00594616, - -0.00840087, - -0.00960344, - -0.01493508, - -0.01639729, - -0.01997820, - -0.02070427, - -0.15511645, - -0.14747203, - -0.14809966, - -0.14230763, - -0.15674925, - -0.15684992, - -0.15983868, - -0.15091767, - -0.15674925, - -0.15684992, - -0.15983868, - -0.15091767, - ], - [ - -0.01990306, - -0.02077094, - -0.01798066, - -0.01935581, - -0.02158076, - -0.02190634, - -0.02195633, - -0.01882258, - -0.05740055, - -0.05240406, - -0.06252644, - -0.05651015, - -0.13072273, - -0.11929265, - -0.13472599, - -0.13105120, - -0.15191900, - -0.14202698, - -0.14371246, - -0.14168892, - -0.14760248, - -0.13907618, - -0.14275290, - -0.14100562, - ], -] - -# imag-self-energy Si-PBEsol 50x50x50 gp=5, bi=4, 101 points, 300K -im_part = [ - [0.0000000, 0.0000000, -0.0000000, -0.1750223, 0.1534611, -0.1794583], - [0.3069222, 0.0180686, 0.3069222, -0.1692049, 0.4603833, -0.1636592], - [0.6138444, 0.0158916, 0.6138444, -0.1621245, 0.7673055, -0.1625514], - [0.9207667, 0.0238034, 0.9207667, -0.1556618, 1.0742278, -0.1484696], - [1.2276889, 0.0131519, 1.2276889, -0.1515719, 1.3811500, -0.1525501], - [1.5346111, 0.0124129, 1.5346111, -0.1541357, 1.6880722, -0.1566124], - [1.8415333, 0.0165506, 1.8415333, -0.1556995, 1.9949944, -0.1567434], - [2.1484555, 0.0196960, 2.1484555, -0.1556492, 2.3019166, -0.1563791], - [2.4553778, 0.0225276, 2.4553778, -0.1553117, 2.6088389, -0.1562531], - [2.7623000, 0.0269193, 2.7623000, -0.1536529, 2.9157611, -0.1520174], - [3.0692222, 0.0247502, 3.0692222, -0.1530976, 3.2226833, -0.1545476], - [3.3761444, 0.0253261, 3.3761444, -0.1565178, 3.5296055, -0.1617560], - [3.6830666, 0.0360216, 3.6830666, -0.1586552, 3.8365277, -0.1618262], - [3.9899888, 0.0510642, 3.9899888, -0.1523272, 4.1434499, -0.1463620], - [4.2969111, 0.0494221, 4.2969111, -0.1428688, 4.4503722, -0.1388442], - [4.6038333, 0.0474328, 4.6038333, -0.1361604, 4.7572944, -0.1307086], - [4.9107555, 0.0370451, 4.9107555, -0.1345154, 5.0642166, -0.1359581], - [5.2176777, 0.0375397, 5.2176777, -0.1361887, 5.3711388, -0.1356714], - [5.5245999, 0.0345936, 5.5245999, -0.1377925, 5.6780610, -0.1390885], - [5.8315222, 0.0327132, 5.8315222, -0.1425343, 5.9849833, -0.1472336], - [6.1384444, 0.0374592, 6.1384444, -0.1489307, 6.2919055, -0.1562694], - [6.4453666, 0.0555985, 6.4453666, -0.1481088, 6.5988277, -0.1452657], - [6.7522888, 0.0586765, 6.7522888, -0.1409779, 6.9057499, -0.1375563], - [7.0592110, 0.0560470, 7.0592110, -0.1371741, 7.2126721, -0.1365273], - [7.3661333, 0.0550400, 7.3661333, -0.1372613, 7.5195944, -0.1387434], - [7.6730555, 0.0565263, 7.6730555, -0.1399341, 7.8265166, -0.1440837], - [7.9799777, 0.0624044, 7.9799777, -0.1457614, 8.1334388, -0.1582010], - [8.2868999, 0.1009214, 8.2868999, -0.1369623, 8.4403610, -0.1261905], - [8.5938221, 0.1090238, 8.5938221, -0.1087372, 8.7472832, -0.0870371], - [8.9007444, 0.0807253, 8.9007444, -0.0903838, 9.0542055, -0.0835210], - [9.2076666, 0.0658383, 9.2076666, -0.0875470, 9.3611277, -0.0853012], - [9.5145888, 0.0592222, 9.5145888, -0.0867791, 9.6680499, -0.0838069], - [9.8215110, 0.0521071, 9.8215110, -0.0853895, 9.9749721, -0.0820186], - [10.1284332, 0.0419588, 10.1284332, -0.0862870, 10.2818943, -0.0860513], - [10.4353554, 0.0364097, 10.4353554, -0.0892629, 10.5888165, -0.0892228], - [10.7422777, 0.0316193, 10.7422777, -0.0922975, 10.8957388, -0.0926032], - [11.0491999, 0.0274798, 11.0491999, -0.0955924, 11.2026610, -0.0960711], - [11.3561221, 0.0233126, 11.3561221, -0.0994131, 11.5095832, -0.1004271], - [11.6630443, 0.0193464, 11.6630443, -0.1043388, 11.8165054, -0.1065527], - [11.9699665, 0.0174292, 11.9699665, -0.1099907, 12.1234276, -0.1125414], - [12.2768888, 0.0164239, 12.2768888, -0.1157951, 12.4303499, -0.1188108], - [12.5838110, 0.0165308, 12.5838110, -0.1218120, 12.7372721, -0.1253937], - [12.8907332, 0.0184723, 12.8907332, -0.1275275, 13.0441943, -0.1309579], - [13.1976554, 0.0211215, 13.1976554, -0.1325454, 13.3511165, -0.1358727], - [13.5045776, 0.0244407, 13.5045776, -0.1369047, 13.6580387, -0.1400194], - [13.8114999, 0.0282908, 13.8114999, -0.1404205, 13.9649610, -0.1429165], - [14.1184221, 0.0313175, 14.1184221, -0.1435582, 14.2718832, -0.1462968], - [14.4253443, 0.0348581, 14.4253443, -0.1467576, 14.5788054, -0.1495649], - [14.7322665, 0.0386150, 14.7322665, -0.1500845, 14.8857276, -0.1533339], - [15.0391887, 0.0424503, 15.0391887, -0.1550110, 15.1926498, -0.1625259], - [15.3461109, 0.0605747, 15.3461109, -0.1550584, 15.4995720, -0.1547951], - [15.6530332, 0.0727408, 15.6530332, -0.1443151, 15.8064943, -0.1346934], - [15.9599554, 0.0625829, 15.9599554, -0.1346277, 16.1134165, -0.1305515], - [16.2668776, 0.0547742, 16.2668776, -0.1324223, 16.4203387, -0.1301107], - [16.5737998, 0.0459500, 16.5737998, -0.1348752, 16.7272609, -0.1365713], - [16.8807220, 0.0432888, 16.8807220, -0.1397155, 17.0341831, -0.1410867], - [17.1876443, 0.0398939, 17.1876443, -0.1450244, 17.3411054, -0.1471968], - [17.4945665, 0.0351088, 17.4945665, -0.1540409, 17.6480276, -0.1617873], - [17.8014887, 0.0424833, 17.8014887, -0.1635035, 17.9549498, -0.1699703], - [18.1084109, 0.0556675, 18.1084109, -0.1649880, 18.2618720, -0.1626782], - [18.4153331, 0.0532241, 18.4153331, -0.1631579, 18.5687942, -0.1618524], - [18.7222554, 0.0458460, 18.7222554, -0.1672846, 18.8757165, -0.1709147], - [19.0291776, 0.0443150, 19.0291776, -0.1758322, 19.1826387, -0.1808661], - [19.3360998, 0.0454289, 19.3360998, -0.1853104, 19.4895609, -0.1911626], - [19.6430220, 0.0483353, 19.6430220, -0.1952856, 19.7964831, -0.2019949], - [19.9499442, 0.0534799, 19.9499442, -0.2053378, 20.1034053, -0.2123304], - [20.2568665, 0.0599861, 20.2568665, -0.2151359, 20.4103276, -0.2225551], - [20.5637887, 0.0685856, 20.5637887, -0.2240731, 20.7172498, -0.2305568], - [20.8707109, 0.0755373, 20.8707109, -0.2331629, 21.0241720, -0.2419628], - [21.1776331, 0.0906438, 21.1776331, -0.2384003, 21.3310942, -0.2380604], - [21.4845553, 0.0827018, 21.4845553, -0.2476712, 21.6380164, -0.2593767], - [21.7914775, 0.0907297, 21.7914775, -0.2660044, 21.9449386, -0.2793854], - [22.0983998, 0.1025946, 22.0983998, -0.2859215, 22.2518609, -0.3026711], - [22.4053220, 0.1210133, 22.4053220, -0.3084041, 22.5587831, -0.3297156], - [22.7122442, 0.1517773, 22.7122442, -0.3307280, 22.8657053, -0.3535969], - [23.0191664, 0.1918115, 23.0191664, -0.3505455, 23.1726275, -0.3769971], - [23.3260886, 0.2484881, 23.3260886, -0.3659809, 23.4795497, -0.3980745], - [23.6330109, 0.3449959, 23.6330109, -0.3587633, 23.7864720, -0.3785512], - [23.9399331, 0.4932745, 23.9399331, -0.2683146, 24.0933942, -0.1740930], - [24.2468553, 0.4000672, 24.2468553, -0.1714061, 24.4003164, -0.1388929], - [24.5537775, 0.3476085, 24.5537775, -0.1478397, 24.7072386, -0.1341295], - [24.8606997, 0.3031722, 24.8606997, -0.1588841, 25.0141608, -0.1796324], - [25.1676220, 0.3332258, 25.1676220, -0.1716723, 25.3210831, -0.1741573], - [25.4745442, 0.3514490, 25.4745442, -0.1621265, 25.6280053, -0.1553650], - [25.7814664, 0.3514801, 25.7814664, -0.1503569, 25.9349275, -0.1458311], - [26.0883886, 0.3490583, 26.0883886, -0.1437619, 26.2418497, -0.1387991], - [26.3953108, 0.3346525, 26.3953108, -0.1471754, 26.5487719, -0.1497006], - [26.7022331, 0.3145614, 26.7022331, -0.1719482, 26.8556942, -0.1898755], - [27.0091553, 0.2913173, 27.0091553, -0.2370443, 27.1626164, -0.2939869], - [27.3160775, 0.2707732, 27.3160775, -0.4139632, 27.4695386, -0.6910918], - [27.6229997, 0.9436577, 27.6229997, -0.3688420, 27.7764608, -0.2026185], - [27.9299219, 0.9147269, 27.9299219, -0.1095194, 28.0833830, -0.0365244], - [28.2368441, 0.9515446, 28.2368441, 0.0642006, 28.3903052, 0.1596622], - [28.5437664, 0.9296466, 28.5437664, 0.2357042, 28.6972275, 0.3228099], - [28.8506886, 0.9383991, 28.8506886, 0.4390380, 29.0041497, 0.6142345], - [29.1576108, 0.7465231, 29.1576108, 0.6502426, 29.3110719, 0.8357126], - [29.4645330, 0.3472854, 29.4645330, 0.6927159, 29.6179941, 0.6873352], - [29.7714552, 0.2258269, 29.7714552, 0.6147208, 29.9249163, 0.6117702], - [30.0783775, 0.1397870, 30.0783775, 0.5578788, 30.2318386, 0.5591731], - [30.3852997, 0.0468188, 30.3852997, 0.4941608, 30.5387608, 0.4706733], - [30.6922219, 0.0000000, 30.6922219, 0.4173657, 30.8456830, 0.3821416], -] -delta_nacl_nac = [ - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - 0.00000000, - -0.43835832, - -0.43835832, - -0.27175512, - 0.00000000, - 0.00000000, - 0.00000000, - -0.24732785, - -0.24732785, - -0.15332798, - 0.00000000, - 0.00000000, - 0.00000000, - -0.45125778, - -0.45125778, - -0.27975198, - 0.00000000, - 0.00000000, - 0.00000000, - -0.80781739, - -0.80781739, - -0.50079699, - 0.00000000, - 0.00000000, - 0.00000000, - -0.36217245, - -0.36217245, - -0.22452456, - 0.00000000, - 0.00000000, - 0.00000000, - 0.54848940, - 0.54848940, - 0.34002959, - 0.00000000, - 0.00000000, - 0.00000000, - 0.29335952, - 0.29335952, - 0.18186480, - 0.00000000, - 0.00000000, - 0.00000000, - 0.16329650, - 0.16329650, - 0.10123375, - 0.00000000, - 0.00000000, - 0.00000000, - 0.11208511, - 0.11208511, - 0.06948585, -] -freq_points_nacl_nac = [ - 0.0, - 1.63223063, - 3.26446125, - 4.89669188, - 6.5289225, - 8.16115313, - 9.79338375, - 11.42561438, - 13.057845, - 14.69007563, -] - - -def test_real_self_energy_with_band_indices(si_pbesol): +def test_real_self_energy_with_band_indices(si_pbesol: Phono3py): """Real part of self energy spectrum of Si. * at frequencies of band indices. """ + if si_pbesol._make_r0_average: + ref_Delta = [ + [ + -0.0057326, + -0.0057326, + -0.01633157, + -0.14797815, + -0.15086179, + -0.15086179, + ], + [ + -0.02080177, + -0.02104276, + -0.06575259, + -0.11439863, + -0.13666415, + -0.14372152, + ], + ] + else: + ref_Delta = [ + [ + -0.0057666, + -0.0057666, + -0.01639729, + -0.14809965, + -0.15091765, + -0.15091765, + ], + [ + -0.02078728, + -0.02102094, + -0.06573269, + -0.11432603, + -0.1366966, + -0.14371315, + ], + ] si_pbesol.mesh_numbers = [9, 9, 9] si_pbesol.init_phph_interaction() _, delta = si_pbesol.run_real_self_energy( @@ -260,7 +59,8 @@ def test_real_self_energy_with_band_indices(si_pbesol): write_hdf5=False, frequency_points_at_bands=True, ) - np.testing.assert_allclose(si_pbesol_Delta, delta[0, 0, :], atol=0.01) + # print(delta[0, 0, :]) + np.testing.assert_allclose(ref_Delta, delta[0, 0, :], atol=0.01) def test_real_self_energy_with_frequency_points(si_pbesol: Phono3py): @@ -269,6 +69,117 @@ def test_real_self_energy_with_frequency_points(si_pbesol: Phono3py): * specified frquency points """ + if si_pbesol._make_r0_average: + ref_Delta_fps = [ + [ + -0.00573260, + -0.00589756, + -0.00839449, + -0.00966402, + -0.00573260, + -0.00589756, + -0.00839449, + -0.00966402, + -0.01486569, + -0.01633157, + -0.01993995, + -0.02073417, + -0.15512961, + -0.14758526, + -0.14797816, + -0.14222444, + -0.15683457, + -0.15691468, + -0.15974324, + -0.15086181, + -0.15683457, + -0.15691468, + -0.15974324, + -0.15086181, + ], + [ + -0.01990876, + -0.02077841, + -0.01798683, + -0.01933049, + -0.02158770, + -0.02193100, + -0.02186381, + -0.01877096, + -0.05743552, + -0.05244391, + -0.06241623, + -0.05643933, + -0.13068294, + -0.11925247, + -0.13470590, + -0.13105466, + -0.15192994, + -0.14204618, + -0.14364976, + -0.14173656, + -0.14762541, + -0.13904288, + -0.14284911, + -0.14112034, + ], + ] + else: + ref_Delta_fps = [ + [ + -0.00576660, + -0.00594616, + -0.00840087, + -0.00960344, + -0.00576660, + -0.00594616, + -0.00840087, + -0.00960344, + -0.01493508, + -0.01639729, + -0.01997820, + -0.02070427, + -0.15511645, + -0.14747203, + -0.14809966, + -0.14230763, + -0.15674925, + -0.15684992, + -0.15983868, + -0.15091767, + -0.15674925, + -0.15684992, + -0.15983868, + -0.15091767, + ], + [ + -0.01990306, + -0.02077094, + -0.01798066, + -0.01935581, + -0.02158076, + -0.02190634, + -0.02195633, + -0.01882258, + -0.05740055, + -0.05240406, + -0.06252644, + -0.05651015, + -0.13072273, + -0.11929265, + -0.13472599, + -0.13105120, + -0.15191900, + -0.14202698, + -0.14371246, + -0.14168892, + -0.14760248, + -0.13907618, + -0.14275290, + -0.14100562, + ], + ] + si_pbesol.mesh_numbers = [9, 9, 9] si_pbesol.init_phph_interaction() frequency_points = [1.469947, 3.085309, 14.997187, 15.129080] @@ -282,18 +193,14 @@ def test_real_self_energy_with_frequency_points(si_pbesol: Phono3py): frequency_points_at_bands=False, ) - np.testing.assert_allclose(frequency_points, fps, atol=1e-5) - np.testing.assert_allclose( - si_pbesol_Delta_fps[0], delta[0, 0, 0].ravel(), atol=0.01 - ) - np.testing.assert_allclose( - si_pbesol_Delta_fps[1], delta[0, 0, 1].ravel(), atol=0.01 - ) - # for b in delta[0, 0, 0]: - # print("".join("%.8f, " % s for s in b)) - # for b in delta[0, 1, 0]: - # print("".join("%.8f, " % s for s in b)) + # print("".join(f"{s:.8f}, " % s for s in b)) + # for b in delta[0, 0, 1]: + # print("".join(f"{s:.8f}, " % s for s in b)) + + np.testing.assert_allclose(frequency_points, fps, atol=1e-5) + np.testing.assert_allclose(ref_Delta_fps[0], delta[0, 0, 0].ravel(), atol=0.01) + np.testing.assert_allclose(ref_Delta_fps[1], delta[0, 0, 1].ravel(), atol=0.01) def test_real_self_energy_nacl_nac_npoints(nacl_pbe: Phono3py): @@ -303,22 +210,290 @@ def test_real_self_energy_nacl_nac_npoints(nacl_pbe: Phono3py): * at q->0 """ + ref_freq_points_nacl_nac = [ + 0.0, + 1.63223063, + 3.26446125, + 4.89669188, + 6.5289225, + 8.16115313, + 9.79338375, + 11.42561438, + 13.057845, + 14.69007563, + ] + + if nacl_pbe._make_r0_average: + ref_delta_nacl_nac = [ + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + -0.43955299, + -0.24659961, + -0.45227602, + -0.80296691, + -0.35433156, + 0.54514663, + 0.29417714, + 0.16346531, + 0.11216578, + ], + [ + 0.00000000, + -0.43955299, + -0.24659961, + -0.45227602, + -0.80296691, + -0.35433156, + 0.54514663, + 0.29417714, + 0.16346531, + 0.11216578, + ], + [ + 0.00000000, + -0.27249573, + -0.15287654, + -0.28038322, + -0.49778992, + -0.21966368, + 0.33795727, + 0.18237167, + 0.10133841, + 0.06953586, + ], + ] + else: + ref_delta_nacl_nac = [ + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + 0.00000000, + ], + [ + 0.00000000, + -0.43835860, + -0.24732790, + -0.45125795, + -0.80781808, + -0.36217377, + 0.54848873, + 0.29335955, + 0.16329652, + 0.11208513, + ], + [ + 0.00000000, + -0.43835860, + -0.24732790, + -0.45125795, + -0.80781808, + -0.36217377, + 0.54848873, + 0.29335955, + 0.16329652, + 0.11208513, + ], + [ + 0.00000000, + -0.27175528, + -0.15332803, + -0.27975208, + -0.50079735, + -0.22452538, + 0.34002916, + 0.18186482, + 0.10123376, + 0.06948586, + ], + ] + nacl_pbe.mesh_numbers = [9, 9, 9] nacl_pbe.init_phph_interaction(nac_q_direction=[1, 0, 0]) fps, delta = nacl_pbe.run_real_self_energy( [nacl_pbe.grid.gp_Gamma], [300], num_frequency_points=10 ) - # for line in np.swapaxes(delta, -1, -2).ravel().reshape(-1, 6): - # print(("%10.8f, " * 6) % tuple(line)) - # print(fps.ravel()) - np.testing.assert_allclose(freq_points_nacl_nac, fps.ravel(), rtol=0, atol=1e-5) - np.testing.assert_allclose( - delta_nacl_nac, np.swapaxes(delta, -1, -2).ravel(), rtol=0, atol=1e-2 - ) + + # for line in delta[0, 0, 0]: + # print("[", ",".join([f"{val:.8f}" for val in line]), "],") + + np.testing.assert_allclose(ref_freq_points_nacl_nac, fps.ravel(), rtol=0, atol=1e-5) + np.testing.assert_allclose(ref_delta_nacl_nac, delta[0, 0, 0], rtol=0, atol=1e-2) def test_ImagToReal(): """Test ImagToReal class (Kramers–Kronig relation).""" + # imag-self-energy Si-PBEsol 50x50x50 gp=5, bi=4, 101 points, 300K + im_part = [ + [0.0000000, 0.0000000, -0.0000000, -0.1750223, 0.1534611, -0.1794583], + [0.3069222, 0.0180686, 0.3069222, -0.1692049, 0.4603833, -0.1636592], + [0.6138444, 0.0158916, 0.6138444, -0.1621245, 0.7673055, -0.1625514], + [0.9207667, 0.0238034, 0.9207667, -0.1556618, 1.0742278, -0.1484696], + [1.2276889, 0.0131519, 1.2276889, -0.1515719, 1.3811500, -0.1525501], + [1.5346111, 0.0124129, 1.5346111, -0.1541357, 1.6880722, -0.1566124], + [1.8415333, 0.0165506, 1.8415333, -0.1556995, 1.9949944, -0.1567434], + [2.1484555, 0.0196960, 2.1484555, -0.1556492, 2.3019166, -0.1563791], + [2.4553778, 0.0225276, 2.4553778, -0.1553117, 2.6088389, -0.1562531], + [2.7623000, 0.0269193, 2.7623000, -0.1536529, 2.9157611, -0.1520174], + [3.0692222, 0.0247502, 3.0692222, -0.1530976, 3.2226833, -0.1545476], + [3.3761444, 0.0253261, 3.3761444, -0.1565178, 3.5296055, -0.1617560], + [3.6830666, 0.0360216, 3.6830666, -0.1586552, 3.8365277, -0.1618262], + [3.9899888, 0.0510642, 3.9899888, -0.1523272, 4.1434499, -0.1463620], + [4.2969111, 0.0494221, 4.2969111, -0.1428688, 4.4503722, -0.1388442], + [4.6038333, 0.0474328, 4.6038333, -0.1361604, 4.7572944, -0.1307086], + [4.9107555, 0.0370451, 4.9107555, -0.1345154, 5.0642166, -0.1359581], + [5.2176777, 0.0375397, 5.2176777, -0.1361887, 5.3711388, -0.1356714], + [5.5245999, 0.0345936, 5.5245999, -0.1377925, 5.6780610, -0.1390885], + [5.8315222, 0.0327132, 5.8315222, -0.1425343, 5.9849833, -0.1472336], + [6.1384444, 0.0374592, 6.1384444, -0.1489307, 6.2919055, -0.1562694], + [6.4453666, 0.0555985, 6.4453666, -0.1481088, 6.5988277, -0.1452657], + [6.7522888, 0.0586765, 6.7522888, -0.1409779, 6.9057499, -0.1375563], + [7.0592110, 0.0560470, 7.0592110, -0.1371741, 7.2126721, -0.1365273], + [7.3661333, 0.0550400, 7.3661333, -0.1372613, 7.5195944, -0.1387434], + [7.6730555, 0.0565263, 7.6730555, -0.1399341, 7.8265166, -0.1440837], + [7.9799777, 0.0624044, 7.9799777, -0.1457614, 8.1334388, -0.1582010], + [8.2868999, 0.1009214, 8.2868999, -0.1369623, 8.4403610, -0.1261905], + [8.5938221, 0.1090238, 8.5938221, -0.1087372, 8.7472832, -0.0870371], + [8.9007444, 0.0807253, 8.9007444, -0.0903838, 9.0542055, -0.0835210], + [9.2076666, 0.0658383, 9.2076666, -0.0875470, 9.3611277, -0.0853012], + [9.5145888, 0.0592222, 9.5145888, -0.0867791, 9.6680499, -0.0838069], + [9.8215110, 0.0521071, 9.8215110, -0.0853895, 9.9749721, -0.0820186], + [10.1284332, 0.0419588, 10.1284332, -0.0862870, 10.2818943, -0.0860513], + [10.4353554, 0.0364097, 10.4353554, -0.0892629, 10.5888165, -0.0892228], + [10.7422777, 0.0316193, 10.7422777, -0.0922975, 10.8957388, -0.0926032], + [11.0491999, 0.0274798, 11.0491999, -0.0955924, 11.2026610, -0.0960711], + [11.3561221, 0.0233126, 11.3561221, -0.0994131, 11.5095832, -0.1004271], + [11.6630443, 0.0193464, 11.6630443, -0.1043388, 11.8165054, -0.1065527], + [11.9699665, 0.0174292, 11.9699665, -0.1099907, 12.1234276, -0.1125414], + [12.2768888, 0.0164239, 12.2768888, -0.1157951, 12.4303499, -0.1188108], + [12.5838110, 0.0165308, 12.5838110, -0.1218120, 12.7372721, -0.1253937], + [12.8907332, 0.0184723, 12.8907332, -0.1275275, 13.0441943, -0.1309579], + [13.1976554, 0.0211215, 13.1976554, -0.1325454, 13.3511165, -0.1358727], + [13.5045776, 0.0244407, 13.5045776, -0.1369047, 13.6580387, -0.1400194], + [13.8114999, 0.0282908, 13.8114999, -0.1404205, 13.9649610, -0.1429165], + [14.1184221, 0.0313175, 14.1184221, -0.1435582, 14.2718832, -0.1462968], + [14.4253443, 0.0348581, 14.4253443, -0.1467576, 14.5788054, -0.1495649], + [14.7322665, 0.0386150, 14.7322665, -0.1500845, 14.8857276, -0.1533339], + [15.0391887, 0.0424503, 15.0391887, -0.1550110, 15.1926498, -0.1625259], + [15.3461109, 0.0605747, 15.3461109, -0.1550584, 15.4995720, -0.1547951], + [15.6530332, 0.0727408, 15.6530332, -0.1443151, 15.8064943, -0.1346934], + [15.9599554, 0.0625829, 15.9599554, -0.1346277, 16.1134165, -0.1305515], + [16.2668776, 0.0547742, 16.2668776, -0.1324223, 16.4203387, -0.1301107], + [16.5737998, 0.0459500, 16.5737998, -0.1348752, 16.7272609, -0.1365713], + [16.8807220, 0.0432888, 16.8807220, -0.1397155, 17.0341831, -0.1410867], + [17.1876443, 0.0398939, 17.1876443, -0.1450244, 17.3411054, -0.1471968], + [17.4945665, 0.0351088, 17.4945665, -0.1540409, 17.6480276, -0.1617873], + [17.8014887, 0.0424833, 17.8014887, -0.1635035, 17.9549498, -0.1699703], + [18.1084109, 0.0556675, 18.1084109, -0.1649880, 18.2618720, -0.1626782], + [18.4153331, 0.0532241, 18.4153331, -0.1631579, 18.5687942, -0.1618524], + [18.7222554, 0.0458460, 18.7222554, -0.1672846, 18.8757165, -0.1709147], + [19.0291776, 0.0443150, 19.0291776, -0.1758322, 19.1826387, -0.1808661], + [19.3360998, 0.0454289, 19.3360998, -0.1853104, 19.4895609, -0.1911626], + [19.6430220, 0.0483353, 19.6430220, -0.1952856, 19.7964831, -0.2019949], + [19.9499442, 0.0534799, 19.9499442, -0.2053378, 20.1034053, -0.2123304], + [20.2568665, 0.0599861, 20.2568665, -0.2151359, 20.4103276, -0.2225551], + [20.5637887, 0.0685856, 20.5637887, -0.2240731, 20.7172498, -0.2305568], + [20.8707109, 0.0755373, 20.8707109, -0.2331629, 21.0241720, -0.2419628], + [21.1776331, 0.0906438, 21.1776331, -0.2384003, 21.3310942, -0.2380604], + [21.4845553, 0.0827018, 21.4845553, -0.2476712, 21.6380164, -0.2593767], + [21.7914775, 0.0907297, 21.7914775, -0.2660044, 21.9449386, -0.2793854], + [22.0983998, 0.1025946, 22.0983998, -0.2859215, 22.2518609, -0.3026711], + [22.4053220, 0.1210133, 22.4053220, -0.3084041, 22.5587831, -0.3297156], + [22.7122442, 0.1517773, 22.7122442, -0.3307280, 22.8657053, -0.3535969], + [23.0191664, 0.1918115, 23.0191664, -0.3505455, 23.1726275, -0.3769971], + [23.3260886, 0.2484881, 23.3260886, -0.3659809, 23.4795497, -0.3980745], + [23.6330109, 0.3449959, 23.6330109, -0.3587633, 23.7864720, -0.3785512], + [23.9399331, 0.4932745, 23.9399331, -0.2683146, 24.0933942, -0.1740930], + [24.2468553, 0.4000672, 24.2468553, -0.1714061, 24.4003164, -0.1388929], + [24.5537775, 0.3476085, 24.5537775, -0.1478397, 24.7072386, -0.1341295], + [24.8606997, 0.3031722, 24.8606997, -0.1588841, 25.0141608, -0.1796324], + [25.1676220, 0.3332258, 25.1676220, -0.1716723, 25.3210831, -0.1741573], + [25.4745442, 0.3514490, 25.4745442, -0.1621265, 25.6280053, -0.1553650], + [25.7814664, 0.3514801, 25.7814664, -0.1503569, 25.9349275, -0.1458311], + [26.0883886, 0.3490583, 26.0883886, -0.1437619, 26.2418497, -0.1387991], + [26.3953108, 0.3346525, 26.3953108, -0.1471754, 26.5487719, -0.1497006], + [26.7022331, 0.3145614, 26.7022331, -0.1719482, 26.8556942, -0.1898755], + [27.0091553, 0.2913173, 27.0091553, -0.2370443, 27.1626164, -0.2939869], + [27.3160775, 0.2707732, 27.3160775, -0.4139632, 27.4695386, -0.6910918], + [27.6229997, 0.9436577, 27.6229997, -0.3688420, 27.7764608, -0.2026185], + [27.9299219, 0.9147269, 27.9299219, -0.1095194, 28.0833830, -0.0365244], + [28.2368441, 0.9515446, 28.2368441, 0.0642006, 28.3903052, 0.1596622], + [28.5437664, 0.9296466, 28.5437664, 0.2357042, 28.6972275, 0.3228099], + [28.8506886, 0.9383991, 28.8506886, 0.4390380, 29.0041497, 0.6142345], + [29.1576108, 0.7465231, 29.1576108, 0.6502426, 29.3110719, 0.8357126], + [29.4645330, 0.3472854, 29.4645330, 0.6927159, 29.6179941, 0.6873352], + [29.7714552, 0.2258269, 29.7714552, 0.6147208, 29.9249163, 0.6117702], + [30.0783775, 0.1397870, 30.0783775, 0.5578788, 30.2318386, 0.5591731], + [30.3852997, 0.0468188, 30.3852997, 0.4941608, 30.5387608, 0.4706733], + [30.6922219, 0.0000000, 30.6922219, 0.4173657, 30.8456830, 0.3821416], + ] + vals = np.array(im_part) i2r = ImagToReal(vals[:, 1], vals[:, 0]) i2r.run() diff --git a/test/phonon3/test_spectral_function.py b/test/phonon3/test_spectral_function.py index 37bd98fe..947c2cee 100644 --- a/test/phonon3/test_spectral_function.py +++ b/test/phonon3/test_spectral_function.py @@ -1,259 +1,620 @@ """Test spectral_function.py.""" import numpy as np +import pytest from phono3py import Phono3py from phono3py.phonon3.spectral_function import SpectralFunction -shifts = [ - -0.0049592, - -0.0049592, - -0.0120983, - -0.1226471, - -0.1214069, - -0.1214069, - -0.0051678, - -0.0051678, - -0.0128471, - -0.1224616, - -0.1200362, - -0.1200362, - -0.0055308, - -0.0055308, - -0.0122157, - -0.1093754, - -0.1077399, - -0.1077399, - -0.0037992, - -0.0037992, - -0.0089979, - -0.0955525, - -0.0958995, - -0.0958995, - -0.0034397, - -0.0034397, - -0.0107575, - -0.1068741, - -0.1067815, - -0.1067815, - -0.0017800, - -0.0017800, - -0.0102865, - -0.1348585, - -0.1275650, - -0.1275650, - 0.0006728, - 0.0006728, - -0.0065349, - -0.2011702, - -0.2015991, - -0.2015991, - 0.0021133, - 0.0021133, - 0.0020353, - -0.0740009, - -0.0833644, - -0.0833644, - 0.0037739, - 0.0037739, - 0.0121357, - 0.1597195, - 0.1585307, - 0.1585307, - 0.0026257, - 0.0026257, - 0.0103523, - 0.1626420, - 0.1634832, - 0.1634832, - -0.0189694, - -0.0188985, - -0.0415773, - -0.0955391, - -0.1180182, - -0.1126508, - -0.0194533, - -0.0191057, - -0.0420358, - -0.0913521, - -0.1140995, - -0.1075009, - -0.0233933, - -0.0219600, - -0.0466734, - -0.0865867, - -0.1086070, - -0.1014454, - -0.0140271, - -0.0150165, - -0.0344515, - -0.0755416, - -0.1018518, - -0.0951606, - -0.0058780, - -0.0089457, - -0.0256867, - -0.0775726, - -0.1070427, - -0.1018654, - -0.0069737, - -0.0092857, - -0.0333909, - -0.1014042, - -0.1320678, - -0.1288315, - -0.0030075, - -0.0060858, - -0.0245855, - -0.1186313, - -0.1963719, - -0.1857004, - 0.0058243, - 0.0030539, - -0.0049966, - -0.0583228, - -0.0921850, - -0.0893692, - 0.0141517, - 0.0149365, - 0.0312156, - 0.0898626, - 0.1454759, - 0.1347802, - 0.0110954, - 0.0137260, - 0.0427527, - 0.1280421, - 0.1715647, - 0.1648037, -] -spec_funcs = [ - -0.0000000, - -0.0000000, - 0.0000000, - -0.0000000, - -0.0000000, - -0.0000000, - 0.0000165, - 0.0000165, - 0.0022357, - 0.0001249, - 0.0001318, - 0.0001318, - 0.0000027, - 0.0000027, - 0.0000592, - 0.0005056, - 0.0004722, - 0.0004722, - 0.0000016, - 0.0000016, - 0.0000118, - 0.0008887, - 0.0008281, - 0.0008281, - 0.0000001, - 0.0000001, - 0.0000007, - 0.0062806, - 0.0053809, - 0.0053809, - 0.0000003, - 0.0000003, - 0.0000026, - 0.0025466, - 0.0035400, - 0.0035400, - 0.0000001, - 0.0000001, - 0.0000010, - 0.0004469, - 0.0002613, - 0.0002613, - 0.0000001, - 0.0000001, - 0.0000011, - 0.0011874, - 0.0012518, - 0.0012518, - 0.0000000, - 0.0000000, - 0.0000003, - 0.0002964, - 0.0003119, - 0.0003119, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - -0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0032185, - 0.0005560, - 0.0001434, - 0.0001868, - 0.0001602, - 0.0001670, - 0.0000726, - 0.0002220, - 0.0016122, - 0.0004059, - 0.0003461, - 0.0003024, - 0.0000878, - 0.0001280, - 0.0033720, - 0.0027162, - 0.0013271, - 0.0011427, - 0.0000049, - 0.0000094, - 0.0000892, - 0.0137571, - 0.0405108, - 0.0173674, - 0.0000052, - 0.0000084, - 0.0000567, - 0.0005807, - 0.0013438, - 0.0014025, - 0.0000021, - 0.0000034, - 0.0000405, - 0.0003176, - 0.0003022, - 0.0003523, - 0.0000019, - 0.0000034, - 0.0000235, - 0.0003419, - 0.0008701, - 0.0008436, - 0.0000004, - 0.0000010, - 0.0000162, - 0.0001759, - 0.0002910, - 0.0002978, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, - 0.0000000, -] - - -def test_SpectralFunction(si_pbesol: Phono3py): +@pytest.mark.parametrize("check_bands", [False, True]) +def test_SpectralFunction(si_pbesol: Phono3py, check_bands: bool): """Spectral function of Si.""" + if si_pbesol._make_r0_average: + ref_shifts = [ + [ + [ + -0.00491549, + -0.00513379, + -0.00549296, + -0.00377646, + -0.00342792, + -0.00178271, + 0.00063823, + 0.00208652, + 0.00376214, + 0.00262103, + ], + [ + -0.00491549, + -0.00513379, + -0.00549296, + -0.00377646, + -0.00342792, + -0.00178271, + 0.00063823, + 0.00208652, + 0.00376214, + 0.00262103, + ], + [ + -0.01200352, + -0.01272740, + -0.01213832, + -0.00902171, + -0.01079296, + -0.01033632, + -0.00661888, + 0.00196845, + 0.01212704, + 0.01037479, + ], + [ + -0.12224881, + -0.12186476, + -0.10950402, + -0.09619987, + -0.10705652, + -0.13503653, + -0.20145401, + -0.07468261, + 0.15954608, + 0.16311580, + ], + [ + -0.12117175, + -0.11966157, + -0.10786945, + -0.09635481, + -0.10686396, + -0.12762500, + -0.20163789, + -0.08374266, + 0.15834565, + 0.16375939, + ], + [ + -0.12117175, + -0.11966157, + -0.10786945, + -0.09635481, + -0.10686396, + -0.12762500, + -0.20163789, + -0.08374266, + 0.15834565, + 0.16375939, + ], + ], + [ + [ + -0.01895098, + -0.01944799, + -0.02343492, + -0.01391542, + -0.00562335, + -0.00675556, + -0.00299433, + 0.00568717, + 0.01407410, + 0.01103152, + ], + [ + -0.01883020, + -0.01904414, + -0.02189420, + -0.01497364, + -0.00887001, + -0.00907876, + -0.00600166, + 0.00297018, + 0.01485332, + 0.01364674, + ], + [ + -0.04158644, + -0.04204489, + -0.04660642, + -0.03449069, + -0.02581911, + -0.03329617, + -0.02458896, + -0.00519089, + 0.03119712, + 0.04283032, + ], + [ + -0.09542060, + -0.09131037, + -0.08642350, + -0.07536168, + -0.07744657, + -0.10100751, + -0.11855897, + -0.05851935, + 0.08976609, + 0.12789279, + ], + [ + -0.11827973, + -0.11431900, + -0.10875016, + -0.10196855, + -0.10719767, + -0.13236285, + -0.19702133, + -0.09252739, + 0.14584477, + 0.17195801, + ], + [ + -0.11277741, + -0.10757643, + -0.10150954, + -0.09524697, + -0.10202478, + -0.12884057, + -0.18556233, + -0.08932224, + 0.13482432, + 0.16483631, + ], + ], + ] + ref_spec_funcs = [ + [ + [ + 0.00000000, + 0.00001578, + 0.00000272, + 0.00000161, + 0.00000013, + 0.00000032, + 0.00000006, + 0.00000006, + 0.00000001, + 0.00000000, + ], + [ + 0.00000000, + 0.00001578, + 0.00000272, + 0.00000161, + 0.00000013, + 0.00000032, + 0.00000006, + 0.00000006, + 0.00000001, + 0.00000000, + ], + [ + 0.00000000, + 0.00223977, + 0.00005791, + 0.00001160, + 0.00000066, + 0.00000259, + 0.00000098, + 0.00000112, + 0.00000029, + 0.00000000, + ], + [ + 0.00000000, + 0.00012503, + 0.00049470, + 0.00089500, + 0.00632551, + 0.00256627, + 0.00044659, + 0.00118653, + 0.00029733, + 0.00000000, + ], + [ + 0.00000000, + 0.00013193, + 0.00044796, + 0.00083448, + 0.00540572, + 0.00352615, + 0.00026154, + 0.00125032, + 0.00031326, + 0.00000000, + ], + [ + 0.00000000, + 0.00013193, + 0.00044796, + 0.00083448, + 0.00540572, + 0.00352615, + 0.00026154, + 0.00125032, + 0.00031326, + 0.00000000, + ], + ], + [ + [ + -0.00000000, + 0.00320096, + 0.00007269, + 0.00008693, + 0.00000484, + 0.00000526, + 0.00000203, + 0.00000189, + 0.00000039, + 0.00000000, + ], + [ + 0.00000000, + 0.00055197, + 0.00022117, + 0.00012818, + 0.00000952, + 0.00000843, + 0.00000335, + 0.00000334, + 0.00000105, + 0.00000000, + ], + [ + 0.00000000, + 0.00014311, + 0.00162453, + 0.00335197, + 0.00009023, + 0.00005696, + 0.00004058, + 0.00002353, + 0.00001610, + 0.00000000, + ], + [ + 0.00000000, + 0.00018525, + 0.00041136, + 0.00272557, + 0.01393003, + 0.00057594, + 0.00031515, + 0.00034235, + 0.00017612, + 0.00000000, + ], + [ + 0.00000000, + 0.00016156, + 0.00034722, + 0.00132145, + 0.04066875, + 0.00134953, + 0.00030062, + 0.00087157, + 0.00029123, + 0.00000000, + ], + [ + -0.00000000, + 0.00016722, + 0.00030198, + 0.00114459, + 0.01745510, + 0.00141671, + 0.00035262, + 0.00084328, + 0.00029789, + 0.00000000, + ], + ], + ] + else: + ref_shifts = [ + [ + [ + -0.00496121, + -0.00517009, + -0.00553453, + -0.00380260, + -0.00343693, + -0.00177772, + 0.00067068, + 0.00210892, + 0.00377279, + 0.00262923, + ], + [ + -0.00496121, + -0.00517009, + -0.00553453, + -0.00380260, + -0.00343693, + -0.00177772, + 0.00067068, + 0.00210892, + 0.00377279, + 0.00262923, + ], + [ + -0.01202453, + -0.01275071, + -0.01219115, + -0.00903023, + -0.01073474, + -0.01031603, + -0.00662244, + 0.00195097, + 0.01211624, + 0.01038809, + ], + [ + -0.12223984, + -0.12186467, + -0.10941590, + -0.09614195, + -0.10716126, + -0.13519843, + -0.20168604, + -0.07470229, + 0.15969340, + 0.16315933, + ], + [ + -0.12114484, + -0.11964957, + -0.10778748, + -0.09630527, + -0.10697739, + -0.12776042, + -0.20180332, + -0.08373516, + 0.15847215, + 0.16377770, + ], + [ + -0.12114484, + -0.11964957, + -0.10778748, + -0.09630527, + -0.10697739, + -0.12776042, + -0.20180332, + -0.08373516, + 0.15847215, + 0.16377770, + ], + ], + [ + [ + -0.01893616, + -0.01942744, + -0.02339230, + -0.01392117, + -0.00568286, + -0.00676300, + -0.00298881, + 0.00566943, + 0.01407270, + 0.01103835, + ], + [ + -0.01882494, + -0.01903756, + -0.02188396, + -0.01496531, + -0.00891242, + -0.00912826, + -0.00600410, + 0.00298462, + 0.01486886, + 0.01365297, + ], + [ + -0.04155678, + -0.04201981, + -0.04661298, + -0.03446840, + -0.02577765, + -0.03332493, + -0.02460421, + -0.00520459, + 0.03117184, + 0.04283480, + ], + [ + -0.09551912, + -0.09141204, + -0.08650838, + -0.07531933, + -0.07736040, + -0.10097208, + -0.11850788, + -0.05857319, + 0.08971321, + 0.12793090, + ], + [ + -0.11821481, + -0.11425389, + -0.10865996, + -0.10189830, + -0.10716084, + -0.13231357, + -0.19690540, + -0.09252776, + 0.14571718, + 0.17189918, + ], + [ + -0.11276994, + -0.10757084, + -0.10142181, + -0.09519851, + -0.10205844, + -0.12882962, + -0.18549798, + -0.08931099, + 0.13476362, + 0.16481222, + ], + ], + ] + ref_spec_funcs = [ + [ + [ + 0.00000000, + 0.00001654, + 0.00000271, + 0.00000163, + 0.00000013, + 0.00000032, + 0.00000006, + 0.00000006, + 0.00000001, + 0.00000000, + ], + [ + 0.00000000, + 0.00001654, + 0.00000271, + 0.00000163, + 0.00000013, + 0.00000032, + 0.00000006, + 0.00000006, + 0.00000001, + 0.00000000, + ], + [ + 0.00000000, + 0.00223584, + 0.00005772, + 0.00001181, + 0.00000067, + 0.00000258, + 0.00000098, + 0.00000112, + 0.00000029, + 0.00000000, + ], + [ + 0.00000000, + 0.00012499, + 0.00049591, + 0.00088903, + 0.00629350, + 0.00256216, + 0.00044658, + 0.00118784, + 0.00029727, + 0.00000000, + ], + [ + 0.00000000, + 0.00013178, + 0.00044892, + 0.00082915, + 0.00537908, + 0.00352736, + 0.00026142, + 0.00125148, + 0.00031313, + 0.00000000, + ], + [ + 0.00000000, + 0.00013178, + 0.00044892, + 0.00082915, + 0.00537908, + 0.00352736, + 0.00026142, + 0.00125148, + 0.00031313, + 0.00000000, + ], + ], + [ + [ + -0.00000000, + 0.00320916, + 0.00007278, + 0.00008659, + 0.00000484, + 0.00000528, + 0.00000202, + 0.00000189, + 0.00000039, + 0.00000000, + ], + [ + 0.00000000, + 0.00055185, + 0.00022088, + 0.00012806, + 0.00000942, + 0.00000847, + 0.00000336, + 0.00000334, + 0.00000105, + 0.00000000, + ], + [ + 0.00000000, + 0.00014260, + 0.00161534, + 0.00335775, + 0.00008970, + 0.00005681, + 0.00004062, + 0.00002350, + 0.00001611, + 0.00000000, + ], + [ + 0.00000000, + 0.00018553, + 0.00041303, + 0.00273911, + 0.01389025, + 0.00057626, + 0.00031509, + 0.00034209, + 0.00017625, + 0.00000000, + ], + [ + 0.00000000, + 0.00016153, + 0.00034741, + 0.00131818, + 0.04062696, + 0.00134833, + 0.00030074, + 0.00087080, + 0.00029123, + 0.00000000, + ], + [ + -0.00000000, + 0.00016730, + 0.00030334, + 0.00113844, + 0.01748363, + 0.00141678, + 0.00035292, + 0.00084285, + 0.00029790, + 0.00000000, + ], + ], + ] + si_pbesol.mesh_numbers = [9, 9, 9] + if check_bands: + si_pbesol.band_indices = [[4, 5]] si_pbesol.init_phph_interaction() sf = SpectralFunction( si_pbesol.phph_interaction, @@ -266,49 +627,35 @@ def test_SpectralFunction(si_pbesol: Phono3py): ) sf.run() - # for line in np.swapaxes(sf.spectral_functions, -2, -1).reshape(-1, 6): - # print(("%.7f, " * 6) % tuple(line)) - # raise - - np.testing.assert_allclose( - shifts, np.swapaxes(sf.shifts, -2, -1).ravel(), atol=1e-2 - ) - np.testing.assert_allclose( - spec_funcs, - np.swapaxes(sf.spectral_functions, -2, -1).ravel(), - atol=1e-2, - rtol=1e-2, - ) + if check_bands: + np.testing.assert_allclose( + np.array(ref_shifts)[:, [4, 5], :], + sf.shifts[0, 0], + atol=1e-2, + ) + np.testing.assert_allclose( + np.array(ref_spec_funcs)[:, [4, 5], :], + sf.spectral_functions[0, 0], + atol=1e-2, + rtol=1e-2, + ) + else: + # for line in sf.shifts[0, 0, 0]: + # print("[", ",".join([f"{val:.8f}" for val in line]), "],") + # print("") + # for line in sf.shifts[0, 0, 1]: + # print("[", ",".join([f"{val:.8f}" for val in line]), "],") + for line in sf.spectral_functions[0, 0, 0]: + print("[", ",".join([f"{val:.8f}" for val in line]), "],") + print("") + for line in sf.spectral_functions[0, 0, 1]: + print("[", ",".join([f"{val:.8f}" for val in line]), "],") -def test_SpectralFunction_band_indices(si_pbesol: Phono3py): - """Spectral function of Si.""" - si_pbesol.mesh_numbers = [9, 9, 9] - si_pbesol.band_indices = [[4, 5]] - si_pbesol.init_phph_interaction() - sf = SpectralFunction( - si_pbesol.phph_interaction, - si_pbesol.grid.grg2bzg[[1, 103]], - temperatures=[ - 300, - ], - num_frequency_points=10, - log_level=1, - ) - sf.run() - - # for line in np.swapaxes(sf.spectral_functions, -2, -1).reshape(-1, 6): - # print(("%.7f, " * 6) % tuple(line)) - # raise + np.testing.assert_allclose(ref_shifts, sf.shifts[0, 0], atol=1e-2) + np.testing.assert_allclose( + ref_spec_funcs, sf.spectral_functions[0, 0], atol=1e-2, rtol=1e-2 + ) - np.testing.assert_allclose( - np.reshape(shifts, (-1, 6))[:, [4, 5]], - np.swapaxes(sf.shifts, -2, -1).reshape(-1, 2), - atol=1e-2, - ) - np.testing.assert_allclose( - np.reshape(spec_funcs, (-1, 6))[:, [4, 5]], - np.swapaxes(sf.spectral_functions, -2, -1).reshape(-1, 2), - atol=1e-2, - rtol=1e-2, - ) + if check_bands: + si_pbesol.band_indices = None