Exemplo n.º 1
0
def main_func(mpid='',mat=None,parameters={}):
    if mpid !='':
       json_dat=parameters['json_dat']
       data = loadfn(json_dat, cls=MontyDecoder)
       for d in data:
            mmpid= str(d['mpid'])
            if mmpid==mpid:
               fin= (d['structure'])

               break

       strt = fin#mp.get_structure_by_material_id(mpid)
       sg_mat = SpacegroupAnalyzer(strt)
       mat_cvn = sg_mat.get_conventional_standard_structure()
       mat_cvn.sort()
       if int(strt.composition._natoms)==int(mat_cvn.composition._natoms):
               mat= Poscar(mat_cvn)
       else:
                mat=Poscar(strt)



       mpid=mpid.replace('-','_')
       mpid=str('bulk@')+str(mpid)
       mat.comment=mpid





    main(p=mat,parameters=parameters)
Exemplo n.º 2
0
def get_chem_pot(s1=None,s2=None,parameters= {}):
#def get_chem_pot(s1=None,s2=None,parameters= {'pair_style':'eam/alloy','pair_coeff':'/scratch/lfs/kamal/POSMAT/Automatic2/Al03.eam.alloy','atom_style': 'charge' ,'control_file':'/home/kamal/inelast.mod'}):
    s1.sort() 
    s2.sort() 
    s3=(set(s2)).symmetric_difference(set(s1))#list(set(s1)-set(s2))
    #s3=[]
    #for el1 in s1:
    #     for el2 in s2:
    #         if el1 !=el2 and el1 not in s3:
    #            s3.append(el1)
    #         if el1 !=el2 and el2 not in s3:
    #            s3.append(el2)
    #             
    #from pymatgen.analysis.structure_matcher import StructureMatcher
    #print "Mather",StructureMatcher().fit(s1, s2)
    print "s3   is   ",type(s1),type(s2),s3
    uniq=[]
    for q in s3:
        el=q._species.elements 
        for j in el:
           print   "j is ",j
           if j not in uniq:   
              uniq.append(j)
              a,b= get_struct_from_mp(j)
              p=Poscar(b)
              p.comment=str(a)
              enp,strt,forces=run_job(mat=p,parameters = parameters)
    if len(uniq)>1:
        print "uniq problem",uniq
    print "uniqqqqqqqqqqqqqqqqqqq=",uniq
    return enp
Exemplo n.º 3
0
def do_phonons(strt=None, parameters=None, c_size=25):
    """
    Setting up phonopy job using LAMMPS

    Args:
        strt: Structure object
        parameters: LAMMPS input file parameters
        c_size: cell-size 
    
    """

    p = get_phonopy_atoms(mat=strt)
    bulk = p

    dim1 = int((float(c_size) / float(max(abs(strt.lattice.matrix[0]))))) + 1
    dim2 = int(float(c_size) / float(max(abs(strt.lattice.matrix[1])))) + 1
    dim3 = int(float(c_size) / float(max(abs(strt.lattice.matrix[2])))) + 1
    Poscar(strt).write_file("POSCAR")
    tmp = strt.copy()
    tmp.make_supercell([dim1, dim2, dim3])
    Poscar(tmp).write_file("POSCAR-Super.vasp")

    phonon = Phonopy(bulk, [[dim1, 0, 0], [0, dim2, 0], [0, 0, dim3]])  # ,
    print("[Phonopy] Atomic displacements:")
    disps = phonon.get_displacements()
    for d in disps:
        print("[Phonopy]", d[0], d[1:])
    supercells = phonon.get_supercells_with_displacements()

    # Force calculations by calculator
    set_of_forces = []
    disp = 0
    for scell in supercells:
        cell = Atoms(
            symbols=scell.get_chemical_symbols(),
            scaled_positions=scell.get_scaled_positions(),
            cell=scell.get_cell(),
            pbc=True,
        )
        disp = disp + 1

    mat = Poscar(AseAtomsAdaptor().get_structure(cell))
    mat.comment = str("disp-") + str(disp)
    parameters["min"] = "skip"
    parameters["control_file"] = "/users/knc6/in.phonon"
    # a,b,forces=run_job(mat=mat,parameters={'min':'skip','pair_coeff': '/data/knc6/JARVIS-FF-NEW/ALLOY4/Mishin-Ni-Al-2009.eam.alloy', 'control_file': '/users/knc6/in.phonon', 'pair_style': 'eam/alloy', 'atom_style': 'charge'})
    a, b, forces = run_job(mat=mat, parameters=parameters)
    print("forces=", forces)
    drift_force = forces.sum(axis=0)
    print("drift forces=", drift_force)
    print("[Phonopy] Drift force:", "%11.5f" * 3 % tuple(drift_force))
    # Simple translational invariance
    for force in forces:
        force -= drift_force / forces.shape[0]
    set_of_forces.append(forces)
    phonon.produce_force_constants(forces=set_of_forces)

    write_FORCE_CONSTANTS(phonon.get_force_constants(), filename="FORCE_CONSTANTS")
    print()
    print("[Phonopy] Phonon frequencies at Gamma:")
