Esempio n. 1
0
def insert(it_ins, ise_ins, mat_path, it_new, calc, type_of_insertion = "xcart" ):
    """For insertion of atoms to cells with changed lateral sizes
    Input:
    'type_of_insertion = xred' used to add xred coordinates  
    mat_path - path to geo files which are supposed to be changed
    it_ins - already existed calculation; xred will be used from this calculation.
    it_new - new folder in geo folder for obtained structure
    
    This function finds version of calculation in folder mat_path and tries to use the same version of it_ins

    """
    if not os.path.exists(mat_path):
        print_and_log("Error! Path "+mat_path+" does not exist\n\n")
        raise RuntimeError

    if it_ins not in mat_path and it_ins not in it_new: 
        print it_ins, mat_path, it_new
        print_and_log("Error! you are trying to insert coordinates from cell with different name\n\n")
        #raise RuntimeError       

    hstring = ("%s    #on %s"% (traceback.extract_stack(None, 2)[0][3],   datetime.date.today() ) )
    if hstring != header.history[-1]: header.history.append( hstring  )

    geofilelist = runBash('find '+mat_path+'/target -name "*.geo*" ').splitlines()
    
    if geofilelist == []:
        print_and_log("Warning! Target folder is empty. Trying to find in root folder ...")
        geofilelist = runBash('find '+mat_path+'/ -name "*.geo*" ').splitlines()

    ins = None
    for mat_geofile in geofilelist:
        mat = CalculationVasp()
        mat.name = mat_geofile
        mat.read_geometry(mat_geofile)
        #step = 0.27
        #r_pore = 0.56
        #r_mat = mat.hex_a / 2 - step
        #pores = find_pores(mat.init, r_mat, r_pore, step, 0.3, 'central') #octahedral
        #mat.xcart.append ( pores.xcart[0] )
        #mat.typat.append(1)
        try:
            ins_working = ins
            ins = calc[(it_ins, ise_ins, mat.version)]
        except KeyError: 
            print "No key", (it_ins, ise_ins, mat.version), "I use previous working version !!!"
            ins = ins_working
            #return
        #ins.end.znucl = ins.znucl
        #ins.end.nznucl = ins.nznucl
        #ins.end.ntypat = ins.ntypat
        #ins.end.typat = ins.typat
        #print ins.xcart[-1]
        mat_geopath = geo_folder+struct_des[it_new].sfolder + '/'

        if type_of_insertion == "xcart":
            #Please update here!
            mat_filename = '/'+it_new+"."+"inserted."+str(mat.version)+'.'+'geo'
            
            v = np.zeros(3)
            result = insert_cluster(ins.end, v, mat.init, v )
            mat.end = result
            mat.init = result
            # mat.znucl  =   mat.end.znucl
            # mat.nznucl =   mat.end.nznucl
            # mat.ntypat =   mat.end.ntypat
            # mat.typat  =   mat.end.typat
            # mat.natom = len(mat.end.xred)    
            #mat.version = ins.version
            des = ins.name+" was inserted to "+mat_geofile
        
        elif type_of_insertion == "xred":

            mat_filename = '/from/'+it_new+".xred."+str(mat.version)+'.'+'geo'
          
            #mat.end.rprimd = mat.rprimd
            #mat.init.xred  = copy.deepcopy(ins.end.xred)
            #mat.init.typat = copy.deepcopy(ins.end.)
            #print ins.end.xcart
            rprimd   = copy.deepcopy(mat.init.rprimd)
            #build    = mat.build
            mat.init = copy.deepcopy(ins.end)
            #mat.build = build
            mat.init.rprimd = rprimd #return initial rprimd
            mat.init.xcart = xred2xcart(mat.init.xred, mat.init.rprimd) #calculate xcart with new rprimd
          
            des = "atoms with reduced coord. from "+ins.name+" was fully copied to "+mat_geofile
            mat.init.name = 'test_insert_xred'+str(mat.version)
            write_xyz(mat.init)


        mat.path["input_geo"] = mat_geopath + it_new + mat_filename
        if not mat.write_geometry("init",des): continue
        print_and_log("Xred from "+it_ins+" was inserted in "+mat_geofile+" and saved as "+mat_filename+" \n\n")

    return
    
