Coverage for biobb_flexdyn/flexdyn/nolb_nma.py: 94%
53 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 nolb 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 Nolb_nma(BiobbObject):
12 """
13 | biobb_flexdyn Nolb_nma
14 | Wrapper of the NOLB tool
15 | Generate an ensemble of structures using the NOLB (NOn-Linear rigid Block) NMA tool.
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_pdb_path (str): Output multi-model PDB file with the generated ensemble. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/nolb_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*) - ("NOLB") NOLB binary path to be used.
22 * **num_structs** (*int*) - (500) Number of structures to be generated
23 * **cutoff** (*float*) - (5.0) This options specifies the interaction cutoff distance for the elastic network models (in angstroms), 5 by default. The Hessian matrix is constructed according to this interaction distance. Some artifacts should be expected for too short distances (< 5 Å).
24 * **rmsd** (*float*) - (1.0) Maximum RMSd for decoy generation.
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.
28 * **container_path** (*str*) - (None) Path to the binary executable of your container.
29 * **container_image** (*str*) - ("cmip/cmip:latest") Container Image identifier.
30 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container.
31 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container.
32 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container.
33 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell.
35 Examples:
36 This is a use example of how to use the building block from Python::
38 from biobb_flexdyn.flexdyn.nolb_nma import nolb_nma
39 prop = {
40 'num_structs' : 20
41 }
42 nolb_nma( input_pdb_path='/path/to/structure.pdb',
43 output_pdb_path='/path/to/output.pdb',
44 properties=prop)
46 Info:
47 * wrapped_software:
48 * name: NOLB
49 * version: >=1.9
50 * license: other
51 * ontology:
52 * name: EDAM
53 * schema: http://edamontology.org/EDAM.owl
55 """
57 def __init__(self, input_pdb_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},
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', 'NOLB')
76 self.num_structs = properties.get('num_structs', 500)
77 # self.num_modes = properties.get('num_modes', 10)
78 self.cutoff = properties.get('cutoff', 5.0)
79 self.rmsd = properties.get('rmsd', 1.0)
81 # Check the properties
82 self.check_properties(properties)
83 self.check_arguments()
85 @launchlogger
86 def launch(self):
87 """Launches the execution of the FlexDyn NOLB module."""
89 # Setup Biobb
90 if self.check_restart():
91 return 0
92 self.stage_files()
94 # Determine working directory (host unique_dir or container volume path)
95 if self.container_path:
96 working_dir = self.container_volume_path if self.container_volume_path else "/data"
97 else:
98 working_dir = self.stage_io_dict.get('unique_dir', '')
100 # Output temporary file
101 out_file_prefix = "nolb_ensemble"
102 out_file = "nolb_ensemble_nlb_decoys.pdb"
104 # Command line
105 # ./NOLB 1ake_monomer.pdb -s 100 --rmsd 5 -m -o patata # Output: patata_nlb_decoys.pdb
106 self.cmd = ["cd", working_dir, ";", self.binary_path,
107 PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name,
108 "-o", out_file_prefix,
109 "-m" # Minimizing the generated structures by default
110 ]
112 # Properties
113 if self.num_structs:
114 self.cmd.append('-s')
115 self.cmd.append(str(self.num_structs))
117 # Num modes is deactivated for the decoys generation. CHECK!
118 # * **num_modes** (*int*) - (10) Number of non-trivial modes to compute, 10 by default. If this number exceeds the size of the Hessian matrix, it will be adapted accordingly.
119 # if self.num_modes:
120 # self.cmd.append('-n')
121 # self.cmd.append(str(self.num_modes))
123 if self.cutoff:
124 self.cmd.append('-c')
125 self.cmd.append(str(self.cutoff))
127 if self.rmsd:
128 self.cmd.append('--rmsd')
129 self.cmd.append(str(self.rmsd))
131 # --dist 1 -m --nSteps 5000 --tol 0.001
132 self.cmd.append("--dist 1 --nSteps 5000 --tol 0.001")
134 # Run Biobb block
135 self.run_biobb()
137 # Rename generated output file to staged output path inside the sandbox.
138 # stage_io_dict output paths are container-internal when running in containers.
139 generated_output = Path(self.stage_io_dict.get("unique_dir", "")).joinpath(out_file)
140 staged_output = Path(self.stage_io_dict.get("unique_dir", "")).joinpath(
141 Path(self.stage_io_dict["out"]["output_pdb_path"]).name
142 )
143 shutil.copy2(generated_output, staged_output)
145 # Copy files to host
146 self.copy_to_host()
148 # remove temporary folder(s)
149 self.remove_tmp_files()
151 self.check_arguments(output_files_created=True, raise_exception=False)
153 return self.return_code
156def nolb_nma(input_pdb_path: str, output_pdb_path: str,
157 properties: Optional[dict] = None, **kwargs) -> int:
158 """Create :class:`Nolb_nma <flexdyn.nolb_nma.Nolb_nma>`flexdyn.nolb_nma.Nolb_nma class and
159 execute :meth:`launch() <flexdyn.nolb_nma.Nolb_nma.launch>` method"""
160 return Nolb_nma(**dict(locals())).launch()
163nolb_nma.__doc__ = Nolb_nma.__doc__
164main = Nolb_nma.get_main(nolb_nma, "Generate an ensemble of structures using the NOLB (NOn-Linear rigid Block) NMA tool.")
166if __name__ == '__main__':
167 main()