def do_command_file(args): """Report on the content of a file """ qr.printlog("Checking file info", loglevel=1) # # File name # if args.fname: fname = args.fname[0] qr.printlog("File name: " + fname, loglevel=1) try: check = qr.check_parcel(fname) qr.printlog("Object type: " + check["class_name"], loglevel=1) if check["class_name"] == "builtins.list": prcl = qr.load_parcel(fname) qr.printlog("List length: " + str(len(prcl)), loglevel=1) types = [] for el in prcl: tp = type(prcl[0]) if tp not in types: types.append(tp) qr.printlog("Element types: " + str(types), loglevel=1) qr.printlog("Saved with Quantarhei version: " + check["qrversion"], loglevel=1) qr.printlog("Description: " + check["comment"]) except: qr.printlog("The file is not a Quantarhei parcel", loglevel=1)
def onOpen(self): import matplotlib.pyplot as plt file = askopenfilename() #print(file, loglevel=qr.LOG_REPORT) obj = qr.load_parcel(file) self.figure(obj)
print("Preparing a model system:") with qr.energy_units("1/cm"): mol1 = qr.Molecule([0.0, 12010]) mol2 = qr.Molecule([0.0, 12000]) mol3 = qr.Molecule([0.0, 12100]) mol4 = qr.Molecule([0.0, 12110]) agg = qr.Aggregate([mol1, mol2, mol3, mol4]) agg.set_resonance_coupling(2, 3, qr.convert(100.0, "1/cm", "int")) agg.set_resonance_coupling(1, 3, qr.convert(100.0, "1/cm", "int")) agg.set_resonance_coupling(1, 2, qr.convert(0.0, "1/cm", "int")) qr.save_parcel(agg, "agg.qrp") agg2 = qr.load_parcel("agg.qrp") agg2.build() H = agg2.get_Hamiltonian() print("...done") print("Setting up Lindblad form relaxation:") Ndim = 5 with qr.eigenbasis_of(H): K12 = qr.qm.ProjectionOperator(1, 2, dim=Ndim) K23 = qr.qm.ProjectionOperator(2, 3, dim=Ndim) K34 = qr.qm.ProjectionOperator(3, 4, dim=Ndim) sbi = qr.qm.SystemBathInteraction(sys_operators=[K12, K23, K34], rates=(1.0 / 200, 1.0 / 100.0, 1.0 / 150))
qr.timeit(show_stamp=True) Nreal = INP.N_realizations # # THIS MAY BE PARALLELIZED # data_initialized = False disM = numpy.zeros((3, Nreal)) sigma = INP.disorder_fwhm / (2.0 * numpy.sqrt(2.0 * numpy.log(2.0))) if INP.random_state["reset"]: try: random_state = qr.load_parcel(INP.random_state["file"]) numpy.random.set_state(random_state) except: raise Exception("Loading random state failed") if INP.random_state["save"]: random_state = numpy.random.get_state() qr.save_parcel(random_state, INP.random_state["file"]) for ri in range(Nreal): disM[:, ri] = sigma * numpy.random.randn(3) # # PARALLEL (if ON) LOOP OVER DISORDER # for ds in qr.block_distributed_range(0, Nreal): # generating random numbers
# # Unite nodes # ii = 0 print("Creating spectral container ...") for node in nodes: if do_nodes: ndp = "_" + str(node) else: ndp = "" file_name = os.path.join(target_dir, "cont_" + ext[ext_i] + ndp + ".qrp") conta = qr.load_parcel(file_name) for tag in conta.spectra: #print(node, tag, ii) sp = conta.get_spectrum(tag) #print("dE = ", sp.params["dE"]) ntag = ii if normalize: sp.normalize2(dpart=qr.part_ABS) cont.set_spectrum(sp, tag=ntag) ii += 1 mfilename = "movie_" + ext[ext_i] + "_cont=" + str(Ncont) + "." + movie_ext print("Exporting movie: ", mfilename)
print("Preparing a model system:") with qr.energy_units("1/cm"): mol1 = qr.Molecule([0.0, 12000]) mol2 = qr.Molecule([0.0, 12000]) mol3 = qr.Molecule([0.0, 12100]) mol4 = qr.Molecule([0.0, 12100]) agg = qr.Aggregate([mol1, mol2, mol3, mol4]) agg.set_resonance_coupling(2, 3, qr.convert(100.0, "1/cm", "int")) agg.set_resonance_coupling(1, 3, qr.convert(100.0, "1/cm", "int")) with tempfile.TemporaryDirectory() as tdir: path = os.path.join(tdir, "agg.qrp") qr.save_parcel(agg, path) agg2 = qr.load_parcel(path) agg2.build() H = agg2.get_Hamiltonian() print("...done") print("Setting up Lindblad form relaxation:") Ndim = 5 with qr.eigenbasis_of(H): K12 = qr.qm.ProjectionOperator(1, 2, dim=Ndim) K23 = qr.qm.ProjectionOperator(2, 3, dim=Ndim) K34 = qr.qm.ProjectionOperator(3, 4, dim=Ndim) sbi = qr.qm.SystemBathInteraction(sys_operators=[K12, K23, K34], rates=(1.0 / 200, 1.0 / 100.0, 1.0 / 150))
except: raise Exception("Output directory name '" +pre_out+"' does not represent a valid directory") # # This is needed in version 0.0.36 and later for propagation with Lindblad form # qr.Manager().gen_conf.legacy_relaxation = True # # Load aggregates constructed in the previous phase of the calculation # agg = qr.load_parcel(os.path.join(pre_in, "fraction_45_2_vibrations_CT_unbuilt.qrp")) agg2 = qr.load_parcel(os.path.join(pre_in, "fraction_45_2_vibrations_CT_unbuilt.qrp")) agg_el = qr.load_parcel(os.path.join(pre_in, "fraction_eff_40_4_CT_unbuilt.qrp")) # # Aggregate with vibrational states, Hamiltonian generated up to single # exciton states in a Two-particle approximation # This object is used for calculation of dynamics # agg.build(mult=1, vibgen_approx="TPA") # # agg2 object will be used for calculation of 2D spectra # so it needs to know how to represent the spectra (what width it should have).
print("Preparing a model system:") with qr.energy_units("1/cm"): mol1 = qr.Molecule([0.0, 12000]) mol2 = qr.Molecule([0.0, 12000]) mol3 = qr.Molecule([0.0, 12100]) mol4 = qr.Molecule([0.0, 12100]) agg = qr.Aggregate([mol1, mol2, mol3, mol4]) agg.set_resonance_coupling(2,3,qr.convert(100.0,"1/cm","int")) agg.set_resonance_coupling(1,3,qr.convert(100.0,"1/cm","int")) with tempfile.TemporaryDirectory() as tdir: path = os.path.join(tdir,"agg.qrp") qr.save_parcel(agg,path) agg2 = qr.load_parcel(path) agg2.build() H = agg2.get_Hamiltonian() print("...done") print("Setting up Lindblad form relaxation:") Ndim = 5 with qr.eigenbasis_of(H): K12 = qr.qm.ProjectionOperator(1, 2, dim=Ndim) K23 = qr.qm.ProjectionOperator(2, 3, dim=Ndim) K34 = qr.qm.ProjectionOperator(3, 4, dim=Ndim) sbi = qr.qm.SystemBathInteraction(sys_operators=[K12, K23, K34], rates=(1.0/200, 1.0/100.0, 1.0/150))
#plt.plot(t2s.data,pp4) #plt.savefig("points.png") # ##sp = twods.get_spectrum(t2s.data[-1]) #with energy_units("1/cm"): # sp.plot(window=window_2D) # #sp.save("spectrum.hdf5") # #rsp = TwoDSpectrum() #rsp.load("spectrum.hdf5") # #with energy_units("1/cm"): # rsp.plot(window=window_2D) with qr.energy_units("1/cm"): twods.trimall_to(window=window_2D) twods.save("allspectra.qrp") #newtw = TwoDSpectrumContainer() newtw = qr.load_parcel("allspectra.qrp") #twods = newtw.get_TwoDSpectrumContainer() # #sp = twods.get_spectrum(0.0) #with energy_units("1/cm"): # sp.plot(window=window_2D)
import sys import os import quantarhei as qr try: dir = sys.argv[1] except: print("Cannot find command line argument: Specify simulation directory.") qr.stop() agpath = os.path.join(dir, "aggregate.qrp") agg = qr.load_parcel(agpath) agg.exciton_report(start=2)
dname = INP.dname #"sim_up" # # Transition energy for which the spectra are calculated # Ecalc = INP_pre.E_P #10000.0 calculated_width = INP_pre.max_available_fwhm # # load all spectra # #for de in des: # fname = op.path.join(dname,"twod_E0=1000_dE="+str(de)+".qrp") cont = qr.load_parcel(os.path.join(dname, INP.container_file)) spects = [] for ii in range(cont.length()): sp = cont.get_spectrum(ii) prms = sp.get_log_params() dE = prms["dE"] spects.append(sp) #print("dE =", dE) de_min = cont.get_spectrum(0).get_log_params()["dE"] de2 = cont.get_spectrum(1).get_log_params()["dE"] de_step = de2 - de_min de_N = cont.length() print("de_min:", de_min)
print("Preparing a model system:") with qr.energy_units("1/cm"): mol1 = qr.Molecule([0.0, 12010]) mol2 = qr.Molecule([0.0, 12000]) mol3 = qr.Molecule([0.0, 12100]) mol4 = qr.Molecule([0.0, 12110]) agg = qr.Aggregate([mol1, mol2, mol3, mol4]) agg.set_resonance_coupling(2,3,qr.convert(100.0,"1/cm","int")) agg.set_resonance_coupling(1,3,qr.convert(100.0,"1/cm","int")) agg.set_resonance_coupling(1,2,qr.convert(0.0,"1/cm","int")) qr.save_parcel(agg,"agg.qrp") agg2 = qr.load_parcel("agg.qrp") agg2.build() H = agg2.get_Hamiltonian() print("...done") print("Setting up Lindblad form relaxation:") Ndim = 5 with qr.eigenbasis_of(H): K12 = qr.qm.ProjectionOperator(1, 2, dim=Ndim) K23 = qr.qm.ProjectionOperator(2, 3, dim=Ndim) K34 = qr.qm.ProjectionOperator(3, 4, dim=Ndim) sbi = qr.qm.SystemBathInteraction(sys_operators=[K12, K23, K34], rates=(1.0/200, 1.0/100.0, 1.0/150))
agg.build(mult=2) #agg.save("RC_Model_40_4_adjusted_CT_no_vibrations_built.hdf5") qr.save_parcel(agg, os.path.join(pre_out, "RC_Model_40_4_adjusted_CT_no_vibrations_built.qrp")) # In[5]: # # Refitted model of the Reaction Center using effective Gaussian lineshapes # # # # # "Environment" modelled by dressing the states # molecules_eff = qr.load_parcel(os.path.join(pre_out,"molecules.qrp")) agg_eff = qr.Aggregate(molecules=molecules_eff) with qr.energy_units("1/cm"): agg_eff.set_resonance_coupling_matrix(J_Matrix) PMe = molecules_eff[0] PLe = molecules_eff[1] BMe = molecules_eff[2] BLe = molecules_eff[3] HMe = molecules_eff[4] HLe = molecules_eff[5] PCT_Me = molecules_eff[6] PCT_Le = molecules_eff[7] with qr.energy_units("1/cm"):
#agg.save("RC_Model_40_4_adjusted_CT_no_vibrations_built.hdf5") qr.save_parcel( agg, os.path.join(pre_out, "RC_Model_40_4_adjusted_CT_no_vibrations_built.qrp")) # In[5]: # # Refitted model of the Reaction Center using effective Gaussian lineshapes # # # # # "Environment" modelled by dressing the states # molecules_eff = qr.load_parcel(os.path.join(pre_out, "molecules.qrp")) agg_eff = qr.Aggregate(molecules=molecules_eff) with qr.energy_units("1/cm"): agg_eff.set_resonance_coupling_matrix(J_Matrix) PMe = molecules_eff[0] PLe = molecules_eff[1] BMe = molecules_eff[2] BLe = molecules_eff[3] HMe = molecules_eff[4] HLe = molecules_eff[5] PCT_Me = molecules_eff[6] PCT_Le = molecules_eff[7] with qr.energy_units("1/cm"):
import time import quantarhei as qr import matplotlib.pyplot as plt plt.switch_backend('agg') print(qr.Manager().version) # In[27]: pre_out = "out" #frac = qr.load("fraction_40_4_CT_unbuilt.hdf5") #frac_electronic = qr.load("fraction_40_4_CT_unbuilt.hdf5") frac = qr.load_parcel(os.path.join(pre_out, "fraction_eff_40_4_CT_unbuilt.qrp")) frac_electronic = qr.load_parcel( os.path.join(pre_out, "fraction_40_4_CT_unbuilt.qrp")) # In[28]: # # Get molecules # PM = frac.get_Molecule_by_name("PM") PL = frac.get_Molecule_by_name("PL") BL = frac.get_Molecule_by_name("BL") include_second_B = False vib_at_second_B = False
import quantarhei as qr dirn = "c01" pre_in = os.path.join(dirn,"out") filename = "pathways_20.0.qrp" Np = 13 ex2Dfile = "test.png" plot_window = [11000, 13500, 11000, 13500] t1axis = qr.TimeAxis(0.0, 1000, 1.0) t2axis = qr.TimeAxis(0.0, 100, 10.0) t3axis = qr.TimeAxis(0.0, 1000, 1.0) pws = qr.load_parcel(os.path.join(pre_in,filename)) print(len(pws)) mscal = qr.MockTwoDSpectrumCalculator(t1axis, t2axis, t3axis) mscal.bootstrap(rwa=qr.convert(12200,"1/cm","int")) pw = pws[Np] mscal.set_pathways([pw]) twod = mscal.calculate() eUt = qr.load_parcel(os.path.join(pre_in,"eUt.qrp")) oset = qr.load_parcel(os.path.join(dirn,"A_saved_state.qrp")) with qr.energy_units("1/cm"):
print("\nSignal component:", ext[ext_i]) cont = qr.TwoDSpectrumContainer() cont.use_indexing_type("integer") ii = 0 for node in nodes: if do_nodes: ndp = "_"+str(node) else: ndp = "" file_name = os.path.join(target_dir, prefix+ext[ext_i]+ndp+".qrp") print("Loading file:", file_name) conta = qr.load_parcel(file_name) for tag in conta.spectra: #print("(node, tag, new tag):", node, tag, ii) sp = conta.get_spectrum(tag) ntag = ii cont.set_spectrum(sp, tag=ntag) ii += 1 #print("Summary ("+ext[ext_i]+"):") for tag in cont.spectra: sp = cont.get_spectrum(tag) #print(tag, sp.params["dE"]) with qr.energy_units("1/cm"):
sing = (INP.disorder and (INP.N_realizations == 1)) if INP.single_realization or sing: print("Single realization 2D map") name1 = "cont_p_re" append_to_dirname = INP.append_to_dirname file = os.path.join( "sim_" + INP.location_of_vibrations + append_to_dirname, name1 + ".qrp") print("Loading file:", file) cont = qr.load_parcel(file) sp = cont.get_spectrum(0) sp.plot(show=False) sp.savefig("plot.png") else: if INP.disorder: if INP.N_realizations: print("Single realization 2D map") else: pass
try: os.makedirs(pre_out, exist_ok=True) except: raise Exception("Output directory name '" + pre_out + "' does not represent a valid directory") # # This is needed in version 0.0.36 and later for propagation with Lindblad form # qr.Manager().gen_conf.legacy_relaxation = True # # Load aggregates constructed in the previous phase of the calculation # agg = qr.load_parcel( os.path.join(pre_in, "fraction_45_2_vibrations_CT_unbuilt.qrp")) agg2 = qr.load_parcel( os.path.join(pre_in, "fraction_45_2_vibrations_CT_unbuilt.qrp")) agg_el = qr.load_parcel( os.path.join(pre_in, "fraction_eff_40_4_CT_unbuilt.qrp")) # # Aggregate with vibrational states, Hamiltonian generated up to single # exciton states in a Two-particle approximation # This object is used for calculation of dynamics # agg.build(mult=1, vibgen_approx="TPA") # # agg2 object will be used for calculation of 2D spectra # so it needs to know how to represent the spectra (what width it should have).
import quantarhei as qr ptype = "REPH" window_L = [11500, 12500, 12000, 13000] window_U = [11500, 12500, 13000, 13500] window = window_U fname = sys.argv[1] try: N = int(sys.argv[2]) except: N = 5 print("Using default value of N =", N) pws = qr.load_parcel(fname) Nparcel = len(pws) print("Number of pathways loaded:", Nparcel) with qr.energy_units("1/cm"): pan = qr.LiouvillePathwayAnalyzer(pathways=pws) pan.select_frequency_window(window=window, replace=True) pws = pan.select_type(ptype=ptype, replace=False) Nselect = len(pws) print("Number of pathways selected:", Nselect) Nshow = numpy.min([N, Nselect]) print("Showing:", Nshow)