Coverage for biobb_mem/gorder/gorder_cg.py: 94%

31 statements  

« prev     ^ index     » next       coverage.py v7.10.6, created at 2025-09-08 09:07 +0000

1#!/usr/bin/env python3 

2 

3"""Module containing the gorder coarse-grained class and the command line interface.""" 

4from biobb_common.generic.biobb_object import BiobbObject 

5from biobb_common.tools.file_utils import launchlogger 

6import gorder 

7 

8 

9class GorderCG(BiobbObject): 

10 """ 

11 | biobb_mem GorderCG 

12 | Wrapper of the gorder coarse-grained module for computing lipid order parameters per atom for carbon tails. 

13 | `gorder <https://ladme.github.io/gorder-manual/cgorder_basics.html>`_ uses `GSL <https://ladme.github.io/gsl-guide/>`_ for all its selections. 

14 

15 Args: 

16 input_top_path (str): Path to the input structure or topology file. File type: input. `Sample file <https://github.com/bioexcel/biobb_mem/raw/main/biobb_mem/test/data/CG/cg_test.tpr>`_. Accepted formats: tpr (edam:format_2333). 

17 input_traj_path (str): Path to the input trajectory to be processed. File type: input. `Sample file <https://github.com/bioexcel/biobb_mem/raw/main/biobb_mem/test/data/CG/cg_test.xtc>`_. Accepted formats: xtc (edam:format_3875), trr (edam:format_3910), gro (edam:format_2033). 

18 output_order_path (str): Path to results of the order analysis. File type: output. `Sample file <https://github.com/bioexcel/biobb_mem/raw/main/biobb_mem/test/reference/gorder/order_cg.yaml>`_. Accepted formats: yaml (edam:format_3570), xvg (edam:format_2330), csv (edam:format_3752). 

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

20 * **beads** (*str*) - ("@membrane") Selection query specifying the beads to be used in the analysis. 

21 * **handle_pbc** (*bool*) - (True) If False, ignores periodic boundary conditions (PBC). 

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

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

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

25 

26 Examples: 

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

28 

29 from biobb_mem.gorder.gorder_cg import gorder_cg 

30 prop = { 

31 'handle_pbc': False 

32 } 

33 gorder_cg(input_top_path='/path/to/myTopology.tpr', 

34 input_traj_path='/path/to/myTrajectory.xtc', 

35 output_order_path='/path/to/orderAnalysis.yaml', 

36 properties=prop) 

37 

38 Info: 

39 * wrapped_software: 

40 * name: gorder 

41 * version: 1.1.0 

42 * license: MIT 

43 * ontology: 

44 * name: EDAM 

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

46 

47 """ 

48 

49 def __init__(self, 

50 input_top_path, 

51 input_traj_path, 

52 output_order_path=None, 

53 properties=None, 

54 **kwargs) -> None: 

55 properties = properties or {} 

56 

57 # Call parent class constructor 

58 super().__init__(properties) 

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

60 

61 # Input/Output files 

62 self.io_dict = { 

63 "in": { 

64 "input_top_path": input_top_path, 

65 "input_traj_path": input_traj_path, 

66 }, 

67 "out": { 

68 "output_order_path": output_order_path 

69 } 

70 } 

71 

72 # Properties specific for BB 

73 self.beads = properties.get('beads', "@membrane") 

74 self.handle_pbc = properties.get('handle_pbc', True) 

75 self.properties = properties 

76 

77 # Check the properties 

78 self.check_properties(properties) 

79 self.check_arguments() 

80 

81 @launchlogger 

82 def launch(self) -> int: 

83 """Execute the :class:`GorderCG <gorder.gorder_cg.GorderCG>` object.""" 

84 

85 # Setup Biobb 

86 if self.check_restart(): 

87 return 0 

88 self.stage_files() 

89 

90 # Run Biobb block 

91 analysis = gorder.Analysis( 

92 structure=self.stage_io_dict["in"]["input_top_path"], 

93 trajectory=self.stage_io_dict["in"]["input_traj_path"], 

94 analysis_type=gorder.analysis_types.CGOrder(self.beads), 

95 output_yaml=self.stage_io_dict["out"]["output_order_path"], 

96 handle_pbc=False, 

97 ) 

98 

99 results = analysis.run() 

100 results.write() 

101 

102 # Copy files to host 

103 self.copy_to_host() 

104 self.remove_tmp_files() 

105 

106 return self.return_code 

107 

108 

109def gorder_cg(input_top_path: str, 

110 input_traj_path: str, 

111 output_order_path: str = None, 

112 properties: dict = None, 

113 **kwargs) -> int: 

114 """Create :class:`GorderCG <gorder.gorder_cg.GorderCG>` class and 

115 execute :meth:`launch() <gorder.gorder_cg.GorderCG.launch>` method""" 

116 return GorderCG(**dict(locals())).launch() 

117 

118 

119gorder_cg.__doc__ = GorderCG.__doc__ 

120main = GorderCG.get_main(gorder_cg, "Compute coarse-grained lipid order parameters using gorder order tool.") 

121 

122if __name__ == '__main__': 

123 main()