Coverage for biobb_flexdyn / flexdyn / nolb_nma.py: 96%

48 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-16 13:07 +0000

1#!/usr/bin/env python3 

2 

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

4from typing import Optional 

5import shutil 

6from pathlib import Path 

7from biobb_common.generic.biobb_object import BiobbObject 

8from biobb_common.tools.file_utils import launchlogger 

9 

10 

11class Nolb_nma(BiobbObject): 

12 """ 

13 | biobb_flexdyn Nolb_nma 

14 | Wrapper of the NOLB tool 

15 | Generate an ensemble of structures using the NOLB (NOn-Linear rigid Block) NMA tool. 

16 

17 Args: 

18 input_pdb_path (str): Input PDB file. File type: input. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/data/flexdyn/structure.pdb>`_. Accepted formats: pdb (edam:format_1476). 

19 output_pdb_path (str): Output multi-model PDB file with the generated ensemble. File type: output. `Sample file <https://github.com/bioexcel/biobb_flexdyn/raw/master/biobb_flexdyn/test/reference/flexdyn/nolb_output.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

21 * **num_structs** (*int*) - (500) Number of structures to be generated 

22 * **cutoff** (*float*) - (5.0) This options specifies the interaction cutoff distance for the elastic network models (in angstroms), 5 by default. The Hessian matrix is constructed according to this interaction distance. Some artifacts should be expected for too short distances (< 5 Å). 

23 * **rmsd** (*float*) - (1.0) Maximum RMSd for decoy generation. 

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

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

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

27 

28 Examples: 

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

30 

31 from biobb_flexdyn.flexdyn.nolb_nma import nolb_nma 

32 prop = { 

33 'num_structs' : 20 

34 } 

35 nolb_nma( input_pdb_path='/path/to/structure.pdb', 

36 output_pdb_path='/path/to/output.pdb', 

37 properties=prop) 

38 

39 Info: 

40 * wrapped_software: 

41 * name: NOLB 

42 * version: >=1.9 

43 * license: other 

44 * ontology: 

45 * name: EDAM 

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

47 

48 """ 

49 

50 def __init__(self, input_pdb_path: str, output_pdb_path: str, 

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

52 

53 properties = properties or {} 

54 

55 # Call parent class constructor 

56 super().__init__(properties) 

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

58 

59 # Input/Output files 

60 self.io_dict = { 

61 'in': {'input_pdb_path': input_pdb_path}, 

62 'out': {'output_pdb_path': output_pdb_path} 

63 } 

64 

65 # Properties specific for BB 

66 self.properties = properties 

67 self.binary_path = properties.get('binary_path', 'NOLB') 

68 

69 self.num_structs = properties.get('num_structs', 500) 

70 # self.num_modes = properties.get('num_modes', 10) 

71 self.cutoff = properties.get('cutoff', 5.0) 

72 self.rmsd = properties.get('rmsd', 1.0) 

73 

74 # Check the properties 

75 self.check_properties(properties) 

76 self.check_arguments() 

77 

78 @launchlogger 

79 def launch(self): 

80 """Launches the execution of the FlexDyn NOLB module.""" 

81 

82 # Setup Biobb 

83 if self.check_restart(): 

84 return 0 

85 self.stage_files() 

86 

87 # Output temporary file 

88 out_file_prefix = Path(self.stage_io_dict.get("unique_dir", "")).joinpath("nolb_ensemble") 

89 out_file = Path(self.stage_io_dict.get("unique_dir", "")).joinpath("nolb_ensemble_nlb_decoys.pdb") 

90 

91 # Command line 

92 # ./NOLB 1ake_monomer.pdb -s 100 --rmsd 5 -m -o patata # Output: patata_nlb_decoys.pdb 

93 self.cmd = [self.binary_path, 

94 str(Path(self.stage_io_dict["in"]["input_pdb_path"]).relative_to(Path.cwd())), 

95 "-o", str(out_file_prefix), 

96 "-m" # Minimizing the generated structures by default 

97 ] 

98 

99 # Properties 

100 if self.num_structs: 

101 self.cmd.append('-s') 

102 self.cmd.append(str(self.num_structs)) 

103 

104 # Num modes is deactivated for the decoys generation. CHECK! 

105 # * **num_modes** (*int*) - (10) Number of non-trivial modes to compute, 10 by default. If this number exceeds the size of the Hessian matrix, it will be adapted accordingly. 

106 # if self.num_modes: 

107 # self.cmd.append('-n') 

108 # self.cmd.append(str(self.num_modes)) 

109 

110 if self.cutoff: 

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

112 self.cmd.append(str(self.cutoff)) 

113 

114 if self.rmsd: 

115 self.cmd.append('--rmsd') 

116 self.cmd.append(str(self.rmsd)) 

117 

118 # --dist 1 -m --nSteps 5000 --tol 0.001 

119 self.cmd.append("--dist 1 --nSteps 5000 --tol 0.001") 

120 

121 # Run Biobb block 

122 self.run_biobb() 

123 

124 # Copying generated output file to the final (user-given) file name 

125 shutil.copy2(out_file, self.stage_io_dict["out"]["output_pdb_path"]) 

126 

127 # Copy files to host 

128 self.copy_to_host() 

129 

130 # remove temporary folder(s) 

131 self.remove_tmp_files() 

132 

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

134 

135 return self.return_code 

136 

137 

138def nolb_nma(input_pdb_path: str, output_pdb_path: str, 

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

140 """Create :class:`Nolb_nma <flexdyn.nolb_nma.Nolb_nma>`flexdyn.nolb_nma.Nolb_nma class and 

141 execute :meth:`launch() <flexdyn.nolb_nma.Nolb_nma.launch>` method""" 

142 return Nolb_nma(**dict(locals())).launch() 

143 

144 

145nolb_nma.__doc__ = Nolb_nma.__doc__ 

146main = Nolb_nma.get_main(nolb_nma, "Generate an ensemble of structures using the NOLB (NOn-Linear rigid Block) NMA tool.") 

147 

148if __name__ == '__main__': 

149 main()