Esempio n. 1
0
def main(api="", queryid=""):
    """Get VASP inputs for Materials Project structure
        Args:
            api <str>: Materials Project API key
            queryid <str>: Materials Project ID of the structure
        Returns:
            creates a folder named with that mpid, and including
            some VASP input files.
    """
    if api == "":
        print "Must have an API key from materialsproject.org"
        return None
    if queryid == "":
        print "No MP structure ID given. Exiting."
        return None
    rest_adapter = MPRester(api)
    entries=list()
    proplist=list()
    proplist.append('pretty_formula')
    proplist.append('structure')
    proplist.append('potcar')
    proplist.append('material_id')
    
    myentry = rest_adapter.mpquery(criteria={'material_id':queryid}, properties=proplist)
    if len(myentry) == 0:
        print "Could not find entry for %s as material_id. Trying entry_id." % queryid
        myentry = rest_adapter.mpquery(criteria={'entry_id':queryid}, properties=proplist)
    if len(myentry) == 0:
        print "Could not find entry for %s" % queryid
        return None
    entries.extend(myentry)

    workdir = os.getcwd()
    from pymatgen.io.vaspio_set import MITVaspInputSet, MPVaspInputSet
    for entry in entries: 
        mpvis = MPVaspInputSet()
        myname = str(entry['pretty_formula'])
        #print entry['structure'].composition
        #print entry['structure'].formula
        #myname = entry['pretty_formula']
        myname = myname.replace("(","_").replace(")","_")
        myname = myname + "_" + entry['material_id']
        os.mkdir(myname)
        os.chdir(myname)
        mystructure = entry['structure']
        if mystructure.num_sites <= 10:
            mystructure.make_supercell([2,2,2])
        #mystructure.perturb(0.01)
        incar = mpvis.get_incar(mystructure)
        incar.write_file("INCAR")
        potcar = mpvis.get_potcar(mystructure)
        potcar.write_file("POTCAR")
        #potcar_symbols = mpvis.get_potcar_symbols(mystructure) 
        myposcar=Poscar(mystructure)
        mykpoints=mpvis.get_kpoints(mystructure)
        mykpoints.write_file("KPOINTS")


        myposcar.write_file("POSCAR")
        os.chdir(workdir)
Esempio n. 2
0
    def __init__(self,save_old_file=False):

        # read in what is there
        json_filename = 'run_data.json'

        try:
            with open(json_filename,'r') as f:
                data =json.load(f)
        except:
            print("CANNOT FIND run_data.json: CLASS MUST BE CALLED IN DIRECTORY WHERE FILE IS")
            return

        last_step = data['relaxation'][-1]

        structure = pymatgen.Structure.from_dict(last_step['structure'])
        composition = structure.composition
        energy = last_step['electronic']['e_0_energy']

        set = MPVaspInputSet()
        incar = set.get_incar(structure)
        poscar = set.get_poscar(structure)
        potcar = set.get_potcar(structure)

        parameters = self.parse_pseudo_inputs(poscar,incar,potcar)

        entry = pymatgen.entries.computed_entries.ComputedEntry(composition, energy, parameters=parameters )

        data['ComputedEntry'] = entry

        if save_old_file:
            shutil.move('run_data.json','run_data_OLD.json')

        pmg_dump(data, 'run_data.json')

        return
Esempio n. 3
0
    def __init__(self, save_old_file=False):

        # read in what is there
        json_filename = 'run_data.json'

        try:
            with open(json_filename, 'r') as f:
                data = json.load(f)
        except:
            print(
                "CANNOT FIND run_data.json: CLASS MUST BE CALLED IN DIRECTORY WHERE FILE IS"
            )
            return

        last_step = data['relaxation'][-1]

        structure = pymatgen.Structure.from_dict(last_step['structure'])
        composition = structure.composition
        energy = last_step['electronic']['e_0_energy']

        set = MPVaspInputSet()
        incar = set.get_incar(structure)
        poscar = set.get_poscar(structure)
        potcar = set.get_potcar(structure)

        parameters = self.parse_pseudo_inputs(poscar, incar, potcar)

        entry = pymatgen.entries.computed_entries.ComputedEntry(
            composition, energy, parameters=parameters)

        data['ComputedEntry'] = entry

        if save_old_file:
            shutil.move('run_data.json', 'run_data_OLD.json')

        pmg_dump(data, 'run_data.json')

        return
