def test_units_management(self): """Testing that Hamiltonian is EnergyUnitsManaged """ cm2int = 2.0 * const.pi * const.c * 1.0e-13 self.assertEquals(self.H.unit_repr(), "2pi/fs") if self.verbose: print("In internal:") print(self.H.data) with energy_units("1/cm"): self.assertEquals(self.H.unit_repr(), "1/cm") self.assertEquals(self.H.data[0, 1], 1.0 / cm2int) if self.verbose: print("In 1/cm:") print(self.H.data) H2 = Hamiltonian(data=[[1000.0, 0.0], [0.0, 2000.0]]) self.assertAlmostEqual(H2.data[0, 0], 1000.0) self.assertAlmostEqual(H2.data[1, 1], 2000.0) self.assertAlmostEqual(H2.data[0, 0], 1000.0 * cm2int) self.assertAlmostEqual(H2.data[1, 1], 2000.0 * cm2int) if self.verbose: print("In internal:") print(self.H.data)
def setUp(self, verbose=False): self.verbose = verbose time = TimeAxis(0.0, 1000, 1.0) with energy_units("1/cm"): params = { "ftype": "OverdampedBrownian", "reorg": 30.0, "T": 300.0, "cortime": 100.0 } cf1 = CorrelationFunction(time, params) cf2 = CorrelationFunction(time, params) sd = SpectralDensity(time, params) cm1 = CorrelationFunctionMatrix(time, 2, 1) cm1.set_correlation_function(cf1, [(0, 0), (1, 1)]) cm2 = CorrelationFunctionMatrix(time, 2, 1) cm2.set_correlation_function(cf2, [(0, 0), (1, 1)]) K11 = numpy.array([[1.0, 0.0], [0.0, 0.0]], dtype=numpy.float) K21 = numpy.array([[1.0, 0.0], [0.0, 0.0]], dtype=numpy.float) K12 = K11.copy() K22 = K21.copy() KK11 = Operator(data=K11) KK21 = Operator(data=K21) KK12 = Operator(data=K12) KK22 = Operator(data=K22) self.sbi1 = SystemBathInteraction([KK11, KK21], cm1) self.sbi2 = SystemBathInteraction([KK12, KK22], cm2) with energy_units("1/cm"): h1 = [[0.0, 100.0], [100.0, 0.0]] h2 = [[0.0, 100.0], [100.0, 0.0]] self.H1 = Hamiltonian(data=h1) self.H2 = Hamiltonian(data=h2) #sd.convert_2_spectral_density() with eigenbasis_of(self.H1): de = self.H1.data[1, 1] - self.H1.data[0, 0] self.c_omega_p = sd.at(de, approx="spline") #interp_data(de) self.c_omega_m = sd.at(-de, approx="spline") #interp_data(-de)
def thermal_population_comparison(self, temp, atol): """Creates canonical populations and checks them against the results from relaxation tensor #begin_feature Then long time Redfield-Foerster populations will correspond to canonical equilibrium with temperature <temp> K with atol <atol> #end_feature """ print("Testing Redfield-Foerster theory") ccutoff = world.ccutoff agg = world.aggregate rho0 = ReducedDensityMatrix(dim=world.N) H = world.aggregate.get_Hamiltonian() H1 = Hamiltonian(data=H.data.copy()) with energy_units("1/cm"): print(H1) print(ccutoff, "1/cm", H1.dim) H1.remove_cutoff_coupling(ccutoff) print(H1) print("\nExpected thermal population at ", temp, "K") with eigenbasis_of(H1): rhoT = agg.get_DensityMatrix(condition_type="thermal_excited_state", relaxation_theory_limit="strong_coupling", temperature=world.temperature) pop_T = numpy.zeros(world.N, dtype=numpy.float64) for i in range(world.N): pop_T[i] = numpy.real(rhoT.data[i, i]) print(i, ":", pop_T[i]) print("Final calculated population") rho0.data[world.N - 1, world.N - 1] = 1.0 rho_t = world.prop.propagate(rho0) pop_C = numpy.zeros(world.N, dtype=numpy.float64) for i in range(world.N): pop_C[i] = numpy.real(rho_t.data[world.time.length - 1, i, i]) print(i, ":", pop_C[i]) print("absolute tolerance atol=", float(atol)) numpy.testing.assert_allclose(pop_C, pop_T, atol=float(atol))
class TestHamiltonian(unittest.TestCase): """Tests for the Hamiltonian class """ def setUp(self,verbose=False): self.h = [[0.0, 1.0],[1.0, 2.0]] self.H = Hamiltonian(data=self.h) self.verbose = verbose def test_units_management(self): """Testing that Hamiltonian is EnergyUnitsManaged """ cm2int = 2.0*const.pi*const.c*1.0e-13 self.assertEquals(self.H.unit_repr(),"1/fs") if self.verbose: print("In internal:") print(self.H.data) with energy_units("1/cm"): self.assertEquals(self.H.unit_repr(),"1/cm") self.assertEquals(self.H.data[0,1],1.0/cm2int) if self.verbose: print("In 1/cm:") print(self.H.data) H2 = Hamiltonian(data=[[1000.0, 0.0],[0.0, 2000.0]]) self.assertAlmostEqual(H2.data[0,0],1000.0) self.assertAlmostEqual(H2.data[1,1],2000.0) self.assertAlmostEqual(H2.data[0,0],1000.0*cm2int) self.assertAlmostEqual(H2.data[1,1],2000.0*cm2int) if self.verbose: print("In internal:") print(self.H.data)
class TestHamiltonian(unittest.TestCase): """Tests for the Hamiltonian class """ def setUp(self, verbose=False): self.h = [[0.0, 1.0], [1.0, 2.0]] self.H = Hamiltonian(data=self.h) self.verbose = verbose def test_units_management(self): """Testing that Hamiltonian is EnergyUnitsManaged """ cm2int = 2.0 * const.pi * const.c * 1.0e-13 self.assertEquals(self.H.unit_repr(), "1/fs") if self.verbose: print("In internal:") print(self.H.data) with energy_units("1/cm"): self.assertEquals(self.H.unit_repr(), "1/cm") self.assertEquals(self.H.data[0, 1], 1.0 / cm2int) if self.verbose: print("In 1/cm:") print(self.H.data) H2 = Hamiltonian(data=[[1000.0, 0.0], [0.0, 2000.0]]) self.assertAlmostEqual(H2.data[0, 0], 1000.0) self.assertAlmostEqual(H2.data[1, 1], 2000.0) self.assertAlmostEqual(H2.data[0, 0], 1000.0 * cm2int) self.assertAlmostEqual(H2.data[1, 1], 2000.0 * cm2int) if self.verbose: print("In internal:") print(self.H.data)
def setUp(self, verbose=False): self.verbose = verbose K12 = numpy.array([[0.0, 1.0], [0.0, 0.0]], dtype=numpy.float) K21 = numpy.array([[0.0, 0.0], [1.0, 0.0]], dtype=numpy.float) KK12 = Operator(data=K12) KK21 = Operator(data=K21) self.KK12 = KK12 self.KK21 = KK21 self.rates = (1.0 / 100.0, 1.0 / 200.0) self.sbi1 = SystemBathInteraction([KK12, KK21], rates=self.rates) self.sbi2 = SystemBathInteraction([KK12, KK21], rates=self.rates) with energy_units("1/cm"): h1 = [[100.0, 0.0], [0.0, 0.0]] h2 = [[100.0, 0.0], [0.0, 0.0]] self.H1 = Hamiltonian(data=h1) self.H2 = Hamiltonian(data=h2)
def setUp(self, verbose=False): self.verbose = verbose # # Lindblad projection operators # K12 = numpy.array([[0.0, 1.0], [0.0, 0.0]], dtype=numpy.float) K21 = numpy.array([[0.0, 0.0], [1.0, 0.0]], dtype=numpy.float) KK12 = Operator(data=K12) KK21 = Operator(data=K21) self.KK12 = KK12 self.KK21 = KK21 # # Linbdlad rates # self.rates = (1.0 / 100.0, 1.0 / 200.0) # # System-bath interaction using operators and rates in site basis # self.sbi1 = SystemBathInteraction([KK12, KK21], rates=self.rates) self.sbi2 = SystemBathInteraction([KK12, KK21], rates=self.rates) # # Test Hamiltonians # with energy_units("1/cm"): h1 = [[100.0, 0.0], [0.0, 0.0]] h2 = [[100.0, 0.0], [0.0, 0.0]] self.H1 = Hamiltonian(data=h1) self.H2 = Hamiltonian(data=h2) h3 = [[100.0, 20.0], [20.0, 0.0]] self.H3 = Hamiltonian(data=h3) # less trivial Hamiltonian h4 = [[100.0, 200.0, 30.0], [200.0, 50.0, -100.0], [30.0, -100.0, 0.0]] self.H4 = Hamiltonian(data=h4) h4s = [[100.0, 0.0, 0.0], [0.0, 50.0, 0.0], [0.0, 0.0, 0.0]] self.H4s = Hamiltonian(data=h4s) # # Projection operators in eigenstate basis # with eigenbasis_of(self.H3): K_12 = ProjectionOperator(0, 1, dim=2) K_21 = ProjectionOperator(1, 0, dim=2) self.K_12 = K_12 self.K_21 = K_21 with eigenbasis_of(self.H4): Ke_12 = ProjectionOperator(0, 1, dim=3) Ke_21 = ProjectionOperator(1, 0, dim=3) Ke_23 = ProjectionOperator(1, 2, dim=3) Ke_32 = ProjectionOperator(2, 1, dim=3) Ks_12 = ProjectionOperator(0, 1, dim=3) Ks_21 = ProjectionOperator(1, 0, dim=3) Ks_23 = ProjectionOperator(1, 2, dim=3) Ks_32 = ProjectionOperator(2, 1, dim=3) self.rates4 = [1.0 / 100, 1.0 / 200, 1.0 / 150, 1.0 / 300] # # System-bath operators defined in exciton basis # self.sbi3 = SystemBathInteraction([K_12, K_21], rates=self.rates) self.sbi4e = SystemBathInteraction([Ke_12, Ke_21, Ke_23, Ke_32], rates=self.rates4) self.sbi4s = SystemBathInteraction([Ks_12, Ks_21, Ks_23, Ks_32], rates=self.rates4)
def setUp(self, verbose=False): self.h = [[0.0, 1.0], [1.0, 2.0]] self.H = Hamiltonian(data=self.h) self.verbose = verbose
# # # EXAMPLE 2.1 # # # ############################################################################### """) # # Hamiltonian of a 2 level molecule with adiabatic coupling # Default energy units are radians per femtosecond (rad/fs) # print(""" We define a simple 2x2 Hamiltonian and an initial state vector with the excited state completely populated. """) h = [[0.0, 0.4], [0.4, 1.0]] H = Hamiltonian(data=h) # # Initial state vector to be propagated by the Hamiltonian above # psi_0 = StateVector(data=[0.0, 1.0]) # # Check the Hamiltonian and state vector # print("Here are the two objects: ") print(H) print(psi_0) pause("\nWe will proceed to calculate time evolution ...")
def setUp(self,verbose=False): self.h = [[0.0, 1.0],[1.0, 2.0]] self.H = Hamiltonian(data=self.h) self.verbose = verbose
# EXAMPLE 2.1 # # # ############################################################################### """) # # Hamiltonian of a 2 level molecule with adiabatic coupling # Default energy units are radians per femtosecond (rad/fs) # print(""" We define a simple 2x2 Hamiltonian and an initial state vector with the excited state completely populated. """) h = [[0.0, 0.4], [0.4, 1.0]] H = Hamiltonian(data=h) # # Initial state vector to be propagated by the Hamiltonian above # psi_0 = StateVector(data=[0.0, 1.0]) # # Check the Hamiltonian and state vector # print("Here are the two objects: ") print(H) print(psi_0) pause("\nWe will proceed to calculate time evolution ...")