def fourdThing(fn): ''' we try myavi ''' a = qp.retrieve_hdf5_data(fn, 'WF')[:, :, :, 0] time = qp.retrieve_hdf5_data(fn, 'Time')[0] fig = figure(size=(600, 600), fgcolor=(0, 0, 0), bgcolor=(1, 1, 1)) contour3d(qp.abs2(a), contours=10, transparent=True, opacity=0.8) #title('Time - {:5.2f}'.format(time)) xlabel('phi') ylabel('gam') zlabel('the') #view(132.05741302902214, 62.73780301264113, 187.6797494627067, np.array([ 15.00000048, 11., 1087643])) view(47.01, 79.90, 105.94, np.array([15.00, 11.00, 15.00])) savefig(fn + '.a.png') view(0.0, 90.0, 87.034, np.array([15., 11., 15.])) savefig(fn + '.b.png') view(90.0, 90.0, 87.034, np.array([15., 11., 15.])) savefig(fn + '.c.png') view(0.0, 0.0, 87.034, np.array([15., 11., 15.])) savefig(fn + '.d.png') close()
def difference_this(file_zero_abs, wave, output_file_name): ''' given the three paths, this will create the difference in wavepacket ''' zero = readWholeH5toDict(file_zero_abs) other = readWholeH5toDict(wave) zero_wf = zero['WF'] other_wf = other['WF'] zero_time = zero['Time'] other_time = other['Time'] zero_pop = qp.abs2(zero_wf) other_pop = qp.abs2(other_wf) difference = zero_pop - other_pop outputDict = {'WF': difference, 'Time0': zero_time, 'Time1': other_time} print('{} cube is done: {} {}'.format(os.path.basename(wave), np.amax(difference), np.amin(difference))) qp.writeH5fileDict(output_file_name, outputDict)
def calculate_dipole_slow(wf, all_h5_dict): ''' This function will calculate the dipole in x,y,z components given a wavepacket and an allH5 file fn :: FilePath <- the path of the wavefunction all_h5_dict :: Dictionary <- the dictionary created by the simulation. ''' pL, gL, tL, nstates = wf.shape dipoles = all_h5_dict['dipCube'] xd = yd = zd = 0.0 for p in range(15, pL - 15): for g in range(15, gL - 15): for t in range(30, tL - 30): for i in range(nstates): for j in range(i + 1): if j != i: # out of diagonal xd += 2 * np.real( np.conj(wf[p, g, t, i]) * wf[p, g, t, j] * dipoles[p, g, t, 0, i, j]) yd += 2 * np.real( np.conj(wf[p, g, t, i]) * wf[p, g, t, j] * dipoles[p, g, t, 1, i, j]) zd += 2 * np.real( np.conj(wf[p, g, t, i]) * wf[p, g, t, j] * dipoles[p, g, t, 2, i, j]) else: # diagonal xd += qp.abs2(wf[p, g, t, i]) * dipoles[p, g, t, 0, i, i] yd += qp.abs2(wf[p, g, t, i]) * dipoles[p, g, t, 1, i, i] zd += qp.abs2(wf[p, g, t, i]) * dipoles[p, g, t, 2, i, i] return (xd, yd, zd)
def test_abs2(): ''' Test for the function abs2 ''' assert abs2(3.2+9.3j) == 96.73000000000002
def propagate3D(dataDict, inputDict): ''' Two dictionaries, one from data file and one from input file it starts and run the 3d propagation of the wavefunction... ''' printDict(inputDict) printDictKeys(dataDict) printDictKeys(inputDict) #startState = inputDict['states'] _, _, _, nstates = dataDict['potCube'].shape phiL, gamL, theL, natoms, _ = dataDict['geoCUBE'].shape # INITIAL WF default values if 'factor' in inputDict: factor = inputDict['factor'] warning('WF widened using factor: {}'.format(factor)) else: factor = 1 if 'displ' in inputDict: displ = inputDict['displ'] else: displ = (0, 0, 0) if 'init_mom' in inputDict: init_mom = inputDict['init_mom'] else: init_mom = (0, 0, 0) if 'initial_state' in inputDict: initial_state = inputDict['initial_state'] warning( 'Initial gaussian wavepacket in state {}'.format(initial_state)) else: initial_state = 0 wf = np.zeros((phiL, gamL, theL, nstates), dtype=complex) print(initial_state) wf[:, :, :, initial_state] = initialCondition3d(wf[:, :, :, initial_state], dataDict, factor, displ, init_mom) # Take values array from labels (radians already) phis, gams, thes = fromLabelsToFloats(dataDict) # take step dphi = phis[0] - phis[1] dgam = gams[0] - gams[1] dthe = thes[0] - thes[1] inp = { 'dt': inputDict['dt'], 'fullTime': inputDict['fullTime'], 'phiL': phiL, 'gamL': gamL, 'theL': theL, 'natoms': natoms, 'phis': phis, 'gams': gams, 'thes': thes, 'dphi': dphi, 'dgam': dgam, 'dthe': dthe, 'potCube': dataDict['potCube'], 'kinCube': dataDict['kinCube'], 'dipCube': dataDict['dipCUBE'], 'nacCube': dataDict['smoCube'], 'pulseX': inputDict['pulseX'], 'pulseY': inputDict['pulseY'], 'pulseZ': inputDict['pulseZ'], 'nstates': nstates, 'kind': inputDict['kind'], } ######################################### # Here the cube expansion/interpolation # ######################################### inp = expandcube(inp) ######################################## # Potentials to Zero and normalization # ######################################## inp['potCube'] = dataDict['potCube'] - np.amin(dataDict['potCube']) norm_wf = np.linalg.norm(wf) good('starting NORM deviation : {}'.format(1 - norm_wf)) # magnify the potcube if 'enePot' in inputDict: enePot = inputDict['enePot'] inp['potCube'] = inp['potCube'] * enePot if enePot == 0: warning('This simulation is done with zero Potential energy') elif enePot == 1: good('Simulation done with original Potential energy') else: warning('The potential energy has been magnified {} times'.format( enePot)) # constant the kinCube kinK = False if kinK: kokoko = 1000 inp['kinCube'] = inp['kinCube'] * kokoko warning('kincube divided by {}'.format(kokoko)) if 'multiply_nac' in inputDict: # this keyword can be used to multiply NACs. It works with a float or a list of triplet # multiply_nac : 10 -> will multiply all by 10 # multiply_nac : [[1,2,10.0],[3,4,5.0]] -> will multiply 1,2 by 10 and 3,4 by 5 nac_multiplier = inputDict['multiply_nac'] if type(nac_multiplier) == int or type(nac_multiplier) == float: warning('all Nacs are multiplied by {}'.format(nac_multiplier)) inp['nacCube'] = inp['nacCube'] * nac_multiplier if type(nac_multiplier) == list: warning('There is a list of nac multiplications, check input') for state_one, state_two, multiply_factor in nac_multiplier: inp['nacCube'][:, :, :, state_one, state_two, :] = inp[ 'nacCube'][:, :, :, state_one, state_two, :] * multiply_factor inp['nacCube'][:, :, :, state_two, state_one, :] = inp[ 'nacCube'][:, :, :, state_two, state_one, :] * multiply_factor warning( 'NACS corresponding of state {} and state {} are multiplied by {}' .format(state_one, state_two, multiply_factor)) inp['Nac_multiplier'] = nac_multiplier nameRoot = create_enumerated_folder(inputDict['outFol']) inputDict['outFol'] = nameRoot inp['outFol'] = nameRoot numStates = inputDict['states'] ################### # Absorbing Thing # ################### if 'absorb' in inputDict: good('ABSORBING POTENTIAL is taken from file') file_absorb = inputDict['absorb'] print('{}'.format(file_absorb)) inp['absorb'] = retrieve_hdf5_data(file_absorb, 'absorb') else: good('NO ABSORBING POTENTIAL') inp['absorb'] = np.zeros_like(inp['potCube']) ################ # slice states # ################ kind = inp['kind'] # Take equilibrium points from directionFile # warning('This is a bad equilibriumfinder') # gsm_phi_ind, gsm_gam_ind, gsm_the_ind = equilibriumIndex(inputDict['directions1'],dataDict) gsm_phi_ind, gsm_gam_ind, gsm_the_ind = (29, 28, 55) warning('You inserted equilibrium points by hand: {} {} {}'.format( gsm_phi_ind, gsm_gam_ind, gsm_the_ind)) inp['nstates'] = numStates if kind == '3d': inp['potCube'] = inp['potCube'][:, :, :, :numStates] inp['kinCube'] = inp['kinCube'][:, :, :] inp['dipCube'] = inp['dipCube'][:, :, :, :, :numStates, :numStates] wf = wf[:, :, :, :numStates] good('Propagation in 3D.') print( '\nDimensions:\nPhi: {}\nGam: {}\nThet: {}\nNstates: {}\nNatoms: {}\n' .format(phiL, gamL, theL, numStates, natoms)) elif kind == 'GamThe': inp['potCube'] = inp['potCube'][gsm_phi_ind, :, :, :numStates] inp['kinCube'] = inp['kinCube'][gsm_phi_ind, :, :] inp['dipCube'] = inp['dipCube'][ gsm_phi_ind, :, :, :, :numStates, :numStates] wf = wf[gsm_phi_ind, :, :, :numStates] good('Propagation in GAM-THE with Phi {}'.format(gsm_phi_ind)) print('Shapes: P:{} K:{} W:{} D:{}'.format(inp['potCube'].shape, inp['kinCube'].shape, wf.shape, inp['dipCube'].shape)) print('\nDimensions:\nGam: {}\nThe: {}\nNstates: {}\nNatoms: {}\n'. format(gamL, theL, numStates, natoms)) norm_wf = np.linalg.norm(wf) wf = wf / norm_wf elif kind == 'Phi': inp['potCube'] = inp['potCube'][:, gsm_gam_ind, gsm_the_ind, :numStates] inp['kinCube'] = inp['kinCube'][:, gsm_gam_ind, gsm_the_ind] inp['dipCube'] = inp['dipCube'][:, gsm_gam_ind, gsm_the_ind, :, :numStates, :numStates] wf = wf[:, gsm_gam_ind, gsm_the_ind, :numStates] good('Propagation in PHI with Gam {} and The {}'.format( gsm_gam_ind, gsm_the_ind)) print('Shapes: P:{} K:{} W:{} D:{}'.format(inp['potCube'].shape, inp['kinCube'].shape, wf.shape, inp['dipCube'].shape)) print('\nDimensions:\nPhi: {}\nNstates: {}\nNatoms: {}\n'.format( phiL, numStates, natoms)) norm_wf = np.linalg.norm(wf) wf = wf / norm_wf elif kind == 'Gam': inp['potCube'] = inp['potCube'][gsm_phi_ind, :, gsm_the_ind, :numStates] inp['kinCube'] = inp['kinCube'][gsm_phi_ind, :, gsm_the_ind] inp['dipCube'] = inp['dipCube'][gsm_phi_ind, :, gsm_the_ind, :, :numStates, :numStates] wf = wf[gsm_phi_ind, :, gsm_the_ind, :numStates] good('Propagation in GAM with Phi {} and The {}'.format( gsm_phi_ind, gsm_the_ind)) print('Shapes: P:{} K:{} W:{} D:{}'.format(inp['potCube'].shape, inp['kinCube'].shape, wf.shape, inp['dipCube'].shape)) print('\nDimensions:\nGam: {}\nNstates: {}\nNatoms: {}\n'.format( gamL, numStates, natoms)) norm_wf = np.linalg.norm(wf) wf = wf / norm_wf elif kind == 'The': sposta = False if sposta: gsm_phi_ind = 20 gsm_gam_ind = 20 warning('Phi is {}, NOT EQUILIBRIUM'.format(gsm_phi_ind)) warning('Gam is {}, NOT EQUILIBRIUM'.format(gsm_gam_ind)) inp['potCube'] = inp['potCube'][gsm_phi_ind, gsm_gam_ind, :, :numStates] inp['absorb'] = inp['absorb'][gsm_phi_ind, gsm_gam_ind, :, :numStates] inp['kinCube'] = inp['kinCube'][gsm_phi_ind, gsm_gam_ind, :] inp['dipCube'] = inp['dipCube'][ gsm_phi_ind, gsm_gam_ind, :, :, :numStates, :numStates] inp['nacCube'] = inp['nacCube'][ gsm_phi_ind, gsm_gam_ind, :, :numStates, :numStates, :] wf = wf[gsm_phi_ind, gsm_gam_ind, :, :numStates] # doubleGridPoints doubleThis = False if doubleThis: warning('POINTS DOUBLED ALONG THETA') inp['thes'] = doubleAxespoins(inp['thes']) inp['theL'] = inp['thes'].size inp['dthe'] = inp['thes'][0] - inp['thes'][1] inp['potCube'] = np.array( [doubleAxespoins(x) for x in inp['potCube'].T]).T newWf = np.empty((inp['theL'], numStates), dtype=complex) for ssssss in range(numStates): newWf[:, ssssss] = doubleAxespoins(wf[:, ssssss]) wf = newWf newNac = np.empty((inp['theL'], numStates, numStates, 3)) for nnn in range(2): for mmm in range(2): for aaa in range(3): newNac[:, nnn, mmm, aaa] = doubleAxespoins(inp['nacCube'][:, nnn, mmm, aaa]) inp['nacCube'] = newNac newKin = np.empty((inp['theL'], 9, 3)) for nnn in range(9): for mmm in range(3): newKin[:, nnn, mmm] = doubleAxespoins(inp['kinCube'][:, nnn, mmm]) inp['kinCube'] = newKin good('Propagation in THE with Phi {} and Gam {}'.format( gsm_phi_ind, gsm_gam_ind)) print('Shapes: P:{} K:{} W:{} D:{}'.format(inp['potCube'].shape, inp['kinCube'].shape, wf.shape, inp['dipCube'].shape)) print('\nDimensions:\nThe: {}\nNstates: {}\nNatoms: {}\n'.format( theL, numStates, natoms)) norm_wf = np.linalg.norm(wf) wf = wf / norm_wf else: err('I do not recognize the kind') initial_time_simulation = 0.0 # take a wf from file (and not from initial condition) if 'initialFile' in inputDict: warning('we are taking initial wf from file') wffn = inputDict['initialFile'] print('File -> {}'.format(wffn)) wf_not_norm = retrieve_hdf5_data(wffn, 'WF') initial_time_simulation = retrieve_hdf5_data(wffn, 'Time')[1] # in hartree #wf = wf_not_norm/np.linalg.norm(wf_not_norm) wf = wf_not_norm ############################# # PROPAGATOR SELECTION HERE # ############################# CEnergy, Cpropagator = select_propagator(kind) good('Cpropagator version: {}'.format(version_Cpropagator())) # INITIAL DYNAMICS VALUES dt = inp['dt'] if 'reverse_time' in inputDict: warning('Time is reversed !!') dt = -dt Cpropagator = Cderivative3dMu_reverse_time t = initial_time_simulation counter = 0 fulltime = inp['fullTime'] fulltimeSteps = int(fulltime / abs(dt)) deltasGraph = inputDict['deltasGraph'] print('I will do {} steps.\n'.format(fulltimeSteps)) outputFile = os.path.join(nameRoot, 'output') outputFileP = os.path.join(nameRoot, 'outputPopul') outputFileA = os.path.join(nameRoot, 'Output_Abs') print('\ntail -f {}\n'.format(outputFileP)) if inputDict['readme']: outputFilereadme = os.path.join(nameRoot, 'README') with open(outputFilereadme, "w") as oofRR: oofRR.write(inputDict['readme']) print('file readme written') # calculating initial total/potential/kinetic kin, pot, pul, absS = CEnergy(t, wf, inp) kinetic = np.vdot(wf, kin) potential = np.vdot(wf, pot) pulse_interaction = np.vdot(wf, pul) initialTotal = kinetic + potential + pulse_interaction inp['initialTotal'] = initialTotal.real # to give the graph a nice range inp['vmax_value'] = abs2(wf).max() # graph the pulse graphic_Pulse(inp) # saving input data in h5 file dataH5filename = os.path.join(nameRoot, 'allInput.h5') writeH5fileDict(dataH5filename, inp) # print top of table header = ' Coun | step N | fs | NORM devia. | Kin. Energy | Pot. Energy | Total Energy | Tot devia. | Pulse_Inter. | Pulse X | Pulse Y | Pulse Z | Norm Loss |' bar = ('-' * (len(header))) print('Energies in ElectronVolt \n{}\n{}\n{}'.format(bar, header, bar)) for ii in range(fulltimeSteps): if (ii % deltasGraph) == 0 or ii == fulltimeSteps - 1: # async is awesome. But it is not needed in 1d and maybe in 2d. if kind == '3D': asyncFun(doAsyncStuffs, wf, t, ii, inp, inputDict, counter, outputFile, outputFileP, outputFileA, CEnergy) else: doAsyncStuffs(wf, t, ii, inp, inputDict, counter, outputFile, outputFileP, outputFileA, CEnergy) counter += 1 wf = Crk4Ene3d(Cpropagator, t, wf, inp) t = t + dt
G_Exp = fn + '/Gaussian*.h5' allH5 = sorted(glob.glob(G_Exp)) from quantumpropagator import abs2 for i, fn in enumerate(allH5[:]): for state in range(8): nameMaterial = "Material.{:03d}".format(state + 1) mat = bpy.data.materials.get(nameMaterial) print('doing {}'.format(fn)) wf = openh5(fn, 'WF') ground2 = abs2(wf[:, :, :, state]) ground = np.swapaxes(ground2, 0, 2) #for iso in [0.000001, 0.00001, 0.0001]: for iso in [0.0001]: generateIso(ground, iso, mat, i, state) bpy.context.scene.frame_set(1) def doThis(strei): for obj in bpy.data.objects: obj.select = False for obj in bpy.data.objects: object_name = obj.name