Exemplo n.º 4
0
def main(p=None,vac_cal=True,surf_cal=True,phon_cal=True, parameters={}):

    #p=Poscar.from_file("POSCAR")
    c_size=parameters['c_size']
    vac_size=parameters['vac_size']
    surf_size=parameters['surf_size']
    phon_size=parameters['phon_size']
    sg_mat = SpacegroupAnalyzer(p.structure)
    mat_cvn = sg_mat.get_conventional_standard_structure()
    dim1=int((float(c_size)/float( max(abs(mat_cvn.lattice.matrix[0])))))+1
    dim2=int(float(c_size)/float( max(abs(mat_cvn.lattice.matrix[1]))))+1
    dim3=int(float(c_size)/float( max(abs(mat_cvn.lattice.matrix[2]))))+1
    cellmax=max(dim1,dim2,dim3)
    tmp=mat_cvn.copy()
    mat_cvn.make_supercell([dim1,dim2,dim3])
    #print "dim1 dim2 dim3",dim1,dim2,dim3
    #mat_cvn.make_supercell([dim1,dim2,dim3])
    mat_pos=Poscar(mat_cvn)
    mat_pos.comment=str(p.comment)
    #print ('execcccccc',parameters['exec'])
    #print mat_pos
    #toten,final_str,forces=run_job(mat=mat_pos,parameters = parameters)
    #do_phonons(strt=final_str,parameters=parameters)
    try:
       print ('in elastic calc')
       toten,final_str,forces=run_job(mat=mat_pos,parameters = parameters)
       print ('done elastic calc')
    except:
       pass
    vac=vac_antisite_def_struct_gen(c_size=vac_size,struct=final_str)
    def_list,header_list=def_energy(vac=vac,parameters = parameters)
    #print def_list,header_list
    try:
     if vac_cal==True:
       print ('in defect calc')
       vac=vac_antisite_def_struct_gen(c_size=vac_size,struct=final_str)
       def_list,header_list=def_energy(vac=vac,parameters = parameters)
       print ('done defect calc',def_list,header_list)
    except:
       pass
    try:
     if surf_cal==True:
        print ('in surf calc')
        surf=pmg_surfer(mat=final_str, min_slab_size=surf_size,vacuum=25,max_index=3)
        surf_list,surf_header_list=surf_energy(surf=surf,parameters = parameters)
        print ('done surf calc',surf_list,surf_header_list)
    except:
       pass
    try:
     if phon_cal==True:
       print ('in phon calc')
       cwd=str(os.getcwd())
       if not os.path.exists("Phonon"):
          os.mkdir("Phonon")
       os.chdir("Phonon")
       do_phonons(strt=final_str,parameters=parameters)
       print ('done phon calc')
       os.chdir(cwd)
    except:
       pass
Exemplo n.º 5
0
def main_func(mpid='',mat=None,parameters={}):
    if mpid !='':
       with MPRester() as mp:
         strt = mp.get_structure_by_material_id(mpid)
         mat=Poscar(strt)

         mpid=mpid.replace('-','_')
         mpid=str('bulk@')+str(mpid)
         mat.comment=mpid

    main(p=mat,parameters=parameters)
Exemplo n.º 6
0
def do_phonons(strt=None,parameters=None):

        p= get_phonopy_atoms(mat=strt)
        bulk =p
        c_size=parameters['phon_size']
        dim1=int((float(c_size)/float( max(abs(strt.lattice.matrix[0])))))+1
        dim2=int(float(c_size)/float( max(abs(strt.lattice.matrix[1]))))+1
        dim3=int(float(c_size)/float( max(abs(strt.lattice.matrix[2]))))+1
        Poscar(strt).write_file("POSCAR")
        tmp=strt.copy()
        tmp.make_supercell([dim1,dim2,dim3])
        Poscar(tmp).write_file("POSCAR-Super.vasp")
    
        print ('supercells',dim1,dim2,dim3)
        phonon = Phonopy(bulk,[[dim1,0,0],[0,dim2,0],[0,0,dim3]]) 
        print ("[Phonopy] Atomic displacements:")
        disps = phonon.get_displacements()

        for d in disps:
            print ("[Phonopy]", d[0], d[1:])
        supercells = phonon.get_supercells_with_displacements()

        # Force calculations by calculator
        set_of_forces = []
        disp=0
        for scell in supercells:
            cell = Atoms(symbols=scell.get_chemical_symbols(),
                         scaled_positions=scell.get_scaled_positions(),
                         cell=scell.get_cell(),
                         pbc=True)
            disp=disp+1

            mat = Poscar(AseAtomsAdaptor().get_structure(cell))
            mat.comment=str("disp-")+str(disp)
            parameters['min']='skip'
            parameters['control_file']= parameters['phonon_control_file']  #'/users/knc6/in.phonon'
            #a,b,forces=run_job(mat=mat,parameters={'min':'skip','pair_coeff': '/data/knc6/JARVIS-FF-NEW/ALLOY4/Mishin-Ni-Al-2009.eam.alloy', 'control_file': '/users/knc6/in.phonon', 'pair_style': 'eam/alloy', 'atom_style': 'charge'})
            a,b,forces=run_job(mat=mat,parameters=parameters)
            #print "forces=",forces
            drift_force = forces.sum(axis=0)
            #print "drift forces=",drift_force
            #print "[Phonopy] Drift force:", "%11.5f"*3 % tuple(drift_force)
            # Simple translational invariance
            for force in forces:
                force -= drift_force / forces.shape[0]
            set_of_forces.append(forces)
        phonon.produce_force_constants(forces=set_of_forces)

        write_FORCE_CONSTANTS(phonon.get_force_constants(),
                              filename="FORCE_CONSTANTS")
        #print
        #print "[Phonopy] Phonon frequencies at Gamma:"
        for i, freq in enumerate(phonon.get_frequencies((0, 0, 0))):
            print ("[Phonopy] %3d: %10.5f THz" %  (i + 1, freq)) # THz
Exemplo n.º 7
0
def main_func(mpid="", mat=None, parameters={}):
    """
    Call master job function either using mpid or Poscar object
    """
    if mpid != "":
        with MPRester() as mp:
            strt = mp.get_structure_by_material_id(mpid)
            mat = Poscar(strt)

            mpid = mpid.replace("-", "_")
            mpid = str("bulk@") + str(mpid)
            mat.comment = mpid

    main(p=mat, parameters=parameters)
