Statistiques
| Branche: | Tag: | Révision :

dockonsurf / modules / refinement.py @ 1d8c374e

Historique | Voir | Annoter | Télécharger (3,21 ko)

1
import logging
2

    
3
logger = logging.getLogger('DockOnSurf')
4

    
5

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

9
    Given a list of ase.Atoms configurations and an energy cutoff, selects all
10
    the structures that have an energy lower than, the energy of the most stable
11
    conformer plus the cutoff.
12

13
    @param conf_list: List of ase.Atoms objects of the conformers
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.
17
    """
18
    sorted_list = sorted(conf_list, key=lambda conf: conf.info['energy'])
19
    lowest_e = sorted_list[0].info['energy']
20
    return [conf for conf in sorted_list
21
            if conf.info['energy'] <= lowest_e + energy_cutoff]
22

    
23

    
24
def run_refinement(inp_vars):
25
    """Carries out the refinement of adsorbate-slab structures after screening.
26

27
    @param inp_vars: Calculation parameters from input file.
28
    """
29
    import os
30
    from modules.formats import collect_confs
31
    from modules.calculation import run_calc, check_finished_calcs
32

    
33
    logger.info('Carrying out procedures for the refinement of '
34
                'adsorbate-surface structures.')
35

    
36
    if not os.path.isdir("screening"):
37
        err = "'screening' directory not found. It is needed in order to carry "
38
        "out the refinement of structures to be adsorbed"
39
        logger.error(err)
40
        raise FileNotFoundError(err)
41

    
42
    finished_calcs, failed_calcs = check_finished_calcs('screening',
43
                                                        inp_vars['code'])
44
    if not finished_calcs:
45
        err_msg = "No calculations on 'screening' finished normally."
46
        logger.error(err_msg)
47
        raise FileNotFoundError(err_msg)
48
    logger.info(f"Found {len(finished_calcs)} structures of "
49
                f"adsorbate-surface atomic configurations whose calculation"
50
                f" finished normally.")
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"
54
                       f"Using only the ones that finished normally: "
55
                       f"{finished_calcs}.")
56

    
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'])
60
    logger.info(f"Selected {len(selected_confs)} structures to carry out the"
61
                f" refinement")
62
    run_calc('refinement', inp_vars, selected_confs)
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.")