mirror of https://github.com/phonopy/phonopy.git
Writing docstrings following pydocstring
This commit is contained in:
parent
39765d0ae4
commit
5bc2d0513e
|
@ -33,7 +33,7 @@
|
|||
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
# POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
from typing import List, Union
|
||||
from typing import Union
|
||||
|
||||
import numpy as np
|
||||
|
||||
|
@ -69,17 +69,22 @@ class Modulation:
|
|||
self._derivative_order = derivative_order
|
||||
|
||||
self._factor = factor
|
||||
self._u = []
|
||||
self._eigvecs = []
|
||||
self._eigvals = []
|
||||
self._supercell = None
|
||||
|
||||
dim = self._get_dimension_3x3()
|
||||
self._supercell = get_supercell(self._primitive, dim)
|
||||
complex_dtype = "c%d" % (np.dtype("double").itemsize * 2)
|
||||
self._u = np.zeros(
|
||||
(len(self._phonon_modes), len(self._supercell), 3),
|
||||
dtype=complex_dtype,
|
||||
order="C",
|
||||
)
|
||||
self._eigvals = np.zeros(len(self._phonon_modes), dtype="double")
|
||||
self._eigvecs = np.zeros(
|
||||
(len(self._phonon_modes), len(self._primitive) * 3), dtype=complex_dtype
|
||||
)
|
||||
|
||||
def run(self):
|
||||
"""Calculate modulations."""
|
||||
for ph_mode in self._phonon_modes:
|
||||
for i, ph_mode in enumerate(self._phonon_modes):
|
||||
q, band_index, amplitude, argument = ph_mode
|
||||
eigvals, eigvecs = get_eigenvectors(
|
||||
q,
|
||||
|
@ -90,9 +95,9 @@ class Modulation:
|
|||
nac_q_direction=self._nac_q_direction,
|
||||
)
|
||||
u = self._get_displacements(eigvecs[:, band_index], q, amplitude, argument)
|
||||
self._u.append(u)
|
||||
self._eigvecs.append(eigvecs[:, band_index])
|
||||
self._eigvals.append(eigvals[band_index])
|
||||
self._u[i] = u
|
||||
self._eigvecs[i] = eigvecs[:, band_index]
|
||||
self._eigvals[i] = eigvals[band_index]
|
||||
|
||||
def get_modulated_supercells(self):
|
||||
"""Return modulations."""
|
||||
|
|
|
@ -233,9 +233,9 @@ class DynamicStructureFactor:
|
|||
freq_min=self._fmin,
|
||||
freq_max=self._fmax,
|
||||
)
|
||||
td.set_temperatures([self._T])
|
||||
td.temperatures = [self._T]
|
||||
td.run()
|
||||
return td.get_thermal_displacements()
|
||||
return td.temperatures, td.thermal_displacements
|
||||
|
||||
def _phonon_structure_factor(self, Q_cart, G, DW, freq, eigvec):
|
||||
symbols = self._primitive.get_chemical_symbols()
|
||||
|
|
|
@ -247,7 +247,9 @@ def helper_methods():
|
|||
|
||||
class HelperMethods:
|
||||
@classmethod
|
||||
def compare_cells_with_order(cls, cell, cell_ref, symprec=1e-5):
|
||||
def compare_cells_with_order(
|
||||
cls, cell: PhonopyAtoms, cell_ref: PhonopyAtoms, symprec=1e-5
|
||||
):
|
||||
"""Compare two cells with the same orders of positions."""
|
||||
np.testing.assert_allclose(cell.cell, cell_ref.cell, atol=symprec)
|
||||
cls.compare_positions_with_order(
|
||||
|
@ -270,7 +272,9 @@ def helper_methods():
|
|||
assert (dist < symprec).all()
|
||||
|
||||
@classmethod
|
||||
def compare_cells(cls, cell, cell_ref, symprec=1e-5):
|
||||
def compare_cells(
|
||||
cls, cell: PhonopyAtoms, cell_ref: PhonopyAtoms, symprec=1e-5
|
||||
):
|
||||
"""Compare two cells where position orders can be different."""
|
||||
np.testing.assert_allclose(cell.cell, cell_ref.cell, atol=symprec)
|
||||
|
||||
|
|
|
@ -91,7 +91,7 @@ def _assert(ph: Phonopy, ref_vals, show=False):
|
|||
dynmat = ph.dynamical_matrix
|
||||
ddynmat = DerivativeOfDynamicalMatrix(dynmat)
|
||||
ddynmat.run([0, 0.1, 0.1])
|
||||
ddm = ddynmat.get_derivative_of_dynamical_matrix()
|
||||
ddm = ddynmat.d_dynamical_matrix
|
||||
condition = np.abs(ddm) > 1e-8
|
||||
vals = np.extract(condition, ddm).real
|
||||
if show:
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
"""Tests for routines in force_constants.py."""
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
||||
from phonopy import Phonopy
|
||||
from phonopy.harmonic.force_constants import cutoff_force_constants
|
||||
from phonopy.structure.cells import get_primitive
|
||||
|
||||
|
@ -41,26 +43,30 @@ fc_1_10_compact_fcsym_ref = [
|
|||
]
|
||||
|
||||
|
||||
def test_fc(ph_nacl):
|
||||
def test_fc(ph_nacl: Phonopy):
|
||||
"""Test of force constants calculation with fcsym by NaCl."""
|
||||
fc_1_10 = ph_nacl.force_constants[1, 10]
|
||||
# print("".join(["%f, " % v for v in fc_1_10.ravel()]))
|
||||
np.testing.assert_allclose(fc_1_10.ravel(), fc_1_10_ref, atol=1e-5)
|
||||
|
||||
|
||||
def test_fc_nofcsym(ph_nacl_nofcsym):
|
||||
def test_fc_nofcsym(ph_nacl_nofcsym: Phonopy):
|
||||
"""Test of force constants calculation without fcsym by NaCl."""
|
||||
fc_1_10 = ph_nacl_nofcsym.force_constants[1, 10]
|
||||
# print("".join(["%f, " % v for v in fc_1_10.ravel()]))
|
||||
np.testing.assert_allclose(fc_1_10.ravel(), fc_1_10_nofcsym_ref, atol=1e-5)
|
||||
|
||||
|
||||
def test_fc_compact_fcsym(ph_nacl_compact_fcsym):
|
||||
def test_fc_compact_fcsym(ph_nacl_compact_fcsym: Phonopy):
|
||||
"""Test of force constants calculation in compact format with fcsym by NaCl."""
|
||||
fc_1_10 = ph_nacl_compact_fcsym.force_constants[1, 10]
|
||||
# print("".join(["%f, " % v for v in fc_1_10.ravel()]))
|
||||
np.testing.assert_allclose(fc_1_10.ravel(), fc_1_10_compact_fcsym_ref, atol=1e-5)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("is_compact", [False, True])
|
||||
def test_fc_cutoff_radius(ph_nacl, ph_nacl_compact_fcsym, is_compact):
|
||||
def test_fc_cutoff_radius(ph_nacl: Phonopy, ph_nacl_compact_fcsym: Phonopy, is_compact):
|
||||
"""Test of cutoff radius of force constants calculation by NaCl."""
|
||||
if is_compact:
|
||||
ph = ph_nacl_compact_fcsym
|
||||
else:
|
||||
|
@ -83,8 +89,9 @@ def test_fc_cutoff_radius(ph_nacl, ph_nacl_compact_fcsym, is_compact):
|
|||
[(False, False), (False, True), (True, False), (True, True)],
|
||||
)
|
||||
def test_fc_cutoff_radius_svecs(
|
||||
ph_nacl, ph_nacl_compact_fcsym, is_compact, store_dense_svecs
|
||||
ph_nacl: Phonopy, ph_nacl_compact_fcsym: Phonopy, is_compact, store_dense_svecs
|
||||
):
|
||||
"""Test of cutoff radius with dense-svecs format by NaCl."""
|
||||
if is_compact:
|
||||
ph = ph_nacl_compact_fcsym
|
||||
else:
|
||||
|
|
|
@ -1,136 +0,0 @@
|
|||
64
|
||||
2
|
||||
|
||||
1
|
||||
0.0100000000000000 0.0000000000000000 0.0000000000000000
|
||||
-0.0180619400 0.0000000000 0.0000000000
|
||||
0.0030240400 0.0000000000 0.0000000000
|
||||
-0.0000434000 0.0000000000 0.0000000000
|
||||
0.0001066900 0.0000000000 0.0000000000
|
||||
-0.0000434000 0.0000000000 0.0000000000
|
||||
0.0001066900 0.0000000000 0.0000000000
|
||||
-0.0001589900 0.0000000000 0.0000000000
|
||||
0.0001344200 0.0000000000 0.0000000000
|
||||
-0.0005716800 -0.0000021200 -0.0000021200
|
||||
0.0003817600 0.0000002400 0.0000002400
|
||||
-0.0005716800 0.0000021200 -0.0000021200
|
||||
0.0003817600 -0.0000002400 0.0000002400
|
||||
-0.0005716800 -0.0000021200 0.0000021200
|
||||
0.0003817600 0.0000002400 -0.0000002400
|
||||
-0.0005716800 0.0000021200 0.0000021200
|
||||
0.0003817600 -0.0000002400 -0.0000002400
|
||||
0.0004845700 0.0000000000 0.0019354900
|
||||
0.0004850100 0.0000000000 -0.0019214300
|
||||
-0.0000183800 0.0000000000 -0.0000178800
|
||||
-0.0000173700 0.0000000000 0.0000170400
|
||||
0.0004845700 0.0000000000 -0.0019354900
|
||||
0.0004850100 0.0000000000 0.0019214300
|
||||
-0.0000183800 0.0000000000 0.0000178800
|
||||
-0.0000173700 0.0000000000 -0.0000170400
|
||||
0.0004845700 0.0019354900 0.0000000000
|
||||
0.0004850100 -0.0019214300 0.0000000000
|
||||
0.0004845700 -0.0019354900 0.0000000000
|
||||
0.0004850100 0.0019214300 0.0000000000
|
||||
-0.0000183800 -0.0000178800 0.0000000000
|
||||
-0.0000173700 0.0000170400 0.0000000000
|
||||
-0.0000183800 0.0000178800 0.0000000000
|
||||
-0.0000173700 -0.0000170400 0.0000000000
|
||||
-0.0000810800 -0.0004282000 -0.0004282000
|
||||
-0.0000835100 0.0004258800 0.0004258800
|
||||
-0.0000810800 0.0004282000 -0.0004282000
|
||||
-0.0000835100 -0.0004258800 0.0004258800
|
||||
-0.0000810800 -0.0004282000 0.0004282000
|
||||
-0.0000835100 0.0004258800 -0.0004258800
|
||||
-0.0000810800 0.0004282000 0.0004282000
|
||||
-0.0000835100 -0.0004258800 -0.0004258800
|
||||
0.0050201700 0.0000000000 0.0000000000
|
||||
0.0046140400 0.0000000000 0.0000000000
|
||||
0.0000408300 0.0000000000 0.0000000000
|
||||
0.0000373700 0.0000000000 0.0000000000
|
||||
0.0000408300 0.0000000000 0.0000000000
|
||||
0.0000373700 0.0000000000 0.0000000000
|
||||
-0.0000105300 0.0000000000 0.0000000000
|
||||
-0.0000118000 0.0000000000 0.0000000000
|
||||
0.0017148800 -0.0000110200 0.0000000000
|
||||
-0.0009600300 -0.0000013600 0.0000000000
|
||||
0.0017148800 0.0000110200 0.0000000000
|
||||
-0.0009600300 0.0000013600 0.0000000000
|
||||
0.0001936100 0.0000011800 0.0000000000
|
||||
-0.0002359000 0.0000000900 0.0000000000
|
||||
0.0001936100 -0.0000011800 0.0000000000
|
||||
-0.0002359000 -0.0000000900 0.0000000000
|
||||
0.0017148800 0.0000000000 -0.0000110200
|
||||
-0.0009600300 0.0000000000 -0.0000013600
|
||||
0.0001936100 0.0000000000 0.0000011800
|
||||
-0.0002359000 0.0000000000 0.0000000900
|
||||
0.0017148800 0.0000000000 0.0000110200
|
||||
-0.0009600300 0.0000000000 0.0000013600
|
||||
0.0001936100 0.0000000000 -0.0000011800
|
||||
-0.0002359000 0.0000000000 -0.0000000900
|
||||
|
||||
33
|
||||
0.0100000000000000 0.0000000000000000 0.0000000000000000
|
||||
-0.0000721800 -0.0004247300 -0.0004247300
|
||||
-0.0000667600 0.0004272300 0.0004272300
|
||||
-0.0000721800 0.0004247300 -0.0004247300
|
||||
-0.0000667600 -0.0004272300 0.0004272300
|
||||
-0.0000721800 -0.0004247300 0.0004247300
|
||||
-0.0000667600 0.0004272300 -0.0004272300
|
||||
-0.0000721800 0.0004247300 0.0004247300
|
||||
-0.0000667600 -0.0004272300 -0.0004272300
|
||||
0.0046345100 0.0000000000 0.0000000000
|
||||
0.0050314800 0.0000000000 0.0000000000
|
||||
0.0000499300 0.0000000000 0.0000000000
|
||||
0.0000510900 0.0000000000 0.0000000000
|
||||
0.0000499300 0.0000000000 0.0000000000
|
||||
0.0000510900 0.0000000000 0.0000000000
|
||||
-0.0000030400 0.0000000000 0.0000000000
|
||||
0.0000012000 0.0000000000 0.0000000000
|
||||
0.0017234100 0.0000077800 0.0000000000
|
||||
-0.0009445700 -0.0000004700 0.0000000000
|
||||
0.0017234100 -0.0000077800 0.0000000000
|
||||
-0.0009445700 0.0000004700 0.0000000000
|
||||
0.0002042400 0.0000019500 0.0000000000
|
||||
-0.0002202400 -0.0000015500 0.0000000000
|
||||
0.0002042400 -0.0000019500 0.0000000000
|
||||
-0.0002202400 0.0000015500 0.0000000000
|
||||
0.0017234100 0.0000000000 0.0000077800
|
||||
-0.0009445700 0.0000000000 -0.0000004700
|
||||
0.0002042400 0.0000000000 0.0000019500
|
||||
-0.0002202400 0.0000000000 -0.0000015500
|
||||
0.0017234100 0.0000000000 -0.0000077800
|
||||
-0.0009445700 0.0000000000 0.0000004700
|
||||
0.0002042400 0.0000000000 -0.0000019500
|
||||
-0.0002202400 0.0000000000 0.0000015500
|
||||
-0.0236731700 0.0000000000 0.0000000000
|
||||
0.0013201600 0.0000000000 0.0000000000
|
||||
-0.0005159800 0.0000000000 0.0000000000
|
||||
0.0006463500 0.0000000000 0.0000000000
|
||||
-0.0005159800 0.0000000000 0.0000000000
|
||||
0.0006463500 0.0000000000 0.0000000000
|
||||
-0.0001691500 0.0000000000 0.0000000000
|
||||
0.0001742700 0.0000000000 0.0000000000
|
||||
-0.0008016000 0.0000039800 0.0000039800
|
||||
0.0005170500 -0.0000010700 -0.0000010700
|
||||
-0.0008016000 -0.0000039800 0.0000039800
|
||||
0.0005170500 0.0000010700 -0.0000010700
|
||||
-0.0008016000 0.0000039800 -0.0000039800
|
||||
0.0005170500 -0.0000010700 0.0000010700
|
||||
-0.0008016000 -0.0000039800 -0.0000039800
|
||||
0.0005170500 0.0000010700 0.0000010700
|
||||
0.0013674700 0.0000000000 0.0020506700
|
||||
0.0013743700 0.0000000000 -0.0020695000
|
||||
-0.0000146100 0.0000000000 0.0001925900
|
||||
-0.0000113300 0.0000000000 -0.0001898400
|
||||
0.0013674700 0.0000000000 -0.0020506700
|
||||
0.0013743700 0.0000000000 0.0020695000
|
||||
-0.0000146100 0.0000000000 -0.0001925900
|
||||
-0.0000113300 0.0000000000 0.0001898400
|
||||
0.0013674700 0.0020506700 0.0000000000
|
||||
0.0013743700 -0.0020695000 0.0000000000
|
||||
0.0013674700 -0.0020506700 0.0000000000
|
||||
0.0013743700 0.0020695000 0.0000000000
|
||||
-0.0000146100 0.0001925900 0.0000000000
|
||||
-0.0000113300 -0.0001898400 0.0000000000
|
||||
-0.0000146100 -0.0001925900 0.0000000000
|
||||
-0.0000113300 0.0001898400 0.0000000000
|
|
@ -28,7 +28,7 @@ def test_parse_vasprun_xml():
|
|||
"""Test parsing vasprun.xml with expat."""
|
||||
filename_vasprun = os.path.join(data_dir, "vasprun.xml.tar.bz2")
|
||||
_tar = tarfile.open(filename_vasprun)
|
||||
filename = os.path.join(data_dir, "FORCE_SETS_NaCl")
|
||||
filename = os.path.join(data_dir, "../FORCE_SETS_NaCl")
|
||||
dataset = parse_FORCE_SETS(filename=filename)
|
||||
for i, member in enumerate(_tar.getmembers()):
|
||||
vr = Vasprun(_tar.extractfile(member), use_expat=True)
|
||||
|
|
Loading…
Reference in New Issue