33import threading , copy
44
55import numpy as np
6+ import scipy , scipy .interpolate
67
78import sys , os
89
@@ -267,4 +268,75 @@ def prepare_input_file(self, structures, calc, labels):
267268 print ('THREAD: {} inputs: {} outputs: {}' .format (threading .get_native_id (), list_of_inputs , list_of_outputs ))
268269
269270
270- return list_of_inputs , list_of_outputs
271+ return list_of_inputs , list_of_outputs
272+
273+
274+
275+ def get_optical_spectrum (ensemble , w_array = None ):
276+ """
277+ COMPUTE THE OPTICAL SPECTRUM
278+ ============================
279+
280+ By averaging the dielectric properties of phonon-displaced configurations,
281+ we can get the phonon-renormalized optical spectrum.
282+
283+
284+ Parameters
285+ ----------
286+ ensemble : sscha.Ensemble.Ensemble
287+ The ensemble. It should contain the optical data.
288+ To do it, use the cluster calculator OpticalQECluster of
289+ the AdvancedCalculation module.
290+ w_array : ndarray, Optional
291+ The frequencies at which to interpolate the results.
292+ If not passed, the full dataset of frequencies will be returned.
293+
294+ Results
295+ -------
296+ w : ndarray, dtype = float
297+ The frequency (eV)
298+ n : ndarray, dtype = complex
299+ The (complex) refractive index
300+ """
301+
302+ w_data = None
303+ for i in range (ensemble .N ):
304+ if not 'epsilon' in ensemble .all_properties [i ]:
305+ ERR = """
306+ Error, the configuration {} has no 'epsilon' data.
307+ """ .format (i )
308+ raise ValueError (ERR )
309+
310+ data = ensemble .all_properties [i ]['epsilon' ]
311+
312+ if w_data is None :
313+ w_data = data [:,0 ]
314+ eps_real = np .zeros_like (w_data )
315+ eps_imag = np .zeros_like (w_data )
316+
317+
318+ eps_real += data [:,1 ]
319+ eps_imag += data [:,2 ]
320+
321+ eps_real /= ensemble .N
322+ eps_imag /= ensemble .N
323+
324+ # Interpolate the data if requested
325+ if w_array is not None :
326+ f_real = scipy .interpolate .interp1d (w_data , eps_real ,
327+ kind = 'cubic' , bounds_error = False , fill_value = 'extrapolate' )
328+ eps_real = f_real (w_array )
329+ f_imag = scipy .interpolate .interp1d (w_data , eps_imag ,
330+ kind = 'cubic' , bounds_error = False , fill_value = 'extrapolate' )
331+ eps_imag = f_imag (w_array )
332+ w_data = w_array
333+
334+ # Build the complex epsilon
335+ epsilon = eps_real + 1j * eps_imag
336+
337+ # Build the refractive index
338+ n = np .sqrt (epsilon )
339+
340+ return w_data , n
341+
342+
0 commit comments