Exemplo n.º 8
0
def make_big(poscar=None,size=11.0):
    """
    Helper function to make supercell
 
    Args:
      poscar: Poscar object
      size: simulation size in Angstrom
    Returns:
       big: Poscar supercell object
    """
    struct=poscar.structure
    comm=poscar.comment
    a, b, c = struct.lattice.abc
    struct.make_supercell([int(float(size)/float(a))+1,int(float(size)/float(b))+1,int(float(size)/float(c))+1])
    big=Poscar(struct)
    big.comment=str(comm)
    return big
Exemplo n.º 9
0
def main_func(mpid='', jid='', mat=None, enforc_cvn=False):
    """
    Main function to carry out property calculations

    Args:
        mpid: materialsproject id
        jid: jarvis-dft id
        mat: Poscar object
        enforc_cvn:  whether or not enforce conventional cell input structure
    Returns:
       en: final energy
       final: final structure
    """

    if mpid != '' or jid != '':
        data = loadfn(json_dat, cls=MontyDecoder)
        for d in data:
            mmpid = str(d['mpid'])
            jjid = str(d['mpid'])
            if mmpid == mpid:
                fin = (d['structure'])
                break
            if jjpid == jid:
                fin = (d['structure'])
                break

        strt = fin
        sg_mat = SpacegroupAnalyzer(strt)
        mat_cvn = sg_mat.get_conventional_standard_structure()
        mat_cvn.sort()
        if int(strt.composition._natoms) == int(
                mat_cvn.composition._natoms) and enforc_cvn == True:
            mat = Poscar(mat_cvn)
        else:
            mat = Poscar(strt)

        mpid = mpid.replace('-', '_')
        mpid = str('bulk@') + str(mpid)
        mat.comment = mpid

    en, final = smart_converge(mat=mat)
    print(en, final)
Exemplo n.º 10
0
def get_chem_pot(s1=None,s2=None,parameters= {}):
#def get_chem_pot(s1=None,s2=None,parameters= {'pair_style':'eam/alloy','pair_coeff':'/scratch/lfs/kamal/POSMAT/Automatic2/Al03.eam.alloy','atom_style': 'charge' ,'control_file':'/home/kamal/inelast.mod'}):
    s1.sort() 
    s2.sort() 
    s3=(set(s2)).symmetric_difference(set(s1))#list(set(s1)-set(s2))
    uniq=[]
    for q in s3:
        el=q._species.elements 
        for j in el:
           j=str(j.symbol)
           if j not in uniq:   
              uniq.append(j)
              a,b= get_struct_from_mp(j)
              p=Poscar(b)
              p.comment=str(a)
              enp,strt,forces=run_job(mat=p,parameters = parameters)
    if len(uniq)>1:
        print ("uniq problem",uniq)
    print ("uniq=",uniq)
    return enp
Exemplo n.º 11
0
def get_chem_pot(s1=None, s2=None, parameters={}):
    """
    Get chemical potential given perfect and defect structures

    Args:
        s1: perfect Structure object
        s2: defect Structure object
        parameters: LAMMPS input parameter
    Returns:
           enp: energy per atom
    """
    # def get_chem_pot(s1=None,s2=None,parameters= {'pair_style':'eam/alloy','pair_coeff':'/scratch/lfs/kamal/POSMAT/Automatic2/Al03.eam.alloy','atom_style': 'charge' ,'control_file':'/home/kamal/inelast.mod'}):
    s1.sort()
    s2.sort()
    s3 = (set(s2)).symmetric_difference(set(s1))  # list(set(s1)-set(s2))
    # s3=[]
    # for el1 in s1:
    #     for el2 in s2:
    #         if el1 !=el2 and el1 not in s3:
    #            s3.append(el1)
    #         if el1 !=el2 and el2 not in s3:
    #            s3.append(el2)
    #
    # from pymatgen.analysis.structure_matcher import StructureMatcher
    # print "Mather",StructureMatcher().fit(s1, s2)
    print("s3   is   ", type(s1), type(s2), s3)
    uniq = []
    for q in s3:
        el = q._species.elements
        for j in el:
            print("j is ", j)
            if j not in uniq:
                uniq.append(j)
                a, b = chempot_struct(j.symbol)
                # a, b = get_struct_from_jv(j)
                p = Poscar(b)
                p.comment = str(a)
                enp, strt, forces = run_job(mat=p, parameters=parameters)
    if len(uniq) > 1:
        print("uniq problem", uniq)
    return enp
