step4

libra_py.workflows.nbra.step4.get_Hvib(params)[source]

Read a single set of vibronic Hamiltonian files

Parameters

params (dictionary) –

parameters controlling the function execution

Required parameter keys:

  • params[“nstates”] ( int ): how many lines/columns in the file [Required!]

  • params[“nfiles”] ( int ): how many files to read, starting from index 0 [Required!]

  • params[“Hvib_re_prefix”] ( string ): prefixes of the files with real part of the Hvib(t) [Required!]

  • params[“Hvib_im_prefix”] ( string ): prefixes of the files with imaginary part of the Hvib(t) [Required!]

  • params[“active_space”] ( list of ints ): the indices of the states we care

    about. These indices will be used to determine the size of the created CMATRIX objects and only these states will be extracted from the original files [ default: range(nstates) ]

  • params[“Hvib_re_suffix”] ( string ): suffixes of the files with real part of the Hvib(t) [default: “_re”]

  • params[“Hvib_im_suffix”] ( string ): suffixes of the files with imaginary part of the Hvib(t) [default: “_im”]

Returns

Hvib:

a time series of Hvib matrices, such that Hvib[time] is a Hvib at time step time

Return type

list of CMATRIX objects

Example

This example will read 10 pairs of files: “Hvib_0_re”, “Hvib_0_im”, “Hvib_1_re”, “Hvib_1_im”, … “Hvib_9_re”, “Hvib_9_im”. Each file should contain a 4 x 4 matrix of numbers. It will generate a list of 4 x 4 complex-valued matrices.

>>> hvib = get_Hvib({"nstates":4, "nfiles":10, "Hvib_re_prefix":"Hvib", "Hvib_im_prefix":"Hvib"})

The following example will do the same as the example above, however the intially-read 4 x 4 matrices will be partially discarded. Out of 16 values only 4 (the upper left block of 4 numbers) will be stored in the resulting list of 2 x 2 complex-valued matrices.

>>> hvib = get_Hvib({"nstates":4, "nfiles":10, "Hvib_re_prefix":"Hvib", "Hvib_im_prefix":"Hvib", "active_space":[0,1]})
libra_py.workflows.nbra.step4.get_Hvib2(params)[source]

Reads several sets of vibronic Hamiltonian files

Parameters

params (dictionary) –

parameters controlling the function execution [Required!]

Required parameter keys:

  • params[“data_set_paths”] ( list of strings ):

    define the paths of the directories where the vibronic Hamiltonian files for different data sets (e.g. independent MD trajectories) are located.

Note

In addition, requires parameters described in libra_py.workflows.nbra.step4.getHvib()

Returns

Hvib:

the time series of Hvib matrices for several data sets, such that Hvib[idata][time] is a CMATRIX for the data set indexed by idata at time time

Return type

list of lists of CMATRIX

Example

The full name of the vibronic Hamiltonian files read by this module should be:

params[“data_set_paths”][idata]+params[“Hvib_re_prefix”]+integer(time step)+params[“Hvib_re_suffix”] - for real part

params[“data_set_paths”][idata]+params[“Hvib_im_prefix”]+integer(time step)+params[“Hvib_im_suffix”] - for imaginary part

Say, the directory “/home/alexeyak/test/step3/res0” contains files: Hvib_0_re, Hvib_1_re, …. , Hvib_999_re Hvib_0_im, Hvib_1_im, …. , Hvib_999_im

Then set:

>>> params["data_set_paths"] = ["/home/alexeyak/test/step3/res0/"]
>>> params["Hvib_re_prefix"] = "Hvib_"
>>> params["Hvib_re_suffix"] = "_re"
>>> params["Hvib_im_prefix"] = "Hvib_"
>>> params["Hvib_im_suffix"] = "_im"
libra_py.workflows.nbra.step4.printout(t, res, outfile)[source]

This function does a simple output of a matrix columns to a file

Parameters
  • t (double) – time [units: a.u.]

  • res (MATRIX(1,N)) – information to be printed out

  • outfile (string) – filename where we’ll print everything out, the output will be appended to the existing output file

Returns

but modifies the file

Return type

None

libra_py.workflows.nbra.step4.run(H_vib, params)[source]

The main procedure to run NA-MD calculations within the NBRA workflow

