def test_rhosyg_vasp6(self): h = VaspErrorHandler("vasp6.rhosyg") self.assertEqual(h.check(), True) self.assertEqual(h.correct()["errors"], ["rhosyg"]) i = Incar.from_file("INCAR") self.assertEqual(i["SYMPREC"], 1e-4) self.assertEqual(h.correct()["errors"], ["rhosyg"]) i = Incar.from_file("INCAR") self.assertEqual(i["ISYM"], 0)
def test_eddrmm(self): h = VaspErrorHandler("vasp.eddrmm") self.assertEqual(h.check(), True) self.assertEqual(h.correct()["errors"], ["eddrmm"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Normal") self.assertEqual(h.correct()["errors"], ["eddrmm"]) i = Incar.from_file("INCAR") self.assertEqual(i["POTIM"], 0.25)
def test_too_large_kspacing(self): shutil.copy("INCAR.kspacing", "INCAR") vi = VaspInput.from_directory(".") h = VaspErrorHandler("vasp.teterror") h.check() d = h.correct() self.assertEqual(d["errors"], ['tet']) self.assertEqual(d["actions"], [{'action': {"_set": {"KSPACING": vi["INCAR"].get("KSPACING")*0.8}},'dict': 'INCAR'}])
def test_first_step(self): shutil.copy("OSZICAR.empty", "OSZICAR") s1 = Structure.from_file("POSCAR") h = VaspErrorHandler("vasp.out") self.assertEqual(h.check(), True) d = h.correct() self.assertEqual(d["errors"], ["zpotrf"]) s2 = Structure.from_file("POSCAR") self.assertAlmostEqual(s2.volume, s1.volume * 1.2**3, 3)
def test_potim_correction(self): shutil.copy("OSZICAR.one_step", "OSZICAR") s1 = Structure.from_file("POSCAR") h = VaspErrorHandler("vasp.out") self.assertEqual(h.check(), True) d = h.correct() self.assertEqual(d['errors'], ['zpotrf']) s2 = Structure.from_file("POSCAR") self.assertAlmostEqual(s2.volume, s1.volume, 3) self.assertAlmostEqual(Incar.from_file("INCAR")['POTIM'], 0.25)
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.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)
def test_posmap_vasp6(self): h = VaspErrorHandler("vasp6.posmap") self.assertEqual(h.check(), True) self.assertEqual(h.correct()["errors"], ["posmap"]) i = Incar.from_file("INCAR") self.assertAlmostEqual(i["SYMPREC"], 1e-6) self.assertEqual(h.check(), True) self.assertEqual(h.correct()["errors"], ["posmap"]) i = Incar.from_file("INCAR") self.assertAlmostEqual(i["SYMPREC"], 1e-4)
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, "SIGMA": 0.05 } }, "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({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" }])
def test_too_few_bands(self): os.chdir(os.path.join(test_dir, "too_few_bands")) shutil.copy("INCAR", "INCAR.orig") h = VaspErrorHandler("vasp.too_few_bands") h.check() d = h.correct() self.assertEqual(d["errors"], ['too_few_bands']) self.assertEqual(d["actions"], [{'action': {'_set': {'NBANDS': 501}}, 'dict': 'INCAR'}]) clean_dir() shutil.move("INCAR.orig", "INCAR") os.chdir(test_dir)
def test_dentet(self): h = VaspErrorHandler("vasp.dentet") h.check() d = h.correct() self.assertEqual(d["errors"], ['dentet']) self.assertEqual(d["actions"], [{ 'action': { '_set': { 'ISMEAR': 0 } }, 'dict': 'INCAR' }])
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.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'}])
def run_task(self, fw_spec): handler_groups = { "default": [VaspErrorHandler(), MeshSymmetryErrorHandler(), UnconvergedErrorHandler(), NonConvergingErrorHandler(),PotimErrorHandler(), PositiveEnergyErrorHandler(), FrozenJobErrorHandler(), StdErrHandler(), DriftErrorHandler()], "strict": [VaspErrorHandler(), MeshSymmetryErrorHandler(), UnconvergedErrorHandler(), NonConvergingErrorHandler(),PotimErrorHandler(), PositiveEnergyErrorHandler(), FrozenJobErrorHandler(), StdErrHandler(), AliasingErrorHandler(), DriftErrorHandler()], "md": [VaspErrorHandler(), NonConvergingErrorHandler()], "no_handler": [] } vasp_cmd = env_chk(self["vasp_cmd"], fw_spec) if isinstance(vasp_cmd, six.string_types): vasp_cmd = os.path.expandvars(vasp_cmd) vasp_cmd = shlex.split(vasp_cmd) # initialize variables scratch_dir = env_chk(self.get("scratch_dir"), fw_spec) gzip_output = self.get("gzip_output", True) max_errors = self.get("max_errors", 5) auto_npar = env_chk(self.get("auto_npar"), fw_spec, strict=False, default=False) gamma_vasp_cmd = env_chk(self.get("gamma_vasp_cmd"), fw_spec, strict=False, default=None) jobs = [VaspJob(vasp_cmd, auto_npar=auto_npar, gamma_vasp_cmd=gamma_vasp_cmd)] # construct handlers handlers = handler_groups[self.get("handler_group", "default")] validators = [] c = Custodian(handlers, jobs, validators=validators, max_errors=max_errors, scratch_dir=scratch_dir, gzipped_output=gzip_output) c.run()
def do_run(args): handlers = [VaspErrorHandler(), UnconvergedErrorHandler()] c = Custodian( handlers, get_runs( vasp_command=args.command.split(), target=args.target, mode=args.mode, max_steps=args.max_steps, ), max_errors=10, ) c.run()
def test_rot_matrix(self): if "PMG_VASP_PSP_DIR" not in os.environ: os.environ["PMG_VASP_PSP_DIR"] = test_dir subdir = os.path.join(test_dir, "poscar_error") os.chdir(subdir) shutil.copy("KPOINTS", "KPOINTS.orig") h = VaspErrorHandler() h.check() d = h.correct() self.assertEqual(d["errors"], ["rot_matrix"]) os.remove(os.path.join(subdir, "error.1.tar.gz")) shutil.copy("KPOINTS.orig", "KPOINTS") os.remove("KPOINTS.orig")
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"], [])
def do_run(args): handlers = [ VaspErrorHandler(), MeshSymmetryErrorHandler(), UnconvergedErrorHandler(), NonConvergingErrorHandler(), PotimErrorHandler() ] c = Custodian(handlers, get_runs(args), max_errors=10, gzipped_output=args.gzip) c.run() logging.info("Geometry optimization complete")
def test_subspace(self): h = VaspErrorHandler("vasp.subspace") h.check() d = h.correct() self.assertEqual(d["errors"], ['subspacematrix']) self.assertEqual(d["actions"], [{'action': {'_set': {'LREAL': False}}, 'dict': 'INCAR'}]) # 2nd error should set PREC to accurate. h.check() d = h.correct() self.assertEqual(d["errors"], ['subspacematrix']) self.assertEqual(d["actions"], [{'action': {'_set': {'PREC': 'Accurate'}}, 'dict': 'INCAR'}])
def test_dentet(self): h = VaspErrorHandler("vasp.dentet") h.check() d = h.correct() self.assertEqual(d["errors"], ["dentet"]) self.assertEqual( d["actions"], [{ "action": { "_set": { "ISMEAR": 0, "SIGMA": 0.05 } }, "dict": "INCAR" }], )
def test_too_few_bands(self): os.chdir(os.path.join(test_dir, "too_few_bands")) shutil.copy("INCAR", "INCAR.orig") h = VaspErrorHandler("vasp.too_few_bands") h.check() d = h.correct() self.assertEqual(d["errors"], ["too_few_bands"]) self.assertEqual(d["actions"], [{ "action": { "_set": { "NBANDS": 501 } }, "dict": "INCAR" }]) clean_dir() shutil.move("INCAR.orig", "INCAR") os.chdir(test_dir)
def test_gradient_not_orthogonal(self): h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Fast") shutil.copy("INCAR.gga_all", "INCAR") i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "All") h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Normal") shutil.copy("INCAR.hybrid_normal", "INCAR") i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Normal") h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Normal") shutil.copy("INCAR.hybrid_all", "INCAR") i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "All") h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "All") shutil.copy("INCAR.metagga_all", "INCAR") i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "All") h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "All") shutil.copy("INCAR.metagga_fast", "INCAR") i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Fast") h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertIn("grad_not_orth", h.correct()["errors"]) i = Incar.from_file("INCAR") self.assertEqual(i["ALGO"], "Fast")
def get_custodian_task(spec): task_type = spec['task_type'] v_exe = 'VASP_EXE' # will be transformed to vasp executable on the node handlers = [VaspErrorHandler(), FrozenJobErrorHandler(), MeshSymmetryErrorHandler(), NonConvergingErrorHandler(), PositiveEnergyErrorHandler()] if 'optimize structure (2x)' in task_type: jobs = VaspJob.double_relaxation_run(v_exe) elif 'static' in task_type or 'deformed' in task_type: jobs = [VaspJob(v_exe)] else: # non-SCF runs jobs = [VaspJob(v_exe)] handlers = [] params = {'jobs': [j_decorate(j.as_dict()) for j in jobs], 'handlers': [h.as_dict() for h in handlers], 'max_errors': 5} return VaspCustodianTask(params)
def run_task(self, fw_spec): directory = self.get("directory", os.getcwd()) os.chdir(directory) stdout_file = self.get("stdout_file", os.path.join(directory, "vasp.out")) stderr_file = self.get("stderr_file", os.path.join(directory, "vasp.out")) vasp_cmd = fw_spec["_fw_env"]["vasp_cmd"].split(" ") default_handlers = [VaspErrorHandler(), UnconvergedErrorHandler()] handlers = self.get("handlers", default_handlers) for handler in handlers: handler.output_filename = stdout_file jobs = [VaspJob(vasp_cmd=vasp_cmd, output_file=stdout_file, stderr_file=stderr_file, auto_npar=False)] c = Custodian(handlers, jobs, max_errors=10, monitor_freq=self.get("monitor_freq", 30)) c.run()
def run_task(self, fw_spec): directory = os.path.abspath(self["directory"]) os.chdir(directory) output = os.path.join(directory, "out") # TODO Make the output file more general vasp_cmd = fw_spec["_fw_env"]["vasp_command"] handlers = [ VaspErrorHandler(output_filename=output), UnconvergedErrorHandler(output_filename=output) ] jobs = [ VaspJob(vasp_cmd=vasp_cmd, output_file=output, stderr_file=output, auto_npar=False) ] c = Custodian(handlers, jobs, max_errors=10) c.run()
def test_brions(self): shutil.copy("INCAR.ibrion", "INCAR") h = VaspErrorHandler("vasp.brions") h.check() d = h.correct() self.assertEqual(d["errors"], ["brions"]) i = Incar.from_file("INCAR") self.assertEqual(i["IBRION"], 1) self.assertAlmostEqual(i["POTIM"], 1.5) h.check() d = h.correct() self.assertEqual(d["errors"], ["brions"]) i = Incar.from_file("INCAR") self.assertEqual(i["IBRION"], 2) self.assertAlmostEqual(i["POTIM"], 1.4) h.check() d = h.correct() self.assertEqual(d["errors"], ["brions"]) i = Incar.from_file("INCAR") self.assertEqual(i["IBRION"], 2) self.assertAlmostEqual(i["POTIM"], 1.5)
def run_task(self, fw_spec): directory = os.path.abspath(self["directory"]) os.chdir(directory) stdout_file = self.get("stdout_file", os.path.join(self["directory"], "out")) stderr_file = self.get("stderr_file", os.path.join(self["directory"], "out")) vasp_cmd = fw_spec["_fw_env"]["vasp_cmd"].split(" ") handlers = [ VaspErrorHandler(output_filename=stdout_file), UnconvergedErrorHandler(output_filename=stdout_file) ] jobs = [ VaspJob(vasp_cmd=vasp_cmd, output_file=stdout_file, stderr_file=stderr_file, auto_npar=False) ] c = Custodian(handlers, jobs, max_errors=10) c.run()
def run_task(self, fw_spec): dec = MontyDecoder() jobs = dec.process_decoded(self["jobs"]) fw_env = fw_spec.get("_fw_env", {}) #Override VASP and gamma VASP commands using fw_env if fw_env.get("vasp_cmd"): for j in jobs: j.vasp_cmd = os.path.expandvars(fw_env["vasp_cmd"]) j.gamma_vasp_cmd = j.gamma_vasp_cmd logging.info("Vasp command is {}".format(j.vasp_cmd)) if fw_env.get("gamma_vasp_cmd"): for j in jobs: j.gamma_vasp_cmd = os.path.expandvars(fw_env["gamma_vasp_cmd"]) logging.info("Vasp gamma command is {}".format( j.gamma_vasp_cmd)) #Override custodian scratch dir. cust_params = self.get("custodian_params", {}) if fw_env.get("scratch_root"): cust_params["scratch_dir"] = os.path.expandvars( fw_env["scratch_root"]) logging.info("Running with custodian params %s" % cust_params) handlers = [ VaspErrorHandler(), MeshSymmetryErrorHandler(), UnconvergedErrorHandler(), NonConvergingErrorHandler(), PotimErrorHandler() ] validators = [VasprunXMLValidator()] c = Custodian(handlers=[h.as_dict() for h in handlers], jobs=jobs, validators=[v.as_dict() for v in validators], **cust_params) output = c.run() return FWAction(stored_data=output)
launch_dir = launch_dir.replace( 'garden/dev', 'garden') try: os.chdir(launch_dir) except: print ' |===> could not find launch directory in usual locations' lpdb.rerun_fw(fw['fw_id']) print ' |===> marked for RERUN' counter['LOCATION_NOT_FOUND'] += 1 continue print ' |===>', launch_dir vaspout = os.path.join(launch_dir, "vasp.out") if not os.path.exists(vaspout): vaspout = os.path.join(launch_dir, "vasp.out.gz") try: h = VaspErrorHandler(vaspout) h.check() d = h.correct() except: counter['GGA_static_Handler_Error'] += 1 if d['errors']: for err in d['errors']: counter['GGA_static_' + err] += 1 if 'brmix' in d['errors']: #lpdb.rerun_fw(fw['fw_id']) print ' |===> BRMIX error -> marked for RERUN with alternative strategy' else: print ' |===> no vasp error indicated -> TODO' counter['GGA_STATIC_NO_VASP_ERROR'] += 1 os.chdir(cwd) else:
def test_gradient_not_orthogonal(self): h = VaspErrorHandler("vasp.gradient_not_orthogonal") self.assertEqual(h.check(), True) self.assertEqual(h.correct()["errors"], ["grad_not_orth"]) i = Incar.from_file("INCAR") self.assertEqual(i["ISMEAR"], 0)
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from custodian.vasp.jobs import VaspJob as cvj from custodian.vasp.validators import VaspFilesValidator, VasprunXMLValidator from custodian.vasp.handlers import VaspErrorHandler,UnconvergedErrorHandler, \ NonConvergingErrorHandler,FrozenJobErrorHandler,StdErrHandler,\ WalltimeHandler,PositiveEnergyErrorHandler from custodian import Custodian import argparse handlers = [ VaspErrorHandler(), FrozenJobErrorHandler(), StdErrHandler(), NonConvergingErrorHandler(), WalltimeHandler(), PositiveEnergyErrorHandler(), UnconvergedErrorHandler() ] validators = [VaspFilesValidator(), VasprunXMLValidator()] def runvasp(cmd, opt=False, max_errors=3, backup=False, auto_gamma=False, auto_npar=False, ediffg=-.05): """
def structure_to_wf(structure): """ This method starts with a Structure object and creates a Workflow object The workflow has two steps - a structure relaxation and a static run :param structure: :return: """ fws = [] # list of FireWorks to run connections = defaultdict(list) # dependencies between FireWorks # generate VASP input objects for 1st VASP run - this is put in the FW spec mpvis = MPGGAVaspInputSet(user_incar_settings={'NPAR': 2}) incar = mpvis.get_incar(structure) poscar = mpvis.get_poscar(structure) kpoints = mpvis.get_kpoints(structure) potcar = mpvis.get_potcar(structure) # serialize the VASP input objects to the FW spec spec = {} spec['vasp'] = {} spec['vasp']['incar'] = incar.as_dict() spec['vasp']['poscar'] = poscar.as_dict() spec['vasp']['kpoints'] = kpoints.as_dict() spec['vasp']['potcar'] = potcar.as_dict() spec['vaspinputset_name'] = mpvis.__class__.__name__ spec['task_type'] = 'GGA optimize structure (2x) example' # set up the custodian that we want to run jobs = VaspJob.double_relaxation_run('') for j in jobs: # turn off auto npar, it doesn't work for >1 node j.auto_npar = False handlers = [ VaspErrorHandler(), FrozenJobErrorHandler(), MeshSymmetryErrorHandler(), NonConvergingErrorHandler() ] c_params = { 'jobs': [j.as_dict() for j in jobs], 'handlers': [h.as_dict() for h in handlers], 'max_errors': 5 } custodiantask = VaspCustodianTaskEx(c_params) # 1st Firework - run GGA optimize structure # VaspWriterTask - write input files (INCAR, POSCAR, KPOINTS, POSCAR) based on spec # CustodianTaskEx - run VASP within a custodian tasks = [VaspWriterTask(), custodiantask] fws.append( Firework(tasks, spec, name=get_name(structure, spec['task_type']), fw_id=1)) # 2nd Firework - insert previous run into DB spec = {'task_type': 'VASP db insertion example'} fws.append( Firework([VaspToDBTaskEx()], spec, name=get_name(structure, spec['task_type']), fw_id=2)) connections[1] = [2] # 3rd Firework - static run. # VaspCopyTask - copy output from previous run to this directory # SetupStaticRunTask - override old parameters for static run # CustodianTaskEx - run VASP within a custodian spec = {'task_type': 'GGA static example'} copytask = VaspCopyTask({'use_CONTCAR': True, 'skip_CHGCAR': True}) setuptask = SetupStaticRunTask() custodiantask = VaspCustodianTaskEx({ 'jobs': [VaspJob('', auto_npar=False).as_dict()], 'handlers': [h.as_dict() for h in handlers], 'max_errors': 5 }) fws.append( Firework([copytask, setuptask, custodiantask], spec, name=get_name(structure, spec['task_type']), fw_id=3)) connections[2] = [3] # 4th Firework - insert previous run into DB spec = {'task_type': 'VASP db insertion example'} fws.append( Firework([VaspToDBTaskEx()], spec, name=get_name(structure, spec['task_type']), fw_id=4)) connections[3] = [4] return Workflow(fws, connections, name=get_slug(structure.formula))