def CreateWavefunction(config): """ Creates a Wavefunction from a config file. Use this function if you only need a wavefunction and not a complete proapagator. The wavefunction will have one data buffer allocated, and the content is unspecified. ex: conf = pyprop.Load("config.ini") psi = CreateWavefunction(config) x = psi.GetData().GetRepresentation().GetLocalGrid(0) psi.GetData()[:] = x * exp(- x**2) """ logger = GetFunctionLogger() logger.debug("Creating DistributionModel...") distribution = CreateDistribution(config) logger.debug("Creating Representation...") representation = CreateRepresentation(config, distribution) logger.debug("Creating Wavefunction...") psi = CreateWavefunctionInstance(representation) return psi
def CreateSubRepresentations(combinedRepr, config): logger = GetFunctionLogger() rank = config.Representation.rank for i in range(rank): sectionName = config.Representation.Get("representation" + str(i)) logger.debug("ConfigSection for rank %i is %s" % (i, sectionName)) section = config.GetSection(sectionName) #create instance repr = section.type() repr.SetBaseRank(i) logger.debug("Representation for rank %i is %s" % (i, repr)) #set distributed model fullDistrib = combinedRepr.GetDistributedModel() distrib = fullDistrib.CreateSubDistributedModel() repr.SetDistributedModel(distrib) #apply configuration section.Apply(repr) #Attach this repr to the main representation combinedRepr.SetRepresentation(i, repr)
def CreateRepresentation(config, distribution): logger = GetFunctionLogger() #Create instance representation = config.Representation.type() #Set distribution model logger.debug("Setting distributed model") representation.SetDistributedModel(distribution) #Apply configuration section config.Representation.Apply(representation) #If the representation is a base class of CombinedRepresentation, #we must set up the 1d sub-representations. combinedRepr = None try: combinedRepr = eval("core.CombinedRepresentation_" + str(config.Representation.rank)) except: pass if combinedRepr != None and combinedRepr in config.Representation.type.__mro__: CreateSubRepresentations(representation, config) return representation
def CreateWavefunctionInstance(representation, allocateData=True): logger = GetFunctionLogger() #Create instance logger.debug(" Creating instance") rank = len(representation.GetFullShape()) psi = CreateInstanceRank("core.Wavefunction", rank) #Set reresentation logger.debug(" Setting representation") psi.SetRepresentation(representation) #Allocate data if allocateData: logger.debug(" Allocating data") psi.AllocateData() return psi