Example #1
0
def run_nbra_namd_wrapper(hvib, istate, outfile_name, params):
    """
    A small wrapper function to run the nbra namd dynamics. 
        hvib ( list of list of matrices ): The vibronic hamiltonian for all timesteps
        istate ( int ): Index of the initial state. This index is from 0
        outfile ( string ): The name of the output file
        params ( dict ): A dictionary of important dynamical parameters
    returns: A list of energy values that is the electronic energy vs time. Returned energy is in eV
    """

    print("decoherence_method = ", params["decoherence_method"])
    params["outfile"] = outfile_name
    params["nstates"] = hvib[0].num_of_rows
    params["istate"] = istate
    res_nbra_namd = step4.run([hvib], params)
    nbra_namd = data_conv.MATRIX2nparray(res_nbra_namd)
    # For SH energies
    energy_nbra_namd = (nbra_namd[:, 3 * params["nstates"] + 2] -
                        nbra_namd[:, 1]) * units.au2ev
    return energy_nbra_namd
            "Boltz_opt"] = 1  # options: 0 (no), 1 (Pyxaid), 2 (Classical), 3 (N-state Boltzmann)

        # Set initial Electronic states
        params["istate"] = j  # indexing here begins from 0, the last is 16

        # Set initial Times
        init_times = []
        for k in xrange(20):
            init_times.append(k * 50 + 1000)
        params[
            "init_times"] = init_times  # starting points for sub-trajectories

        # Set  output file
        params["outfile"] = "_out_" + str(
            params["decoherence_method"]) + "_" + str(
                params["istate"]) + ".txt"  # output file

        # For running NA-MD
        #        Hvib = step4.get_Hvib2(params)      # get the Hivib for all data stes. Hvib is a list of lists

        # Compute avergae band gap:
        # avg_gap = decoherence_times.energy_gaps_av(Hvib, params["init_times"], params["nsteps"])

        # Apply rigid energy shift to data
        # data_con.scissor(Hvib, 1, shift)

        # Optional: Print decoherence times

        # Run NA-MD
        res = step4.run(Hvib, params)
Example #3
0
params["nfiles"] = 30

# Normal example
params["data_set_paths"] = [
    "/mnt/c/cygwin/home/Alexey-user/Programming/Project_libra/tests/example_workflows/pyxaid2/example_1_Si/step3/res_setup1/"
]

# Pretend we have 2 directories:
#params["data_set_paths"].append("/mnt/c/cygwin/home/Alexey-user/Programming/Project_libra/tests/example_workflows/pyxaid2/example_1_Si/step3/res_setup1/")

params["Hvib_re_prefix"] = "Hvib_"
params["Hvib_re_suffix"] = "_re"
params["Hvib_im_prefix"] = "Hvib_"
params["Hvib_im_suffix"] = "_im"

# General simulaiton parameters
params["T"] = 300.0  # Temperature, K
params["ntraj"] = 10  # how many stochastic trajectories
params["sh_method"] = 1  # 0 - MSSH, 1 - FSSH
params[
    "decoherence_method"] = 0  # 0 - no decoherence, 1 - decoherence (ID-A), 2 - MSDM, 3 - DISH
params["dt"] = 41.3413  # Nuclear dynamics integration timestep, in a.u.
params["nsteps"] = 10  # The length of the NA-MD trajectory
params["Boltz_opt"] = 3  # Option for the frustrated hops acceptance/rejection
params[
    "istate"] = 3  # The index of the starting excited state (indexing from 0)
params["init_times"] = [0, 15]  # starting points for sub-trajectories
params["outfile"] = "_out.txt"  # output file

