Révision 69d17e8b modules/calculation.py

b/modules/calculation.py
4 4
logger = logging.getLogger('DockOnSurf')
5 5

  
6 6

  
7
def check_bak(file_name):
8
    """Checks if a file already exists and backs it up if so.
9
    @param file_name: file to be checked if exists
10
    """
11
    new_name = file_name
12
    bak_num = 0
13
    while os.path.isdir(new_name) or os.path.isfile(new_name):
14
        bak_num += 1
15
        new_name = new_name.split(".bak")[0] + f".bak{bak_num}"
16
    if bak_num > 0:
17
        os.rename(file_name, new_name)
18
        logger.warning(f"'{file_name}' already present. Backed it up to "
19
                       f"{new_name}")
20

  
21

  
22 7
def prep_cp2k(inp_file, run_type, atms_list):  # TODO name to PROJECT_NAME
23 8
    """Prepares the directories to run isolated calculation with CP2K.
24 9

  
......
31 16
    from shutil import copy
32 17
    import ase.io
33 18
    from pycp2k import CP2K
19
    from utilities import check_bak
34 20
    cp2k = CP2K()
35 21
    cp2k.parse(inp_file)
36 22
    force_eval = cp2k.CP2K_INPUT.FORCE_EVAL_list[0]
......
114 100
    @param atms_list: List of ase.Atoms objects containing the sets of atoms
115 101
    aimed to run the calculations of.
116 102
    """
103
    from utilities import check_bak
117 104
    run_types = ['isolated', 'screening', 'refinement']
118 105
    run_type_err = f"'run_type' must be one of the following: {run_types}"
119 106
    if not isinstance(run_type, str) or run_type.lower() not in run_types:

Formats disponibles : Unified diff