Esempio n. 2
0
    def add(znucl, xyzpath = "", new = None, write_geo = True, put_exactly_to = None):
        "if put_exactly_to is True, then atom just added and nothing are searched"


        if write_geo and os.path.exists(new.path["input_geo"]):
            print_and_log("add: File '"+new.path["input_geo"]+"' already exists; continue\n");
            return new

        #new.init = return_atoms_to_cell(new.init)

        new_before = copy.deepcopy(new)
        
        # new.init.xcart[-2][0]-=0.9 #was made once manually for c1gCOi10.1
        # new.init.xcart[-2][2]+=0.2
        # new.init.xred = xcart2xred(new.init.xcart, new.init.rprimd)
        write_xyz(new.init)
        #step = 0.042
        step = 0.06
        #r_pore = 0.56
        #fine = 0.3 # for visualisation of pores
        #fine = 4   #controls small steps; the steps are smaller for larger numbers
        #r_pore = 0.54
        prec = 0.004 # precision of center Angs
        if new.hex_a == None:
            r_mat = 1.48 -step
        else:
            r_mat = new.hex_a / 2 - step

        if put_exactly_to:
            pores_xred = [np.array(put_exactly_to),]
            print 'Inmpurity just put in ', pores_xred
        else:
            pores = find_pores(new.init, r_mat, r_pore, step, fine, prec,  addtype, new.gbpos, find_close_to, check_pore_vol) #octahedral
            pores_xred = pores.xred
        


        npores = len(pores_xred)
        
        st = new.init

        #delete last oxygen; was made once manually for c1gCOi10.1
        # st.natom-=1
        # del st.xred[-1]
        # del st.typat[-1]




        st.natom += npores
        st.xred.extend( pores_xred )

        if znucl in st.znucl:
            print "znucl of added impurity is already in cell"
            ind = st.znucl.index(znucl)
            typat = ind+1
            st.nznucl[ind]+=npores
        else:
            st.ntypat +=1
            typat = st.ntypat
            st.znucl.append( znucl )
            st.nznucl.append( npores )



        for i in range( npores  ):
            st.typat.append( typat )



        st.xcart = xred2xcart(st.xred, st.rprimd)

        new.init = st

        #print "Add impurity: len(xred ", len(new.init.xred)
        #print "natom", new.init.natom


        #For automatisation of fit
        try: 
            #new.build
            if new.build.nadded == None:      new.build.nadded=npores
            else: new.build.nadded+=npores
            if new.build.listadded == [None]: new.build.listadded = range(new.natom - npores, new.natom) #list of atoms which were added
            else: new.build.listadded.extend( range(new.natom - npores, new.natom) )
            #print "Warning!!! Information about added impurities rewritten"
        except AttributeError: 
            pass

        #new.init.znucl = new.znucl
        #new.init.typat = new.typat
        
        #write_xyz(replic(new.init, (2,1,2))  , xyzpath)

        #test_adding_of_impurities(new, new_before, v)

        print_and_log("Impurity with Z="+str(znucl)+" has been added to the found pore in "+new.name+"\n\n")
        
        if write_geo:
            write_xyz(new.init , xyzpath)
            new.write_geometry("init",new.des)

        print "\n"


        return new