Exemplo n.º 12
0
                bg_arr.append(bg)
                tm_arr.append(tm)
                ucf_arr.append(ucf)
                ehull_arr.append(ehull)

                comment = str("bulk@") + str(x)
                folder2 = str(
                    os.getcwd()) + str("/") + str(comment) + str("_fold")
                if not os.path.exists(folder2):
                    os.makedirs(str(folder2))
                print("folder2=", folder2)
                cwd2 = str(os.getcwd())
                os.chdir(str(folder2))

                p = Poscar(structure)
                p.comment = comment
                p.write_file("POSCAR")
                poscar_file = str(os.getcwd()) + str("/POSCAR")

                pair_coeff = str(cwd1) + str("/") + str(file)
                # pair_coeff=str('/data/knc6/JARVIS-FF-NEW/ALLOY')+str("/")+str(file)
                parameters = {
                    "pair_style": "eam/fs",
                    "pair_coeff": pair_coeff,
                    "atom_style": "charge",
                    "control_file": "/users/knc6/inelast.mod",
                }
                main_file = open("setup.py", "w")
                line = str("from NEW_LAMMPS10 import main_func") + "\n"
                main_file.write(line)
                line = str(
Exemplo n.º 13
0
def main_alloy():
    """
   Run alloy FFs job
   """
    for file in glob.glob("*.alloy"):
        try:
            folder1 = str(os.getcwd()) + str("/") + str(file) + str("_nist")
            if not os.path.exists(folder1):
                os.makedirs(str(folder1))
            cwd1 = str(os.getcwd())
            print("folder1=", folder1)
            ff = str(file)
            element_ff = []
            f = open(ff, "r")
            os.chdir(str(folder1))
            list_el = []
            lines = f.readlines()
            content = (lines[3]).split(" ")
            # content=(lines[3]).split("' '|\n|\r\n")
            for val in content:

                if val != "" and val != "\n" and val != "\r\n":
                    list_el.append(val)
            for i in range(0, len(list_el)):
                if i != 0:
                    element_ff.append(list_el[i])
            #    print ff,' ',element_ff
            with MPRester(MAPI_KEY) as m:
                data = m.get_entries_in_chemsys(
                    element_ff,
                    inc_structure="final",
                    property_data=[
                        "unit_cell_formula",
                        "material_id",
                        "icsd_id",
                        "spacegroup",
                        "energy_per_atom",
                        "formation_energy_per_atom",
                        "pretty_formula",
                        "band_gap",
                        "total_magnetization",
                        "e_above_hull",
                    ],
                )
                if len(element_ff) > 1:
                    try:
                        entries = m.get_entries_in_chemsys(element_ff)
                        pd = PhaseDiagram(entries)
                        plotter = PDPlotter(pd, show_unstable=True)
                        image = str(ff) + str("_DFT") + str(".jpg")
                        plotter.write_image(image)
                    except:
                        pass
                structures = []
                structures_cvn = []
                icsd_arr = []
                mp_arr = []
                sg_arr = []
                enp_arr = []
                fenp_arr = []
                pf_arr = []
                ucf_arr = []
                bg_arr = []
                tm_arr = []
                ehull_arr = []
                for d in data:
                    x = d.data["material_id"]
                    sg = d.data["spacegroup"]
                    enp = d.data["energy_per_atom"]
                    fenp = d.data["formation_energy_per_atom"]
                    pf = d.data["pretty_formula"]
                    ucf = d.data["unit_cell_formula"]
                    bg = d.data["band_gap"]
                    tm = d.data["total_magnetization"]
                    ehull = d.data["e_above_hull"]
                    icsd = d.data["icsd_id"]
                    structure = m.get_structure_by_material_id(x)
                    structures.append(structure)
                    icsd_arr.append(icsd)
                    mp_arr.append(x)
                    sg_arr.append(sg)
                    enp_arr.append(enp)
                    fenp_arr.append(fenp)
                    pf_arr.append(pf)
                    bg_arr.append(bg)
                    tm_arr.append(tm)
                    ucf_arr.append(ucf)
                    ehull_arr.append(ehull)

                    comment = str("bulk@") + str(x)
                    folder2 = str(os.getcwd()) + str("/") + str(comment) + str("_fold")
                    if not os.path.exists(folder2):
                        os.makedirs(str(folder2))
                    print("folder2=", folder2)
                    cwd2 = str(os.getcwd())
                    os.chdir(str(folder2))

                    p = Poscar(structure)
                    p.comment = comment
                    p.write_file("POSCAR")
                    poscar_file = str(os.getcwd()) + str("/POSCAR")

                    pair_coeff = str(cwd1) + str("/") + str(file)
                    # pair_coeff=str('/data/knc6/JARVIS-FF-NEW/ALLOY')+str("/")+str(file)
                    parameters = {
                        "pair_style": "eam/alloy",
                        "exec": lammps_exec,
                        "pair_coeff": pair_coeff,
                        "atom_style": "charge",
                        "control_file": input_box,
                    }
                    main_file = open("setup.py", "w")
                    line = str("from jlammps import main_func") + "\n"
                    main_file.write(line)
                    line = str("from pymatgen.io.vasp.inputs import  Poscar") + "\n"
                    main_file.write(line)
                    # line=str("try:")+'\n'
                    # main_file.write(line)
                    line = (
                        str("p=Poscar.from_file(")
                        + str('"')
                        + str(poscar_file)
                        + str('"')
                        + str(")")
                        + "\n"
                    )
                    main_file.write(line)
                    line = (
                        str("main_func(mat=p")
                        + str(",")
                        + str("parameters=")
                        + str(parameters)
                        + str(")")
                        + "\n"
                    )
                    main_file.write(line)
                    # line=str("except:")+'\n'
                    # main_file.write(line)
                    # line=str("     pass")+'\n'
                    # main_file.write(line)
                    main_file.close()
                    # try:
                    #    p=Poscar.from_file(poscar_file)
                    #    main_func(mat=p,parameters=parameters)
                    # except:
                    #     pass
                    os.chdir(cwd2)  # =str(os.getcwd())
            os.chdir(cwd1)  # =str(os.getcwd())
        except:
            pass
Exemplo n.º 14
0
def main(p=None, parameters={}, c_size=35):
    """
    Master function to run LAMMPS job

    Args:
        p: Poscar object
        parameters: LAMMPS input parameters
        c_size:cell size
    """
    # p=Poscar.from_file("POSCAR")
    c_size = 35
    sg_mat = SpacegroupAnalyzer(p.structure)
    mat_cvn = sg_mat.get_conventional_standard_structure()
    dim1 = int((float(c_size) / float(max(abs(mat_cvn.lattice.matrix[0]))))) + 1
    dim2 = int(float(c_size) / float(max(abs(mat_cvn.lattice.matrix[1])))) + 1
    dim3 = int(float(c_size) / float(max(abs(mat_cvn.lattice.matrix[2])))) + 1
    cellmax = max(dim1, dim2, dim3)
    # print "dim1 dim2 dim3",dim1,dim2,dim3
    # mat_cvn.make_supercell([dim1,dim2,dim3])
    mat_pos = Poscar(mat_cvn)
    mat_pos.comment = str(p.comment)
    print(mat_pos)
    try:
        toten, final_str, forces = run_job(mat=mat_pos, parameters=parameters)
    except:
        pass
    print("p.comment issssss", p.comment)
    vac = vac_antisite_def_struct_gen(c_size=c_size, struct=final_str)
    def_list, header_list = def_energy(vac=vac, parameters=parameters)
    print(def_list, header_list)
    try:
        print("p.comment issssss", p.comment)
        vac = vac_antisite_def_struct_gen(c_size=c_size, struct=final_str)
        def_list, header_list = def_energy(vac=vac, parameters=parameters)
        print(def_list, header_list)
    except:
        pass
    try:
        surf = pmg_surfer(mat=final_str, min_slab_size=35, vacuum=35, max_index=3)
        surf_list, surf_header_list = surf_energy(surf=surf, parameters=parameters)
        print(surf_list, surf_header_list)
    except:
        pass
    try:
        cwd = str(os.getcwd())
        if not os.path.exists("Phonon"):
            os.mkdir("Phonon")
        os.chdir("Phonon")
        do_phonons(strt=final_str, parameters=parameters)
        os.chdir(cwd)
    except:
        pass
    sub_files = []
    calc = 0
    for a in glob.glob("*.json"):
        fold = a.split(".json")[0]
        cwd = os.getcwd()
        target_file = str(cwd) + str("/") + str(fold)
        dest_file = str(cwd) + str("/") + str(fold) + str(".zip")
        sub_files.append(dest_file)
        ZipDir(
            target_file,
            dest_file,
            contents=[
                "init.mod",
                "potential.mod",
                "in.elastic",
                "data",
                "log.lammps",
                "restart.equil",
                "data0",
            ],
        )
    calc = calc + 1

    target_file = str(cwd)
    dest_file = str(cwd) + str("/") + str("Calc-") + str(calc) + str(".zip")
    ZipDir(target_file, dest_file, contents=sub_files)
    for a in glob.glob("*.json"):
        fold = a.split(".json")[0]
        cwd = os.getcwd()
        dest_file = str(cwd) + str("/") + str(fold) + str(".zip")
        line = str("rm ") + str(dest_file)
        os.system(line)
Exemplo n.º 15
0
from jarvis.vasp.joptb88vdw import smart_converge
from pymatgen.io.vasp.inputs import Poscar
from pymatgen.core.structure import Structure

import os, time
s = Structure.from_file('POSCAR')
p = Poscar(s)
p.comment = 'bulk@ATAT'
en, final = smart_converge(mat=p, elast_prop=False)
print "en,finel", en, final
Exemplo n.º 16
0
def smart_converge(mat=None,encut='',leng='',band_str=True,elast_prop=True,optical_prop=True,mbj_prop=True,spin_orb=False,phonon=False,surf_en=False,def_en=False):
    """
    Main function to converge k-points/cut-off
    optimize structure, and run subsequent property calculations

    Args:
         mat: Poscar object with structure information
         encut: if '' then automataic convergence, else use defined fixed-cutoff
         leng: if '' then automataic convergence, else use defined fixed-line density
         band_str: if True then do band-structure calculations along high-symmetry points
         elast_prop: if True then do elastic property calculations using finite-difference
         optical_prop: if True do frequency dependent dielectric function calculations using he independent-particle (IP) approximation
         mbj_prop: if True do METAGGA-TBmBJ optical property calculations with IP approximation
         spin_orb: if True do spin-orbit calculations
         phonon: if True do phonon calculations using DFPT
         surf_en: if True do surface enrgy calculations 
         def_en: if True do defect enrgy calculations 
    Returns:
         en2: final energy
         mat_f: final structure
    """
    if encut=="":
      encut=converg_encut(encut=500,mat=mat)

    if leng=="":
       leng= converg_kpoints(length=0,mat=mat)

    kpoints=Auto_Kpoints(mat=mat,length=leng)
    isif=2
    commen=str(mat.comment)
    lcharg='.FALSE.' 
    if commen.split('@')[0] =='bulk' :
       isif=3
       lcharg='.TRUE.' 
    if commen.split('@')[0] == 'sbulk':
       isif=3
    incar_dict = use_incar_dict
    incar_dict.update({"ENCUT":encut,"EDIFFG":-1E-3,"ISIF":3,"NEDOS":5000,"NSW":500,"NELM":500,"LORBIT":11,"LVTOT":'.TRUE.',"LVHAR":'.TRUE.',"ISPIN":2,"LCHARG":'.TRUE.'})
    incar = Incar.from_dict(incar_dict)
    try:
       if mat.comment.startswith('Mol'):
          incar.update({"ISIF": '2'})
    except:  
         print ("Mol error")
         pass
    #if commen.startswith('Surf-') :
    #   pol=check_polar(mat_f.structure)
    #   if pol==True:
    #        ase_atoms = AseAtomsAdaptor().get_atoms(mat_f.structure)
    #        COM=ase_atoms.get_center_of_mass(scaled=True)
    #        incar.update({"LDIPOL": '.TRUE.',"IDIPOL":4,"ISYM": 0,"DIPOL":COM})
    print ("running smart_converge for",str(mat.comment)+str('-')+str('MAIN-RELAX'))
    cwd=str(os.getcwd()) 
    en2,contc=run_job(mat=mat,incar=incar,kpoints=kpoints,jobname=str('MAIN-RELAX')+str('-')+str(mat.comment)) 
    os.chdir(cwd)
    path=str(contc.split('/CONTCAR')[0])+str('/vasprun.xml')
    v=open(path,"r").readlines()
    for line in v:
           if "NBANDS" in  line:
               nbands=int(line.split(">")[1].split("<")[0])
               print ("nbands=",nbands)
               break
    strt=Structure.from_file(contc)
    mat_f=Poscar(strt)
    mat_f.comment=str(mat.comment)
    if band_str==True:
       incar_dict = use_incar_dict
       incar_dict.update({"ISPIN":2,"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":int(nbands)+10})
       incar = Incar.from_dict(incar_dict)
       kpath = HighSymmKpath(mat_f.structure)
       frac_k_points, k_points_labels = kpath.get_kpoints(line_density=20,coords_are_cartesian=False)
       kpoints = Kpoints(comment="Non SCF run along symmetry lines",style=Kpoints.supported_modes.Reciprocal,num_kpts=len(frac_k_points),kpts=frac_k_points, labels=k_points_labels,kpts_weights=[1] * len(frac_k_points))
 
       try: 
           print ("running MAIN-BAND")
           kpoints=mpvis.get_kpoints(mat_f.structure)
           en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment))  
          # kpoints=mpvis.get_kpoints(mat_f.structure)
          # en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment))  
       except:
           print ("No band str calc.")
           if str(os.getcwd)!=cwd:
                print ("Changing directory")
                line=str("cd ")+str(cwd)
                os.chdir(cwd)
                print (os.getcwd())

           pass
    os.chdir(cwd)
    if surf_en==True:
       incar_dict = use_incar_dict
       incar_dict.update({"ENCUT":encut,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11})
       incar = Incar.from_dict(incar_dict)
       surf=surfer(mat=mat_f.structure,layers=3)
       for i in surf:

         try: 
           print ("running MAIN-BAND")
           #NSCF
           #chg_file=str(contc).replace('CONTCAR','CHGCAR')
           #print ('chrfile',chg_file)
           #shutil.copy2(chg_file,'./')
           kpoints=Auto_Kpoints(mat=i,length=leng)
           en2s,contcs=run_job(mat=i,incar=incar,kpoints=kpoints,jobname=str('Surf_en-')+str(i.comment)+str('-')+str(mat_f.comment))  
           #kpoints=mpvis.get_kpoints(mat_f.structure)
           #en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment))  
         except:
           pass
    os.chdir(cwd)
    if def_en==True:
       incar_dict = use_incar_dict
       incar_dict.update({"ENCUT":encut,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11})
       incar = Incar.from_dict(incar_dict)
       #surf=surfer(mat=mat_f.structure,layers=3)
       vac=vac_antisite_def_struct_gen(cellmax=3,struct=mat_f.structure)
       for i in vac:
         try: 
           print ("running MAIN-vac")
           kpoints=Auto_Kpoints(mat=i,length=leng)
           en2d,contcd=run_job(mat=i,incar=incar,kpoints=kpoints,jobname=str('Def_en-')+str(i.comment)+str('-')+str(mat_f.comment))  
          # kpoints=mpvis.get_kpoints(mat_f.structure)
          # en2B,contcB=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-BAND')+str('-')+str(mat_f.comment))  
         except:
           pass
    os.chdir(cwd)
    #surf=surfer(mat=strt,layers=layers)
    #surf=surfer(mat=strt,layers=layers)
    if spin_orb==True:
       #chg_file=str(contc).replace('CONTCAR','CHGCAR')
       #print ('chrfile',chg_file)
       #shutil.copy2(chg_file,'./')
       incar_dict = use_incar_dict
       incar_dict.update({"ENCUT":encut,"NPAR":ncores,"GGA_COMPAT":'.FALSE.',"LSORBIT":'.TRUE.',"IBRION":1,"ISYM":0,"NEDOS":5000,"IBRION":1,"NSW":500,"LORBIT":11})
       incar = Incar.from_dict(incar_dict)
       sg_mat = SpacegroupAnalyzer(mat_f.structure)
       mat_cvn = sg_mat.get_conventional_standard_structure()
       mat_cvn.sort()
       kpoints=Auto_Kpoints(mat=Poscar(mat_cvn),length=leng/2)
       try:
          en2S,contcS=run_job(mat=Poscar(mat_cvn),incar=incar,kpoints=kpoints,jobname=str('MAIN-SOC')+str('-')+str(mat_f.comment)) 
       except:
           pass 
    os.chdir(cwd)
    if optical_prop==True:
       incar_dict = use_incar_dict
       incar_dict.update({"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":3*int(nbands),"LOPTICS":'.TRUE.'})
       incar = Incar.from_dict(incar_dict)
       kpoints=Auto_Kpoints(mat=mat_f,length=leng)
       try:
           en2OP,contcOP=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-OPTICS')+str('-')+str(mat_f.comment)) 
       except:
           pass 
    os.chdir(cwd)
    if mbj_prop==True:
       incar_dict = use_incar_dict
       incar_dict.update({"NEDOS":5000,"LORBIT":11,"IBRION":1,"ENCUT":encut,"NBANDS":3*int(nbands),"LOPTICS":'.TRUE.','METAGGA':'MBJ','ISYM':0,"SIGMA":0.1})
       incar = Incar.from_dict(incar_dict)
       kpoints=Auto_Kpoints(mat=mat_f,length=leng)
       try:
           en2OP,contcOP=run_job(mat=mat_f,incar=incar,kpoints=kpoints,jobname=str('MAIN-MBJ')+str('-')+str(mat_f.comment))
       except:
           pass
    os.chdir(cwd)

    if elast_prop==True:
       incar_dict = use_incar_dict
       incar_dict.update({"NEDOS":5000,"IBRION":6,"ENCUT":1.3*float(encut),"ISIF":3,"POTIM":0.015,"NPAR":ncores,"ISPIN":2})
       incar = Incar.from_dict(incar_dict)
       sg_mat = SpacegroupAnalyzer(mat_f.structure)
       mat_cvn = sg_mat.get_conventional_standard_structure()
       mat_cvn.sort()
       kpoints=Auto_Kpoints(mat=Poscar(mat_cvn),length=leng)
       try:
          en2E,contcE=run_job(mat=Poscar(mat_cvn),incar=incar,kpoints=kpoints,jobname=str('MAIN-ELASTIC')+str('-')+str(mat_f.comment)) 
       except:
           pass 
    os.chdir(cwd)


    if phonon==True:
       incar_dict = use_incar_dict
       incar_dict.update({"IBRION":8,"ENCUT":float(encut),"ISYM":0,"ADDGRID":'.TRUE.','EDIFF': 1e-09,'LORBIT': 11})
       incar = Incar.from_dict(incar_dict)
       kpoints=Auto_Kpoints(mat=mat_f,length=leng)
       mat_pho=make_big(poscar=mat_f,size=11.0)
       try:
          en2P,contcP=run_job(mat=mat_pho,incar=incar,kpoints=kpoints,jobname=str('MAIN-PHO8')+str('-')+str(mat_f.comment)) 
       except:
           pass 
    os.chdir(cwd)


    #if Raman_calc==True:
    #    Raman(strt=mat_f,encut=encut,length=leng)
    os.chdir(cwd)
    return en2,mat_f
