def manipulate_cos_phi(self): if self.last_ts > 0: return None for e in self.events_cos_phi: interval, interval_i, ts_list, bus_id, bus_tag, load_mapping, load_ids, cos_phi = self._get_cos_phi_vars( e) print('+++' * 10) string = 'From {} (idx: {}) change cos phi from load {} at bus {} with cos_phi of {} ' \ 'until {} (idx: {})'.format(interval[0], interval_i[0], load_ids, bus_id, cos_phi, interval[1], interval_i[1]) print(string) print('Use load mapping: {}'.format(load_mapping)) tmp_data = self.unscaled_data.loc[interval[0]:interval[1]] print('Manipulate {} samples!'.format(len(tmp_data))) list_q = [] list_p = [] for i, val in enumerate(load_mapping): prod_p = np.dot( val, self.unscaled_data[self.unscaled_data.columns[i]]. loc[interval[0]:interval[1]].T) list_p.append(prod_p) if i in load_ids: reactive_power = gu.compute_q(prod_p, cos_phi=cos_phi) else: reactive_power = gu.compute_q(prod_p) list_q.append(reactive_power) assert len(list_p) == len(list_q) summed_p = np.zeros(len(list_p[0])) summed_q = np.zeros(len(list_q[0])) for val_p, val_q in zip(list_p, list_q): summed_p += val_p summed_q += val_q assert len(summed_p) == len(summed_q) == len(tmp_data) ### replace old data by drifted data with q vals with new cos phi for t_step, q_val, p_val in zip(ts_list, summed_q, summed_p): self.data.loc[(t_step, bus_id - 1)] = [bus_tag, p_val, q_val] print('+++' * 10) return self.data
def prepareForceFields( store = True, storeXsf = False, autogeom = False, FFparams=None ): newEl = False newLJ = False head = None # --- try to load FFel or compute it from LOCPOT.xsf if ( os.path.isfile('FFel_x.xsf') ): print " FFel_x.xsf found " FFel, lvecEl, nDim, head = GU.loadVecField('FFel', FFel) lvec2params( lvecEl ) else: print "FFel_x.xsf not found " if ( xsfLJ and os.path.isfile('LOCPOT.xsf') ): print " LOCPOT.xsf found " V, lvecEl, nDim, head = GU.loadXSF('LOCPOT.xsf') lvec2params( lvecEl ) FFel_x,FFel_y,FFel_z = libFFTfin.potential2forces( V, lvecEl, nDim, sigma = 1.0 ) FFel = GU.packVecGrid( FFel_x,FFel_y,FFel_z ) del FFel_x,FFel_y,FFel_z GU.saveVecFieldXsf( 'FFel', FF, lvecEl, head = head ) else: print " LOCPOT.xsf not found " newEl = True # --- try to load FFLJ if ( os.path.isfile('FFLJ_x.xsf') ): print " FFLJ_x.xsf found " FFLJ, lvecLJ, nDim, head = GU.loadVecFieldXsf( 'FFLJ' ) lvec2params( lvecLJ ) else: newLJ = True # --- compute Forcefield by atom-wise interactions if ( newEl or newEl ): atoms = basUtils.loadAtoms('geom.bas', elements.ELEMENT_DICT ) iZs,Rs,Qs = parseAtoms( atoms, autogeom = autogeom, PBC = params['PBC'] ) lvec = params2lvec( ) if head is None: head = GU.XSF_HEAD_DEFAULT if newLJ: FFLJ = computeLJ ( Rs, iZs, FFparams=FFparams ) GU.saveVecFieldXsf( 'FFLJ', FF, lvecEl, head = head ) if newEl: FFel = computeCoulomb( Rs, Qs, FFel ) GU.saveVecFieldXsf( 'FFel', FF, lvecEl, head = head ) return FFLJ, FFel
def manipulate_load_mapping(self): """ Manipulates the load mapping. Loops over all given load mapping events and manipulates the data by multiplying new load mapping times unscaled data and finally replaces the old data by new manipulated data. :return: the manipulated data with new load mapping as pandas DataFrame """ if self.last_ts > 0: return None for event in self.events_load_mapping: start_ts = self.timestamp_list[event['at_time_idx']] end_ts = self.timestamp_list[event['until_time_idx']] start_ts_i = event['at_time_idx'] end_ts_i = event['until_time_idx'] if end_ts_i == -1: ts_list = self.timestamp_list[start_ts_i:] else: end_ts_i += 1 ts_list = self.timestamp_list[start_ts_i:end_ts_i] bus_id = event['bus_id'] bus_tag = 'AGG_BUS_{}'.format(bus_id) new_load_mapping = event['load_mapping'] old_load_mapping = self.initial_load_mapping[bus_id] print('+++' * 10) print('On {} change load mapping at bus: {} until {}'.format( start_ts, bus_id, end_ts)) print('Old load mapping was: {}'.format(old_load_mapping)) print('New load mapping is: {}'.format(new_load_mapping)) assert len(new_load_mapping) == len(old_load_mapping) tmp_data = self.unscaled_data.loc[start_ts:end_ts] agg_data_p = np.dot(new_load_mapping, tmp_data.T) print('Manipulate {} samples!'.format(len(agg_data_p))) print('+++' * 10) q_list = [] for val in agg_data_p: q = gu.compute_q(val) q_list.append(q) assert len(ts_list) == len(q_list) == len(agg_data_p) for t_step, q_val, p_val in zip(ts_list, q_list, agg_data_p): self.data.loc[(t_step, bus_id - 1)] = [bus_tag, p_val, q_val] return self.data
(options, args) = parser.parse_args() Ks = [ 0.3 ] Qs = [ 0.0] Amps = [ 1.0 ] print " ============= RUN " print " >> WARNING!!! OVEWRITING SETTINGS by params.ini " PP.loadParams( 'params.ini' ) PPPlot.params = PP.params print " load Electrostatic Force-field " FFel, lvec, nDim, head = GU.loadVecFieldXsf( "FFel" ) print " load Lenard-Jones Force-field " FFLJ, lvec, nDim, head = GU.loadVecFieldXsf( "FFLJ" ) PP.lvec2params( lvec ) PP.setFF( FFel ) xTips,yTips,zTips,lvecScan = PP.prepareScanGrids( ) #Ks = [ 0.25, 0.5, 1.0 ] #Qs = [ -0.2, 0.0, +0.2 ] #Amps = [ 2.0 ] for iq,Q in enumerate( Qs ): FF = FFLJ + FFel * Q
makeclean() import GridUtils as GU import Multipoles as MP import ProbeParticle as PP # ============== Setup WORK_DIR = '/home/prokop/Desktop/Probe_Particle_Simulations/Multipoles/COCu4/' # NOTE: Data for COCu4 tip example are on tarkil /auto/praha1/prokop/STHM/vasp/COCu4 # ============== load reference grid V, lvec, nDim, head = GU.loadXSF(WORK_DIR + 'LOCPOT.xsf') cell = np.array([lvec[1], lvec[2], lvec[3]]) MP.setGrid(V, cell) # ============== prepare atoms atom_types, atom_pos = GU.getFromHead_PRIMCOORD( head) # load atoms from header of xsf file # set sample region around atom atom_Rmin, atom_Rmax spacies = PP.loadSpecies('./defaults/atomtypes.ini') R_type = spacies[:, 0] atom_Rmin, atom_Rmax = MP.make_Ratoms(atom_types, R_type)
if query_yes_no( "I have found files containing electrostatic forcefield. Should I use them (yes) or do you want me to recompute them from scratch (n) ?" ): todoEL = 'read' else: todoEL = 'compute' else: print "I haven't found files containing electrostatic forcefields. Therefore I will recompute them from scratch" todoEL = 'compute' #print iZs if todoLJ == 'compute': FFLJ = PP.computeLJ(Rs, iZs, FFLJ=None, FFparams=None) GU.saveVecFieldXsf(ProjName + "_LJ_F", FFLJ, lvec=[[0.0, 0.0, 0.0], PP.params['gridA'], PP.params['gridB'], PP.params['gridC']]) elif todoLJ == 'read': FFLJ, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_LJ_F") PP.lvec2params(lvec) xTips, yTips, zTips, lvecScan = PP.prepareScanGrids() print xTips, yTips, zTips if todoEL == 'read': FFEL, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_EL_F") Q = PP.params['charge'] K = 0.3 PP.setTip(kSpring=np.array((K, K, 0.0)) / -PP.eVA_Nm)
sys.path = [ LWD ] print " sys.path = ", sys.path import basUtils import elements import GridUtils as GU import ProbeParticle as PP print " ============= RUN " print " >> WARNING!!! OVEWRITING SETTINGS by params.ini " #PP.loadParams( 'params_carbox.ini' ) print " load Electrostatic Force-field " FFel_x,lvec,nDim,head=GU.loadXSF('FFel_x.xsf') PP.params['gridA'] = lvec[ 1,: ].copy() PP.params['gridB'] = lvec[ 2,: ].copy() PP.params['gridC'] = lvec[ 3,: ].copy() PP.params['gridN'] = nDim.copy() print " compute Lennard-Jones Force-filed " atoms = basUtils.loadAtoms('geom.bas') if os.path.isfile( 'atomtypes.ini' ): print ">> LOADING LOCAL atomtypes.ini" FFparams=PPU.loadSpecies( 'atomtypes.ini' ) else: FFparams = PPU.loadSpecies( cpp_utils.PACKAGE_PATH+'/defaults/atomtypes.ini' ) iZs,Rs,Qs = parseAtoms( atoms, autogeom = False, PBC = True, FFparams=FFparams ) FFLJ = PP.computeLJ( iZs, Rs, FFLJ=None, cell=None, autogeom = False, PBC = True, FFparams=FFparams)
LWD = '/home/prokop/git/ProbeParticleModel/code' def makeclean(): import os [os.remove(f) for f in os.listdir(".") if f.endswith(".so")] [os.remove(f) for f in os.listdir(".") if f.endswith(".o")] [os.remove(f) for f in os.listdir(".") if f.endswith(".pyc")] CWD = os.getcwd() os.chdir(LWD) print " >> WORKDIR: ", os.getcwd() makeclean() sys.path.insert(0, ".") import GridUtils as gu os.chdir(CWD) print " >> WORKDIR: ", os.getcwd() print " ============= RUN " Fz, lvec, nDim, head = gu.loadXSF('Fz.xsf') nslice = min(len(Fz), 10) for i in range(nslice): plt.figure() plt.imshow(Fz[i, :, :], origin='image', interpolation='nearest') plt.show()
print " # ========== make & load ProbeParticle C++ library " def makeclean( ): import os [ os.remove(f) for f in os.listdir(".") if f.endswith(".so") ] [ os.remove(f) for f in os.listdir(".") if f.endswith(".o") ] [ os.remove(f) for f in os.listdir(".") if f.endswith(".pyc") ] CWD = os.getcwd() os.chdir(LWD); print " >> WORKDIR: ", os.getcwd() makeclean( ) sys.path.insert(0, "./") import GridUtils as GU import ProbeParticle as PP os.chdir(CWD); print " >> WORKDIR: ", os.getcwd() print " ============= RUN " F,lvec,nDim,head=GU.loadXSF('LOCPOT.xsf') F4 = 0.25*( F + F[:,:,::-1] + F[:,::-1,:] + F[:,::-1,::-1] ) #GU.saveXSF('LOCPOT_4sym.xsf', GU.XSF_HEAD_DEFAULT, lvec, F4 ) GU.saveXSF('LOCPOT_4sym.xsf', head, lvec, F4 ) plt.show()
(options, args) = parser.parse_args() num = len(sys.argv) if (num < 2): sys.exit("Number of arguments = "+str(num-1)+". This script should have at least one argument. I am terminating...") finput = sys.argv[num-1] # --- initialization --- sigma = 1.0 # [ Angstroem ] print('--- Data Loading ---') # TODO with time implement reading a hartree potential generated by different software if(options.input == 'vasp.locpot.xsf'): V, lvec, nDim, head = GU.loadXSF(finput) elif(options.input == 'aims.cube'): V, lvec, nDim, head = GU.loadCUBE(finput) print('--- Preprocessing ---') sampleSize = getSampleDimensions(lvec) dims = (nDim[2], nDim[1], nDim[0]) xsize, dx = getSize('x', dims, sampleSize) ysize, dy = getSize('y', dims, sampleSize) zsize, dz = getSize('z', dims, sampleSize) dd = (dx, dy, dz)
exit(1) parser = OptionParser() parser.add_option( "--dfrange", action="store", type="float", help="Range of plotted frequency shift (df)", nargs=2) parser.add_option( "--df", action="store_true", help="Write AFM frequency shift in df.xsf file", default=False) (options, args) = parser.parse_args() print "Reading coordinates from the file {}".format(sys.argv[1]) print " >> WARNING!!! OVERWRITING SETTINGS by params.ini " PP.loadParams( 'params.ini' ) Fx,lvec,nDim,head=GU.loadXSF('FFel_x.xsf') Fy,lvec,nDim,head=GU.loadXSF('FFel_y.xsf') Fz,lvec,nDim,head=GU.loadXSF('FFel_z.xsf') PP.params['gridA'] = lvec[ 1,: ].copy() PP.params['gridB'] = lvec[ 2,: ].copy() PP.params['gridC'] = lvec[ 3,: ].copy() PP.params['gridN'] = nDim.copy() FF = np.zeros( (nDim[0],nDim[1],nDim[2],3) ) FFLJ = np.zeros( np.shape( FF ) ) FFel = np.zeros( np.shape( FF ) ) FFel[:,:,:,0]=Fx FFel[:,:,:,1]=Fy FFel[:,:,:,2]=Fz
# --- initialization --- sigma = 1.0 # [ Angstroem ] print " >> OVEWRITING SETTINGS by params.ini " PPU.loadParams( 'params.ini' ) print " ========= get electrostatic forcefiled from hartree " # TODO with time implement reading a hartree potential generated by different software print " loading Hartree potential from disk " if(options.input == 'vasp.locpot.xsf'): V, lvec, nDim, head = GU.loadXSF(finput) elif(options.input == 'aims.cube'): V, lvec, nDim, head = GU.loadCUBE(finput) print " computing convolution with tip by FFT " Fel_x,Fel_y,Fel_z = LFF. potential2forces( V, lvec, nDim, sigma = 1.0 ) print " saving electrostatic forcefiled " GU.saveXSF('FFel_x.xsf', Fel_x, lvec, head) GU.saveXSF('FFel_y.xsf', Fel_y, lvec, head) GU.saveXSF('FFel_z.xsf', Fel_z, lvec, head) del Fel_x,Fel_y,Fel_z,V
type="float", help="Range of plotted frequency shift (df)", nargs=2) parser.add_option("--df", action="store_true", help="Write AFM frequency shift in df.xsf file", default=False) (options, args) = parser.parse_args() print "Reading coordinates from the file {}".format(sys.argv[1]) print " >> WARNING!!! OVERWRITING SETTINGS by params.ini " PP.loadParams('params.ini') Fx, lvec, nDim, head = GU.loadXSF('FFel_x.xsf') Fy, lvec, nDim, head = GU.loadXSF('FFel_y.xsf') Fz, lvec, nDim, head = GU.loadXSF('FFel_z.xsf') PP.params['gridA'] = lvec[1, :].copy() PP.params['gridB'] = lvec[2, :].copy() PP.params['gridC'] = lvec[3, :].copy() PP.params['gridN'] = nDim.copy() FF = np.zeros((nDim[0], nDim[1], nDim[2], 3)) FFLJ = np.zeros(np.shape(FF)) FFel = np.zeros(np.shape(FF)) FFel[:, :, :, 0] = Fx FFel[:, :, :, 1] = Fy FFel[:, :, :, 2] = Fz
): todoEL = "read" else: todoEL = "compute" else: print "I haven't found files containing electrostatic forcefields. Therefore I will recompute them from scratch" todoEL = "compute" # print iZs if todoLJ == "compute": FFLJ = PP.computeLJ(Rs, iZs, FFLJ=None, FFparams=None) GU.saveVecFieldXsf( ProjName + "_LJ_F", FFLJ, lvec=[[0.0, 0.0, 0.0], PP.params["gridA"], PP.params["gridB"], PP.params["gridC"]] ) elif todoLJ == "read": FFLJ, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_LJ_F") PP.lvec2params(lvec) xTips, yTips, zTips, lvecScan = PP.prepareScanGrids() print xTips, yTips, zTips if todoEL == "read": FFEL, lvec, nDim, head = GU.loadVecFieldXsf(ProjName + "_EL_F") Q = PP.params["charge"]
# This is a sead of simple plotting script which should get AFM frequency delta 'df.xsf' and generate 2D plots for different 'z' import os import sys import numpy as np import matplotlib.pyplot as plt import GridUtils as GU from optparse import OptionParser parser = OptionParser() parser.add_option( "--dfrange", action="store", type="float", help="Range of plotted frequency shift (df)", nargs=2) (options, args) = parser.parse_args() dfs,lvec,nDim,head=GU.loadXSF('df.xsf') #print lvec #print nDim print " # ============ Plot Relaxed Scan 3D " slices = range( 0, len(dfs) ) #print slices extent=( 0.0, lvec[1][0], 0.0, lvec[2][1]) for ii,i in enumerate(slices): print " plotting ", i plt.figure( figsize=( 10,10 ) ) if(options.dfrange != None): fmin = options.dfrange[0] fmax = options.dfrange[1] plt.imshow( dfs[i], origin='image', interpolation='bicubic', vmin=fmin, vmax=fmax, cmap='gray', extent=extent)
parser = OptionParser() parser.add_option( "-i", "--input", action="store", type="string", help="format of input file", default='vasp.locpot.xsf') (options, args) = parser.parse_args() num = len(sys.argv) finput = sys.argv[num-1] # --- initialization --- sigma = 1.0 # [ Angstroem ] print '--- Data Loading ---' # TODO with time implement reading a hartree potential generated by different software if(options.input == 'vasp.locpot.xsf'): V, lvec, nDim, head = GU.loadXSF(finput) elif(options.input == 'aims.cube'): V, lvec, nDim, head = GU.loadCUBE(finput) print '--- Preprocessing ---' sampleSize = getSampleDimensions(lvec) dims = (nDim[2], nDim[1], nDim[0]) xsize, dx = getSize('x', dims, sampleSize) ysize, dy = getSize('y', dims, sampleSize) zsize, dz = getSize('z', dims, sampleSize) dd = (dx, dy, dz)
LWD = '/home/prokop/git/ProbeParticleModel/code' def makeclean( ): import os [ os.remove(f) for f in os.listdir(".") if f.endswith(".so") ] [ os.remove(f) for f in os.listdir(".") if f.endswith(".o") ] [ os.remove(f) for f in os.listdir(".") if f.endswith(".pyc") ] CWD = os.getcwd() os.chdir(LWD); print " >> WORKDIR: ", os.getcwd() makeclean( ) sys.path.insert(0, ".") import GridUtils as gu os.chdir(CWD); print " >> WORKDIR: ", os.getcwd() print " ============= RUN " Fz,lvec,nDim,head=gu.loadXSF('Fz.xsf') nslice = min( len( Fz ), 10 ) for i in range(nslice): plt.figure() plt.imshow( Fz[i,:,:], origin='image', interpolation='nearest' ) plt.show()
nargs=3) (options, args) = parser.parse_args() Ks = [0.3, 0.5, 0.7] Qs = [-0.2, -0.1, 0.0, 0.1, 0.2] Amps = [1.0] print(" ============= RUN ") print(" >> WARNING!!! OVEWRITING SETTINGS by params.ini ") PP.loadParams('params.ini') PPPlot.params = PP.params print(" load Electrostatic Force-field ") FFel, lvec, nDim, head = GU.loadVecFieldXsf("FFel") print(" load Lenard-Jones Force-field ") FFLJ, lvec, nDim, head = GU.loadVecFieldXsf("FFLJ") PP.lvec2params(lvec) PP.setFF(FFel) xTips, yTips, zTips, lvecScan = PP.prepareScanGrids() #Ks = [ 0.25, 0.5, 1.0 ] #Qs = [ -0.2, 0.0, +0.2 ] #Amps = [ 2.0 ] for iq, Q in enumerate(Qs): FF = FFLJ + FFel * Q PP.setFF_Pointer(FF) for ik, K in enumerate(Ks):
os.chdir(CWD) makeclean( ) import GridUtils as GU import Multipoles as MP import ProbeParticle as PP # ============== Setup WORK_DIR = '/home/prokop/Desktop/Probe_Particle_Simulations/Multipoles/COCu4/' # NOTE: Data for COCu4 tip example are on tarkil /auto/praha1/prokop/STHM/vasp/COCu4 # ============== load reference grid V, lvec, nDim, head = GU.loadXSF( WORK_DIR + 'LOCPOT.xsf' ) cell = np.array( [ lvec[1], lvec[2], lvec[3] ]); MP.setGrid( V, cell ); # ============== prepare atoms atom_types,atom_pos = GU.getFromHead_PRIMCOORD( head ) # load atoms from header of xsf file # set sample region around atom atom_Rmin, atom_Rmax spacies = PP.loadSpecies( './defaults/atomtypes.ini' ) R_type = spacies[:,0] atom_Rmin, atom_Rmax = MP.make_Ratoms( atom_types, R_type ) # mask atoms which should not to be included into the expansion