Exemplo n.º 1
0
def TestBanded():
    conf = pyprop.Load("config.ini")
    conf.KineticEnergy0.geometry0 = "Dense"
    conf.KineticEnergy0.geometry1 = "Dense"
    conf.KineticEnergy1.geometry0 = "Dense"
    conf.KineticEnergy1.geometry1 = "Dense"
    conf.TestPotential.geometry0 = "Dense"
    conf.TestPotential.geometry1 = "Dense"
    propDense = pyprop.Problem(conf)
    propDense.SetupStep()
    tempDense = propDense.GetTempPsi()
    tempDense.GetData()[:] = 0
    propDense.MultiplyHamiltonian(tempDense)

    conf = pyprop.Load("config.ini")
    conf.KineticEnergy0.geometry0 = "Banded"
    conf.KineticEnergy0.geometry1 = "Banded"
    conf.KineticEnergy1.geometry0 = "Banded"
    conf.KineticEnergy1.geometry1 = "Banded"
    conf.TestPotential.geometry0 = "Banded"
    conf.TestPotential.geometry1 = "Banded"
    propBanded = pyprop.Problem(conf)
    propBanded.SetupStep()
    tempBanded = propBanded.GetTempPsi()
    tempBanded.GetData()[:] = 0
    propBanded.MultiplyHamiltonian(tempBanded)

    figure()
    pcolormesh(tempDense.GetData().real.copy())
    figure()
    pcolormesh(tempBanded.GetData().real.copy())
Exemplo n.º 2
0
def test(**args):
    conf = pyprop.Load("config.ini")
    SetupConfig(conf, **args)

    prop = pyprop.Problem(conf)
    prop.SetupStep()
    return prop
Exemplo n.º 3
0
def SetupInitialState(**args):

    if 'stateIndex' in args:
        stateIndex = args['stateIndex']
    else:
        stateIndex = 0
        args['stateIndex'] = stateIndex

    #Set up problem
    conf = SetupConfig(**args)

    prop = pyprop.Problem(conf)
    prop.SetupStep()

    #Find eigenstates of desired l-subspace
    M = GetHamiltonMatrix(prop)
    E, V = eig(M)
    I = argsort(E)
    print "Initial state energy = ", E[I[stateIndex]].real

    #Assign initial state
    prop.psi.GetData()[:] = 0
    prop.psi.GetData()[:] = V[:, I[stateIndex]]
    prop.psi.Normalize()

    return prop
Exemplo n.º 4
0
def test(gridType=RadialGridType.CARTESIAN):
    conf = pyprop.Load("kulander.ini")
    SetRadialGridType(conf, gridType)

    prop = pyprop.Problem(conf)
    prop.SetupStep()
    return prop
Exemplo n.º 5
0
def Test():
    conf = pyprop.Load("find_groundstate.ini")
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    print prop.GetEnergyExpectationValue()
    print prop.GetEnergyExpectationValue()
Exemplo n.º 6
0
def CalculateDensityOfStates(configFile):

    #Set up config
    conf = pyprop.Load(configFile)

    #Set up pyprop problem
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    #Calculate eigenvalues
    E, V = SetupEigenstates(prop)

    #Calculate DOS
    dos = 1.0 / diff(E)

    #Calculate exact dos
    xmax = conf.RadialRepresentation.xmax
    dos_exact = xmax / (pi * sqrt(2 * E[1:]))

    #Estimate highest reliable energy, about 2/3*E_max for B-splines
    maxIdx = int(2 * len(E) / 3.0)
    maxReliableEnergy = E[maxIdx]
    print "Estimated highest reliable energy = %1.1e" % maxReliableEnergy

    return E[1:], dos_exact, dos
