Skip to content

Commit 58cfd6e

Browse files
committed
Merge branch 'devel'
2 parents 334d449 + 7428ccf commit 58cfd6e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+4761
-254
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,11 @@ Next, all what we actually need:
138138
conda install -y -c psi4/label/dev libint2=2.7.1
139139
conda install -y -c anaconda h5py gmp
140140

141+
142+
Installation instruction of Scikit-learn from its official website:
143+
144+
pip install -U scikit-learn
145+
141146

142147
>
143148
> YES - IT GOT SMALLER AND MORE COMPACT !

src/dyn/Dynamics.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,9 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
12951295
// Recompute diabatic/adiabatic states, time-overlaps, NAC, Hvib, etc. in response to change of q
12961296
update_Hamiltonian_variables(prms, dyn_var, ham, ham_aux, py_funct, params, 0);
12971297

1298+
// Copy diabatic-to-adiabatic basis transformation to the dynamical variable
1299+
dyn_var.update_basis_transform(ham);
1300+
12981301
// Recompute the orthogonalized reprojection matrices, stored in dyn_var.proj_adi
12991302
// this calculaitons used ham.children[i].time_overlap matrix, updated in the previous step
13001303
update_proj_adi(prms, dyn_var, ham);
@@ -1326,15 +1329,20 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
13261329
}
13271330

13281331
// Recompute density matrices in response to the updated amplitudes
1329-
dyn_var.update_amplitudes(prms, ham);
1330-
dyn_var.update_density_matrix(prms, ham, 1);
1332+
// dyn_var.update_amplitudes(prms, ham);
1333+
dyn_var.update_amplitudes(prms);
1334+
// dyn_var.update_density_matrix(prms, ham, 1);
1335+
dyn_var.update_density_matrix(prms);
13311336

13321337
vector<int> old_states( dyn_var.act_states);
13331338

13341339
// In the interval [t, t + dt], we may have experienced the basis reordering, so we need to
13351340
// change the active adiabatic state
1336-
if(prms.tsh_method != 3 && prms.tsh_method != 4 ){ // Don't update states based on amplitudes, in the LZ method
1337-
dyn_var.update_active_states(1, 0); // 1 - forward; 0 - only active state
1341+
if(prms.tsh_method == 3 or prms.tsh_method == 4 ){
1342+
// Don't update states based on amplitudes, in the LZ method
1343+
;;
1344+
}
1345+
else{ dyn_var.update_active_states(1, 0); // 1 - forward; 0 - only active state
13381346
}
13391347

13401348
// For now, this function also accounts for the kinetic energy adjustments to reflect the adiabatic evolution
@@ -1406,6 +1414,10 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
14061414
decoherence_rates = schwartz_2(prms, ham, *prms.schwartz_decoherence_inv_alpha);
14071415
}
14081416

