def read_data( verbose=True ): dir_list = find_vasp_calculations() if not dir_list: raise ValueError( 'Did not find any subdirectories containing vasprun.xml or vasprun.xml.gz files' ) data = [] for d in dir_list: converged = True try: with warnings.catch_warnings(record=True) as w: vasprun = read_vasprun( match_filename( d + 'vasprun.xml' ) ) for warning in w: if isinstance( warning.message, UnconvergedVASPWarning ): converged = False else: print( warning.message ) except: continue poscar = Poscar.from_file( d + 'POSCAR' ) data.append( [ poscar.scaling, vasprun.final_structure.volume, vasprun.final_energy, converged ] ) column_titles = [ 'scaling', 'volume', 'energy', 'converged' ] df = pd.DataFrame( data, columns=column_titles ).sort_values( by='scaling' ) df = df.reset_index( drop=True ) df['scaling_factor'] = df.volume / df.scaling**3 scaling_factor_round = 4 if verbose: print( df.to_string(index=False) ) if len( set( df.scaling_factor.round( scaling_factor_round ) ) ) != 1: raise ValueError( "POSCAR scaling factors and volumes are inconsistent" ) return df
def main(): supported_flags = Summary.supported_flags to_print = [ 'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy', 'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion', 'converged', 'version', 'md5', 'directory' ] titles = None args = get_args() if args.list: for k, v, in supported_flags.items(): print("{}: {}".format(k.ljust(15), v)) sys.exit() if args.file: with open(args.file, 'r') as stream: settings = yaml.load(stream) if 'to_print' in settings: to_print = settings['to_print'] if 'titles' in settings: titles = settings['titles'] if args.print: not_supported = [p for p in args.print if p not in supported_flags] if not_supported: raise ValueError(not_supported) else: to_print = args.print if args.recursive: path = sorted(find_vasp_calculations()) else: path = ['.'] if args.check: for p in path: vaspmeta = Path('{}/vaspmeta.yaml'.format(p)) if not vaspmeta.is_file(): print('{} is missing vaspmeta.yaml'.format(p)) vasprun = Path('{}/vasprun.xml'.format(p)) if not vasprun.is_file(): print('{} is missing vasprun.xml'.format(p)) else: if titles: # Only parse directories with matching vasp_meta titles matching_path = [] for p in path: vm = VASPMeta.from_file('{}/vaspmeta.yaml'.format(p)) if vm.title in titles: matching_path.append(p) path = matching_path for p in path: s = Summary(p) s.output(to_print=to_print)
def main(): supported_flags = Summary.supported_flags to_print=[ 'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy', 'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion', 'converged', 'version', 'md5', 'directory' ] titles = None args = get_args() if args.list: for k, v, in supported_flags.items(): print( "{}: {}".format( k.ljust(15), v ) ) sys.exit() if args.file: with open( args.file, 'r' ) as stream: settings = yaml.load( stream, Loader=yaml.SafeLoader ) if 'to_print' in settings: to_print = settings['to_print'] if 'titles' in settings: titles = settings['titles'] if args.print: not_supported = [ p for p in args.print if p not in supported_flags ] if not_supported: raise ValueError( not_supported ) else: to_print = args.print if args.recursive: path = sorted( find_vasp_calculations() ) else: path = [ '.' ] if args.check: for p in path: vaspmeta = Path( '{}/vaspmeta.yaml'.format( p ) ) if not vaspmeta.is_file(): print( '{} is missing vaspmeta.yaml'.format( p ) ) vasprun = Path( '{}/vasprun.xml'.format( p ) ) if not vasprun.is_file(): print( '{} is missing vasprun.xml'.format( p ) ) else: if titles: # Only parse directories with matching vasp_meta titles matching_path = [] for p in path: vm = VASPMeta.from_file( '{}/vaspmeta.yaml'.format(p) ) if vm.title in titles: matching_path.append( p ) path = matching_path for p in path: s = Summary( p ) s.output( to_print=to_print )
def main(): parser = argparse.ArgumentParser() parser.add_argument('-d', '--directories', default='all', help='directories (containing INCARs) to edit') args = parser.parse_args() directories = args.directories parameters_to_update = { "GGA": "PE", "ISYM": 3, "PRECFOCK": "Fast", "LMAXFOCK": 4, "TIME": 0.30, "LHFCALC": True, "AEXX": 0.25, "HFSCREEN": 0.2 } if directories == 'all': directories = find_vasp_calculations() for directory in directories: incar = Incar.from_file(f"{directory}/INCAR").as_dict() incar = deepcopy(incar) to_del = [i for i in incar.keys() if "LDA" in i] for d in to_del: incar.pop(d) new_incar = Incar.from_dict(incar | parameters_to_update) os.mkdir(f"{directory}/hygam") new_incar.write_file(f"{directory}/hygam/INCAR") structure = Poscar.from_file(f"{directory}/CONTCAR").structure structure.to(filename=f"{directory}/hygam/POSCAR") os.system(f"cp {directory}/POTCAR {directory}/hygam/POTCAR") Kpoints().write_file(f"{directory}/hygam/KPOINTS")
def parse_calcs(): """ find all vasp caluclations in directories "below" current directory and generate a ".csv" summarising the status of these calculations ("calc_data.csv") args: - None returns: - None """ calculation_status = {} home = os.getcwd() entries = [] calculations = find_vasp_calculations() for calc_dir in tqdm(calculations): calc_status = { 'converged': assess_vasprun(f'{home}/{calc_dir}'), 'errors': assess_stdout(f'{home}/{calc_dir}'), 'contcar': assess_CONTCAR(f'{home}/{calc_dir}'), 'ionic_steps': assess_XDATCAR(f'{home}/{calc_dir}'), 'last_updated': assess_OUTCAR(f'{home}/{calc_dir}') } calculation_status.update({calc_dir: calc_status}) df = pd.DataFrame.from_dict(calculation_status, orient='index') df.to_csv('calc_data.csv')
def main(): supported_flags = Summary.supported_flags to_print = [ 'title', 'status', 'stoichiometry', 'potcar', 'plus_u', 'energy', 'lreal', 'k-points', 'functional', 'encut', 'ediffg', 'ibrion', 'converged', 'version', 'md5', 'directory' ] titles = None args = get_args() if args.list: for k, v, in supported_flags.items(): print("{}: {}".format(k.ljust(15), v)) sys.exit() if args.file: with open(args.file, 'r') as stream: settings = yaml.load(stream, Loader=yaml.SafeLoader) if 'to_print' in settings: to_print = settings['to_print'] if 'titles' in settings: titles = settings['titles'] if args.print: not_supported = [p for p in args.print if p not in supported_flags] if not_supported: raise ValueError(not_supported) else: to_print = args.print if args.recursive: path = sorted(find_vasp_calculations()) else: path = ['.'] if args.check: for p in path: vaspmeta = Path('{}/vaspmeta.yaml'.format(p)) if not vaspmeta.is_file(): print('{} is missing vaspmeta.yaml'.format(p)) vasprun = Path('{}/vasprun.xml'.format(p)) if not vasprun.is_file(): print('{} is missing vasprun.xml'.format(p)) else: if titles: # Only parse directories with matching vasp_meta titles matching_path = [] for p in path: vm = VASPMeta.from_file('{}/vaspmeta.yaml'.format(p)) if vm.title in titles: matching_path.append(p) path = matching_path if args.maxjobs: n = len(path) with Pool(args.maxjobs) as p: if args.progress_bar: summaries = list( tqdm.tqdm(p.imap(get_summary, path), total=len(path))) else: summaries = p.map(get_summary, path) else: if args.progress_bar: path_iterator = tqdm.tqdm(path, unit='vasprun') else: path_iterator = path summaries = [get_summary(p) for p in path_iterator] if args.progress_bar: iterable = tqdm.tqdm(summaries, unit='records') else: iterable = summaries for s in iterable: s.output(to_print=to_print)
def test_find_vasp_calculations(self): mock_glob_output = ['dir_A/vasprun.xml', 'dir_B/dir_C/vasprun.xml'] with patch('glob.iglob', return_value=mock_glob_output) as mock_glob: v = find_vasp_calculations() self.assertEqual(v, ['./dir_A/', './dir_B/dir_C/'])
def test_find_vasp_calculations( self ): mock_glob_output = [ 'dir_A/vasprun.xml', 'dir_B/dir_C/vasprun.xml' ] with patch('glob.iglob', side_effect=[mock_glob_output, []]) as mock_glob: v = find_vasp_calculations() self.assertEqual( v, [ './dir_A/', './dir_B/dir_C/' ] )
sys.exit() if args.file: with open(args.file, 'r') as stream: settings = yaml.load(stream) if 'to_print' in settings: to_print = settings['to_print'] if 'titles' in settings: titles = settings['titles'] if args.print: not_supported = [p for p in args.print if p not in supported_flags] if not_supported: raise ValueError(not_supported) else: to_print = args.print if args.recursive: path = sorted(find_vasp_calculations()) else: path = ['.'] if args.check: for p in path: vaspmeta = Path('{}/vaspmeta.yaml'.format(p)) if not vaspmeta.is_file(): print('{} is missing vaspmeta.yaml'.format(p)) vasprun = Path('{}/vasprun.xml'.format(p)) if not vasprun.is_file(): print('{} is missing vasprun.xml'.format(p)) else: if titles: # Only parse directories with matching vasp_meta titles matching_path = [] for p in path: