def main(args): param = InputParams() for filename in [f for f in os.listdir() if f.endswith(".yaml")]: try: param = InputParams.from_file(filename) break except: continue pseudos = not (args.no_pseudos) positions = [ Posinp.from_file(args.positions_dir + file) for file in os.listdir(args.positions_dir) if file.endswith(".xyz") ] # Create directories os.makedirs("run_dir/", exist_ok=True) os.makedirs("saved_results/", exist_ok=True) os.chdir("run_dir/") for i in range(args.n_structs): j = int(np.random.choice(len(positions), 1)) posinp = generate_random_structure(positions[j]) run(posinp, i, args, param, pseudos)
def test_run_with_dry_run(self): with Job(inputparams=self.inp, name="dry_run", run_dir="tests") as job: # Run the calculation job.clean() assert not job.is_completed job.run(dry_run=True, nmpi=2, nomp=4) assert job.is_completed # There must be input and output files afterwards new_inp = InputParams.from_file(job.input_name) assert new_inp == self.inp new_pos = Posinp.from_file(job.posinp_name) assert new_pos == self.pos bigdft_tool_log = Logfile.from_file(job.logfile_name) assert bigdft_tool_log.energy is None
def test_run_with_dry_run_with_posinp(self): with Job(inputparams=self.inp, posinp=self.pos, name="dry_run", run_dir="tests") as job: job.clean() assert not job.is_completed job.run(dry_run=True, nmpi=2, nomp=4) assert job.is_completed # Make sure that input, posinp and output files are created new_inp = InputParams.from_file(job.input_name) assert new_inp == self.inp new_pos = Posinp.from_file(job.posinp_name) assert new_pos == self.pos bigdft_tool_log = Logfile.from_file(job.logfile_name) assert bigdft_tool_log.energy is None
def prepare_calculations(overwrite=False): r""" Determines which files are present and which need to be generated. Parameters: ------------- overwrite : bool (default : False) if True, the present files are ignored Returns: base_inp : InputParams base input parameters for the calculation base_pos : Posinp base atomic positions for the calculation jobname : string Name of the calculation if there is a pos file, string "jobname" if no position file. """ files = [f for f in os.listdir() if f.endswith((".xyz", ".yaml"))] posinp_is_present, jobname = verify_posinp(files) if verify_input(files): base_inp = InputParams.from_file("input.yaml") else: base_inp = InputParams() if posinp_is_present: base_pos = Posinp.from_file(jobname + ".xyz") elif base_inp.posinp is not None: base_pos = base_inp.posinp jobname = "jobname" base_pos.write(jobname + ".xyz") else: raise ValueError("No atomic positions are available.") return base_inp, base_pos, jobname
def main(args): initpos = generate_graphene_cell(args.xsize, args.zsize) param = InputParams() for filename in [f for f in os.listdir() if f.endswith(".yaml")]: try: param = InputParams.from_file(filename) break except: continue pseudos = not (args.no_pseudos) # Create directories os.makedirs("run_dir/", exist_ok=True) os.makedirs("saved_results/", exist_ok=True) os.chdir("run_dir/") if args.n_defects == 0: for i in range(1, args.n_structs + 1): posinp = generate_random_structure(initpos) run(posinp, i, args, param, pseudos) elif args.n_defects == 1: initpos, _ = place_first_nitrogen(initpos) for i in range(1, args.n_structs + 1): posinp = generate_random_structure(initpos) run(posinp, i, args, param, pseudos) elif args.n_defects == 2: initpos, first_idx = place_first_nitrogen(initpos) root = np.sqrt(args.n_structs) if root % 1 == 0: n_angle, n_radius = root, root else: n_angle, n_radius = np.ceil(root), np.floor(root) max_radius = np.max(np.array(initpos.cell) / 2) radiuses = np.linspace(1.0, max_radius, n_radius) angles = np.linspace(0, 2 * np.pi, n_angle) i = 0 # distances = np.zeros(int(n_angle * n_radius)) for theta in angles: for r in radiuses: i += 1 posinp, second_idx = place_second_nitrogen( initpos, theta, r, first_idx) # distances[i-1] = np.linalg.norm(posinp.positions[first_idx] - posinp.positions[second_idx]) run(posinp, i, args, param, pseudos) # np.savetxt("distances.data", distances) elif args.n_defects == 3: root = np.sqrt(args.n_structs) if root % 1 == 0: n_angle, n_radius = root, root else: n_angle, n_radius = np.ceil(root), np.floor(root) else: raise NotImplementedError("No method for this number of defects.")
def test_from_file(self): inp = InputParams.from_file(self.filename) assert inp == {}