Beispiel #1
0
def build_aggregate_2(settings):
    """Example function for building aggregate no. 2"""
    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
Beispiel #2
0
    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')
Beispiel #3
0
 def setUp(self):
     self.en = [0.0, 1.0, 2.0]
     self.m = Molecule(name="Molecule",elenergies=self.en)
     self.m.set_dipole(0,1,[1.0,0.0,0.0])
     self.m.set_dipole(0,2,[0.5,0.0,0.0])
 
     self.rho_eq = self.m.get_thermal_ReducedDensityMatrix()
 def setUp(self,verbose=False):
     
     fluors = FluorSpectrumBase()
     with energy_units("1/cm"):
         f = FrequencyAxis(10000.0,2000, 1.0)
         a = self._spectral_shape(f, [1.0, 11000.0, 100.0])
         fluors.axis = f
         fluors.data = a
     self.fluors = fluors
     self.axis = fluors.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])
         params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100,
                       T=300)
         mol1.set_dipole(0,1,[0.0, 1.0, 0.0])
         cf = CorrelationFunction(time, params)
         mol1.set_transition_environment((0,1),cf)
         
         fluor_calc = FluorSpectrumCalculator(time, system=mol1)
         fluor_calc.bootstrap(rwa=12000)
         
     fluor1 = fluor_calc.calculate()
     
     self.fluor1 = fluor1
Beispiel #5
0
class TestReducedDensityMatrix(unittest.TestCase):
    """Tests for the Manager class
    
    
    """
    def setUp(self):
        self.en = [0.0, 1.0, 2.0]
        self.m = Molecule(name="Molecule", elenergies=self.en)
        self.m.set_dipole(0, 1, [1.0, 0.0, 0.0])
        self.m.set_dipole(0, 2, [0.5, 0.0, 0.0])

        self.rho_eq = self.m.get_thermal_ReducedDensityMatrix()

    def test_excitation_by_delta(self):
        """Testing reduced density matrix excitation by delta-pulse
        
        
        """

        rho_exp = numpy.zeros((3, 3), dtype=numpy.float)
        rho_exp[0, 0] = 1.0

        self.assertTrue(numpy.allclose(self.rho_eq._data, rho_exp))

        dd = self.m.get_TransitionDipoleMoment()
        epol = [1.0, 0.0, 0.0]

        rho_ex = self.rho_eq.excite_delta(dmoment=dd, epolarization=epol)

        rho_exp = numpy.array([[0.00 + 0.j, 0.00 + 0.j, 0.00 + 0.j],
                               [0.00 + 0.j, 1.00 + 0.j, 0.50 + 0.j],
                               [0.00 + 0.j, 0.50 + 0.j, 0.25 + 0.j]])

        self.assertTrue(numpy.allclose(rho_exp, rho_ex._data))

        rho_ex2 = self.rho_eq.excite_delta(
            dmoment=dd,
            epolarization=[1.0 / numpy.sqrt(2.0), 1.0 / numpy.sqrt(2.0), 0.0])

        rho_exp2 = numpy.array([[0.000 + 0.j, 0.000 + 0.j, 0.000 + 0.j],
                                [0.000 + 0.j, 0.500 + 0.j, 0.250 + 0.j],
                                [0.000 + 0.j, 0.250 + 0.j, 0.125 + 0.j]])

        self.assertTrue(numpy.allclose(rho_ex2._data, rho_exp2))

    def test_conversion_2_populations(self):
        """Testing conversion of reduced density matrix to population vector
        
        
        """

        rdm = ReducedDensityMatrix(
            data=[[0.5, 0.0, 0.1], [0.0, 0.3, 0.0], [0.1, 0.0, 0.2]])

        pop = rdm.get_populations()

        self.assertTrue(numpy.allclose(pop, [0.5, 0.3, 0.2]))
Beispiel #6
0
 def setUp(self):
     self.en = [0.0, 1.0, 2.0]
     self.m = Molecule(name="Molecule", elenergies=self.en)
     time = TimeAxis(0, 1000, 1.0)
     params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100, T=300)
     with energy_units("1/cm"):
         fc = CorrelationFunction(time, params)
     self.m.set_transition_environment((0, 1), fc)
     self.fc = fc
Beispiel #7
0
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
Beispiel #8
0
    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)
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
Beispiel #10
0
class TestMolecule(unittest.TestCase):
    """Tests for the Manager class
    
    
    """
    def setUp(self):
        self.en = [0.0, 1.0, 2.0]
        self.m = Molecule(name="Molecule", elenergies=self.en)

    def test_Molecule_instantiation(self):
        """Testing Molecule instantiation
        
        
        """

        self.assertEqual(self.m.name, "Molecule")
        for i in range(2):
            self.assertEqual(self.m.elenergies[i], self.en[i])

    def test_get_Hamiltonian(self):
        """Testing that Molecule returns correct Hamiltonian 
        
        """

        H = self.m.get_Hamiltonian()

        h = numpy.zeros((3, 3), dtype=numpy.float)
        h[1, 1] = 1.0
        h[2, 2] = 2.0

        self.assertTrue(numpy.allclose(H.data, h))
Beispiel #11
0
    def setUp(self):
        
        en = [0.0, 1.0]
        self.m = Molecule(name="Molecule",elenergies=en)

        mod1 = Mode(frequency=0.1)
        self.m.add_Mode(mod1)
        mod1.set_nmax(0,3)
        mod1.set_nmax(1,3)
    
        en2 = [0.0,0.1,0.1]
        self.m2 = Molecule(name="AdMolecule",elenergies=en2)    
        self.m2.set_adiabatic_coupling(1,2,0.02)
        mod2 = Mode(frequency=0.01)
        self.m2.add_Mode(mod2)
        mod2.set_nmax(0,3)
        mod2.set_nmax(1,3)
        mod2.set_nmax(2,3)
