def test_saving_of_aggregate(self): """(Aggregate) Testing its saving capability """ use_temporary_file = True if use_temporary_file: #drv = "core" #bcs = False #with h5py.File('tempfile.hdf5', # driver=drv, # backing_store=bcs) as f: with tempfile.TemporaryFile() as f: self.agg.save(f, test=True) #,report_unsaved=True) # reread it agg = Aggregate() agg = agg.load(f, test=True) else: #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp','wb') as f: self.agg.save(f) #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp','rb') as f: agg = Aggregate() agg.load(f) self.assertEqual(self.agg.nmono, agg.nmono) self.assertEqual(self.agg.mult, agg.mult) self.assertEqual(self.agg.sbi_mult, agg.sbi_mult) self.assertEqual(self.agg.name, agg.name) self.assertEqual(self.agg._has_egcf_matrix, agg._has_egcf_matrix) self.assertEqual(self.agg._has_system_bath_interaction, agg._has_system_bath_interaction) self.assertEqual(self.agg.coupling_initiated, agg.coupling_initiated) self.assertEqual(self.agg._has_relaxation_tensor, agg._has_relaxation_tensor) self.assertEqual(self.agg._relaxation_theory, agg._relaxation_theory) self.assertEqual(self.agg._built, agg._built) self.assertEqual(self.agg.Nel,agg.Nel) self.assertEqual(self.agg.Ntot,agg.Ntot) numpy.testing.assert_array_equal(self.agg.Nb,agg.Nb) for key in agg.mnames.keys(): self.assertEqual(self.agg.mnames[key],agg.mnames[key]) numpy.testing.assert_array_equal(self.agg.resonance_coupling, agg.resonance_coupling) mnames = ["Molecule 1", "Molecule 2"] for k in range(agg.nmono): m = agg.monomers[k] self.assertIn(m.name, mnames) mnames.remove(m.name)
def test_abs_calculator(self): """Testing some basic methods of the AbsSpectrumCalculator class """ #Calculations for monomer are already performed. Now testing that #absorption spectrum can be calculated for an aggregate. try: mol1 = Molecule(elenergies=[0.0, 12000.0]) mol2 = Molecule(elenergies=[0.0, 12000.0]) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) mol1.set_dipole(0,1,[0.0, 1.0, 0.0]) mol2.set_dipole(0,1,[0.0, 1.0, 0.0]) cf = CorrelationFunction(self.ta, params) mol1.set_transition_environment((0,1),cf) mol2.set_transition_environment((0,1),cf) agg = Aggregate(name="tester_dim", molecules=[mol1, mol2]) agg.build() HH = agg.get_Hamiltonian() abs_calc = AbsSpectrumCalculator(self.ta, system=agg, dynamics="secular", relaxation_tensor=None, rate_matrix=None) abs_calc.bootstrap(rwa=12000) abs_calc = abs_calc.calculate() except: raise Exception('Absorption not calculatable for aggregate')
def test_abs_calculator(self): """Testing some basic methods of the AbsSpectrumCalculator class """ #Calculations for monomer are already performed. Now testing that #absorption spectrum can be calculated for an aggregate. try: mol1 = Molecule(elenergies=[0.0, 12000.0]) mol2 = Molecule(elenergies=[0.0, 12000.0]) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) mol1.set_dipole(0,1,[0.0, 1.0, 0.0]) mol2.set_dipole(0,1,[0.0, 1.0, 0.0]) cf = CorrelationFunction(self.ta, params) mol1.set_transition_environment((0,1),cf) mol2.set_transition_environment((0,1),cf) agg = Aggregate(name="tester_dim", molecules=[mol1, mol2]) agg.build() HH = agg.get_Hamiltonian() abs_calc = AbsSpectrumCalculator(self.ta, system=agg, dynamics="secular", relaxation_tensor=None, rate_matrix=None) abs_calc.bootstrap(rwa=12000) abs_calc = abs_calc.calculate() except: raise Exception('Absorption not calculatable for aggregate')
def absorption_spectrum_trimer(self): dd1 = [0.0,3.0,0.0] dd2 = [0.0,1.0,2.0] dd3 = [0.0,1.0,1.0] cf = world.cf with energy_units("1/cm"): m1 = Molecule([0.0, 12100]) m1.set_dipole(0,1,dd1) m1.set_transition_environment((0,1), cf) m2 = Molecule([0.0, 11800]) m2.set_dipole(0,1,dd2) m2.set_transition_environment((0,1), cf) m3 = Molecule([0.0, 12500]) m3.set_dipole(0,1,dd3) m3.set_transition_environment((0,1), cf) m1.position = [0.0,0.0,0.0] m2.position = [5.0,0.0,0.0] m3.position = [0.0,5.0,0.0] AG = Aggregate(name="TestAggregate") AG.add_Molecule(m1) AG.add_Molecule(m2) AG.add_Molecule(m3) AG.set_coupling_by_dipole_dipole(epsr=3.0) AG.build() (RRr,hamr) = AG.get_RelaxationTensor(world.ta, relaxation_theory="standard_Redfield", time_dependent=True) ac = AbsSpectrumCalculator(world.ta,AG, relaxation_tensor=RRr, effective_hamiltonian=hamr) with energy_units("1/cm"): ac.bootstrap(rwa=12000) a1 = ac.calculate(raw=True) with energy_units("1/cm"): world.abs = numpy.zeros((len(a1.data),2)) for kk in range(len(a1.data)): world.abs[kk,0] = a1.axis.data[kk] #frequency[kk] world.abs[kk,1] = a1.data[kk]
def build_aggregate_1(settings): """Example function for building aggregate no. 1""" mol_l = [] mod_l = [] with qr.energy_units("1/cm"): for ind in range(settings["Nmol"]): mol = Molecule([0.0, settings["E1"]]) # mol1.set_dipole(0,1,[1.0, 0.0, 0.0]) # mol1.set_transition_width((0,1), width) mod = Mode(settings["omega"]) mol.add_Mode(mod) mod.set_nmax(0, settings["Nvib_0"]) mod.set_nmax(1, settings["Nvib_1"]) mod.set_HR(1, settings["HR"]) mol_l.append(mol) mod_l.append(mod) agg = Aggregate(molecules=mol_l) for ind in range(settings["Nmol"] - 1): agg.set_resonance_coupling(ind, ind + 1, settings["JJ"]) agg.set_resonance_coupling(settings["Nmol"] - 1, 0, settings["JJ"]) agg.build(mult=1) return agg
def test_saving_of_aggregate(self): """Testing the saving capability of the Aggregate class """ use_temporary_file = True if use_temporary_file: drv = "core" bcs = False with h5py.File('tempfile.hdf5', driver=drv, backing_store=bcs) as f: self.agg.save(f,report_unsaved=True) # reread it agg = Aggregate() agg.load(f) else: with h5py.File('tempfile.hdf5') as f: self.agg.save(f) with h5py.File('tempfile.hdf5') as f: agg = Aggregate() agg.load(f) self.assertEqual(self.agg.nmono, agg.nmono) self.assertEqual(self.agg.mult, agg.mult) self.assertEqual(self.agg.sbi_mult, agg.sbi_mult) self.assertEqual(self.agg.name, agg.name) self.assertEqual(self.agg._has_egcf_matrix, agg._has_egcf_matrix) self.assertEqual(self.agg._has_system_bath_interaction, agg._has_system_bath_interaction) self.assertEqual(self.agg.coupling_initiated, agg.coupling_initiated) self.assertEqual(self.agg._has_relaxation_tensor, agg._has_relaxation_tensor) self.assertEqual(self.agg._relaxation_theory, agg._relaxation_theory) self.assertEqual(self.agg._built, agg._built) self.assertEqual(self.agg.Nel,agg.Nel) self.assertEqual(self.agg.Ntot,agg.Ntot) numpy.testing.assert_array_equal(self.agg.Nb,agg.Nb) for key in agg.mnames.keys(): self.assertEqual(self.agg.mnames[key],agg.mnames[key]) numpy.testing.assert_array_equal(self.agg.resonance_coupling, agg.resonance_coupling) mnames = ["Molecule 1", "Molecule 2"] for k in range(agg.nmono): m = agg.monomers[k] self.assertIn(m.name, mnames) mnames.remove(m.name)
def homochain_aggregate(self): molecules = [] time = world.time #TimeAxis(0.0, 10000, 1.0) k = 0 couplings = [] temp = 0.0 for row in self.hashes: tenergy = float(row['tr_energy']) coupling = float(row['neighbor_coupling']) ftype_abbv = row['corfce'] if ftype_abbv == "OB": ftype = "OverdampedBrownian" reorg = float(row['reorg']) e_units = row['e_units'] ctime = float(row['ctime']) tempp = float(row['temperature']) matsu = int(row['matsubara']) if temp == 0.0: temp = tempp else: if temp != tempp: raise Exception( "Temperatures must be the same for all molecules") params = dict(ftype=ftype, cortime=ctime, reorg=reorg, T=temp, matsubara=matsu) with energy_units(e_units): m = Molecule(name="", elenergies=[0.0, tenergy]) cf = CorrelationFunction(time, params) m.set_transition_environment((0, 1), cf) molecules.append(m) couplings.append(coupling) k += 1 agg = Aggregate(name="", molecules=molecules) with energy_units("1/cm"): for i in range(k): if i + 1 < k: agg.set_resonance_coupling(i, i + 1, couplings[i]) else: agg.set_resonance_coupling(i, 0, couplings[i]) agg.build() world.temperature = temp world.aggregate = agg world.time = time world.N = k + 1
def setUp(self, verbose=False): lindichs = LinDichSpectrumBase() with energy_units("1/cm"): f = FrequencyAxis(10000.0, 2000, 1.0) a = self._spectral_shape(f, [1.0, 11000.0, 100.0]) lindichs.axis = f lindichs.data = a self.lindichs = lindichs self.axis = lindichs.axis #make a single-molecule system time = TimeAxis(0.0, 1000, 1.0) self.ta = time with energy_units("1/cm"): mol1 = Molecule(elenergies=[0.0, 12000.0]) mol2 = Molecule(elenergies=[0.0, 12000.0]) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) mol1.set_dipole(0, 1, [0.0, 1.0, 0.0]) mol2.set_dipole(0, 1, [0.0, 1.0, 0.0]) cf = CorrelationFunction(time, params) mol1.set_transition_environment((0, 1), cf) mol2.set_transition_environment((0, 1), cf) mol1.position = [0, 0, 0] mol2.position = [10, 10, 10] agg = Aggregate(name="tester_dim", molecules=[mol1, mol2]) agg.build() lindich_calc = LinDichSpectrumCalculator(time, system=agg, \ vector_perp_to_membrane=numpy.array((0,1,0))) lindich_calc.bootstrap(rwa=12000) lindich1 = lindich_calc.calculate() self.lindich1 = lindich1
def setUp(self): m1 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m2 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) time = TimeAxis(0.0, 1000, 1.0) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) with energy_units("1/cm"): fc = CorrelationFunction(time, params) m1.set_transition_environment((0,1), fc) m1.position = [0.0, 0.0, 0.0] m1.set_dipole(0,1,[10.0, 0.0, 0.0]) m2.set_transition_environment((0,1), fc) m2.position = [10.0, 0.0, 0.0] m2.set_dipole(0,1,[10.0, 0.0, 0.0]) self.agg = Aggregate(name="TestAgg", molecules=[m1,m2]) self.agg.set_coupling_by_dipole_dipole() self.agg.build() m3 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m4 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) m3.add_Mode(Mode(0.01)) m4.add_Mode(Mode(0.01)) mod3 = m3.get_Mode(0) mod4 = m4.get_Mode(0) mod3.set_nmax(0, 4) mod3.set_nmax(1, 4) mod3.set_HR(1, 0.1) mod4.set_nmax(0, 4) mod4.set_nmax(1, 4) mod4.set_HR(1, 0.3) self.vagg = Aggregate(molecules=[m3, m4]) self.vagg.build()
def setUp(self,verbose=False): lindichs = LinDichSpectrumBase() with energy_units("1/cm"): f = FrequencyAxis(10000.0,2000, 1.0) a = self._spectral_shape(f, [1.0, 11000.0, 100.0]) lindichs.axis = f lindichs.data = a self.lindichs = lindichs self.axis = lindichs.axis #make a single-molecule system time = TimeAxis(0.0,1000,1.0) self.ta = time with energy_units("1/cm"): mol1 = Molecule(elenergies=[0.0, 12000.0]) mol2 = Molecule(elenergies=[0.0, 12000.0]) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) mol1.set_dipole(0,1,[0.0, 1.0, 0.0]) mol2.set_dipole(0,1,[0.0, 1.0, 0.0]) cf = CorrelationFunction(time, params) mol1.set_transition_environment((0,1),cf) mol2.set_transition_environment((0,1),cf) mol1.position = [0, 0, 0] mol2.position = [10, 10, 10] agg = Aggregate(name="tester_dim", molecules=[mol1, mol2]) agg.build() lindich_calc = LinDichSpectrumCalculator(time, system=agg, \ vector_perp_to_membrane=numpy.array((0,1,0))) lindich_calc.bootstrap(rwa=12000) lindich1 = lindich_calc.calculate() self.lindich1 = lindich1
def setUp(self): m1 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m2 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) time = TimeAxis(0.0, 1000, 1.0) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) with energy_units("1/cm"): fc = CorrelationFunction(time, params) m1.set_transition_environment((0, 1), fc) m1.position = [0.0, 0.0, 0.0] m1.set_dipole(0, 1, [10.0, 0.0, 0.0]) m2.set_transition_environment((0, 1), fc) m2.position = [10.0, 0.0, 0.0] m2.set_dipole(0, 1, [10.0, 0.0, 0.0]) self.agg = Aggregate(name="TestAgg", molecules=[m1, m2]) self.agg.set_coupling_by_dipole_dipole() self.agg.build() m3 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m4 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) m3.add_Mode(Mode(0.01)) m4.add_Mode(Mode(0.01)) mod3 = m3.get_Mode(0) mod4 = m4.get_Mode(0) mod3.set_nmax(0, 4) mod3.set_nmax(1, 4) mod3.set_HR(1, 0.1) mod4.set_nmax(0, 4) mod4.set_nmax(1, 4) mod4.set_HR(1, 0.3) self.vagg = Aggregate(molecules=[m3, m4]) self.vagg.build()
def hamiltonian_is_created(self): # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule([0.0, en], "mol1") m2 = Molecule([0.0, en], "mol2") agg = Aggregate(name="Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) with energy_units(world.r_units): agg.set_resonance_coupling(0, 1, world.r_coupl) agg.build() world.HH = agg.get_Hamiltonian()
def absorption_spectrum_dimer(self): dd1 = [0.0,3.0,0.0] dd2 = [0.0,1.0,1.0] cf = world.cf #cm = CorrelationFunctionMatrix(world.ta,2,1) #cm.set_correlation_function(cf,[(1,1),(0,0)]) with energy_units("1/cm"): m1 = Molecule([0.0, 12100]) m1.set_dipole(0,1,dd1) m1.set_transition_environment((0,1), cf) m2 = Molecule([0.0, 12000]) m2.set_dipole(0,1,dd2) m2.set_transition_environment((0,1), cf) #m1.set_egcf([0,1],cf) #m2.set_egcf([0,1],cf) #m1.set_egcf_mapping((0,1),cm,0) #m2.set_egcf_mapping((0,1),cm,1) m1.position = [0.0,0.0,0.0] m2.position = [5.0,0.0,0.0] AG = Aggregate(name="TestAggregate") #AG.set_egcf_matrix(cm) AG.add_Molecule(m1) AG.add_Molecule(m2) AG.set_coupling_by_dipole_dipole() AG.build() ac = AbsSpectrumCalculator(world.ta,AG) with energy_units("1/cm"): ac.bootstrap(rwa=12000) a1 = ac.calculate(raw=True) with energy_units("1/cm"): world.abs = numpy.zeros((len(a1.data),2)) for kk in range(len(a1.data)): world.abs[kk,0] = a1.axis.data[kk] #frequency[kk] world.abs[kk,1] = a1.data[kk]
def build_testing_aggregate(): """Testing aggregate for unit tests.""" # Number of molecules Nmol = 2 # energy of molecule one E1 = 12500.0 # energy gap to molecule two Edelta = 100.0 # coupling between the two molecules JJ = 30.0 # frequency of the vibrational mode omega = 110.0 # Huan-Rhys factor HR = 0.01 # transition width width = 80 # max nvib states Nvib_0 = 3 Nvib_1 = 3 mol_l = [] mod_l = [] with qr.energy_units("1/cm"): for ind in range(Nmol): mol = Molecule([0.0, E1]) mol.set_dipole(0, 1, [1.0, 0.0, 0.0]) mol.set_transition_width((0, 1), width) mod = Mode(omega) mol.add_Mode(mod) mod.set_nmax(0, Nvib_0) mod.set_nmax(1, Nvib_1) mod.set_HR(1, HR) mol_l.append(mol) mod_l.append(mod) agg = Aggregate(molecules=mol_l) for ind in range(Nmol - 1): agg.set_resonance_coupling(ind, ind + 1, JJ) agg.set_resonance_coupling(Nmol - 1, 0, JJ) agg.build(mult=1) return agg
def homochain_aggregate(self): molecules = [] time = world.time #TimeAxis(0.0, 10000, 1.0) k = 0 couplings = [] temp = 0.0 for row in self.hashes: tenergy = float(row['tr_energy']) coupling = float(row['neighbor_coupling']) ftype_abbv = row['corfce'] if ftype_abbv == "OB": ftype = "OverdampedBrownian" reorg = float(row['reorg']) e_units = row['e_units'] ctime = float(row['ctime']) tempp = float(row['temperature']) matsu = int(row['matsubara']) if temp == 0.0: temp = tempp else: if temp != tempp: raise Exception("Temperatures must be the same for all molecules") params = dict(ftype=ftype, cortime=ctime, reorg=reorg, T=temp, matsubara=matsu) with energy_units(e_units): m = Molecule([0.0, tenergy]) cf = CorrelationFunction(time, params) m.set_transition_environment((0,1), cf) molecules.append(m) couplings.append(coupling) k += 1 agg = Aggregate(molecules=molecules) with energy_units("1/cm"): for i in range(k): if i+1 < k: agg.set_resonance_coupling(i,i+1,couplings[i]) else: agg.set_resonance_coupling(i,0,couplings[i]) agg.build() world.temperature = temp world.aggregate = agg world.time = time world.N = k+1
def hamiltonian_is_created(self): # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule([0.0, en], "mol1") m2 = Molecule([0.0, en], "mol2") agg = Aggregate(name="Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) with energy_units(world.r_units): agg.set_resonance_coupling(0,1,world.r_coupl) agg.build() world.HH = agg.get_Hamiltonian()
def redfield_relaxation(self): print("Redfield rate calculation") # # Correlation function # params = {"ftype": world.ctype, "reorg": world.reorg, "cortime": world.ctime, "T": world.temp, "matsubara":world.mats} # FIXME: also time_units, temperature_units with energy_units(world.e_units): cf = CorrelationFunction(world.ta,params) # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule([0.0, en],"mol1") m2 = Molecule([0.0, en], "mol2") # m3 = Molecule("mol2", [0.0, en]) m1.set_egcf((0,1), cf) m2.set_egcf((0,1), cf) # m3.set_egcf((0,1), cf) agg = Aggregate(name="Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) # agg.add_Molecule(m3) # with energy_units("1/cm"): # Hm = m1.get_Hamiltonian() # print(Hm) # print(m.convert_energy_2_current_u(Hm._data)) with energy_units(world.r_units): agg.set_resonance_coupling(0,1,world.r_coupl) # agg.set_resonance_coupling(1,2,world.r_coupl) agg.build() H = agg.get_Hamiltonian() # with energy_units("1/cm"): # print(H) # print(m.convert_energy_2_current_u(H._data)) sbi = agg.get_SystemBathInteraction() RRM = RedfieldRateMatrix(H, sbi) world.K12 = numpy.real(RRM.data[1,2]) dim = H.dim rates_M = numpy.zeros(dim*dim) k = 0 for i in range(dim): for j in range(dim): rates_M[k] = RRM.data[i,j] k += 1 world.rates_M = rates_M
the we create electronic Lindblad form for a system with vibrational levels """ # # PURELY ELECTRONIC Aggregate of two molecules # from quantarhei import Molecule m1 = Molecule([0.0, 1.0]) m2 = Molecule([0.0, 1.1]) m3 = Molecule([0.0, 1.2]) from quantarhei import Aggregate agg = Aggregate([m1, m2, m3]) agg.build() # # Operator describing relaxation # from quantarhei.qm import Operator HH = agg.get_Hamiltonian() K = Operator(dim=HH.dim,real=True) K.data[1,2] = 1.0 # # System bath interaction with prescribed rate # from quantarhei.qm import SystemBathInteraction
# -*- coding: utf-8 -*- _show_plots_ = False from quantarhei import Molecule, Aggregate #from quantarhei import energy_units en = [0.0, 1.0] m1 = Molecule(name="Mol1", elenergies=en) m2 = Molecule(name="Mol2", elenergies=en) ag = Aggregate(name="Homodimer") ag.add_Molecule(m1) ag.add_Molecule(m2) ag.set_resonance_coupling(0, 1, 0.1) ag.build(mult=1) H = ag.get_Hamiltonian() #with energy_units("1/cm"): # print(H)
import matplotlib.pyplot as plt plt.plot(time.data, sm) plt.axis([0.0, 100.0, 0.0, 1.1]) plt.show() # # Molecular dimer without vibrations # from quantarhei import Aggregate mol1 = Molecule("Mol 1", [0.0, 1.0]) mol2 = Molecule("Mol 2", [0.0, 1.0]) agg = Aggregate("Dimer") agg.add_Molecule(mol1) agg.add_Molecule(mol2) agg.set_resonance_coupling(0, 1, 0.01) agg.build() H = agg.get_Hamiltonian() print(H) psi = StateVector(3) psi.data[2] = 1.0 dimer_propagator = StateVectorPropagator(time, H)
# -*- coding: utf-8 -*- from quantarhei import Molecule, Aggregate from quantarhei import energy_units en = [0.0, 1.0] m1 = Molecule("Mol1", en) m2 = Molecule("Mol2", en) ag = Aggregate("Homodimer", maxband=1) ag.add_Molecule(m1) ag.add_Molecule(m2) ag.set_resonance_coupling(0, 1, 0.1) ag.build() H = ag.get_Hamiltonian() with energy_units("1/cm"): print(H)
gamma=1.0/10000.0) with energy_units('1/cm'): cf2 = CorrelationFunction(tsbi, params2) cf.add_to_data(cf2) # # Set system-bath interaction # mol1.set_transition_environment((0,1),cf) mol2.set_transition_environment((0,1),cf) # # Creating aggregate # agg = Aggregate(name="Dimer", molecules=[mol1, mol2]) agg.set_coupling_by_dipole_dipole() with energy_units("1/cm"): print(agg.get_resonance_coupling(0,1)) agg.build(mult=2) with energy_units("1/cm"): rwa_cm = agg.get_RWA_suggestion() rwa = agg.get_RWA_suggestion() # # Prepare for calculation of 2D spectra # # TimeAxis for t2 waiting time
class TestAggregate(unittest.TestCase): """Tests for the Manager class """ def setUp(self): m1 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m2 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) time = TimeAxis(0.0, 1000, 1.0) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) with energy_units("1/cm"): fc = CorrelationFunction(time, params) m1.set_transition_environment((0,1), fc) m1.position = [0.0, 0.0, 0.0] m1.set_dipole(0,1,[10.0, 0.0, 0.0]) m2.set_transition_environment((0,1), fc) m2.position = [10.0, 0.0, 0.0] m2.set_dipole(0,1,[10.0, 0.0, 0.0]) self.agg = Aggregate(name="TestAgg", molecules=[m1,m2]) self.agg.set_coupling_by_dipole_dipole() self.agg.build() m3 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m4 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) m3.add_Mode(Mode(0.01)) m4.add_Mode(Mode(0.01)) mod3 = m3.get_Mode(0) mod4 = m4.get_Mode(0) mod3.set_nmax(0, 4) mod3.set_nmax(1, 4) mod3.set_HR(1, 0.1) mod4.set_nmax(0, 4) mod4.set_nmax(1, 4) mod4.set_HR(1, 0.3) self.vagg = Aggregate(molecules=[m3, m4]) self.vagg.build() def test_saving_of_aggregate(self): """Testing the saving capability of the Aggregate class """ use_temporary_file = True if use_temporary_file: drv = "core" bcs = False with h5py.File('tempfile.hdf5', driver=drv, backing_store=bcs) as f: self.agg.save(f,report_unsaved=True) # reread it agg = Aggregate() agg.load(f) else: with h5py.File('tempfile.hdf5') as f: self.agg.save(f) with h5py.File('tempfile.hdf5') as f: agg = Aggregate() agg.load(f) self.assertEqual(self.agg.nmono, agg.nmono) self.assertEqual(self.agg.mult, agg.mult) self.assertEqual(self.agg.sbi_mult, agg.sbi_mult) self.assertEqual(self.agg.name, agg.name) self.assertEqual(self.agg._has_egcf_matrix, agg._has_egcf_matrix) self.assertEqual(self.agg._has_system_bath_interaction, agg._has_system_bath_interaction) self.assertEqual(self.agg.coupling_initiated, agg.coupling_initiated) self.assertEqual(self.agg._has_relaxation_tensor, agg._has_relaxation_tensor) self.assertEqual(self.agg._relaxation_theory, agg._relaxation_theory) self.assertEqual(self.agg._built, agg._built) self.assertEqual(self.agg.Nel,agg.Nel) self.assertEqual(self.agg.Ntot,agg.Ntot) numpy.testing.assert_array_equal(self.agg.Nb,agg.Nb) for key in agg.mnames.keys(): self.assertEqual(self.agg.mnames[key],agg.mnames[key]) numpy.testing.assert_array_equal(self.agg.resonance_coupling, agg.resonance_coupling) mnames = ["Molecule 1", "Molecule 2"] for k in range(agg.nmono): m = agg.monomers[k] self.assertIn(m.name, mnames) mnames.remove(m.name) def test_trace_over_vibrations(self): """Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2)
class AggregateTest(unittest.TestCase): """Tests for the Manager class """ def setUp(self): m1 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m2 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) time = TimeAxis(0.0, 1000, 1.0) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) with energy_units("1/cm"): fc = CorrelationFunction(time, params) m1.set_transition_environment((0,1), fc) m1.position = [0.0, 0.0, 0.0] m1.set_dipole(0,1,[10.0, 0.0, 0.0]) m2.set_transition_environment((0,1), fc) m2.position = [10.0, 0.0, 0.0] m2.set_dipole(0,1,[10.0, 0.0, 0.0]) self.agg = Aggregate(name="TestAgg", molecules=[m1,m2]) self.agg.set_coupling_by_dipole_dipole() self.agg.build() m3 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m4 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) m3.add_Mode(Mode(0.01)) m4.add_Mode(Mode(0.01)) mod3 = m3.get_Mode(0) mod4 = m4.get_Mode(0) mod3.set_nmax(0, 4) mod3.set_nmax(1, 4) mod3.set_HR(1, 0.1) mod4.set_nmax(0, 4) mod4.set_nmax(1, 4) mod4.set_HR(1, 0.3) self.vagg = Aggregate(molecules=[m3, m4]) self.vagg.build() ######################################################################### # # TESTS # ######################################################################### def test_saving_of_aggregate(self): """(Aggregate) Testing its saving capability """ use_temporary_file = True if use_temporary_file: #drv = "core" #bcs = False #with h5py.File('tempfile.hdf5', # driver=drv, # backing_store=bcs) as f: with tempfile.TemporaryFile() as f: self.agg.save(f, test=True) #,report_unsaved=True) # reread it agg = Aggregate() agg = agg.load(f, test=True) else: #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp','wb') as f: self.agg.save(f) #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp','rb') as f: agg = Aggregate() agg.load(f) self.assertEqual(self.agg.nmono, agg.nmono) self.assertEqual(self.agg.mult, agg.mult) self.assertEqual(self.agg.sbi_mult, agg.sbi_mult) self.assertEqual(self.agg.name, agg.name) self.assertEqual(self.agg._has_egcf_matrix, agg._has_egcf_matrix) self.assertEqual(self.agg._has_system_bath_interaction, agg._has_system_bath_interaction) self.assertEqual(self.agg.coupling_initiated, agg.coupling_initiated) self.assertEqual(self.agg._has_relaxation_tensor, agg._has_relaxation_tensor) self.assertEqual(self.agg._relaxation_theory, agg._relaxation_theory) self.assertEqual(self.agg._built, agg._built) self.assertEqual(self.agg.Nel,agg.Nel) self.assertEqual(self.agg.Ntot,agg.Ntot) numpy.testing.assert_array_equal(self.agg.Nb,agg.Nb) for key in agg.mnames.keys(): self.assertEqual(self.agg.mnames[key],agg.mnames[key]) numpy.testing.assert_array_equal(self.agg.resonance_coupling, agg.resonance_coupling) mnames = ["Molecule 1", "Molecule 2"] for k in range(agg.nmono): m = agg.monomers[k] self.assertIn(m.name, mnames) mnames.remove(m.name) def test_trace_over_vibrations(self): """(Aggregate) Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N+5, N+5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2) def test_get_Density_Matrix_thermal(self): """(Aggregate) Testing the get_Densitymatrix method with `thermal` condition type """ from quantarhei.core.units import kB_intK vagg = self.vagg H = vagg.get_Hamiltonian() N = H.data.shape[0] # zero temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal") tst0 = numpy.zeros((N,N),dtype=qr.COMPLEX) tst0[0,0] = 1.0 numpy.testing.assert_almost_equal(rho0.data, tst0) # room temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal", temperature=300) # cannonical balance between neighboring states is tested kbT = kB_intK*300.0 for k in range(N-1): E2 = H.data[k+1,k+1] E1 = H.data[k,k] ratio = numpy.exp(-(E2-E1)/kbT) numpy.testing.assert_almost_equal(ratio, rho0.data[k+1,k+1]/rho0.data[k,k]) def test_get_Density_Matrix_thermal_excited(self): """(Aggregate) Testing the get_Densitymatrix method with `thermal_excited_state` condition type """ from quantarhei.core.units import kB_intK vagg = self.vagg H = vagg.get_Hamiltonian() N = H.data.shape[0] Nb0 = vagg.Nb[0] # zero temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal_excited_state") tst0 = numpy.zeros((N,N),dtype=qr.COMPLEX) tst0[Nb0,Nb0] = 1.0 numpy.testing.assert_almost_equal(rho0.data, tst0) # room temperature kbT = kB_intK*300.0 H = self.agg.get_Hamiltonian() N = H.data.shape[0] Nb0 = self.agg.Nb[0] with qr.eigenbasis_of(H): rho0 = self.agg.get_DensityMatrix(condition_type="thermal_excited_state", temperature=300) tst0 = numpy.zeros((N,N),dtype=qr.COMPLEX) with qr.eigenbasis_of(H): ssum = 0.0 for i in range(Nb0, N): tst0[i,i] = numpy.exp(-(H.data[i,i]-H.data[Nb0,Nb0])/kbT) ssum += tst0[i,i] tst0 = tst0/ssum numpy.testing.assert_almost_equal(rho0.data, tst0) # ssum = 0.0 # for i in range(N): # tst0[i,i] = numpy.exp(-H.data[i,i]/kbT) # ssum += tst0[i,i] # tst0 = tst0/ssum # # DD = vagg.TrDMOp.data # # abs value of the transition dipole moment # dabs = numpy.sqrt(DD[:,:,0]**2 + \ # DD[:,:,1]**2 + DD[:,:,2]**2) # # excitation from bra and ket # tst0 = numpy.dot(dabs, numpy.dot(tst0,dabs)) # # numpy.testing.assert_almost_equal(rho0.data, tst0) def test_get_temperature(self): """(Aggregate) Testing temperature retrieval """ agg = self.agg T = agg.get_temperature() numpy.testing.assert_almost_equal(T, 300.0) def test_init_coupling_matrix(self): """(Aggregate) Testing coupling matrix initialization """ agg = TestAggregate(name="dimer-2-env") self.assertFalse(agg.coupling_initiated) agg.init_coupling_matrix() self.assertTrue(agg.coupling_initiated) self.assertAlmostEqual(0.0, agg.resonance_coupling[0,1]) def test_set_resonance_coupling(self): """(Aggregate) Testing resonance coupling setting with different units """ agg = TestAggregate(name="dimer-2-env") agg.init_coupling_matrix() agg.set_resonance_coupling(0, 1, 1.0) self.assertAlmostEqual(1.0, agg.resonance_coupling[0,1]) self.assertAlmostEqual(1.0, agg.resonance_coupling[1,0]) with qr.energy_units("1/cm"): agg.set_resonance_coupling(0, 1, 100.0) self.assertAlmostEqual(qr.convert(100.0, "1/cm", "int"), agg.resonance_coupling[0,1]) self.assertAlmostEqual(qr.convert(100.0, "1/cm", "int"), agg.resonance_coupling[1,0]) def test_get_resonance_coupling(self): """(Aggregate) Testing resonance coupling retrieval in different units """ agg = TestAggregate(name="dimer-2-env") agg.init_coupling_matrix() agg.set_resonance_coupling(0, 1, 1.0) coup = agg.get_resonance_coupling(1,0) self.assertAlmostEqual(coup, 1.0) with qr.energy_units("1/cm"): coup = agg.get_resonance_coupling(1,0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "1/cm")) with qr.energy_units("eV"): coup = agg.get_resonance_coupling(1,0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "eV")) with qr.energy_units("THz"): coup = agg.get_resonance_coupling(1,0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "THz")) def test_set_resonance_coupling_matrix(self): """(Aggregate) Testing setting the whole resonance coupling matrix """ agg = TestAggregate(name="dimer-2-env") mat = [[0.0, 1.0], [1.0, 0.0]] agg.set_resonance_coupling_matrix(mat) self.assertAlmostEqual(agg.resonance_coupling[1,0], 1.0) self.assertAlmostEqual(agg.resonance_coupling[0,1], 1.0) self.assertAlmostEqual(agg.resonance_coupling[0,0], 0.0) self.assertAlmostEqual(agg.resonance_coupling[1,1], 0.0) mat = ((0.0, 500.0), (500.0, 0.0)) with qr.energy_units("1/cm"): agg.set_resonance_coupling_matrix(mat) inint = qr.convert(500, "1/cm", "int") self.assertAlmostEqual(agg.resonance_coupling[1,0], inint) self.assertAlmostEqual(agg.resonance_coupling[0,1], inint) self.assertAlmostEqual(agg.resonance_coupling[0,0], 0.0) self.assertAlmostEqual(agg.resonance_coupling[1,1], 0.0) def test_dipole_dipole_coupling(self): """(Aggregate) Testing dipole-dipole coupling calculation """ agg = TestAggregate(name="dimer-2-env") coup1 = agg.dipole_dipole_coupling(0,1) coup2 = agg.dipole_dipole_coupling(0,1, epsr=2.0) self.assertAlmostEqual(coup1, coup2*2.0) with qr.energy_units("1/cm"): coup = agg.dipole_dipole_coupling(0,1) self.assertAlmostEqual(qr.convert(coup1,"int","1/cm"), coup) def test_set_coupling_by_dipole_dipole(self): """(Aggregate) Testing dipole-dipole coupling calculation for the whole agregate """ agg = TestAggregate(name="dimer-2-env") agg.set_coupling_by_dipole_dipole() coup1 = agg.dipole_dipole_coupling(0,1) self.assertAlmostEqual(coup1, agg.resonance_coupling[0,1]) with qr.energy_units("1/cm"): agg.set_coupling_by_dipole_dipole() coup1 = agg.dipole_dipole_coupling(0,1) self.assertAlmostEqual(coup1, agg.resonance_coupling[0,1]) def test_calculate_resonance_coupling(self): """(Aggregate) Testing resonance coupling calculation by various methods """ agg = TestAggregate(name="dimer-2-env") agg.calculate_resonance_coupling(method="dipole-dipole") coup1 = agg.dipole_dipole_coupling(0,1) self.assertEqual(coup1, agg.resonance_coupling[1,0]) with qr.energy_units("1/cm"): agg.calculate_resonance_coupling(method="dipole-dipole") self.assertEqual(coup1, agg.resonance_coupling[1,0]) def test_add_Molecule(self): """(Aggregate) Testing add_Molecule() method """ agg = TestAggregate(name="dimer-2-env") mol = qr.Molecule(elenergies=[0.0, 1.0]) nmols1 = agg.nmono agg.add_Molecule(mol) nmols2 = agg.nmono self.assertEqual(nmols1 + 1, nmols2) self.assertEqual(len(agg.monomers), nmols2) self.assertLessEqual(len(agg.mnames), nmols2)
def setUp(self,verbose=False): self.verbose = verbose # # PURE ELECTRONIC AGGREGATE # m1 = Molecule([0.0, 1.0]) m2 = Molecule([0.0, 1.0]) agg = Aggregate(molecules=[m1, m2]) agg.set_resonance_coupling(0,1, 0.1) agg.build() self.ham = agg.get_Hamiltonian() KK12 = ProjectionOperator(1, 2, dim=self.ham.dim) KK21 = ProjectionOperator(2, 1, dim=self.ham.dim) self.rates = (1.0/100.0, 1.0/200.0) self.sbi = SystemBathInteraction([KK12,KK21], rates=self.rates) self.sbi.set_system(agg) # # VIBRONIC AGGREGATE # vm1 = Molecule([0.0, 1.0]) vm2 = Molecule([0.0, 1.0]) mod1 = Mode(0.01) mod2 = Mode(0.01) vm1.add_Mode(mod1) vm2.add_Mode(mod2) mod1.set_nmax(0, 3) mod1.set_nmax(1, 3) mod2.set_nmax(0, 3) mod2.set_nmax(1, 3) vagg = Aggregate(molecules=[vm1, vm2]) vagg.set_resonance_coupling(0, 1, 0.1) vagg.build() self.vham = vagg.get_Hamiltonian() self.vsbi = SystemBathInteraction([KK12, KK21], rates=self.rates) self.vsbi.set_system(vagg)
gamma=1.0 / 10000.0) with energy_units('1/cm'): cf2 = CorrelationFunction(tsbi, params2) cf.add_to_data(cf2) # # Set system-bath interaction # mol1.set_transition_environment((0, 1), cf) mol2.set_transition_environment((0, 1), cf) # # Creating aggregate # agg = Aggregate("Dimer", molecules=[mol1, mol2]) agg.set_coupling_by_dipole_dipole() with energy_units("1/cm"): print(agg.get_resonance_coupling(0, 1)) agg.build(mult=2) with energy_units("1/cm"): rwa_cm = agg.get_RWA_suggestion() rwa = agg.get_RWA_suggestion() # # Prepare for calculation of 2D spectra # # TimeAxis for t2 waiting time
def get_Aggregate(self, name="dimer-1"): if name == "dimer-1": agg = Aggregate(name=name) elif name == "trimer-1": agg = Aggregate(name=name) with energy_units("1/cm"): m1 = Molecule("Mol 1", [0.0, 10100.0]) m2 = Molecule("Mol 2", [0.0, 10050.0]) m3 = Molecule("Mol 3", [0.0, 10000.0]) m1.position = [0.0, 0.0, 0.0] m2.position = [15.0, 0.0, 0.0] m3.position = [10.0, 10.0, 0.0] m1.set_dipole(0, 1, [5.8, 0.0, 0.0]) m2.set_dipole(0, 1, [5.8, 0.0, 0.0]) m3.set_dipole(0, 1, [numpy.sqrt(12.0), 0.0, 0.0]) agg.add_Molecule(m1) agg.add_Molecule(m2) agg.add_Molecule(m3) self.molecules = [m1, m2, m3] # m4 = Molecule("Mol 4", [0.0, 11000.0]) # m5 = Molecule("Mol 5", [0.0, 11000.0]) # m4.position = [15.0, 15.0, 0.0] # m5.position = [15.0, 10.0, 0.0] # m4.set_dipole(0,1,[5.8, 0.0, 0.0]) # m5.set_dipole(0,1,[5.8, 0.0, 0.0]) # agg.add_Molecule(m4) # agg.add_Molecule(m5) agg.set_coupling_by_dipole_dipole() elif name == "pentamer-1": agg = Aggregate(name=name) with energy_units("1/cm"): m1 = Molecule("Mol 1", [0.0, 10100.0]) m2 = Molecule("Mol 2", [0.0, 10050.0]) m3 = Molecule("Mol 3", [0.0, 10000.0]) m4 = Molecule("Mol 4", [0.0, 10200.0]) m5 = Molecule("Mol 5", [0.0, 10070.0]) m1.position = [0.0, 0.0, 0.0] m2.position = [15.0, 0.0, 0.0] m3.position = [10.0, 10.0, 0.0] m4.position = [15.0, 15.0, 0.0] m5.position = [0, 10.0, 10.0] m1.set_dipole(0, 1, [5.8, 0.0, 0.0]) m2.set_dipole(0, 1, [5.8, 0.0, 0.0]) m3.set_dipole(0, 1, [numpy.sqrt(12.0), 0.0, 0.0]) m4.set_dipole(0, 1, [5.8, 0.0, 0.0]) m5.set_dipole(0, 1, [5.8, 0.0, 0.0]) agg.add_Molecule(m1) agg.add_Molecule(m2) agg.add_Molecule(m3) agg.add_Molecule(m4) agg.add_Molecule(m5) self.molecules = [m1, m2, m3, m4, m5] agg.set_coupling_by_dipole_dipole() else: raise Exception("Unknown model name %s" % name) return agg
def setUp(self, verbose=False): self.verbose = verbose # # PURE ELECTRONIC AGGREGATE # m1 = Molecule([0.0, 1.0]) m2 = Molecule([0.0, 1.0]) agg = Aggregate(molecules=[m1, m2]) agg.set_resonance_coupling(0, 1, 0.1) agg.build() self.ham = agg.get_Hamiltonian() KK12 = ProjectionOperator(1, 2, dim=self.ham.dim) KK21 = ProjectionOperator(2, 1, dim=self.ham.dim) self.rates = (1.0 / 100.0, 1.0 / 200.0) self.sbi = SystemBathInteraction([KK12, KK21], rates=self.rates) self.sbi.set_system(agg) # # VIBRONIC AGGREGATE # vm1 = Molecule([0.0, 1.0]) vm2 = Molecule([0.0, 1.0]) mod1 = Mode(0.01) mod2 = Mode(0.01) vm1.add_Mode(mod1) vm2.add_Mode(mod2) mod1.set_nmax(0, 3) mod1.set_nmax(1, 3) mod2.set_nmax(0, 3) mod2.set_nmax(1, 3) vagg = Aggregate(molecules=[vm1, vm2]) vagg.set_resonance_coupling(0, 1, 0.1) vagg.build() self.vham = vagg.get_Hamiltonian() self.vsbi = SystemBathInteraction([KK12, KK21], rates=self.rates) self.vsbi.set_system(vagg)
import matplotlib.pyplot as plt plt.plot(time.data, sm) plt.axis([0.0,100.0, 0.0, 1.1]) plt.show() # # Molecular dimer without vibrations # from quantarhei import Aggregate mol1 = Molecule(name="Mol 1", elenergies=[0.0, 1.0]) mol2 = Molecule(name="Mol 2", elenergies=[0.0, 1.0]) agg = Aggregate(name="Dimer") agg.add_Molecule(mol1) agg.add_Molecule(mol2) agg.set_resonance_coupling(0,1,0.01) agg.build() H = agg.get_Hamiltonian() print(H) psi = StateVector(3) psi.data[2] = 1.0 dimer_propagator = StateVectorPropagator(time, H)
# en = [0.0, 1.0] m1 = Molecule("Mol1", en) m2 = Molecule("Mol2", en) m3 = Molecule("Mol3", en) m1.set_dipole(0, 1, [1.0, 0.0, 0.0]) time = TimeAxis(0.0, 1000, 1.0) bath_params = dict(ftype="OverdampedBrownian", T=300, cortime=100, reorg=30.0) with energy_units("1/cm"): cf = CorrelationFunction(time, bath_params) m1.set_transition_environment((0, 1), cf) m2.set_transition_environment((0, 1), cf) m3.set_transition_environment((0, 1), cf) ag = Aggregate("Homodimer") ag.add_Molecule(m1) ag.add_Molecule(m2) ag.add_Molecule(m3) ag.set_resonance_coupling(0, 1, 0.1) mult = 2 ag.build(mult=mult, sbi_for_higher_ex=False) # # Look at its various components # H = ag.get_Hamiltonian() print("Shape of the operators")
# -*- coding: utf-8 -*- #<remove> _show_plots_ = False #</remove> from quantarhei import Molecule, Aggregate #from quantarhei import energy_units en = [0.0, 1.0] m1 = Molecule(name="Mol1",elenergies=en) m2 = Molecule(name="Mol2",elenergies=en) ag = Aggregate(name="Homodimer") ag.add_Molecule(m1) ag.add_Molecule(m2) ag.set_resonance_coupling(0,1,0.1) ag.build(mult=1) H = ag.get_Hamiltonian() #with energy_units("1/cm"): # print(H)
tsbi = TimeAxis(0.0, 3 * Nr, 2.0) params = dict(ftype="OverdampedBrownian", T=300, reorg=50.0, cortime=100.0) with energy_units('1/cm'): cf = CorrelationFunction(tsbi, params) mol1.set_transition_environment((0, 1), cf) mol2.set_transition_environment((0, 1), cf) mol3.set_transition_environment((0, 1), cf) mol4.set_transition_environment((0, 1), cf) # # Creating aggregate # agg = Aggregate("Dimer", molecules=[mol1, mol2, mol3, mol4]) #agg = Aggregate("Dimer", molecules=[mol1, mol2, mol3]) with energy_units("1/cm"): agg.set_resonance_coupling(0, 1, 60.0) agg.set_resonance_coupling(1, 2, 60.0) agg.set_resonance_coupling(0, 2, 30.0) agg.set_resonance_coupling(1, 3, 30.0) pass #agg.set_coupling_by_dipole_dipole() agg.build(mult=2) with energy_units("1/cm"): rwa_cm = agg.get_RWA_suggestion()
class AggregateTest(unittest.TestCase): """Tests for the Manager class """ def setUp(self): m1 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m2 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) time = TimeAxis(0.0, 1000, 1.0) params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300) with energy_units("1/cm"): fc = CorrelationFunction(time, params) m1.set_transition_environment((0, 1), fc) m1.position = [0.0, 0.0, 0.0] m1.set_dipole(0, 1, [10.0, 0.0, 0.0]) m2.set_transition_environment((0, 1), fc) m2.position = [10.0, 0.0, 0.0] m2.set_dipole(0, 1, [10.0, 0.0, 0.0]) self.agg = Aggregate(name="TestAgg", molecules=[m1, m2]) self.agg.set_coupling_by_dipole_dipole() self.agg.build() m3 = Molecule(name="Molecule 1", elenergies=[0.0, 1.0]) m4 = Molecule(name="Molecule 2", elenergies=[0.0, 1.0]) m3.add_Mode(Mode(0.01)) m4.add_Mode(Mode(0.01)) mod3 = m3.get_Mode(0) mod4 = m4.get_Mode(0) mod3.set_nmax(0, 4) mod3.set_nmax(1, 4) mod3.set_HR(1, 0.1) mod4.set_nmax(0, 4) mod4.set_nmax(1, 4) mod4.set_HR(1, 0.3) self.vagg = Aggregate(molecules=[m3, m4]) self.vagg.build() ######################################################################### # # TESTS # ######################################################################### def test_saving_of_aggregate(self): """(Aggregate) Testing its saving capability """ use_temporary_file = True if use_temporary_file: #drv = "core" #bcs = False #with h5py.File('tempfile.hdf5', # driver=drv, # backing_store=bcs) as f: with tempfile.TemporaryFile() as f: self.agg.save(f, test=True) #,report_unsaved=True) # reread it agg = Aggregate() agg = agg.load(f, test=True) else: #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp', 'wb') as f: self.agg.save(f) #with h5py.File('tempfile.hdf5') as f: with open('tempfile.qrp', 'rb') as f: agg = Aggregate() agg.load(f) self.assertEqual(self.agg.nmono, agg.nmono) self.assertEqual(self.agg.mult, agg.mult) self.assertEqual(self.agg.sbi_mult, agg.sbi_mult) self.assertEqual(self.agg.name, agg.name) self.assertEqual(self.agg._has_egcf_matrix, agg._has_egcf_matrix) self.assertEqual(self.agg._has_system_bath_interaction, agg._has_system_bath_interaction) self.assertEqual(self.agg.coupling_initiated, agg.coupling_initiated) self.assertEqual(self.agg._has_relaxation_tensor, agg._has_relaxation_tensor) self.assertEqual(self.agg._relaxation_theory, agg._relaxation_theory) self.assertEqual(self.agg._built, agg._built) self.assertEqual(self.agg.Nel, agg.Nel) self.assertEqual(self.agg.Ntot, agg.Ntot) numpy.testing.assert_array_equal(self.agg.Nb, agg.Nb) for key in agg.mnames.keys(): self.assertEqual(self.agg.mnames[key], agg.mnames[key]) numpy.testing.assert_array_equal(self.agg.resonance_coupling, agg.resonance_coupling) mnames = ["Molecule 1", "Molecule 2"] for k in range(agg.nmono): m = agg.monomers[k] self.assertIn(m.name, mnames) mnames.remove(m.name) def test_trace_over_vibrations(self): """(Aggregate) Testing trace over vibrational DOF """ agg = self.vagg ham = agg.get_Hamiltonian() rho = ReducedDensityMatrix(dim=ham.dim) rho._data[5, 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=7) N = agg.Nb[0] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N + 5, N + 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=3) N = agg.Nb[1] rho = ReducedDensityMatrix(dim=ham.dim) rho._data[N + 5, N + 5] = 1.0 redr = agg.trace_over_vibrations(rho) numpy.testing.assert_almost_equal(numpy.trace(redr._data), 1.0, decimal=2) def test_get_Density_Matrix_thermal(self): """(Aggregate) Testing the get_Densitymatrix method with `thermal` condition type """ from quantarhei.core.units import kB_intK vagg = self.vagg H = vagg.get_Hamiltonian() N = H.data.shape[0] # zero temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal") tst0 = numpy.zeros((N, N), dtype=qr.COMPLEX) tst0[0, 0] = 1.0 numpy.testing.assert_almost_equal(rho0.data, tst0) # room temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal", temperature=300) # cannonical balance between neighboring states is tested kbT = kB_intK * 300.0 for k in range(N - 1): E2 = H.data[k + 1, k + 1] E1 = H.data[k, k] ratio = numpy.exp(-(E2 - E1) / kbT) numpy.testing.assert_almost_equal( ratio, rho0.data[k + 1, k + 1] / rho0.data[k, k]) def test_get_Density_Matrix_thermal_excited(self): """(Aggregate) Testing the get_Densitymatrix method with `thermal_excited_state` condition type """ from quantarhei.core.units import kB_intK vagg = self.vagg H = vagg.get_Hamiltonian() N = H.data.shape[0] Nb0 = vagg.Nb[0] # zero temperature rho0 = vagg.get_DensityMatrix(condition_type="thermal_excited_state") tst0 = numpy.zeros((N, N), dtype=qr.COMPLEX) tst0[Nb0, Nb0] = 1.0 numpy.testing.assert_almost_equal(rho0.data, tst0) # room temperature kbT = kB_intK * 300.0 H = self.agg.get_Hamiltonian() N = H.data.shape[0] Nb0 = self.agg.Nb[0] with qr.eigenbasis_of(H): rho0 = self.agg.get_DensityMatrix( condition_type="thermal_excited_state", temperature=300) tst0 = numpy.zeros((N, N), dtype=qr.COMPLEX) with qr.eigenbasis_of(H): ssum = 0.0 for i in range(Nb0, N): tst0[i, i] = numpy.exp(-(H.data[i, i] - H.data[Nb0, Nb0]) / kbT) ssum += tst0[i, i] tst0 = tst0 / ssum numpy.testing.assert_almost_equal(rho0.data, tst0) # ssum = 0.0 # for i in range(N): # tst0[i,i] = numpy.exp(-H.data[i,i]/kbT) # ssum += tst0[i,i] # tst0 = tst0/ssum # # DD = vagg.TrDMOp.data # # abs value of the transition dipole moment # dabs = numpy.sqrt(DD[:,:,0]**2 + \ # DD[:,:,1]**2 + DD[:,:,2]**2) # # excitation from bra and ket # tst0 = numpy.dot(dabs, numpy.dot(tst0,dabs)) # # numpy.testing.assert_almost_equal(rho0.data, tst0) def test_get_temperature(self): """(Aggregate) Testing temperature retrieval """ agg = self.agg T = agg.get_temperature() numpy.testing.assert_almost_equal(T, 300.0) def test_init_coupling_matrix(self): """(Aggregate) Testing coupling matrix initialization """ agg = TestAggregate(name="dimer-2-env") self.assertFalse(agg.coupling_initiated) agg.init_coupling_matrix() self.assertTrue(agg.coupling_initiated) self.assertAlmostEqual(0.0, agg.resonance_coupling[0, 1]) def test_set_resonance_coupling(self): """(Aggregate) Testing resonance coupling setting with different units """ agg = TestAggregate(name="dimer-2-env") agg.init_coupling_matrix() agg.set_resonance_coupling(0, 1, 1.0) self.assertAlmostEqual(1.0, agg.resonance_coupling[0, 1]) self.assertAlmostEqual(1.0, agg.resonance_coupling[1, 0]) with qr.energy_units("1/cm"): agg.set_resonance_coupling(0, 1, 100.0) self.assertAlmostEqual(qr.convert(100.0, "1/cm", "int"), agg.resonance_coupling[0, 1]) self.assertAlmostEqual(qr.convert(100.0, "1/cm", "int"), agg.resonance_coupling[1, 0]) def test_get_resonance_coupling(self): """(Aggregate) Testing resonance coupling retrieval in different units """ agg = TestAggregate(name="dimer-2-env") agg.init_coupling_matrix() agg.set_resonance_coupling(0, 1, 1.0) coup = agg.get_resonance_coupling(1, 0) self.assertAlmostEqual(coup, 1.0) with qr.energy_units("1/cm"): coup = agg.get_resonance_coupling(1, 0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "1/cm")) with qr.energy_units("eV"): coup = agg.get_resonance_coupling(1, 0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "eV")) with qr.energy_units("THz"): coup = agg.get_resonance_coupling(1, 0) self.assertAlmostEqual(coup, qr.convert(1.0, "int", "THz")) def test_set_resonance_coupling_matrix(self): """(Aggregate) Testing setting the whole resonance coupling matrix """ agg = TestAggregate(name="dimer-2-env") mat = [[0.0, 1.0], [1.0, 0.0]] agg.set_resonance_coupling_matrix(mat) self.assertAlmostEqual(agg.resonance_coupling[1, 0], 1.0) self.assertAlmostEqual(agg.resonance_coupling[0, 1], 1.0) self.assertAlmostEqual(agg.resonance_coupling[0, 0], 0.0) self.assertAlmostEqual(agg.resonance_coupling[1, 1], 0.0) mat = ((0.0, 500.0), (500.0, 0.0)) with qr.energy_units("1/cm"): agg.set_resonance_coupling_matrix(mat) inint = qr.convert(500, "1/cm", "int") self.assertAlmostEqual(agg.resonance_coupling[1, 0], inint) self.assertAlmostEqual(agg.resonance_coupling[0, 1], inint) self.assertAlmostEqual(agg.resonance_coupling[0, 0], 0.0) self.assertAlmostEqual(agg.resonance_coupling[1, 1], 0.0) def test_dipole_dipole_coupling(self): """(Aggregate) Testing dipole-dipole coupling calculation """ agg = TestAggregate(name="dimer-2-env") coup1 = agg.dipole_dipole_coupling(0, 1) coup2 = agg.dipole_dipole_coupling(0, 1, epsr=2.0) self.assertAlmostEqual(coup1, coup2 * 2.0) with qr.energy_units("1/cm"): coup = agg.dipole_dipole_coupling(0, 1) self.assertAlmostEqual(qr.convert(coup1, "int", "1/cm"), coup) def test_set_coupling_by_dipole_dipole(self): """(Aggregate) Testing dipole-dipole coupling calculation for the whole agregate """ agg = TestAggregate(name="dimer-2-env") agg.set_coupling_by_dipole_dipole() coup1 = agg.dipole_dipole_coupling(0, 1) self.assertAlmostEqual(coup1, agg.resonance_coupling[0, 1]) with qr.energy_units("1/cm"): agg.set_coupling_by_dipole_dipole() coup1 = agg.dipole_dipole_coupling(0, 1) self.assertAlmostEqual(coup1, agg.resonance_coupling[0, 1]) def test_calculate_resonance_coupling(self): """(Aggregate) Testing resonance coupling calculation by various methods """ agg = TestAggregate(name="dimer-2-env") agg.calculate_resonance_coupling(method="dipole-dipole") coup1 = agg.dipole_dipole_coupling(0, 1) self.assertEqual(coup1, agg.resonance_coupling[1, 0]) with qr.energy_units("1/cm"): agg.calculate_resonance_coupling(method="dipole-dipole") self.assertEqual(coup1, agg.resonance_coupling[1, 0]) def test_add_Molecule(self): """(Aggregate) Testing add_Molecule() method """ agg = TestAggregate(name="dimer-2-env") mol = qr.Molecule(elenergies=[0.0, 1.0]) nmols1 = agg.nmono agg.add_Molecule(mol) nmols2 = agg.nmono self.assertEqual(nmols1 + 1, nmols2) self.assertEqual(len(agg.monomers), nmols2) self.assertLessEqual(len(agg.mnames), nmols2)
# en = [0.0, 1.0] m1 = Molecule("Mol1",en) m2 = Molecule("Mol2",en) m3 = Molecule("Mol3",en) m1.set_dipole(0,1,[1.0, 0.0, 0.0]) time = TimeAxis(0.0, 1000, 1.0) bath_params = dict(ftype="OverdampedBrownian", T=300, cortime=100, reorg=30.0) with energy_units("1/cm"): cf = CorrelationFunction(time, bath_params) m1.set_transition_environment((0,1),cf) m2.set_transition_environment((0,1),cf) m3.set_transition_environment((0,1),cf) ag = Aggregate("Homodimer") ag.add_Molecule(m1) ag.add_Molecule(m2) ag.add_Molecule(m3) ag.set_resonance_coupling(0,1,0.1) mult = 2 ag.build(mult=mult,sbi_for_higher_ex=False) # # Look at its various components #
"A376":"BChl6", "A377":"BChl7", "A378":"BChl8"} for name in names: for m in molecules: if m.name == name: m.set_name(naming_map[name]) # all except for 378 go into aggregate if name != "378": for_aggregate.append(m) # # Create an new aggregate of the Bacteriochlorophylls without BChl8 # agg = Aggregate(name="FMO", molecules=for_aggregate) # Setting site energies according to literature # with energy_units("1/cm"): m = agg.get_Molecule_by_name("BChl1") m.set_energy(1, 12468.0) m = agg.get_Molecule_by_name("BChl2") m.set_energy(1, 12466.0) m = agg.get_Molecule_by_name("BChl3") m.set_energy(1, 12129.0) m = agg.get_Molecule_by_name("BChl4") m.set_energy(1, 12410.0) m = agg.get_Molecule_by_name("BChl5") m.set_energy(1, 12320.0)
m1.set_transition_environment((0,1),cfce2) m2.set_transition_environment((0,1),cfce1) m3.set_transition_environment((0,1),cfce1) m4.set_transition_environment((0,1),cfce2) m5.set_transition_environment((0,1),cfce1) m6.set_transition_environment((0,1),cfce2) m7.set_transition_environment((0,1),cfce1) m8.set_transition_environment((0,1),cfce1) m9.set_transition_environment((0,1),cfce2) m10.set_transition_environment((0,1),cfce2) m11.set_transition_environment((0,1),cfce2) m12.set_transition_environment((0,1),cfce1) # create an aggregate AG = Aggregate("TestAggregate") if explicit_mapping: AG.set_egcf_matrix(cm) # fill the cluster with monomers AG.add_Molecule(m1) AG.add_Molecule(m2) AG.add_Molecule(m3) AG.add_Molecule(m4) AG.add_Molecule(m5) AG.add_Molecule(m6) AG.add_Molecule(m7) AG.add_Molecule(m8) AG.add_Molecule(m9) AG.add_Molecule(m10)
# FIXME: temporary fix for version 0.0.34 # Manager().gen_conf.legacy_relaxation = True # # PURELY ELECTRONIC Aggregate of two molecules # from quantarhei import Molecule m1 = Molecule([0.0, 1.0]) m2 = Molecule([0.0, 1.1]) m3 = Molecule([0.0, 1.2]) from quantarhei import Aggregate agg = Aggregate([m1, m2, m3]) agg.build() # # Operator describing relaxation # from quantarhei.qm import Operator HH = agg.get_Hamiltonian() K = Operator(dim=HH.dim,real=True) K.data[1,2] = 1.0 # # System bath interaction with prescribed rate # from quantarhei.qm import SystemBathInteraction
def redfield_relaxation(self): print("Redfield rate calculation") # # Correlation function # params = { "ftype": world.ctype, "reorg": world.reorg, "cortime": world.ctime, "T": world.temp, "matsubara": world.mats } # FIXME: also time_units, temperature_units with energy_units(world.e_units): cf = CorrelationFunction(world.ta, params) # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule([0.0, en], "mol1") m2 = Molecule([0.0, en], "mol2") # m3 = Molecule("mol2", [0.0, en]) m1.set_egcf((0, 1), cf) m2.set_egcf((0, 1), cf) # m3.set_egcf((0,1), cf) agg = Aggregate(name="Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) # agg.add_Molecule(m3) # with energy_units("1/cm"): # Hm = m1.get_Hamiltonian() # print(Hm) # print(m.convert_energy_2_current_u(Hm._data)) with energy_units(world.r_units): agg.set_resonance_coupling(0, 1, world.r_coupl) # agg.set_resonance_coupling(1,2,world.r_coupl) agg.build() H = agg.get_Hamiltonian() # with energy_units("1/cm"): # print(H) # print(m.convert_energy_2_current_u(H._data)) sbi = agg.get_SystemBathInteraction() RRM = RedfieldRateMatrix(H, sbi) world.K12 = numpy.real(RRM.data[1, 2]) dim = H.dim rates_M = numpy.zeros(dim * dim) k = 0 for i in range(dim): for j in range(dim): rates_M[k] = RRM.data[i, j] k += 1 world.rates_M = rates_M
tsbi = TimeAxis(0.0, 3 * Nr, 10.0) params = dict(ftype="OverdampedBrownian", T=300, reorg=30.0, cortime=50.0) with energy_units('1/cm'): cf = CorrelationFunction(tsbi, params) mol1.set_transition_environment((0, 1), cf) mol2.set_transition_environment((0, 1), cf) mol3.set_transition_environment((0, 1), cf) mol4.set_transition_environment((0, 1), cf) # # Creating aggregate # agg = Aggregate(molecules=molecules) #agg = Aggregate("Dimer", molecules=[mol1, mol2, mol3]) if True: with energy_units("1/cm"): agg.set_resonance_coupling(0, 1, 60.0) agg.set_resonance_coupling(1, 2, 60.0) agg.set_resonance_coupling(0, 2, 30.0) agg.set_resonance_coupling(1, 3, 30.0) pass #agg.set_coupling_by_dipole_dipole() agg.build(mult=2) with energy_units("1/cm"):
"A377": "BChl7", "A378": "BChl8" } for name in names: for m in molecules: if m.name == name: m.set_name(naming_map[name]) # all except for 378 go into aggregate if name != "378": for_aggregate.append(m) # # Create an new aggregate of the Bacteriochlorophylls without BChl8 # agg = Aggregate(name="FMO", molecules=for_aggregate) # Setting site energies according to literature # with energy_units("1/cm"): m = agg.get_Molecule_by_name("BChl1") m.set_energy(1, 12468.0) m = agg.get_Molecule_by_name("BChl2") m.set_energy(1, 12466.0) m = agg.get_Molecule_by_name("BChl3") m.set_energy(1, 12129.0) m = agg.get_Molecule_by_name("BChl4") m.set_energy(1, 12410.0) m = agg.get_Molecule_by_name("BChl5") m.set_energy(1, 12320.0) m = agg.get_Molecule_by_name("BChl6")
def redfield_tensor(self): print("Redfield tensor calculation") # # Correlation function # params = { "ftype": world.ctype, "reorg": world.reorg, "cortime": world.ctime, "T": world.temp, "matsubara": world.mats } # FIXME: also time_units, temperature_units with energy_units(world.e_units): cf = CorrelationFunction(world.ta, params) # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule("mol1", [0.0, en]) m2 = Molecule("mol2", [0.0, en]) m1.set_egcf((0, 1), cf) m2.set_egcf((0, 1), cf) agg = Aggregate("Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) # m = Manager() ## # with energy_units("1/cm"): # Hm = m1.get_Hamiltonian() # print(Hm) # print(m.convert_energy_2_current_u(Hm._data)) with energy_units(world.r_units): agg.set_resonance_coupling(0, 1, world.r_coupl) agg.build() H = agg.get_Hamiltonian() world.HH = H ## # with energy_units("1/cm"): # print(H) # print(m.convert_energy_2_current_u(H._data)) sbi = agg.get_SystemBathInteraction() H.protect_basis() with eigenbasis_of(H): RRT = RedfieldRelaxationTensor(H, sbi) dim = H.dim rates_T = numpy.zeros(dim * dim) k = 0 world.K12 = numpy.real(RRT.data[1, 1, 2, 2]) for i in range(dim): for j in range(dim): rates_T[k] = numpy.real(RRT.data[i, i, j, j]) k += 1 world.rates_T = rates_T
def absorption_spectrum_trimer(self): dd1 = [0.0, 3.0, 0.0] dd2 = [0.0, 1.0, 2.0] dd3 = [0.0, 1.0, 1.0] cf = world.cf with energy_units("1/cm"): m1 = Molecule([0.0, 12100]) m1.set_dipole(0, 1, dd1) m1.set_transition_environment((0, 1), cf) m2 = Molecule([0.0, 11800]) m2.set_dipole(0, 1, dd2) m2.set_transition_environment((0, 1), cf) m3 = Molecule([0.0, 12500]) m3.set_dipole(0, 1, dd3) m3.set_transition_environment((0, 1), cf) m1.position = [0.0, 0.0, 0.0] m2.position = [5.0, 0.0, 0.0] m3.position = [0.0, 5.0, 0.0] AG = Aggregate(name="TestAggregate") AG.add_Molecule(m1) AG.add_Molecule(m2) AG.add_Molecule(m3) AG.set_coupling_by_dipole_dipole(epsr=3.0) AG.build() (RRr, hamr) = AG.get_RelaxationTensor(world.ta, relaxation_theory="standard_Redfield", time_dependent=True) ac = AbsSpectrumCalculator(world.ta, AG, relaxation_tensor=RRr, effective_hamiltonian=hamr) with energy_units("1/cm"): ac.bootstrap(rwa=12000) a1 = ac.calculate() with energy_units("1/cm"): world.abs = numpy.zeros((len(a1.data), 2)) for kk in range(len(a1.data)): world.abs[kk, 0] = a1.axis.data[kk] #frequency[kk] world.abs[kk, 1] = a1.data[kk]
# FIXME: temporary fix for version 0.0.34 # Manager().gen_conf.legacy_relaxation = True # # PURELY ELECTRONIC Aggregate of two molecules # from quantarhei import Molecule m1 = Molecule([0.0, 1.0]) m2 = Molecule([0.0, 1.1]) m3 = Molecule([0.0, 1.2]) from quantarhei import Aggregate agg = Aggregate([m1, m2, m3]) agg.build() # # Operator describing relaxation # from quantarhei.qm import Operator HH = agg.get_Hamiltonian() K = Operator(dim=HH.dim, real=True) K.data[1, 2] = 1.0 # # System bath interaction with prescribed rate # from quantarhei.qm import SystemBathInteraction
def redfield_tensor(self): print("Redfield tensor calculation") # # Correlation function # params = {"ftype": world.ctype, "reorg": world.reorg, "cortime": world.ctime, "T": world.temp, "matsubara":world.mats} # FIXME: also time_units, temperature_units with energy_units(world.e_units): cf = CorrelationFunction(world.ta,params) # # Homodimer # with energy_units(world.h_units): en = world.senergy m1 = Molecule([0.0, en], "mol1") m2 = Molecule([0.0, en], "mol2") m1.set_egcf((0,1), cf) m2.set_egcf((0,1), cf) agg = Aggregate(name="Homodimer") agg.add_Molecule(m1) agg.add_Molecule(m2) # m = Manager() ## # with energy_units("1/cm"): # Hm = m1.get_Hamiltonian() # print(Hm) # print(m.convert_energy_2_current_u(Hm._data)) with energy_units(world.r_units): agg.set_resonance_coupling(0,1,world.r_coupl) agg.build() H = agg.get_Hamiltonian() world.HH = H ## # with energy_units("1/cm"): # print(H) # print(m.convert_energy_2_current_u(H._data)) sbi = agg.get_SystemBathInteraction() H.protect_basis() with eigenbasis_of(H): RRT = RedfieldRelaxationTensor(H, sbi) dim = H.dim rates_T = numpy.zeros(dim*dim) k = 0 world.K12 = numpy.real(RRT.data[1,1,2,2]) for i in range(dim): for j in range(dim): rates_T[k] = numpy.real(RRT.data[i,i,j,j]) k += 1 world.rates_T = rates_T