Coverage for biobb_gromacs / gromacs / convert_tpr.py: 0%

50 statements  

« prev     ^ index     » next       coverage.py v7.13.4, created at 2026-03-05 08:26 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the Convert_tpr class and the command line interface.""" 

4from typing import Optional 

5from biobb_common.generic.biobb_object import BiobbObject 

6from biobb_common.tools.file_utils import launchlogger 

7from biobb_gromacs.gromacs.common import get_gromacs_version 

8 

9 

10class ConvertTpr(BiobbObject): 

11 """ 

12 | biobb_gromacs ConvertTpr 

13 | Wrapper of the `GROMACS convert-tpr <https://manual.gromacs.org/current/onlinehelp/gmx-convert-tpr.html>`_ module. 

14 | The GROMACS convert-tpr module can edit run input files (.tpr) 

15 

16 Args: 

17 input_tpr_path (str): Path to the input portable binary run file TPR. File type: input. `Sample file <https://github.com/bioexcel/biobb_gromacs/raw/master/biobb_gromacs/test/reference/gromacs/ref_grompp.tpr>`_. Accepted formats: tpr (edam:format_2333). 

18 output_tpr_path (str): Path to the output portable binary run file TPR. File type: output. `Sample file <https://github.com/bioexcel/biobb_gromacs/raw/master/biobb_gromacs/test/reference/gromacs/ref_grompp.tpr>`_. Accepted formats: tpr (edam:format_2333). 

19 properties (dict - Python dictionary object containing the tool parameters, not input/output files): 

20 * **extend** (*int*) - (0) Extend the runtime by this amount (ps). 

21 * **until** (*int*) - (0) Extend the runtime until this ending time (ps). 

22 * **nsteps** (*int*) - (0) Change the number of steps remaining to be made. 

23 * **gmx_lib** (*str*) - (None) Path set GROMACS GMXLIB environment variable. 

24 * **binary_path** (*str*) - ("gmx") Path to the GROMACS executable binary. 

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) Path to the binary executable of your container. 

29 * **container_image** (*str*) - ("gromacs/gromacs:latest") Container Image identifier. 

30 * **container_volume_path** (*str*) - ("/data") Path to an internal directory in the container. 

31 * **container_working_dir** (*str*) - (None) Path to the internal CWD in the container. 

32 * **container_user_id** (*str*) - (None) User number id to be mapped inside the container. 

33 * **container_shell_path** (*str*) - ("/bin/bash") Path to the binary executable of the container shell. 

34 

35 Examples: 

36 This is a use example of how to use the building block from Python:: 

37 

38 from biobb_gromacs.gromacs.convert_tpr import convert_tpr 

39 

40 prop = { 'extend': 100000} 

41 convert_tpr(input_tpr_path='/path/to/myStructure.tpr', 

42 output_tpr_path='/path/to/newCompiledBin.tpr', 

43 properties=prop) 

44 

45 Info: 

46 * wrapped_software: 

47 * name: GROMACS Convert-tpr 

48 * version: 2025.2 

49 * license: LGPL 2.1 

50 * ontology: 

51 * name: EDAM 

52 * schema: http://edamontology.org/EDAM.owl 

53 """ 

54 

55 def __init__(self, input_tpr_path: str, output_tpr_path: str, 

56 properties: Optional[dict] = None, **kwargs) -> None: 

57 properties = properties or {} 

58 

59 # Call parent class constructor 

60 super().__init__(properties) 

61 self.locals_var_dict = locals().copy() 

62 

63 # Input/Output files 

64 self.io_dict = { 

65 "in": {"input_tpr_path": input_tpr_path}, 

66 "out": {"output_tpr_path": output_tpr_path} 

67 } 

68 

69 # Properties specific for BB 

70 self.extend = properties.get('extend') 

71 self.until = properties.get('until') 

72 self.nsteps = properties.get('nsteps') 

73 

74 # Properties common in all GROMACS BB 

75 self.gmx_lib = properties.get('gmx_lib', None) 

76 self.binary_path = properties.get('binary_path', 'gmx') 

77 self.gmx_nobackup = properties.get('gmx_nobackup', True) 

78 self.gmx_nocopyright = properties.get('gmx_nocopyright', True) 

79 if self.gmx_nobackup: 

80 self.binary_path += ' -nobackup' 

81 if self.gmx_nocopyright: 

82 self.binary_path += ' -nocopyright' 

83 if not self.container_path: 

84 self.gmx_version = get_gromacs_version(self.binary_path) 

85 

86 # Check the properties 

87 self.check_properties(properties) 

88 self.check_arguments() 

89 

90 @launchlogger 

91 def launch(self) -> int: 

92 """Execute the :class:`ConvertTpr <gromacs.convert_tpr.ConvertTpr>` object.""" 

93 

94 # Setup Biobb 

95 if self.check_restart(): 

96 return 0 

97 self.stage_files() 

98 

99 self.cmd = [self.binary_path, 'convert-tpr', 

100 '-s', self.stage_io_dict["in"]["input_tpr_path"], 

101 '-o', self.stage_io_dict["out"]["output_tpr_path"] 

102 ] 

103 

104 if self.extend: 

105 self.cmd.extend(['-extend', str(self.extend)]) 

106 if self.until: 

107 self.cmd.extend(['-until', str(self.until)]) 

108 if self.nsteps: 

109 self.cmd.extend(['-nsteps', str(self.nsteps)]) 

110 

111 if self.gmx_lib: 

112 self.env_vars_dict['GMXLIB'] = self.gmx_lib 

113 

114 # Run Biobb block 

115 self.run_biobb() 

116 

117 # Copy files to host 

118 self.copy_to_host() 

119 

120 self.remove_tmp_files() 

121 

122 self.check_arguments(output_files_created=True, raise_exception=False) 

123 return self.return_code 

124 

125 

126def convert_tpr(input_tpr_path: str, output_tpr_path: str, properties: Optional[dict] = None, **kwargs) -> int: 

127 """Create :class:`ConvertTpr <gromacs.convert_tpr.ConvertTpr>` class and 

128 execute the :meth:`launch() <gromacs.convert_tpr.ConvertTpr.launch>` method.""" 

129 return ConvertTpr(**dict(locals())).launch() 

130 

131 

132convert_tpr.__doc__ = ConvertTpr.__doc__ 

133main = ConvertTpr.get_main( 

134 convert_tpr, "Wrapper of the GROMACS convert-tpr module.") 

135 

136 

137if __name__ == '__main__': 

138 main()