Exemplo n.º 17
0
dim1 = int((float(c_size) / float(max(abs(mat_cvn.lattice.matrix[0]))))) + 1
dim2 = int(float(c_size) / float(max(abs(mat_cvn.lattice.matrix[1])))) + 1
dim3 = int(float(c_size) / float(max(abs(mat_cvn.lattice.matrix[2])))) + 1
p.make_supercell([dim1, dim2, dim3])
write_lammps_data(p, file='dat.dat')  #can be visulaized using Ovito
"""
Step-2: writing LAMMPS input file
Adjust parameters according to LAMMPS executable, force-field file, main input file that you'll be using, pair style and atom style
"""
parameters = {
    'exec': 'mpirun /cluster/bin/lmp_ctcms-14439-knc6 <in.elastic >out',
    'pair_coeff':
    '/users/knc6/Software/jarvis/jarvis/lammps/examples/Mishin-Ni-Al-2009.eam.alloy',
    'control_file': '/users/knc6/inelast.mod',
    'pair_style': 'eam/alloy',
    'atom_style': 'charge',
    'cluster': 'pbs'
}
write_lammps_in(structure=p,
                lammps_in="init.mod",
                lammps_in1="potential.mod",
                lammps_in2="in.elastic",
                parameters=parameters)
"""
Step-3
If you survive the above two steps, lets submit job to computer-cluster
"""
pos = Poscar(p)
pos.comment = 'bulk@Al'
main_func(mat=pos, parameters=parameters)
Exemplo n.º 18
0
def step2():
    """
    read in the realxed bulk substrates and relaxed 2d,
    create substrate slab,
    get aligned substrates and 2d,
    relax the aligned structures seperatly(only ionic positions, ISIF=2)

    - input from step1_sub.json and step1_2d.json
    - 8(pairs) * 2 = 16 jobs
    - returns step2.json
    """
    nlayers_2d = 1
    nlayers_sub = 2
    hkl_sub = [1,1,1]
    min_thick = 10.0
    min_vac = 18.0
    hkl_2d = [0,0,1]
    #job directory for the runs
    job_dir_sub = 'step2_sub'
    job_dir_2d = 'step2_2d'
    # isif = 2
    incar_sub['ISIF'] = 2
    incar_2d['ISIF'] = 2
    # kpoints
    kpoints_sub = Kpoints.monkhorst_automatic(kpts=(18, 18, 1))
    kpoints_2d = Kpoints.monkhorst_automatic(kpts=(18, 18, 1))    
    # CSL settings for each substrate
    alignment_settings = { 'Pt': [120, 0.10, 1, 0.5],
                        'Ag': [120, 0.10, 1, 0.5],
                        'Al': [120, 0.10, 1, 0.5],
                        'Au': [120, 0.10, 1, 0.5],
                        'Pd': [120, 0.10, 1, 0.5],
                        'Ir': [120, 0.10, 1, 0.5],
                        'Cu': [50, 0.06, 1, 0.5],
                        'Ni': [50, 0.06, 1, 0.5] }
    # load in previous jobs
    relaxed_sub_jobs = Calibrate.jobs_from_file('step1_sub.json')
    relaxed_2d_jobs = Calibrate.jobs_from_file('step1_2d.json')
    poscars_sub = []
    poscars_2d = []
    # create list of all aligned substrate and 2d slabs
    for jsub in relaxed_sub_jobs:
        jdir = os.path.join(jsub.parent_job_dir, jsub.job_dir)
        contcar_file = os.path.join(jdir, 'CONTCAR')
        relaxed_struct_sub = Structure.from_file(contcar_file)
        # create slab
        slab_sub = Interface(relaxed_struct_sub,  hkl = hkl_sub,
                             min_thick = min_thick, min_vac = min_vac,
                             primitive = False, from_ase = True)
        species_sub = ''.join([tos.symbol for tos in slab_sub.types_of_specie])
        # loop over 2d
        for j2d in relaxed_2d_jobs:    
            jdir = os.path.join(j2d.parent_job_dir, j2d.job_dir)
            contcar_file = os.path.join(jdir, 'CONTCAR')
            slab_2d = slab_from_file(hkl_2d, contcar_file)
            species_2d = ''.join([tos.symbol for tos in slab_2d.types_of_specie])
            # align
            slab_sub_aligned, slab_2d_aligned = get_aligned_lattices(
                slab_sub,
                slab_2d,
                *alignment_settings[species_sub])
            # aligned sub poscar
            sd_flags = CalibrateSlab.set_sd_flags(interface=slab_sub_aligned,
                                                  n_layers=nlayers_sub)
            poscar = Poscar(slab_sub_aligned, selective_dynamics=sd_flags)
            poscar.comment = '_'.join([species_sub,species_2d,'sub'])            
            poscars_sub.append(poscar)
            # aligned 2d slab
            sd_flags = CalibrateSlab.set_sd_flags(interface=slab_2d_aligned,
                                                  n_layers=nlayers_2d)
            poscar = Poscar(slab_2d_aligned, selective_dynamics=sd_flags)
            poscar.comment = '_'.join([species_sub,species_2d,'2d'])
            poscars_2d.append(poscar)
    # setup calibrate and run'em
    turn_knobs_sub = OrderedDict(
        [
            ('POSCAR', poscars_sub)
        ])
    turn_knobs_2d = OrderedDict(
        [
            ('POSCAR', poscars_2d)
        ])
    qadapter, job_cmd = get_run_cmmnd(nnodes=nnodes, nprocs=nprocs,
                                            walltime=walltime,
                                            job_bin=bin_sub, mem=mem)
    run_cal(turn_knobs_sub, qadapter, job_cmd, job_dir_sub,
            'step2_sub', incar=incar_sub, kpoints=kpoints_sub)
    run_cal(turn_knobs_2d, qadapter, job_cmd, job_dir_2d,
            'step2_2d', incar=incar_2d, kpoints=kpoints_2d)
    return ['step2_sub.json', 'step2_2d.json']
