Floats on landing page and fixes to Mie Gans docs
This MR includes floats on the landing page and updates the docs
- Floats on front page linking to all three examples (with a dynamic number of columns depending on screen size!)
- Mistakes in the Mie-Gans documentation are fixed
- Mie-Gans documentation made to reflect the code better (include dielectric constant of environment)
- Document the
__call__method of the dielectric functions
If we every need to plot the static figures on the landing page again then here is the code
import numpy as np
import matplotlib.pyplot as plt
from pandas import DataFrame
from strongcoca import CoupledSystem, PolarizableUnit
from strongcoca.calculators import CasidaCalculator, PolarizabilityCalculator
from strongcoca.response import (read_nwchem_casida, read_gpaw_tddft, build_random_casida,
read_dielec_function_file, MieGansResponse)
from strongcoca.response.utilities import LorentzianBroadening
# -------- Dipolar coupling ---------
broadening = LorentzianBroadening(0.1)
mol_response = read_nwchem_casida('doc/get_started/benzene_monomer.out.gz', broadening=broadening)
NP_response = read_gpaw_tddft('doc/get_started/Al201_dm.dat', broadening=broadening)
pus = [PolarizableUnit(mol_response, [-14, 0, 0]), # Benzene at -14 Å
PolarizableUnit(mol_response, [+14, 0, 0]), # Benzene at +14 Å
PolarizableUnit(NP_response, [0, 0, 0]), # NP at the origin
]
cs = CoupledSystem(pus)
calc = PolarizabilityCalculator(cs, [0, 1])
frequencies = np.linspace(5, 9, 200)
NP_absorption = NP_response.get_dipole_strength_function(frequencies)
mol_absorption = mol_response.get_dipole_strength_function(frequencies)
coupled_absorption = calc.get_dipole_strength_function(frequencies)
fig, ax = plt.subplots(1, 1, figsize=(3, 2.5), dpi=200)
ax.plot(frequencies, NP_absorption[:, 0], color='k')
ax.plot(frequencies, 10 * mol_absorption[:, 0], color='k', ls='--')
ax.plot(frequencies, coupled_absorption[:, 0], color='cornflowerblue', lw=3)
ax.annotate('Al$_{201}$', (8, 260), color='k', va='bottom')
ax.annotate('Al$_{201}$ + benzene', (5.5, 220), color='cornflowerblue', va='bottom')
ax.annotate(r'benzene $\times 10$', (7.45, 20), color='k', va='bottom')
ax.set(xlabel='Energy (eV)', ylabel='Absorption', yticks=[], xlim=[5, 9], ylim=[0, 300])
fig.tight_layout()
fig.savefig('doc/_static/dipolar_coupling.png')
# ---------- Mie-Gans ---------------
# Read Ag dielectric function (data from DFT)
df = read_dielec_function_file('doc/get_started/dielectric_function_Pd_0.00_Ag_100.00.txt')
response = MieGansResponse([20, 25, 25], df) # Semi-axes of (20, 25, 25)Å
frequencies = np.linspace(2, 5, 200)
absorption = response.get_dipole_strength_function(frequencies)
fig, axes = plt.subplots(2, 1, figsize=(3, 2.5), dpi=200, sharex=True,
gridspec_kw=dict(hspace=0))
ax = axes[0]
ax.plot(frequencies, df(frequencies).real, label='Real', color='cornflowerblue')
ax.plot(frequencies, df(frequencies).imag, label='Imag', color='goldenrod')
ax.annotate('Real', (2.2, 0.1), color='goldenrod', va='bottom')
ax.annotate('Imag', (2.6, -4.5), color='cornflowerblue', va='bottom')
ax.set(ylim=[-5, 5], ylabel='DF', yticks=[])
ax = axes[1]
ax.plot(frequencies, absorption[:, 0], color='k')
ax.set(xlabel='Energy (eV)', ylabel='Absorption', yticks=[])
ax.annotate('Ag sphere', (3.3, 350), color='k', va='bottom', ha='right')
fig.tight_layout()
fig.savefig('doc/_static/mie_gans.png')
# ------ Correlation energies ---------
# Set up a the response of a hypothetical system based on a Casida matrix
# description
response = build_random_casida(n_states=3, name='Grizzly', random_seed=42)
# We construct a coupled system from two polarizable units with the same
# response functions.
pu1 = PolarizableUnit(response, [0, 0, 0])
pu2 = PolarizableUnit(response, [1.5, 0, 0])
cs = CoupledSystem([pu1, pu2])
# Now we set up a calculator and compute the spectrum and correlation energy
# as a function of the distance between the units.
calc = CasidaCalculator(cs)
data = {}
for dr in np.arange(2.0, 6.0, 0.02):
pu2.position = [dr, 0, 0]
ecor = calc.get_correlation_energy()
excitations = calc.excitations.energies
data[dr] = {'energy': ecor}
data[dr].update({f'excitation{k}': en for k, en in enumerate(excitations)})
df = DataFrame.from_dict(data).T
fig, ax = plt.subplots(1, 1, figsize=(3, 2.5), dpi=200)
ax.plot(df.energy, color='cornflowerblue')
ax.set_xlabel('Distance (Å)')
ax.set_ylabel('Correlation energy (eV)', color='cornflowerblue')
ax.set_ylim((-0.37, 0.02))
ax2 = ax.axes.twinx()
for fld in df.columns:
if 'excitation' not in fld:
continue
ax2.plot(df[fld], color='orange')
ax2.set_ylabel('Excitation energy (eV)', color='orange')
ax2.set_ylim(0, 6)
fig.tight_layout()
fig.savefig('doc/_static/correlation.png')
Edited by Jakub Fojt