1417+
else if(prms.decoherence_times_type==4){
1418+
decoherence_rates = schwartz_1(prms, *dyn_var.ampl_adi, *dyn_var.p, ham, *prms.schwartz_interaction_width);
1419+
}
1420+
14091421
///== Optionally, apply the dephasing-informed correction ==
14101422
if(prms.dephasing_informed==1){
14111423
Eadi = get_Eadi(ham);
@@ -1438,7 +1450,7 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
14381450
if(prms.rep_tdse==1){
14391451
p = *dyn_var.p;
14401452
//cout<<"p before mfsd\n"; dyn_var.p->show_matrix();
1441-
*dyn_var.ampl_adi = mfsd(p, *dyn_var.ampl_adi, *dyn_var.iM, prms.dt, decoherence_rates, ham, rnd, prms.isNBRA);
1453+
*dyn_var.ampl_adi = mfsd(p, *dyn_var.ampl_adi, *dyn_var.iM, prms.dt, dyn_var.act_states, decoherence_rates, ham, rnd, prms.isNBRA);
14421454
*dyn_var.p = p;
14431455
//cout<<"p after mfsd\n"; dyn_var.p->show_matrix();
14441456

@@ -1464,25 +1476,28 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
14641476

14651477

14661478
// Update amplitudes and density matrices in response to decoherence corrections
1467-
dyn_var.update_amplitudes(prms, ham);
1468-
dyn_var.update_density_matrix(prms, ham, 1);
1479+
// dyn_var.update_amplitudes(prms, ham);
1480+
dyn_var.update_amplitudes(prms);
1481+
// dyn_var.update_density_matrix(prms, ham, 1);
1482+
dyn_var.update_density_matrix(prms);
14691483

14701484

14711485
//************************************ TSH options ****************************************
14721486
// Adiabatic dynamics
14731487
if(prms.tsh_method==-1){ ;; }
14741488

1475-
// FSSH, GFSH, MSSH, LZ, ZN, DISH, MASH, FSSH2
1489+
// FSSH, GFSH, MSSH, LZ, ZN, DISH, MASH, FSSH2, FSSH3
14761490
else if(prms.tsh_method == 0 || prms.tsh_method == 1 || prms.tsh_method == 2 || prms.tsh_method == 3
1477-
|| prms.tsh_method == 4 || prms.tsh_method == 5 || prms.tsh_method == 6 || prms.tsh_method == 7){
1491+
|| prms.tsh_method == 4 || prms.tsh_method == 5 || prms.tsh_method == 6 || prms.tsh_method == 7
1492+
|| prms.tsh_method == 8 ){
14781493

14791494

14801495
vector<int> old_states(dyn_var.act_states);
14811496
//========================== Hop proposal and acceptance ================================
14821497

1483-
// FSSH (0), GFSH (1), MSSH (2), LZ(3), ZN (4), MASH(6), FSSH2(7)
1498+
// FSSH (0), GFSH (1), MSSH (2), LZ(3), ZN (4), MASH(6), FSSH2(7), FSSH3(8)
14841499
if(prms.tsh_method == 0 || prms.tsh_method == 1 || prms.tsh_method == 2 || prms.tsh_method == 3
1485-
|| prms.tsh_method == 4 || prms.tsh_method == 6 || prms.tsh_method == 7 ){
1500+
|| prms.tsh_method == 4 || prms.tsh_method == 6 || prms.tsh_method == 7 || prms.tsh_method == 8){
14861501

14871502
/// Compute hop proposal probabilities from the active state of each trajectory to all other states
14881503
/// of that trajectory
@@ -1549,15 +1564,17 @@ void compute_dynamics(dyn_variables& dyn_var, bp::dict dyn_params,
15491564
// Update vib Hamiltonian to reflect the change of the momentum
15501565
update_Hamiltonian_variables(prms, dyn_var, ham, ham_aux, py_funct, params, 1);
15511566

1552-
}// tsh_method == 0, 1, 2, 3, 4, 5
1567+
}// tsh_method == 0, 1, 2, 3, 4, 5, 6, 7, 8
15531568

15541569
else{ cout<<"tsh_method == "<<prms.tsh_method<<" is undefined.\nExiting...\n"; exit(0); }
15551570

15561571

15571572
// Update the amplitudes and DM, in response to state hopping and other changes in the TSH part
15581573
// so that we have them consistent in the output
1559-
dyn_var.update_amplitudes(prms, ham);
1560-
dyn_var.update_density_matrix(prms, ham, 1);
1574+
// dyn_var.update_amplitudes(prms, ham);
1575+
dyn_var.update_amplitudes(prms);
1576+
// dyn_var.update_density_matrix(prms, ham, 1);
1577+
dyn_var.update_density_matrix(prms);
15611578

15621579

15631580
// Saves the current density matrix into the previous - needed for FSSH2

src/dyn/dyn_control_params.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*********************************************************************************
2-
* Copyright (C) 2019-2022 Alexey V. Akimov
2+
* Copyright (C) 2019-2024 Alexey V. Akimov
33
*
44
* This file is distributed under the terms of the GNU General Public License
55
* as published by the Free Software Foundation, either version 3 of
@@ -64,14 +64,27 @@ dyn_control_params::dyn_control_params(){
6464
tsh_method = 0;
6565
hop_acceptance_algo = 0;
6666
momenta_rescaling_algo = 0;
67+
use_Jasper_Truhlar_criterion = 1;
6768
use_boltz_factor = 0;
6869

70+
///================= FSSH2 specific ====================
71+
fssh2_revision = 0;
72+
73+
///================= FSSH3 specific ====================
74+
fssh3_size_option = 1;
75+
fssh3_approach_option = 0;
76+
fssh3_decomp_option = 3;
77+
fssh3_dt = 0.001;
78+
fssh3_max_steps = 1000;
79+
fssh3_err_tol = 1e-7;
80+
6981
///================= Decoherence options =========================================
7082
decoherence_algo = -1;
7183
sdm_norm_tolerance = 0.0;
7284
dish_decoherence_event_option = 1;
7385
decoherence_times_type = -1;
7486
schwartz_decoherence_inv_alpha = NULL;
87+
schwartz_interaction_width = NULL;
7588
decoherence_C_param = 1.0;
7689
decoherence_eps_param = 0.1;
7790
dephasing_informed = 0;
@@ -151,8 +164,20 @@ dyn_control_params::dyn_control_params(const dyn_control_params& x){
151164
tsh_method = x.tsh_method;
152165
hop_acceptance_algo = x.hop_acceptance_algo;
153166
momenta_rescaling_algo = x.momenta_rescaling_algo;
167+
use_Jasper_Truhlar_criterion = x.use_Jasper_Truhlar_criterion;
154168
use_boltz_factor = x.use_boltz_factor;
155169

170+
///================= FSSH2 specific ====================
171+
fssh2_revision = x.fssh2_revision;
172+
173+
///================= FSSH3 specific ====================
174+
fssh3_size_option = x.fssh3_size_option;
175+
fssh3_approach_option = x.fssh3_approach_option;
176+
fssh3_decomp_option = x.fssh3_decomp_option;
177+
fssh3_dt = x.fssh3_dt;
178+
fssh3_max_steps = x.fssh3_max_steps;
179+
fssh3_err_tol = x.fssh3_err_tol;
180+
156181
///================= Decoherence options =========================================
157182
decoherence_algo = x.decoherence_algo;
158183
sdm_norm_tolerance = x.sdm_norm_tolerance;
@@ -207,6 +232,9 @@ dyn_control_params::dyn_control_params(const dyn_control_params& x){
207232

208233
schwartz_decoherence_inv_alpha = new MATRIX( x.schwartz_decoherence_inv_alpha->n_rows, x.schwartz_decoherence_inv_alpha->n_cols );
209234
*schwartz_decoherence_inv_alpha = *x.schwartz_decoherence_inv_alpha;
235+
236+
schwartz_interaction_width = new MATRIX( x.schwartz_interaction_width->n_rows, x.schwartz_interaction_width->n_cols );
237+
*schwartz_interaction_width = *x.schwartz_interaction_width;
210238

211239
thermally_corrected_nbra = x.thermally_corrected_nbra;
212240
total_energy = x.total_energy;
@@ -224,6 +252,7 @@ dyn_control_params::~dyn_control_params() {
224252
delete decoherence_rates;
225253
delete ave_gaps;
226254
delete schwartz_decoherence_inv_alpha;
255+
delete schwartz_interaction_width;
227256
}
228257

229258

@@ -326,8 +355,20 @@ void dyn_control_params::set_parameters(bp::dict params){
326355
else if(key=="tsh_method") { tsh_method = bp::extract<int>(params.values()[i]); }
327356
else if(key=="hop_acceptance_algo") { hop_acceptance_algo = bp::extract<int>(params.values()[i]); }
328357
else if(key=="momenta_rescaling_algo"){ momenta_rescaling_algo = bp::extract<int>(params.values()[i]); }
358+
else if(key=="use_Jasper_Truhlar_criterion"){ use_Jasper_Truhlar_criterion = bp::extract<int>(params.values()[i]); }
329359
else if(key=="use_boltz_factor"){ use_boltz_factor = bp::extract<int>(params.values()[i]); }
330360

361+
///================= FSSH2 specific ====================
362+
else if(key=="fssh2_revision"){ fssh2_revision = bp::extract<int>(params.values()[i]); }
363+
364+
///================= FSSH3 specific ====================
365+
else if(key=="fssh3_size_option"){ fssh3_size_option = bp::extract<int>(params.values()[i]); }
366+
else if(key=="fssh3_approach_option"){ fssh3_approach_option = bp::extract<int>(params.values()[i]); }
367+
else if(key=="fssh3_decomp_option"){ fssh3_decomp_option = bp::extract<int>(params.values()[i]); }
368+
else if(key=="fssh3_dt"){ fssh3_dt = bp::extract<double>(params.values()[i]); }
369+
else if(key=="fssh3_max_steps"){ fssh3_max_steps = bp::extract<int>(params.values()[i]); }
370+
else if(key=="fssh3_err_tol"){ fssh3_err_tol = bp::extract<double>(params.values()[i]); }
371+
331372
///================= Decoherence options =========================================
332373
else if(key=="decoherence_algo"){ decoherence_algo = bp::extract<int>(params.values()[i]); }
333374
else if(key=="sdm_norm_tolerance"){ sdm_norm_tolerance = bp::extract<double>(params.values()[i]); }
@@ -340,6 +381,13 @@ void dyn_control_params::set_parameters(bp::dict params){
340381
for(int b=0;b<x.n_cols;b++){ schwartz_decoherence_inv_alpha->set(a, b, x.get(a,b)); }
341382
}
342383
}
384+
else if(key=="schwartz_interaction_width"){
385+
MATRIX x( bp::extract<MATRIX>(params.values()[i]) );
386+
schwartz_interaction_width = new MATRIX(x.n_rows, x.n_cols);
387+
for(int a=0;a<x.n_rows;a++){
388+
for(int b=0;b<x.n_cols;b++){ schwartz_interaction_width->set(a, b, x.get(a,b)); }
389+
}
390+
}
343391
else if(key=="decoherence_C_param"){ decoherence_C_param = bp::extract<double>(params.values()[i]); }
344392
else if(key=="decoherence_eps_param"){ decoherence_eps_param = bp::extract<double>(params.values()[i]); }
345393
else if(key=="dephasing_informed"){ dephasing_informed = bp::extract<int>(params.values()[i]); }

src/dyn/dyn_control_params.h

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ class dyn_control_params{
309309
- 5: DISH
310310
- 6: MASH
311311
- 7: FSSH2
312+
- 8: FSSH3 - experimental
312313
*/
313314
int tsh_method;
314315

@@ -358,6 +359,23 @@ class dyn_control_params{
358359
*/
359360
int momenta_rescaling_algo;
360361

362+
363+
/**
364+
A flag to turn on/off the Jasper-Truhlar criterion for reversal of velocities on frustrated hops.
365+
According to: Jasper, A. W.; Truhlar, D. G. Chem. Phys. Lett. 2003, 369, 60− 67
366+
367+
Options:
368+
369+
- 0: don't use this criterion (naive handling)
370+
- 1: use it [ default ] - the velocities are reversed along the direction d_{a,j} if
371+
a) (F_a * d_{a,j}) * (F_j * d_{a,j}) < 0 and b) (v * d_{a,j}) * (F_j * d_{a,j}) < 0
372+
where a - is the active state index; Only in effect, if `momenta_rescaling_algo == 201`
373+
374+
375+
*/
376+
int use_Jasper_Truhlar_criterion;
377+
378+
361379
/**
362380
A flag to scale the proposed hopping probabilities by the
363381
Boltzmann factor. This is needed for the libra_py/workflows/nbra calculations, where the hop proposal
@@ -371,6 +389,72 @@ class dyn_control_params{
371389
int use_boltz_factor;
372390

373391

392+
//=========== FSSH2 options ==========
393+
/**
394+
Whether to use the revised FSSH2
395+
396+
Options:
397+
398+
- 0: use the FSSH2 as it was formulated in the original paper [ default ]
399+
- 1: apply the revised version
400+
*/
401+
int fssh2_revision;
402+
403+
404+
//=========== FSSH3 options ==========
405+
/**
406+
The size of the vectorized density matrix in equations to determine hopping probabilites/fluxes
407+
408+
Options:
409+
410+
- 0: N elements - only populations; the matrices are overdetermined
411+
- 1: N^2 elements - first N elements are populations, then Re and Im parts of upper-triangular coherences
412+
that is rho_{0,1}, rho_{0,2}, ... rho_{0,N-1}, rho_{1,2}, ... rho_{1,N-1}, ... rho_{N-2,N-1} [ default ]
413+
*/
414+
int fssh3_size_option;
415+
416+
/**
417+
The approach to determine the hopping probabilities:
418+
419+
Options:
420+
421+
- 0: based on master equation, rho(t+dt) = J * rho(t); J matrix contains hopping probabilities directly [ defualt ]
422+
- 1: based on kinetic approach, drho/dt = J * rho; J matrix contains fluxes
423+
*/
424+
int fssh3_approach_option;
425+
426+
/**
427+
The matrix decomposition method for solving the least-squares problem
428+
429+
Options:
430+
- 0: bdcSvd
431+
- 1: fullPivLu
432+
- 2: fullPivHouseholderQr
433+
- 3: completeOrthogonalDecomposition [ default ]
434+
*/
435+
int fssh3_decomp_option;
436+
437+
438+
/**
439+
The time-step of the optimization procedure in the FSSH3 calculations
440+
Default: 0.001
441+
*/
442+
double fssh3_dt;
443+
444+
445+
/**
446+
The maximal number of steps in the FSSH3 optimization step
447+
Default: 1000
448+
*/
449+
int fssh3_max_steps;
450+
451+
452+
/**
453+
FSSH3 error tolerance
454+
Default: 1e-7
455+
*/
456+
double fssh3_err_tol;
457+
374458

375459
///===============================================================================
376460
///================= Decoherence options =========================================
@@ -437,6 +521,12 @@ class dyn_control_params{
437521
computing decoherence rates [ default: NULL ]
438522
*/
439523
MATRIX* schwartz_decoherence_inv_alpha;
524+
525+
/**
526+
MATRIX(ndof, 1) - the parameters for the spatial extent of NAC in
527+
computing decoherence rates [ default: NULL ]
528+
*/
529+
MATRIX* schwartz_interaction_width;
440530

441531

442532
/**

src/dyn/dyn_decoherence.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ CMATRIX bcsh(CMATRIX& Coeff, double dt, vector<int>& act_states, MATRIX& reversa
7070

7171

7272
// For MF-SD of Schwartz
73-
CMATRIX mfsd(MATRIX& p, CMATRIX& Coeff, MATRIX& invM, double dt, vector<MATRIX>& decoherence_rates, nHamiltonian& ham, Random& rnd, int isNBRA);
74-
CMATRIX mfsd(MATRIX& p, CMATRIX& Coeff, MATRIX& invM, double dt, vector<MATRIX>& decoherence_rates, nHamiltonian& ham, Random& rnd);
73+
CMATRIX mfsd(MATRIX& p, CMATRIX& Coeff, MATRIX& invM, double dt, vector<int>& act_st, vector<MATRIX>& decoherence_rates, nHamiltonian& ham, Random& rnd, int isNBRA);
74+
CMATRIX mfsd(MATRIX& p, CMATRIX& Coeff, MATRIX& invM, double dt, vector<int>& act_st, vector<MATRIX>& decoherence_rates, nHamiltonian& ham, Random& rnd);
7575

7676
// Independent-trajectory XF methods
7777
void xf_hop_reset(dyn_variables& dyn_var, vector<int>& accepted_states, vector<int>& initial_states);
@@ -107,6 +107,7 @@ MATRIX coherence_intervals(CMATRIX& Coeff, MATRIX& rates);
107107
MATRIX coherence_intervals(CMATRIX& Coeff, vector<MATRIX>& rates);
108108

109109
vector<MATRIX> schwartz_1(dyn_control_params& prms, CMATRIX& amplitudes, nHamiltonian& ham, MATRIX& inv_alp);
110+
vector<MATRIX> schwartz_1(dyn_control_params& prms, CMATRIX& amplitudes, MATRIX& p, nHamiltonian& ham, MATRIX& inv_alp);
110111
vector<MATRIX> schwartz_2(dyn_control_params& prms, nHamiltonian& ham, MATRIX& inv_alp);
111112

112113

0 commit comments

Comments
 (0)