Parameters
  • H_vib (list of lists of CMATRIX objects) – the vibronic Hamiltonian for all data sets and all time-points H_vib[idata][istep].get(i,j) - i,j matrix element for the data set idata and step in that data set istep

  • params (dictionary) –

    the parameters that control the execution of the NA-MD-NBRA calculations

    • params[“nsteps”] ( int ): the length of the NA-MD trajectory. This parameter is not

      necessarily the same as len(H_vib[0]), so need to be provided [Required!]

    • params[“T”] ( double ): temperature of nuclear/electronic dynamics [in K, default: 300.0]

    • params[“ntraj”] ( int ): the number of stochastic surface hopping trajectories [default: 1]

    • params[“tdse_Ham”] ( int ): option to select either the regular (input) or Boltzmann-corrected

      Hamiltonian:

      • 0 - regular [ default ]

      • 1 - Boltzmann-corrected

    • params[“Hvib_type”] ( int ): option to select if the Hvib is a diabatic or an adiabatic

      Hamiltonian:

      • 0 - diabatic

      • 1 - adiabatic [ default ]

    • params[“sh_method”] ( int ): selects the algorithm to compute surface hopping probabilities

      Options:

      • 0 - MSSH

      • 1 - FSSH [ default ]

    • params[“decoherence_constants”] ( int ): selects whether to compute decoherence parameters

      on the fly or to use provided parameters:

      • 0 - pre-compute the parameters from the trajectory data before NA-MD run [ default ]

      • 1 - use the provided parameters ..seealso:: `params["decoherence_times"]` and `params["decoherence_rates"]`

      • 20 - use the time-dependent decoherence times as in DISH paper. This is different from

        option 0 in that these numbers depend on the state amplitudes. Dephasing times are computed as in 0.

      • 21 - use the time-dependent decoherence times as in DISH paper. This is different from

        option 0 in that these numbers depend on the state amplitudes. Dephasing times are computed as in 1.

    • params[“decoherence_times”] ( MATRIX(nstates,nstates) ): decoherence times for all

      pairs of states. This should be provided if ` params["decoherence_constants"] == 1` the dimensions should be consistent with those of the input Hvib data. [ units: a.u. of time ]

    • params[“decoherence_method”] ( int ): selects the decoherence method

      Options:

      • 0 - no decoherence [ default ]

      • 1 - ID-A

      • 2 - MSDM

      • 3 - DISH

    • params[“dt”] ( double ): nuclear dynamics integration time step [in a.u. of time, default: 41.0]

    • params[“Boltz_opt”] ( int ): option to select a probability of hopping acceptance [default: 3]

      Options:

      • 0 - all proposed hops are accepted - no rejection based on energies

      • 1 - proposed hops are accepted with exp(-E/kT) probability - the old (hence the default approach)

      • 2 - proposed hops are accepted with the probability derived from Maxwell-Boltzmann distribution - more rigorous

      • 3 - generalization of “1”, but actually it should be changed in case there are many degenerate levels

    • params[“istate”] ( int ): index of the initial state [default: 0]

    • params[“init_times”] ( list of ints ): indices of the starting point in the provided data arrays [default: [0]]

    • params[“outfile”] ( string ): the name of the file where to print populations

      and energies of states [default: “_out.txt”]

Returns

the trajectory (and initial-condition)-averaged observables for every timesteps,

the assumed format is:

time, first state info … N-st state info All-states-related data

time, E(0), P_SE(0), P_SH(0), …, E(nst-1), P_SE(nst-1), P_SH(nst-1), <E*P_SE>, <E*P_SH>, sum{P_SE}, sum{P_SH}

Return type

MATRIX(nsteps, 3*nstates+5)

libra_py.workflows.nbra.step4.traj_statistics(i, Coeff, istate, Hvib, itimes)[source]

Compute the averages over the TSH-ensembles

Parameters
  • i (int) – timestep index, counting since the beginning of the current sub-trajectory

  • Coeff (list of ntraj CMATRIX(nstates,1) object) – the TD-SE amplitudes for all trajectories (data sets/initial times/stochastic realizations)

  • istate (list of ntraj integers) – indices of the active states for each trajectory (data sets/initial times/stochastic realizations)

  • Hvib (list of lists of CMATRIX(nstates,nstates)) – Hamiltonians for all data sets and all (not just a sub-set of data!) timesteps

  • itimes (list of ints) – indices of the NA-MD starting points (in the global data indexing scale)

Returns

the trajectory (and initial-condition)-averaged observables,

the assumed format is:

First state info … N-st state info All-states-related data

E(0), P_SE(0), P_SH(0), …, E(nst-1), P_SE(nst-1), P_SH(nst-1), <E*P_SE>, <E*P_SH>, sum{P_SE}, sum{P_SH}

Return type

MATRIX(1, 3*nstates+4)

libra_py.workflows.nbra.step4.traj_statistics2(i, Pop, istate, Hvib, itimes)[source]

Compute the averages over the TSH-ensembles

Parameters
  • i (int) – timestep index, counting since the beginning of the current sub-trajectory

  • Pop (list of ntraj CMATRIX(nstates, 1) object) – the qunatum populations for all trajectories (data sets/initial times/stochastic realizations)

  • istate (list of ntraj integers) – indices of the active states for each trajectory (data sets/initial times/stochastic realizations)

  • Hvib (list of lists of CMATRIX(nstates,nstates)) – Hamiltonians for all data sets and all (not just a sub-set of data!) timesteps

  • itimes (list of ints) – indices of the NA-MD starting points (in the global data indexing scale)

Returns

the trajectory (and initial-condition)-averaged observables,

the assumed format is:

First state info … N-st state info All-states-related data

E(0), P_SE(0), P_SH(0), …, E(nst-1), P_SE(nst-1), P_SH(nst-1), <E*P_SE>, <E*P_SH>, sum{P_SE}, sum{P_SH}

Return type

MATRIX(1, 3*nstates+4)

libra_py.workflows.nbra.step4.traj_statistics2_fast(i, Pop, istate, Hvib, itimes)[source]

Compute the averages over the TSH-ensembles

This version is optimized by removing all the dancing around data and doing the direct calculations asap - no intermediate massive memory allocation!

Parameters
  • i (int) – timestep index, counting since the beginning of the current sub-trajectory

  • Pop (list of ntraj CMATRIX(nstates, 1) object) – the quantum populations for all trajectories (data sets/initial times/stochastic realizations)

  • istate (list of ntraj integers) – indices of the active states for each trajectory (data sets/initial times/stochastic realizations)

  • Hvib (list of lists of CMATRIX(nstates,nstates)) – Hamiltonians for all data sets and all (not just a sub-set of data!) timesteps

  • itimes (list of ints) – indices of the NA-MD starting points (in the global data indexing scale)

Returns

the trajectory (and initial-condition)-averaged observables,

the assumed format is:

First state info … N-st state info All-states-related data

E(0), P_SE(0), P_SH(0), …, E(nst-1), P_SE(nst-1), P_SH(nst-1), <E*P_SE>, <E*P_SH>, sum{P_SE}, sum{P_SH}

Return type

MATRIX(1, 3*nstates+4)