dockonsurf / modules / refinement.py @ 365d5b9a
Historique | Voir | Annoter | Télécharger (3,44 ko)
1 |
import logging |
---|---|
2 |
|
3 |
logger = logging.getLogger('DockOnSurf')
|
4 |
|
5 |
|
6 |
def select_confs(orig_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 orig_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_list = deepcopy(orig_conf_list) |
23 |
selected_ids = [] |
24 |
conf_enrgs = collect_energies(calc_dirs, code, 'screening')
|
25 |
|
26 |
for i, conf in enumerate(conf_list): |
27 |
conf.info['energy'] = conf_enrgs[i]
|
28 |
|
29 |
sorted_list = sorted(conf_list, key=lambda conf: conf.info['energy']) |
30 |
lowest_e = sorted_list[0].info['energy'] |
31 |
return [conf for conf in sorted_list |
32 |
if conf.info['energy'] < lowest_e + energy_cutoff] |
33 |
|
34 |
|
35 |
def run_refinement(inp_vars): |
36 |
"""Carries out the refinement of adsorbate-slab structures after screening.
|
37 |
|
38 |
@param inp_vars: Calculation parameters from input file.
|
39 |
"""
|
40 |
import os |
41 |
from modules.formats import collect_coords |
42 |
from modules.calculation import run_calc, check_finished_calcs |
43 |
|
44 |
logger.info('Carrying out procedures for the refinement of '
|
45 |
'adsorbate-surface structures.')
|
46 |
|
47 |
if not os.path.isdir("screening"): |
48 |
err = "'screening' directory not found. It is needed in order to carry "
|
49 |
"out the refinement of structures to be adsorbed"
|
50 |
logger.error(err) |
51 |
raise FileNotFoundError(err)
|
52 |
|
53 |
finished_calcs, unfinished_calcs = check_finished_calcs('screening',
|
54 |
inp_vars['code'])
|
55 |
if not finished_calcs: |
56 |
err_msg = "No calculations on 'screening' finished normally."
|
57 |
logger.error(err_msg) |
58 |
raise FileNotFoundError(err_msg)
|
59 |
logger.info(f"Found {len(finished_calcs)} structures of "
|
60 |
f"adsorbate-surface atomic configurations whose calculation"
|
61 |
f" finished normally.")
|
62 |
if len(unfinished_calcs) != 0: |
63 |
logger.warning(f"Found {len(unfinished_calcs)} calculations more that "
|
64 |
f"did not finish normally: {unfinished_calcs}. \n"
|
65 |
f"Using only the ones that finished normally: "
|
66 |
f"{finished_calcs}.")
|
67 |
|
68 |
conf_list = collect_coords(finished_calcs, inp_vars['code'], 'screening', |
69 |
inp_vars['special_atoms'])
|
70 |
selected_confs = select_confs(conf_list, finished_calcs, |
71 |
inp_vars['energy_cutoff'], inp_vars['code']) |
72 |
logger.info(f"Selected {len(selected_confs)} structures to carry out the"
|
73 |
f" refinement")
|
74 |
run_calc('refinement', inp_vars, selected_confs)
|
75 |
most_stable_conf = select_confs(conf_list, finished_calcs, 0,
|
76 |
inp_vars['code'])[0] |
77 |
logger.info('Finished the procedures for the refinement of '
|
78 |
'adsorbate-surface structures section. Most stable structure '
|
79 |
f'is {most_stable_conf}')
|