def choose_cell(inputs): print "doping the given structure ", inputs[1] filename = inputs[1] target_ele = inputs[2:] # num_ta_ele = int(inputs[3]) # change_ele = inputs[4] output_name = filename + '_targets.vasp' unitcell, compound, position = jh.r_cryst_vasp(filename) print "Among the elements in the target file %s containing," % filename, compound[ 0], ", you choose:", target_ele #print epsilon, unitcell new_position = [] temp_position = [] for a in range(len(position)): for b in target_ele: if position[a][0] == b: temp_position = position[a] temp_position[0] = b new_position.append(temp_position) # print temp_position[0] # print temp_position,num_ta_ele,target_ele # for a in new_position: # for a in new_position: print a if len(new_position[0]) == 7 and opts.Selec == False: select = False else: select = opts.Selec new_compound, new_position1 = jh.component_from_positions(new_position) jh.w_poscar(position = new_position1,\ compound = new_compound, \ filename = output_name, \ unitcell = unitcell, \ Selective = select)
def expand_cell(filename,expantion,output_name, Selec): print( "[CODE] expand the given structure ", filename) print( """[CODE] output: %s with selective dynamics %s""" %(output_name,out)) unitcell, compound, position = jh.r_cryst_vasp(filename) unitcell, compound, position = jh.pst_cell_expansion(unitcell, position, expantion ) jh.w_poscar(position = position, \ compound = compound, \ filename = output_name,\ unitcell = unitcell, \ Selective= Selec)
def add_atom_in_box(totatom, cellpar, Box, InsertAtomDF, OutputPath, unitcell): exAtomPosition = [[0 for i in range(3)] for j in range(totatom)] N_Atoms = InsertAtomDF['N_atom'].values.tolist() AtomName = InsertAtomDF['element'].values.tolist() AtomRadious = InsertAtomDF['radious'].values.tolist() LabelN = 0 maxAtom = N_Atoms[LabelN] tot_attempt = 0 NewPositions = [] for newatom in range(totatom): exatom = -1 while exatom < newatom and tot_attempt < totatom * 100: NewAtomPosition = [cellpar[i] * random.random() for i in range(3)] tot_attempt = tot_attempt + 1 if tot_attempt > totatom * 100: # Exit Loop if it takes too long print("[CODE] WARNING!!! The LOOP TAKE TOO LONG") break if point_in_box_vector(NewAtomPosition, Box) == True: i = 0 x = exAtomPosition[i] while distance(NewAtomPosition, x) > min(AtomRadious) * 2.5 and i < totatom: i = i + 1 if exAtomPosition[i] != [0, 0, 0]: x = exAtomPosition[i] else: break if distance(NewAtomPosition, x) > min(AtomRadious) * 2.5: exatom = totatom else: pass if distance(NewAtomPosition, x) < 3: pass # print(distance(NewAtomPosition,x)) if newatom < maxAtom: pass elif newatom == maxAtom: LabelN = LabelN + 1 maxAtom = N_Atoms[LabelN] + maxAtom NewPositions.append([ AtomName[LabelN], NewAtomPosition[0], NewAtomPosition[1], NewAtomPosition[2], 'T', 'T', 'T' ]) NewCompound = jh.component_from_positions(NewPositions) jh.w_poscar(NewPositions, compound=NewCompound, filename=OutputPath, unitcell=unitcell, Selective=True) return True
def doping_cell(opts): print "[CODE] doping the given structure ", opts.poscar outname = opts.poscar + '_new.vasp' unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) new_position = [] if len(opts.select) > 0: i = 1 print '[CODE] You choose a mode to doping only -An-Atom %s%i to %s'\ %(opts.select[0][0], int(opts.select[0][1]), opts.select[0][2]) for a in range(len(position)): temp_position = [] if position[a][0] == opts.select[0][0]: if i == int(opts.select[0][1]): temp_position = position[a] temp_position[0] = opts.select[0][2] new_position.append(temp_position) else: new_position.append(position[a]) i = i + 1 else: new_position.append(position[a]) elif opts.target_ele and opts.dopant_ele: wmin, wmax = opts.window print '[CODE] You choose a mode to doping Atoms (%s) in specific region from %f to %f along z-axis to %s'\ %(opts.target_ele, wmin, wmax, opts.dopant_ele) for a in range(len(position)): temp_position = [] if position[a][0] == opts.target_ele and position[a][ 3] < wmax and position[a][3] > wmin: temp_position = position[a] temp_position[0] = opts.dopant_ele new_position.append(temp_position) else: new_position.append(position[a]) else: print '[CODE] YOU NEED TO CHECK help (-h) option' new_compound, new_position1 = jh.component_from_positions(new_position) jh.w_poscar(position = new_position1, \ compound = new_compound, \ filename = outname, \ unitcell = unitcell, \ Selective = False)
def macro(opts): f = open(opts.outname + '.txt', 'r') x = [] y = [] i = 1 for a in f: if i == 1: i = i + 1 else: x.append(float(a.split()[0])) y.append(float(a.split()[1])) l1 = opts.macro_len[ 0] #4.2#abs(x_dipole[0] - x_dipole[1]) #length of 1st target phase l2 = opts.macro_len[ 1] # 4.0#unitcell[2][2] - l1 #length of 2nd target phase# v_m_aver1, m_aver1 = jh.macroscopic_average(x, y, l1) v_m_aver2, m_aver2 = jh.macroscopic_average(x, m_aver1, l2) return x, m_aver2
def add_atom_in_box(totatom, Box, InsertAtomDF, OutputPath, unitcell): exAtomPosition = [] minDistance = InsertAtomDF['radious'].sum() / InsertAtomDF.shape[0] * 2.5 for j in range(InsertAtomDF.shape[0]): label = InsertAtomDF.element.iloc[j] N_atom = InsertAtomDF.N_atom.iloc[j] for natom in range(N_atom): exAtomPosition.append([label, 0, 0, 0, 'T', 'T', 'T']) exAtomPositionDF = pd.DataFrame( exAtomPosition, columns=['label', 'x', 'y', 'z', 'rx', 'ry', 'rz']) for newatom in range(InsertAtomDF.N_atom.sum()): tot_attempt = 0 condition = True while condition and tot_attempt < InsertAtomDF.N_atom.sum() * 1000: NewAtomPosition0 = [random.random() for i in range(3)] while min( np.dot(NewAtomPosition0, unitcell) ) < minDistance / 2 and tot_attempt < InsertAtomDF.N_atom.sum( ) * 1000: NewAtomPosition0 = [random.random() for i in range(3)] NewAtomPosition = np.dot(NewAtomPosition0, unitcell) tot_attempt = tot_attempt + 1 exAtomPositionDF['distance'] = ( (exAtomPositionDF['x'] - NewAtomPosition[0])**2 + (exAtomPositionDF['y'] - NewAtomPosition[1])**2 + (exAtomPositionDF['z'] - NewAtomPosition[2])**2)**0.5 condition = exAtomPositionDF['distance'].min() < minDistance # print(newatom, NewAtomPosition, exAtomPositionDF['distance'].min() > minDistance, min(NewAtomPosition)) exAtomPositionDF['x'].iloc[newatom] = NewAtomPosition[0] exAtomPositionDF['y'].iloc[newatom] = NewAtomPosition[1] exAtomPositionDF['z'].iloc[newatom] = NewAtomPosition[2] NewPositions = exAtomPositionDF.iloc[:, 0:7].values.tolist() NewCompound = jh.component_from_positions(NewPositions) jh.w_poscar(NewPositions, compound=NewCompound, filename=OutputPath, unitcell=unitcell, Selective=True) return True
def temp(filename): i = 1 dist = 2 overlap = 6.87639 / 6 * 1 y_shift = 0.5 unitcell, compound, position = jh.r_cryst_vasp(filename) spli = [] fermi = [] with os.popen("grep fermi OUTCAR |tail -1 | awk '{print $3}'") as a: temp = 1 for line in a: if temp == 1: fermi = line temp = +1 else: pass print "python /team/ptcad/jhlee/b_codework/py_vasp_post_process/py_vasp.dos.py \\" print "-y 0 %10.3f -z %8.5s --notot -q -s 8 %i --fill -x -10 5 \\" \ %((unitcell[2][2] * y_shift +2)/dist , fermi, int(unitcell[2][2] / 2 / dist)) for a in range(int(unitcell[2][2] / dist) + 1): temp = [] i = 1 speci = [] for x in position: if x[3] > a * dist - overlap and x[3] < (a + 1) * dist + overlap: temp.append(i) speci.append(x[0]) i += 1 speci.sort(reverse=True) # print "\ #python /team/ptcad/jhlee/b_codework/py_vasp_post_process/py_vasp.dos.py \ #-y 0 1.0 -z %8.5s --notot -q -s 8 2 --fill -x -10 5 --pdosoffset=%s\ #-p " %(fermi, str(a*dist)), print "\\\n -p ", for xx in temp: print xx, #print " --lc=%s --fill --fac=2 --pdosoffset=%f -l " %(color, y_shift), print " --fill --fac=2 --pdosoffset=%f -l " % (y_shift), for yy in set(speci): sys.stdout.write(yy) if 'Hf' in speci: color = 'black' if 'Ti' in speci: color = 'blue' print " --lc=%s " % (color),
def get_born_effective(opts): in_unitcell, in_compound, in_position = jh.r_cryst_vasp(opts.poscar) n_atom = len(in_position) d = pd.DataFrame( np.zeros((10, n_atom)), columns=['atom', 'xx', 'xy', 'xz', 'yx', 'yy', 'yz', 'zx', 'zy', 'zz']) j = 0 for a, b in zip(in_compound[0], in_compound[1]): for i in range(int(b)): d.atom.iloc[j] = a + '%s' % (int(i) + 1) j = j + 1 if os.path.isfile(opts.outcar) == True: strings = "BORN EFFECTIVE CHARGES (in e, cummulative output)" start_num = read_file_line(opts.outcar, strings) if start_num == 0: return d else: with open(opts.outcar, 'r') as f: i = 0 for line in f: if i > start_num + 1 and i < start_num + n_atom * 4 + 2: if 'ion' in line: index_num = int(line.split()[1]) - 1 if (i - start_num - 2) % 4 == 1: for col_num in range(3): d.iloc[index_num, col_num + 1] = float( line.split()[col_num + 1]) elif (i - start_num - 3) % 4 == 1: for col_num in range(3): d.iloc[index_num, col_num + 4] = float( line.split()[col_num + 1]) elif (i - start_num - 4) % 4 == 1: for col_num in range(3): d.iloc[index_num, col_num + 7] = float( line.split()[col_num + 1]) i = i + 1 else: print("[CODE] Error, There is no %s/OUTCAR" % filename) return d
def main(opts): #print "[CODE] Start to read the given structure: ", opts.poscar unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) a = np.array(unitcell[0]) b = np.array(unitcell[1]) c = np.array(unitcell[2]) volume = np.dot(np.cross(a,b),c) vec_a= np.sum(a**2) ** (0.5) vec_b= np.sum(b**2) ** (0.5) vec_c= np.sum(c**2) ** (0.5) alpha= np.degrees(np.arccos(np.dot(b,c)/vec_b/vec_c)) beta = np.degrees(np.arccos(np.dot(a,c)/vec_a/vec_c)) gamma= np.degrees(np.arccos(np.dot(a,b)/vec_a/vec_b)) print('a %8.8s : %20.10f' %('alpha' ,alpha)) print('a %8.8s : %20.10f' %('beta' ,beta)) print('a %8.8s : %20.10f' %('gamma' ,gamma)) print('l %8.8s : %20.10f' %('vec_a' ,vec_a)) print('l %8.8s : %20.10f' %('vec_b' ,vec_b)) print('l %8.8s : %20.10f' %('vec_c' ,vec_c)) print('V %8.8s : %20.10f' %('volume',volume)) for a,b in zip(compound[0],compound[1]): print('C %8.8s : %20.i' %(a,int(b)))
def main(opts): print("[CODE] Start to read the given structure: ", opts.poscar) if opts.out: output_name = opts.out else: output_name = opts.poscar + '_targets.vasp' new_position = [] temp_position = [] select = True unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) if opts.condi: print('[CODE] the -c option is chosen (not the elements)') if opts.condi[1] < opts.condi[0]: reverse = True print('[CODE] [0] %f is higher than [1] %f' % (opts.condi[0], opts.condi[1])) print( '[CODE] atoms higher than [0] %f and lower then [1] %f are chosen' % (opts.condi[0], opts.condi[1])) else: reverse = False print('[CODE] [1] %f is higher than [0] %f' % (opts.condi[1], opts.condi[0])) print('[CODE] choose element higher than %f and lower than %f' % (opts.condi[0], opts.condi[1])) for a in range(len(position)): if opts.condi[0] > 1 or opts.condi[1] > 1: z = 1 else: z = unitcell[2][2] if reverse: if position[a][3]/z > opts.condi[0] or \ position[a][3]/z < opts.condi[1]: # print a, len(new_position), position[a] temp_position = position[a] new_position.append(temp_position) else: if position[a][3]/z > opts.condi[0] and \ position[a][3]/z < opts.condi[1]: # print position[a][3]/unitcell[2][2], opts.condi temp_position = position[a] new_position.append(temp_position) else: print( "[CODE] Among the elements in the target file %s containing," % opts.poscar, compound[0], ", you choose:", opts.t_ele) for a in range(len(position)): for b in opts.t_ele: if position[a][0] == b: temp_position = position[a] temp_position[0] = b new_position.append(temp_position) if len(position[0]) == 7 and opts.selec == False: select = False else: select = opts.selec new_compound, new_position1 = jh.component_from_positions(new_position) if len(new_position) == 0: print("error!!!") else: jh.w_poscar(position = new_position1,\ compound = new_compound, \ filename = output_name, \ unitcell = unitcell, \ Selective = select)
#Purpose: Moving a poscar import JH_lib as jh import os import numpy as np from optparse import OptionParser #1. Read. import sys if __name__ == '__main__': from time import time # filename = 'CONTCAR' t0 = time() filename = sys.argv[1] ## Lines for JH in SK hynix (180326) unitcell, compound, position = jh.r_cryst_vasp(filename) aver = 0 i = 0 for a in position: aver += a[3] i += 1 # print aver/float(i) new_position = jh.pst_poscar_move(position, 0.0, 0.0, aver / float(i)) # if len(new_position[0]) == 7: select = True # else: # select = False jh.w_poscar(position, compound=compound,
#!/bin/python #Using code JH_lib #Purpose: Moving a poscar import JH_lib as jh import os #1. Read. import sys ## Lines for JH in SK hynix (180326) filename = sys.argv[1] unitcell, compound, position = jh.r_cryst_vasp(filename) print """ [CODE] run this commend with target POSCAR file name and expanded cell which you want: [CODE] for example: python /team/ptcad/jhlee/b_codework/py_edit_poscar/change_unitcell.py POSCAR 0 0 15 [CODE] means: change cell with giving 0, 0, and 15 angstrom in x-axis and y-axis and keeping z-axis [CODE] for the direction, please check after test this code. [CODE] output: %s """ % (filename + '_new.vasp') new_unitcell = [] new_unitcell.append([ float(unitcell[0][0]) + float(sys.argv[2]), unitcell[0][1], unitcell[0][2] ]) new_unitcell.append([ unitcell[1][0], float(unitcell[1][1]) + float(sys.argv[3]), unitcell[1][2] ])
def main(opts): if check_the_input_path(opts.outname+'.txt'): print("[CODE] There is output file ( %s )" %(opts.outname+'.txt')) print("[CODE] Stop to re-reading/writing the potential") print("[CODE] If you want to run, please remove the file or change the outputname (-o)") elif check_the_input_path(opts.poscar) and check_the_input_path(opts.chg): chg =read_CHGCHR_line(opts.chg) length = len(chg) unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) Volume = float(unitcell[0][0]) * float(unitcell[1][1]) * float(unitcell[2][2]) result=[] f=open(opts.outname+'.txt','w' ) f.write(' %10.9s %30.20s %30.20s\n' \ %('height(A)', 'chg (e/A^3)', 'chg (e)')) for a in range(length): f.write(' %10.9s %30.20s %30.20s \n' \ %( float(unitcell[2][2])/length * a + float(unitcell[2][2])/length/2 , \ chg[a] / Volume , \ chg[a])) else: print('[ERROR] There is no input files') print('[ERROR] Stop the calculation') sys.exit() #################################################################### if opts.plotting and check_the_input_path(opts.outname+'.txt'): import matplotlib import matplotlib.pyplot as plt #set the figure format width, height = opts.figsize xmin, xmax = opts.xlim dpi = opts.dpi fig,(ax, ax0) = plt.subplots(2,1) #if opts.macroscopic: fig,(ax, ax0) = plt.subplots(2,1) #else: fig,(ax, ax0) = plt.subplots(2,1) fig.set_size_inches(width, height) fig.tight_layout(pad=0.50) def set_plot(axx, opts): if opts.plot_v == 2: axx.set(xlabel='height(A)', ylabel=r'%s $(e)$' %opts.ylabel ) if opts.plot_v == 1: axx.set(xlabel='height(A)', ylabel=r'%s $(e/A^3)$' %opts.ylabel ) if opts.grid: axx.grid() axx.legend(fontsize='small', frameon=True, framealpha=0.6) if opts.p_title: str2 = os.getcwd().split('/') # get the title from the path axx.set_title('%s of %s' % (str2[len(str2)-1], opts.p_title)) if xmax == 0: pass else: axx.set_xlim([xmin,xmax]) if opts.plot_v == 2: V = 1. elif opts.plot_v == 1: unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) V = float(unitcell[0][0]) * float(unitcell[1][1]) * float(unitcell[2][2]) with open(opts.outname + '.txt' , 'r') as f: x=[]; y=[]; yp =[]; ym=[]; z=[]; i = 1 # ; NGZ = 0 y = [] y_a = [] y_b = [] for line in f: if i == 1: pass else: x.append(float(line.split()[0])) y.append(float(line.split()[2])/V) i = i + 1 ax.plot(x, y, '-', label=opts.label, color='black', linewidth=1) #################################################################### if opts.macroscopic: l1= opts.macro_len[0] #4.2#abs(x_dipole[0] - x_dipole[1]) #length of 1st target phase l2= opts.macro_len[1]# 4.0#unitcell[2][2] - l1 #length of 2nd target phase# print 'plotting macroscopic average (integrated twice with length scale of %s %s' %(l1, l2) v_m_aver1, m_aver1 = jh.macroscopic_average(x,y,l1) v_m_aver2, m_aver2 = jh.macroscopic_average(x,m_aver1,l2) v_m_aver1, m_aver1 = jh.macroscopic_average(x,y,l1) v_m_aver2, m_aver2 = jh.macroscopic_average(x,m_aver1,l2) if opts.plotting: ax0.plot(x, m_aver2, '-', label='2nd integration', color= 'red', linewidth=1) #################################################################### if opts.plotting: set_plot(ax,opts)#,opts.outname) set_plot(ax0, opts)#,opts.outname+'0') fig.tight_layout(pad=0.50) fig.subplots_adjust(hspace= 0.30,\ left = 0.10,\ bottom= 0.10,\ right = 0.90,\ top = 0.90 \ ) plt.savefig(opts.outname+'.png', dpi=opts.dpi) plt.show()
help='Turn on the Selective Dynamics to T T T(Default: False)') return par.parse_args() ############################################################ if __name__ == '__main__': from time import time opts, args = command_line_arg() t0 = time() filename1 = opts.file1 filename2 = opts.file2 output_name = opts.out ## Lines for JH in SK hynix (180326) unitcell1, compound1, position1 = jh.r_cryst_vasp(filename1) unitcell2, compound2, position2 = jh.r_cryst_vasp(filename2) if unitcell1 == unitcell2: #pass print "same!" else: print sys.stderr new_position = position1 + position2 if len(new_position[0]) == 7 and opts.Selec == False: select = False else: select = opts.Selec new_compound, new_position1 = jh.component_from_positions(new_position) jh.w_poscar(position = new_position1,\
############################################################ def check_potcar(elements): f = open(opts.potcar_list, 'r') for line in f: if "'%s'" % elements in line: return line.split()[2:] if __name__ == '__main__': opts, args = command_line_arg() if opts.printout: from time import time t0 = time() unitcell, compound, position = jh.r_cryst_vasp(opts.structure) # print(compound[0],position) x = jh.w_poscar(position, filename=opts.structure + '.vasp', unitcell=unitcell) unitcell, compound, position = jh.r_cryst_vasp(opts.structure + '.vasp') os.system('mv %s %s/POSCAR' % (opts.structure + '.vasp', opts.folderpath)) if opts.printout: print(compound[0], position) commends = 'cat ' MetaList = [] for ele in compound[0]: [PotcarName, Enmax, Valency, AtomicMass] = check_potcar(ele) MetaDict = { 'element': ele, 'PotcarName': PotcarName,
return par.parse_args( ) #################################################################### #################################################################### if __name__ == '__main__': from time import time opts, args = command_line_arg() t0 = time() # filename1 = sys.argv[1] # filename2 = sys.argv[2] ## Lines for JH in SK hynix (180326) sub_unitcell, sub_compound, sub_position = jh.r_cryst_vasp(opts.filename1) add_unitcell, add_compound, add_position = jh.r_cryst_vasp(opts.filename2) z=[]; for a in sub_position: z.append(a[3]) if opts.twoside: min_add=[] ; max_add=[] else: max_add=[] for a in add_position: if opts.twoside: mi = - float(a[3]) + ( min(z) - opts.dist ) ma = float(a[3]) + ( max(z) + opts.dist ) min_add.append([a[0],a[1],a[2], mi])
def main(opts): if check_the_input_path(opts.outname + '.txt'): print("[CODE] There is output file ( %s )" % (opts.outname + '.txt')) print("[CODE] Stop to re-reading/writing the potential") print( "[CODE] If you want to run, please remove the file or change the outputname (-o)" ) elif check_the_input_path(opts.poscar_AB) and check_the_input_path(opts.chg_ab) and \ check_the_input_path(opts.poscar_A) and check_the_input_path(opts.chg_a) and \ check_the_input_path(opts.poscar_B) and check_the_input_path(opts.chg_b): chg_ab = read_CHGCHR_line(opts.chg_ab) chg_a = read_CHGCHR_line(opts.chg_a) chg_b = read_CHGCHR_line(opts.chg_b) length = len(chg_ab) unitcell, compound, position = jh.r_cryst_vasp(opts.poscar_AB) Volume = float(unitcell[0][0]) * float(unitcell[1][1]) * float( unitcell[2][2]) result = [] f = open(opts.outname + '.txt', 'w') f.write(' %10.9s %30.20s %30.20s %30.20s %30.20s %30.20s \n' \ %('height(A)', 'cdd (e/A^3)', 'cdd (e)', 'chg_ab (e)','chg_a (e)', 'chg_b (e)')) for a in range(length): f.write(' %10.9s %30.20s %30.20s %30.20s %30.20s %30.20s \n' \ %( float(unitcell[2][2])/length * a + float(unitcell[2][2])/length/2 , \ (chg_ab[a] - chg_a[a] - chg_b[a]) / Volume , \ (chg_ab[a] - chg_a[a] - chg_b[a]), \ chg_ab[a], chg_a[a], chg_b[a])) else: print('[ERROR] There is no input files') print('[ERROR] Stop the calculation') sys.exit() #################################################################### if opts.plotting and check_the_input_path(opts.outname + '.txt'): import matplotlib import matplotlib.pyplot as plt #set the figure format width, height = opts.figsize xmin, xmax = opts.xlim ymin, ymax = opts.ylim dpi = opts.dpi #fig,(ax, ax0) = plt.subplots(2,1) if opts.macroscopic or opts.plot_all: fig, (ax, ax0) = plt.subplots(2, 1) else: fig, (ax) = plt.subplots(1, 1) fig.set_size_inches(width, height) fig.tight_layout(pad=0.50) option1 = { 'horizontalalignment': 'right', 'verticalalignment': 'baseline', 'fontsize': 10 } #, 'bbox':props} option2 = { 'horizontalalignment': 'left', 'verticalalignment': 'baseline', 'fontsize': 10 } #, 'bbox':props} def set_plot(axx, opts): if opts.plot_v == 2: axx.set(xlabel='height(A)', ylabel=r'%s $(e)$' % opts.ylabel) if opts.plot_v == 1: axx.set(xlabel='height(A)', ylabel=r'%s $(e/A^3)$' % opts.ylabel) if opts.grid: axx.grid() axx.legend(fontsize='small', frameon=True, framealpha=0.6) if opts.p_title: str2 = os.getcwd().split('/') # get the title from the path axx.set_title('%s of %s' % (str2[len(str2) - 1], opts.p_title)) if xmax == 0: pass else: axx.set_xlim([xmin, xmax]) if ymax == 0: pass else: axx.set_ylim([ymin, ymax]) if opts.plot_v == 2: V = 1. elif opts.plot_v == 1: unitcell, compound, position = jh.r_cryst_vasp(opts.poscar_AB) V = float(unitcell[0][0]) * float(unitcell[1][1]) * float( unitcell[2][2]) with open(opts.outname + '.txt', 'r') as f: x = [] y = [] yp = [] ym = [] z = [] i = 1 # ; NGZ = 0 y_ab = [] y_a = [] y_b = [] for line in f: if i == 1: pass else: x.append(float(line.split()[0])) y.append(float(line.split()[2]) / V) y_ab.append(float(line.split()[3]) / V) y_a.append(float(line.split()[4]) / V) y_b.append(float(line.split()[5]) / V) if float(line.split()[2]) > 0: yp.append(float(line.split()[2]) / V) ym.append(0) if float(line.split()[2]) < 0: yp.append(0) ym.append(float(line.split()[2]) / V) i = i + 1 ax.plot(x, y, '-', label='Difference', color='black', linewidth=1) if opts.plot_all: ax0.plot(x, y_ab, '-', label='(AB)', color='black', linewidth=1) ax0.plot(x, y_a, '--', label='(A)', color='silver', linewidth=1) ax0.plot(x, y_b, '--', label='(B)', color='grey', linewidth=1) ax.plot([], [], linewidth=5, label='Electron Accumulated', color='r', alpha=0.5) ax.plot([], [], linewidth=5, label='Electron Loss', color='g', alpha=0.5) ax.fill_between(x, yp, facecolor='r', alpha=0.5) ax.fill_between(x, ym, facecolor='g', alpha=0.5) #################################################################### if opts.cal_area or opts.macroscopic: """ Define the regions for area calculation (center of interface) Condition for center of interface 1. Elements 2. Charge density (or potential density difference) """ x_dipole = [] centering = sum(x) / float(len(x)) unitcell, compound, position_b = jh.r_cryst_vasp(opts.poscar_B) spcl = [] # 2nd phase coordinate list #Get the max/min coordination for the defined 2nd phase for a in position_b: if a[opts.direction] > 0: spcl.append(a[opts.direction]) else: spcl.append(a[opts.direction] + unitcell[opts.direction - 1][opts.direction - 1]) # Applying PBC gap = max(x[len(x) - 1] - x[len(x) - 2], spcl[len(spcl) - 1] - spcl[len(spcl) - 2]) * 2 # When the sign of charge/potential difference change, pcc = [] # potential/charge density sign chage coordinate for num in range(len(y) - 1): if y[num] * y[num + 1] < 0.0: # and abs(x[num]- float(a)) < gap : pcc.append( x[num]) # potential/charge density sign chage coordinate if len(pcc) > 2: temp1 = [] temp2 = [] temp3 = [] less_cent = [] higher_cent = [] for a in pcc: # x_dipole: if a < min(spcl): temp1.append(a) if a > max(spcl): temp2.append(a) x_dipole.append(max(temp1)) x_dipole.append(min(temp2)) elif (max(pcc) - centering) * (min(pcc) - centering) < 0: x_dipole = pcc if opts.cal_area: if opts.plotting: for a in set(x_dipole): ax.plot([a, a], [min(y), max(y)], '--', color='black', linewidth=1) ## Calculate Area import numpy as np from numpy import trapz dist_r11 = [] dist_r12 = [] dist_r21 = [] dist_r22 = [] chg_q11 = [] chg_q12 = [] chg_q21 = [] chg_q22 = [] D_qor11 = [] D_qor12 = [] D_qor21 = [] D_qor22 = [] for num in range(len(y)): if x[num] < min(x_dipole) or x[num] == min(x_dipole): dist_r11.append(x[num]) chg_q11.append(y[num]) D_qor11.append(y[num] / x[num]) elif x[num] > min(x_dipole) and x[num] < centering: dist_r12.append(x[num]) chg_q12.append(y[num]) D_qor12.append(y[num] / x[num]) elif x[num] < max(x_dipole) and x[num] > centering or x[ num] == max(x_dipole): dist_r21.append(x[num]) chg_q21.append(y[num]) D_qor21.append(y[num] / x[num]) else: dist_r22.append(x[num]) chg_q22.append(y[num]) D_qor22.append(y[num] / x[num]) print("area1-1 = %.12f; Dipole1-1 = %.12f" % (trapz(chg_q11, dist_r11), sum(D_qor11))) print("area1-2 = %.12f; Dipole1-2 = %.12f" % (trapz(chg_q12, dist_r12), sum(D_qor12))) print("area2-1 = %.12f; Dipole2-1 = %.12f" % (trapz(chg_q21, dist_r21), sum(D_qor21))) print("area2-2 = %.12f; Dipole2-2 = %.12f" % (trapz(chg_q22, dist_r22), sum(D_qor22))) if opts.plotting: # props = dict(boxstyle='round', facecolor='wheat', alpha=0.5) ax.text(x_dipole[0] * 0.99, max(y) * 0.95, r'%.5f (1-1)$\rightarrow$' % (trapz(chg_q11, dist_r11)), **option1) ax.text(x_dipole[0] * 1.01, max(y) * 0.90, r'$\leftarrow$(1-2) %.5f' % (trapz(chg_q12, dist_r12)), **option2) ax.text(x_dipole[1] * 0.99, max(y) * 0.95, r'%.5f (2-1)$\rightarrow$' % (trapz(chg_q21, dist_r21)), **option1) ax.text(x_dipole[1] * 1.01, max(y) * 0.90, r'$\leftarrow$(2-2) %.5f' % (trapz(chg_q22, dist_r22)), **option2) #################################################################### if opts.macroscopic: print opts.macro_len l1 = opts.macro_len[ 0] #4.2#abs(x_dipole[0] - x_dipole[1]) #length of 1st target phase l2 = opts.macro_len[ 1] # 4.0#unitcell[2][2] - l1 #length of 2nd target phase# v_m_aver1, m_aver1 = jh.macroscopic_average(x, y, l1) v_m_aver2, m_aver2 = jh.macroscopic_average(x, m_aver1, l2) v_m_aver1_ab, m_aver1_ab = jh.macroscopic_average(x, y_ab, l1) v_m_aver2_ab, m_aver2_ab = jh.macroscopic_average(x, m_aver1_ab, l2) sum_m1 = 0 i = 0 i2 = [] for a in range(len(x)): if ( x[a] - min(x_dipole) ) * ( x[a] - max(x_dipole) ) < 0 and \ abs(x[a] - centering) < (max(x_dipole) -min(x_dipole) ) / 6: sum_m1 = sum_m1 + m_aver2_ab[a] i = i + 1 if max(m_aver2_ab) == m_aver2_ab[a]: i2 = a sum_M1 = sum_m1 / i if (m_aver2_ab[i2] - sum_M1) * (m_aver2_ab[0] - sum_M1) < 0: sum_M2 = max(m_aver2_ab) else: sum_M2 = min(m_aver2_ab) print "MACROSCOPIC AVERAGE: min - %s , max-of-center-regiron: %5.4f" \ %(min(m_aver2_ab), sum_m1/i) print "MACROSCOPIC AVERAGE: diff: %5.4f" % (sum_m1 / i - min(m_aver2_ab)) if opts.plotting: if opts.plot_all: ax0.plot(x, m_aver1_ab, '--', label='1st integration', color='blue', linewidth=1) ax0.plot(x, m_aver2_ab, '-', label='$\Delta \widebar \\rho$', color='red', linewidth=1) ax0.plot([min(x), centering], [sum_M1, sum_M1], ':', color='red', linewidth=1) ax0.plot([min(x), centering], [sum_M2, sum_M2], ':', color='red', linewidth=1) arwx0 = (min(x) + centering) / 6 arwy0 = min(sum_M2, sum_M1) darwx = 0 darwy = abs(sum_M1 - sum_M2) ax0.arrow(arwx0, arwy0, darwx, darwy, color='red', head_width=min(.5, darwy / 10), head_length=darwy / 6, length_includes_head=True, linewidth=1) ax0.text(arwx0, arwy0 + darwy / 3, r'%.3f' % (darwy), **option2) #################################################################### if opts.plotting: set_plot(ax, opts) #,opts.outname) if opts.macroscopic: set_plot(ax0, opts) #,opts.outname+'0') fig.tight_layout(pad=0.50) fig.subplots_adjust(hspace= 0.30,\ left = 0.20,\ bottom= 0.10,\ right = 0.90,\ top = 0.90 \ ) plt.savefig(opts.outname + '.png', dpi=opts.dpi) plt.show()
def plot_heatmat_dos(folderpath, ax, points=200, len_dos=1.5): import JH_lib as jh import pandas as pd tdos, atoms = read_doscar(folderpath) unitcell, compound, position = jh.r_cryst_vasp(folderpath + '/POSCAR') surf = 0 for a in position: if a[3] < 20 and a[3] > surf: surf = a[3] plotting = False plotting2 = False plotting3 = True ndos = len(tdos) z_limits = [0, 20] energy_limits = [-5, 5] zlist = [z_limits[1] / points * i for i in range(points)] df_plt = pd.DataFrame() noverlap = np.zeros((int(ndos))) for x in zlist: df_plt['%2.1f' % x] = np.zeros((int(ndos))) df = pd.DataFrame(tdos, columns=['level', 'tdos']) ymax = ndos - int((df.level.max() - energy_limits[1]) / ((df.level.max() - df.level.min()) / ndos)) ymin = int((energy_limits[0] - df.level.min()) / ((df.level.max() - df.level.min()) / ndos)) print(ymax, ymin, surf) ele = 1 for a in atoms: df1 = pd.DataFrame( a, columns=['atom%i_s' % ele, 'atom%i_p' % ele, 'atom%i_d' % ele]) df1['atom%i' % ele] = df1['atom%i_s' % ele] + df1['atom%i_p' % ele] + df1['atom%i_d' % ele] df = pd.concat([df, df1], axis=1) # print(df1['atom%i'%ele].min(), df1['atom%i'%ele].max()) if plotting: zlevel = [position[ele - 1][3] for x in range(int(ndos))] clevel = df1['atom%i' % ele] plt.scatter(x=zlevel, y=df.level, s=0.1, c=clevel, cmap=plt.cm.rainbow) plt.clim(10, 30) if plotting2: for zz in zlist: if abs(position[ele - 1][3] - zz) < 1.0: zlevel = [zz for i in range(int(ndos))] clevel = df1['atom%i' % ele] plt.scatter(x=zlevel, y=df.level, s=0.1, c=clevel, cmap=plt.cm.rainbow) plt.clim(10, 15) if plotting3: for i in range(points): zz = zlist[i] if abs(position[ele - 1][3] - zlist[i]) < len_dos: weight_dist = 1 - abs(position[ele - 1][3] - zlist[i]) / len_dos if df_plt['%2.1f' % zz].sum == 0: # print('zero!') df_plt['%2.1f' % zz] = df1['atom%i' % ele] * weight_dist else: noverlap[i] = noverlap[i] + 1 df_plt['%2.1f' % zz] = df1['atom%i' % ele] * weight_dist + df_plt['%2.1f' % zz] ele = ele + 1 if plotting3: import seaborn as sns df_plt.index = df.level if '01_GaN_0001_' in folderpath: sns.heatmap(df_plt, vmin=0.10, vmax=1.5 / 4, ax=ax, cbar=False) else: sns.heatmap(df_plt, vmin=0.10, vmax=1.5, ax=ax, cbar=False) ax.set( ylim=[ymin, ymax], xlabel='Distance $(\\rm \\AA)$', ylabel='Energy Level (eV)', yticks=[-5, 0, 5], # xticks=[0,20], )
filename = sys.argv[1] epsilon = [float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]) ] print """ [CODE] run this commend with target POSCAR file name and strain which you want: [CODE] for example: python /team/ptcad/jhlee/b_codework/py_edit_poscar/expand_poscar.py POSCAR 0.1 0.1 0 [CODE] means: expand cell with given strain 0.1 and 0.1 in x-axis and y-axis and keeping z-axis [CODE] for some unit cell not keeping cubic/tetragonal like system (non-vertical), check the result [CODE] output: %s """ %(filename+'_new.vasp') ## Lines for JH in SK hynix (180326) unitcell, compound, position = jh.r_cryst_vasp(filename) #print epsilon, unitcell for a in range(3): for b in range(3): # print a,b unitcell[a][b] = float(unitcell[a][b]) * (1 + epsilon[a]) for a in range(len(position)): position[a][1] = float(position[a][1]) * (1 + epsilon[0]) position[a][2] = float(position[a][2]) * (1 + epsilon[1]) position[a][3] = float(position[a][3]) * (1 + epsilon[2]) jh.w_poscar(position = position, \ compound = compound, \ filename = filename+'_new.vasp', \
############################################################ __version__ = "1.0" ############################################################ print """[CODE] run this commend with target POSCAR file name and distance which you want: [CODE] for example: python /team/ptcad/jhlee/b_codework/py_move-poscar/move_poscar.py POSCAR 1 1 1 [CODE] means: moving atoms in given POSCAR 1 Angstrom in x-axis and 1 A in y-axis and 1 A z-axis [CODE] for the direction, please check after test this code. """ if __name__ == '__main__': from time import time t0 = time() filename = sys.argv[1] unitcell, compound, position = jh.r_cryst_vasp(filename) new_position = jh.pst_poscar_move(position, float(sys.argv[2]), \ float(sys.argv[3]),float(sys.argv[4])) if len(new_position[0]) == 7: select = True else: select = False jh.w_poscar(position, compound=compound, filename='new.vasp', unitcell=unitcell, Selective=select) t1 = time()
def main(opts): print '''\ [CODE] Chosen input file:''' if check_the_input_path(opts.poscar) and check_the_input_path( opts.inputname): pass else: print('[ERROR] Stop the calculation') sys.exit if check_the_input_path(opts.outname + '.txt'): print('[CODE] there is same name for output, %s' % opts.outname) print('[CODE] Skip the reading input file: %s' % opts.inputname) #print('[ERROR] Stop the calculation') else: print('[CODE] Start to read input file: %s' % opts.inputname) unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) total = read_potential_line(opts) write_potential_line( unitcell =unitcell ,\ local_potental =total ,\ # plot =opts.plotting ,\ output_name =opts.outname ) # ,\ # ax =axx) #sys.exit() if opts.plotting: print( '''[CODE] Drawing: ON with output (-o, --outname) : %s .txt''' % opts.outname) #set the figure format width, height = opts.figsize xmin, xmax = opts.xlim ymin, ymax = opts.ylim if opts.macroscopic: if opts.permit: fig, (ax0, ax1, ax2) = plt.subplots(3, 1) axx = ax0 else: fig, (ax0, ax1) = plt.subplots(2, 1) axx = ax0 else: fig, ax0 = plt.subplots(1, 1) axx = ax0 plot_1D_plot(opts.outname + '.txt', ax=ax0) else: axx = '' print( '''[CODE] Drawing: OFF (If you want: use -f with/without -o or --outname)''' ) if opts.yyy: f = open(opts.outname + '.txt', 'r') x = [] y = [] i = 1 evac = 9999 for a in f: if i == 1: i = i + 1 ll = a.split()[1] ef = float(a.split()[2]) else: x.append(float(a.split()[0])) y.append(float(a.split()[1])) if float(a.split()[0]) > opts.yyy and evac == 9999: evac = a.split()[1] print( """ filename = %s vaccume energy = %s fermi energy = %s work-function = %f """ % (opts.outname + '.txt', evac, ef, float(evac) - float(ef))) #Ef = read_fermi(opts) if opts.macroscopic: print( '''[CODE] Calculating Macrocsropic average (differenticate) : ON ''' ) target = opts.outname + '.txt' x, bar_V = macro(opts) d_bar_V = np.zeros(bar_V.shape, np.float) d_bar_V[0:-1] = np.diff(bar_V) / np.diff(x) d_bar_V[-1] = (bar_V[-1] - bar_V[-2]) / (x[-1] - x[-2]) write_lines( x = x ,\ xh = 'dist' ,\ ys = [bar_V, d_bar_V] ,\ ysh = ['b', 'db'] ,\ output_name = opts.outname+'_m' ) if opts.permit: p, pz = relative_permitivity(d_bar_V, x, opts.permit) if opts.plotting: if opts.macroscopic: ax0.plot(x, bar_V, '-', label=opts.label + '_macro', color='red', linewidth=1) ax1.plot(x, d_bar_V, '-', label=opts.label + '_macro_differ', color='red', linewidth=1) if opts.permit: ax2.plot(pz, p, '-', label=opts.label, color='red', linewidth=1) ax2.set_xlabel('relative permittivity $(1/\varepsilon)$') if xmin == xmax: pass else: ax0.set_xlim([xmin, xmax]) if ymin == ymax: pass else: ax0.set_ylim([ymin, ymax]) fig.set_size_inches(width, height) # ax0.yaxis.set_ticks(np.arange(ymin, ymax, 4)) # ax0.axes.get_yaxis().set_visible(True) # plt.gca().set_aspect('equal', adjustable='box') # fig.tight_layout(pad=0.50) # ax0.legend(fontsize='small', # frameon=True, # framealpha=0.6) # fig.subplots_adjust(left = 0.10,\ # bottom= 0.10,\ # right = 0.90,\ # top = 0.90 \ # ) plt.grid() # plt.savefig(opts.outname+'.png', dpi=opts.dpi) plt.show() print('[CODE] Finish converting and writting')
def read_doscar_long(folderpath): import JH_lib as jh doscar = open(folderpath+'/DOSCAR', 'r') start_atom_dos=False len_pdos, maxdos, mindos, ndos, efermi,temp , natom= 0,0,0,0,0,0,0 i = 1 ; atoms=[] for line in doscar: # try: if i == 6: [maxdos, mindos, ndos, efermi,temp] = line.split() column=['level','tdos'] tdos=np.zeros((int(ndos),2)) elif i > 6 and i < 6 + (1 + int(ndos)) * 1: tdos[i-7] = [float(xx)-float(efermi) for xx in line.split()[:2]] elif i == 7 + int(ndos): natom=1 elif i > 6 + (1 + int(ndos)) * natom and i < 6 + (1 + int(ndos)) * (natom+1): if start_atom_dos: # print(line, i- 7 - (1 + int(ndos)) * (natom), atom_dos.shape) atom_dos[i- 7 - (1 + int(ndos)) * (natom)] = [float(xx) for xx in line.split()[1:]] else: start_atom_dos = True len_pdos = len(line.split()[1:]) atom_dos=np.zeros(((int(ndos),len_pdos))) # print(line, i- 7 - (1 + int(ndos)) * (natom), atom_dos.shape) elif i == 6 + (1 + int(ndos)) * (natom+1) : if natom != 0: atoms.append(atom_dos) atom_dos=np.zeros(((int(ndos),len_pdos))) natom = natom + 1 i = i + 1 unitcell, compound, position = jh.r_cryst_vasp(folderpath+'/POSCAR') df_plt= pd.DataFrame() df = pd.DataFrame(tdos, columns=['level','tdos']) i=1 ; num = 1; element='' for a in atoms: if position[i-1][0] == element: ele = '%s%i' %(element,i) else: num = 1 ele = '%s%i' %(position[i-1][0],num) element = position[i-1][0] if len_pdos == 9: colname=['%s_s'%ele,'%s_px'%ele, '%s_py'%ele,'%s_pz'%ele, '%s_dxy'%ele,'%s_dyz'%ele,'%s_dz2r2'%ele,'%s_dxz'%ele,'%s_dx2y2'%ele] df1 = pd.DataFrame(a, columns=[colname]) df1['%s_p'%ele] = df1[colname[1:4]].sum(axis=1) df1['%s_d'%ele] = df1[colname[4:]].sum(axis=1) df1['%s'%ele] = df1[colname].sum(axis=1) elif len_pdos == 3: colname=['%s_s'%ele,'%s_p'%ele, '%s_d'%ele] df1 = pd.DataFrame(a, columns=[colname]) df1['%s'%ele] = df1[colname].sum(axis=1) df = pd.concat([df, df1], axis=1) i = i+1 ; num = num + 1 new_colname =['level', 'tdos'] for x in df.columns[2:]: new_colname.append(x[0]) df.columns = new_colname return df, position
def main(opts): print("[CODE] Start to read the given structure: ", opts.poscar) # Read a POSCAR and write to a CIF. path1 = opts.path path2 = path1 + '/xx_SOD_FINDSYM' path3 = path2 + '/0_pre_SOD_FINDSYM' path4 = path2 + '/1_SOD' os.system('mkdir %s' % path2) os.system('mkdir %s' % path3) os.system('mkdir %s' % path4) print("[CODE] Generate the program output in %s", path2) repeat = opts.expand print("[CODE] Doping with expanding structure:", repeat) unitcell, compound, position = jh.r_cryst_vasp('%s' % opts.poscar) structure = pmg.Structure.from_file(opts.poscar) structure.to(filename=path3 + "/POSCAR.cif") # findsym running commends ='cd ' + path3 + '; bash '+ opts.findsym +'/findsym.sh %s %s %s' \ %("./POSCAR.cif", './POSCAR.in', "./POSCAR.iso") os.system(commends) target = [] i = 0 start = False f = open(path3 + "/POSCAR.iso", 'r') for line in f: if start: # print(line) if len(line.split()) > 1: target.append(line.split()[1].split(',')) if 'Space Group' in line: head = line if '_space_group_symop_operation_xyz' in line: start = True if start: if 'loop_' in line: start = False # print(targlet) print_out = False f2 = open(path4 + "/SGO", 'w') f2.write('%s' % head) if print_out: print('%s' % head, end='') for temp in range(len(target)): output_m = [] output_shift = [] for temp1 in range(3): if len(target[temp][temp1].split('+')) == 1: output_m.append( from_operation_xyz_to_matrix(target[temp][temp1])) output_shift.append('0') if len(target[temp][temp1].split('+')) == 2: output_m.append( from_operation_xyz_to_matrix( target[temp][temp1].split('+')[0])) output_shift.append(target[temp][temp1].split('+')[1]) f2.write('%1.0i\n' % (temp + 1)) if print_out: print('%1.0i' % (temp + 1)) # output_m = [[1, 0, 0], [2, 1, 0], [3, 0, 1]] for temp1 in range(3): for temp2 in range(3): f2.write("%4.1i" % output_m[temp1][temp2]) #,end='') if print_out: print("%4.1i" % output_m[temp1][temp2], end='') f2.write("%6.1f\n" % (from_operation_shift_to_matrix(output_shift[temp1]))) if print_out: print("%6.1f" % (from_operation_shift_to_matrix(output_shift[temp1]))) f2.write('0\n') if print_out: print(0) f2.close() commends = 'python2 %s/poscar_info.py -p %s > %s/out.txt' % ( opts.python_jh, opts.poscar, path3) os.system(commends) element = [] Nelement = [] with open('%s/out.txt' % path3, 'r') as f: for line in f: if 'C ' in line: element.append(line.split()[1]) Nelement.append(line.split()[3]) elif 'l ' in line: if 'vec_a' in line: len_a = float(line.split()[3]) elif 'vec_b' in line: len_b = float(line.split()[3]) elif 'vec_c' in line: len_c = float(line.split()[3]) elif 'a ' in line: if 'alpha' in line: alpha = float(line.split()[3]) elif 'beta' in line: beta = float(line.split()[3]) elif 'gamma' in line: gamma = float(line.split()[3]) elif 'V ' in line: if 'vo' in line: volume = line.split()[3] os.system('rm %s/out.txt' % path3) # print(element) f3 = open('%s/INSOD' % path4, 'w') f3.write('''#Title Python-Based-Structure-Generate # a,b,c,alpha,beta,gamma %9.8f %9.8f %9.8f %6.3f %6.3f %6.3f\n''' % (len_a, len_b, len_c, alpha, beta, gamma)) f3.write('''\n# nsp: Number of species %i\n''' % len(element)) f3.write('\n# symbol(1:nsp): Atom symbols\n') for ele in element: f3.write('%5s' % ele) f3.write( '\n\n# natsp0(1:nsp): Number of atoms for each species in the assymetric unit\n' ) for Nele in Nelement: f3.write('%5i' % int(Nele)) f3.write( '\n\n# coords0(1:nat0,1:3): Coordinates of each atom (one line per atom)\n' ) for pos in position: #print ('%8.7f %8.7f %8.7f' %(pos[1],pos[2],pos[3])) f3.write('%8.7f %8.7f %8.7f\n' % (pos[1], pos[2], pos[3])) f3.write('\n# na,nb,nc (supercell definition)\n') for r in repeat: f3.write('%3i' % int(r)) f3.write('\n\n# sptarget: Species to be substituted\n') i = 1 for ele in element: if ele == opts.target: f3.write('%3i' % i) i = i + 1 f3.write('\n\n# nsubs: Number of substitutions in the supercell\n%3i\n' % opts.Nelement) f3.write( '''\n# newsymbol(1:2): Symbol of atom to be inserted in the selected position, # symbol to be inserted in the rest of the positions for the same species. %5s %5s\n''' % (opts.doping, opts.target)) # Ca Mg f3.write(''' # FILER, MAPPER # # FILER: 0 (no calc files generated), 1 (GULP), 2 (METADISE), 11 (VASP) # # MAPPER: 0 (no mapping, use currect structure), >0 (map to structure in MAPTO file) # # (each position in old structure is mapped to MAPPER positions in new structure) 11 0 ''') f3.close() os.system('cd ' + path4 + '; bash ' + opts.sod)
def temp(opts): i = 1 spli = [] fermi = [] unitcell, compound, position = jh.r_cryst_vasp(opts.poscar) width, height = opts.figsize xmin, xmax = opts.xlim out = open("%s" % opts.outname, "w") with os.popen("grep fermi %s |tail -1 | awk '{print $3}'" % opts.outcar) as a: temp = 1 for line in a: if temp == 1: fermi = line temp = +1 else: pass out.write("python %s \\\n" % opts.vasp_dos) out.write( " -y 0 %10.3f -z %8.5s --notot -q -s %i %i --fill -x %i %i \\"\ %( (unitcell[2][2] * opts.shift +2)/opts.dist ,\ fermi, \ width, height,\ # int(unitcell[2][2] / 2 / opts.dist),\ xmin, xmax\ )) out.write( "\n -p 0 --pdosoffset=%f --lc=white --fac=%.2f --pdosoffset=%f -l '' \\" % (opts.shift, opts.pdosFactor, opts.shift)) color = 'white' for a in range(int(unitcell[2][2] / opts.dist) + 1): temp = [] i = 1 speci = [] zzzzz = [] for x in position: if x[3] > a * opts.dist - opts.overlap and \ x[3] < (a + 1) * opts.dist + opts.overlap: temp.append(i) zzzzz.append(x[3]) speci.append(x[0]) i += 1 speci.sort(reverse=True) if sum(zzzzz) == 0: la = 0 else: la = sum(zzzzz) / len(zzzzz) if len(speci) == 0: color = 'white' if la < unitcell[2][2] / 2 and opts.skip: out.write( "\n -p 0 --pdosoffset=%f --lc=white --fac=%.2f --pdosoffset=%f -l '' \\" % (opts.shift, opts.pdosFactor, opts.shift)) if la > unitcell[2][2] / 2: out.write( "\n -p 0 --pdosoffset=%f --lc=white --fac=%.2f --pdosoffset=%f -l '' \\" % (opts.shift, opts.pdosFactor, opts.shift)) else: color = 'white' out.write("\n -p '", ) for xx in temp: out.write(" %s" % xx, ) out.write(" '", ) for x in opts.subele: if x in speci: color = 'red' if color != 'red': for x in opts.ele2: if x in speci: color = 'blue' if color != 'red' and color != 'blue': for x in opts.ele1: if x in speci: color = 'black' # if opts.element[0][0] in speci: # if opts.element[0][1] in speci: color ='red' # else: color ='black' # elif opts.element[0][1] in speci: color ='blue' # else: # for c in opts.subelement[0]: # if c in speci: # color = 'red' out.write( " --lc=%s --fill --fac=%.2f --pdosoffset=%f -l " % (color, opts.pdosFactor, opts.shift), ) for yy in set(speci): out.write("%s" % yy) out.write("_%.1f \\" % la) if len(speci) == 0: print 'Dividing slab with %.2f, In the %2i (th) layer, there is no element' % ( opts.dist, a) else: print 'Dividing slab with %.2f, In the %2i (th) layer, there is element:' % ( opts.dist, a), set(speci), 'as color of %s' % color if opts.dosname: out.write("\n --tofile %s" % (opts.dosname))