dockonsurf / modules / refinement.py @ 082685ad
Historique | Voir | Annoter | Télécharger (3,7 ko)
1 |
import logging |
---|---|
2 |
|
3 |
logger = logging.getLogger('DockOnSurf')
|
4 |
|
5 |
|
6 |
def select_confs(conf_list, calc_dirs, energy_cutoff, code): |
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 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
|
18 |
"""
|
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 |
sorted_list = sorted(conf_list, key=lambda conf: conf.info['energy']) |
29 |
lowest_e = sorted_list[0].info['energy'] |
30 |
return [conf for conf in sorted_list |
31 |
if conf.info['energy'] <= lowest_e + energy_cutoff] |
32 |
|
33 |
|
34 |
def run_refinement(inp_vars): |
35 |
"""Carries out the refinement of adsorbate-slab structures after screening.
|
36 |
|
37 |
@param inp_vars: Calculation parameters from input file.
|
38 |
"""
|
39 |
import os |
40 |
from modules.formats import collect_coords |
41 |
from modules.calculation import run_calc, check_finished_calcs |
42 |
|
43 |
logger.info('Carrying out procedures for the refinement of '
|
44 |
'adsorbate-surface structures.')
|
45 |
|
46 |
if not os.path.isdir("screening"): |
47 |
err = "'screening' directory not found. It is needed in order to carry "
|
48 |
"out the refinement of structures to be adsorbed"
|
49 |
logger.error(err) |
50 |
raise FileNotFoundError(err)
|
51 |
|
52 |
finished_calcs, unfinished_calcs = check_finished_calcs('screening',
|
53 |
inp_vars['code'])
|
54 |
if not finished_calcs: |
55 |
err_msg = "No calculations on 'screening' finished normally."
|
56 |
logger.error(err_msg) |
57 |
raise FileNotFoundError(err_msg)
|
58 |
logger.info(f"Found {len(finished_calcs)} structures of "
|
59 |
f"adsorbate-surface atomic configurations whose calculation"
|
60 |
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"
|
64 |
f"Using only the ones that finished normally: "
|
65 |
f"{finished_calcs}.")
|
66 |
|
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']) |
71 |
logger.info(f"Selected {len(selected_confs)} structures to carry out the"
|
72 |
f" refinement")
|
73 |
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']}")
|