Skip to content

Commit 20bf3bf

Browse files
committed
Fixed a number of other small problems introduced with the isNBRA and that prevented some scripts from running
1 parent eb51323 commit 20bf3bf

File tree

1 file changed

+36
-27
lines changed

1 file changed

+36
-27
lines changed

src/libra_py/dynamics/tsh/compute.py

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -925,14 +925,6 @@ def run_dynamics(_q, _p, _iM, _Cdia, _Cadi, _projectors, _states, _dyn_params, c
925925
decoherence_algo = dyn_params["decoherence_algo"]
926926
is_nbra = dyn_params["is_nbra"]
927927

928-
ndia = Cdia.num_of_rows
929-
nadi = Cadi.num_of_rows
930-
nnucl= q.num_of_rows
931-
ntraj= q.num_of_cols
932-
933-
if(dyn_params["quantum_dofs"]==None):
934-
dyn_params["quantum_dofs"] = list(range(nnucl))
935-
936928

937929
q = MATRIX(_q)
938930
p = MATRIX(_p)
@@ -941,13 +933,23 @@ def run_dynamics(_q, _p, _iM, _Cdia, _Cadi, _projectors, _states, _dyn_params, c
941933
Cadi = CMATRIX(_Cadi)
942934
states = intList()
943935
projectors = CMATRIXList()
936+
937+
ndia = Cdia.num_of_rows
938+
nadi = Cadi.num_of_rows
939+
nnucl= q.num_of_rows
940+
ntraj= q.num_of_cols
941+
nstates = len(_states)
942+
943+
if(dyn_params["quantum_dofs"]==None):
944+
dyn_params["quantum_dofs"] = list(range(nnucl))
945+
944946

945947
if is_nbra == 1:
946-
for i in range(len(_states)):
948+
for i in range(nstates):
947949
states.append(_states[i])
948950
projectors.append(CMATRIX(_projectors[0]))
949951
else:
950-
for i in range(len(_states)):
952+
for i in range(nstates):
951953
states.append(_states[i])
952954
projectors.append(CMATRIX(_projectors[i]))
953955

@@ -1024,8 +1026,8 @@ def run_dynamics(_q, _p, _iM, _Cdia, _Cadi, _projectors, _states, _dyn_params, c
10241026
elif rep_tdse==1:
10251027
ham.ampl_adi2dia(Cdia, Cadi, 0, 1)
10261028

1027-
dm_dia, dm_adi, dm_dia_raw, dm_adi_raw = tsh_stat.compute_dm(ham, Cdia, Cadi, projectors, rep_tdse, 1, dyn_params["isNBRA"])
1028-
pops, pops_raw = tsh_stat.compute_sh_statistics(nadi, states, projectors, dyn_params["isNBRA"])
1029+
dm_dia, dm_adi, dm_dia_raw, dm_adi_raw = tsh_stat.compute_dm(ham, Cdia, Cadi, projectors, rep_tdse, 1, is_nbra)
1030+
pops, pops_raw = tsh_stat.compute_sh_statistics(nadi, states, projectors, is_nbra)
10291031
# Energies
10301032
Ekin, Epot, Etot, dEkin, dEpot, dEtot = 0.0, 0.0, 0.0, 0.0, 0.0, 0.0
10311033
Etherm, E_NHC = 0.0, 0.0
@@ -1161,49 +1163,56 @@ def generic_recipe(q, p, iM, _dyn_params, compute_model, _model_params, _init_el
11611163
11621164
"""
11631165

1164-
comn.check_input(_model_params, { }, [ "model0" ] )
1165-
comn.check_input(_dyn_params, { "rep_tdse":1 }, [ ] )
1166+
model_params = dict(_model_params)
1167+
dyn_params = dict(_dyn_params)
1168+
init_elec = dict(_init_elec)
1169+
1170+
comn.check_input( model_params, { }, [ "model0" ] )
1171+
comn.check_input( dyn_params, { "rep_tdse":1, "is_nbra":0 }, [ ] )
11661172

1173+
is_nbra = dyn_params["is_nbra"]
1174+
1175+
init_elec.update({"is_nbra":is_nbra})
11671176

11681177

11691178
# Internal parameters
11701179
nnucl, ntraj = q.num_of_rows, q.num_of_cols
11711180

11721181
# Initialize electronic variables - either diabatic or adiabatic
1173-
Cdia, Cadi, projectors, states = init_electronic_dyn_var(_init_elec, _dyn_params["isNBRA"], rnd)
1182+
Cdia, Cadi, projectors, states = init_electronic_dyn_var(init_elec, rnd)
11741183
ndia, nadi = Cdia.num_of_rows, Cadi.num_of_rows
11751184

11761185

11771186
# In case the initial conditions rep and the propagation rep are different,
11781187
# compute the diabatic-to-adiabatic transformation matrices and
11791188
# transform the amplitudes accordingly
11801189
ham = nHamiltonian(ndia, nadi, nnucl)
1181-
if _dyn_params["isNBRA"]==1:
1190+
if is_nbra == 1:
11821191
ham.add_new_children(ndia, nadi, nnucl, 1)
11831192
else:
11841193
ham.add_new_children(ndia, nadi, nnucl, ntraj)
11851194
ham.init_all(2,1)
11861195

1187-
if _init_elec["rep"]==0:
1188-
if _dyn_params["rep_tdse"]==1:
1189-
model_params = dict(_model_params)
1190-
model_params.update({"model":_model_params["model0"]})
1191-
update_Hamiltonian_q({"rep_tdse":1, "rep_ham":0}, q, projectors, ham, compute_model, model_params )
1196+
if init_elec["rep"]==0:
1197+
if dyn_params["rep_tdse"]==1:
1198+
model_params1 = dict(model_params)
1199+
model_params1.update({"model":model_params["model0"]})
1200+
update_Hamiltonian_q({"rep_tdse":1, "rep_ham":0}, q, projectors, ham, compute_model, model_params1 )
11921201

11931202
Cadi = transform_amplitudes(0, 1, Cdia, ham)
11941203

1195-
elif _init_elec["rep"]==1:
1196-
if _dyn_params["rep_tdse"]==0:
1197-
model_params = dict(_model_params)
1198-
model_params.update({"model":_model_params["model0"]})
1199-
update_Hamiltonian_q({"rep_tdse":1, "rep_ham":0}, q, projectors, ham, compute_model, model_params )
1204+
elif init_elec["rep"]==1:
1205+
if dyn_params["rep_tdse"]==0:
1206+
model_params1 = dict(model_params)
1207+
model_params1.update({"model":model_params["model0"]})
1208+
update_Hamiltonian_q({"rep_tdse":1, "rep_ham":0}, q, projectors, ham, compute_model, model_params1 )
12001209

12011210
Cdia = transform_amplitudes(1, 0, Cdia, ham)
12021211

12031212
#if _dyn_params["isNBRA"]==1:
12041213
# res = run_dynamics_nbra(q, p, iM, Cdia, Cadi, projectors, states, _dyn_params, compute_model, _model_params, rnd)
12051214
#else:
1206-
res = run_dynamics(q, p, iM, Cdia, Cadi, projectors, states, _dyn_params, compute_model, _model_params, rnd)
1215+
res = run_dynamics(q, p, iM, Cdia, Cadi, projectors, states, _dyn_params, compute_model, model_params, rnd)
12071216

12081217
return res
12091218

0 commit comments

Comments
 (0)