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

38 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 PCZanimate 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 

8 

9 

10class PCZanimate(BiobbObject): 

11 """ 

12 | biobb_flexserv PCZanimate 

13 | Extract PCA animations from a compressed PCZ file. 

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

15 

16 Args: 

17 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). 

18 output_crd_path (str): Output PCA animated trajectory file. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexserv/raw/master/biobb_flexserv/test/reference/pcasuite/pcazip_anim1.pdb>`_. Accepted formats: crd (edam:format_3878), mdcrd (edam:format_3878), inpcrd (edam:format_3878), pdb (edam:format_1476). 

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

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

21 * **eigenvector** (*int*) - (1) Eigenvector to be used for the animation 

22 * **pdb** (*bool*) - (False) Use PDB format for output trajectory 

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_animate import pcz_animate 

37 prop = { 

38 'eigenvector': 1, 

39 'pdb': True 

40 } 

41 pcz_animate( input_pcz_path='/path/to/pcazip_input.pcz', 

42 output_crd_path='/path/to/animated_traj.pdb', 

43 properties=prop) 

44 

45 Info: 

46 * wrapped_software: 

47 * name: FlexServ PCAsuite 

48 * version: >=1.0 

49 * license: Apache-2.0 

50 * ontology: 

51 * name: EDAM 

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

53 

54 """ 

55 

56 def __init__(self, input_pcz_path: str, 

57 output_crd_path: str, properties: Optional[dict] = None, **kwargs) -> None: 

58 

59 properties = properties or {} 

60 

61 # Call parent class constructor 

62 super().__init__(properties) 

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

64 

65 # Input/Output files 

66 self.io_dict = { 

67 'in': {'input_pcz_path': input_pcz_path}, 

68 'out': {'output_crd_path': output_crd_path} 

69 } 

70 

71 # Properties specific for BB 

72 self.properties = properties 

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

74 self.eigenvector = properties.get('eigenvector', 1) 

75 self.pdb = properties.get('pdb', False) 

76 

77 # Check the properties 

78 self.check_properties(properties) 

79 self.check_arguments() 

80 

81 @launchlogger 

82 def launch(self): 

83 """Launches the execution of the FlexServ pcz_animate module.""" 

84 

85 # Setup Biobb 

86 if self.check_restart(): 

87 return 0 

88 self.stage_files() 

89 

90 if self.container_path: 

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

92 else: 

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

94 

95 # Command line 

96 # pczdump -i structure.ca.std.pcz --anim=1 --pdb -o anim_1.pdb 

97 # self.cmd = [self.binary_path, 

98 # "-i", input_pcz, 

99 # "-o", output_crd, 

100 # "--anim={}".format(self.eigenvector) 

101 # ] 

102 

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

104 self.binary_path, 

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

106 '-o', PurePath(self.stage_io_dict["out"]["output_crd_path"]).name, 

107 "--anim={}".format(self.eigenvector) 

108 ] 

109 

110 if self.pdb: 

111 self.cmd.append('--pdb') 

112 

113 # Run Biobb block 

114 self.run_biobb() 

115 

116 # Copy files to host 

117 self.copy_to_host() 

118 

119 # Remove temporary folder(s) 

120 self.remove_tmp_files() 

121 

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

123 

124 return self.return_code 

125 

126 

127def pcz_animate(input_pcz_path: str, output_crd_path: str, 

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

129 """Create :class:`PCZanimate <flexserv.pcasuite.pcz_animate>`flexserv.pcasuite.PCZanimate class and 

130 execute :meth:`launch() <flexserv.pcasuite.pcz_animate.launch>` method""" 

131 return PCZanimate(**dict(locals())).launch() 

132 

133 

134pcz_animate.__doc__ = PCZanimate.__doc__ 

135main = PCZanimate.get_main(pcz_animate, "Extract PCA animations from a compressed PCZ file.") 

136 

137if __name__ == '__main__': 

138 main()