Coverage for ase/vibrations/placzek.py: 96.88%
96 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
« prev ^ index » next coverage.py v7.16.2, created at 2026-11-27 15:21 +0000
1import numpy as np
3import ase.units as u
4from ase.calculators.excitation_list import polarizability
5from ase.vibrations.raman import Raman, RamanPhonons
6from ase.vibrations.resonant_raman import ResonantRaman
9class Placzek(ResonantRaman):
10 """Raman spectra within the Placzek approximation."""
12 def __init__(self, *args, **kwargs):
13 self._approx = 'PlaczekAlpha'
14 ResonantRaman.__init__(self, *args, **kwargs)
16 def set_approximation(self, value):
17 raise ValueError('Approximation can not be set.')
19 def _signed_disps(self, sign):
20 for a, i in zip(self.myindices, self.myxyz):
21 yield self._disp(a, i, sign)
23 def _read_exobjs(self, sign):
24 return [disp.read_exobj() for disp in self._signed_disps(sign)]
26 def read_excitations(self):
27 """Read excitations from files written"""
28 self.ex0E_p = None # mark as read
29 self.exm_r = self._read_exobjs(sign=-1)
30 self.exp_r = self._read_exobjs(sign=1)
32 def electronic_me_Qcc(self, omega, gamma=0):
33 self.calculate_energies_and_modes()
35 V_rcc = np.zeros((self.ndof, 3, 3), dtype=complex)
36 pre = 1.0 / (2 * self.delta)
37 pre *= u.Hartree * u.Bohr # e^2Angstrom^2 / eV -> Angstrom^3
39 om = omega
40 if gamma:
41 om += 1j * gamma
43 for i, r in enumerate(self.myr):
44 V_rcc[r] = pre * (
45 polarizability(
46 self.exp_r[i], om, form=self.dipole_form, tensor=True
47 )
48 - polarizability(
49 self.exm_r[i], om, form=self.dipole_form, tensor=True
50 )
51 )
52 self.comm.sum(V_rcc)
54 return self.map_to_modes(V_rcc)
57class PlaczekStatic(Raman):
58 def read_excitations(self):
59 """Read excitations from files written"""
60 self.al0_rr = None # mark as read
61 self.alm_rr = []
62 self.alp_rr = []
63 for a, i in zip(self.myindices, self.myxyz):
64 for sign, al_rr in zip([-1, 1], [self.alm_rr, self.alp_rr]):
65 disp = self._disp(a, i, sign)
66 al_rr.append(disp.load_static_polarizability())
68 def electronic_me_Qcc(self):
69 self.calculate_energies_and_modes()
71 V_rcc = np.zeros((self.ndof, 3, 3), dtype=complex)
72 pre = 1.0 / (2 * self.delta)
73 pre *= u.Hartree * u.Bohr # e^2Angstrom^2 / eV -> Angstrom^3
75 for i, r in enumerate(self.myr):
76 V_rcc[r] = pre * (self.alp_rr[i] - self.alm_rr[i])
77 self.comm.sum(V_rcc)
79 return self.map_to_modes(V_rcc)
82class PlaczekStaticPhonons(RamanPhonons, PlaczekStatic):
83 pass
86class Profeta(ResonantRaman):
87 """Profeta type approximations.
89 Reference
90 ---------
91 Mickael Profeta and Francesco Mauri
92 Phys. Rev. B 63 (2000) 245415
93 """
95 def __init__(self, *args, **kwargs):
96 self.set_approximation(kwargs.pop('approximation', 'Profeta'))
97 self.nonresonant = kwargs.pop('nonresonant', True)
98 ResonantRaman.__init__(self, *args, **kwargs)
100 def set_approximation(self, value):
101 approx = value.lower()
102 if approx in ['profeta', 'placzek', 'p-p']:
103 self._approx = value
104 else:
105 raise ValueError('Please use "Profeta", "Placzek" or "P-P".')
107 def electronic_me_profeta_rcc(
108 self, omega, gamma=0.1, energy_derivative=False
109 ):
110 """Raman spectra in Profeta and Mauri approximation
112 Returns
113 -------
114 Electronic matrix element, unit Angstrom^2
115 """
116 self.calculate_energies_and_modes()
118 V_rcc = np.zeros((self.ndof, 3, 3), dtype=complex)
119 pre = 1.0 / (2 * self.delta)
120 pre *= u.Hartree * u.Bohr # e^2Angstrom^2 / eV -> Angstrom^3
122 def kappa_cc(me_pc, e_p, omega, gamma, form='v'):
123 """Kappa tensor after Profeta and Mauri
124 PRB 63 (2001) 245415"""
125 k_cc = np.zeros((3, 3), dtype=complex)
126 for p, me_c in enumerate(me_pc):
127 me_cc = np.outer(me_c, me_c.conj())
128 k_cc += me_cc / (e_p[p] - omega - 1j * gamma)
129 if self.nonresonant:
130 k_cc += me_cc.conj() / (e_p[p] + omega + 1j * gamma)
131 return k_cc
133 mr = 0
134 for a, i, r in zip(self.myindices, self.myxyz, self.myr):
135 if energy_derivative >= 0:
136 V_rcc[r] += pre * (
137 kappa_cc(
138 self.expm_rpc[mr],
139 self.ex0E_p,
140 omega,
141 gamma,
142 self.dipole_form,
143 )
144 - kappa_cc(
145 self.exmm_rpc[mr],
146 self.ex0E_p,
147 omega,
148 gamma,
149 self.dipole_form,
150 )
151 )
152 if energy_derivative:
153 V_rcc[r] += pre * (
154 kappa_cc(
155 self.ex0m_pc,
156 self.expE_rp[mr],
157 omega,
158 gamma,
159 self.dipole_form,
160 )
161 - kappa_cc(
162 self.ex0m_pc,
163 self.exmE_rp[mr],
164 omega,
165 gamma,
166 self.dipole_form,
167 )
168 )
169 mr += 1
170 self.comm.sum(V_rcc)
172 return V_rcc
174 def electronic_me_Qcc(self, omega, gamma):
175 self.read()
176 Vel_rcc = np.zeros((self.ndof, 3, 3), dtype=complex)
177 approximation = self.approximation.lower()
178 if approximation == 'profeta':
179 Vel_rcc += self.electronic_me_profeta_rcc(omega, gamma)
180 elif approximation == 'placzek':
181 Vel_rcc += self.electronic_me_profeta_rcc(omega, gamma, True)
182 elif approximation == 'p-p':
183 Vel_rcc += self.electronic_me_profeta_rcc(omega, gamma, -1)
184 else:
185 raise RuntimeError(
186 'Bug: call with {} should not happen!'.format(
187 self.approximation
188 )
189 )
191 return self.map_to_modes(Vel_rcc)