Exemplo n.º 19
0
from jarvis.vasp.joptb88vdw import smart_converge
from pymatgen.io.vasp.inputs import Poscar
from pymatgen.core.structure import Structure

import os, time

s = Structure.from_file("POSCAR")
p = Poscar(s)
p.comment = "bulk@ATAT"
en, final = smart_converge(mat=p, elast_prop=False)
print("en,finel", en, final)
Exemplo n.º 20
0
def step3():
    """
    put aligned & relaxed 2d materials in all possible ways on the
    aligned & relaxed slab,
    relax interface ionic positions(ISIF=2)

    - uses info from step2_sub.json and step2_2d.json
    - creates required input files and submits the jobs to the que
    - 8(pairs) * 2(atoms in graphene basis) = 16 jobs
    - returns: step3.json     
    """
    seperation = 3 # in angstroms
    nlayers_2d = 1
    nlayers_sub = 2
    hkl_sub = [1,1,1]
    hkl_2d = [0,0,1]
    #job directory for the runs
    name = 'step3'    
    job_dir = 'step3'
    # incar
    incar = Incar.from_dict(incar_dict)
    incar['ISMEAR'] = 1
    incar['ISIF'] = 2
    # kpoints
    kpoints = Kpoints.monkhorst_automatic(kpts=(18, 18, 1))
    # load in previous jobs
    relaxed_sub_jobs = Calibrate.jobs_from_file('step2_sub.json')
    relaxed_2d_jobs = Calibrate.jobs_from_file('step2_2d.json')
    # create list of all substrate poscars
    all_poscars = []
    # loop over aligned & relaxed substrates and 2d
    for jsub, j2d in zip(relaxed_sub_jobs,relaxed_2d_jobs):
        # substrate
        job_dir_sub = os.path.join(jsub.parent_job_dir, jsub.job_dir)
        contcar_file = os.path.join(job_dir_sub, 'CONTCAR')
        # read in as structure object
        substrate_slab_aligned = Structure.from_file(contcar_file)
        species_sub = ''.join([tos.symbol for tos in substrate_slab_aligned.types_of_specie])
        # 2d
        job_dir_2d = os.path.join(j2d.parent_job_dir, j2d.job_dir)
        contcar_file = os.path.join(job_dir_2d, 'CONTCAR')
        # read in as structure object        
        mat2d_slab_aligned = Structure.from_file(contcar_file)
        species_2d = ''.join([tos.symbol for tos in mat2d_slab_aligned.types_of_specie])
        # position the aligned materials in all possible ways
        hetero_interfaces = generate_all_configs(mat2d_slab_aligned,
                                                 substrate_slab_aligned,
                                                 nlayers_2d,
                                                 nlayers_sub,
                                                 seperation )
        # loop over all hetero-interfaces
        for i, iface in enumerate(hetero_interfaces):
            sd_flags = CalibrateSlab.set_sd_flags(interface=iface,
                                                  n_layers=nlayers_2d+nlayers_sub,
                                                  top=True, bottom=False)
            poscar = Poscar(iface, selective_dynamics=sd_flags)
            poscar.comment = '_'.join([species_sub,species_2d,str(i)])
            all_poscars.append(poscar)
    # setup calibrate and run'em
    turn_knobs = OrderedDict(
        [
            ('POSCAR', all_poscars)
        ])
    qadapter, job_cmd = get_run_cmmnd(nnodes=nnodes, nprocs=nprocs,
                                      walltime=walltime,
                                      job_bin=bin_sub, mem=mem)
    run_cal(turn_knobs, qadapter, job_cmd, job_dir,
            name, incar=incar, kpoints=kpoints)
    return [name+'.json']