Révision ffa1b366

b/modules/calculation.py
15 15
    """
16 16
    from glob import glob
17 17
    import ase.io
18
    from pycp2k import CP2K
18 19
    from modules.utilities import tail
19 20

  
20 21
    finished_calcs = []
21 22
    unfinished_calcs = []
22 23
    for conf in sorted(os.listdir(run_type), key=_human_key):
23
        if not os.path.isdir(f'{run_type}/{conf}') or 'conf_' not in conf:
24
        conf_path = f'{run_type}/{conf}'
25
        if not os.path.isdir(conf_path) or 'conf_' not in conf:
24 26
            continue
25 27
        if code == 'cp2k':
26
            out_file_list = glob(f"{run_type}/{conf}/*.out")
27
            restart_file_list = glob(f"{run_type}/{conf}/*-1.restart")
28
            if len(out_file_list) == 0 or len(restart_file_list) == 0:
28
            cp2k = CP2K()
29
            restart_file_list = glob(f"{conf_path}/*-1.restart")
30
            if len(restart_file_list) == 0:
31
                logger.warning(f"No *-1.restart file found on {conf_path}.")
29 32
                unfinished_calcs.append(conf)
30
            elif len(out_file_list) > 1 or len(restart_file_list) > 1:
31
                warn_msg = f'There is more than one file matching the {code} ' \
32
                           f'pattern for finished calculation (*.out / ' \
33
                           f'*-1.restart) in {run_type}/{conf}: ' \
34
                           f'{out_file_list, restart_file_list}. ' \
35
                           f'Skipping directory.'
33
                continue
34
            elif len(restart_file_list) > 1:
35
                warn_msg = f'There is more than one CP2K restart file ' \
36
                           f'(*-1.restart / in {conf_path}: ' \
37
                           f'{restart_file_list}. Skipping directory.'
38
                unfinished_calcs.append(conf)
39
                logger.warning(warn_msg)
40
                continue
41
            out_files = []
42
            for file in os.listdir(conf_path):
43
                with open(conf_path+"/"+file, "rb") as out_fh:
44
                    tail_out_str = tail(out_fh)
45
                if tail_out_str.count("PROGRAM STOPPED IN") == 1:
46
                    out_files.append(file)
47
            if len(out_files) > 1:
48
                warn_msg = f'There is more than one CP2K output file in ' \
49
                           f'{conf_path}: {out_files}. Skipping directory.'
50
                logger.warning(warn_msg)
51
                unfinished_calcs.append(conf)
52
            elif len(out_files) == 0:
53
                warn_msg = f'There is no CP2K output file in {conf_path}. ' \
54
                           'Skipping directory.'
36 55
                logger.warning(warn_msg)
37 56
                unfinished_calcs.append(conf)
38 57
            else:
39
                with open(out_file_list[0], 'rb') as out_fh:
40
                    if "PROGRAM STOPPED IN" not in tail(out_fh):
41
                        unfinished_calcs.append(conf)
42
                    else:
43
                        finished_calcs.append(conf)
58
                finished_calcs.append(conf)
44 59
        elif code == 'vasp':
45
            out_file_list = glob(f"{run_type}/{conf}/OUTCAR")
60
            out_file_list = glob(f"{conf_path}/OUTCAR")
46 61
            if len(out_file_list) == 0:
47 62
                unfinished_calcs.append(conf)
48 63
            elif len(out_file_list) > 1:
49 64
                warn_msg = f'There is more than one file matching the {code} ' \
50 65
                           f'pattern for finished calculation (*.out / ' \
51
                           f'*-1.restart) in {run_type}/{conf}: ' \
66
                           f'*-1.restart) in {conf_path}: ' \
52 67
                           f'{out_file_list}. Skipping directory.'
53 68
                logger.warning(warn_msg)
54 69
                unfinished_calcs.append(conf)
55 70
            else:
56 71
                try:
57
                    ase.io.read(f"{run_type}/{conf}/OUTCAR")
72
                    ase.io.read(f"{conf_path}/OUTCAR")
58 73
                except ValueError:
59 74
                    unfinished_calcs.append(conf)
60 75
                    continue
61 76
                except IndexError:
62 77
                    unfinished_calcs.append(conf)
63 78
                    continue
64
                with open(f"{run_type}/{conf}/OUTCAR", 'rb') as out_fh:
79
                with open(f"{conf_path}/OUTCAR", 'rb') as out_fh:
65 80
                    if "General timing and accounting" not in tail(out_fh):
66 81
                        unfinished_calcs.append(conf)
67 82
                    else:

Formats disponibles : Unified diff