Exemplo n.º 7
0
def SetupProblem(**args):
    """
	Load configuration and set up problem
	"""
    conf = SetupConfig(**args)
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    return prop
Exemplo n.º 8
0
def TestStability():
    conf = pyprop.Load("config.ini")
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    for t in prop.Advance(50):
        print "t = %.4f, E(t) = %.6f" % (t, prop.GetEnergyExpectationValue())

    initPsi = prop.psi

    conf = pyprop.Load("config_radial.ini")
    conf.Propagation.timestep = abs(conf.Propagation.timestep)
    conf.Propagation.renormalization = False
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    prop.psi.GetData()[:] = initPsi.GetData()
    for t in prop.Advance(50):
        print "t = %.4f, N(t) = %.6f, P(t) = %.6f" % (
            t, prop.psi.GetNorm(), abs(prop.psi.InnerProduct(initPsi))**2)
Exemplo n.º 9
0
def MakeOddEvenMovie(**args):
    args['config'] = "config.ini"
    args['imtime'] = False
    inputfile = GetInputFile(**args)

    conf = SetupConfig(**args)
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    LoadInitialState(prop, **args)
    initPsi = prop.psi.Copy()

    E, V = LoadDifferenceBasis(**args)

    r = prop.psi.GetRepresentation().GetLocalGrid(0)
    dr = diff(r)[0]

    outputCount = 500
    if "outputCount" in args:
        outputCount = args["outputCount"]

    curIndex = 0

    interactive = rcParams["interactive"]
    rcParams["interactive"] = False

    figure(figsize=(8, 8))

    def output():
        corr = abs(dot(V, prop.psi.GetData()[:, 0]))**2
        curtime = t / femtosec_to_au

        progressStr = "%#3i%s Complete" % (curIndex * 100 / float(outputCount),
                                           "%")
        sys.stdout.write(progressStr)
        sys.stdout.flush()
        sys.stdout.write("\b" * len(progressStr))

        clf()
        CorrelationBarPlot(abs(corr)**2)
        axis([-1, 20, 0, 0.35])
        title("t = %3.3f" % curtime)
        savefig("movie/frame%05i.png" % curIndex)

    #output initial state
    for t in prop.Advance(outputCount):
        output()
        curIndex += 1

    output()

    mymovie = myplot.MakeMovie()
    conf.Movie.Apply(mymovie)
    mymovie.CreateMovie()

    rcParams["interactive"] = interactive
Exemplo n.º 10
0
def FindEigenvalues():
    conf = pyprop.Load("find_groundstate.ini")
    conf.Propagation.silent = pyprop.ProcId != 0
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    solver = pyprop.PiramSolver(prop)
    solver.Solve()

    print "Eigenvalues = ", solver.Solver.GetEigenvalues().real
    return solver
Exemplo n.º 11
0
def SetupProblem(**args):
    """
	Sets up a problem corresponding to the 
	arguments given in **args
	"""
    conf = SetupConfig(**args)
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    return prop
Exemplo n.º 12
0
    def SetupProblem(geometry0, geometry1):
        conf = pyprop.Load("config_radial.ini")
        conf.Propagation.silent = True
        conf.Propagation.grid_potential_list = ["LaserPotential"]
        conf.LaserPotential.geometry0 = geometry0
        conf.LaserPotential.geometry1 = geometry1
        prop = pyprop.Problem(conf)
        prop.SetupStep()

        return prop
Exemplo n.º 13
0
def FindGroundstate(**args):
    conf = pyprop.Load("groundstate.ini")
    SetupConfig(conf, **args)

    prop = pyprop.Problem(conf)
    prop.SetupStep()

    for t in prop.Advance(5):
        print "t = ", t, " E = ", prop.GetEnergyImTime()

    return prop
Exemplo n.º 14
0
def FindGroundstateEnergy(transformType, N, dt):
    conf = pyprop.Load("config.ini")
    conf.Representation.n = N
    conf.Representation.transform_type = transformType
    conf.Propagation.timestep = abs(dt) * -1.0j

    prop = pyprop.Problem(conf)
    prop.SetupStep()

    for t in prop.Advance(1):
        pass
    return prop.GetEnergy()
Exemplo n.º 15
0
def FindIonizationProbability(datafile,
                              boundstateFiles,
                              ionizationThreshhold=-2.0):
    """
	Find total single and double ionization of Helium by projecting on states with 
	energy < 2.0 a.u.
	"""

    conf = pyprop.Config(pyprop.serialization.GetConfigFromHDF5(datafile))
    lmax = conf.AngularRepresentation.index_iterator.lmax
    Lmax = conf.AngularRepresentation.index_iterator.L[-1]

    conf.Propagation.grid_potential_list = []
    conf.Propagation.preconditioner = None

    #h5file = tables.openFile(datafile)
    #try:
    #	ionizationProbability = h5file.root.Norm[0]
    #finally:
    #	h5file.close()
    ionizationProbability = 1.0

    #Set up problem
    #conf.AngularRepresentation.index_iterator = pyprop.DefaultCoupledIndexIterator(lmax=lmax, L=L)
    prop = pyprop.Problem(conf)
    tmpPsi = prop.psi.Copy()
    totalIdxIterator = pyprop.DefaultCoupledIndexIterator(lmax=lmax,
                                                          L=range(Lmax))

    #Load wavefunction
    h5file = tables.openFile(datafile, "r")
    try:
        prop.psi.GetData()[:] = h5file.root.wavefunction[:]
    finally:
        h5file.close()
    for L in range(Lmax + 1):
        #Project on all bound states for current L
        print "    L = %i" % L
        h5file = tables.openFile(boundstateFiles.pop(0), "r")
        numEigs = size(h5file.root.Eig.Eigenvalues)
        for i in range(numEigs):
            tmpPsi.Clear()
            for j, cur in enumerate(totalIdxIterator):
                if cur.L == L and h5file.root.Eig.Eigenvalues[
                        i] < ionizationThreshhold:
                    datasetPath = GetEigenvectorDatasetPath(i)
                    tmpPsi.GetData()[j, :, :] += array(
                        h5file.getNode(datasetPath))[cur.l1, :, :]
            ionizationProbability -= abs(prop.psi.InnerProduct(tmpPsi))**2

        h5file.close()

    return ionizationProbability
Exemplo n.º 16
0
def Setup(**args):
    """
	Setup Krotov problem
	"""
    conf = pyprop.Load('config.ini')

    if "timestep" in args:
        config.Propagation.timestep = args["timestep"]

    prob = pyprop.Problem(conf)
    prob.SetupStep()
    krotov = pyprop.Krotov(prob)
    return krotov
Exemplo n.º 17
0
    def SetupProblem(geometry0, geometry1):
        conf = pyprop.Load("config.ini")
        conf.Propagation.silent = True
        conf.KineticEnergy0.geometry0 = geometry0
        conf.KineticEnergy0.geometry1 = geometry1
        conf.KineticEnergy1.geometry0 = geometry0
        conf.KineticEnergy1.geometry1 = geometry1
        conf.TestPotential.geometry0 = geometry0
        conf.TestPotential.geometry1 = geometry1
        prop = pyprop.Problem(conf)
        prop.SetupStep()

        return prop
Exemplo n.º 18
0
def SetupProblem(**args):
    #load config file. hydrogen.ini uses ../sphericalbase.ini as a base
    #configuration file, so be sure to check out that one as well.
    conf = SetupConfig(**args)

    #Uses the same Problem class, only changes the propagator specified in the
    #config file
    prop = pyprop.Problem(conf)

    #Set up all transformations and potentials.
    prop.SetupStep()

    return prop
Exemplo n.º 19
0
def SetupProblemFromFile(file, nodeName=None):
    """
	Set up problem object and load wavefunction from file.
	"""
    prop = None
    cfgObj = pyprop.serialization.GetConfigFromHDF5(file)
    cfgObj.set("InitialCondition", "type", "None")
    conf = pyprop.Config(cfgObj)
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    GetWavefunctionFromFile(file, prop.psi, nodeName=nodeName)

    return prop
