Coverage for biobb_flexserv/flexserv/dmd_run.py: 94%
51 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 dmd_run class and the command line interface."""
4from typing import Optional
5from pathlib import Path, PurePath
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.
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.dmd_run import dmd_run
39 prop = {
40 'binary_path': 'dmdgoopt'
41 }
42 flexserv_run(input_pdb_path='/path/to/dmd_input.pdb',
43 output_log_path='/path/to/dmd_log.log',
44 output_crd_path='/path/to/dmd_ensemble.crd',
45 properties=prop)
47 Info:
48 * wrapped_software:
49 * name: FlexServ Discrete Molecular 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', 'dmdgoopt')
77 # self.dt = properties.get('dt', 1.D-12)
78 self.dt = properties.get('dt', 1e-12)
79 self.temperature = properties.get('temperature', 300)
80 self.frames = properties.get('frames', 1000)
82 # Check the properties
83 self.check_properties(properties)
84 self.check_arguments()
86 @launchlogger
87 def launch(self):
88 """Launches the execution of the FlexServ BDRun module."""
90 # Setup Biobb
91 if self.check_restart():
92 return 0
93 self.stage_files()
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 # Config file
101 instructions_file = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath("dmd.in"))
102 with open(instructions_file, 'w') as dmdin:
104 dmdin.write("&INPUT\n")
105 dmdin.write(" FILE9='{}',\n".format(PurePath(self.stage_io_dict["in"]["input_pdb_path"]).name))
106 dmdin.write(" FILE21='{}',\n".format(PurePath(self.stage_io_dict["out"]["output_crd_path"]).name))
107 dmdin.write(" TSNAP={},\n".format(self.dt))
108 dmdin.write(" NBLOC={},\n".format(self.frames))
109 dmdin.write(" TEMP={},\n".format(self.temperature))
110 dmdin.write(" RCUTGO=8,\n")
111 dmdin.write(" RCA=0.5,\n")
112 dmdin.write(" SIGMA=0.05,\n")
113 dmdin.write(" SIGMAGO=0.1,\n")
114 dmdin.write(" KKK=2839\n")
115 dmdin.write("&END\n")
117 # Command line
118 # dmdgoopt < dmd.in > dmd.log
119 self.cmd = ["cd", working_dir, ";",
120 self.binary_path,
121 '<', PurePath(instructions_file).name,
122 '>', PurePath(self.stage_io_dict["out"]["output_log_path"]).name
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()