Coverage for biobb_cmip/utils/representation.py: 0%

63 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-28 09:52 +0000

1""" Representation functions for package biobb_cmip.cmip """ 

2from biobb_cmip.cmip.common import get_grid 

3from pathlib import Path 

4from MDAnalysis.lib.util import inverse_aa_codes # type: ignore 

5from typing import Union 

6 

7 

8def get_energies_byat(cmip_energies_byat_out: Union[str, Path], cutoff: float = 100.0) -> tuple[list[str], dict[str, list[float]]]: 

9 

10 with open(cmip_energies_byat_out, 'r') as energies_file: 

11 atom_list = [] 

12 energy_dict: dict[str, list] = {"ES": [], "VDW": [], "ES&VDW": []} 

13 for line in energies_file: 

14 atom_list.append(line[6:12].strip()) 

15 vdw = float(line[42:53]) if float(line[42:53]) < cutoff else 0.0 

16 es = float(line[57:68]) if float(line[57:68]) < cutoff else 0.0 

17 both = float(line[72:83]) if float(line[72:83]) < cutoff else 0.0 

18 

19 energy_dict["ES"].append(es) 

20 energy_dict["VDW"].append(vdw) 

21 energy_dict["ES&VDW"].append(both) 

22 

23 return atom_list, energy_dict 

24 

25 

26def get_energies_byres(cmip_energies_byat_out: Union[str, Path], cutoff: float = 100.0) -> tuple[list[str], dict[str, list[float]]]: 

27 residues: list = [] 

28 energy_dict: dict[str, list] = {"ES": [], "VDW": [], "ES&VDW": []} 

29 with open(cmip_energies_byat_out, 'r') as energies_file: 

30 for line in energies_file: 

31 chain = line[21:22].strip() 

32 residue_id = line[22:28].strip() 

33# residue_id = str(int(residue_id) + 697) 

34# if (int(residue_id) > 746): 

35# residue_id = str(int(residue_id) + 9) 

36# if (int(residue_id) > 749): 

37# residue_id = str(int(residue_id) + 4) 

38# if (int(residue_id) > 867): 

39# residue_id = str(int(residue_id) + 8) 

40# if (int(residue_id) > 987): 

41# residue_id = str(int(residue_id) + 7) 

42# if (int(residue_id) > 1004): 

43# residue_id = str(int(residue_id) + 5) 

44 resname = inverse_aa_codes.get(line[17:21].strip().upper(), "X") 

45 residue = resname+' '+chain+residue_id 

46 vdw = float(line[42:53]) if float(line[42:53]) < cutoff else 0.0 

47 es = float(line[57:68]) if float(line[57:68]) < cutoff else 0.0 

48 both = float(line[72:83]) if float(line[72:83]) < cutoff else 0.0 

49 

50 if residue in residues: 

51 index = residues.index(residue) 

52 energy_dict["ES"][index] += es 

53 energy_dict["VDW"][index] += vdw 

54 energy_dict["ES&VDW"][index] += both 

55 else: 

56 residues.append(residue) 

57 # residues.append(int(residue_id)+696) 

58 energy_dict["ES"].append(es) 

59 energy_dict["VDW"].append(vdw) 

60 energy_dict["ES&VDW"].append(both) 

61 

62 return residues, energy_dict 

63 

64 

65def create_box_representation(cmip_log_path: Union[str, Path], cmip_pdb_path: Union[str, Path]) -> tuple[str, list[list[str]]]: 

66 return _create_box_representation_file(cmip_log_path, cmip_pdb_path), _get_atom_pair() 

67 

68 

69def _create_box_representation_file(cmip_log_path: Union[str, Path], cmip_pdb_path: Union[str, Path]) -> str: 

70 vertex_list = _get_vertex_list(cmip_log_path) 

71 

72 cmip_pdb_path = Path(cmip_pdb_path).resolve() 

73 boxed_pdb_path = cmip_pdb_path.parent.joinpath("boxed_"+str(cmip_pdb_path.name)) 

74 with open(cmip_pdb_path) as cmip_pdb_file: 

75 pdb_lines = cmip_pdb_file.readlines() 