step4.run(params)
Example #4
0
def myfunc(subtraj):

    start_time = subtraj * subtraj_increment

    print("\nsubtraj ", subtraj)
    print("start time = ", start_time)
    print("end time   = ", start_time + subtraj_len)

    md_time = [i for i in range(subtraj_len)]
    md_time = np.array(md_time) * params["dt"] * units.au2fs

    # Obtain the subtrajectory
    for i in range(start_time, start_time + subtraj_len):
        hvib_mb_subtrajs[subtraj].append(hvib_mb[0][i])
        hvib_sd_subtrajs[subtraj].append(hvib_sd[0][i])

    # Compute mb energy gaps and decoherence times
    params["nsteps"] = subtraj_len
    params["init_times"] = [0]
    tau_mb, rates_mb = decoherence_times.decoherence_times(
        hvib_mb_subtrajs[subtraj])
    dE_mb = decoherence_times.energy_gaps(hvib_mb_subtrajs[subtraj])
    avg_deco_mb = tau_mb * units.au2fs
    print("Finished gather data for MD time",
          params["init_times"][0] + params["nsteps"], "steps.")
    print("Dephasing time between mb states 0 and 1 is:",
          tau_mb.get(0, 1) * units.au2fs, "fs")

    # Compute sd energy gaps and decoherence times
    params["nsteps"] = subtraj_len
    params["init_times"] = [0]
    tau_sd, rates_sd = decoherence_times.decoherence_times(
        hvib_sd_subtrajs[subtraj])
    dE_sd = decoherence_times.energy_gaps(hvib_sd_subtrajs[subtraj])
    avg_deco_sd = tau_sd * units.au2fs
    print("Finished gather data for MD time",
          params["init_times"][0] + params["nsteps"], "steps.")
    print("Dephasing time between sd states 0 and 1 is:",
          tau_sd.get(0, 1) * units.au2fs, "fs")

    # Compute mb energies
    mb_subtraj_energy = []
    params["nstates"] = 31
    for mb_index in range(params["nstates"]):
        mb_subtraj_energy.append([])
        for step in range(params["nsteps"]):
            mb_subtraj_energy[mb_index].append(
                hvib_mb_subtrajs[subtraj][step].get(mb_index, mb_index).real -
                hvib_mb_subtrajs[subtraj][step].get(0, 0).real)
    mb_subtraj_energy = np.array(mb_subtraj_energy)
    tmp_mb_energies.append(mb_subtraj_energy)

    # Compute sd energies
    params["nstates"] = 64
    sd_subtraj_energy = []
    for sd_index in range(params["nstates"]):
        sd_subtraj_energy.append([])
        for step in range(params["nsteps"]):
            sd_subtraj_energy[sd_index].append(
                hvib_sd_subtrajs[subtraj][step].get(sd_index, sd_index).real -
                hvib_sd_subtrajs[subtraj][step].get(0, 0).real)
    sd_subtraj_energy = np.array(sd_subtraj_energy)
    tmp_sd_energies.append(sd_subtraj_energy)

    ###############################################
    ###############################################
    # Now it is time to run the NAMD
    params["T"] = 300.0
    params["ntraj"] = 250
    params["sh_method"] = 1
    params["Boltz_opt"] = 1

    params["nsteps"] = subtraj_len
    params["init_times"] = [0]

    istates = [14, 18]

    for istate in istates:

        params["istate"] = istate  # Recall index from 0

        ### FSSH
        params["decoherence_method"] = 0
        start = time.time()
        # mb fssh
        params["outfile"] = "_out_mb_fssh_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 31  # total number of mb electronic states
        res_mb_fssh = step4.run([hvib_mb_subtrajs[subtraj]], params)
        mb_nbra_namd = data_conv.MATRIX2nparray(res_mb_fssh)
        tmp_fssh_mb.append(mb_nbra_namd)
        mb_hot_energy_fssh = (mb_nbra_namd[:, 95] -
                              mb_nbra_namd[:, 1]) * units.au2ev
        #sys.exit(0)

        #sd fssh
        params["outfile"] = "_out_sd_fssh_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 64  # total number of sd electronic states
        res_sd_fssh = step4.run([hvib_sd_subtrajs[subtraj]], params)
        sd_nbra_namd = data_conv.MATRIX2nparray(res_sd_fssh)
        tmp_fssh_sd.append(sd_nbra_namd)
        sd_hot_energy_fssh = (sd_nbra_namd[:, 194] -
                              sd_nbra_namd[:, 1]) * units.au2ev
        end = time.time()
        print("Time to run NBRA NAMD = ", end - start)

        ### IDA
        params["decoherence_method"] = 1
        start = time.time()
        # mb ida
        params["outfile"] = "_out_mb_ida_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 31  # total number of mb electronic states
        res_mb_ida = step4.run([hvib_mb_subtrajs[subtraj]], params)
        mb_nbra_namd = data_conv.MATRIX2nparray(res_mb_ida)
        tmp_ida_mb.append(mb_nbra_namd)
        mb_hot_energy_ida = (mb_nbra_namd[:, 95] -
                             mb_nbra_namd[:, 1]) * units.au2ev

        #sd ida
        params["outfile"] = "_out_sd_ida_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 64  # total number of sd electronic states
        res_sd_ida = step4.run([hvib_sd_subtrajs[subtraj]], params)
        sd_nbra_namd = data_conv.MATRIX2nparray(res_sd_ida)
        tmp_ida_sd.append(sd_nbra_namd)
        sd_hot_energy_ida = (sd_nbra_namd[:, 194] -
                             sd_nbra_namd[:, 1]) * units.au2ev
        end = time.time()
        print("Time to run NBRA NAMD = ", end - start)

        ### mSDM
        params["decoherence_method"] = 2
        start = time.time()
        # mb msdm
        params["outfile"] = "_out_mb_msdm_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 31  # total number of mb electronic states
        res_mb_msdm = step4.run([hvib_mb_subtrajs[subtraj]], params)
        mb_nbra_namd = data_conv.MATRIX2nparray(res_mb_msdm)
        tmp_msdm_mb.append(mb_nbra_namd)
        mb_hot_energy_msdm = (mb_nbra_namd[:, 95] -
                              mb_nbra_namd[:, 1]) * units.au2ev

        #sd msdm
        params["outfile"] = "_out_sd_msdm_subtraj_" + str(
            subtraj) + "_istate" + str(istate) + ".txt"
        params["nstates"] = 64  # total number of sd electronic states
        res_sd_msdm = step4.run([hvib_sd_subtrajs[subtraj]], params)
        sd_nbra_namd = data_conv.MATRIX2nparray(res_sd_msdm)
        tmp_msdm_sd.append(sd_nbra_namd)
        sd_hot_energy_msdm = (sd_nbra_namd[:, 194] -
                              sd_nbra_namd[:, 1]) * units.au2ev
        end = time.time()
        print("Time to run NBRA NAMD = ", end - start)

        plt.figure(num=None,
                   figsize=(3.21, 2.41),
                   dpi=300,
                   edgecolor='black',
                   frameon=True)
        plt.subplot(1, 1, 1)
        plt.title('(CdSe)$_{33}$ MB traj' + str(subtraj) + ' istate' +
                  str(istate) + '',
                  fontsize=10)
        plt.xlabel('Time, fs', fontsize=10)
        plt.ylabel('Energy, eV', fontsize=10)
        plt.ylim(0, 3.5)
        plt.yticks([0, 1, 2, 3])
        for sd_index in range(31):
            plt.plot(md_time,
                     mb_subtraj_energy[sd_index] * units.au2ev,
                     label="",
                     linewidth=1,
                     color="gray")
        plt.plot(md_time,
                 mb_hot_energy_fssh,
                 linewidth=2.5,
                 color="red",
                 label="FSSH")
        plt.plot(md_time,
                 mb_hot_energy_ida,
                 linewidth=2.5,
                 color="green",
                 label="IDA")
        plt.plot(md_time,
                 mb_hot_energy_msdm,
                 linewidth=2.5,
                 color="blue",
                 label="mSDM")
        plt.tight_layout()
        plt.legend(fontsize=8, ncol=3, loc="lower left")
        plt.savefig("CdSe33_MB_Dyn_" + str(subtraj) + "_" + str(istate) +
                    ".png",
                    dpi=300)

        plt.figure(num=None,
                   figsize=(3.21, 2.41),
                   dpi=300,
                   edgecolor='black',
                   frameon=True)
        plt.subplot(1, 1, 1)
        plt.title('(CdSe)$_{33}$ SP traj' + str(subtraj) + ' istate' +
                  str(istate) + '',
                  fontsize=10)
        plt.xlabel('Time, fs', fontsize=10)
        plt.ylabel('Energy, eV', fontsize=10)
        plt.ylim(0, 3.5)
        plt.yticks([0, 1, 2, 3])
        for sd_index in range(64):
            plt.plot(md_time,
                     sd_subtraj_energy[sd_index] * units.au2ev,
                     label="",
                     linewidth=1,
                     color="gray")
        plt.plot(md_time,
                 sd_hot_energy_fssh,
                 linewidth=2.5,
                 color="red",
                 label="FSSH")
        plt.plot(md_time,
                 sd_hot_energy_ida,
                 linewidth=2.5,
                 color="green",
                 label="IDA")
        plt.plot(md_time,
                 sd_hot_energy_msdm,
                 linewidth=2.5,
                 color="blue",
                 label="mSDM")
        plt.tight_layout()
        plt.legend(fontsize=8, ncol=3, loc="lower left")
        plt.savefig("CdSe33_" + str(subtraj) + "_SP_Dyn_" + str(istate) +
                    ".png",
                    dpi=300)