Coverage for biobb_flexserv/pcasuite/pcz_lindemann.py: 92%

49 statements  

« prev     ^ index     » next       coverage.py v7.14.1, created at 2026-05-28 11:28 +0000

1#!/usr/bin/env python3 

2 

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

4from typing import Optional 

5import json 

6from pathlib import Path, PurePath 

7from biobb_common.generic.biobb_object import BiobbObject 

8from biobb_common.tools.file_utils import launchlogger 

9 

10 

11class PCZlindemann(BiobbObject): 

12 """ 

13 | biobb_flexserv PCZlindemann 

14 | Extract Lindemann coefficient (an estimate of the solid-liquid behaviour of a protein) from a compressed PCZ file. 

15 | Wrapper of the pczdump tool from the PCAsuite FlexServ module. 

16 

17 Args: 

18 input_pcz_path (str): Input compressed trajectory file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/data/pcasuite/pcazip.pcz>`_. Accepted formats: pcz (edam:format_3874). 

19 output_json_path (str): Output json file with PCA Eigen Vectors. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/pcasuite/pcz_lindemann.json>`_. Accepted formats: json (edam:format_3464). 

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

21 * **binary_path** (*str*) - ("pczdump") pczdump binary path to be used. 

22 * **mask** (*str*) - ("all atoms") Residue mask, in the format ":resnum1, resnum2, resnum3" (e.g. ":10,21,33"). See https://mmb.irbbarcelona.org/software/pcasuite/ for the complete format specification. 

23 * **remove_tmp** (*bool*) - (True) [WF property] Remove temporal files. 

24 * **restart** (*bool*) - (False) [WF property] Do not execute if output files exist. 

25 * **sandbox_path** (*str*) - ("./") [WF property] Parent path to the sandbox directory. 

26 * **container_path** (*str*) - (None) Container path definition. 

27 * **container_image** (*str*) - ('afandiadib/ambertools:serial') Container image definition. 

28 * **container_volume_path** (*str*) - ('/tmp') Container volume path definition. 

29 * **container_working_dir** (*str*) - (None) Container working directory definition. 

30 * **container_user_id** (*str*) - (None) Container user_id definition. 

31 * **container_shell_path** (*str*) - ('/bin/bash') Path to default shell inside the container. 

32 

33 Examples: 

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

35 

36 from biobb_flexserv.pcasuite.pcz_lindemann import pcz_lindemann 

37 prop = { 

38 'mask': ':10,12,15' 

39 } 

40 pcz_lindemann( input_pcz_path='/path/to/pcazip_input.pcz', 

41 output_json_path='/path/to/lindemann_report.json', 

42 properties=prop) 

43 

44 Info: 

45 * wrapped_software: 

46 * name: FlexServ PCAsuite 

47 * version: >=1.0 

48 * license: Apache-2.0 

49 * ontology: 

50 * name: EDAM 

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

52 

53 """ 

54 

55 def __init__(self, input_pcz_path: str, 

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

57 

58 properties = properties or {} 

59 

60 # Call parent class constructor 

61 super().__init__(properties) 

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

63 

64 # Input/Output files 

65 self.io_dict = { 

66 'in': {'input_pcz_path': input_pcz_path}, 

67 'out': {'output_json_path': output_json_path} 

68 } 

69 

70 # Properties specific for BB 

71 self.properties = properties 

72 self.binary_path = properties.get('binary_path', 'pczdump') 

73 self.mask = properties.get('mask', '') 

74 

75 # Check the properties 

76 self.check_properties(properties) 

77 self.check_arguments() 

78 

79 @launchlogger 

80 def launch(self): 

81 """Launches the execution of the FlexServ pcz_lindemann module.""" 

82 

83 # Setup Biobb 

84 if self.check_restart(): 

85 return 0 

86 self.stage_files() 

87 

88 if self.container_path: 

89 working_dir = self.container_volume_path if self.container_volume_path else "/data" 

90 else: 

91 working_dir = self.stage_io_dict.get("unique_dir", "") 

92 

93 unique_dir = Path(self.stage_io_dict.get("unique_dir", "")) 

94 

95 # Temporary output 

96 # temp_out = str(Path(self.stage_io_dict.get("unique_dir", "")).joinpath("output.dat")) 

97 temp_out = "output.dat" 

98 temp_out_path = unique_dir.joinpath(temp_out) 

99 staged_output_json_path = unique_dir.joinpath(Path(self.stage_io_dict["out"]["output_json_path"]).name) 

100 

101 # Command line 

102 # pczdump -i structure.ca.std.pcz --lindemann -M ":2-86" -o lindemann_report.txt 

103 # self.cmd = [self.binary_path, 

104 # "-i", input_pcz, 

105 # "-o", temp_out, 

106 # "--lindemann" 

107 # ] 

108 

109 self.cmd = ['cd', working_dir, ';', 

110 self.binary_path, 

111 "-i", PurePath(self.stage_io_dict["in"]["input_pcz_path"]).name, 

112 "-o", temp_out, 

113 "--lindemann" 

114 ] 

115 

116 if self.mask: 

117 self.cmd.extend(["-M", self.mask]) 

118 

119 # Run Biobb block 

120 self.run_biobb() 

121 

122 # Parse output Lindemann 

123 # 0.132891 

124 info_dict = {} 

125 with open(temp_out_path, 'r') as file: 

126 for line in file: 

127 info = float(line.strip()) 

128 info_dict['lindemann'] = info 

129 

130 with open(staged_output_json_path, 'w') as out_file: 

131 out_file.write(json.dumps(info_dict, indent=4)) 

132 

133 # Copy files to host 

134 self.copy_to_host() 

135 

136 # Remove temporary folder(s) 

137 self.remove_tmp_files() 

138 

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

140 

141 return self.return_code 

142 

143 

144def pcz_lindemann(input_pcz_path: str, output_json_path: str, 

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

146 """Create :class:`PCZlindemann <flexserv.pcasuite.pcz_lindemann>`flexserv.pcasuite.PCZlindemann class and 

147 execute :meth:`launch() <flexserv.pcasuite.pcz_lindemann.launch>` method""" 

148 return PCZlindemann(**dict(locals())).launch() 

149 

150 

151pcz_lindemann.__doc__ = PCZlindemann.__doc__ 

152main = PCZlindemann.get_main(pcz_lindemann, "Extract Lindemann coefficients from a compressed PCZ file.") 

153 

154if __name__ == '__main__': 

155 main()