Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Args:
dim (int): 2 for relaxing a 2D material, 3 for a 3D material.
submit (bool): Whether or not to submit the job.
force_overwrite (bool): Whether or not to overwrite files
if an already converged vasprun.xml exists in the
directory.
"""
if force_overwrite or not utl.is_converged(os.getcwd()):
directory = os.getcwd().split('/')[-1]
# vdw_kernel.bindat file required for VDW calculations.
if VDW_KERNEL != '/path/to/vdw_kernel.bindat':
os.system('cp {} .'.format(VDW_KERNEL))
# KPOINTS
Kpoints.automatic_density(Structure.from_file('POSCAR'),
1000).write_file('KPOINTS')
# INCAR
INCAR_DICT.update(
{'MAGMOM': utl.get_magmom_string(Structure.from_file('POSCAR'))}
)
Incar.from_dict(INCAR_DICT).write_file('INCAR')
# POTCAR
utl.write_potcar()
# Special tasks only performed for 2D materials.
if dim == 2:
# Ensure 20A interlayer vacuum
utl.ensure_vacuum(Structure.from_file('POSCAR'), 20)
# Remove all z k-points.
kpts_lines = open('KPOINTS').readlines()
def _parse_kpoints(self, elem):
e = elem
if elem.find("generation"):
e = elem.find("generation")
k = Kpoints("Kpoints from vasprun.xml")
k.style = Kpoints.supported_modes.from_string(
e.attrib["param"] if "param" in e.attrib else "Reciprocal")
for v in e.findall("v"):
name = v.attrib.get("name")
toks = v.text.split()
if name == "divisions":
k.kpts = [[int(i) for i in toks]]
elif name == "usershift":
k.kpts_shift = [float(i) for i in toks]
elif name in {"genvec1", "genvec2", "genvec3", "shift"}:
setattr(k, name, [float(i) for i in toks])
for va in elem.findall("varray"):
name = va.attrib["name"]
if name == "kpointlist":
actual_kpoints = _parse_varray(va)
elif name == "weights":
submit (bool): Whether or not to submit the job.
"""
if not os.path.isdir('hse_prep'):
os.mkdir('hse_prep')
os.chdir('hse_prep')
shutil.copy('../CONTCAR', 'POSCAR')
if os.path.isfile('../POTCAR'):
shutil.copy('../POTCAR', '.')
relax(dim=2, submit=False)
incar_dict = Incar.from_file('INCAR').as_dict()
incar_dict.update({'NSW': 0, 'NELM': 1, 'LWAVE': False, 'LCHARG': False,
'LAECHG': False})
Incar.from_dict(incar_dict).write_file('INCAR')
Kpoints.automatic_density(
Structure.from_file('POSCAR'), 200).write_file('KPOINTS')
if dim == 2:
kpts_lines = open('KPOINTS').readlines()
with open('KPOINTS', 'w') as kpts:
for line in kpts_lines[:3]:
kpts.write(line)
kpts.write(kpts_lines[3].split()[0] + ' '
+ kpts_lines[3].split()[1] + ' 1')
if QUEUE_SYSTEM == 'pbs':
write_pbs_runjob('{}_prep'.format(
os.getcwd().split('/')[-2]), 1, 16, '800mb', '6:00:00', VASP_STD_BIN)
submission_command = 'qsub runjob'
Args:
string (str): KPOINTS string.
Returns:
Kpoints object
"""
lines = [line.strip() for line in string.splitlines()]
comment = lines[0]
num_kpts = int(lines[1].split()[0].strip())
style = lines[2].lower()[0]
# Fully automatic KPOINTS
if style == "a":
return Kpoints.automatic(int(lines[3]))
coord_pattern = re.compile(r'^\s*([\d+.\-Ee]+)\s+([\d+.\-Ee]+)\s+'
r'([\d+.\-Ee]+)')
# Automatic gamma and Monk KPOINTS, with optional shift
if style == "g" or style == "m":
kpts = [int(i) for i in lines[3].split()]
kpts_shift = (0, 0, 0)
if len(lines) > 4 and coord_pattern.match(lines[4]):
try:
kpts_shift = [int(i) for i in lines[4].split()]
except ValueError:
pass
return Kpoints.gamma_automatic(kpts, kpts_shift) if style == "g" \
else Kpoints.monkhorst_automatic(kpts, kpts_shift)
# Set up reference directory for the pure element.
if not os.path.isdir(elt):
os.mkdir(elt)
os.chdir(elt)
# Poscar
s = MPR.get_structure_by_material_id(
self._config['Mpids'][elt]['self']
)
s.to('POSCAR', 'POSCAR')
plines = open('POSCAR').readlines()
elements = plines[5].split()
# Kpoints
kp = Kpoints.automatic_density(s, self._n_kpts_per_atom)
kp.write_file('KPOINTS')
# Incar
incar = Incar.from_dict(self._incar_dict)
incar.write_file('INCAR')
# Potcar
utl.write_potcar(types=[self._potcar_dict[el] for el in elements])
# Runjob
if QUEUE == 'pbs':
utl.write_pbs_runjob('{}_cal'.format(elt), self._ncores,
self._nprocs, self._pmem, self._walltime,
self._binary)
submission_command = 'qsub runjob'
structure (Structure): structure for determining k-path
n_kpts (int): number of divisions along high-symmetry lines
dim (int): 2 for a 2D material, 3 for a 3D material.
ibzkpt_path (str): location of IBZKPT file. Defaults to one
directory up.
"""
ibz_lines = open(os.path.join(ibzkpt_path, "IBZKPT")).readlines()
for i, line in enumerate(ibz_lines):
if "Tetrahedra" in line:
ibz_lines = ibz_lines[:i]
break
n_ibz_kpts = int(ibz_lines[1].split()[0])
kpath = HighSymmKpath(structure)
Kpoints.automatic_linemode(n_kpts, kpath).write_file('KPOINTS')
if dim == 2:
remove_z_kpoints()
linemode_lines = open('KPOINTS').readlines()
abs_path = []
i = 4
while i < len(linemode_lines):
start_kpt = linemode_lines[i].split()
end_kpt = linemode_lines[i+1].split()
increments = [
(float(end_kpt[0]) - float(start_kpt[0])) / 20,
(float(end_kpt[1]) - float(start_kpt[1])) / 20,
(float(end_kpt[2]) - float(start_kpt[2])) / 20
]
abs_path.append(start_kpt[:3] + ['0', start_kpt[4]])
toks = v.text.split()
if name == "divisions":
k.kpts = [[int(i) for i in toks]]
elif name == "usershift":
k.kpts_shift = [float(i) for i in toks]
elif name in {"genvec1", "genvec2", "genvec3", "shift"}:
setattr(k, name, [float(i) for i in toks])
for va in elem.findall("varray"):
name = va.attrib["name"]
if name == "kpointlist":
actual_kpoints = _parse_varray(va)
elif name == "weights":
weights = [i[0] for i in _parse_varray(va)]
elem.clear()
if k.style == Kpoints.supported_modes.Reciprocal:
k = Kpoints(comment="Kpoints from vasprun.xml",
style=Kpoints.supported_modes.Reciprocal,
num_kpts=len(k.kpts),
kpts=actual_kpoints, kpts_weights=weights)
return k, actual_kpoints, weights
Args:
POSCAR_input (str): path to POSCAR
KPOINTS_output (str): path to output KPOINTS
reciprocal_density (int): Grid density
isym (int): either -1 or 0. Current Lobster versions only allow -1.
from_grid (bool): If True KPOINTS will be generated with the help of a grid given in input_grid. Otherwise,
they will be generated from the reciprocal_density
input_grid (list): grid to generate the KPOINTS file
line_mode (bool): If True, band structure will be generated
kpoints_line_density (int): density of the lines in the band structure
symprec (float): precision to determine symmetry
"""
structure = Structure.from_file(POSCAR_input)
# should this really be static? -> make it similar to INCAR?
if not from_grid:
kpointgrid = Kpoints.automatic_density_by_vol(structure, reciprocal_density).kpts
mesh = kpointgrid[0]
else:
mesh = input_grid
# The following code is taken from: SpacegroupAnalyzer
# we need to switch off symmetry here
latt = structure.lattice.matrix
positions = structure.frac_coords
unique_species = [] # type: List[Any]
zs = []
magmoms = []
for species, g in itertools.groupby(structure,
key=lambda s: s.species):
if species in unique_species:
ind = unique_species.index(species)
def setup(self):
"""
setup solvation jobs for the calibrate objects
copies WAVECAR and sets the solvation params in the incar file
also dumps system.json file in each directory for the database
crawler
mind: works only for cal objects that does only single
calculations
"""
for cal in self.cal_objs:
jdir = cal.old_job_dir_list[0]
cal.poscar = Poscar.from_file(jdir + os.sep + 'POSCAR')
cal.potcar = Potcar.from_file(jdir + os.sep + 'POTCAR')
cal.kpoints = Kpoints.from_file(jdir + os.sep + 'KPOINTS')
cal.incar = Incar.from_file(jdir + os.sep + 'INCAR')
cal.incar['LSOL'] = '.TRUE.'
syms = [site.specie.symbol for site in cal.poscar.structure]
zvals = {p.symbol: p.nelectrons for p in cal.potcar}
nelectrons = sum([zvals[a[0]] * len(tuple(a[1]))
for a in itertools.groupby(syms)])
keys = [k for k in self.sol_params.keys()
if self.sol_params[k]]
prod_list = [self.sol_params.get(k) for k in keys]
for params in itertools.product(*tuple(prod_list)):
job_dir = self.job_dir + os.sep \
+ cal.old_job_dir_list[0].replace(os.sep,
'_').replace('.',
'_') \
+ os.sep + 'SOL'
for i, k in enumerate(keys):
def from_dict(cls, d):
incar = Incar.from_dict(d["incar"])
poscar = Poscar.from_dict(d["poscar"])
potcar = Potcar.from_dict(d["potcar"])
kpoints = Kpoints.from_dict(d["kpoints"])
qadapter = None
if d["qadapter"] is not None:
qadapter = CommonAdapter.from_dict(d["qadapter"])
script_name = d["script_name"]
return MPINTVaspInputSet(d["name"], incar, poscar, potcar,
kpoints, qadapter,
script_name=script_name,
vis_logger=logging.getLogger(d["logger"]),
**d["kwargs"])