Skip to content

Commit

Permalink
unitcell != supercell
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Oct 20, 2023
1 parent f15856f commit ecb9b0a
Show file tree
Hide file tree
Showing 6 changed files with 453 additions and 4 deletions.
8 changes: 4 additions & 4 deletions phonopy_vibspec/phonons_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class PhononsAnalyzer:

def __init__(self, phonon: phonopy.Phonopy):
self.phonotopy = phonon
self.supercell = phonon.supercell
self.unitcell = phonon.unitcell

# get eigenvalues and eigenvectors at gamma point
# See https://github.com/phonopy/phonopy/issues/308#issuecomment-1769736200
Expand All @@ -39,7 +39,7 @@ def __init__(self, phonon: phonopy.Phonopy):

mesh_dict = phonon.get_mesh_dict()

self.N = self.supercell.get_number_of_atoms()
self.N = self.unitcell.get_number_of_atoms()
l_logger.info('Analyze {} modes (including acoustic)'.format(3 * self.N))
self.frequencies = mesh_dict['frequencies'][0] * THZ_TO_INV_CM # in [cm⁻¹]

Expand All @@ -50,7 +50,7 @@ def __init__(self, phonon: phonopy.Phonopy):
self.eigenvectors = mesh_dict['eigenvectors'][0].real.T # in [Å sqrt(AMU)]

# compute displacements with Eq. 4 of 10.1039/C7CP01680H
sqrt_masses = numpy.repeat(numpy.sqrt(self.supercell.masses), 3)
sqrt_masses = numpy.repeat(numpy.sqrt(self.unitcell.masses), 3)
self.eigendisps = (self.eigenvectors / sqrt_masses[numpy.newaxis, :]).reshape(-1, self.N, 3) # in [Å]

# get irreps
Expand Down Expand Up @@ -144,7 +144,7 @@ def prepare_raman(
mode_calcs = []
steps = []

base_geometry = self.phonotopy.unitcell
base_geometry = self.unitcell

for mode in modes:
if mode < 0 or mode >= 3 * self.N:
Expand Down
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
def context_SiO2(monkeypatch):
dir_ = pathlib.Path(__file__).parent / 'tests_files/SiO2'
monkeypatch.chdir(dir_)


@pytest.fixture
def context_SiO2_supercell(monkeypatch):
dir_ = pathlib.Path(__file__).parent / 'tests_files/SiO2_supercell'
monkeypatch.chdir(dir_)
11 changes: 11 additions & 0 deletions tests/test_vibspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,14 @@ def test_raman_spectrum_extract_dielectrics(context_SiO2):
assert raman_intensities[i] != pytest.approx(.0, abs=1e-3)
else:
assert raman_intensities[i] == pytest.approx(.0, abs=1e-3)


def test_infrared_SiO2_supercell(context_SiO2_supercell):
phonons = PhononsAnalyzer.from_phonopy(
phonopy_yaml='phonopy_disp.yaml',
force_constants_filename='force_constants.hdf5',
born_filename='BORN'
)

# get spectrum
spectrum = phonons.infrared_spectrum()
4 changes: 4 additions & 0 deletions tests/tests_files/SiO2_supercell/BORN
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# epsilon and Z* of atoms 1 4
2.48082155 -0.00000000 0.00000000 0.00000000 2.48082155 0.00000000 0.00000000 0.00000000 2.51333836
2.98054793 -0.00000000 0.00000000 -0.00000000 3.62049126 -0.32132376 0.00000000 0.27802860 3.42535654
-1.31115748 -0.49333488 -0.31019627 -0.43614151 -1.98936212 -0.67895864 -0.24344107 -0.72145846 -1.71267827
Binary file not shown.
Loading

0 comments on commit ecb9b0a

Please sign in to comment.