def write_convergence_tests(args, conv_params): """Write convergence tests for each parameter to check Args: args (dict): arguments passed from the command line. conv_params: convergence test parameters red from a .conv file. Returns: folder_names (list): list of folder paths that were created for each of the convergence tests. """ # Get folder containing DFTB+ structure if os.path.isdir(args.seedname): path = os.path.join(args.seedname, "geo_end.gen") struct = io.read(path, format="gen") else: raise RuntimeError("Input seed must be a folder") params = load_input_file(args.parameter_file) kpt_range = range(conv_params['kpoint_n_min'], conv_params['kpoint_n_max'] + 1) folder_names = [] for num_kpts in kpt_range: params['k_points_grid'] = np.array([num_kpts] * 3) ext = "_k{}".format(num_kpts) name = os.path.basename(args.seedname) + ext folder_name = safe_create_folder(name) save_dftb_format(struct, folder_name, params) folder_names.append(folder_name) return folder_names
def generate_single_structure(struct, params, batch_path=''): """Generate input files for a single structure and configuration file""" atoms = generate_structure_defects(struct, params).structures[0] # (Re)Create the output folder output_folder = os.path.join(batch_path, params['out_folder']) output_folder = safe_create_folder(output_folder) # Now save in the appropriate format save_funcs = {'castep': save_castep_format, 'dftb+': save_dftb_format} # Which calculators? calcs = map(lambda s: s.strip(), params['calculator'].split(',')) if 'all' in calcs: calcs = save_funcs.keys() for cname in calcs: try: os.mkdir(os.path.join(output_folder, cname)) except OSError: continue fold = os.path.join(output_folder, cname, params['name']) os.mkdir(fold) save_funcs[cname](atoms, fold, params)
def main(): description = """Convert DFTB+ input files to CASTEP input files""" parser = ap.ArgumentParser( description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) parser.add_argument('input', type=str, help="""DFTB+ .gen file or folder of .gen files to convert to CASTEP .cell file(s)""") parser.add_argument('param_file', type=str, help="""YAML parameters file to convert to CASTEP param file""") parser.add_argument('--output', type=str, default=".", help='Output directory to place generated files') args = parser.parse_args() param_file = args.param_file if os.path.isfile(args.input): gen_file = args.input convert_single_structure(gen_file, param_file, args.output) elif os.path.isdir(args.input): directory = args.input gen_files = get_all_folders_containing_pattern("*.gen", directory) base_output = safe_create_folder(args.output) for gen_file in gen_files: output = os.path.join(base_output, os.path.basename(gen_file)) os.mkdir(output) gen_file = os.path.join(gen_file, "geo_end.gen") convert_single_structure(gen_file, param_file, directory=output)
def main(): description = """Convert CASTEP .cell files to DFTB+ .gen files""" parser = ap.ArgumentParser( description=description, formatter_class=ap.ArgumentDefaultsHelpFormatter) parser.add_argument('input', type=str, help='CASTEP .cell file to convert to DFTB+ .gen file') parser.add_argument('param_file', type=str, help='CASTEP .param file to convert to DFTB+ .in file') parser.add_argument('--output', type=str, default=".", help='Output folder to save file to') args = parser.parse_args() param_file = args.param_file if os.path.isfile(args.input): cell_file = args.input convert_single_structure(cell_file, param_file, directory=args.output) elif os.path.isdir(args.input): directory = args.input cell_files = glob.glob(os.path.join(directory, "*.cell")) base_output = safe_create_folder(args.output) for cell_file in cell_files: output = os.path.join( base_output, os.path.basename(cell_file.replace(".cell", ""))) os.mkdir(output) convert_single_structure(cell_file, param_file, directory=output)
def create_batch_tests(args): pattern = os.path.join(os.path.abspath(args.structure), "*.cif") structure_files = glob.glob(pattern) params = load_input_file(args.parameter_file) conv_params = yaml.load(open(args.conv_file, 'r')) if 'castep_param' in params: params['castep_param'] = os.path.abspath(params['castep_param']) batch_path = safe_create_folder(params['batch_name']) os.chdir(batch_path) for file_name in structure_files: struct = io.read(file_name) params['out_folder'] = os.path.basename(file_name)[:-4] params['name'] = os.path.basename(file_name)[:-4] create_convergence_test(struct, params, conv_params, args.parameter_file, args.conv_file)
def main(): description = """Convert a folder containing the raw output files of CASTEP and/or DFTB+ results to a folder of pickled ase.Atoms objects. The output folder will mimic the folder structure of the input folder, but will contain only *.pkl files. Each pickle file is a ASE atoms object with a single point calculator attached to it. """ parser = ap.ArgumentParser(description=description) parser.add_argument('input', type=str, default=None, help="""Folder containing castep and DFTB+ result files. For CASTEP the program will search for *-out.cell files to load. For DFTB+ it will search for either result.tag files or for *.json files. The former is that standard outpt of DFTB+. The latter is output from batch_dftb+ when run with the --precon option.""") parser.add_argument('output', type=str, default=None, help="Output folder to store pickled structures in") args = parser.parse_args() args.output = safe_create_folder(args.output) # Find all files in the input directory all_files = [ os.path.join(dir_name, file_name) for dir_name, folders, files in os.walk(args.input) for file_name in files ] cell_files = filter(lambda x: x.endswith("-out.cell"), all_files) json_files = filter(lambda x: x.endswith(".json"), all_files) tag_files = filter(lambda x: x.endswith(".tag"), all_files) pickle_structures(load_castep, cell_files, args.output) pickle_structures(load_dftb_precon, json_files, args.output) pickle_structures(load_dtfb, tag_files, args.output)