Révision 4e82c425 modules/dos_input.py

b/modules/dos_input.py
1 1
"""Functions to deal with DockOnSurf input files.
2 2

  
3
Functions
4
try_command:Tries to run a command and logs its exceptions (expected and not).
3
List of functions:
4

  
5
Auxiliary functions
6
-------------------
5 7
str2lst: Converts a string of integers, and groups of them, to a list of lists.
6 8
check_expect_val: Checks whether the value of an option has an adequate value.
7
read_input: Sets up the calculation by reading the parameters from input file.
9
check_inp_files: Checks if the CP2K/VASP input files are consistent.
10

  
11
Functions to read parameters in the Global section
12
--------------------------------------------------
8 13
get_run_type: Gets 'run_type' value and checks that its value is acceptable.
9 14
get_code: Gets 'code' value and checks that its value is acceptable.
10 15
get_batch_q_sys: Gets 'batch_q_sys' value and checks that its value is
11
acceptable.
16
    acceptable.
17
get_pbc_cell: Gets 'pbc_cell' value and checks that its value is acceptable.
18
get_subm_script: Gets 'subm_script' value and checks that its value is
19
    acceptable.
20
get_project_name: Gets 'project_name' value and checks that its value is
21
    acceptable.
12 22
get_relaunch_err: Gets 'relaunch_err' value and checks that its value is
13
acceptable.
23
    acceptable. # WARNING: OPTION NOT IMPLEMENTED
14 24
get_max_jobs: Gets 'max_jobs' value and checks that its value is acceptable.
15 25
get_special_atoms: Gets 'special_atoms' value and checks that its value is
16
acceptable.
26
    acceptable.
27
get_potcar_dir: Gets 'potcar_dir' value and checks that its value is
28
    acceptable.
29

  
30
Functions to read parameters in the Isolated section
31
----------------------------------------------------
17 32
get_isol_inp_file: Gets 'isol_inp_file' value and checks that its value is
18
acceptable.
19
get_cluster_magns: Gets 'cluster_magns' value and checks that its value is
20
acceptable.
33
    acceptable.
34
get_molec_file: Gets 'molec_file' value and checks that its value is acceptable.
21 35
get_num_conformers: Gets 'num_conformers' value and checks that its value is
22
acceptable.
23
get_num_prom_cand: Gets 'num_prom_cand' value and checks that its value is
24
acceptable.
25
get_iso_rmsd: Gets 'iso_rmsd' value and checks that its value is acceptable.
36
    acceptable.
26 37
get_pre_opt: Gets 'pre_opt' value and checks that its value is acceptable.
38

  
39
Functions to read parameters in the Screening section
40
-----------------------------------------------------
27 41
get_screen_inp_file: Gets 'screen_inp_file' value and checks that its value is
28
acceptable.
42
    acceptable.
43
get_surf_file: Gets 'surf_file' value and checks that its value is acceptable.
29 44
get_sites: Gets 'sites' value and checks that its value is acceptable.
30
get_molec_ctrs: Gets 'molec_ctrs' value and checks that its value is
31
acceptable.
32
get_try_disso: Gets 'try_disso' value and checks that its value is acceptable.
45
get_surf_ctrs2: Gets 'surf_ctrs2' value and checks that its value is acceptable.
46
get_molec_ctrs: Gets 'molec_ctrs' value and checks that its value is acceptable.
47
get_molec_ctrs2: Gets 'molec_ctrs2' value and checks that its value is
48
    acceptable.
49
get_molec_ctrs3: Gets 'molec_ctrs3' value and checks that its value is
50
    acceptable.
51
get_max_helic_angle: Gets 'max_helic_angle' value and checks that its value is
52
    acceptable.
53
get_select_magns: Gets 'select_magns' value and checks that its value is
54
    acceptable.
55
get_confs_per_magn: Gets 'confs_per_magn' value and checks that its value is
56
    acceptable.
57
get_surf_norm_vect: Gets 'surf_norm_vect' value and checks that its value is
58
    acceptable.
59
get_adsorption_height: Gets 'adsorption_height' value and checks that its value
60
    is acceptable.
61
get_set_angles: Gets 'set_angles' value and checks that its value is
62
    acceptable.
33 63
get_pts_per_angle: Gets 'pts_per_angle' value and checks that its value is
34
acceptable.
64
    acceptable.
65
get_max_structures: Gets 'max_structures' value and checks that its value is
66
    acceptable.
35 67
get_coll_thrsld: Gets 'coll_thrsld' value and checks that its value is
36
acceptable.
37
get_screen_rmsd: Gets 'screen_rmsd' value and checks that its value is
38
acceptable.
39
get_coll_bottom_z: Gets 'coll_bottom_z' value and checks that its value is
40
acceptable.
68
    acceptable.
69
get_min_coll_height: Gets 'coll_bottom_z' value and checks that its value is
70
    acceptable.
71
get_exclude_ads_ctr: Gets 'exclude_ads_ctr' value and checks that its value is
72
    acceptable.
73
get_H_donor: Gets 'H_donor' value and checks that its value is
74
    acceptable.
75
get_H_acceptor: Gets 'H_acceptor' value and checks that its value is
76
    acceptable.
77
get_use_molec_file: Gets 'use_molec_file' value and checks that its value is
78
    acceptable.
79

  
80
Functions to read parameters in the Refinement section
81
------------------------------------------------------
41 82
get_refine_inp_file: Gets 'refine_inp_file' value and checks that its value is
42
acceptable.
83
    acceptable.
43 84
get_energy_cutoff: Gets 'energy_cutoff' value and checks that its value is
44
acceptable.
85
    acceptable.
86

  
87
read_input: Directs the reading of the parameters in the input file
45 88
"""
46 89
import os.path
47 90
import logging
......
54 97

  
55 98
dos_inp = ConfigParser(inline_comment_prefixes='#',
56 99
                       empty_lines_in_values=False)
