def get_potcar(self, potcar_symbols=None, potcar_functional='PBE'): """ Get Pymatgen Potcar object. The PMG_VASP_PSP directory has to be defined in .pmgrc.yaml file as required by Pymatgen. Parameters ---------- potcar_symbols : List, optional List of strings with symbols of POTCARs. The default is None. If None the default symbols from the Materials Project \n database are used for every specie in the given Structure object. potcar_functional : (str), optional Functional to be used, as defined by Pymatgen Potcar class. The default is 'PBE'. Returns ------- Pymatgen Potcar object. """ if potcar_symbols: potcar = Potcar(symbols=potcar_symbols, functional=potcar_functional) self.potcar_symbols = potcar_symbols else: if self.structure: potcar_symbols = self.potcar_symbols else: raise ValueError( 'potcar symbols or Structure object need to be given to get Potcar onject' ) potcar = Potcar(symbols=potcar_symbols, functional=potcar_functional) return potcar
def test_default_functional(self): p = Potcar(["Fe", "P"]) self.assertEqual(p[0].functional_class, 'GGA') self.assertEqual(p[1].functional_class, 'GGA') SETTINGS["PMG_DEFAULT_FUNCTIONAL"] = "LDA" p = Potcar(["Fe", "P"]) self.assertEqual(p[0].functional_class, 'LDA') self.assertEqual(p[1].functional_class, 'LDA')
def get_potcar(self, structure): """ Method for getting LDA potcars """ if self.sort_structure: structure = structure.get_sorted_structure() return Potcar(self.get_potcar_symbols(structure), functional=self.functional)
def convert_computed_entry_to_job(self,entry): """ Convert ComputedStructureEntry into VaspJob object Parameters ---------- entry : ComputedStructureEntry. Returns ------- vaspjob : VaspJob object. """ e = entry path = e.data['dir_name'] inp = e.data['calculations'][0]['input'] incar = Incar(inp['incar']) kpoints = Kpoints.from_dict(inp['kpoints']) poscar = Poscar(e.structure) potcar = Potcar(inp['potcar']) inputs = VaspInput(incar, kpoints, poscar, potcar) job_settings = e.data['job_settings'] job_script_filename = e.data['job_script_filename'] name = e.data['job_name'] outputs = {'ComputedStructureEntry':e} vaspjob = VaspJob(path,inputs,job_settings,outputs,job_script_filename,name) vaspjob._is_converged = e.data['is_converged'] vaspjob._band_structure = None return vaspjob
def update_pot_by_symbols(InputSet, write_file=True): """ Update POTCAR by symbols considering the MAGMOM difference Parameter --------- InputSet: VaspInputSet The input set defined by pymatgen, e.g. MPRelaxSet write_file: bool Write POSCAR (True) or not (False) Return ------ potcar: Potcar (in pymatgen) The Potcar type defined in pymatgen """ symbol, natom = check_symbol(InputSet) potcar_symbols = [] settings = InputSet._config_dict["POTCAR"] if isinstance(settings[symbol[-1]], dict): for el in symbol: potcar_symbols.append(settings[el]["symbol"] if el in settings else el) else: for el in symbol: potcar_symbols.append(settings.get(el, el)) potcar = Potcar(symbols=potcar_symbols, functional=InputSet.potcar_functional) if write_file: potcar.write_file(filename="POTCAR") return potcar
def test_potcar_map(self): fe_potcar = zopen(PymatgenTest.TEST_FILES_DIR / "POT_GGA_PAW_PBE" / "POTCAR.Fe_pv.gz").read().decode("utf-8") # specify V instead of Fe - this makes sure the test won't pass if the # code just grabs the POTCAR from the config file (the config file would # grab the V POTCAR) potcar = Potcar(["V"], sym_potcar_map={"V": fe_potcar}) self.assertEqual(potcar.symbols, ["Fe_pv"], "Wrong symbols read in " "for POTCAR")
def write_potcar(self): # NEED check if correct # TODO: # Every time when changing running environment, need uncomment the following two lines # os.system('pmg config --add PMG_VASP_PSP_DIR G:/pseudo-potential/') potcar_file_name = os.path.join(self._save_to_path, 'POTCAR') # Vasp functional set as potpaw_GGA Potcar(symbols=self.elements, functional='PW91').write_file(potcar_file_name)
def generate_files(args): from pymatgen.io.vasp.inputs import Potcar if args.symbols: try: p = Potcar(args.symbols, functional=args.functional) p.write_file("POTCAR") except Exception as ex: print("An error has occurred: {}".format(str(ex))) else: print("No valid options selected.")
def __init__(self, species=None, functionals=None): if species and functionals: self._potcar = Potcar(species, functionals) self._species = species self._functionals = functionals else: self._potcar = None self._species = None self._functionals = None self._file_path = None
def generate_potcar(struct,dirname='.'): avail_pot =" ".join(Potcar.FUNCTIONAL_CHOICES) tip=""" Available Pseudo-potentials are: """ tip+=avail_pot+'\n' warn_tip(1,tip) print('your choice ?') wait_sep() in_str="" while in_str=="": in_str=input().strip() assert in_str.upper() in avail_pot potcar=Potcar([el.value for el in struct.types_of_specie],functional=in_str) potcar.write_file(os.path.join(dirname, "POTCAR"))
def generate_potcar(struct, dirname='.'): """ Generate POTCAR according to input structure via pymatgen's POTCAR module """ avail_pot = " ".join(Potcar.FUNCTIONAL_CHOICES) tip = """ Available Pseudo-potentials are: """ tip += avail_pot + '\n' warn_tip(1, tip) print('your choice ?') wait_sep() in_str = wait() assert in_str.upper() in avail_pot potcar = Potcar([el.value for el in struct.types_of_specie], functional=in_str) potcar.write_file(os.path.join(dirname, "POTCAR"))
def set_potcar(self, mapping=None, functional='PBE'): """ set the potcar: symbol to potcar type mapping """ symbols = self.poscar.site_symbols mapped_symbols = [] if mapping: for sym in symbols: mapped_symbols.append(mapping[sym]) elif self.mappings_override: for sym in symbols: if sym in self.mappings_override.keys(): mapped_symbols.append(self.mappings_override[sym]) else: mapped_symbols.append(sym) else: mapped_symbols = symbols if functional: func = functional else: func = self.functional self.potcar = Potcar(symbols=mapped_symbols, functional=func)
def potcar_from_linklist(cls, poscar_data, linklist): """ Assemble pymatgen Potcar object from a list of VaspPotcarData instances Reads pseudo-potential from the passed list connecting each element with it's potential and creates the complete Potcar file according to the element ordering fodun in the passed poscar data object. :param poscar_data: input structure for VASP calculations :type poscar: :class:`aiida_cusp.data.inputs.VaspPoscarData` :param linklist: dictionary mapping element names to VaspPotcarData instances :type linklist: `dict` :returns: pymatgen Potcar data instance with containing the concatenated pseudo-potential information for all elements defined in the linklist :rtype: :class:`~pymatgen.io.vasp.inputs.Potcar` """ # initialize empty Potcar object complete_potcar = Potcar() # file empty potcar with potential in order of elements found in the # passed structure data site_symbols = poscar_data.get_poscar().site_symbols for site_symbol in site_symbols: try: potential_pointer = linklist[site_symbol] except KeyError: raise VaspPotcarDataError( "Found no potential in passed " "potential-element map for " "site symbol '{}'".format(site_symbol)) potential_file = potential_pointer.load_potential_file_node() potential_contents = potential_file.get_content() potcar_single = PotcarSingle(potential_contents) complete_potcar.append(potcar_single) return complete_potcar
def test_init(self): self.assertEqual(self.potcar.symbols, ["Fe", "P", "O"], "Wrong symbols read in for POTCAR") potcar = Potcar(["Fe_pv", "O"]) self.assertEqual(potcar[0].enmax, 293.238)
INCAR['LDAUL'].append(-1) INCAR['LDAUU'].append(0.0) INCAR['LDAUJ'].append(0.0) LDAUL_dic = dict(zip(elements, INCAR['LDAUL'])) LDAUU_dic = dict(zip(elements, INCAR['LDAUU'])) LDAUJ_dic = dict(zip(elements, INCAR['LDAUJ'])) INCAR['LDAUL'] = [LDAUL_dic[x] for x in sorted(elements)] INCAR['LDAUU'] = [LDAUU_dic[x] for x in sorted(elements)] INCAR['LDAUJ'] = [LDAUJ_dic[x] for x in sorted(elements)] f.writelines('\tLDAUL: %s\t LDAUU: %s\tLDAUJ: %s\n' % (INCAR['LDAUL'], INCAR['LDAUU'], INCAR['LDAUJ'])) potcar_symbols.append('H') potcar_symbols.sort() POTCAR = Potcar(potcar_symbols) f.writelines(['\tPOTCAR_symbols: ',str(potcar_symbols), '\n']) potcar_symbols.remove('H') else: f.writelines('\tLDAUL: %s\t LDAUU: %s\tLDAUJ: %s\n' % (INCAR['LDAUL'], INCAR['LDAUU'], INCAR['LDAUJ'])) POTCAR = Potcar(potcar_symbols) f.writelines(['\tPOTCAR_symbols: ',str(potcar_symbols), '\n']) view(slab_sorted) write_vasp(file_path + '%s/POSCAR' % (adsorbate_names[ads_idx]), slab_sorted) # Put AFM, def in the path if requried INCAR.write_file(file_path + '%s/INCAR' % (adsorbate_names[ads_idx])) # Put AFM, def in the path if requried KPOINTS.write_file(file_path + '%s/KPOINTS' % (adsorbate_names[ads_idx])) # Put AFM, def in the path if requried POTCAR.write_file(file_path + '%s/POTCAR' % (adsorbate_names[ads_idx])) # Put AFM, def in the path if requried
# POSCAR poscar = Poscar(struct) poscar_dict = poscar.as_dict() # KPOINTS k = 7 kpoints = Kpoints.gamma_automatic(kpts=(k, k, k), shift=(0.0, 0.0, 0.0)) # get POTCAR with right order from POSCAR # check for prevoius element - if it's the same don't write it twice prevoius_el = None # initializing potcar_symbols potcar_symbols = [] #getting sites list sites = poscar_dict['structure']['sites'] # getting label for element on site for site_index in range(0, len(sites)): el = sites[site_index]['label'] # write only if it is different from the prevoious one if prevoius_el != el: potcar_symbols.append(potcar_choices[el]) prevoius_el = el # set Potcar object potcar = Potcar(symbols=potcar_symbols, functional='PBE', sym_potcar_map=None) VASP_input = VaspInput(incar, kpoints, poscar, potcar) VASP_input.write_input(file_dir, make_dir_if_not_present=True)
from pymatgen.io.vasp.inputs import Incar, Poscar from pymatgen.io.vasp.inputs import Potcar import yaml import os os.environ["VASP_PSP_DIR"] = "/home/knc6/Software/VASP-POTENTIAL" with open('/home/knc6/bin/Special_POTCAR.yaml', 'r') as f: doc = yaml.load(f) pots = doc['POTCAR'] mat = Poscar.from_file('POSCAR') new_symb = [] for el in mat.site_symbols: new_symb.append(pots[el]) potcar = Potcar(symbols=new_symb, functional="PBE") potcar.write_file("POTCAR")
charge_states_dict = { 'Na': [-1, 0, 1], 'Nb': [-5, -4, -3, -2, -1, 0], 'O': [-2, -1, -0, 1, 2] } potcar_symbols = ['Na', 'Nb_pv', 'O'] ########################################################################### structure = Poscar.from_file('POSCAR_unit').structure default_inputs = DefaultInputs(structure) incar_settings = default_inputs.get_incar_default(xc='HSE06', aexx=0.25) kpoints = Kpoints.gamma_automatic(kpts=(2, 2, 2)) if potcar_symbols: potcar = Potcar(potcar_symbols, functional='PBE') else: potcar = default_inputs.get_potcar(potcar_symbols=None, potcar_functional='PBE') val = {} for p in potcar: val[p.element] = p.nelectrons supercell_size = 3 structure_pure = structure.copy() for el in charge_states_dict: structure = structure_pure.copy() interstitial_supercells = create_interstitial_supercells( structure, el, size=supercell_size)
def from_file(self, file_path): #add exception handeling self._file_path = file_path self._potcar = Potcar().from_file(file_path) self._species = self._potcar.symbols self._functionals = self._potcar.FUNCTIONAL_CHOICES
def run_job(mat=None,incar=None,kpoints=None,jobname='',copy_file=[]): """ Generic function to run a VASP job, error correction implemented using custodian package A jobname+.json file is produced after successful completion of the job A first_cust.py file is generated which is invoked using python command Args: mat: Poscar object with structure information incar: Incar object with control information kpoints: Kpoints object with mesh information jobname: a uniq name for a job-type, say MAIN-ELAST for elastic properties copy_file: copy file from previous runs, say CHGCAR for Non-SCF bandstructure calculations Returns: f_energy: final energy contcar: path to final relaxed structure """ #hostname=str(socket.gethostname()) poscar_list=[(mat)] cwd=str(os.getcwd()) job_name=str(mat.comment) job_dir=str(jobname) run_file = str(os.getcwd())+str('/')+str(jobname)+str('.json') run_dir = str(os.getcwd())+str('/')+str(jobname) if mat.comment.startswith('Surf'): [a,b,c]=kpoints.kpts[0] kpoints.kpts=[[a,b,1]] try: pol=check_polar(mat.structure) if pol==True: ase_atoms = AseAtomsAdaptor().get_atoms(mat.structure) COM=ase_atoms.get_center_of_mass(scaled=True) print ("COM=",COM) print ('Found polar surface, will be setting dipole corrections') incar.update({"LDIPOL": '.TRUE.',"IDIPOL":3,"ISYM": 0,"DIPOL":str(COM[0])+str(" ")+str(COM[2])+str(" ")+str(COM[2])}) print ("Polar surface encountered in run_job",mat.comment) except: pass wait=False json_file=str(jobname)+str('.json') print ('json should be here=',str(os.getcwd())+str('/')+str(json_file)) #print ('json should be=',json_file,run_file,os.getcwd()) if os.path.exists(str(os.getcwd())+str('/')+str(json_file)): try: data_cal=loadfn(str(os.getcwd())+str('/')+str(json_file),cls=MontyDecoder) tmp_outcar=str(os.getcwd())+str('/')+str(json_file.split('.json')[0])+str('/OUTCAR') print ('outcar is',tmp_outcar) wait=main_outcar(tmp_outcar) #True print ('outcar status',wait) if wait==True: f_energy=data_cal[0]['final_energy'] contcar=str(os.getcwd())+str('/')+str(json_file.split('.json')[0])+str('/CONTCAR') return f_energy,contcar except: pass while wait==False: print ("Setting up POTCAR") with open(pot_yaml, 'r') as f: doc = yaml.load(f) pots=doc['POTCAR'] new_symb=[] for el in mat.site_symbols: new_symb.append(pots[el]) #potcar = Potcar(symbols=new_symb,functional=functional) try: potcar = Potcar(symbols=new_symb,functional=functional) except: print ('JARVIS-ERROR: Could not set POTCAR, check POTCAR yaml file and VASP_PSP_DIR') pass if not os.path.exists(run_dir): print ('Starting new job') os.makedirs(run_dir) os.chdir(run_dir) incar.write_file("INCAR") potcar.write_file("POTCAR") kpoints.write_file("KPOINTS") mat.write_file("POSCAR") for i in copy_file: print ('copying',i) shutil.copy2(i,'./') #f=open('job.out','w') cmd=str('python first_cust.py >out_dat')+'\n' cust_file=open("first_cust.py","w") cline=str('from pymatgen.io.vasp.inputs import Incar, Poscar, VaspInput,Potcar, Kpoints')+'\n' cust_file.write(cline) cline=str('import os,shutil')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.jobs import VaspJob')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.handlers import VaspErrorHandler, UnconvergedErrorHandler,MeshSymmetryErrorHandler, NonConvergingErrorHandler, PotimErrorHandler')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.validators import VaspFilesValidator,VasprunXMLValidator')+'\n' cust_file.write(cline) cline=str('from custodian.custodian import Custodian')+'\n' cust_file.write(cline) cline=str('inc=Incar.from_file("INCAR")')+'\n' cust_file.write(cline) cline=str('pot=Potcar.from_file("POTCAR")')+'\n' cust_file.write(cline) cline=str('pos=Poscar.from_file("POSCAR")')+'\n' cust_file.write(cline) cline=str('kp=Kpoints.from_file("KPOINTS")')+'\n' cust_file.write(cline) cline=str("shutil.copy2('")+vdw_dat+str("','./')")+'\n' cust_file.write(cline) cline=str('vinput = VaspInput.from_directory(".")')+'\n' cust_file.write(cline) cline=str("job=VaspJob(['mpirun', '")+str(main_exe)+str("'], final=False, backup=False)")+'\n' if mat.comment.startswith('Surf'): cline=str("job=VaspJob(['mpirun', '")+str(surf_exe)+str("'], final=False, backup=False)")+'\n' if 'SOC' in jobname: cline=str("job=VaspJob(['mpirun', '")+str(soc_exe)+str("'], final=False, backup=False)")+'\n' cust_file.write(cline) cline=str('handlers = [VaspErrorHandler(), MeshSymmetryErrorHandler(),UnconvergedErrorHandler(), NonConvergingErrorHandler(),PotimErrorHandler()]')+'\n' cust_file.write(cline) cline=str('validators = [VasprunXMLValidator()]')+'\n' #cline=str('validators = [VaspFilesValidator()]')+'\n' cust_file.write(cline) cline=str('c = Custodian(handlers, [job],max_errors=5,validators=validators)')+'\n' cust_file.write(cline) cline=str('c.run()')+'\n' cust_file.write(cline) cust_file.close() print ("I AM HERE 2") os.system(cmd) if os.path.isfile('OUTCAR'): try: wait=main_outcar('OUTCAR') #Vasprun("vasprun.xml").converged except: pass print ("End of the first loop",os.getcwd(),wait) else : print ('Jobs seens to have started before') os.chdir(run_dir) wait=False if os.path.isfile('OUTCAR'): try: wait=main_outcar('OUTCAR') #Vasprun("vasprun.xml").converged #wait=Vasprun("vasprun.xml").converged except: pass print ("Tried to find OUTCAR, wait is=",wait) if wait==False: incar.write_file("INCAR") kpoints.write_file("KPOINTS") mat.write_file("POSCAR") try: potcar.write_file("POTCAR") print ('FOUND OLD CONTCAR in', os.getcwd()) old_contcar=Poscar.from_file('CONTCAR') #old_contcar.write_file('POSCAR') copy_cmd=str('cp CONTCAR POSCAR') print ('copy_cmd=',copy_cmd) if 'ELAST' not in jobname: #Because in ELASTIC calculations structures are deformed os.system(copy_cmd) #time.sleep(3) except: pass for i in copy_file: print ('copying',i) shutil.copy2(i,'./') cmd=str('python first_cust.py >out_dat')+'\n' cust_file=open("first_cust.py","w") cline=str('from pymatgen.io.vasp.inputs import Incar, Poscar, VaspInput,Potcar, Kpoints')+'\n' cust_file.write(cline) cline=str('import os,shutil')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.jobs import VaspJob')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.handlers import VaspErrorHandler, UnconvergedErrorHandler,MeshSymmetryErrorHandler, NonConvergingErrorHandler, PotimErrorHandler')+'\n' cust_file.write(cline) cline=str('from custodian.vasp.validators import VaspFilesValidator,VasprunXMLValidator')+'\n' cust_file.write(cline) cline=str('from custodian.custodian import Custodian')+'\n' cust_file.write(cline) cline=str('inc=Incar.from_file("INCAR")')+'\n' cust_file.write(cline) cline=str('pot=Potcar.from_file("POTCAR")')+'\n' cust_file.write(cline) cline=str('pos=Poscar.from_file("POSCAR")')+'\n' cust_file.write(cline) cline=str('kp=Kpoints.from_file("KPOINTS")')+'\n' cust_file.write(cline) cline=str("shutil.copy2('")+vdw_dat+str("','./')")+'\n' cust_file.write(cline) cline=str('vinput = VaspInput.from_directory(".")')+'\n' cust_file.write(cline) cline=str("job=VaspJob(['mpirun', '")+str(main_exe)+str("'], final=False, backup=False)")+'\n' if mat.comment.startswith('Surf'): cline=str("job=VaspJob(['mpirun', '")+str(surf_exe)+str("'], final=False, backup=False)")+'\n' if 'SOC' in jobname: cline=str("job=VaspJob(['mpirun', '")+str(soc_exe)+str("'], final=False, backup=False)")+'\n' cust_file.write(cline) cline=str('handlers = [VaspErrorHandler(), MeshSymmetryErrorHandler(),UnconvergedErrorHandler(), NonConvergingErrorHandler(),PotimErrorHandler()]')+'\n' cust_file.write(cline) #cline=str('validators = [VaspFilesValidator()]')+'\n' cline=str('validators = [VasprunXMLValidator()]')+'\n' cust_file.write(cline) cline=str('c = Custodian(handlers, [job],max_errors=5,validators=validators)')+'\n' cust_file.write(cline) cline=str('c.run()')+'\n' cust_file.write(cline) cust_file.close() os.system(cmd) if os.path.isfile('OUTCAR'): try: wait=main_outcar('OUTCAR') #Vasprun("vasprun.xml").converged #wait=Vasprun("vasprun.xml").converged except: pass f_energy='na' enp='na' contcar=str(os.getcwd())+str('/')+str('CONTCAR') final_str=Structure.from_file(contcar) try: oszicar = Oszicar("OSZICAR") f_energy=float(oszicar.final_energy) enp=float(oszicar.final_energy)/float(final_str.composition.num_atoms) except: print ('Error in OSZICAR file during re-run jpb') pass natoms=final_str.composition.num_atoms os.chdir('../') if wait==True: data_cal=[] data_cal.append({'jobname':jobname,'poscar_initial':mat.as_dict(),'poscar_final':final_str.as_dict(),'incar':incar.as_dict(),'kpoints':kpoints.as_dict(),'final_energy':(f_energy),'contcar':final_str.as_dict()}) json_file=str(jobname)+str('.json') f_json=open(json_file,'w') f_json.write(json.dumps(data_cal,indent=4,cls=MontyEncoder)) f_json.close() print ('Wrote json file',contcar) return f_energy,contcar
INCAR['LDAU'] = '.TRUE.' INCAR['LDAUL'] = [2, -1] INCAR['LDAUU'] = [U_dict[TM], 0.0] INCAR['LDAUJ'] = [0.0, 0.0] else: INCAR['LDAU'] = '.FALSE.' INCAR['LDAUL'] = [-1, -1] INCAR['LDAUU'] = [0.0, 0.0] INCAR['LDAUJ'] = [0.0, 0.0] INCAR.write_file('%02d_%s/INCAR' % (idx + 1.0, formula)) KPOINTS.write_file('%02d_%s/KPOINTS' % (idx + 1.0, formula)) # Potcar setup POTCAR = Potcar([PP_dict[TM], PP_dict['O']]) POTCAR.write_file('%02d_%s/POTCAR' % (idx + 1.0, formula)) # jobscript copy for n, line in enumerate(fileinput.FileInput('jobscript_vasp.sh')): if '#PBS -N' in line: n_line = n PBS_N = '#PBS -N %02d_%s_np\n' % (idx + 1.0, formula) replace_line('jobscript_vasp.sh', n_line, PBS_N) destination = '%02d_%s/' % (idx + 1.0, formula) job_file = os.getcwd() + '/jobscript_vasp.sh' shutil.copy(job_file, destination) end_time = time.time() print('Execution time for script (sec) : %5.1f\n' %
def __init__(self, incar, poscar, potcar, kpoints, system=None, is_matrix=False, Grid_type='A', parent_job_dir='.', job_dir='Job', qadapter=None, job_cmd='qsub', wait=True, mappings_override=None, functional="PBE", database=None, magnetism=None, mag_init=None, reuse=None, reuse_override=None, reuse_incar=None, solvation=None, turn_knobs=OrderedDict([('ENCUT', []), ('KPOINTS', [])]), checkpoint_file=None, finer_kpoint=None, cal_logger=None): """ Calibrate constructor Args: incar (Incar object): input INCAR poscar (Poscar object): input POSCAR potcar (Potcar object): input POTCAR kpoints (Kpoints object): input KPOINTS system: system info as a dictionary, slab or interface example: system={'hkl':[1,1,1], 'ligand':None}, is_matrix (bool): whether the jobs are dependent on each other Grid_type (str): kpoints grid_type parent_job_dir (str): the directory from which all the jobs are launched job_dir (str): job directory created for each job in the parent_job_dir qadapter (?): adapter for the batch system job_cmd (str): command to be used for submitting the job. If qadapter is specified then job_cmd is ignored wait (bool): whther to wait for the job to finish. If the job is being submitted to the queue then there is no need for waiting turn_knobs (dict): an ordered dictionary of parmaters and the corresponding values mappings_override (dict): override symbol mapping in potcar eg:- {'S':'S_sv'} functional (str): exchange-correlation functional database (str): A work in progress, will be a database_name.yaml file for defaults specific to a database workflow that will have defaults for INCAR: cutoff, convergence for relaxation and continuation jobs KPOINTS: for relaxation, band structure jobs POTCAR: database specific For now defaults to None, if set to 'twod' activates twod set of directives reuse (list or bool): list of filenames for reuse Eg: ['CHGCAR', 'WAVECAR'] 'CONTCAR' is copied by default and if found empty warning is issued. Use the following flag for override only if you know what you are doing 'True' for just copying the CONTCAR file reuse_override (bool): whether to override the missing CONTCAR for a reuse calc magnetism (str): specifies magnetism calculation to be used implemented are 'AntiFerroMagnetism' and 'Magntic Anisotropy Energy' solvation (bool): whether to activate a solvation job, sets LSOL=True for now Calibrate jobs represent the engine configuration of mpinterfaces, where the fuel (input file sources) and driving method (kind of calculation) are decided . The Engine itself is instrument.py which creates the input set configured in Calibrate. Current fueling methods: 1. simplest test case involving a single job: - specify the incar, kpoints, poscar, potcar (aka the VASP 4) explicitly as pymatgen objects - turn_knobs = {} , is_matrix = False 2. test case for calibration of parameters: - specify an initial configuration for the VASP 4 - specify parameters to calibrate via turn_knobs, set is_matrix = True only if number of parameters > 1 3. Database production case: (possibly most used) - specify initial configuration for the VASP 4 based on a database.yaml - specify an input.yaml that details the workflow Note: input structure if needed will be obtained from the provided poscar object """ self.name = datetime.datetime.now().isoformat() self.system = system self.parent_job_dir = os.path.abspath(parent_job_dir) self.job_dir = job_dir self.incar = incar self.poscar = poscar self.potcar = potcar if poscar: self.potcar = Potcar(symbols=poscar.site_symbols, functional=functional) self.kpoints = kpoints if incar: self.incar_orig = incar.as_dict() if poscar: self.poscar_orig = poscar.as_dict() if self.potcar: self.potcar_orig = self.potcar.as_dict() if kpoints: self.kpoints_orig = kpoints.as_dict() self.qadapter = qadapter self.job_dir_list = [] self.jobs = [] self.job_ids = [] self.handlers = [] self.job_cmd = job_cmd self.n_atoms = 0 self.turn_knobs = turn_knobs self.response_to_knobs = {} self.sorted_response_to_knobs = {} for k, v in turn_knobs.items(): self.response_to_knobs[k] = {} self.sorted_response_to_knobs[k] = {} self.is_matrix = is_matrix self.Grid_type = Grid_type self.wait = wait self.cal_log = [] self.mappings_override = mappings_override self.database = database self.magnetism = magnetism self.mag_init = mag_init self.solvation = solvation self.reuse = reuse self.reuse_incar = reuse_incar self.reuse_override = reuse_override self.reuse_paths = None # list object communicated to instrument self.finer_kpoint = finer_kpoint self.functional = functional self.checkpoint_file = checkpoint_file if cal_logger: self.logger = cal_logger else: self.logger = logger
from matgendb.creator import VaspToDbTaskDrone drone = VaspToDbTaskDrone(collection='test') for j in ds: drone.assimilate(j.path) #%% from matgendb.query_engine import QueryEngine qe = QueryEngine(collection='test') # entries = qe.get_entries({'dir_name':'localhost:/home/lorenzo/tests/project-test/tutorials/Si-BS-dataset/3-PBE-BS'}) entries = qe.get_entries({'chemsys': 'Si'}, optional_data=['calculations'], inc_structure=True) #%% e = entries[0] inputs = e.data['calculations'][0]['input'] incar = Incar(inputs['incar']) kpoints = Kpoints.from_dict(inputs['kpoints']) poscar = Poscar(e.structure) potcar = Potcar(inputs['potcar']) vaspinput = VaspInput(incar, kpoints, poscar, potcar) #%%
# vasp input incar_dict = { 'SYSTEM': 'test', 'ENCUT': 500, 'ISIF': 2, 'IBRION': 2, 'ISMEAR': 1, 'EDIFF': 1e-06, 'NPAR': 8, 'SIGMA': 0.1, 'NSW': 100, 'PREC': 'Accurate' } incar = Incar.from_dict(incar_dict) poscar = Poscar(iface) potcar = Potcar(poscar.site_symbols) kpoints = Kpoints.automatic(20) #set job list. if empty a single job will be run encut_list = [] #range(400,800,100) turn_knobs = OrderedDict([('ENCUT', encut_list)]) #job directory job_dir = 'vasp_job' # run settings qadapter = None job_cmd = None nprocs = 16 nnodes = 1 walltime = '24:00:00' mem = 1000 incar['NPAR'] = int(sqrt(nprocs)) job_bin = '/home/km468/Software/VASP/vasp.5.3.5/vasp'
INCAR['LDAUL'][index] = 2 INCAR['LDAUU'][index] = U_dict[element] INCAR.write_file('%03d_%s/INCAR' % (idx + 1.0, formula)) KPOINTS.write_file('%03d_%s/KPOINTS' % (idx + 1.0, formula)) # Potcar setup mp_calc = mpr.get_entry_by_material_id({'material_id': mp_id}) mp_potcar_symbols = mp_calc.parameters['potcar_symbols'] for i in range(len(mp_potcar_symbols)): mp_potcar_symbols[i] = mp_potcar_symbols[i].replace("PBE ", "") if 'W_pv' in mp_potcar_symbols: mp_potcar_symbols[1] = 'W_sv' POTCAR = Potcar(mp_potcar_symbols) POTCAR.write_file(file_path + 'POTCAR') print('%02d' % (idx + 1.0), " ", formula, " ", conv_struc.formula, " ", len(conv_struc), " %4.3f %4.3f %4.3f" % (conv_struc.lattice.abc), " ", mp_potcar_symbols, " ", INCAR['LDAUU'], " %s" % INCAR['MAGMOM']) f.writelines([ '%02d' % (idx + 1.0), " ", formula, " ", conv_struc.formula, " ", str(len(conv_struc)), " %4.3f %4.3f %4.3f" % (conv_struc.lattice.abc), " %s" % mp_potcar_symbols, " %s" % INCAR['LDAUU'], " %s\n" % INCAR['MAGMOM'] ])
def __init__(self, incar, poscar, potcar, kpoints, system=None, is_matrix=False, Grid_type='A', parent_job_dir='.', job_dir='Job', qadapter=None, job_cmd='qsub', wait=True, mappings_override=None, functional="PBE", turn_knobs=OrderedDict([('ENCUT', []), ('KPOINTS', [])]), checkpoint_file=None, cal_logger=None): """ Calibrate constructor Args: incar (Incar object): input INCAR poscar (Poscar object): input POSCAR potcar (Potcar object): input POTCAR kpoints: input KPOINTS system: system info as a dictionary, slab or interface example: system={'hkl':[1,1,1], 'ligand':None}, is_matrix (bool): whether the jobs are dependent on each other Grid_type: kpoints grid_type parent_job_dir: the directory from which all the jobs are launched job_dir: job directory qadapter: adapter for the batch system job_cmd: command to be used for submitting the job. If qadapter is specified then job_cmd is ignored wait: whther to wait for the job to finish. If the job is being submitted to the queue then there is no need for waiting turn_knobs: an ordered dictionary of parmaters and the corresponding values mappings_override: override symbol mapping in potcar eg:- {'S':'S_sv'} functional: exchange-correlation functional Note: input structure if needed will be obtained from the provided poscar object """ self.name = datetime.datetime.now().isoformat() self.system = system self.parent_job_dir = os.path.abspath(parent_job_dir) self.job_dir = job_dir self.incar = incar self.poscar = poscar self.potcar = potcar if poscar: self.potcar = Potcar(symbols=poscar.site_symbols, functional=functional) self.kpoints = kpoints if incar: self.incar_orig = incar.as_dict() if poscar: self.poscar_orig = poscar.as_dict() if self.potcar: self.potcar_orig = self.potcar.as_dict() if kpoints: self.kpoints_orig = kpoints.as_dict() self.qadapter = qadapter self.job_dir_list = [] self.jobs = [] self.job_ids = [] self.handlers = [] self.job_cmd = job_cmd self.n_atoms = 0 self.turn_knobs = turn_knobs self.response_to_knobs = {} self.sorted_response_to_knobs = {} for k, v in turn_knobs.items(): self.response_to_knobs[k] = {} self.sorted_response_to_knobs[k] = {} self.is_matrix = is_matrix self.Grid_type = Grid_type self.wait = wait self.cal_log = [] self.mappings_override = mappings_override self.functional = functional self.checkpoint_file = checkpoint_file if cal_logger: self.logger = cal_logger else: self.logger = logger