Coverage for biobb_flexserv/flexserv/bd_run.py: 92%
37 statements
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 11:28 +0000
« prev ^ index » next coverage.py v7.14.1, created at 2026-05-28 11:28 +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 PurePath
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.
28 * **container_path** (*str*) - (None) Container path definition.
29 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition.
30 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition.
31 * **container_working_dir** (*str*) - (None) Container working directory definition.
32 * **container_user_id** (*str*) - (None) Container user_id definition.
33 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container.
35 Examples:
36 This is a use example of how to use the building block from Python::
38 from biobb_flexserv.flexserv.bd_run import bd_run
39 prop = {
40 'binary_path': 'bd'
41 }
42 flexserv_run(input_pdb_path='/path/to/bd_input.pdb',
43 output_log_path='/path/to/bd_log.log',
44 output_crd_path='/path/to/bd_ensemble.crd',
45 properties=prop)
47 Info:
48 * wrapped_software:
49 * name: FlexServ Brownian Dynamics
50 * version: >=1.0
51 * license: Apache-2.0
52 * ontology:
53 * name: EDAM
54 * schema: http://edamontology.org/EDAM.owl
56 """
58 def __init__(self, input_pdb_path: str, output_log_path: str,
59 output_crd_path: str, properties: Optional[dict] = None, **kwargs) -> None:
61 properties = properties or {}
63 # Call parent class constructor
64 super().__init__(properties)
65 self.locals_var_dict = locals().copy()
67 # Input/Output files
68 self.io_dict = {
69 'in': {'input_pdb_path': input_pdb_path},
70 'out': {'output_log_path': output_log_path,
71 'output_crd_path': output_crd_path}
72 }
74 # Properties specific for BB
75 self.properties = properties
76 self.binary_path = properties.get('binary_path', 'bd')
77 self.time = properties.get('time', 1000000)
78 self.dt = properties.get('dt', 1e-15)
79 self.wfreq = properties.get('wfreq', 1000)
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 FlexServ BDRun module."""
89 # Setup Biobb
90 if self.check_restart():
91 return 0
92 self.stage_files()
94 if self.container_path:
95 working_dir = self.container_volume_path if self.container_volume_path else "/data"
96 else:
97 working_dir = self.stage_io_dict.get("unique_dir", "")
99 # Command line
100 # bd structure.ca.pdb 1000000 1e-15 1000 40 3.8 traj.crd > bd.log
101 # itempsmax, dt, itsnap, const, r0
102 self.cmd = ["cd", working_dir, ";",
103 self.binary_path,
104 PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name,
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 PurePath(self.stage_io_dict["out"]["output_crd_path"]).name,
111 '>', PurePath(self.stage_io_dict["out"]["output_log_path"]).name
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()