Coverage for biobb_flexserv / flexserv / bd_run.py: 86%
42 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 bd_run class and the command line interface."""
4from typing import Optional
5from pathlib import Path
6from biobb_common.generic.biobb_object import BiobbObject
7from biobb_common.tools.file_utils import launchlogger
10class BDRun(BiobbObject):
11 """
12 | biobb_flexserv BDRun
13 | Wrapper of the Browian Dynamics tool from the FlexServ module.
14 | Generates protein conformational structures using the Brownian Dynamics (BD) method.
16 Args:
17 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).
18 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/bd_run_out.log>`_. Accepted formats: log (edam:format_2330), out (edam:format_2330), txt (edam:format_2330), o (edam:format_2330).
19 output_crd_path (str): Output ensemble. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/flexserv/bd_run_out.crd>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878).
20 properties (dict - Python dictionary object containing the tool parameters, not input/output files):
21 * **binary_path** (*str*) - ("bd") BD binary path to be used.
22 * **time** (*int*) - (1000000) Total simulation time (ps)
23 * **dt** (*float*) - (1e-15) Integration time (ps)
24 * **wfreq** (*int*) - (1000) Writing frequency (ps)
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': 'bd'
35 }
36 flexserv_run(input_pdb_path='/path/to/bd_input.pdb',
37 output_log_path='/path/to/bd_log.log',
38 output_crd_path='/path/to/bd_ensemble.crd',
39 properties=prop)
41 Info:
42 * wrapped_software:
43 * name: FlexServ Brownian Dynamics
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', 'bd')
71 self.time = properties.get('time', 1000000)
72 self.dt = properties.get('dt', 1e-15)
73 self.wfreq = properties.get('wfreq', 1000)
75 # Check the properties
76 self.check_properties(properties)
77 self.check_arguments()
79 @launchlogger
80 def launch(self):
81 """Launches the execution of the FlexServ BDRun module."""
83 # Setup Biobb
84 if self.check_restart():
85 return 0
86 self.stage_files()
88 # Internal file paths
89 try:
90 # Using rel paths to shorten the amount of characters due to fortran path length limitations
91 input_pdb = str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd()))
92 output_crd = str(Path(self.stage_io_dict["out"]["output_crd_path"]).relative_to(Path.cwd()))
93 output_log = str(Path(self.stage_io_dict["out"]["output_log_path"]).relative_to(Path.cwd()))
94 except ValueError:
95 # Container or remote case
96 input_pdb = self.stage_io_dict["in"]["input_pdb_path"]
97 output_crd = self.stage_io_dict["out"]["output_crd_path"]
98 output_log = self.stage_io_dict["out"]["output_log_path"]
100 # Command line
101 # bd structure.ca.pdb 1000000 1e-15 1000 40 3.8 traj.crd > bd.log
102 # itempsmax, dt, itsnap, const, r0
103 self.cmd = [self.binary_path,
104 input_pdb,
105 str(self.time),
106 str(self.dt),
107 str(self.wfreq),
108 "40", # Hardcoded "Const", see https://mmb.irbbarcelona.org/gitlab/adam/FlexServ/blob/master/bd/bd2.f#L51
109 "3.8", # Hardcoded "r0", see https://mmb.irbbarcelona.org/gitlab/adam/FlexServ/blob/master/bd/bd2.f#L52
110 output_crd,
111 '>', output_log
112 ]
114 # Run Biobb block
115 self.run_biobb()
117 # Copy files to host
118 self.copy_to_host()
120 # Remove temporary folder(s)
121 self.remove_tmp_files()
122 self.check_arguments(output_files_created=True, raise_exception=False)
124 return self.return_code
127def bd_run(input_pdb_path: str,
128 output_log_path: str, output_crd_path: str,
129 properties: Optional[dict] = None, **kwargs) -> int:
130 """Create :class:`BDRun <flexserv.bd_run.BDRun>`flexserv.bd_run.BDRun class and
131 execute :meth:`launch() <flexserv.bd_run.BDRun.launch>` method"""
132 return BDRun(**dict(locals())).launch()
135bd_run.__doc__ = BDRun.__doc__
136main = BDRun.get_main(bd_run, "Generates protein conformational structures using the Brownian Dynamics method.")
138if __name__ == '__main__':
139 main()