Coverage for biobb_flexdyn / flexdyn / imod_imove.py: 95%
42 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-16 13:07 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-16 13:07 +0000
1#!/usr/bin/env python3
3"""Module containing the imode class and the command line interface."""
4from typing import Optional
5import shutil
6from pathlib import PurePath
7from biobb_common.tools import file_utils as fu
8from biobb_common.generic.biobb_object import BiobbObject
9from biobb_common.tools.file_utils import launchlogger
12class ImodImove(BiobbObject):
13 """
14 | biobb_flexdyn imod_imove
15 | Wrapper of the imove tool
16 | Compute the normal modes of a macromolecule using the imove tool from the iMODS package.
18 Args:
19 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).
20 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).
21 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).
22 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
23 * **pc** (*int*) - (1) Principal Component.
24 * **num_frames** (*int*) - (11) Number of frames to be generated
25 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
26 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
27 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_flexdyn.flexdyn.imod_imove import imod_imove
33 prop = {
34 'pc' : 1
35 }
36 imod_imove( input_pdb_path='/path/to/structure.pdb',
37 input_dat_path='/path/to/input_evecs.dat',
38 output_pdb_path='/path/to/output_anim.pdb',
39 properties=prop)
41 Info:
42 * wrapped_software:
43 * name: iMODS
44 * version: >=1.0.4
45 * license: other
46 * ontology:
47 * name: EDAM
48 * schema: http://edamontology.org/EDAM.owl
50 """
52 def __init__(self, input_pdb_path: str, input_dat_path: str, output_pdb_path: str,
53 properties: Optional[dict] = None, **kwargs) -> None:
55 properties = properties or {}
57 # Call parent class constructor
58 super().__init__(properties)
59 self.locals_var_dict = locals().copy()
61 # Input/Output files
62 self.io_dict = {
63 'in': {'input_pdb_path': input_pdb_path, 'input_dat_path': input_dat_path},
64 'out': {'output_pdb_path': output_pdb_path}
65 }
67 # Properties specific for BB
68 self.properties = properties
69 self.binary_path = properties.get('binary_path', 'imove')
71 self.pc = properties.get('pc', 1)
72 self.num_frames = properties.get('num_frames', 11)
74 # Check the properties
75 self.check_properties(properties)
76 self.check_arguments()
78 @launchlogger
79 def launch(self):
80 """Launches the execution of the FlexDyn iMOD imove module."""
82 # Setup Biobb
83 if self.check_restart():
84 return 0
85 # self.stage_files()
87 # Manually creating a Sandbox to avoid issues with input parameters buffer overflow:
88 # Long strings defining a file path makes Fortran or C compiled programs crash if the string
89 # declared is shorter than the input parameter path (string) length.
90 # Generating a temporary folder and working inside this folder (sandbox) fixes this problem.
91 # The problem was found in Galaxy executions, launching Singularity containers (May 2023).
93 # Creating temporary folder
94 self.tmp_folder = fu.create_unique_dir()
95 fu.log('Creating %s temporary folder' % self.tmp_folder, self.out_log)
97 shutil.copy2(self.io_dict["in"]["input_pdb_path"], self.tmp_folder)
98 shutil.copy2(self.io_dict["in"]["input_dat_path"], self.tmp_folder)
100 # Command line
101 # imove 1ake_backbone.pdb 1ake_backbone_evecs.dat -o 1ake_backbone.ensemble.pdb 1 -c 500
102 # self.cmd = [self.binary_path,
103 # str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd())),
104 # str(Path(self.stage_io_dict["in"]["input_dat_path"]).relative_to(Path.cwd())),
105 # str(Path(self.stage_io_dict["out"]["output_pdb_path"]).relative_to(Path.cwd())),
106 # str(self.pc)
107 # ]
109 self.cmd = ['cd', self.tmp_folder, ';',
110 self.binary_path,
111 PurePath(self.io_dict["in"]["input_pdb_path"]).name,
112 PurePath(self.io_dict["in"]["input_dat_path"]).name,
113 PurePath(self.io_dict["out"]["output_pdb_path"]).name,
114 str(self.pc)
115 ]
117 # Properties
118 if self.num_frames:
119 self.cmd.append('-c')
120 self.cmd.append(str(self.num_frames))
122 # Run Biobb block
123 self.run_biobb()
125 # Copy outputs from temporary folder to output path
126 shutil.copy2(PurePath(self.tmp_folder).joinpath(PurePath(self.io_dict["out"]["output_pdb_path"]).name), PurePath(self.io_dict["out"]["output_pdb_path"]))
128 # Copy files to host
129 # self.copy_to_host()
131 # remove temporary folder(s)
132 self.tmp_files.extend([
133 self.tmp_folder
134 ])
135 self.remove_tmp_files()
137 self.check_arguments(output_files_created=True, raise_exception=False)
139 return self.return_code
142def imod_imove(input_pdb_path: str, input_dat_path: str, output_pdb_path: str,
143 properties: Optional[dict] = None, **kwargs) -> int:
144 """Create :class:`ImodImove <flexdyn.imod_imove.ImodImove>`flexdyn.imod_imove.ImodImove class and
145 execute :meth:`launch() <flexdyn.imod_imove.ImodImove.launch>` method"""
146 return ImodImove(**dict(locals())).launch()
149imod_imove.__doc__ = ImodImove.__doc__
150main = ImodImove.get_main(imod_imove, "Animate the normal modes of a macromolecule using the imove tool from the iMODS package.")
152if __name__ == '__main__':
153 main()