Exemple #1
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')
Exemple #2
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
Exemple #3
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')
Exemple #4
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
    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)       
Exemple #6
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)
Exemple #7
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()

    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]
Exemple #8
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]  
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
Exemple #10
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]    
Exemple #11
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
Exemple #12
0
    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 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 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 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
#
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
Exemple #17
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)
    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
Exemple #19
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")
print(H.data.shape)
with energy_units("1/cm"):
    print(H)
    
D = ag.get_TransitionDipoleMoment()

Exemple #20
0
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

t2s = TimeAxis(0.0, 5, 20.0)

#
# Set up calculator
# -*- 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)
Exemple #22
0
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

t2s = TimeAxis(0.0, 5, 20.0)

#
# Set up calculator
Exemple #23
0
#
# 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)
psi_t = dimer_propagator.propagate(psi)
psi_t.plot(ptype="square", show=False)

#dat = [[0.0, 0.0, 0.0], [0.0, 1.0, 0.01], [0.0, 0.01, 1.1]]
H._data[2,2] = 1.2 #dat
Exemple #24
0
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)
Exemple #25
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")
print(H.data.shape)
with energy_units("1/cm"):
    print(H)

D = ag.get_TransitionDipoleMoment()

with eigenbasis_of(H):
    with energy_units("1/cm"):
        print(H)
Exemple #26
0
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 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
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)
        
        
        
        
Exemple #29
0
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
Exemple #30
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)
Exemple #31
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
Exemple #32
0
AG.add_Molecule(m12)


print(AG._has_egcf_matrix)
print(AG._has_system_bath_interaction)


# setting coupling by dipole-dipole formula
AG.set_coupling_by_dipole_dipole(prefac=0.0147520827152)

print (AG.resonance_coupling[1,2]/cm2int)

# building aggregate
print("Building aggregate... ")
start = tm.time()
AG.build()
print("...done in ",tm.time()-start)

with energy_units("1/cm"):
    anth = Molecule("Anth",[0.0,11380]) #*cm2int],[d0,d1])
anth.set_dipole(0,1,d1)
anth.set_egcf((0,1),cfce1)

# FIXME: use with construct
aAnth = AbsSpect(time,anth)
aAnth.calculate(12000*cm2int)
aAnth.normalize2()

a1 = AbsSpect(time,AG)
a1.calculate(12000*cm2int)
a1.normalize2()
Exemple #33
0
#
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