Beispiel #12
0
    def setUp(self):

        en = [0.0, 1.0]
        self.m = Molecule(name="Molecule", elenergies=en)

        mod1 = Mode(frequency=0.1)
        self.m.add_Mode(mod1)
        mod1.set_nmax(0, 3)
        mod1.set_nmax(1, 3)

        en2 = [0.0, 0.1, 0.1]
        self.m2 = Molecule(name="AdMolecule", elenergies=en2)
        self.m2.set_adiabatic_coupling(1, 2, 0.02)
        mod2 = Mode(frequency=0.01)
        self.m2.add_Mode(mod2)
        mod2.set_nmax(0, 3)
        mod2.set_nmax(1, 3)
        mod2.set_nmax(2, 3)
Beispiel #13
0
 def setUp(self):
     self.en = [0.0, 1.0, 2.0]
     self.m = Molecule(name="Molecule",elenergies=self.en)   
     time = TimeAxis(0,1000,1.0)
     params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100,
                   T=300)
     with energy_units("1/cm"):
         fc = CorrelationFunction(time,params)
     self.m.set_transition_environment((0,1),fc)  
     self.fc = fc
Beispiel #14
0
def absorption_spectrum_molecule(self):

    dd = [0.0,1.0,0.0]
    cf = world.cf
 
    with energy_units("1/cm"):
        m = Molecule([0.0, 12000])
    m.set_dipole(0,1,dd)
    
    m.set_egcf([0,1],cf)
    
    ac = AbsSpectrumCalculator(world.ta,m)
    ac.bootstrap(rwa=m.elenergies[1])
    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]
Beispiel #15
0
def when_molecules_are_created(self):
    N = len(world.e0)
    molecules = []
    for i in range(N):
        e0 = world.e0[i]
        e1 = world.e1[i]
        units = world.units[i]
        m1 = Molecule("Mol",[e0,e1])
        molecules.append(m1)

    world.molecules = molecules
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()
Beispiel #17
0
    def setUp(self, verbose=False):

        abss = AbsSpectrumBase()
        with energy_units("1/cm"):
            f = FrequencyAxis(10000.0, 2000, 1.0)
            a = self._spectral_shape(f, [1.0, 11000.0, 100.0])
            abss.axis = f
            abss.data = a
        self.abss = abss
        self.axis = abss.axis

        time = TimeAxis(0.0, 1000, 1.0)
        with energy_units("1/cm"):
            mol1 = 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])
            cf = CorrelationFunction(time, params)
            mol1.set_transition_environment((0, 1), cf)

            abs_calc = AbsSpectrumCalculator(time, system=mol1)
            abs_calc.bootstrap(rwa=12000)

        abs1 = abs_calc.calculate()

        self.abs1 = abs1
Beispiel #18
0
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
Beispiel #19
0
    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)       
Beispiel #20
0
def absorption_spectrum_molecule(self):

    dd = [0.0, 1.0, 0.0]
    cf = world.cf

    with energy_units("1/cm"):
        m = Molecule("Mol", [0.0, 12000])
    m.set_dipole(0, 1, dd)

    m.set_egcf([0, 1], cf)

    a1 = AbsSpect(world.ta, m)
    a1.calculate(rwa=m.elenergies[1])

    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]
Beispiel #21
0
# -*- coding: utf-8 -*-

from quantarhei import Molecule, Aggregate, CorrelationFunction
from quantarhei import TimeAxis
from quantarhei import energy_units, eigenbasis_of
  
#
# Define and build the system
#  
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
Beispiel #22
0
class TestMolecule(unittest.TestCase):
    """Tests for the Manager class
    
    
    """
    
    def setUp(self):
        self.en = [0.0, 1.0, 2.0]
        self.m = Molecule(name="Molecule",elenergies=self.en)   
        time = TimeAxis(0,1000,1.0)
        params = dict(ftype="OverdampedBrownian", reorg=20, cortime=100,
                      T=300)
        with energy_units("1/cm"):
            fc = CorrelationFunction(time,params)
        self.m.set_transition_environment((0,1),fc)  
        self.fc = fc
        
            
    
    def test_Molecule_instantiation(self):
        """Testing Molecule instantiation
        
        
        """

        
        self.assertEqual(self.m.name,"Molecule")
        for i in range(2):
            self.assertEqual(self.m.elenergies[i],self.en[i])
            
            
    def test_get_Hamiltonian(self):
        """Testing that Molecule returns correct Hamiltonian 
        
        """
        
        H = self.m.get_Hamiltonian()

        h = numpy.zeros((3,3),dtype=numpy.float)
        h[1,1] = 1.0
        h[2,2] = 2.0
        
        self.assertTrue(numpy.allclose(H.data,h))

    def test_saving_of_molecule(self):
        """Testing the saving capability of the Molecule class
        
        
        """
        use_temporary_file = True
        
        with energy_units("1/cm"):
            mod = Mode(frequency=150)
            mod1 = Mode(frequency=100)
            
        m2 = Molecule(elenergies=[0.0, 2.0])
        m2.add_Mode(mod)
        m2.add_Mode(mod1)

        
        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.m.save_as(f,"Molecule")
                self.m.save(f, test=True)
                
                # reread it
                m = Molecule()
                #m.load_as(f,"Molecule")
                m = m.load(f, test=True)

        else:

            #with h5py.File('tempfile.hdf5') as f: 
            with open('tempfile.qrp', 'wb') as f:                                          
                #self.m.save_as(f,"Molecules")
                self.m.save(f)
            
            #with h5py.File('tempfile.hdf5') as f:
            with open('tempfile.qrp', 'rb') as f:
                m = Molecule()
                #m.load_as(f,"Molecules")
                m = m.load(f)
            

        self.assertEqual(self.m.name, m.name)
        self.assertEqual(self.m.nel, m.nel)
        numpy.testing.assert_array_equal(self.m.elenergies, m.elenergies)
        
        numpy.testing.assert_array_equal(
                self.m.get_transition_environment((0,1)).data, self.fc.data)
        
        #with h5py.File('tempfile.hdf5', 
        #               driver=drv, 
        #               backing_store=bcs) as f:
        with tempfile.TemporaryFile() as f:
                                         
            #self.m.save_as(f,"Molecule")
            m2.save(f, test=True)
            
            # reread it
            m3 = Molecule()
            #m.load_as(f,"Molecule")
            m3 = m3.load(f, test=True)

        self.assertEqual(m2.name, m3.name)
        self.assertEqual(m2.nel, m3.nel)
        numpy.testing.assert_array_equal(m2.elenergies, m3.elenergies)
        
        self.assertEqual(m2.get_Mode(0).get_energy(0), mod.get_energy(0))
        self.assertEqual(m2.get_Mode(1).get_energy(0), mod1.get_energy(0))
