Skip to content

Commit 5866cdf

Browse files
authored
Merge pull request #257 from YuchenWang2015/devel
add files for Shin–Metiu-Polariton model
2 parents f745e8b + e292d4e commit 5866cdf

4 files changed

Lines changed: 267 additions & 0 deletions

File tree

363 KB
Binary file not shown.
363 KB
Binary file not shown.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
This .h5 file contains simulation output data generated from a DVR calculation using Shin-Metiu model.
2+
The file stores a set of physical quantities computed over a one-dimensional grid of nuclear coordinates (R_grid).
3+
The data is stored in NumPy array format within HDF5 datasets.
4+
5+
File Structure and Variables
6+
7+
R_grid — Shape: (N_grids_R,)
8+
coordiates on the grid
9+
10+
eigvals — Shape: (N_grids_R, nelec_dim_dump)
11+
adiabatic electronic energies
12+
13+
d_V — Shape: (N_grids_R, nelec_dim_dump, nelec_dim_dump)
14+
matrix of potential energy gradient [\nabla V]
15+
16+
nac — Shape: (N_grids_R, nelec_dim_dump, nelec_dim_dump)
17+
non-adiabatic coupling matrix
18+
19+
mu — Shape: (N_grids_R, nelec_dim_dump, nelec_dim_dump)
20+
dipole moment matrix
21+
22+
d_mu — Shape: (N_grids_R, nelec_dim_dump, nelec_dim_dump)
23+
dipole moment gradient matrix [\nabla \mu]
24+
25+
mu_deri — Shape: (N_grids_R, nelec_dim_dump, nelec_dim_dump)
26+
derivative of dipole moment matrix elements \nabla [\mu]
Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
import numpy as np
2+
import h5py
3+
from functools import reduce
4+
from liblibra_core import *
5+
import util.libutil as comn
6+
7+
"""
8+
.. module:: models_shin_meitu model with polaritonic effects
9+
:platform: Unix, Windows
10+
:synopsis: This module implements the polaritonic effects using Shin-metiu potential
11+
:Calculate the polaritonic states with the 2-state and 4-state models
12+
in reference paper.
13+
See (34)-(40) in J. Chem. Phys. 157, 104118 (2022)
14+
.. moduleauthor:: Yuchen Wang
15+
.. module co-author:: Mohammad Shakiba, Alexey V. Akimov, Norah M. Hoffmann
16+
17+
"""
18+
19+
# constants
20+
from dataclasses import dataclass
21+
22+
HARTREE2EV = 27.2116 # constant stays as a constant
23+
24+
# dvr_data
25+
26+
# general nomenclature:
27+
# d_X = [\nabla X] and X_deri = \nabla [X], see reference paper
28+
29+
# solve cavity-free electronic DVR
30+
# eigvals: adiabatic electronic energies
31+
# eigvecs: adiabatic electronic wavefunctions
32+
# d_V: matrix of potential energy gradient [\nabla V]
33+
# nac: non-adiabatic coupling matrix
34+
# mu: dipole moment matrix
35+
# d_mu: dipole moment gradient matrix [\nabla \mu]
36+
# mu_deri: derivative of dipole moment matrix elements \nabla [\mu]
37+
38+
@dataclass
39+
class DVRData:
40+
R_grid: np.ndarray
41+
eigvals: np.ndarray
42+
d_V: np.ndarray
43+
nac: np.ndarray
44+
mu: np.ndarray
45+
d_mu: np.ndarray
46+
mu_deri: np.ndarray
47+
48+
# DVR shin meitu surface was loaded from fitted potential file with HDF5 format
49+
def load_dvr_from_file(filename: str) -> DVRData:
50+
with h5py.File(filename, 'r') as f:
51+
return DVRData(
52+
R_grid=f['R_grid'][:],
53+
eigvals=f['eigvals'][:],
54+
d_V=f['d_V'][:],
55+
nac=f['nac'][:],
56+
mu=f['mu'][:],
57+
d_mu=f['d_mu'][:],
58+
mu_deri=f['mu_deri'][:]
59+
)
60+
#Interpolation of the fitted potential from HDF5 file
61+
def interpolateDVR_from_file(R: float, dvr_data: DVRData):
62+
nelec_dim_dump = dvr_data.eigvals.shape[-1]
63+
64+
eigvals = np.zeros((nelec_dim_dump))
65+
d_V = np.zeros((nelec_dim_dump, nelec_dim_dump))
66+
nac = np.zeros((nelec_dim_dump, nelec_dim_dump))
67+
mu = np.zeros((nelec_dim_dump, nelec_dim_dump))
68+
d_mu = np.zeros((nelec_dim_dump, nelec_dim_dump))
69+
mu_deri = np.zeros((nelec_dim_dump, nelec_dim_dump))
70+
71+
for i in range(nelec_dim_dump):
72+
eigvals[i] = np.interp(R, dvr_data.R_grid, dvr_data.eigvals[:, i])
73+
for j in range(nelec_dim_dump):
74+
d_V[i, j] = np.interp(R, dvr_data.R_grid, dvr_data.d_V[:, i, j])
75+
nac[i, j] = np.interp(R, dvr_data.R_grid, dvr_data.nac[:, i, j])
76+
mu[i, j] = np.interp(R, dvr_data.R_grid, dvr_data.mu[:, i, j])
77+
d_mu[i, j] = np.interp(R, dvr_data.R_grid, dvr_data.d_mu[:, i, j])
78+
mu_deri[i, j] = np.interp(R, dvr_data.R_grid, dvr_data.mu_deri[:, i, j])
79+
80+
return eigvals, d_V, nac, mu, d_mu, mu_deri
81+
82+
#Define parameters for polaritonic effects
83+
def polariton_info(R, dvr_data: DVRData, model='4-state',
84+
g_c=0.005, omega_c=0.1, epsilon=1.0,
85+
force_subspace=True, ndim_elec=None, ndim_ph=None):
86+
87+
assert model in ['2-state', '4-state', 'general'] "Model must be either '2-state' or '4-state'."
88+
89+
if model == 'general':
90+
assert ndim_ph is not None and ndim_ph > 0
91+
92+
if ndim_elec is None:
93+
ndim_elec = 2 if model in ['2-state', '4-state'] else ndim_elec
94+
# Load interpolated values
95+
eigvals, d_V, nac, mu, d_mu, mu_deri = interpolateDVR_from_file(R, dvr_data)
96+
97+
# H_deri = d_H + np.dot(H, nac) - np.dot(nac, H)
98+
H_deri = d_V + np.dot(np.diag(eigvals), nac) - np.dot(nac, np.diag(eigvals)) # (27)
99+
100+
# electronic part of D^2
101+
# assuming polarization direction aligned with dipole
102+
# (31d)
103+
D_square = epsilon**2 *g_c**2 / omega_c * np.dot(mu, mu)
104+
# gradient of D^2
105+
D_square_deri = epsilon**2 *g_c**2 / omega_c * (np.dot(mu, mu_deri) + np.dot(mu_deri, mu))
106+
107+
# d_D_square = epsilon**2 *g_c**2 / omega_c * (np.dot(mu, d_mu) + np.dot(d_mu, mu))
108+
# D_square_deri = d_D_square + np.dot(D_square, nac) - np.dot(nac, D_square) # (27)
109+
110+
# construct Hamiltonian in adiabatic-Fock basis
111+
# although the reference denote it as V but it is actually the Hamiltonian
112+
# Attention: for 2- and 4-state models, the Hamiltonian is shifted by 0.5*omega_c
113+
# to match the reference paper.
114+
if model == '2-state':
115+
# |e_0>, |g_1>
116+
# Eqn. (34)
117+
V_adia_fock = np.zeros((2, 2))
118+
V_adia_fock[0,0] = eigvals[1] + D_square[1,1]
119+
V_adia_fock[0,1] = g_c * epsilon * mu[1,0]
120+
V_adia_fock[1,0] = g_c * epsilon * mu[0,1]
121+
V_adia_fock[1,1] = eigvals[0] + D_square[0,0] + omega_c
122+
# Eqn. (36), in this case, d_V = H_deri
123+
V_deri_adia_fock = np.zeros((2, 2))
124+
V_deri_adia_fock[0,0] = H_deri[1,1] + D_square_deri[1,1]
125+
V_deri_adia_fock[0,1] = g_c * epsilon * mu_deri[1,0]
126+
V_deri_adia_fock[1,0] = g_c * epsilon * mu_deri[0,1]
127+
V_deri_adia_fock[1,1] = H_deri[0,0] + D_square_deri[0,0]
128+
d_V_adia_fock = V_deri_adia_fock.copy()
129+
elif model == '4-state':
130+
# |g_0>, |e_0>, |g_1>, |e_1>
131+
# Eqn. (37)
132+
V_adia_fock = np.zeros((4, 4))
133+
V_adia_fock[0,0] = eigvals[0] + D_square[0,0] + 0.5 * omega_c
134+
V_adia_fock[1,1] = eigvals[1] + D_square[1,1] + 0.5 * omega_c
135+
V_adia_fock[2,2] = eigvals[0] + D_square[0,0] + 1.5 * omega_c
136+
V_adia_fock[3,3] = eigvals[1] + D_square[1,1] + 1.5 * omega_c
137+
V_adia_fock[0,1] = D_square[0,1]
138+
V_adia_fock[2,3] = D_square[0,1]
139+
V_adia_fock[0,2] = g_c * epsilon * mu[0,0]
140+
V_adia_fock[0,3] = g_c * epsilon * mu[0,1]
141+
V_adia_fock[1,2] = g_c * epsilon * mu[1,0]
142+
V_adia_fock[1,3] = g_c * epsilon * mu[1,1]
143+
V_adia_fock[1,0] = V_adia_fock[0,1]
144+
V_adia_fock[3,2] = V_adia_fock[2,3]
145+
V_adia_fock[2,0] = V_adia_fock[0,2]
146+
V_adia_fock[3,0] = V_adia_fock[0,3]
147+
V_adia_fock[2,1] = V_adia_fock[1,2]
148+
V_adia_fock[3,1] = V_adia_fock[1,3]
149+
# Eqn. (38)
150+
nac_adia_fock = np.zeros((4, 4))
151+
nac_adia_fock[0,1] = nac[0,1]
152+
nac_adia_fock[2,3] = nac[0,1]
153+
nac_adia_fock[1,0] = nac[1,0]
154+
nac_adia_fock[3,2] = nac[1,0]
155+
assert np.linalg.norm(nac_adia_fock + nac_adia_fock.T) < 1e-10, \
156+
"Non-adiabatic coupling matrix is not anti-symmetric."
157+
# Eqn. (39)
158+
V_deri_adia_fock = np.zeros((4, 4))
159+
V_deri_adia_fock[0,0] = H_deri[0,0] + D_square_deri[0,0]
160+
V_deri_adia_fock[1,1] = H_deri[1,1] + D_square_deri[1,1]
161+
V_deri_adia_fock[2,2] = H_deri[0,0] + D_square_deri[0,0]
162+
V_deri_adia_fock[3,3] = H_deri[1,1] + D_square_deri[1,1]
163+
V_deri_adia_fock[0,1] = D_square_deri[0,1]
164+
V_deri_adia_fock[2,3] = D_square_deri[0,1]
165+
V_deri_adia_fock[0,2] = g_c * epsilon * mu_deri[0,0]
166+
V_deri_adia_fock[0,3] = g_c * epsilon * mu_deri[0,1]
167+
V_deri_adia_fock[1,2] = g_c * epsilon * mu_deri[1,0]
168+
V_deri_adia_fock[1,3] = g_c * epsilon * mu_deri[1,1]
169+
V_deri_adia_fock[1,0] = V_deri_adia_fock[0,1]
170+
V_deri_adia_fock[3,2] = V_deri_adia_fock[2,3]
171+
V_deri_adia_fock[2,0] = V_deri_adia_fock[0,2]
172+
V_deri_adia_fock[3,0] = V_deri_adia_fock[0,3]
173+
V_deri_adia_fock[2,1] = V_deri_adia_fock[1,2]
174+
V_deri_adia_fock[3,1] = V_deri_adia_fock[1,3]
175+
# (27)
176+
d_V_adia_fock = V_deri_adia_fock - np.dot(V_adia_fock, nac_adia_fock) + np.dot(nac_adia_fock, V_adia_fock)
177+
elif model == 'general':
178+
raise NotImplementedError("General model is not implemented yet.")
179+
else:
180+
raise ValueError("Model must be either '2-state', '4-state', or 'general'.")
181+
182+
return V_adia_fock.copy(), d_V_adia_fock.copy(), nac_adia_fock.copy() # eigvals_polariton, grad_polariton, nac_polariton, eigvecs_polariton
183+
184+
185+
def compute_model(q, params, full_id):
186+
critical_params = []
187+
default_params = {"g_c": 0.005, "omega_c": 0.1, "epsilon": 1.0, "nstates": 4}
188+
comn.check_input(params, default_params, critical_params)
189+
190+
g_c = params["g_c"]
191+
omega_c = params["omega_c"]
192+
epsilon = params["epsilon"]
193+
nstates = params["nstates"]
194+
model = params["model"]
195+
196+
if model == 0:
197+
dvr_file = "dvr_sm1.h5"
198+
elif model == 1:
199+
dvr_file = "dvr_sm2.h5"
200+
else:
201+
raise ValueError(f"Unknown nstates {nstates}")
202+
203+
model_polariton = '2-state' if nstates == 2 else '4-state'
204+
205+
Id = Cpp2Py(full_id)
206+
indx = Id[-1]
207+
R = q.get(0, indx)
208+
209+
# Load DVR data once, no globals
210+
dvr_data = load_dvr_from_file(dvr_file)
211+
212+
V_dia_fock, dV_dia_fock, nac_adia_fock = polariton_info(
213+
R, dvr_data, model_polariton, g_c, omega_c, epsilon
214+
)
215+
216+
H_adia = CMATRIX(nstates, nstates)
217+
S_adia = CMATRIX(nstates, nstates)
218+
d1ham_adia = CMATRIXList()
219+
d1ham_adia.append(CMATRIX(nstates, nstates))
220+
dc1_adia = CMATRIXList()
221+
dc1_adia.append(CMATRIX(nstates, nstates))
222+
223+
for i in range(nstates):
224+
S_adia.set(i, i, 1.0 + 0.0j)
225+
for j in range(nstates):
226+
H_adia.set(i, j, V_dia_fock[i,j]+0.0j)
227+
d1ham_adia[0].set(i, j, dV_dia_fock[i,j]+0.0j)
228+
229+
230+
class tmp:
231+
pass
232+
233+
obj = tmp()
234+
obj.ham_dia = H_adia
235+
obj.ovlp_dia = S_adia
236+
obj.d1ham_dia = d1ham_adia
237+
obj.dc1_dia = dc1_adia
238+
239+
240+
return obj
241+

0 commit comments

Comments
 (0)