Coverage for biobb_flexdyn / flexdyn / prody_anm.py: 95%

43 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 prody_anm class and the command line interface.""" 

4from typing import Optional 

5import prody # type: ignore 

6from biobb_common.generic.biobb_object import BiobbObject 

7from biobb_common.tools.file_utils import launchlogger 

8 

9 

10class ProdyANM(BiobbObject): 

11 """ 

12 | biobb_flexdyn ProdyANM 

13 | Wrapper of the ANM tool from the Prody package. 

14 | Generate an ensemble of structures using the Prody Anisotropic Network Model (ANM), for coarse-grained NMA. 

15 

16 Args: 

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

18 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/prody_output.pdb>`_. Accepted formats: pdb (edam:format_1476). 

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

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

21 * **selection** (*str*) - (calpha) Atoms selection (Prody syntax: http://prody.csb.pitt.edu/manual/reference/atomic/select.html) 

22 * **cutoff** (*float*) - (15.0) Cutoff distance (Å) for pairwise interactions, minimum is 4.0 Å 

23 * **gamma** (*float*) - (1.0) Spring constant 

24 * **rmsd** (*float*) - (1.0) Average RMSD that the conformations will have with respect to the initial conformation 

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

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

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

28 

29 Examples: 

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

31 

32 from biobb_flexdyn.flexdyn.prody_anm import prody_anm 

33 prop = { 

34 'num_structs' : 20, 

35 'rmsd' : 4.0 

36 } 

37 prody_anm( input_pdb_path='/path/to/structure.pdb', 

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

39 properties=prop) 

40 

41 Info: 

42 * wrapped_software: 

43 * name: Prody 

44 * version: >=2.2.0 

45 * license: MIT 

46 * ontology: 

47 * name: EDAM 

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

49 

50 """ 

51 

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

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

54 

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': {'input_pdb_path': input_pdb_path}, 

64 'out': {'output_pdb_path': output_pdb_path} 

65 } 

66 

67 # Properties specific for BB 

68 self.properties = properties 

69 

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

71 self.selection = properties.get('selection', 'calpha') 

72 self.cutoff = properties.get('cutoff', 15.0) 

73 self.gamma = properties.get('gamma', 1.0) 

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

75 

76 # Check the properties 

77 self.check_properties(properties) 

78 self.check_arguments() 

79 

80 @launchlogger 

81 def launch(self): 

82 """Launches the execution of the FlexDyn ConcoordDist module.""" 

83 

84 # Setup Biobb 

85 if self.check_restart(): 

86 return 0 

87 self.stage_files() 

88 

89 prot = prody.parsePDB(self.stage_io_dict["in"]["input_pdb_path"],) 

90 

91 # http://prody.csb.pitt.edu/manual/reference/atomic/select.html 

92 prot_sel = prot.select(self.selection) # type: ignore 

93 

94 enm = prody.ANM('BioBB_flexdyn Prody ANM ensemble generator') 

95 

96 enm.buildHessian(prot_sel, cutoff=self.cutoff, gamma=self.gamma) 

97 

98 enm.calcModes() 

99 

100 bb_enm, bb_atoms = prody.extendModel(enm, prot_sel, prot_sel) 

101 

102 ensemble = prody.sampleModes(bb_enm[:3], bb_atoms, n_confs=self.num_structs, rmsd=self.rmsd) 

103 

104 nmastruct = bb_atoms.copy() 

105 nmastruct.addCoordset(ensemble) 

106 

107 prody.writePDB(self.stage_io_dict["out"]["output_pdb_path"], nmastruct) 

108 

109 # Copy files to host 

110 self.copy_to_host() 

111 

112 # remove temporary folder(s) 

113 self.remove_tmp_files() 

114 

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

116 

117 return self.return_code 

118 

119 

120def prody_anm(input_pdb_path: str, output_pdb_path: str, 

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

122 """Create :class:`ProdyANM <flexdyn.prody_anm.ProdyANM>`flexdyn.prody_anm.ProdyANM class and 

123 execute :meth:`launch() <flexdyn.prody_anm.ProdyANM.launch>` method""" 

124 return ProdyANM(**dict(locals())).launch() 

125 

126 

127prody_anm.__doc__ = ProdyANM.__doc__ 

128main = ProdyANM.get_main(prody_anm, "Generate an ensemble of structures using the Prody Anisotropic Network Model (ANM), for coarse-grained NMA.") 

129 

130if __name__ == '__main__': 

131 main()