Beispiel #23
0
    def test_saving_of_molecule(self):
        """Testing the saving capability of the Molecule class
        
        
        """
        use_temporary_file = True
        
        with energy_units("1/cm"):
            mod = Mode(frequency=150)
            mod1 = Mode(frequency=100)
            
        m2 = Molecule(elenergies=[0.0, 2.0])
        m2.add_Mode(mod)
        m2.add_Mode(mod1)

        
        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.m.save_as(f,"Molecule")
                self.m.save(f, test=True)
                
                # reread it
                m = Molecule()
                #m.load_as(f,"Molecule")
                m = m.load(f, test=True)

        else:

            #with h5py.File('tempfile.hdf5') as f: 
            with open('tempfile.qrp', 'wb') as f:                                          
                #self.m.save_as(f,"Molecules")
                self.m.save(f)
            
            #with h5py.File('tempfile.hdf5') as f:
            with open('tempfile.qrp', 'rb') as f:
                m = Molecule()
                #m.load_as(f,"Molecules")
                m = m.load(f)
            

        self.assertEqual(self.m.name, m.name)
        self.assertEqual(self.m.nel, m.nel)
        numpy.testing.assert_array_equal(self.m.elenergies, m.elenergies)
        
        numpy.testing.assert_array_equal(
                self.m.get_transition_environment((0,1)).data, self.fc.data)
        
        #with h5py.File('tempfile.hdf5', 
        #               driver=drv, 
        #               backing_store=bcs) as f:
        with tempfile.TemporaryFile() as f:
                                         
            #self.m.save_as(f,"Molecule")
            m2.save(f, test=True)
            
            # reread it
            m3 = Molecule()
            #m.load_as(f,"Molecule")
            m3 = m3.load(f, test=True)

        self.assertEqual(m2.name, m3.name)
        self.assertEqual(m2.nel, m3.nel)
        numpy.testing.assert_array_equal(m2.elenergies, m3.elenergies)
        
        self.assertEqual(m2.get_Mode(0).get_energy(0), mod.get_energy(0))
        self.assertEqual(m2.get_Mode(1).get_energy(0), mod1.get_energy(0))
Beispiel #24
0
 def setUp(self):
     self.en = [0.0, 1.0, 2.0]
     self.m = Molecule(name="Molecule", elenergies=self.en)
Beispiel #25
0
    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')
Beispiel #26
0
pause("\nLet us add some vibrational states to the studied system ...")

print("""
###############################################################################
#                                                                             #
#    EXAMPLE 2.2                                                              #
#                                                                             #
###############################################################################
""")
#
# The same Hamiltonian using the Molecule class
#

from quantarhei import Molecule

m = Molecule(name="Mol 1", elenergies=[0.0, 1.0])
m.set_adiabatic_coupling(0,1,0.4)

from quantarhei import Mode

vib1 = Mode(frequency=0.01)
m.add_Mode(vib1)

vib1.set_shift(1, 0.5)
vib1.set_nmax(0, 5)
vib1.set_nmax(1, 5)


Hm = m.get_Hamiltonian()
print(Hm)
print(m)
Beispiel #27
0
if verbose:
    print("\nSingle photosynthetic reaction center fluorescence simulation")
    print(  "-------------------------------------------------------------\n")
    
