def test_espresso_input_edit(): """ Load a structure in from qe_input_1, change the position and cell, then edit and re-parse :return: """ os.system('cp test_files/qe_input_1.in .') positions, species, cell, masses = parse_dft_input('./qe_input_1.in') _, coded_species = get_unique_species(species) structure = Structure(cell, coded_species, positions, masses, species_labels=species) structure.vec1 += np.random.randn(3) structure.positions[0] += np.random.randn(3) new_file = edit_dft_input_positions('./qe_input_1.in', structure=structure) positions, species, cell, masses = parse_dft_input(new_file) assert np.equal(positions[0], structure.positions[0]).all() assert np.equal(structure.vec1, cell[0, :]).all() os.remove('qe_input_1.in')
def test_cp2k_input_edit(): """ Load a structure in from cp2k_input_1, change the position and cell, then edit and re-parse :return: """ positions, species, cell, masses = parse_dft_input( "./test_files/cp2k_input_1.in") _, coded_species = get_unique_species(species) structure = Structure(cell, coded_species, positions, masses, species_labels=species) structure.positions[0] += np.random.randn(3) newfilename = edit_dft_input_positions("./test_files/cp2k_input_1.in", structure=structure) positions, species, cell, masses = parse_dft_input(newfilename) assert np.isclose(positions[0], structure.positions[0]).all() assert np.isclose(structure.vec1, cell[0, :]).all() remove(newfilename) cleanup()
def dft_input_to_structure(qe_input: str): """ Parses a qe input and returns the atoms in the file as a Structure object :param qe_input: QE Input file to parse :return: """ positions, species, cell, masses = parse_dft_input(qe_input) _, coded_species = struc.get_unique_species(species) return struc.Structure(positions=positions, species=coded_species, cell=cell, mass_dict=masses, species_labels=species)
def __init__(self, dft_input: str, dt: float, number_of_steps: int, gp: gp.GaussianProcess, dft_loc: str, std_tolerance_factor: float = 1, prev_pos_init: np.ndarray = None, par: bool = False, skip: int = 0, init_atoms: List[int] = None, calculate_energy=False, output_name='otf_run', max_atoms_added=1, freeze_hyps=10, rescale_steps=[], rescale_temps=[], dft_softwarename="qe", no_cpus=1, npool=None, mpi="srun"): self.dft_input = dft_input self.dt = dt self.number_of_steps = number_of_steps self.gp = gp self.dft_loc = dft_loc self.std_tolerance = std_tolerance_factor self.skip = skip self.dft_step = True self.freeze_hyps = freeze_hyps self.dft_module = dft_software[dft_softwarename] # parse input file positions, species, cell, masses = \ self.dft_module.parse_dft_input(self.dft_input) _, coded_species = struc.get_unique_species(species) self.structure = struc.Structure(cell=cell, species=coded_species, positions=positions, mass_dict=masses, prev_positions=prev_pos_init, species_labels=species) self.noa = self.structure.positions.shape[0] self.atom_list = list(range(self.noa)) self.curr_step = 0 self.max_atoms_added = max_atoms_added # initialize local energies if calculate_energy: self.local_energies = np.zeros(self.noa) else: self.local_energies = None # set atom list for initial dft run if init_atoms is None: self.init_atoms = [int(n) for n in range(self.noa)] else: self.init_atoms = init_atoms self.dft_count = 0 # set pred function if not par and not calculate_energy: self.pred_func = predict.predict_on_structure elif par and not calculate_energy: self.pred_func = predict.predict_on_structure_par elif not par and calculate_energy: self.pred_func = predict.predict_on_structure_en elif par and calculate_energy: self.pred_func = predict.predict_on_structure_par_en self.par = par # set rescale attributes self.rescale_steps = rescale_steps self.rescale_temps = rescale_temps self.output = Output(output_name, always_flush=True) # set number of cpus and npool for qe runs self.no_cpus = no_cpus self.npool = npool self.mpi = mpi