Exemplo n.º 20
0
def SetupDegani(config, **args):
    """
	Setup Degani problem
	"""

    conf = pyprop.Load(config)

    prop = pyprop.Problem(conf)
    prop.SetupStep()
    degani = pyprop.Degani(prop)
    degani.ApplyConfigSection(conf.Degani)
    degani.Setup()

    return degani
Exemplo n.º 21
0
def SetupKrotov(config, **args):
    """
	Setup Krotov problem
	"""

    conf = pyprop.Load(config)

    if "timestep" in args:
        config.Propagation.timestep = args["timestep"]

    prop = pyprop.Problem(conf)
    prop.SetupStep()
    krotov = pyprop.Krotov(prop)
    krotov.ApplyConfigSection(conf.Krotov)
    krotov.Setup()

    return krotov
Exemplo n.º 22
0
def SetupZhuRabitz(config, **args):
    """
	Setup ZhuRabitz problem
	"""

    conf = pyprop.Load(config)

    if "timestep" in args:
        config.Propagation.timestep = args["timestep"]

    prop = pyprop.Problem(conf)
    prop.SetupStep()
    zhurabitz = pyprop.ZhuRabitz(prop)
    zhurabitz.ApplyConfigSection(conf.ZhuRabitz)
    zhurabitz.Setup()

    return zhurabitz
Exemplo n.º 23
0
def TestSoftParameter():

    conf = SetupConfig()

    E = []
    softParams = [0.005, 0.01, 0.02, 0.04, 0.06]

    for s in softParams:
        conf.TwoElectronCorrelation.soft_param = s
        prop = pyprop.Problem(conf)
        prop.SetupStep()

        for t in prop.Advance(True):
            pass

        E.append(prop.GetEnergyExpectationValue())

    return E
Exemplo n.º 24
0
def TestStability(**args):
    args["imtime"] = True
    args["omega_left"] = 1
    initProp = FindGroundstate(**args)

    args["imtime"] = False
    #args["omega_left"] = 1.5
    conf = SetupConfig(**args)
    #conf.Propagation.potential_evaluation = ["StarkPotential"]
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    prop.psi.GetData()[:] = initProp.psi.GetData()
    initPsi = prop.psi.Copy()

    for t in prop.Advance(10):
        print "t = %.2f, N(t) = %.8f, P(t) = %.8f" % (
            t, prop.psi.GetNorm(), abs(prop.psi.InnerProduct(initPsi)**2))
    return prop
Exemplo n.º 25
0
def FindGroundstate():
    #load config
    conf = pyprop.Load("find_groundstate.ini")
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    #propagate to find ground state
    for t in prop.Advance(10):
        print "t = ", t, ", E =", prop.GetEnergy()

    #save groundstate to disk
    prop.SaveWavefunctionHDF("groundstate.h5", "/wavefunction")

    #Find energy
    E1 = prop.GetEnergyImTime()
    E2 = prop.GetEnergyExpectationValue()
    print "Groundstate energy:\n\t %s a.u.\n\t %s" % (E1, E2)
    pyprop.Plot1D(prop)

    return prop
Exemplo n.º 26
0
def CompareFortran(**args):
    conf = pyprop.Load("config_compare_fortran.ini")
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    init = prop.psi.Copy()

    for t in prop.Advance(5):
        corr = abs(prop.psi.InnerProduct(init))**2
        print "Time = %f, initial state correlation = %f" % (t, corr)

    corr = abs(prop.psi.InnerProduct(init))**2
    t = prop.PropagatedTime
    print "Time = %f, initial state correlation = %f" % (t, corr)

    #Load fortran data and compare
    fdata = pylab.load("fortran_propagation.dat")
    print "Max difference pyprop/fortran: %e" % nmax(
        abs(prop.psi.GetData())**2 - fdata[1:])

    return prop