Esempio n. 4
0
def get_MaterialsProject_VASP_inputs(structure, workdir, job_name, nproc=16, supplementary_incar_dict=None):

    if os.path.exists(workdir):
        print 'WORKDIR ALREADY EXISTS. DELETE TO LAUNCH NEW JOB'
        return -1

    os.mkdir(workdir)

    input_set = MPVaspInputSet()
   
    incar  = input_set.get_incar(structure)


    # set the number of parallel processors to sqrt(nproc), 
    # as recommended in manual.
    incar.update({'NPAR':int(np.sqrt(nproc))}) 

    if supplementary_incar_dict != None:
        incar.update(supplementary_incar_dict) 

    poscar = input_set.get_poscar(structure)
    kpoints = input_set.get_kpoints(structure)
    potcar = input_set.get_potcar(structure)

    incar.write_file(workdir+'INCAR')
    poscar.write_file(workdir+'POSCAR', vasp4_compatible = True)
    kpoints.write_file(workdir+'KPOINTS')
    potcar.write_file(workdir+'POTCAR')


    with open(workdir+'job.sh','w') as f:
        f.write(submit_template.format(job_name,nproc))

    with open(workdir+'clean.sh','w') as f:
        f.write(clean_template)

    return 0
Esempio n. 5
0
def get_ModifiedMaterialsProject_VASP_inputs(structure, workdir, job_name, nproc=16, 
                                U_strategy_instance = None, supplementary_incar_dict = None):
    """
    Inputs will be inspired by MaterialsProject, but this function is appropriate
    when we are seriously modifying the inputs such that they no longer conform to Materials Project.
    """

    if os.path.exists(workdir):
        print 'WORKDIR ALREADY EXISTS. DELETE TO LAUNCH NEW JOB'
        return -1

    os.mkdir(workdir)

    # let's start with MP
    input_set = MPVaspInputSet()
   
    incar  = input_set.get_incar(structure)

    if U_strategy_instance != None:
        #  reading the structure here insures consistency, rather
        #  than having the strategy read the structure outside this driver.
        U_strategy_instance.read_structure(structure)

        # Generate all LDAU-related variables according to specified strategy.
        LDAU_dict, poscar_need_hack, potcar_need_hack = U_strategy_instance.get_LDAU()

        incar.update(LDAU_dict) 

    # set the number of parallel processors to sqrt(nproc), 
    # as recommended in manual.
    incar.update({'NPAR':int(np.sqrt(nproc))}) 

    if supplementary_incar_dict != None:
        incar.update(supplementary_incar_dict) 

    poscar = input_set.get_poscar(structure)

    kpoints = input_set.get_kpoints(structure)
    potcar = input_set.get_potcar(structure)

    incar.write_file(workdir+'INCAR')
    poscar.write_file(workdir+'POSCAR', vasp4_compatible = True)
    kpoints.write_file(workdir+'KPOINTS')
    potcar.write_file(workdir+'POTCAR')


    if poscar_need_hack:
        # do we need specialized hacking of the poscar because of the U strategy?       
        new_poscar_lines = U_strategy_instance.get_new_poscar_lines()
        with open(workdir+'POSCAR','w') as f:
            for line in new_poscar_lines:
                print >>f, line.strip()

    if potcar_need_hack:
        # do we need specialized hacking of the potcar because of the U strategy?       
        new_potcar_symbols = U_strategy_instance.get_new_potcar_symbols(potcar)
        new_potcar = Potcar(new_potcar_symbols) 
        # overwrite the previous potcar
        new_potcar.write_file(workdir+'POTCAR')

    with open(workdir+'job.sh','w') as f:
        f.write(submit_template.format(job_name,nproc))

    with open(workdir+'clean.sh','w') as f:
        f.write(clean_template)

    return 0