Esempio n. 3
0
    def write_geometry_files(
        dlist,
        in_calc,
        xcart_pores,
        segtyp,
        take_final_rprimd_from=None,
        add_name_before="",
        tlist=[],
        configver=False,
        add_typat=None,
    ):
        """Creating files
        dlist - list of pairs with distances and numbers
        in_calc - base calculation without pores

        tlist - list of additional atoms in the case of triples; list of structures
        configver - if True each configuration saved as a new version
        add_typat - manually determined; please automatize!
        """

        print "Warning! add_typat", add_typat
        if tlist == []:  # convert dlist to tlist - to do earlier
            for el in dlist:
                config = Structure()
                config.name = el[2]
                config.length = el[0]
                config.typat = add_typat
                config.xcart = [el[7], el[8]]
                tlist.append(config)

        for i, el in enumerate(tlist):  # by all found structures
            print "el name is ", el.name
            stn = copy.deepcopy(in_calc.init)
            calc = copy.deepcopy(in_calc)

            stn.typat.extend(el.typat)
            stn.xcart.extend(el.xcart)

            stn.xred = xcart2xred(stn.xcart, stn.rprimd)

            xcart_check = xred2xcart(stn.xred, stn.rprimd)
            assert len(xcart_check) == len(stn.xcart)  # test

            assert all(
                [all(np.around(v1, 8) == np.around(v2, 8)) for (v1, v2) in zip(stn.xcart, xcart_check)]
            )  # check if xcart2xred(stn.xcart,r) and xred2xcart(stn.xred,r) are working correctly up to the eight digits after

            stn.natom = len(stn.xcart)

            """Adapt new rprimd"""
            print "take final rprimd is ", take_final_rprimd_from
            if take_final_rprimd_from:  # read final rprimd and version
                print "Start to read rprimd and version from " + take_final_rprimd_from
                in_calc_rprimd = CalculationVasp()
                in_calc_rprimd.name = "temp"
                in_calc_rprimd.read_geometry(take_final_rprimd_from)

                stn.rprimd = in_calc_rprimd.init.rprimd
                stn.xcart = xred2xcart(stn.xred, stn.rprimd)

                calc.version = in_calc_rprimd.version
            elif configver:
                calc.version = i + 1

            calc.init = stn

            des = (
                " was obtained by the insertion of C-O pair into "
                + in_calc_name
                + "; final vectors taken from corresponding ver"
            )

            calc.build.ipairlen = el.length  # Initial length of pair
            if not hasattr(calc.build, "nadded") or calc.build.nadded == None:
                calc.build.nadded = 2
            else:
                calc.build.nadded += 2
            if not hasattr(calc.build, "listadded") or calc.build.listadded == [None]:
                calc.build.listadded = range(stn.natom - 2, stn.natom)  # list of atoms which were added
            else:
                calc.build.listadded.extend(range(stn.natom - 2, stn.natom))

            structure_name = calc.name + el.name.split(".")[0]
            # calc.name = add_name_before+calc.name+ '.' +el[2]+'.'+str(calc.version)
            print "Structure_name", structure_name
            if structure_name in struct_des:

                if configver:
                    fname = structure_name  # calc.name+'C2O2'
                    calc.path["input_geo"] = (
                        geo_folder
                        + struct_des[fname].sfolder
                        + "/"
                        + fname
                        + "/"
                        + structure_name
                        + "."
                        + segtyp
                        + "."
                        + str(calc.version)
                        + ".geo"
                    )
                else:
                    calc.path["input_geo"] = (
                        geo_folder
                        + struct_des[structure_name].sfolder
                        + "/"
                        + structure_name
                        + "/"
                        + structure_name
                        + "."
                        + segtyp
                        + "."
                        + str(calc.version)
                        + ".geo"
                    )
                print "write geo to ", calc.path["input_geo"]
                calc.write_geometry("init", des)

            print "write_geometry_files(): name ", el.name
            stn.name = add_name_before + calc.name + "" + str(el.name) + "." + str(calc.version)
            # stn = replic(stn, (1,2,2))
            write_xyz(stn)
            print "__________________________\n\n\n"
        return
Esempio n. 4
0
        for i in range(npores.value):
            v_pore = l_npores[i] * aaa
            print  "Volume of pore is ", l_npores[i] * aaa, " A^3";
            if v_pore > v_max: v_max = v_pore; i_max = i
        print "Pore number ", i_max,"has the largest volume ", v_max," A^3"
        # st_result.xred = l_pxred[i_max] # here coordinates of all local points to show geometry of pore with largerst volume
        st_result.xred = [x for group in l_pxred for x in group ] # all pores


    elif calctype == 'all_pores':
        st_result.name = "all_local_pores_from "+name
        st_result.xred = pxred



    st_result.xcart = xred2xcart(st_result.xred, rprimd)

    return st_result




