Coverage for biobb_amber/pmemd/common.py: 0%

27 statements  

« prev     ^ index     » next       coverage.py v7.5.1, created at 2024-05-07 08:11 +0000

1""" Common functions for package biobb_amber.pmemd """ 

2from pathlib import Path, PurePath 

3from biobb_common.tools import file_utils as fu 

4 

5 

6# CHECK INPUT PARAMETERS 

7def check_input_path(path, argument, optional, out_log, classname): 

8 """ Checks input file """ 

9 if optional and not path: 

10 return None 

11 if not Path(path).exists(): 

12 fu.log(classname + ': Unexisting %s file, exiting' % argument, out_log) 

13 raise SystemExit(classname + ': Unexisting %s file' % argument) 

14 file_extension = PurePath(path).suffix 

15 if not is_valid_file(file_extension[1:], argument): 

16 fu.log(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument), out_log) 

17 raise SystemExit(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument)) 

18 return path 

19 

20 

21# CHECK OUTPUT PARAMETERS 

22def check_output_path(path, argument, optional, out_log, classname): 

23 """ Checks output file """ 

24 if optional and not path: 

25 return None 

26 if PurePath(path).parent and not Path(PurePath(path).parent).exists(): 

27 fu.log(classname + ': Unexisting %s folder, exiting' % argument, out_log) 

28 raise SystemExit(classname + ': Unexisting %s folder' % argument) 

29 file_extension = PurePath(path).suffix 

30 if not is_valid_file(file_extension[1:], argument): 

31 fu.log(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument), out_log) 

32 raise SystemExit(classname + ': Format %s in %s file is not compatible' % (file_extension[1:], argument)) 

33 return path 

34 

35 

36def is_valid_file(ext, argument): 

37 """ Checks if file format is compatible """ 

38 formats = { 

39 'input_top_path': ['top', 'prmtop', 'parmtop'], 

40 'input_crd_path': ['crd', 'inpcrd', 'mdcrd', 'rst', 'rst7', 'netcdf', 'nc', 'ncrst'], 

41 'input_mdin_path': ['mdin', 'txt', 'in'], 

42 'input_cpin_path': ['cpin', 'txt', 'in'], 

43 'input_ref_path': ['crd', 'inpcrd', 'mdcrd', 'rst', 'rst7', 'netcdf', 'nc', 'ncrst'], 

44 'output_log_path': ['log', 'out', 'txt', 'o'], 

45 'output_traj_path': ['trj', 'crd', 'mdcrd', 'x', 'netcdf', 'nc'], 

46 'output_rst_path': ['rst', 'rst7', 'netcdf', 'nc', 'ncrst'], 

47 'output_cpout_path': ['cpout'], 

48 'output_cprst_path': ['cprst', 'rst', 'rst7'], 

49 'output_mdinfo_path': ['mdinfo'] 

50 } 

51 return ext in formats[argument]