Exemplo n.º 1
0
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)
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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)
Exemplo n.º 5
0
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
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
#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,
                filename='new.vasp',
                unitcell=unitcell,
                Selective=select)

    t1 = time()
Exemplo n.º 9
0
## 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]
])
new_unitcell.append([
    unitcell[2][0], unitcell[2][1],
    float(unitcell[2][2]) + float(sys.argv[4])
])

jh.w_poscar(position,
            compound=compound,
            filename=filename + '_new.vasp',
            unitcell=new_unitcell,
            Selective=False)
Exemplo n.º 10
0
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', \
            unitcell = unitcell, \
            Selective = False)
Exemplo n.º 11
0
    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,
            'Enmax': int(Enmax),
            'Valency': int(Valency),
            'AtomicMass': float(AtomicMass)