def add_impurity(it_new, impurity_type = None, addtype = 'central', calc = [], r_pore = 0.5,
    it_to = '', ise_to = '', verlist_to = [], copy_geo_from = "", find_close_to = (),add_to_version = 0,
    write_geo = True, only_version = None, fine = 4, put_exactly_to = None, check_pore_vol = 0):

    """
    Add impurities in pores.

    Input:
    it_new - name of new structure with impurity
Esempio n. 5
0
    def write_geometry_files(dlist,
                             in_calc,
                             xcart_pores,
                             segtyp,
                             take_final_rprimd_from=None,
                             add_name_before='',
                             tlist=[],
                             configver=False,
                             add_typat=None):
        """Creating files
        dlist - list of pairs with distances and numbers
        in_calc - base calculation without pores

        tlist - list of additional atoms in the case of triples; list of structures
        configver - if True each configuration saved as a new version
        add_typat - manually determined; please automatize!
        """

        print "Warning! add_typat", add_typat
        if tlist == []:  #convert dlist to tlist - to do earlier
            for el in dlist:
                config = Structure()
                config.name = el[2]
                config.length = el[0]
                config.typat = add_typat
                config.xcart = [el[7], el[8]]
                tlist.append(config)

        for i, el in enumerate(tlist):  #by all found structures
            print "el name is ", el.name
            stn = copy.deepcopy(in_calc.init)
            calc = copy.deepcopy(in_calc)

            stn.typat.extend(el.typat)
            stn.xcart.extend(el.xcart)

            stn.xred = xcart2xred(stn.xcart, stn.rprimd)

            xcart_check = xred2xcart(stn.xred, stn.rprimd)
            assert len(xcart_check) == len(stn.xcart)  #test

            assert all(
                [
                    all(np.around(v1, 8) == np.around(v2, 8))
                    for (v1, v2) in zip(stn.xcart, xcart_check)
                ]
            )  #check if xcart2xred(stn.xcart,r) and xred2xcart(stn.xred,r) are working correctly up to the eight digits after

            stn.natom = len(stn.xcart)
            """Adapt new rprimd"""
            print "take final rprimd is ", take_final_rprimd_from
            if take_final_rprimd_from:  #read final rprimd and version
                print "Start to read rprimd and version from " + take_final_rprimd_from
                in_calc_rprimd = CalculationVasp()
                in_calc_rprimd.name = 'temp'
                in_calc_rprimd.read_geometry(take_final_rprimd_from)

                stn.rprimd = in_calc_rprimd.init.rprimd
                stn.xcart = xred2xcart(stn.xred, stn.rprimd)

                calc.version = in_calc_rprimd.version
            elif configver:
                calc.version = i + 1

            calc.init = stn

            des = ' was obtained by the insertion of C-O pair into ' + in_calc_name + '; final vectors taken from corresponding ver'

            calc.build.ipairlen = el.length  # Initial length of pair
            if not hasattr(calc.build, 'nadded') or calc.build.nadded == None:
                calc.build.nadded = 2
            else:
                calc.build.nadded += 2
            if not hasattr(calc.build,
                           'listadded') or calc.build.listadded == [None]:
                calc.build.listadded = range(
                    stn.natom - 2, stn.natom)  #list of atoms which were added
            else:
                calc.build.listadded.extend(range(stn.natom - 2, stn.natom))

            structure_name = calc.name + el.name.split('.')[0]
            #calc.name = add_name_before+calc.name+ '.' +el[2]+'.'+str(calc.version)
            print 'Structure_name', structure_name
            if structure_name in struct_des:

                if configver:
                    fname = structure_name  # calc.name+'C2O2'
                    calc.path["input_geo"] = geo_folder + struct_des[
                        fname].sfolder + '/' + fname + '/' + structure_name + '.' + segtyp + '.' + str(
                            calc.version) + '.geo'
                else:
                    calc.path["input_geo"] = geo_folder + struct_des[
                        structure_name].sfolder + '/' + structure_name + '/' + structure_name + '.' + segtyp + '.' + str(
                            calc.version) + '.geo'
                print "write geo to ", calc.path["input_geo"]
                calc.write_geometry('init', des)

            print "write_geometry_files(): name ", el.name
            stn.name = add_name_before + calc.name + '' + str(
                el.name) + '.' + str(calc.version)
            #stn = replic(stn, (1,2,2))
            write_xyz(stn)
            print "__________________________\n\n\n"
        return