#
# All definitions below are done with energy units of inverse 
# centimeters (1/cm). We use Python's context manager concept for this.
#
# Here we switch to the 1/cm units 
with energy_units("1/cm"):
    
    # Molecule named "RC-P" with three states (ground, CT and exciton state)
    # is created
    en = [0.0, 14500, 15500]
    m = Molecule("RC-P",en)    

    # Transition dipole moment from 0 -> 2 (exciton state) is set to 
    # a unit vector in the direction of x-axis (this choice is arbitrary)
    di = numpy.sqrt(23.0)*0.20819434
    m.set_dipole(0,2,[di,0.0,0.0])
    
    #
    # To represent CT coordinate, we add an explicite harmonic mode 
    # to the molecule.
    #
    
    # First the mode with frequency 10 1/cm is created
    qct = Mode(frequency=10.0)
    # and registered with the molecule
    m.add_Mode(qct)
    def setup(self):
        """Simulation definition
        
        
        In this method we define the simulation. We have to define molecular
        system, type of system-bath interaction and the theory to handel it, 
        and the data to be calculated. Below, the definition sections are 
        described in detail together with the definition options and required
        Quantarhei imports.
        
        
        
        """
        ###############################################################
        #
        #     General section
        #
        ###############################################################
        from quantarhei import TimeAxis
        
        # time interval of propagation
        self.timeaxis = TimeAxis(0.0, 1000, 1.0)
        
        ###############################################################
        #
        #     Molecular system definition section
        #
        ###############################################################
        from quantarhei import Molecule
        from quantarhei import energy_units
        
        # define as many molecules as you want
        # use energy units of your choice
        with energy_units("1/cm"):
            m1 = Molecule([0.0, 12000.0])
            m2 = Molecule([0.0, 12200.0])
            m3 = Molecule([0.0, 12000.0])
        
        # optionally you can specify positions (default units are Angstroms)
        m1.position = [0.0, 0.0, 0.0]
        m2.position = [10.0, 0.0, 0.0]
        m3.position = [0.0, 10.0, 0.0]
        
        # transition dipole moments for selected transitions
        m1.set_dipole(0, 1, [12.0, 0.0, 0.0])
        m2.set_dipole(0, 1, [8.0, 8.0, 0.0])
        m3.set_dipole(0, 1, [0.0, 8.0, 8.0])
        
        # couplings between molecules
        #
        #self.coupling_matrix = [[0.0, 100.0],
        #                        [100.0, 0.0]]
        #self.energy_units = "1/cm"
        #
        # or
        #
        self.coupling_matrix = "by_dipole_dipole"
        #
        
        # setting molecules is compulsory
        self.molecules = [m1, m2, m3]
        
        ##############################################################
        #
        #    Type of excitonic problem section
        #
        ##############################################################
        
        # here we define what kind of problem we calculate
        self.exciton_type = "electronic"
        #self.exciton_type = "vibronic"
        
        # exciton multiplicity specifies if we handle only single
        # exciton band (value 1) or also include two-exciton band (value 2)
        self.exciton_multiplicity = 2
        
        #############################################################
        #
        #    Relaxation theory
        #
        #############################################################
        
        #
        # Relaxation using Lindblad form
        #
        from quantarhei.qm import Operator
        
        o1 = Operator(dim=7, real=True)
        o1.data[1,2] = 1.0
        o1.data[2,3] = 1.0
        
        self.sys_operators = [o1]
        self.rates = (1.0/300,)
        self.relaxation_theory = "Lindblad_form"
        
        # Use it in site or excitonic basis
        self.use_sitebasis = True
        
        #
        # Redfield theory 
        #
        #self.relaxation_theory = "Standard_Redfield"
        #
        # Nothings else needs to be specified; it was defined on molecules
        #
        # Redfield is calculated strictly in excitonic basis
        # The  ``use_sitebasis`` attribute does not affect anything
        #
        
        
        #############################################################
        #
        #     Initial condition
        #
        #############################################################
        from quantarhei import ReducedDensityMatrix
        
        rho0 = ReducedDensityMatrix(dim=7)
        rho0.data[3,3] = 1.0
        
        self.rho0 = rho0

        #############################################################
        #
        #     Simulation tasks
        #
        #############################################################
        
        #task_1 = dict(task="density_matrix_dynamics", 
        #              object_file="rdm"+self._get_timestamp(filename=True)
        #              +".hdf5")

        task_1 = dict(task="density_matrix_dynamics") 
        
        self.tasks = [task_1]
# -*- coding: utf-8 -*-

from quantarhei import Molecule
from quantarhei import energy_units

en = [0.0, 12500]  # 12500 1/cm corresponds to an absorption
# at the wavelength of 800 nm (near infra red light)
with energy_units("1/cm"):
    m = Molecule("Molecule with units", en)

H = m.get_Hamiltonian()
print(H)

with energy_units("1/cm"):
    print(H)

with energy_units("eV"):
    print("Managed data: \n", H.data)
    print("\nRaw data:\n", H._data)
time = TimeAxis()

# time is not used here at all
LFa, ham = agg.get_RelaxationTensor(time, 
           relaxation_theory="electronic_Lindblad")
LFa.convert_2_tensor()

print(LFa.data[1,1,2,2])
print(LFa.data[1,2,1,2])


#
# VIBRONIC Aggregate of two molecules
#

m1v = Molecule([0.0, 1.0])
m2v = Molecule([0.0, 1.1])
m3v = Molecule([0.0, 1.2])

from quantarhei import Mode

mod1 = Mode(0.01)
mod2 = Mode(0.01)
mod3 = Mode(0.01)

Nvib = 2

m1v.add_Mode(mod1)
mod1.set_nmax(0, Nvib)
mod1.set_nmax(1, Nvib)
mod1.set_HR(1, 0.3)
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
Beispiel #32
0
def when_Molecule_is_created(self):
    with energy_units(world.units):
        world.m1 = Molecule("Mol1",[world.e0,world.e1]) 
# -*- coding: utf-8 -*-

from quantarhei import Molecule
from quantarhei import energy_units

en = [0.0, 12500]  # 12500 1/cm corresponds to an absorption
# at the wavelength of 800 nm (near infra red light)
with energy_units("1/cm"):
    m = Molecule(en, name="Molecule with units")

H = m.get_Hamiltonian()
print("\nInternal units:")
print("---------------")
print(H)

with energy_units("1/cm"):
    print("\nInverse centimeters:")
    print("--------------------")
    print(H)

with energy_units("eV"):
    print("\nElectronvolts:")
    print("--------------")
    print("\nManaged data: \n", H.data)
    print("\nRaw data:\n", H._data)
