Coverage for biobb_flexserv / flexserv / nma_run.py: 87%
46 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-05 13:10 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-05 13:10 +0000
1#!/usr/bin/env python3
3"""Module containing the nma_run class and the command line interface."""
4from typing import Optional
5import os
6from pathlib import Path
7from biobb_common.generic.biobb_object import BiobbObject
8from biobb_common.tools.file_utils import launchlogger
11class NMARun(BiobbObject):
12 """
13 | biobb_flexserv NMARun
14 | Wrapper of the Normal Mode Analysis tool from the FlexServ module.
15 | Generates protein conformational structures using the Normal Mode Analysis (NMA) method.
17 Args:
18 input_pdb_path (str): Input PDB file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/data/flexserv/structure.ca.pdb>`_. Accepted formats: pdb (edam:format_1476).
19 output_log_path (str): Output log file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/flexserv/nma_run_out.log>`_. Accepted formats: log (edam:format_2330), out (edam:format_2330), txt (edam:format_2330), o (edam:format_2330).
20 output_crd_path (str): Output ensemble. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/flexserv/nma_run_out.crd>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878).
21 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
22 * **binary_path** (*str*) - ("diaghess") NMA binary path to be used.
23 * **frames** (*int*) - (1000) Number of frames in the final ensemble
24 * **nvecs** (*int*) - (50) Number of vectors to take into account for the ensemble 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.
29 Examples:
30 This is a use example of how to use the building block from Python::
32 from biobb_flexserv.flexserv.bd_run import bd_run
33 prop = {
34 'binary_path': 'diaghess'
35 }
36 flexserv_run(input_pdb_path='/path/to/nma_input.pdb',
37 output_log_path='/path/to/nma_log.log',
38 output_crd_path='/path/to/nma_ensemble.crd',
39 properties=prop)
41 Info:
42 * wrapped_software:
43 * name: FlexServ Normal Mode Analysis
44 * version: >=1.0
45 * license: Apache-2.0
46 * ontology:
47 * name: EDAM
48 * schema: http://edamontology.org/EDAM.owl
50 """
52 def __init__(self, input_pdb_path: str, output_log_path: str,
53 output_crd_path: str, 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},
64 'out': {'output_log_path': output_log_path,
65 'output_crd_path': output_crd_path}
66 }
68 # Properties specific for BB
69 self.properties = properties
70 self.binary_path = properties.get('binary_path', 'diaghess')
71 self.frames = properties.get('frames', 1000)
72 self.nvecs = properties.get('nvecs', 50)
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 FlexServ NMARun module."""
82 # Setup Biobb
83 if self.check_restart():
84 return 0
85 self.stage_files()
87 # Internal file paths
88 try:
89 # Using rel paths to shorten the amount of characters due to fortran path length limitations
90 input_pdb = str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd()))
91 output_crd = str(Path(self.stage_io_dict["out"]["output_crd_path"]).relative_to(Path.cwd()))
92 output_log = str(Path(self.stage_io_dict["out"]["output_log_path"]).relative_to(Path.cwd()))
93 except ValueError:
94 # Container or remote case
95 input_pdb = self.stage_io_dict["in"]["input_pdb_path"]
96 output_crd = self.stage_io_dict["out"]["output_crd_path"]
97 output_log = self.stage_io_dict["out"]["output_log_path"]
99 # Command line
100 # nmanu.pl structure.ca.pdb hessian.dat 1 0 40
101 # diaghess
102 # mc-eigen.pl eigenvec.dat > file.proj
103 # pca_anim_mc.pl -pdb structure.ca.pdb -evec eigenvec.dat -i file.proj -n 50 -pout traj.crd
104 conda_path = os.getenv("CONDA_PREFIX")
105 nmanu = str(conda_path) + "/bin/nmanu.pl"
106 nma_eigen = str(conda_path) + "/bin/mc-eigen-mdweb.pl"
107 pca_anim = str(conda_path) + "/bin/pca_anim_mc.pl"
108 self.cmd = ["perl ",
109 nmanu,
110 input_pdb,
111 "hessian.dat 1 0 40;",
112 self.binary_path,
113 "; perl",
114 nma_eigen,
115 "eigenvec.dat ", str(self.frames), " > file.proj",
116 "; perl",
117 pca_anim,
118 "-pdb",
119 input_pdb,
120 " -evec eigenvec.dat -i file.proj -n ",
121 str(self.nvecs),
122 " -pout", output_crd,
123 '>', output_log
124 ]
126 # Run Biobb block
127 self.run_biobb()
129 # Copy files to host
130 self.copy_to_host()
132 # Remove temporary folder(s)
133 self.remove_tmp_files()
134 self.check_arguments(output_files_created=True, raise_exception=False)
136 return self.return_code
139def nma_run(input_pdb_path: str,
140 output_log_path: str, output_crd_path: str,
141 properties: Optional[dict] = None, **kwargs) -> int:
142 """Create :class:`NMARun <flexserv.nma_run.NMARun>`flexserv.nma_run.NMARun class and
143 execute :meth:`launch() <flexserv.nma_run.NMARun.launch>` method"""
144 return NMARun(**dict(locals())).launch()
147nma_run.__doc__ = NMARun.__doc__
148main = NMARun.get_main(nma_run, "Generates protein conformational structures using the Normal Mode Analysis method.")
150if __name__ == '__main__':
151 main()