Coverage for biobb_flexserv / flexserv / dmd_run.py: 89%
56 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 dmd_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 DMDRun(BiobbObject):
11 """
12 | biobb_flexserv DMDRun
13 | Wrapper of the Discrete Molecular Dynamics tool from the FlexServ module.
14 | Generates protein conformational structures using the Discrete Molecular Dynamics (DMD) 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/dmd_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/dmd_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*) - ("dmdgoopt") DMD binary path to be used.
22 * **dt** (*float*) - (1e-12) Integration time (s)
23 * **temperature** (*int*) - (300) Simulation temperature (K)
24 * **frames** (*int*) - (1000) Number of frames in the final ensemble
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.dmd_run import dmd_run
33 prop = {
34 'binary_path': 'dmdgoopt'
35 }
36 flexserv_run(input_pdb_path='/path/to/dmd_input.pdb',
37 output_log_path='/path/to/dmd_log.log',
38 output_crd_path='/path/to/dmd_ensemble.crd',
39 properties=prop)
41 Info:
42 * wrapped_software:
43 * name: FlexServ Discrete Molecular 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', 'dmdgoopt')
71 # self.dt = properties.get('dt', 1.D-12)
72 self.dt = properties.get('dt', 1e-12)
73 self.temperature = properties.get('temperature', 300)
74 self.frames = properties.get('frames', 1000)
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 FlexServ BDRun module."""
84 # Setup Biobb
85 if self.check_restart():
86 return 0
87 self.stage_files()
89 # Internal file paths
90 try:
91 # Using rel paths to shorten the amount of characters due to fortran path length limitations
92 input_pdb = str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd()))
93 output_crd = str(Path(self.stage_io_dict["out"]["output_crd_path"]).relative_to(Path.cwd()))
94 output_log = str(Path(self.stage_io_dict["out"]["output_log_path"]).relative_to(Path.cwd()))
95 except ValueError:
96 # Container or remote case
97 input_pdb = self.stage_io_dict["in"]["input_pdb_path"]
98 output_crd = self.stage_io_dict["out"]["output_crd_path"]
99 output_log = self.stage_io_dict["out"]["output_log_path"]
101 # Config file
102 instructions_file = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath("dmd.in"))
103 with open(instructions_file, 'w') as dmdin:
105 dmdin.write("&INPUT\n")
106 dmdin.write(" FILE9='{}',\n".format(input_pdb))
107 dmdin.write(" FILE21='{}',\n".format(output_crd))
108 dmdin.write(" TSNAP={},\n".format(self.dt))
109 dmdin.write(" NBLOC={},\n".format(self.frames))
110 dmdin.write(" TEMP={},\n".format(self.temperature))
111 dmdin.write(" RCUTGO=8,\n")
112 dmdin.write(" RCA=0.5,\n")
113 dmdin.write(" SIGMA=0.05,\n")
114 dmdin.write(" SIGMAGO=0.1,\n")
115 dmdin.write(" KKK=2839\n")
116 dmdin.write("&END\n")
118 # Command line
119 # dmdgoopt < dmd.in > dmd.log
120 self.cmd = [self.binary_path,
121 '<', instructions_file,
122 '>', output_log
123 ]
125 # Run Biobb block
126 self.run_biobb()
128 # Copy files to host
129 self.copy_to_host()
131 # Remove temporary folder(s)
132 self.remove_tmp_files()
133 self.check_arguments(output_files_created=True, raise_exception=False)
135 return self.return_code
138def dmd_run(input_pdb_path: str,
139 output_log_path: str, output_crd_path: str,
140 properties: Optional[dict] = None, **kwargs) -> int:
141 """Create :class:`DMDRun <flexserv.dmd_run.DMDRun>`flexserv.dmd_run.DMDRun class and
142 execute :meth:`launch() <flexserv.dmd_run.DMDRun.launch>` method"""
143 return DMDRun(**dict(locals())).launch()
146dmd_run.__doc__ = DMDRun.__doc__
147main = DMDRun.get_main(dmd_run, "Generates protein conformational structures using the Discrete Molecular Dynamics method.")
149if __name__ == '__main__':
150 main()