Beispiel #34
0
    def setup(self):
        """Simulation definition
        
        
        In this method we define the simulation. We have to define molecular
        system, type of system-bath interaction and the theory to handel it, 
        and the data to be calculated. Below, the definition sections are 
        described in detail together with the definition options and required
        Quantarhei imports.
        
        
        
        """
        ###############################################################
        #
        #     General section
        #
        ###############################################################
        from quantarhei import TimeAxis

        # time interval of propagation
        self.timeaxis = TimeAxis(0.0, 1000, 1.0)

        ###############################################################
        #
        #     Molecular system definition section
        #
        ###############################################################
        from quantarhei import Molecule
        from quantarhei import energy_units

        # define as many molecules as you want
        # use energy units of your choice
        with energy_units("1/cm"):
            m1 = Molecule([0.0, 12000.0])
            m2 = Molecule([0.0, 12200.0])
            m3 = Molecule([0.0, 12000.0])

        # optionally you can specify positions (default units are Angstroms)
        m1.position = [0.0, 0.0, 0.0]
        m2.position = [10.0, 0.0, 0.0]
        m3.position = [0.0, 10.0, 0.0]

        # transition dipole moments for selected transitions
        m1.set_dipole(0, 1, [12.0, 0.0, 0.0])
        m2.set_dipole(0, 1, [8.0, 8.0, 0.0])
        m3.set_dipole(0, 1, [0.0, 8.0, 8.0])

        # couplings between molecules
        #
        #self.coupling_matrix = [[0.0, 100.0],
        #                        [100.0, 0.0]]
        #self.energy_units = "1/cm"
        #
        # or
        #
        self.coupling_matrix = "by_dipole_dipole"
        #

        # setting molecules is compulsory
        self.molecules = [m1, m2, m3]

        ##############################################################
        #
        #    Type of excitonic problem section
        #
        ##############################################################

        # here we define what kind of problem we calculate
        self.exciton_type = "electronic"
        #self.exciton_type = "vibronic"

        # exciton multiplicity specifies if we handle only single
        # exciton band (value 1) or also include two-exciton band (value 2)
        self.exciton_multiplicity = 2

        #############################################################
        #
        #    Relaxation theory
        #
        #############################################################

        #
        # Relaxation using Lindblad form
        #
        from quantarhei.qm import Operator

        o1 = Operator(dim=7, real=True)
        o1.data[1, 2] = 1.0
        o1.data[2, 3] = 1.0

        self.sys_operators = [o1]
        self.rates = (1.0 / 300, )
        self.relaxation_theory = "Lindblad_form"

        # Use it in site or excitonic basis
        self.use_sitebasis = True

        #
        # Redfield theory
        #
        #self.relaxation_theory = "Standard_Redfield"
        #
        # Nothings else needs to be specified; it was defined on molecules
        #
        # Redfield is calculated strictly in excitonic basis
        # The  ``use_sitebasis`` attribute does not affect anything
        #

        #############################################################
        #
        #     Initial condition
        #
        #############################################################
        from quantarhei import ReducedDensityMatrix

        rho0 = ReducedDensityMatrix(dim=7)
        rho0.data[3, 3] = 1.0

        self.rho0 = rho0

        #############################################################
        #
        #     Simulation tasks
        #
        #############################################################

        #task_1 = dict(task="density_matrix_dynamics",
        #              object_file="rdm"+self._get_timestamp(filename=True)
        #              +".hdf5")

        task_1 = dict(task="density_matrix_dynamics")

        self.tasks = [task_1]
Beispiel #35
0
# Time axis for t1 and t3 times
Nr = 1000
ta = TimeAxis(0.0, Nr, 2.0)

###############################################################################
#
# Define problem
#
###############################################################################

#
# define molecules
#
with energy_units("1/cm"):
    mol1 = Molecule(elenergies=[0.0, 12300.0])
    mol2 = Molecule(elenergies=[0.0, 12000.0])
mol1.position = [0.0, 0.0, 0.0]
# dimer 1
mol2.position = [0.0, 6.0, 0.0]
## dimer 2
#mol2.position = [0.0, 0.0, 6.0]
mol1.set_dipole(0, 1, [4.0, 2.0, 0.0])
mol2.set_dipole(0, 1, [1.0, 2.0, 0.0])

#
# Setting up laboratory
#
lab = lab_settings(lab_settings.FOUR_WAVE_MIXING)
a_0 = numpy.array([1.0, 0.0, 0.0], dtype=numpy.float64)
lab.set_laser_polarizations(a_0, a_0, a_0, a_0)
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
    
    
Beispiel #37
0
# Time axis for t1 and t3 times
Nr = 1000
ta = TimeAxis(0.0, Nr, 2.0)

###############################################################################
#
# Define problem
#
###############################################################################

#
# define molecules
#
with energy_units("1/cm"):
    mol1 = Molecule(elenergies=[0.0, 12300.0])
    mol2 = Molecule(elenergies=[0.0, 12000.0])
mol1.position = [0.0, 0.0, 0.0]
# dimer 1
mol2.position = [0.0, 6.0, 0.0]
## dimer 2
#mol2.position = [0.0, 0.0, 6.0]
mol1.set_dipole(0,1,[4.0, 2.0, 0.0])
mol2.set_dipole(0,1,[1.0, 2.0, 0.0])

