Coverage for biobb_vs/vina/common.py: 58%
31 statements
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 12:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2025-01-28 12:00 +0000
1"""Common functions for package biobb_vs.vina"""
3from pathlib import Path, PurePath
5from biobb_common.tools import file_utils as fu
7# CHECK PARAMETERS
10def check_input_path(path, argument, out_log, classname):
11 """Checks input file"""
12 if not Path(path).exists():
13 fu.log(classname + ": Unexisting %s file, exiting" % argument, out_log)
14 raise SystemExit(classname + ": Unexisting %s file" % argument)
15 file_extension = PurePath(path).suffix
16 if not is_valid_file(file_extension[1:], argument):
17 fu.log(
18 classname + ": Format %s in %s file is not compatible"
19 % (file_extension[1:], argument),
20 out_log,
21 )
22 raise SystemExit(
23 classname + ": Format %s in %s file is not compatible"
24 % (file_extension[1:], argument)
25 )
26 return path
29def check_output_path(path, argument, optional, out_log, classname):
30 """Checks output file"""
31 if optional and not path:
32 return None
33 if PurePath(path).parent and not Path(PurePath(path).parent).exists():
34 fu.log(classname + ": Unexisting %s folder, exiting" % argument, out_log)
35 raise SystemExit(classname + ": Unexisting %s folder" % argument)
36 file_extension = PurePath(path).suffix
37 if not is_valid_file(file_extension[1:], argument):
38 fu.log(
39 classname + ": Format %s in %s file is not compatible"
40 % (file_extension[1:], argument),
41 out_log,
42 )
43 raise SystemExit(
44 classname + ": Format %s in %s file is not compatible"
45 % (file_extension[1:], argument)
46 )
47 return path
50def is_valid_file(ext, argument):
51 """Checks if file format is compatible"""
52 formats = {
53 "input_ligand_path": ["pdb"],
54 "output_ligand_path": ["pdbqt"],
55 "input_receptor_path": ["pdb"],
56 "output_receptor_path": ["pdbqt"],
57 "input_ligand_pdbqt_path": ["pdbqt"],
58 "input_receptor_pdbqt_path": ["pdbqt"],
59 "input_box_path": ["pdb"],
60 "output_pdbqt_path": ["pdbqt"],
61 "output_log_path": ["log"],
62 }
63 return ext in formats[argument]
66def check_mgltools_path(mgltools_path, out_log, classname):
67 """Checks the path of mgltools"""
68 if not Path(mgltools_path).exists():
69 fu.log(classname + ": Unexisting mgltools_path, exiting", out_log)
70 raise SystemExit(classname + ": Unexisting mgltools_path, exiting")
71 return mgltools_path
74'''def check_input_autodock(structure, out_log):
75 """ if structure ends with END, remove last line """
76 lines_new = []
77 with open(structure, 'r') as f:
78 lines = f.read().splitlines()
79 for item in lines:
80 #if not item.startswith('END'):
81 if not item.strip() == 'END':
82 lines_new.append(item)
83 else:
84 fu.log('%s file ends with END, cleaning' % structure, out_log)
86 with open(structure, 'w') as f:
87 for item in lines_new:
88 f.write("%s\n" % item)'''