Esempio n. 6
0
for line in id_expgap:
    words=line.split()
    print words
    id_line=words[0]
    os.mkdir(id_line)
    os.chdir(id_line)
    s = mpr.get_structure_by_material_id(id_line)
    # obtain structural information from Materials Project database
    #print json.dumps(s.to_dict)
    # convert structural infomation into a dictionary and then dump to a json file

    user_incar_settings={"ALGO":'Normal',"EDIFF":1E-8,"ENCUT":500,"NSW":0,"LWAVE":True}
    mpvis = MPVaspInputSet(user_incar_settings=user_incar_settings)

    mpvis.get_incar(s).write_file('INCAR')
    # from the GW input set, get the incar parameters, generate INCAR
    print mpvis.get_incar(s)
    #
    kp_density = mpvis.get_kpoints(s).kpts[0]
    # from the GW input set, get the k-point density
    kpoints = Kpoints.gamma_automatic(kp_density)
    # generate Gamma centered k-point mesh
    kpoints.write_file('KPOINTS')
    # generate KPOINTS file
    mpvis.get_poscar(s).write_file('POSCAR')
    # generate POSCAR file
    mpvis.get_potcar(s).write_file('POTCAR')
    # generate POTCAR file
    os.chdir('..')
id_expgap.close()
Esempio n. 7
0
def main(api="", queryid=""):
    """Get VASP inputs for Materials Project structure
        Args:
            api <str>: Materials Project API key
            queryid <str>: Materials Project ID of the structure
        Returns:
            creates a folder named with that mpid, and including
            some VASP input files.
    """
    if api == "":
        print "Must have an API key from materialsproject.org"
        return None
    if queryid == "":
        print "No MP structure ID given. Exiting."
        return None
    rest_adapter = MPRester(api)
    entries = list()
    proplist = list()
    proplist.append('pretty_formula')
    proplist.append('structure')
    proplist.append('potcar')
    proplist.append('material_id')

    myentry = rest_adapter.mpquery(criteria={'material_id': queryid},
                                   properties=proplist)
    if len(myentry) == 0:
        print "Could not find entry for %s as material_id. Trying entry_id." % queryid
        myentry = rest_adapter.mpquery(criteria={'entry_id': queryid},
                                       properties=proplist)
    if len(myentry) == 0:
        print "Could not find entry for %s" % queryid
        return None
    entries.extend(myentry)

    workdir = os.getcwd()
    from pymatgen.io.vaspio_set import MITVaspInputSet, MPVaspInputSet
    for entry in entries:
        mpvis = MPVaspInputSet()
        myname = str(entry['pretty_formula'])
        #print entry['structure'].composition
        #print entry['structure'].formula
        #myname = entry['pretty_formula']
        myname = myname.replace("(", "_").replace(")", "_")
        myname = myname + "_" + entry['material_id']
        os.mkdir(myname)
        os.chdir(myname)
        mystructure = entry['structure']
        if mystructure.num_sites <= 10:
            mystructure.make_supercell([2, 2, 2])
        #mystructure.perturb(0.01)
        incar = mpvis.get_incar(mystructure)
        incar.write_file("INCAR")
        potcar = mpvis.get_potcar(mystructure)
        potcar.write_file("POTCAR")
        #potcar_symbols = mpvis.get_potcar_symbols(mystructure)
        myposcar = Poscar(mystructure)
        mykpoints = mpvis.get_kpoints(mystructure)
        mykpoints.write_file("KPOINTS")

        myposcar.write_file("POSCAR")
        os.chdir(workdir)