Exemplo n.º 27
0
def Propagate():
    conf = pyprop.Load("propagation.ini")
    prop = pyprop.Problem(conf)
    prop.SetupStep()
    prop.psi.Normalize()

    #Create a copy of the wavefunction so that we can calculate
    #the autocorrelation function during propagation
    initPsi = prop.psi.Copy()

    #Propagate the system to the time specified in propagation.ini,
    #printing the autocorrelation function, and plotting the wavefunction
    #10 evenly spaced times during the propagation
    for t in prop.Advance(10):
        corr = abs(prop.psi.InnerProduct(initPsi))**2
        norm = prop.psi.GetNorm()
        if pyprop.ProcId == 0:
            print "t = ", t, ", P(t) = ", corr, ", N(t) = ", norm
        #pyprop.Plot2DFull(prop)

    return prop
Exemplo n.º 28
0
def FindGroundstate(**args):
    """
	Loads the configuration file "find_groundstate.ini", which contains information
	on how to find the ground state of 2d hydrogen, by imaginary time propagation.

	When the problem is fully advanced, the wavefunction is saved to the file 
	"groundstate.dat", and the ground state energy is written to screen

	finally it returns the Problem object prop back to the caller for further processing
	"""

    #load config
    conf = pyprop.Load("find_groundstate.ini")
    silent = False
    if 'silent' in args:
        silent = args['silent']
        conf.Propagation.silent = silent
    prop = pyprop.Problem(conf)
    prop.SetupStep()

    #propagate to find ground state
    for t in prop.Advance(10):
        E = prop.GetEnergy()
        if not silent:
            print "t =", t, "E =", E

    #save groundstate to disk
    if pyprop.ProcId == 0:
        if os.path.exists("groundstate.h5"):
            os.unlink("groundstate.h5")
    prop.SaveWavefunctionHDF("groundstate.h5", "wavefunction")

    #Find energy
    energy = prop.GetEnergy()
    if not silent:
        print "Groundstate energy:", energy, "a.u."

    return prop, energy
Exemplo n.º 29
0
def RunKulanderExperiment(gridType=RadialGridType.CARTESIAN):
    #load config file. hydrogen.ini uses ../sphericalbase.ini as a base
    #configuration file, so be sure to check out that one as well.
    conf = pyprop.Load("kulander.ini")
    SetRadialGridType(conf, gridType)

    #Uses the same Problem class, only changes the propagator specified in the
    #config file
    prop = pyprop.Problem(conf)

    #Set up all transformations and potentials.
    prop.SetupStep()

    #Make sure the wavefunction is normalized
    prop.psi.Normalize()

    #save the initial wavefunction
    initPsi = prop.psi.Copy()

    lcount = len(CalculateAngularMomentumDistribution(prop))
    ldist = zeros((500, lcount), dtype=double)
    save("output/ldist", ldist)

    #propagate through the problem, and do something
    #every timestep
    index = 0
    for t in prop.Advance(500):
        #pyprop.Plot2DRank(prop, 0)
        norm = prop.psi.GetNorm()
        corr = abs(prop.psi.InnerProduct(initPsi))**2
        print "t = ", t, "; Norm = ", norm, "; Corr = ", corr

        ldist[index, :] = CalculateAngularMomentumDistribution(prop)
        save("output/ldist", ldist)

        index += 1

    return prop
Exemplo n.º 30
0
def SetupInitialState(**args):
    stateIndex = args["stateIndex"]

    #Set up problem
    conf = SetupConfig(**args)

    prop = pyprop.Problem(conf)
    prop.SetupStep()

    #Find eigenstates of desired l-subspace
    M = GetHamiltonMatrix(prop)
    print "Finding eigenvectors and eigenvalues..."
    sys.stdout.flush()
    E, V = eig(M)
    I = argsort(E)
    print "Initial state energy = ", E[I[stateIndex]].real
    sys.stdout.flush()

    #Assign initial state
    prop.psi.GetData()[:] = V[:, I[stateIndex]]
    prop.psi.Normalize()

    return prop