本文整理汇总了Python中pymatgen.io.vasp.VaspInput类的典型用法代码示例。如果您正苦于以下问题:Python VaspInput类的具体用法?Python VaspInput怎么用?Python VaspInput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VaspInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_brmix
def test_brmix(self):
h = VaspErrorHandler("vasp.brmix")
self.assertEqual(h.check(), True)
# The first (no good OUTCAR) correction, check IMIX
d = h.correct()
self.assertEqual(d["errors"], ['brmix'])
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["IMIX"], 1)
self.assertTrue(os.path.exists("CHGCAR"))
# The next correction check Gamma and evenize
h.correct()
vi = VaspInput.from_directory(".")
self.assertFalse("IMIX" in vi["INCAR"])
self.assertTrue(os.path.exists("CHGCAR"))
if vi["KPOINTS"].style == Kpoints.supported_modes.Gamma and vi["KPOINTS"].num_kpts < 1:
all_kpts_even = all([
bool(n % 2 == 0) for n in vi["KPOINTS"].kpts[0]
])
self.assertFalse(all_kpts_even)
# The next correction check ISYM and no CHGCAR
h.correct()
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["ISYM"], 0)
self.assertFalse(os.path.exists("CHGCAR"))
shutil.copy("INCAR.nelect", "INCAR")
h = VaspErrorHandler("vasp.brmix")
self.assertEqual(h.check(), False)
d = h.correct()
self.assertEqual(d["errors"], [])
示例2: check
def check(self):
msg = "Reciprocal lattice and k-lattice belong to different class of" \
" lattices."
vi = VaspInput.from_directory('.')
# According to VASP admins, you can disregard this error
# if symmetry is off
# Also disregard if automatic KPOINT generation is used
if (not vi["INCAR"].get('ISYM', True)) or \
vi[
"KPOINTS"].style == Kpoints.supported_modes.Automatic:
return False
try:
v = Vasprun(self.output_vasprun)
if v.converged:
return False
except:
pass
with open(self.output_filename, "r") as f:
for line in f:
l = line.strip()
if l.find(msg) != -1:
return True
return False
示例3: correct
def correct(self):
# if change_algo is True, change ALGO = Fast to Normal if ALGO is
# Fast. If still not converging, following Kresse's
# recommendation, we will try two iterations of different mixing
# parameters. If this error is caught again, then kil the job
vi = VaspInput.from_directory(".")
algo = vi["INCAR"].get("ALGO", "Normal")
amix = vi["INCAR"].get("AMIX", 0.4)
bmix = vi["INCAR"].get("BMIX", 1.0)
amin = vi["INCAR"].get("AMIN", 0.1)
actions = []
if self.change_algo:
if algo == "Fast":
backup(VASP_BACKUP_FILES)
actions.append({"dict": "INCAR", "action": {"_set": {"ALGO": "Normal"}}})
elif amix > 0.1 and bmix > 0.01:
# try linear mixing
backup(VASP_BACKUP_FILES)
actions.append({"dict": "INCAR", "action": {"_set": {"AMIX": 0.1, "BMIX": 0.01, "ICHARG": 2}}})
elif bmix < 3.0 and amin > 0.01:
# Try increasing bmix
backup(VASP_BACKUP_FILES)
actions.append({"dict": "INCAR", "action": {"_set": {"AMIN": 0.01, "BMIX": 3.0, "ICHARG": 2}}})
if actions:
VaspModder(vi=vi).apply_actions(actions)
return {"errors": ["Non-converging job"], "actions": actions}
# Unfixable error. Just return None for actions.
else:
return {"errors": ["Non-converging job"], "actions": None}
示例4: test_lrf_comm
def test_lrf_comm(self):
h = LrfCommutatorHandler("std_err.txt")
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['lrf_comm'])
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["LPEAD"], True)
示例5: get_runs
def get_runs(vasp_command, target=1e-3, max_steps=10, mode="linear"):
energy = 0
vinput = VaspInput.from_directory(".")
kpoints = vinput["KPOINTS"].kpts[0]
for i in range(max_steps):
if mode == "linear":
m = [k * (i + 1) for k in kpoints]
else:
m = [k + 1 for k in kpoints]
if i == 0:
settings = None
backup = True
else:
backup = False
v = Vasprun("vasprun.xml")
e_per_atom = v.final_energy / len(v.final_structure)
ediff = abs(e_per_atom - energy)
if ediff < target:
logging.info("Converged to {} eV/atom!".format(ediff))
break
else:
energy = e_per_atom
settings = [
{"dict": "INCAR",
"action": {"_set": {"ISTART": 1}}},
{'dict': 'KPOINTS',
'action': {'_set': {'kpoints': [m]}}},
{"filename": "CONTCAR",
"action": {"_file_copy": {"dest": "POSCAR"}}}]
yield VaspJob(vasp_command, final=False, backup=backup,
suffix=".kpoints.{}".format("x".join(map(str, m))),
settings_override=settings)
示例6: test_check_correct
def test_check_correct(self):
h = VaspErrorHandler("vasp.teterror")
h.check()
d = h.correct()
self.assertEqual(d["errors"], ['tet'])
self.assertEqual(d["actions"],
[{'action': {'_set': {'ISMEAR': 0}},
'dict': 'INCAR'}])
h = VaspErrorHandler("vasp.teterror", errors_subset_to_catch=["eddrmm"])
self.assertFalse(h.check())
h = VaspErrorHandler("vasp.sgrcon")
h.check()
d = h.correct()
self.assertEqual(d["errors"], ['rot_matrix'])
self.assertEqual(set([a["dict"] for a in d["actions"]]),
{"KPOINTS"})
h = VaspErrorHandler("vasp.real_optlay")
h.check()
d = h.correct()
self.assertEqual(d["errors"], ['real_optlay'])
self.assertEqual(d["actions"],
[{'action': {'_set': {'LREAL': False}},
'dict': 'INCAR'}])
subdir = os.path.join(test_dir, "large_cell_real_optlay")
os.chdir(subdir)
shutil.copy("INCAR", "INCAR.orig")
h = VaspErrorHandler()
h.check()
d = h.correct()
self.assertEqual(d["errors"], ['real_optlay'])
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["LREAL"], True)
h.check()
d = h.correct()
self.assertEqual(d["errors"], ['real_optlay'])
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["LREAL"], False)
shutil.copy("INCAR.orig", "INCAR")
os.remove("INCAR.orig")
os.remove("error.1.tar.gz")
os.remove("error.2.tar.gz")
os.chdir(test_dir)
示例7: test_oom
def test_oom(self):
vi = VaspInput.from_directory(".")
from custodian.vasp.interpreter import VaspModder
VaspModder(vi=vi).apply_actions([{"dict": "INCAR",
"action": {"_set": {"KPAR": 4}}}])
h = StdErrHandler("std_err.txt.oom", correct_out_of_memory=True)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['out_of_memory'])
self.assertEqual(d["actions"],
[{'dict': 'INCAR',
'action': {'_set': {'KPAR': 2}}}])
h = StdErrHandler("std_err.txt.oom2", correct_out_of_memory=True)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['out_of_memory'])
self.assertEqual(d["actions"],
[{'dict': 'INCAR',
'action': {'_set': {'KPAR': 1}}}])
vi = VaspInput.from_directory(".")
from custodian.vasp.interpreter import VaspModder
VaspModder(vi=vi).apply_actions([{"dict": "INCAR",
"action": {"_set": {"KPAR": 4}}}])
h = StdErrHandler("std_err.txt.emlsp", correct_out_of_memory=True)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['out_of_memory'])
self.assertEqual(d["actions"],
[{'dict': 'INCAR',
'action': {'_set': {'KPAR': 2}}}])
vi = VaspInput.from_directory(".")
from custodian.vasp.interpreter import VaspModder
VaspModder(vi=vi).apply_actions([{"dict": "INCAR",
"action": {"_set": {"KPAR": 4}}}])
h = StdErrHandler("std_err.txt.insufficient_mem", correct_out_of_memory=True)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['out_of_memory'])
self.assertEqual(d["actions"],
[{'dict': 'INCAR',
'action': {'_set': {'KPAR': 2}}}])
示例8: check
def check(self):
vi = VaspInput.from_directory(".")
nelm = vi["INCAR"].get("NELM", 60)
try:
oszicar = Oszicar(self.output_filename)
esteps = oszicar.electronic_steps
if len(esteps) > self.nionic_steps:
return all([len(e) == nelm for e in esteps[-(self.nionic_steps + 1) : -1]])
except:
pass
return False
示例9: test_lrf_comm
def test_lrf_comm(self):
h = StdErrHandler("std_err.txt")
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['lrf_comm'])
vi = VaspInput.from_directory(".")
self.assertEqual(vi["INCAR"]["ISTART"], 1)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['lrf_comm'])
self.assertEqual(d["actions"], []) # don't correct twice
示例10: correct
def correct(self):
backup(VASP_BACKUP_FILES | {self.output_filename})
actions = []
vi = VaspInput.from_directory(".")
if "lrf_comm" in self.errors:
if Outcar(zpath(os.path.join(
os.getcwd(), "OUTCAR"))).is_stopped is False:
if not vi["INCAR"].get("LPEAD"):
actions.append({"dict": "INCAR",
"action": {"_set": {"LPEAD": True}}})
VaspModder(vi=vi).apply_actions(actions)
return {"errors": list(self.errors), "actions": actions}
示例11: test_seg_fault
def test_seg_fault(self):
vi = VaspInput.from_directory(".")
from custodian.vasp.interpreter import VaspModder
VaspModder(vi=vi).apply_actions([{"dict": "INCAR",
"action": {"_set": {"KPAR": 4}}}])
h = StdErrHandler("std_err.txt.seg_fault", correct_seg_fault=True)
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['seg_fault'])
self.assertEqual(d["actions"],
[{'dict': 'INCAR',
'action': {'_set': {'ISMEAR': '0'}}}])
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['seg_fault'])
# no fix if still seg fault
self.assertEqual(d["actions"], [])
示例12: __init__
def __init__(self, actions=None, strict=True, vi=None):
"""
Initializes a Modder for VaspInput sets
Args:
actions ([Action]): A sequence of supported actions. See
:mod:`custodian.ansible.actions`. Default is None,
which means DictActions and FileActions are supported.
strict (bool): Indicating whether to use strict mode. In non-strict
mode, unsupported actions are simply ignored without any
errors raised. In strict mode, if an unsupported action is
supplied, a ValueError is raised. Defaults to True.
vi (VaspInput): A VaspInput object from the current directory.
Initialized automatically if not passed (but passing it will
avoid having to reparse the directory).
"""
self.vi = vi or VaspInput.from_directory('.')
actions = actions or [FileActions, DictActions]
super(VaspModder, self).__init__(actions, strict)
示例13: run
def run(self):
"""
Perform the actual VASP run.
Returns:
(subprocess.Popen) Used for monitoring.
"""
cmd = list(self.vasp_cmd)
if self.auto_gamma:
vi = VaspInput.from_directory(".")
kpts = vi["KPOINTS"]
if kpts.style == "Gamma" and tuple(kpts.kpts[0]) == (1, 1, 1):
if self.gamma_vasp_cmd is not None and which(
self.gamma_vasp_cmd[-1]):
cmd = self.gamma_vasp_cmd
elif which(cmd[-1] + ".gamma"):
cmd[-1] += ".gamma"
logging.info("Running {}".format(" ".join(cmd)))
with open(self.output_file, 'w') as f:
p = subprocess.Popen(cmd, stdout=f)
return p
示例14: test_brmix
def test_brmix(self):
h = VaspErrorHandler("vasp.brmix")
self.assertEqual(h.check(), True)
d = h.correct()
self.assertEqual(d["errors"], ['brmix'])
vi = VaspInput.from_directory(".")
chgcar_exists = os.path.exists("CHGCAR")
if h.error_count['brmix'] > 1:
self.assertFalse(chgcar_exists)
else:
self.assertTrue(chgcar_exists)
if vi["KPOINTS"].style == Kpoints.supported_modes.Gamma and vi["KPOINTS"].num_kpts < 1:
all_kpts_even = all([
bool(n % 2 == 0) for n in vi["KPOINTS"].kpts[0]
])
self.assertFalse(all_kpts_even)
shutil.copy("INCAR.nelect", "INCAR")
h = VaspErrorHandler("vasp.brmix")
self.assertEqual(h.check(), False)
d = h.correct()
self.assertEqual(d["errors"], [])
示例15: run
def run(self):
"""
Perform the actual VASP run.
Returns:
(subprocess.Popen) Used for monitoring.
"""
cmd = list(self.vasp_cmd)
if self.auto_gamma:
vi = VaspInput.from_directory(".")
kpts = vi["KPOINTS"]
if kpts.style == Kpoints.supported_modes.Gamma \
and tuple(kpts.kpts[0]) == (1, 1, 1):
if self.gamma_vasp_cmd is not None and which(
self.gamma_vasp_cmd[-1]):
cmd = self.gamma_vasp_cmd
elif which(cmd[-1] + ".gamma"):
cmd[-1] += ".gamma"
logger.info("Running {}".format(" ".join(cmd)))
with open(self.output_file, 'w') as f_std, \
open(self.stderr_file, "w", buffering=1) as f_err:
# use line buffering for stderr
p = subprocess.Popen(cmd, stdout=f_std, stderr=f_err)
return p