Révision 1d8c374e modules/refinement.py

b/modules/refinement.py
3 3
logger = logging.getLogger('DockOnSurf')
4 4

  
5 5

  
6
def select_confs(conf_list, calc_dirs, energy_cutoff, code):
6
def select_stable_confs(conf_list, energy_cutoff):
7 7
    """From a list of atomic configurations selects the most stable ones.
8 8

  
9 9
    Given a list of ase.Atoms configurations and an energy cutoff, selects all
......
11 11
    conformer plus the cutoff.
12 12

  
13 13
    @param conf_list: List of ase.Atoms objects of the conformers
14
    @param calc_dirs: List of the directories of the finished calculations
15
    @param energy_cutoff: The maximum energy above the most stable configuration
16
    @param code: the code used to carry out the screening of structures.
17
    @return: list of the the most stable configurations within the energy cutoff
14
    @param energy_cutoff: The maximum energy above the most stable
15
        configuration.
16
    @return: list of the the most stable configurations within the energy cutoff.
18 17
    """
19
    from copy import deepcopy
20
    from modules.formats import collect_energies
21

  
22
    conf_enrgs = collect_energies(calc_dirs, code, 'screening')
23

  
24
    for i, conf in enumerate(conf_list):
25
        conf.info['energy'] = conf_enrgs[i]
26
        conf.info['id'] = calc_dirs[i]
27

  
28 18
    sorted_list = sorted(conf_list, key=lambda conf: conf.info['energy'])
29 19
    lowest_e = sorted_list[0].info['energy']
30 20
    return [conf for conf in sorted_list
......
37 27
    @param inp_vars: Calculation parameters from input file.
38 28
    """
39 29
    import os
40
    from modules.formats import collect_coords
30
    from modules.formats import collect_confs
41 31
    from modules.calculation import run_calc, check_finished_calcs
42 32

  
43 33
    logger.info('Carrying out procedures for the refinement of '
......
49 39
        logger.error(err)
50 40
        raise FileNotFoundError(err)
51 41

  
52
    finished_calcs, unfinished_calcs = check_finished_calcs('screening',
53
                                                            inp_vars['code'])
42
    finished_calcs, failed_calcs = check_finished_calcs('screening',
43
                                                        inp_vars['code'])
54 44
    if not finished_calcs:
55 45
        err_msg = "No calculations on 'screening' finished normally."
56 46
        logger.error(err_msg)
......
58 48
    logger.info(f"Found {len(finished_calcs)} structures of "
59 49
                f"adsorbate-surface atomic configurations whose calculation"
60 50
                f" finished normally.")
61
    if len(unfinished_calcs) != 0:
62
        logger.warning(f"Found {len(unfinished_calcs)} calculations more that "
63
                       f"did not finish normally: {unfinished_calcs}. \n"
51
    if len(failed_calcs) != 0:
52
        logger.warning(f"Found {len(failed_calcs)} calculations more that "
53
                       f"did not finish normally: {failed_calcs}. \n"
64 54
                       f"Using only the ones that finished normally: "
65 55
                       f"{finished_calcs}.")
66 56

  
67
    conf_list = collect_coords(finished_calcs, inp_vars['code'], 'screening',
68
                               inp_vars['special_atoms'])
69
    selected_confs = select_confs(conf_list, finished_calcs,
70
                                  inp_vars['energy_cutoff'], inp_vars['code'])
57
    conf_list = collect_confs(finished_calcs, inp_vars['code'], 'screening',
58
                              inp_vars['special_atoms'])
59
    selected_confs = select_stable_confs(conf_list, inp_vars['energy_cutoff'])
71 60
    logger.info(f"Selected {len(selected_confs)} structures to carry out the"
72 61
                f" refinement")
73 62
    run_calc('refinement', inp_vars, selected_confs)
74
    finished_calcs, unfinished_calcs = check_finished_calcs('refinement',
75
                                                            inp_vars['code'])
76
    conf_list = collect_coords(finished_calcs, inp_vars['code'], 'refinement',
77
                               inp_vars['special_atoms'])
78
    most_stable_conf = select_confs(conf_list, finished_calcs, 0,
79
                                    inp_vars['code'])[0]
80
    logger.info('Finished the procedures for the refinement of '
81
                'adsorbate-surface structures section. Most stable structure '
82
                f"is {most_stable_conf.info['id']}")
63
    finished_calcs, failed_calcs = check_finished_calcs('refinement',
64
                                                        inp_vars['code'])
65
    conf_list = collect_confs(finished_calcs, inp_vars['code'], 'refinement',
66
                              inp_vars['special_atoms'])
67
    most_stable_conf = select_stable_confs(conf_list, 0)[0]
68
    logger.info("Finished the procedures for the refinement of "
69
                "adsorbate-surface structures section. Most stable structure "
70
                f"is {most_stable_conf.info['id']} with a Total energy of "
71
                f"{most_stable_conf.info['energy']} eV.")

Formats disponibles : Unified diff