57

  
100
# Define new answers to be interpreted as True or False.
58 101
new_answers = {'n': False, 'none': False, 'nay': False,
59 102
               'y': True, 'sí': True, 'aye': True, 'sure': True}
60 103
for answer, val in new_answers.items():
......
64 107
turn_true_answers = [answer for answer in dos_inp.BOOLEAN_STATES
65 108
                     if dos_inp.BOOLEAN_STATES[answer]]
66 109

  
110
# Template error messages to be customized in place.
67 111
no_sect_err = "Section '%s' not found on input file"
68 112
no_opt_err = "Option '%s' not found on section '%s'"
69 113
num_error = "'%s' value must be a %s"
......
73 117

  
74 118
def str2lst(cmplx_str, func=int):  # TODO: enable deeper level of nested lists
75 119
    # TODO Treat all-enclosing parenthesis as a list instead of list of lists.
76
    """Converts a string of integers, and groups of them, to a list.
120
    """Converts a string of integers/floats, and groups of them, to a list.
77 121

  
78 122
    Keyword arguments:
79 123
    @param cmplx_str: str, string of integers (or floats) and groups of them
......
159 203
    return True
160 204

  
161 205

  
162
def check_inp_files(inp_files, code, potcar_dir=None):
206
def check_inp_files(inp_files, code: str, potcar_dir=None):
207
    """Checks if the CP2K/VASP input files are consistent.
208

  
209
    @param inp_files: List of input files
210
    @param code: The code for which the input files are for (VASP or CP2K).
211
    @param potcar_dir: The path where POTCARs are found
212
    @return: None
213
    """
163 214
    if code == 'cp2k':
164 215
        from pycp2k import CP2K
165 216
        if not isinstance(inp_files, str):
......
184 235
                               "also enabled via the 'potcar_dir' keyword. The "
185 236
                               "POTCAR specified as input_file will be used "
186 237
                               "instead of the auto-generated one.")
187
        # Check that it inp_files is a list of file paths
238
        # Check that if inp_files is a list of file paths
188 239
        if not isinstance(inp_files, list) and all(isinstance(inp_file, str)
189 240
                                                   for inp_file in inp_files):
190 241
            err_msg = "'inp_files' should be a list of file names/paths"
......
306 357

  
307 358

  
308 359
def get_relaunch_err():
360
    # WARNING: OPTION NOT IMPLEMENTED
309 361
    relaunch_err_vals = ['geo_not_conv']
310 362
    relaunch_err = dos_inp.get('Global', 'relaunch_err',
311 363
                               fallback="False")
......
815 867
# Read input parameters
816 868

  
817 869
def read_input(in_file):
870
    """Directs the reading of the parameters in the input file.
871

  
872
    @param in_file: The path to the DockOnSurf input file.
873
    @return inp_vars: Dictionary with the values for every option in the input
874
    file.
875
    """
818 876
    from modules.formats import adapt_format
819 877

  
878
    # Checks for errors in the Input file.
820 879
    err_msg = False
821 880
    try:
822 881
        dos_inp.read(in_file)
......
851 910
            logger.error(no_opt_err % (opt, 'Global'))
852 911
            raise NoOptionError(opt, 'Global')
853 912

  
854
    # Gets which sections are to be carried out
913
    # Mandatory options
855 914
    isolated, screening, refinement = get_run_type()
856 915
    inp_vars['isolated'] = isolated
857 916
    inp_vars['screening'] = screening
......
882 941
            logger.error(no_sect_err % 'Isolated')
883 942
            raise NoSectionError('Isolated')
884 943
        # Mandatory options
885
        # Checks whether the mandatory options are present.
886 944
        iso_mand_opts = ['isol_inp_file', 'molec_file']
887 945
        for opt in iso_mand_opts:
888 946
            if not dos_inp.has_option('Isolated', opt):
......
929 987
            raise NoSectionError('Screening')
930 988
        # Mandatory options:
931 989
        # Checks whether the mandatory options are present.
990
        # Mandatory options
932 991
        screen_mand_opts = ['screen_inp_file', 'surf_file', 'sites',
933 992
                            'molec_ctrs']
934 993
        for opt in screen_mand_opts:
......
946 1005
        inp_vars['molec_ctrs'] = get_molec_ctrs()
947 1006

  
948 1007
        # Checks for PBC
949
        # Checks for PBC
950 1008
        atms = adapt_format('ase', inp_vars['surf_file'],
951 1009
                            inp_vars['special_atoms'])
952 1010
        if inp_vars['code'] == 'vasp' and np.linalg.det(atms.cell) == 0.0 \

Formats disponibles : Unified diff