Coverage for biobb_chemistry/ambertools/common.py: 70%
30 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 09:28 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-12 09:28 +0000
1""" Common functions for package biobb_chemistry.ambertools """
2from pathlib import Path, PurePath
3from biobb_common.tools import file_utils as fu
6def check_input_path(path, out_log, classname):
7 """ Checks input file """
8 if not Path(path).exists():
9 fu.log(classname + ': Unexisting input file, exiting', out_log)
10 raise SystemExit(classname + ': Unexisting input file')
11 file_extension = PurePath(path).suffix
12 if not is_valid_reduce(file_extension[1:]):
13 fu.log(classname + ': Format %s in input file is not compatible' % file_extension[1:], out_log)
14 raise SystemExit(classname + ': Format %s in input file is not compatible' % file_extension[1:])
15 if (PurePath(path).name == path or not PurePath(path).is_absolute()):
16 path = str(PurePath(Path.cwd()).joinpath(path))
18 return path
21def check_output_path(path, out_log, classname):
22 """ Checks output path """
23 if PurePath(path).parent and not Path(PurePath(path).parent).exists():
24 fu.log(classname + ': Unexisting output %s output folder, exiting' % type, out_log)
25 raise SystemExit(classname + ': Unexisting %s output folder' % type)
26 file_extension = PurePath(path).suffix
27 if not is_valid_reduce(file_extension[1:]):
28 fu.log(classname + ': Format %s in input file is not compatible' % file_extension[1:], out_log)
29 raise SystemExit(classname + ': Format %s in output file is not compatible' % file_extension[1:])
31 return path
34def get_binary_path(properties, type):
35 """ Gets binary path """
36 return properties.get(type, get_default_value(type))
39def get_default_value(key):
40 """ Gives default values according to the given key """
41 default_values = {
42 "binary_path": "reduce",
43 }
45 return default_values[key]
48def is_valid_reduce(ext):
49 """ Checks if input file format is compatible with Reduce """
50 formats = ["pdb"]
52 return ext in formats