Coverage for biobb_flexdyn/flexdyn/imod_imove.py: 92%
39 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 07:02 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 07:02 +0000
1#!/usr/bin/env python3
3"""Module containing the imode class and the command line interface."""
4from typing import Optional
5from pathlib import PurePath
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
10class ImodImove(BiobbObject):
11 """
12 | biobb_flexdyn imod_imove
13 | Wrapper of the imove tool
14 | Compute the normal modes of a macromolecule using the imove tool from the iMODS package.
16 Args:
17 input_pdb_path (str): Input PDB file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/data/flexdyn/structure_cleaned.pdb>`_. Accepted formats: pdb (edam:format_1476).
18 input_dat_path (str): Input dat with normal modes. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/data/flexdyn/imod_imode_evecs.dat>`_. Accepted formats: dat (edam:format_1637), txt (edam:format_2330).
19 output_pdb_path (str): Output multi-model PDB file with the generated animation by Principal Component. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/imod_imove_output.pdb>`_. Accepted formats: pdb (edam:format_1476).
20 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
21 * **binary_path** (*str*) - ("imove") iMODS imove binary path to be used.
22 * **pc** (*int*) - (1) Principal Component.
23 * **num_frames** (*int*) - (11) Number of frames to be generated
24 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
25 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
26 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
27 * **container_path** (*str*) - (None) Path to the binary executable of your container.
28 * **container_image** (*str*) - ("cmip/cmip:latest") Container Image identifier.
29 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
30 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
31 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
32 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
34 Examples:
35 This is a use example of how to use the building block from Python::
37 from biobb_flexdyn.flexdyn.imod_imove import imod_imove
38 prop = {
39 'pc' : 1
40 }
41 imod_imove( input_pdb_path='/path/to/structure.pdb',
42 input_dat_path='/path/to/input_evecs.dat',
43 output_pdb_path='/path/to/output_anim.pdb',
44 properties=prop)
46 Info:
47 * wrapped_software:
48 * name: iMODS
49 * version: >=1.0.4
50 * license: other
51 * ontology:
52 * name: EDAM
53 * schema: http://edamontology.org/EDAM.owl
55 """
57 def __init__(self, input_pdb_path: str, input_dat_path: str, output_pdb_path: str,
58 properties: Optional[dict] = None, **kwargs) -> None:
60 properties = properties or {}
62 # Call parent class constructor
63 super().__init__(properties)
64 self.locals_var_dict = locals().copy()
66 # Input/Output files
67 self.io_dict = {
68 'in': {'input_pdb_path': input_pdb_path, 'input_dat_path': input_dat_path},
69 'out': {'output_pdb_path': output_pdb_path}
70 }
72 # Properties specific for BB
73 self.properties = properties
74 self.binary_path = properties.get('binary_path', 'imove')
76 self.pc = properties.get('pc', 1)
77 self.num_frames = properties.get('num_frames', 11)
79 # Check the properties
80 self.check_properties(properties)
81 self.check_arguments()
83 @launchlogger
84 def launch(self):
85 """Launches the execution of the FlexDyn iMOD imove module."""
87 # Setup Biobb
88 if self.check_restart():
89 return 0
90 self.stage_files()
92 # Determine working directory (host unique_dir or container volume path)
93 if self.container_path:
94 working_dir = self.container_volume_path if self.container_volume_path else "/data"
95 else:
96 working_dir = self.stage_io_dict.get('unique_dir', '')
98 # Command line
99 # imove 1ake_backbone.pdb 1ake_backbone_evecs.dat -o 1ake_backbone.ensemble.pdb 1 -c 500
100 # self.cmd = [self.binary_path,
101 # str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd())),
102 # str(Path(self.stage_io_dict["in"]["input_dat_path"]).relative_to(Path.cwd())),
103 # str(Path(self.stage_io_dict["out"]["output_pdb_path"]).relative_to(Path.cwd())),
104 # str(self.pc)
105 # ]
107 self.cmd = ['cd', working_dir, ';',
108 self.binary_path,
109 PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name,
110 PurePath(self.stage_io_dict["in"]["input_dat_path"]).name,
111 PurePath(self.stage_io_dict["out"]["output_pdb_path"]).name,
112 str(self.pc)
113 ]
115 # Properties
116 if self.num_frames:
117 self.cmd.append('-c')
118 self.cmd.append(str(self.num_frames))
120 # Run Biobb block
121 self.run_biobb()
123 # Copy files to host
124 self.copy_to_host()
126 # remove temporary folder(s)
127 self.remove_tmp_files()
129 self.check_arguments(output_files_created=True, raise_exception=False)
131 return self.return_code
134def imod_imove(input_pdb_path: str, input_dat_path: str, output_pdb_path: str,
135 properties: Optional[dict] = None, **kwargs) -> int:
136 """Create :class:`ImodImove <flexdyn.imod_imove.ImodImove>`flexdyn.imod_imove.ImodImove class and
137 execute :meth:`launch() <flexdyn.imod_imove.ImodImove.launch>` method"""
138 return ImodImove(**dict(locals())).launch()
141imod_imove.__doc__ = ImodImove.__doc__
142main = ImodImove.get_main(imod_imove, "Animate the normal modes of a macromolecule using the imove tool from the iMODS package.")
144if __name__ == '__main__':
145 main()