dockonsurf / modules / refinement.py @ cf980c86
Historique | Voir | Annoter | Télécharger (3,84 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 |
import numpy as np |
31 |
from modules.formats import collect_confs |
32 |
from modules.calculation import run_calc, check_finished_calcs |
33 |
|
34 |
logger.info('Carrying out procedures for the refinement of '
|
35 |
'adsorbate-surface structures.')
|
36 |
|
37 |
if not os.path.isdir("screening"): |
38 |
err = "'screening' directory not found. It is needed in order to carry "
|
39 |
"out the refinement of structures to be adsorbed"
|
40 |
logger.error(err) |
41 |
raise FileNotFoundError(err)
|
42 |
|
43 |
finished_calcs, failed_calcs = check_finished_calcs('screening',
|
44 |
inp_vars['code'])
|
45 |
if not finished_calcs: |
46 |
err_msg = "No calculations on 'screening' finished normally."
|
47 |
logger.error(err_msg) |
48 |
raise FileNotFoundError(err_msg)
|
49 |
logger.info(f"Found {len(finished_calcs)} structures of "
|
50 |
f"adsorbate-surface atomic configurations whose calculation"
|
51 |
f" finished normally.")
|
52 |
if len(failed_calcs) != 0: |
53 |
logger.warning(f"Found {len(failed_calcs)} calculations more that "
|
54 |
f"did not finish normally: {failed_calcs}. \n"
|
55 |
f"Using only the ones that finished normally: "
|
56 |
f"{finished_calcs}.")
|
57 |
|
58 |
conf_list = collect_confs(finished_calcs, inp_vars['code'], 'screening', |
59 |
inp_vars['special_atoms'])
|
60 |
selected_confs = select_stable_confs(conf_list, inp_vars['energy_cutoff'])
|
61 |
logger.info(f"Selected {len(selected_confs)} structures to carry out the"
|
62 |
f" refinement")
|
63 |
run_calc('refinement', inp_vars, selected_confs)
|
64 |
logger.info("Finished the procedures for the refinement of "
|
65 |
"adsorbate-surface structures section. ")
|
66 |
if inp_vars["batch_q_sys"]: |
67 |
finished_calcs, failed_calcs = check_finished_calcs('refinement',
|
68 |
inp_vars['code'])
|
69 |
conf_list = collect_confs(finished_calcs, inp_vars['code'],
|
70 |
'refinement', inp_vars['special_atoms']) |
71 |
sorted_confs = select_stable_confs(conf_list, np.inf) |
72 |
logger.info(f"Most stable structure is {sorted_confs[0].info['ref']} "
|
73 |
f"with a total energy of {sorted_confs[0].info['energy']} "
|
74 |
f"eV.")
|
75 |
confs_str = "\n".join([" ".join((str(conf.info['ref']), 'E =', |
76 |
str(conf.info['energy'] - |
77 |
sorted_confs[0].info['energy']), |
78 |
'eV'))
|
79 |
for conf in sorted_confs]) |
80 |
logger.info("The relative energies, of all structures obtained at the "
|
81 |
"refinement stage, respect the most stable one "
|
82 |
f"({sorted_confs[0].info['ref']}) are:\n{confs_str}")
|