#
# Setting up laboratory
#
lab = lab_settings(lab_settings.FOUR_WAVE_MIXING)
a_0 = numpy.array([1.0, 0.0, 0.0], dtype=numpy.float64)
lab.set_laser_polarizations(a_0,a_0,a_0,a_0)
Beispiel #38
0
class TestMoleculeVibrations(unittest.TestCase):
    def setUp(self):

        en = [0.0, 1.0]
        self.m = Molecule(name="Molecule", elenergies=en)

        mod1 = Mode(frequency=0.1)
        self.m.add_Mode(mod1)
        mod1.set_nmax(0, 3)
        mod1.set_nmax(1, 3)

        en2 = [0.0, 0.1, 0.1]
        self.m2 = Molecule(name="AdMolecule", elenergies=en2)
        self.m2.set_adiabatic_coupling(1, 2, 0.02)
        mod2 = Mode(frequency=0.01)
        self.m2.add_Mode(mod2)
        mod2.set_nmax(0, 3)
        mod2.set_nmax(1, 3)
        mod2.set_nmax(2, 3)

    def test_molecule_with_vibrations_1(self):
        """Testing hamiltonian of a two-level molecule with one mode
        
        """

        H1 = self.m.get_Hamiltonian()
        H1expected = numpy.diag([0.0, 0.1, 0.2, 1.0, 1.1, 1.2])
        self.assertTrue(numpy.allclose(H1expected, H1.data))

        mod1 = self.m.get_Mode(0)
        mod1.set_nmax(1, 2)
        H2 = self.m.get_Hamiltonian()
        H2expected = numpy.diag([0.0, 0.1, 0.2, 1.0, 1.1])
        self.assertTrue(numpy.allclose(H2expected, H2.data))

    def test_thermal_density_matrix_0_temp(self):
        """Thermal density matrix: molecule with one mode, zero temperature
        
        """
        rho_eq = self.m.get_thermal_ReducedDensityMatrix()

        # Check if the matrix is diagonal
        dat = rho_eq.data.copy()
        for i in range(dat.shape[0]):
            dat[i, i] = 0.0
        zer = numpy.zeros(dat.shape, dtype=numpy.float)
        self.assertTrue(numpy.allclose(dat, zer))

        # Check if diagonal is a thermal population
        pop = numpy.zeros(dat.shape[0])
        # get temperature from the molecule
        T = self.m.get_temperature()
        self.assertEquals(T, 0.0)

        # get density matrix
        rho = self.m.get_thermal_ReducedDensityMatrix()
        rpop = rho.get_populations()

        if numpy.abs(T) < 1.0e-10:
            pop[0] = 1.0

        else:
            # thermal populations
            pass

        self.assertTrue(numpy.allclose(pop, rpop))

    def test_thermal_density_matrix_finite_temp(self):
        """Thermal density matrix: molecule with one mode, finite temperature
        
        """

        timeAxis = TimeAxis(0.0, 1000, 1.0)
        params = {
            "ftype": "OverdampedBrownian",
            "T": 300,
            "reorg": 30,
            "cortime": 100
        }
        cfcion = CorrelationFunction(timeAxis, params)
        self.m.set_egcf((0, 1), cfcion)

        rho_eq = self.m.get_thermal_ReducedDensityMatrix()

        # Check if the matrix is diagonal
        dat = rho_eq.data.copy()
        for i in range(dat.shape[0]):
            dat[i, i] = 0.0
        zer = numpy.zeros(dat.shape, dtype=numpy.float)
        self.assertTrue(numpy.allclose(dat, zer))

        # Check if diagonal is a thermal population
        pop = numpy.zeros(dat.shape[0])
        # get temperature from the molecule
        T = self.m.get_temperature()
        self.assertTrue(T == 300.0)

        # get density matrix
        rpop = rho_eq.get_populations()

        # get Hamiltonian
        H = self.m.get_Hamiltonian()

        if numpy.abs(T) < 1.0e-10:
            pop[0] = 1.0

        else:
            # thermal populations
            psum = 0.0
            for n in range(pop.shape[0]):
                pop[n] = numpy.exp(-H.data[n, n] / (kB_intK * T))
                psum += pop[n]
            pop *= 1.0 / psum

        self.assertTrue(numpy.allclose(pop, rpop))

    def test_thermal_density_matrix_finite_temp_nondiag(self):
        """Thermal density matrix: finite temperature, non-diagonal Hamiltonian
        
        """

        timeAxis = TimeAxis(0.0, 1000, 1.0)
        params = {
            "ftype": "OverdampedBrownian",
            "T": 300.0,
            "reorg": 30,
            "cortime": 100
        }
        cfcion = CorrelationFunction(timeAxis, params)
        self.m2.set_egcf((0, 1), cfcion)
        self.m2.set_egcf((0, 2), cfcion)

        rho_eq = self.m2.get_thermal_ReducedDensityMatrix()

        pop = numpy.zeros(rho_eq._data.shape[0])
        # get temperature from the molecule
        T = self.m2.get_temperature()
        self.assertTrue(numpy.abs(T - 300.0) < 1.0e-10)

        # get Hamiltonian
        H = self.m2.get_Hamiltonian()

        with eigenbasis_of(H):
            # get density matrix

            rpop = rho_eq.get_populations()

            if numpy.abs(T) < 1.0e-10:
                pop[0] = 1.0

            else:
                # thermal populations
                psum = 0.0
                for n in range(pop.shape[0]):
                    pop[n] = numpy.exp(-H.data[n, n] / (kB_intK * T))
                    psum += pop[n]
                pop *= 1.0 / psum

        self.assertTrue(numpy.allclose(pop, rpop))
_show_plots_ = False