76 if pdb_lines[-1].strip().upper() == "END": 

77 pdb_lines = pdb_lines[:-1] 

78 with open(boxed_pdb_path, 'w') as boxed_pdb_file: 

79 for pdb_line in pdb_lines: 

80 boxed_pdb_file.write(pdb_line) 

81 for i, v in enumerate(vertex_list): 

82 boxed_pdb_file.write('HETATM10000 ZN' + str(i) + ' ZN Z9999 ' + v + ' 1.00 50.00 ZN\n') 

83 boxed_pdb_file.write("END") 

84 return str(boxed_pdb_path) 

85 

86 

87def _get_vertex_list(cmip_log_path: Union[str, Path]) -> list[str]: 

88 origin, size, _ = get_grid(cmip_log_path) 

89 return [ 

90 _pdb_coord_formatter(origin[0]) + _pdb_coord_formatter(origin[1]) + _pdb_coord_formatter(origin[2]), 

91 _pdb_coord_formatter(origin[0] + size[0]) + _pdb_coord_formatter(origin[1]) + _pdb_coord_formatter(origin[2]), 

92 _pdb_coord_formatter(origin[0]) + _pdb_coord_formatter(origin[1] + size[1]) + _pdb_coord_formatter(origin[2]), 

93 _pdb_coord_formatter(origin[0]) + _pdb_coord_formatter(origin[1]) + _pdb_coord_formatter(origin[2] + size[2]), 

94 _pdb_coord_formatter(origin[0] + size[0]) + _pdb_coord_formatter(origin[1] + size[1]) + _pdb_coord_formatter(origin[2]), 

95 _pdb_coord_formatter(origin[0] + size[0]) + _pdb_coord_formatter(origin[1]) + _pdb_coord_formatter(origin[2] + size[2]), 

96 _pdb_coord_formatter(origin[0]) + _pdb_coord_formatter(origin[1] + size[1]) + _pdb_coord_formatter(origin[2] + size[2]), 

97 _pdb_coord_formatter(origin[0] + size[0]) + _pdb_coord_formatter(origin[1] + size[1]) + _pdb_coord_formatter(origin[2] + size[2]), 

98 ] 

99 

100 

101def _pdb_coord_formatter(coordinate: float) -> str: 

102 return str(round(coordinate, 3)).rjust(8) 

103 

104 

105def _get_atom_pair() -> list[list[str]]: 

106 return [["9999:Z.ZN0", "9999:Z.ZN1"], 

107 ["9999:Z.ZN0", "9999:Z.ZN2"], 

108 ["9999:Z.ZN0", "9999:Z.ZN3"], 

109 ["9999:Z.ZN1", "9999:Z.ZN4"], 

110 ["9999:Z.ZN1", "9999:Z.ZN5"], 

111 

112 ["9999:Z.ZN2", "9999:Z.ZN4"], 

113 ["9999:Z.ZN2", "9999:Z.ZN6"], 

114 

115 ["9999:Z.ZN3", "9999:Z.ZN5"], 

116 ["9999:Z.ZN3", "9999:Z.ZN6"], 

117 

118 ["9999:Z.ZN4", "9999:Z.ZN7"], 

119 ["9999:Z.ZN5", "9999:Z.ZN7"], 

120 ["9999:Z.ZN6", "9999:Z.ZN7"]] 

121 

122# AUTOMATIC OUTER GRID / titleGrid0=Automatic Outer Grid 

123# 

124# INT: 

125# spacing= 1.50000000 , 1.50000000 , 1.50000000 

126# Grid units: 1.500 1.500 1.500 

127# CEN: 

128# center= 71.6100006 , 67.7550049 , 56.3150024 

129# Grid center: 71.610 67.755 56.315 

130# DIM: 

131# dim= 64 , 92 , 72 

132# Grid density: 64 92 72 

133# 

134# To create graphic representations: 

135# Size: 

136# Grid Size: 96.000 138.000 108.000 90.000 90.000 90.000 

137# size= 96.0000000 , 138.000000 , 108.000000 

138# 

139# Origin: 

140# Grid origin: 23.610 -1.245 2.315 

141# origin= 23.6100006 , -1.24499512 , 2.31500244