Coverage for biobb_flexdyn/flexdyn/imod_imode.py: 93%
41 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
5import shutil
6from pathlib import Path, PurePath
7from biobb_common.generic.biobb_object import BiobbObject
8from biobb_common.tools.file_utils import launchlogger
11class ImodImode(BiobbObject):
12 """
13 | biobb_flexdyn imod_imode
14 | Wrapper of the imode tool
15 | Compute the normal modes of a macromolecule using the imode tool from the iMODS package.
17 Args:
18 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.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_dat_path (str): Output dat with normal modes. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/imod_imode_evecs.dat>`_. Accepted formats: dat (edam:format_1637), txt (edam:format_2330).
20 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
21 * **binary_path** (*str*) - ("imode_gcc") iMODS imode binary path to be used.
22 * **cg** (*int*) - (2) Coarse-Grained model. Values: 0 (CA), 1 (C5), 2 (Heavy atoms).
23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files.
24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist.
25 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory.
26 * **container_path** (*str*) - (None) Path to the binary executable of your container.
27 * **container_image** (*str*) - ("cmip/cmip:latest") Container Image identifier.
28 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
29 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
30 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
31 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
33 Examples:
34 This is a use example of how to use the building block from Python::
36 from biobb_flexdyn.flexdyn.imod_imode import imod_imode
37 prop = {
38 'cg' : 2
39 }
40 imod_imode( input_pdb_path='/path/to/structure.pdb',
41 output_dat_path='/path/to/output_evecs.dat',
42 properties=prop)
44 Info:
45 * wrapped_software:
46 * name: iMODS
47 * version: >=1.0.4
48 * license: other
49 * ontology:
50 * name: EDAM
51 * schema: http://edamontology.org/EDAM.owl
53 """
55 def __init__(self, input_pdb_path: str, output_dat_path: str,
56 properties: Optional[dict] = None, **kwargs) -> None:
58 properties = properties or {}
60 # Call parent class constructor
61 super().__init__(properties)
62 self.locals_var_dict = locals().copy()
64 # Input/Output files
65 self.io_dict = {
66 'in': {'input_pdb_path': input_pdb_path},
67 'out': {'output_dat_path': output_dat_path}
68 }
70 # Properties specific for BB
71 self.properties = properties
72 self.binary_path = properties.get('binary_path', 'imode_gcc')
74 self.cg = properties.get('cg', 2)
76 # Check the properties
77 self.check_properties(properties)
78 self.check_arguments()
80 @launchlogger
81 def launch(self):
82 """Launches the execution of the FlexDyn iMOD imode module."""
84 # Setup Biobb
85 if self.check_restart():
86 return 0
87 self.stage_files()
89 # Determine working directory (host unique_dir or container volume path)
90 if self.container_path:
91 working_dir = self.container_volume_path if self.container_volume_path else "/data"
92 else:
93 working_dir = self.stage_io_dict.get('unique_dir', '')
95 # Output temporary file
96 # out_file_prefix = Path(self.stage_io_dict.get("unique_dir", "")).joinpath("imods_evecs")
97 # out_file = Path(self.stage_io_dict.get("unique_dir", "")).joinpath("imods_evecs_ic.evec")
98 out_file_prefix = "imods_evecs" # Needed as imod is appending the _ic.evec extension
99 out_file = "imods_evecs_ic.evec"
101 # Command line
102 # imode_gcc 1ake_backbone.pdb -m 0 -o patata.evec
103 # self.cmd = [self.binary_path,
104 # str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd())),
105 # "-o", str(out_file_prefix),
106 # "-m", str(self.cg)
107 # ]
109 self.cmd = ['cd', working_dir, ';',
110 self.binary_path,
111 PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name,
112 '-o', out_file_prefix,
113 '-m', str(self.cg)
114 ]
116 # Run Biobb block
117 self.run_biobb()
119 # Rename generated output file to staged output path inside the sandbox.
120 # stage_io_dict output paths are container-internal when running in containers.
121 generated_output = Path(self.stage_io_dict.get('unique_dir', '')).joinpath(out_file)
122 staged_output = Path(self.stage_io_dict.get('unique_dir', '')).joinpath(
123 Path(self.stage_io_dict["out"]["output_dat_path"]).name
124 )
125 shutil.copy2(generated_output, staged_output)
127 # Copy files to host
128 self.copy_to_host()
130 # remove temporary folder(s)
131 self.remove_tmp_files()
133 self.check_arguments(output_files_created=True, raise_exception=False)
135 return self.return_code
138def imod_imode(input_pdb_path: str, output_dat_path: str,
139 properties: Optional[dict] = None, **kwargs) -> int:
140 """Create :class:`ImodImode <flexdyn.imod_imode.ImodImode>`flexdyn.imod_imode.ImodImode class and
141 execute :meth:`launch() <flexdyn.imod_imode.ImodImode.launch>` method"""
142 return ImodImode(**dict(locals())).launch()
145imod_imode.__doc__ = ImodImode.__doc__
146main = ImodImode.get_main(imod_imode, "Compute the normal modes of a macromolecule using the imode tool from the iMODS package.")
148if __name__ == '__main__':
149 main()