"""
    Demo of the Lindblad form
    
    First we create a Lindblad form for a purely electronic system,
    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)
Beispiel #40
0
    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()
Beispiel #41
0
# -*- 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)
Beispiel #42
0
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]  
Beispiel #43
0
from quantarhei import energy_units

from quantarhei.utils import normalize2 
from quantarhei.core.units import cm2int, kB_intK

""" Create monomers """
# state energies
en1 = [0.0,12100] #*cm2int]
en2 = [0.0,12000] #*cm2int]

# transition dipole moment
""" d0 = [0.0,0.0,0.0] """
d1 = normalize2([0.0,1.0,0.0],1.0)

with energy_units("1/cm"):
    m1 = Molecule("M1",en1) #,[d0,d1])
    m1.set_dipole(0,1,d1)
    m2 = Molecule("M2",en1) #,[d0,d1])
    m2.set_dipole(0,1,d1)
    m3 = Molecule("M3",en2) #,[d0,d1])
    m3.set_dipole(0,1,d1)
    m4 = Molecule("M4",en1) #,[d0,d1])
    m4.set_dipole(0,1,d1)
    m5 = Molecule("M5",en1) #,[d0,d1])
    m5.set_dipole(0,1,d1)
    m6 = Molecule("M6",en1) #,[d0,d1])
    m6.set_dipole(0,1,d1)
    m7 = Molecule("M7",en1) #,[d0,d1])
    m7.set_dipole(0,1,d1)
    m8 = Molecule("M8",en1) #,[d0,d1])
    m8.set_dipole(0,1,d1)
Beispiel #44
0
# Time axis for t1 and t3 times
Nr = 100
ta = TimeAxis(0.0, Nr, 10.0)

###############################################################################
#
# Define problem
#
###############################################################################

#
# define molecules
#
with energy_units("1/cm"):
    mol1 = Molecule(elenergies=[0.0, 12000.0])
    mol2 = Molecule(elenergies=[0.0, 12200.0])
    mol3 = Molecule(elenergies=[0.0, 12400.0])
    mol4 = Molecule(elenergies=[0.0, 12500.0])
mol1.position = [0.0, 0.0, 0.0]
mol2.position = [0.0, 10.0, 0.0]
mol3.position = [10.0, 0.0, 0.0]
mol4.position = [0.0, 0.0, 10.0]
mol1.set_dipole(0, 1, [10.0, 0.0, 0.0])
mol2.set_dipole(0, 1, [-10.0, 0.0, 0.0])
mol3.set_dipole(0, 1, [0.0, 0.0, 10.0])
v1 = numpy.array([0.3, 0.3, 0.3])
v1 = 10.0 * v1 / numpy.sqrt(numpy.dot(v1, v1))
mol4.set_dipole(0, 1, v1)

molecules = [mol1, mol2, mol3, mol4]
Beispiel #45
0
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]    
Beispiel #46
0
class TestReducedDensityMatrix(unittest.TestCase):
    """Tests for the Manager class
    
    
    """
    
    def setUp(self):
        self.en = [0.0, 1.0, 2.0]
        self.m = Molecule(name="Molecule",elenergies=self.en)
        self.m.set_dipole(0,1,[1.0,0.0,0.0])
        self.m.set_dipole(0,2,[0.5,0.0,0.0])
    
        self.rho_eq = self.m.get_thermal_ReducedDensityMatrix()
    
    def test_excitation_by_delta(self):
        """Testing reduced density matrix excitation by delta-pulse
        
        
        """

        
        
        rho_exp = numpy.zeros((3,3),dtype=numpy.float)
        rho_exp[0,0] = 1.0
        
        self.assertTrue(numpy.allclose(self.rho_eq._data,rho_exp))
        
        dd = self.m.get_TransitionDipoleMoment()
        epol = [1.0, 0.0, 0.0]        
        
        rho_ex = self.rho_eq.excite_delta(dmoment=dd,epolarization=epol)
            
        rho_exp = numpy.array([[ 0.00+0.j,  0.00+0.j,  0.00+0.j],
                               [ 0.00+0.j,  1.00+0.j,  0.50+0.j],
                               [ 0.00+0.j,  0.50+0.j,  0.25+0.j]])
                               
        self.assertTrue(numpy.allclose(rho_exp,rho_ex._data))
        
        
        
        rho_ex2 = self.rho_eq.excite_delta(dmoment=dd,
                                      epolarization=[1.0/numpy.sqrt(2.0),
                                                     1.0/numpy.sqrt(2.0),0.0])
                                                     
        rho_exp2 = numpy.array([[ 0.000+0.j,  0.000+0.j,  0.000+0.j],
                                [ 0.000+0.j,  0.500+0.j,  0.250+0.j],
                                [ 0.000+0.j,  0.250+0.j,  0.125+0.j]])
                                
        self.assertTrue(numpy.allclose(rho_ex2._data,rho_exp2))
        
        
    def test_conversion_2_populations(self):
        """Testing conversion of reduced density matrix to population vector
        
        
        """
        
        rdm = ReducedDensityMatrix(data=[[0.5, 0.0, 0.1],
                                         [0.0, 0.3, 0.0],
                                         [0.1, 0.0, 0.2]])
                                         
        pop = rdm.get_populations()
        
        self.assertTrue(numpy.allclose(pop,[0.5,0.3,0.2]))
        
        
    def test_saveable(self):
        """Testing reduced density matrix as Saveable
        
        
        """
        
        rdm = ReducedDensityMatrix(data=[[0.5, 0.0, 0.1],
                                         [0.0, 0.3, 0.0],
                                         [0.1, 0.0, 0.2]])
                         
        #import h5py
              
        #with h5py.File("test_file_operators",driver="core", 
        #                   backing_store=False) as fid:
        import tempfile
        with tempfile.TemporaryFile() as fid:
            
            rdm.save(fid) #, test=True)
            fid.seek(0)
            
            rdm2 = ReducedDensityMatrix()
            
            rdm2 = rdm2.load(fid) #, test=True)
        
        self.assertTrue(numpy.allclose(rdm2.data,rdm.data))
                                    
Beispiel #47
0
 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()
Beispiel #48
0
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
# -*- coding: utf-8 -*-


from quantarhei import Molecule
from quantarhei import energy_units

en = [0.0, 12500] # 12500 1/cm corresponds to an absorption
                  # at the wavelength of 800 nm (near infra red light)
with energy_units("1/cm"):
    m = Molecule(en, name="Molecule with units")


H = m.get_Hamiltonian()
print("\nInternal units:")
print("---------------")
print(H)

with energy_units("1/cm"):
    print("\nInverse centimeters:")
    print("--------------------")
    print(H)

with energy_units("eV"):
    print("\nElectronvolts:")
    print("--------------")
    print("\nManaged data: \n", H.data)
    print("\nRaw data:\n",H._data)    
Beispiel #50
0
    def setUp(self,verbose=False):
        
        circdichs = CircDichSpectrumBase()
        with energy_units("1/cm"):
            f = FrequencyAxis(10000.0,2000, 1.0)
            a = self._spectral_shape(f, [1.0, 11000.0, 100.0])
            circdichs.axis = f
            circdichs.data = a
        self.circdichs = circdichs
        self.axis = circdichs.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()
            
            circdich_calc = CircDichSpectrumCalculator(time, system=agg)
            circdich_calc.bootstrap(rwa=12000)
            
        circdich1 = circdich_calc.calculate()
        
        self.circdich1 = circdich1
Beispiel #51
0
# -*- 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)
Beispiel #52
0
*
***********************************************************
""")

