def test_otf_parser(md_engine): output_name = f"{md_engine}.out" otf_traj = OtfAnalysis(output_name) try: replicated_gp = otf_traj.make_gp() except: init_flare = FLARE_Calculator.from_file(md_engine + "_flare.json") replicated_gp = otf_traj.make_gp(init_gp=init_flare.gp_model) print("ase otf traj parsed") for f in glob.glob(md_engine + "*"): os.remove(f)
def test_otf_parser(md_engine): output_name = f"{md_engine}.out" otf_traj = OtfAnalysis(output_name) try: replicated_gp = otf_traj.make_gp() except: init_flare = FLARE_Calculator.from_file(md_engine + "_flare.json") replicated_gp = otf_traj.make_gp(init_gp=init_flare.gp_model) print("ase otf traj parsed") # Check that the GP forces change. comp1 = otf_traj.force_list[0][1, 0] comp2 = otf_traj.force_list[-1][1, 0] assert (comp1 != comp2) for f in glob.glob(md_engine + "*"): os.remove(f)
def test_otf_parser(md_engine, write_model): output_name = f"{md_engine}_{write_model}" otf_traj = OtfAnalysis(output_name + ".out") try: replicated_gp = otf_traj.make_gp() except: init_flare = FLARE_Calculator.from_file(output_name + "_flare.json") replicated_gp = otf_traj.make_gp(init_gp=init_flare.gp_model) print("ase otf traj parsed") # Check that the GP forces change. comp1 = otf_traj.force_list[-2][1, 0] comp2 = otf_traj.force_list[-1][1, 0] assert comp1 != comp2 for f in glob.glob(output_name + "*"): os.remove(f) for f in glob.glob("*_ckpt_*"): shutil.rmtree(f, ignore_errors=True)
def from_dict(dct): flare_calc_dict = json.load(open(dct["flare_calc"])) # Build FLARE_Calculator from dict if flare_calc_dict["class"] == "FLARE_Calculator": flare_calc = FLARE_Calculator.from_file(dct["flare_calc"]) _kernels = None # Build SGP_Calculator from dict # TODO: we still have the issue that the c++ kernel needs to be # in the current space, otherwise there is Seg Fault # That's why there is the _kernels elif flare_calc_dict["class"] == "SGP_Calculator": from flare_pp.sparse_gp_calculator import SGP_Calculator flare_calc, _kernels = SGP_Calculator.from_file(dct["flare_calc"]) else: raise TypeError( f"The calculator from {dct['flare_calc']} is not recognized." ) flare_calc.reset() dct["atoms"] = read(dct["atoms"]) dct["calculator"] = flare_calc dct.pop("gp") with open(dct["dft_loc"], "rb") as f: dct["dft_calc"] = pickle.load(f) for key in ["dt", "dft_loc"]: dct.pop(key) new_otf = ASE_OTF(**dct) new_otf._kernels = _kernels new_otf.dft_count = dct["dft_count"] new_otf.curr_step = dct["curr_step"] new_otf.std_tolerance = dct["std_tolerance"] if new_otf.md_engine == "NPT": if not new_otf.md.initialized: new_otf.md.initialize() return new_otf
def from_dict(dct): flare_calc = FLARE_Calculator.from_file(dct["flare_calc"]) flare_calc.reset() dct["atoms"] = read(dct["atoms"]) dct["atoms"].calc = flare_calc dct.pop("gp") with open(dct["dft_loc"], "rb") as f: dct["dft_calc"] = pickle.load(f) for key in ["dt", "dft_loc"]: dct.pop(key) new_otf = ASE_OTF(**dct) new_otf.dft_count = dct["dft_count"] new_otf.curr_step = dct["curr_step"] if new_otf.md_engine == "NPT": if not new_otf.md.initialized: new_otf.md.initialize() return new_otf
def from_dict(dct): flare_calc = FLARE_Calculator.from_file(dct["flare_calc"]) # https://github.com/mir-group/flare/commit/88efe67e28f2b6a9cb5c6662675aad0209af134d flare_calc.reset() dct["atoms"] = read(dct["atoms"]) dct["atoms"].calc = flare_calc dct.pop("gp") with open(dct["dft_loc"], "rb") as f: dct["dft_calc"] = pickle.load(f) for key in ["dt", "dft_loc"]: dct.pop(key) new_otf = ASE_OTF(**dct) new_otf.dft_count = dct["dft_count"] new_otf.curr_step = dct["curr_step"] new_otf.std_tolerance = dct["std_tolerance"] if new_otf.md_engine == "NPT": if not new_otf.md.initialized: new_otf.md.initialize() return new_otf