Coverage for biobb_structure_utils/utils/remove_pdb_water.py: 72%
39 statements
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-14 19:03 +0000
« prev ^ index » next coverage.py v7.5.3, created at 2024-06-14 19:03 +0000
1#!/usr/bin/env python3
3"""Module containing the RemovePdbWater class and the command line interface."""
4import argparse
5from biobb_common.configuration import settings
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
10class RemovePdbWater(BiobbObject):
11 """
12 | biobb_structure_utils RemovePdbWater
13 | This class is a wrapper of the Structure Checking tool to remove water molecules from PDB 3D structures.
14 | Wrapper for the `Structure Checking <https://github.com/bioexcel/biobb_structure_checking>`_ tool to remove water molecules from PDB 3D structures.
16 Args:
17 input_pdb_path (str): Input PDB file path. File type: input. `Sample file <https://github.com/bioexcel/biobb_structure_utils/raw/master/biobb_structure_utils/test/data/utils/WT_aq4_md_WAT.pdb>`_. Accepted formats: pdb (edam:format_1476).
18 output_pdb_path (str): Output PDB file path. File type: output. `Sample file <https://github.com/bioexcel/biobb_structure_utils/raw/master/biobb_structure_utils/test/reference/utils/WT_apo_no_wat.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 properties (dic - Python dictionary object containing the tool parameters, not input/output files):
20 * **binary_path** (*string*) - ("check_structure") path to the check_structure application
21 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
22 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
23 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
25 Examples:
26 This is a use example of how to use the building block from Python::
28 from biobb_structure_utils.utils.remove_pdb_water import remove_pdb_water
29 prop = { }
30 remove_pdb_water(input_pdb_path='/path/to/myStructure.pdb',
31 output_pdb_path='/path/to/newStructure.pdb',
32 properties=prop)
34 Info:
35 * wrapped_software:
36 * name: Structure Checking from MDWeb
37 * version: >=3.0.3
38 * license: Apache-2.0
39 * ontology:
40 * name: EDAM
41 * schema: http://edamontology.org/EDAM.owl
43 """
45 def __init__(self, input_pdb_path, output_pdb_path, properties=None, **kwargs) -> None:
46 properties = properties or {}
48 # Call parent class constructor
49 super().__init__(properties)
50 self.locals_var_dict = locals().copy()
52 # Input/Output files
53 self.io_dict = {
54 "in": {"input_pdb_path": input_pdb_path},
55 "out": {"output_pdb_path": output_pdb_path}
56 }
58 # Properties specific for BB
59 self.binary_path = properties.get('binary_path', 'check_structure')
61 # Check the properties
62 self.check_properties(properties)
63 self.check_arguments()
65 @launchlogger
66 def launch(self) -> int:
67 """Execute the :class:`RemovePdbWater <utils.remove_pdb_water.RemovePdbWater>` utils.remove_pdb_water.RemovePdbWater object."""
69 # Setup Biobb
70 if self.check_restart():
71 return 0
72 self.stage_files()
74 self.cmd = [self.binary_path,
75 '-i', self.stage_io_dict['in']['input_pdb_path'],
76 '-o', self.stage_io_dict['out']['output_pdb_path'],
77 '--force_save',
78 'water', '--remove', 'yes']
80 # Run Biobb block
81 self.run_biobb()
83 # Copy files to host
84 self.copy_to_host()
86 # Remove temporal files
87 self.tmp_files.append(self.stage_io_dict.get("unique_dir"))
88 self.remove_tmp_files()
90 self.check_arguments(output_files_created=True, raise_exception=False)
92 return self.return_code
95def remove_pdb_water(input_pdb_path: str, output_pdb_path: str, properties: dict = None, **kwargs) -> int:
96 """Execute the :class:`RemovePdbWater <utils.remove_pdb_water.RemovePdbWater>` class and
97 execute the :meth:`launch() <utils.remove_pdb_water.RemovePdbWater.launch>` method."""
99 return RemovePdbWater(input_pdb_path=input_pdb_path,
100 output_pdb_path=output_pdb_path,
101 properties=properties, **kwargs).launch()
104def main():
105 """Command line execution of this building block. Please check the command line documentation."""
106 parser = argparse.ArgumentParser(description="Remove the water molecules from a PDB 3D structure.",
107 formatter_class=lambda prog: argparse.RawTextHelpFormatter(prog, width=99999))
108 parser.add_argument('-c', '--config', required=False, help="This file can be a YAML file, JSON file or JSON string")
110 # Specific args of each building block
111 required_args = parser.add_argument_group('required arguments')
112 required_args.add_argument('-i', '--input_pdb_path', required=True, help="Input pdb file name")
113 required_args.add_argument('-o', '--output_pdb_path', required=True, help="Output pdb file name")
115 args = parser.parse_args()
116 config = args.config if args.config else None
117 properties = settings.ConfReader(config=config).get_prop_dic()
119 # Specific call of each building block
120 remove_pdb_water(input_pdb_path=args.input_pdb_path,
121 output_pdb_path=args.output_pdb_path,
122 properties=properties)
125if __name__ == '__main__':
126 main()