Révision c3cb279a modules/calculation.py

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

  
6 6

  
7
def create_bak_calc_dir(run_type):
8
    """Checks if calculations directory already exists, backs it up if so and
9
    creates an empty one to work on.
10
    @param run_type: Type of calculation. 'isolated', 'screening' or
11
    'refinement'
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
12 10
    """
13
    dir_name = run_type
11
    new_name = file_name
14 12
    bak_num = 0
15
    while dir_name in os.listdir("."):
13
    while new_name in os.listdir("."):
16 14
        bak_num += 1
17
        dir_name = dir_name.split(".")[0] + f".bak{bak_num}"
15
        new_name = new_name.split(".bak")[0] + f".bak{bak_num}"
18 16
    if bak_num > 0:
19
        os.rename(run_type, dir_name)
20
        logger.warning(f"'{run_type}' directory already present. Moved former "
21
                       f"directory to {dir_name}")
22
    os.mkdir(run_type)
17
        os.rename(file_name, new_name)
18
        logger.warning(f"'{file_name}' already present. Backed it up to "
19
                       f"{new_name}")
23 20

  
24 21

  
25 22
def prep_cp2k(inp_file, run_type, atms_list):
......
99 96

  
100 97
    logger.info(f"Running {run_type} calculation with {inp_vars['code']} on "
101 98
                f"{inp_vars['batch_q_sys']}")
102
    create_bak_calc_dir(run_type)
99
    check_bak(run_type)
100
    os.mkdir(run_type)
103 101
    if run_type == 'isolated':
104 102
        if inp_vars['code'] == 'cp2k':
105 103
            prep_cp2k(inp_vars['isol_inp_file'], run_type, atms_list)

Formats disponibles : Unified diff