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 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 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
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,\ compound = new_compound, \ filename = output_name, \ unitcell = unitcell1, \ Selective = select) t1 = time()
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)