dockonsurf / modules / refinement.py @ 1e9e784d
Historique | Voir | Annoter | Télécharger (3,2 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 |
if not os.path.isdir("screening"): |
44 |
err = "'screening' directory not found. It is needed in order to carry "
|
45 |
"out the refinement of structures to be adsorbed"
|
46 |
logger.error(err) |
47 |
raise FileNotFoundError(err)
|
48 |
|
49 |
logger.info('Carrying out procedures for the refinement of '
|
50 |
'adsorbate-surface structures.')
|
51 |
|
52 |
finished_calcs, unfinished_calcs = check_finished_calcs('screening',
|
53 |
inp_vars['code'])
|
54 |
if len(unfinished_calcs) == 0: |
55 |
logger.info(f"Found {len(finished_calcs)} structures of "
|
56 |
f"adsorbate-surface atomic configurations.")
|
57 |
else:
|
58 |
logger.info(f"Found {len(finished_calcs)} structures of "
|
59 |
f"adsorbate-surface atomic configurations whose calculation"
|
60 |
f" finished normally.")
|
61 |
logger.warning(f"Found {len(unfinished_calcs)} calculations more that "
|
62 |
f"did not finish normally: {unfinished_calcs}. Using "
|
63 |
f"only the {len(finished_calcs)} ones who finished "
|
64 |
f"normally")
|
65 |
|
66 |
conf_list = collect_coords(inp_vars['code'], 'screening', 'ase', |
67 |
inp_vars['special_atoms'])
|
68 |
logger.info(f"Found {len(conf_list)} structures on screening directory.")
|
69 |
selected_confs = select_confs(conf_list, finished_calcs, |
70 |
inp_vars['energy_cutoff'], inp_vars['code']) |
71 |
run_calc('refinement', inp_vars, selected_confs)
|
72 |
logger.info('Finished the procedures for the refinement of '
|
73 |
'adsorbate-surface structures section.')
|