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

33 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 all atom 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 GorderAA(BiobbObject): 

10 """ 

11 | biobb_mem GorderAA 

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

13 | `gorder <https://ladme.github.io/gorder-manual/aaorder_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/A01IP/A01IP.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/A01IP/A01IP.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_aa.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 * **heavy_atoms** (*str*) - ("@membrane and name r'C3.+|C2.+'") Selection query specifying the heavy atoms to be used in the analysis (typically carbon atoms in lipid tails). 

21 * **hydrogens** (*str*) - ("@membrane and element name hydrogen") Selection query specifiying the hydrogen atoms to be used in the analysis (only those bonded to heavy atoms will be considered). 

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

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 

27 Examples: 

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

29 

30 from biobb_mem.gorder.gorder_aa import gorder_aa 

31 prop = { 

32 'handle_pbc': False 

33 } 

34 gorder_aa(input_top_path='/path/to/myTopology.tpr', 

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

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

37 properties=prop) 

38 

39 Info: 

40 * wrapped_software: 

41 * name: gorder 

42 * version: 1.1.0 

43 * license: MIT 

44 * ontology: 

45 * name: EDAM 

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

47 

48 """ 

49 

50 def __init__(self, 

51 input_top_path, 

52 input_traj_path, 

53 output_order_path=None, 

54 properties=None, 

55 **kwargs) -> None: 

56 properties = properties or {} 

57 

58 # Call parent class constructor 

59 super().__init__(properties) 

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

61 

62 # Input/Output files 

63 self.io_dict = { 

64 "in": { 

65 "input_top_path": input_top_path, 

66 "input_traj_path": input_traj_path, 

67 }, 

68 "out": { 

69 "output_order_path": output_order_path 

70 } 

71 } 

72 

73 # Properties specific for BB 

74 self.heavy_atoms = properties.get('heavy_atoms', "@membrane and name r'C3.+|C2.+'") 

75 self.hydrogens = properties.get('hydrogens', '@membrane and element name hydrogen') 

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

77 self.properties = properties 

78 

79 # Check the properties 

80 self.check_properties(properties) 

81 self.check_arguments() 

82 

83 @launchlogger 

84 def launch(self) -> int: 

85 """Execute the :class:`GorderAA <gorder.gorder_aa.GorderAA>` object.""" 

86 

87 # Setup Biobb 

88 if self.check_restart(): 

89 return 0 

90 self.stage_files() 

91 

92 out = self.stage_io_dict["out"]["output_order_path"] 

93 # Run Biobb block 

94 analysis = gorder.Analysis( 

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

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

97 analysis_type=gorder.analysis_types.AAOrder(self.heavy_atoms, self.hydrogens), 

98 output_yaml=out if out.endswith('.yaml') else None, 

99 output_csv=out if out.endswith('.csv') else None, 

100 output_xvg=out if out.endswith('.xvg') else None, 

101 handle_pbc=self.handle_pbc, 

102 ) 

103 

104 results = analysis.run() 

105 results.write() 

106 

107 # Copy files to host 

108 self.copy_to_host() 

109 self.remove_tmp_files() 

110 

111 return self.return_code 

112 

113 

114def gorder_aa(input_top_path: str, 

115 input_traj_path: str, 

116 output_order_path: str = None, 

117 properties: dict = None, 

118 **kwargs) -> int: 

119 """Create :class:`GorderAA <gorder.gorder_aa.GorderAA>` class and 

120 execute :meth:`launch() <gorder.gorder_aa.GorderAA.launch>` method""" 

121 return GorderAA(**dict(locals())).launch() 

122 

123 

124gorder_aa.__doc__ = GorderAA.__doc__ 

125main = GorderAA.get_main(gorder_aa, "Compute atomistic lipid order parameters using gorder order tool.") 

126 

127if __name__ == '__main__': 

128 main()