def run(self): n = 10 dftb = DFTBplus() kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=10000, force_odd=True) dftb.initialize(workdir=self.workdir, structure=self.structure, kpoints=kpoints) ans = dftb.set_slater_koster(search_paths=self.slater_path) if not ans: print('Slater-Koster files not complete') return grid = None energies = [] while True: density = n ** 3 kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=density, force_odd=True) if np.sum(grid) != np.sum(kpoints.grid): pcm_log.debug('Trial density: %d Grid: %s' % (density, kpoints.grid)) grid = list(kpoints.grid) dftb.kpoints = kpoints dftb.basic_input() dftb.hamiltonian['MaxSCCIterations'] = 50 if os.path.isfile('charges.bin'): dftb.hamiltonian['ReadInitialCharges'] = True dftb.hamiltonian['Mixer'] = {'name': 'DIIS'} dftb.set_static() dftb.set_inputs() dftb.run() if self.waiting: dftb.runner.wait() while True: if dftb.runner is not None and dftb.runner.poll() is not None: pcm_log.info('Execution completed. Return code %d' % dftb.runner.returncode) filename = dftb.workdir + os.sep + 'detailed.out' if os.path.exists(filename): ret = read_detailed_out(filename) line = 'KPoint_grid= %15s iSCC= %4d Total_energy= %10.4f SCC_error= %9.3E' print(line % (grid, ret['SCC']['iSCC'], ret['total_energy'], ret['SCC']['SCC_error'])) else: print('detailed.out could not be found, exiting...') return n += 2 energies.append(ret['total_energy']) break time.sleep(10) self.results.append({'kp_grid': grid, 'iSCC': ret['SCC']['iSCC'], 'Total_energy': ret['total_energy'], 'SCC_error': ret['SCC']['SCC_error']}) else: n += 2 if len(energies) > 2 and abs(max(energies[-3:]) - min(energies[-3:])) < self.energy_tolerance: break
def __init__(self, structure, workdir='.', kpoints=None, binary='vasp', energy_tolerance=1E-3, increment_factor=0.2, initial_encut=1.3): self.structure = structure self.workdir = workdir self.binary = binary self.increment_factor = increment_factor self.initial_encut = initial_encut if kpoints is None: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=1E4, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints Convergence.__init__(self, energy_tolerance) self.task_params = { 'energy_tolerance': self.energy_tolerance, 'increment_factor': self.increment_factor, 'initial_encut': self.initial_encut } Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, binary=binary)
def __init__(self, structure, workdir='.', kpoints=None, executable='vasp', energy_tolerance=1E-3, increment_factor=0.2, initial_encut=1.3, pspdir='potpaw_PBE', psp_options=None, extra_vars=None, heterostructure=False): self.structure = structure self.workdir = workdir self.executable = executable self.increment_factor = increment_factor self.initial_encut = initial_encut self.pspdir = pspdir if psp_options is not None: self.psp_options = psp_options else: self.psp_options = {} if extra_vars is not None: self.extra_vars = extra_vars else: self.extra_vars = {} if kpoints is None: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=1E4, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints # If heterostructure is true it will keep the repeating order found # in the POSCAR. # Added by Uthpala on Apr 20th, 2020. self.heterostructure = heterostructure Convergence.__init__(self, energy_tolerance) self.task_params = {'energy_tolerance': self.energy_tolerance, 'increment_factor': self.increment_factor, 'initial_encut': self.initial_encut} Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, executable=executable)
def __init__(self, structure, workdir='.', target_forces=1E-3, executable='vasp', encut=1.3, kp_grid=None, kp_density=1E4, relax_cell=True, max_calls=10,pspdir='potpaw_PBE', psp_options=None, extra_vars=None, heterostructure=False): Relaxator.__init__(self, target_forces) self.target_forces = target_forces # If heterostructure is true it will keep the repeating order found # in the POSCAR. # Added by Uthpala on Apr 20th, 2020. self.heterostructure = heterostructure self.vaspjob = VaspJob(executable=executable, workdir=workdir) self.relaxed = False if kp_grid is not None: self.kpoints = KPoints(kmode='gamma', grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.vaspjob.initialize(structure=structure, kpoints=self.kpoints, pspdir=pspdir, heterostructure=self.heterostructure) self.vaspjob.potcar_setup = psp_options self.encut = encut self.relax_cell = relax_cell self.max_calls = max_calls self.pspdir = pspdir if extra_vars is not None: self.extra_vars = extra_vars else: self.extra_vars = {} task_params = {'target_forces': self.target_forces, 'encut': self.encut, 'relax_cell': self.relax_cell, 'max_calls': self.max_calls} Task.__init__(self, structure=structure, task_params=task_params, workdir=workdir, executable=executable)
def __init__(self, structure, workdir='.', binary='vasp', encut=1.3, kpoints=None, kp_density=1E4): self.encut = encut if kpoints is None: kp = KPoints.optimized_grid(structure.lattice, kp_density=kp_density, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints self.task_params = { 'encut': self.encut, 'kpoints': self.kpoints.to_dict } Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, binary=binary)
def __init__(self, structure, relaxator_params=None, workdir='.', kpoints=None, target_forces=1E-3, waiting=False, kp_density=10000, forced=True): self.workdir = workdir self.initial_structure = structure self.slater_path = None self.symmetrize = False self.forced = forced if relaxator_params is None: relaxator_params = {'slater_path': '.'} self.set_params(relaxator_params) if self.symmetrize: self.initial_structure = symmetrize(structure) self.structure = self.initial_structure.copy() self.waiting = waiting if kpoints is None: self.kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=kp_density) else: self.kpoints = kpoints Relaxator.__init__(self, target_forces)
def __init__(self, structure, workdir='.', slater_path='.', waiting=False, energy_tolerance=1E-3, output_file='results.json'): self.structure = structure self.workdir = workdir self.slater_path = slater_path self.waiting = waiting self.energy_tolerance = energy_tolerance if isinstance(slater_path, str): self.slater_path = [slater_path] self.results = [] self.output_file = output_file dftb = DFTBplus(workdir=self.workdir) kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=10000, force_odd=True) dftb.initialize(structure=self.structure, kpoints=kpoints) ans = dftb.set_slater_koster(search_paths=self.slater_path) if not ans: print('Slater-Koster files not complete')
def __init__(self, structure, workdir='.', binary='abinit', ecut=50, kpoints=None, kp_density=1E4): self.ecut = ecut if kpoints is None: kp = KPoints.optimized_grid(structure.lattice, kp_density=kp_density, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints self.task_params = {'ecut': self.ecut, 'kpoints': self.kpoints.to_dict} Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, binary=binary) self.abinitjob = AbinitJob() self.abinitjob.initialize(workdir=workdir, structure=structure, binary=binary)
def __init__(self, structure, workdir='.', target_forces=1E-3, waiting=False, executable='vasp', encut=1.3, kp_grid=None, kp_density=1E4, relax_cell=True): Relaxator.__init__(self, target_forces) self.target_forces = target_forces self.waiting = waiting self.vaspjob = VaspJob(workdir=workdir, executable=executable) self.relaxed = False if kp_grid is not None: self.kpoints = KPoints(kmode='gamma', grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.vaspjob.initialize(structure=structure, kpoints=self.kpoints) self.encut = encut self.relax_cell = relax_cell task_params = { 'target_forces': self.target_forces, 'encut': self.encut, 'relax_cell': self.relax_cell } Task.__init__(self, structure=structure, task_params=task_params, workdir=workdir, executable=executable) self.stage = 1
def __init__( self, structure, workdir=".", kpoints=None, executable="vasp", energy_tolerance=1e-3, increment_factor=0.2, initial_encut=1.3, pspdir="potpaw_PBE", psp_options=None, extra_vars=None, heterostructure=False, make_potcar=True, ): self.structure = structure self.workdir = workdir self.executable = executable self.increment_factor = increment_factor self.initial_encut = initial_encut self.pspdir = pspdir if psp_options is not None: self.psp_options = psp_options else: self.psp_options = {} if extra_vars is not None: self.extra_vars = extra_vars else: self.extra_vars = {} if kpoints is None: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=1e4, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints # If heterostructure is true it will keep the repeating order found # in the POSCAR. # Added by Uthpala on Apr 20th, 2020. self.heterostructure = heterostructure # setting make_potcar=False will not generate a new POTCAR. # Added by Uthpala on May 12th, 2021. self.make_potcar = make_potcar Convergence.__init__(self, energy_tolerance) self.task_params = { "energy_tolerance": self.energy_tolerance, "increment_factor": self.increment_factor, "initial_encut": self.initial_encut, } Task.__init__( self, structure=structure, task_params=self.task_params, workdir=workdir, executable=executable, )
def best_kpoints(self): if not self.is_converge: print('Convergence not completed') return None else: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=self.convergence_info[-3]['kp_density'], force_odd=True) return kp
def best_kpoints(self): if not self.is_converge: print('Convergence not completed') return None else: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=self.convergence_info[-3]['kp_density'], force_odd=True) return kp
def initialize(self, structure, kpoints=None, kp_density=10000): assert structure.is_crystal assert structure.is_perfect self.structure = structure self.get_geometry() self.kp_density = kp_density if kpoints is None: kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=self.kp_density, force_odd=True) self.kpoints = kpoints
def initialize(self, structure, kpoints=None, kp_density=10000): assert structure.is_crystal assert structure.is_perfect self.structure = structure self.get_geometry() self.kp_density = kp_density if kpoints is None: kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=self.kp_density, force_odd=True) self.kpoints = kpoints
def __init__(self, structure, workdir='.', executable='vasp', encut=1.3, kpoints=None, kp_density=1E4, extra_incar=None): self.encut = encut if kpoints is None: kp = KPoints.optimized_grid(structure.lattice, kp_density=kp_density, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints self.task_params = {'encut': self.encut, 'kpoints': self.kpoints.to_dict, 'extra_incar': extra_incar} Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, executable=executable)
def __init__(self, structure, workdir='.', binary='abinit', ecut=50, kpoints=None, kp_density=1E4): self.ecut = ecut if kpoints is None: kp = KPoints.optimized_grid(structure.lattice, kp_density=kp_density, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints self.task_params = {'ecut': self.ecut, 'kpoints': self.kpoints.to_dict} Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, binary=binary) self.abinitjob = AbinitJob() self.abinitjob.initialize(workdir=workdir, structure=structure, binary=binary)
def initialize(self, structure, workdir='.', kpoints=None, binary='dftb+', kp_density=10000): assert structure.is_crystal assert structure.is_perfect self.structure = structure self.get_geometry() self.workdir = workdir if not os.path.lexists(workdir): os.mkdir(workdir) self.binary = binary self.kp_density = kp_density if kpoints is None: kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=self.kp_density, force_odd=True) self.kpoints = kpoints
def __init__(self, structure, workdir, slater_path, waiting=False, kpoints=None, output_file='results.json', max_scc_iterations=50): self.structure = structure self.workdir = workdir self.slater_path = slater_path self.waiting = waiting self.MaxSCCIterations = max_scc_iterations if isinstance(slater_path, str): self.slater_path = [slater_path] self.results = [] self.output_file = output_file if kpoints is None: self.kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=10000, force_odd=True) else: self.kpoints = kpoints
def __init__(self, structure, workdir, slater_path, waiting=False, kpoints=None, output_file='results.json', max_scc_iterations=50): self.structure = structure self.workdir = workdir self.slater_path = slater_path self.waiting = waiting self.MaxSCCIterations = max_scc_iterations if isinstance(slater_path, str): self.slater_path = [slater_path] self.results = [] self.output_file = output_file if kpoints is None: self.kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=10000, force_odd=True) else: self.kpoints = kpoints
def __init__(self, structure, workdir='.', kpoints=None, binary='vasp', energy_tolerance=1E-3, increment_factor=0.2, initial_encut=1.3): self.structure = structure self.workdir = workdir self.binary = binary self.increment_factor = increment_factor self.initial_encut = initial_encut if kpoints is None: kp = KPoints.optimized_grid(self.structure.lattice, kp_density=1E4, force_odd=True) self.kpoints = kp else: self.kpoints = kpoints Convergence.__init__(self, energy_tolerance) self.task_params = {'energy_tolerance': self.energy_tolerance, 'increment_factor': self.increment_factor, 'initial_encut': self.initial_encut} Task.__init__(self, structure=structure, task_params=self.task_params, workdir=workdir, binary=binary)
def __init__(self, structure, workdir='.', target_forces=1E-3, waiting=False, binary='vasp', encut=1.3, kp_grid=None, kp_density=1E4, relax_cell=True): Relaxator.__init__(self, target_forces) self.target_forces = target_forces self.waiting = waiting self.vaspjob = VaspJob() self.relaxed = False if kp_grid is not None: self.kpoints = KPoints(kmode='gamma', grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.vaspjob.initialize(workdir=workdir, structure=structure, kpoints=self.kpoints, binary=binary) self.encut = encut self.relax_cell = relax_cell task_params = {'target_forces': self.target_forces, 'encut': self.encut, 'relax_cell': self.relax_cell} Task.__init__(self, structure=structure, task_params=task_params, workdir=workdir, binary=binary) self.stage = 1
def prepare_folder(self, entry_id, workdir, binary='vasp', source_dir='.'): vj = VaspJob() structure = self.get_structure(entry_id) kp = KPoints.optimized_grid(structure.lattice, kp_density=2E4) vj.initialize(structure, workdir=workdir, kpoints=kp, binary=binary) vj.clean() vj.input_variables = read_incar(source_dir + '/INCAR') magmom_sph = self.get_entry(entry_id, {'properties.magmom': 1})['properties']['magmom'] magmom_car = spherical_to_cartesian(magmom_sph) vj.input_variables.variables['MAGMOM'] = [float(x) for x in magmom_car.flatten()] vj.input_variables.variables['M_CONSTR'] = [float(x) for x in magmom_car.flatten()] vj.input_variables.variables['IBRION'] = -1 vj.input_variables.variables['LWAVE'] = True vj.input_variables.variables['EDIFF'] = 1E-5 vj.input_variables.variables['LAMBDA'] = 10 vj.input_variables.variables['NSW'] = 0 vj.input_variables.variables['I_CONSTRAINED_M'] = 1 vj.set_inputs()
def __init__(self, structure, workdir='.', slater_path='.', waiting=False, energy_tolerance=1E-3, output_file='results.json'): self.structure = structure self.workdir = workdir self.slater_path = slater_path self.waiting = waiting self.energy_tolerance = energy_tolerance if isinstance(slater_path, str): self.slater_path = [slater_path] self.results = [] self.output_file = output_file dftb = DFTBplus() kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=10000, force_odd=True) dftb.initialize(workdir=self.workdir, structure=self.structure, kpoints=kpoints) ans = dftb.set_slater_koster(search_paths=self.slater_path) if not ans: print('Slater-Koster files not complete')
def create_inputs(self, kp_density=10000, encut=1.0): # kpoints = KPoints(kmode='gamma', grid=[4, 4, 4]) for entry in self.population.pcdb.entries.find(): name = str(entry['_id']) workdir = self.basedir + os.sep + name structure = self.population.db.get_structure(entry['_id']) kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) print(kpoints) vj = VaspJob() vj.initialize(workdir=workdir, structure=structure, kpoints=kpoints) inp = InputVariables() inp.set_rough_relaxation() vj.set_input_variables(inp) vj.write_potcar() vj.input_variables.set_encut(ENCUT=encut, POTCAR=workdir + os.sep + 'POTCAR') vj.set_inputs() self.vasp_jobs[name] = vj self.runs[name] = 0 self.status[name] = ['ACTIVE']
def __init__(self, structure, workdir='.', tolmxf=1E-4, tolrff=1E-2, waiting=False, binary='abinit', ecut=50, kp_grid=None, kp_density=1E4, relax_cell=True, max_calls=10): Relaxator.__init__(self, tolmxf) self.tolmxf = tolmxf self.ecut = ecut self.waiting = waiting self.abinitjob = AbinitJob() self.relaxed = False if kp_grid is not None: self.kpoints = KPoints(kmode='gamma', grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.abinitjob.initialize(workdir=workdir, structure=structure, binary=binary) self.relax_cell = relax_cell self.max_calls = max_calls task_params = {'tolmxf': self.target_forces, 'ecut': self.ecut, 'relax_cell': self.relax_cell, 'max_calls': self.max_calls} Task.__init__(self, structure=structure, task_params=task_params, workdir=workdir, binary=binary)
def __init__(self, structure, workdir='.', tolmxf=1E-4, tolrff=1E-2, waiting=False, executable='abinit', ecut=50, kp_grid=None, kp_density=1E4, relax_cell=True, max_calls=10): Relaxator.__init__(self, tolmxf) self.tolmxf = tolmxf self.ecut = ecut self.waiting = waiting self.abinitjob = AbinitJob(workdir=workdir, executable=executable) self.relaxed = False self.tolmxf = tolmxf self.tolrff = tolrff if kp_grid is not None: self.kpoints = KPoints(kmode='gamma', grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.abinitjob.initialize(structure=structure) self.relax_cell = relax_cell self.max_calls = max_calls task_params = {'tolmxf': self.target_forces, 'ecut': self.ecut, 'relax_cell': self.relax_cell, 'max_calls': self.max_calls} Task.__init__(self, structure=structure, task_params=task_params, workdir=workdir, executable=executable)
def create_inputs(self, kp_density=10000, encut=1.0): # kpoints = KPoints(kmode='gamma', grid=[4, 4, 4]) for entry in self.population.pcdb.entries.find(): name = str(entry['_id']) workdir = self.basedir + os.sep + name structure = self.population.db.get_structure(entry['_id']) kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) print(kpoints) vj = VaspJob(workdir=workdir) vj.initialize(structure=structure, kpoints=kpoints) inp = VaspInput() inp.set_rough_relaxation() vj.set_input_variables(inp) vj.write_potcar() vj.input_variables.set_encut(ENCUT=encut, POTCAR=workdir + os.sep + 'POTCAR') vj.set_inputs() self.vasp_jobs[name] = vj self.runs[name] = 0 self.status[name] = ['ACTIVE']
def __init__(self, structure, relaxator_params=None, workdir='.', kpoints=None, target_forces=1E-3, waiting=False, kp_density=10000, forced=True): self.workdir = workdir self.initial_structure = structure self.slater_path = None self.symmetrize = False self.forced = forced if relaxator_params is None: relaxator_params = {'slater_path': '.'} self.set_params(relaxator_params) if self.symmetrize: self.initial_structure = symmetrize(structure) self.structure = self.initial_structure.copy() self.waiting = waiting if kpoints is None: self.kpoints = KPoints.optimized_grid(self.structure.lattice, kp_density=kp_density) else: self.kpoints = kpoints Relaxator.__init__(self, target_forces)
def run(self, nparal=4): self.started = True vj = VaspJob(workdir=self.workdir, executable=self.executable) vj.potcar_setup = self.psp_options kp = KPoints() vj.initialize(structure=self.structure, kpoints=kp, pspdir=self.pspdir, heterostructure=self.heterostructure) grid = None energies = [] if not self.is_converge: n = self.initial_number else: n = self.convergence_info[-3]['kp_n'] self.convergence_info = [] while True: density = n ** 3 kp = KPoints.optimized_grid(self.structure.lattice, kp_density=density, force_odd=True) pcm_log.debug('Trial density: %d Grid: %s' % (density, kp.grid)) if np.sum(grid) != np.sum(kp.grid): grid = kp.grid vj.set_kpoints(kp) vj.clean() vj.job_static() vj.input_variables.set_density_for_restart() vj.input_variables.set_encut(ENCUT=self.encut, POTCAR=self.workdir + os.sep + 'POTCAR') vj.input_variables.variables['NBANDS'] = nparal * ((30 + self.structure.valence_electrons()) // nparal + 1) vj.input_variables.set_ismear(kp) vj.input_variables.variables['SIGMA'] = 0.2 vj.input_variables.variables['ISPIN'] = 2 for i in self.extra_vars: vj.input_variables[i] = self.extra_vars[i] vj.set_inputs() vj.run(mpi_num_procs=nparal) while True: energy_str = '' filename = self.workdir + os.sep + 'vasp_stdout.log' if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout['data']) > 2: scf_energies = [i[2] for i in vasp_stdout['data']] energy_str = ' %7.3f' % scf_energies[1] for i in range(1, len(scf_energies)): if scf_energies[i] < scf_energies[i - 1]: energy_str += ' >' else: energy_str += ' <' pcm_log.debug(energy_str) if vj.runner is not None and vj.runner.poll() is not None: filename = self.workdir + os.sep + 'vasp_stdout.log' if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout['data']) > 2: scf_energies = [i[2] for i in vasp_stdout['data']] energy_str += ' %7.3f' % scf_energies[-1] pcm_log.debug(energy_str) break time.sleep(5) vj.get_outputs() energy = vj.outcar.final_data['energy']['free_energy']/self.structure.natom energies.append(energy) print('kp_density= %10d kp_grid= %15s free_energy= %9.6f' % (density, grid, energy)) self.convergence_info.append({'free_energy': vj.outcar.final_data['energy']['free_energy']/self.structure.natom, 'kp_grid': list(grid), 'kp_density': density, 'kp_n': n}) if len(energies) > 2 and abs(max(energies[-3:]) - min(energies[-3:])) < self.energy_tolerance: self.success = True break n += 2 self.output = {'convergence': self.convergence_info, 'best_kp_grid': list(self.best_kpoints.grid)} self.finished = True
def run(self, nparal=4): self.started = True vj = VaspJob(workdir=self.workdir, executable=self.executable) vj.potcar_setup = self.psp_options kp = KPoints() vj.initialize( structure=self.structure, kpoints=kp, pspdir=self.pspdir, heterostructure=self.heterostructure, make_potcar=self.make_potcar, ) grid = None energies = [] if not self.is_converge: n = self.initial_number else: n = self.convergence_info[-3]["kp_n"] self.convergence_info = [] while True: density = n**3 kp = KPoints.optimized_grid(self.structure.lattice, kp_density=density, force_odd=True) pcm_log.debug("Trial density: %d Grid: %s" % (density, kp.grid)) if np.sum(grid) != np.sum(kp.grid): grid = kp.grid vj.set_kpoints(kp) vj.clean() vj.job_static() vj.input_variables.set_density_for_restart() vj.input_variables.set_encut(ENCUT=self.encut, POTCAR=self.workdir + os.sep + "POTCAR") vj.input_variables.variables["NBANDS"] = nparal * ( (30 + self.structure.valence_electrons()) // nparal + 1) vj.input_variables.set_ismear(kp) vj.input_variables.variables["SIGMA"] = 0.2 vj.input_variables.variables["ISPIN"] = 2 for i in self.extra_vars: vj.input_variables[i] = self.extra_vars[i] vj.set_inputs() vj.run(mpi_num_procs=nparal) while True: energy_str = "" filename = self.workdir + os.sep + "vasp_stdout.log" if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout["data"]) > 2: scf_energies = [i[2] for i in vasp_stdout["data"]] energy_str = " %7.3f" % scf_energies[1] for i in range(1, len(scf_energies)): if scf_energies[i] < scf_energies[i - 1]: energy_str += " >" else: energy_str += " <" pcm_log.debug(energy_str) if vj.runner is not None and vj.runner.poll() is not None: filename = self.workdir + os.sep + "vasp_stdout.log" if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout["data"]) > 2: scf_energies = [ i[2] for i in vasp_stdout["data"] ] energy_str += " %7.3f" % scf_energies[-1] pcm_log.debug(energy_str) break time.sleep(5) vj.get_outputs() energy = (vj.outcar.final_data["energy"]["free_energy"] / self.structure.natom) energies.append(energy) print("kp_density= %10d kp_grid= %15s free_energy= %9.6f" % (density, grid, energy)) self.convergence_info.append({ "free_energy": vj.outcar.final_data["energy"]["free_energy"] / self.structure.natom, "kp_grid": list(grid), "kp_density": density, "kp_n": n, }) if (len(energies) > 2 and abs(max(energies[-3:]) - min(energies[-3:])) < self.energy_tolerance): self.success = True break n += 2 self.output = { "convergence": self.convergence_info, "best_kp_grid": list(self.best_kpoints.grid), } self.finished = True
def __init__( self, structure, workdir=".", target_forces=1e-3, executable="vasp", encut=1.3, kp_grid=None, kp_density=1e4, relax_cell=True, max_calls=10, pspdir="potpaw_PBE", psp_options=None, extra_vars=None, heterostructure=False, make_potcar=True, auto_ibrion=False, fire=False, ): Relaxator.__init__(self, target_forces) self.target_forces = target_forces # If heterostructure is true it will keep the repeating order found # in the POSCAR. # Added by Uthpala on Apr 20th, 2020. self.heterostructure = heterostructure # setting make_potcar=False will not generate a new POTCAR. # Added by Uthpala on May 12th, 2021. self.make_potcar = make_potcar # Turn on adaptive IBRION update. self.auto_ibrion = auto_ibrion # Use FIRE algorithm for relaxation. # Requires VTST Tools self.fire = fire self.vaspjob = VaspJob(executable=executable, workdir=workdir) self.relaxed = False if kp_grid is not None: self.kpoints = KPoints(kmode="gamma", grid=kp_grid) else: self.kpoints = KPoints.optimized_grid(structure.lattice, kp_density=kp_density) self.vaspjob.initialize( structure=structure, kpoints=self.kpoints, pspdir=pspdir, heterostructure=self.heterostructure, make_potcar=self.make_potcar, ) self.vaspjob.potcar_setup = psp_options self.encut = encut self.relax_cell = relax_cell self.max_calls = max_calls self.pspdir = pspdir if extra_vars is not None: self.extra_vars = extra_vars else: self.extra_vars = {} task_params = { "target_forces": self.target_forces, "encut": self.encut, "relax_cell": self.relax_cell, "max_calls": self.max_calls, } Task.__init__( self, structure=structure, task_params=task_params, workdir=workdir, executable=executable, )
def run(self, nparal=4): self.started = True vj = VaspJob() kp = KPoints() vj.initialize(self.structure, self.workdir, kp, binary=self.binary) grid = None energies = [] if not self.is_converge: n = self.initial_number else: n = self.convergence_info[-3]['kp_n'] self.convergence_info = [] while True: density = n ** 3 kp = KPoints.optimized_grid(self.structure.lattice, kp_density=density, force_odd=True) pcm_log.debug('Trial density: %d Grid: %s' % (density, kp.grid)) if np.sum(grid) != np.sum(kp.grid): grid = kp.grid vj.set_kpoints(kp) vj.clean() vj.job_static() vj.input_variables.set_density_for_restart() vj.input_variables.set_encut(ENCUT=self.encut, POTCAR=self.workdir + os.sep + 'POTCAR') vj.input_variables.variables['NBANDS'] = nparal * ((30 + self.structure.valence_electrons()) / nparal + 1) vj.input_variables.set_ismear(kp) vj.input_variables.variables['SIGMA'] = 0.2 vj.input_variables.variables['ISPIN'] = 2 vj.set_inputs() vj.run(use_mpi=True, mpi_num_procs=nparal) while True: energy_str = '' filename = self.workdir + os.sep + 'vasp_stdout.log' if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout['data']) > 2: scf_energies = [i[2] for i in vasp_stdout['data']] energy_str = ' %7.3f' % scf_energies[1] for i in range(1, len(scf_energies)): if scf_energies[i] < scf_energies[i - 1]: energy_str += ' >' else: energy_str += ' <' pcm_log.debug(energy_str) if vj.runner is not None and vj.runner.poll() is not None: filename = self.workdir + os.sep + 'vasp_stdout.log' if os.path.exists(filename): vasp_stdout = read_vasp_stdout(filename=filename) if len(vasp_stdout['data']) > 2: scf_energies = [i[2] for i in vasp_stdout['data']] energy_str += ' %7.3f' % scf_energies[-1] pcm_log.debug(energy_str) break time.sleep(5) vj.get_outputs() energy = vj.outcar.final_data['energy']['free_energy'] energies.append(energy) print('kp_density= %10d kp_grid= %15s free_energy= %9.6f' % (density, grid, energy)) self.convergence_info.append({'free_energy': vj.outcar.final_data['energy']['free_energy'], 'kp_grid': list(grid), 'kp_density': density, 'kp_n': n}) if len(energies) > 2 and abs(max(energies[-3:]) - min(energies[-3:])) < self.energy_tolerance: self.success = True break n += 2 self.output = {'convergence': self.convergence_info, 'best_kp_grid': list(grid)} self.finished = True