from quantarhei import Manager
#
# 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)
Beispiel #53
0
class TestMoleculeVibrations(unittest.TestCase):
    
    def setUp(self):
        
        en = [0.0, 1.0]
        self.m = Molecule(name="Molecule",elenergies=en)

        mod1 = Mode(frequency=0.1)
        self.m.add_Mode(mod1)
        mod1.set_nmax(0,3)
        mod1.set_nmax(1,3)
    
        en2 = [0.0,0.1,0.1]
        self.m2 = Molecule(name="AdMolecule",elenergies=en2)    
        self.m2.set_adiabatic_coupling(1,2,0.02)
        mod2 = Mode(frequency=0.01)
        self.m2.add_Mode(mod2)
        mod2.set_nmax(0,3)
        mod2.set_nmax(1,3)
        mod2.set_nmax(2,3)
        

    def test_molecule_with_vibrations_1(self):
        """Testing hamiltonian of a two-level molecule with one mode
        
        """
        
        H1 = self.m.get_Hamiltonian()
        H1expected = numpy.diag([0.0, 0.1, 0.2, 1.0, 1.1, 1.2])        
        self.assertTrue(numpy.allclose(H1expected,H1.data))
        
        mod1 = self.m.get_Mode(0)
        mod1.set_nmax(1,2)
        H2 = self.m.get_Hamiltonian()
        H2expected = numpy.diag([0.0, 0.1, 0.2, 1.0, 1.1])        
        self.assertTrue(numpy.allclose(H2expected,H2.data))    
        
        
    def test_thermal_density_matrix_0_temp(self):
        """Thermal density matrix: molecule with one mode, zero temperature
        
        """
        rho_eq = self.m.get_thermal_ReducedDensityMatrix()

        # Check if the matrix is diagonal        
        dat = rho_eq.data.copy()
        for i in range(dat.shape[0]):
            dat[i,i] = 0.0
        zer = numpy.zeros(dat.shape,dtype=numpy.float)
        self.assertTrue(numpy.allclose(dat,zer))
        
        # Check if diagonal is a thermal population
        pop = numpy.zeros(dat.shape[0])
        # get temperature from the molecule
        T = self.m.get_temperature()
        self.assertEquals(T,0.0)        
        
        # get density matrix
        rho = self.m.get_thermal_ReducedDensityMatrix()
        rpop = rho.get_populations()
        
        if numpy.abs(T) < 1.0e-10:
            pop[0] = 1.0
            
        else:
            # thermal populations
            pass

        self.assertTrue(numpy.allclose(pop,rpop))
        
        
    def test_thermal_density_matrix_finite_temp(self):
        """Thermal density matrix: molecule with one mode, finite temperature
        
        """
        
        timeAxis = TimeAxis(0.0,1000,1.0)
        params = {"ftype":"OverdampedBrownian",
                  "T":300,
                  "reorg":30,
                  "cortime":100}
        with energy_units("1/cm"):
            cfcion = CorrelationFunction(timeAxis,params)
            self.m.set_egcf((0,1),cfcion)
        
            rho_eq = self.m.get_thermal_ReducedDensityMatrix()

        # Check if the matrix is diagonal        
        dat = rho_eq.data.copy()
        for i in range(dat.shape[0]):
            dat[i,i] = 0.0
        zer = numpy.zeros(dat.shape,dtype=numpy.float)
        self.assertTrue(numpy.allclose(dat,zer))
        
        # Check if diagonal is a thermal population
        pop = numpy.zeros(dat.shape[0])
        # get temperature from the molecule
        T = self.m.get_temperature()
        self.assertTrue(T==300.0)

        
        # get density matrix
        rpop = rho_eq.get_populations()
        
        # get Hamiltonian
        H = self.m.get_Hamiltonian()       

        if numpy.abs(T) < 1.0e-10:
            pop[0] = 1.0
            
        else:
            # thermal populations
            psum = 0.0
            for n in range(pop.shape[0]):
                pop[n] = numpy.exp(-H.data[n,n]/(kB_intK*T))
                psum += pop[n]
            pop *= 1.0/psum
            
        self.assertTrue(numpy.allclose(pop,rpop))
        
        
    def test_thermal_density_matrix_finite_temp_nondiag(self):
        """Thermal density matrix: finite temperature, non-diagonal Hamiltonian
        
        """
        
        timeAxis = TimeAxis(0.0,1000,1.0)
        params = {"ftype":"OverdampedBrownian",
                  "T":300.0,
                  "reorg":30,
                  "cortime":100}
        cfcion = CorrelationFunction(timeAxis,params)
        self.m2.set_egcf((0,1),cfcion)
        self.m2.set_egcf((0,2),cfcion)
        
        rho_eq = self.m2.get_thermal_ReducedDensityMatrix()

        pop = numpy.zeros(rho_eq._data.shape[0])
        # get temperature from the molecule
        T = self.m2.get_temperature()
        self.assertTrue(numpy.abs(T-300.0)<1.0e-10)
 
        # get Hamiltonian
        H = self.m2.get_Hamiltonian() 
        
        with eigenbasis_of(H):
            # get density matrix

            rpop = rho_eq.get_populations()


            if numpy.abs(T) < 1.0e-10:
                pop[0] = 1.0
            
            else:
                # thermal populations
                psum = 0.0
                for n in range(pop.shape[0]):
                    pop[n] = numpy.exp(-H.data[n,n]/(kB_intK*T))
                    psum += pop[n]
                pop *= 1.0/psum

        
        self.assertTrue(numpy.allclose(pop,rpop))