src.serena.utilities.ensemble_groups
File for the classes associated with the ensemble groups
1""" 2File for the classes associated with the ensemble groups 3""" 4from typing import List, Dict 5import attrs 6 7from serena.utilities.ensemble_structures import (Sara2SecondaryStructure, 8 Sara2StructureList, 9 KcalRanges) 10 11@attrs.define 12class EnsembleSwitchStateMFEStructs(): 13 """ 14 Class that holds the secondary structures for representing 15 the mfe and folded structures uses for LMV 16 """ 17 non_switch_mfe_struct:Sara2SecondaryStructure= Sara2SecondaryStructure() 18 switched_mfe_struct:Sara2SecondaryStructure = Sara2SecondaryStructure() 19 20 def set_non_switch_mfe(self, kcal:float, struct:str): 21 """ 22 Sets the unbound mfe secondary structure 23 """ 24 self.non_switch_mfe_struct = Sara2SecondaryStructure(structure=struct, 25 free_energy=kcal) 26 27 def set_switch_mfe(self, kcal:float, struct:str): 28 """ 29 Sets the folded mfe secondary structure. 30 """ 31 self.switched_mfe_struct = Sara2SecondaryStructure(structure=struct, 32 free_energy=kcal) 33 34#need to turn into a dataclass or attrs.define 35class SingleEnsembleGroup():#pylint: disable=too-many-instance-attributes 36 """ 37 Datatype that represents and hold the info for a single 38 energy span group in the ensemble 39 """ 40 def __init__(self) -> None: 41 self._group: Sara2StructureList = Sara2StructureList() 42 self._switch_state_structures: EnsembleSwitchStateMFEStructs = None 43 self._multi_state_mfe_struct: List[str] = [] 44 """ 45 0 is mfe for unbound and 1 is mfe for bound 46 """ 47 self._multi_state_mfe_kcal: List[float] = [] 48 self._kcal_start: float = 0 49 self._kcal_end: float = 0 50 self._kcal_span: float = 0 51 52 @property 53 def group(self)->Sara2StructureList: 54 """ 55 Return the ensemble group as a sara2structurelist 56 """ 57 return self._group 58 59 @group.setter 60 def group(self, the_group:Sara2StructureList): 61 """ 62 Set the ensemble group using a Sara2SecondaryStructure 63 """ 64 self._group = the_group 65 66 @property 67 def multi_state_mfe_struct(self)->List[str]: 68 """ 69 Return the multi state mfe struct that holds 70 the unbound and bound structs 71 """ 72 return self._multi_state_mfe_struct 73 74 @multi_state_mfe_struct.setter 75 def multi_state_mfe_struct(self, structs:List[str]): 76 """ 77 Sets teh multi state struct 78 """ 79 self._multi_state_mfe_struct = structs 80 81 def append_multi_state_mfe_data(self, structure: str, kcal: float): 82 """ 83 Appends structures to the multo state mfe data 84 """ 85 self._multi_state_mfe_struct.append(structure) 86 self._multi_state_mfe_kcal.append(kcal) 87 88 @property 89 def multi_state_mfe_kcal(self)->List[float]: 90 """ 91 Return the multi state mfe kcal list 92 """ 93 return self._multi_state_mfe_kcal 94 95 @multi_state_mfe_kcal.setter 96 def multi_state_mfe_kcal(self, kcals:List[float]): 97 """ 98 Set the multi state mfe kcal list 99 """ 100 self._multi_state_mfe_kcal = kcals 101 102 @property 103 def kcal_span(self)->float: 104 """ 105 Return the kcal span of the group 106 """ 107 return self._kcal_span 108 109 @kcal_span.setter 110 def kcal_span(self, kcal:float): 111 """ 112 Set the kcal span of the group 113 """ 114 self._kcal_span = kcal 115 116 @property 117 def kcal_start(self)->float: 118 """ 119 Return the kcal start of the group 120 """ 121 return self._kcal_start 122 123 @kcal_start.setter 124 def kcal_start(self, kcal:float): 125 """ 126 Set the kcal start of the group 127 """ 128 self._kcal_start = kcal 129 130 @property 131 def kcal_end(self)->float: 132 """ 133 Return the kcal end of the group 134 """ 135 return self._kcal_end 136 137 @kcal_end.setter 138 def kcal_end(self, kcal:float): 139 """ 140 Set the kcal end of the group 141 """ 142 self._kcal_end = kcal 143 144 def update_kcals(self, start:float, stop:float, span:float): 145 "Update all the kcal properties at once" 146 self._kcal_start = start 147 self._kcal_end = stop 148 self._kcal_span = span 149 150 @property 151 def switch_state_structures(self)->EnsembleSwitchStateMFEStructs: 152 """ 153 Return the switch state structures that hold the 154 unbound and bound mfe structures 155 """ 156 return self._switch_state_structures 157 158 @switch_state_structures.setter 159 def switch_state_structures(self, structs:EnsembleSwitchStateMFEStructs): 160 """ 161 Set the switch state structures that hold the 162 unbound and bound mfe structures 163 """ 164 self._switch_state_structures = structs 165 166class MultipleEnsembleGroups(): 167 """" 168 Multiple Ensemble Groups class 169 """ 170 def __init__(self, switch_state_structures: EnsembleSwitchStateMFEStructs) -> None: 171 self._groups: List[SingleEnsembleGroup] = [] 172 self._raw_groups: List[Sara2StructureList] = [] 173 self._switch_state_structures: EnsembleSwitchStateMFEStructs = switch_state_structures 174 self._groups_dict: Dict[int, Sara2StructureList] = {} 175 self._group_values: List[float] = [] 176 self._num_groups: int = 0 177 self._group_kcal_ranges: List[KcalRanges] = [] 178 179 @property 180 def switch_state_structures(self)->EnsembleSwitchStateMFEStructs: 181 """ 182 Return the switch state structures for holdng the unbound and 183 bound mfe structs for analysis 184 """ 185 return self._switch_state_structures 186 187 @property 188 def num_groups(self)->int: 189 """ 190 Return the number of energy groups in the ensemble 191 """ 192 return self._num_groups 193 194 def add_group(self, group:SingleEnsembleGroup): 195 """ 196 Prefered way to add a ensemble group to the multi group class 197 """ 198 self._groups.append(group) 199 self._raw_groups.append(group.group) 200 self._groups_dict[self._num_groups]= group.group 201 self._group_values.append(group.kcal_start) 202 kcal_range: KcalRanges = KcalRanges(start=group.kcal_start, stop=group.kcal_end) 203 self._group_kcal_ranges.append(kcal_range) 204 self._num_groups = self._num_groups + 1 205 206 @property 207 def groups(self)->List[SingleEnsembleGroup]: 208 """ 209 Return the ensemble groupds as a list of 210 SingleEnsembleGroups 211 """ 212 return self._groups 213 214 @property 215 def raw_groups(self)->List[Sara2StructureList]: 216 """ 217 Return the raw ensembled groups as a list of 218 Sara2StructureLists 219 """ 220 return self._raw_groups 221 222 @property 223 def non_switch_state_structure(self)->Sara2SecondaryStructure: 224 """ 225 Return the unbound mfe secondary structure 226 """ 227 return self._switch_state_structures.non_switch_mfe_struct 228 229 @property 230 def switched_state_structure(self)->Sara2SecondaryStructure: 231 """ 232 Return the folded mfe secondary structure 233 """ 234 return self._switch_state_structures.switched_mfe_struct 235 236 @property 237 def groups_dict(self)->Dict[int, Sara2StructureList]: 238 """ 239 Return the groups dict for values and structures 240 """ 241 return self._groups_dict 242 243 @property 244 def group_values(self)->List[float]: 245 """ 246 Return the group values as a list of floats 247 """ 248 return self._group_values 249 250 @property 251 def group_kcal_ranges(self)->List[KcalRanges]: 252 """ 253 Return the list of kcal ranges 254 """ 255 return self._group_kcal_ranges 256 257 @property 258 def total_structures(self)->int: 259 """ 260 Return the total number of structures 261 """ 262 total:int = 0 263 for group in self.raw_groups: 264 total += group.num_structures 265 return total 266 267class MakeEnsembleGroups(): 268 """ 269 Class for generating the ensemble groups consumed by serena and sara 270 """ 271 272 def make_switch_mfe_states_from_secondary_strucures(self, switched_mfe_struc:Sara2SecondaryStructure, non_switch_mfe_struct:Sara2SecondaryStructure):#pylint: disable=line-too-long 273 """ 274 Make switch states 275 """ 276 return EnsembleSwitchStateMFEStructs(non_switch_mfe_struct=non_switch_mfe_struct, 277 switched_mfe_struct=switched_mfe_struc) 278 279 def make_singel_ensemble_group(self, ensemble_structures:Sara2StructureList, mfe_switch_structures:EnsembleSwitchStateMFEStructs, kcal_start:float, kcal_end:float):#pylint: disable=line-too-long 280 """ 281 Function to make a single ensemble group from a sara2structure list 282 """ 283 single_ensemble_group:SingleEnsembleGroup = SingleEnsembleGroup() 284 single_ensemble_group.group = ensemble_structures 285 single_ensemble_group.switch_state_structures = mfe_switch_structures 286 single_ensemble_group.kcal_start = kcal_start 287 single_ensemble_group.kcal_end = kcal_end 288 single_ensemble_group.kcal_span = kcal_end - kcal_start 289 return single_ensemble_group 290 291 def make_multiple_ensemple_groups(self, ensemble_groups:List[SingleEnsembleGroup], mfe_switch_structures:EnsembleSwitchStateMFEStructs):#pylint: disable=line-too-long 292 """ 293 Function to make a multi ensemble group from a list of single ensemble goups 294 """ 295 multi_group:MultipleEnsembleGroups = MultipleEnsembleGroups(switch_state_structures=mfe_switch_structures)#pylint: disable=line-too-long 296 for group in ensemble_groups: 297 multi_group.add_group(group=group) 298 return multi_group
12@attrs.define 13class EnsembleSwitchStateMFEStructs(): 14 """ 15 Class that holds the secondary structures for representing 16 the mfe and folded structures uses for LMV 17 """ 18 non_switch_mfe_struct:Sara2SecondaryStructure= Sara2SecondaryStructure() 19 switched_mfe_struct:Sara2SecondaryStructure = Sara2SecondaryStructure() 20 21 def set_non_switch_mfe(self, kcal:float, struct:str): 22 """ 23 Sets the unbound mfe secondary structure 24 """ 25 self.non_switch_mfe_struct = Sara2SecondaryStructure(structure=struct, 26 free_energy=kcal) 27 28 def set_switch_mfe(self, kcal:float, struct:str): 29 """ 30 Sets the folded mfe secondary structure. 31 """ 32 self.switched_mfe_struct = Sara2SecondaryStructure(structure=struct, 33 free_energy=kcal)
Class that holds the secondary structures for representing the mfe and folded structures uses for LMV
2def __init__(self, non_switch_mfe_struct=attr_dict['non_switch_mfe_struct'].default, switched_mfe_struct=attr_dict['switched_mfe_struct'].default): 3 self.non_switch_mfe_struct = non_switch_mfe_struct 4 self.switched_mfe_struct = switched_mfe_struct
Method generated by attrs for class EnsembleSwitchStateMFEStructs.
21 def set_non_switch_mfe(self, kcal:float, struct:str): 22 """ 23 Sets the unbound mfe secondary structure 24 """ 25 self.non_switch_mfe_struct = Sara2SecondaryStructure(structure=struct, 26 free_energy=kcal)
Sets the unbound mfe secondary structure
36class SingleEnsembleGroup():#pylint: disable=too-many-instance-attributes 37 """ 38 Datatype that represents and hold the info for a single 39 energy span group in the ensemble 40 """ 41 def __init__(self) -> None: 42 self._group: Sara2StructureList = Sara2StructureList() 43 self._switch_state_structures: EnsembleSwitchStateMFEStructs = None 44 self._multi_state_mfe_struct: List[str] = [] 45 """ 46 0 is mfe for unbound and 1 is mfe for bound 47 """ 48 self._multi_state_mfe_kcal: List[float] = [] 49 self._kcal_start: float = 0 50 self._kcal_end: float = 0 51 self._kcal_span: float = 0 52 53 @property 54 def group(self)->Sara2StructureList: 55 """ 56 Return the ensemble group as a sara2structurelist 57 """ 58 return self._group 59 60 @group.setter 61 def group(self, the_group:Sara2StructureList): 62 """ 63 Set the ensemble group using a Sara2SecondaryStructure 64 """ 65 self._group = the_group 66 67 @property 68 def multi_state_mfe_struct(self)->List[str]: 69 """ 70 Return the multi state mfe struct that holds 71 the unbound and bound structs 72 """ 73 return self._multi_state_mfe_struct 74 75 @multi_state_mfe_struct.setter 76 def multi_state_mfe_struct(self, structs:List[str]): 77 """ 78 Sets teh multi state struct 79 """ 80 self._multi_state_mfe_struct = structs 81 82 def append_multi_state_mfe_data(self, structure: str, kcal: float): 83 """ 84 Appends structures to the multo state mfe data 85 """ 86 self._multi_state_mfe_struct.append(structure) 87 self._multi_state_mfe_kcal.append(kcal) 88 89 @property 90 def multi_state_mfe_kcal(self)->List[float]: 91 """ 92 Return the multi state mfe kcal list 93 """ 94 return self._multi_state_mfe_kcal 95 96 @multi_state_mfe_kcal.setter 97 def multi_state_mfe_kcal(self, kcals:List[float]): 98 """ 99 Set the multi state mfe kcal list 100 """ 101 self._multi_state_mfe_kcal = kcals 102 103 @property 104 def kcal_span(self)->float: 105 """ 106 Return the kcal span of the group 107 """ 108 return self._kcal_span 109 110 @kcal_span.setter 111 def kcal_span(self, kcal:float): 112 """ 113 Set the kcal span of the group 114 """ 115 self._kcal_span = kcal 116 117 @property 118 def kcal_start(self)->float: 119 """ 120 Return the kcal start of the group 121 """ 122 return self._kcal_start 123 124 @kcal_start.setter 125 def kcal_start(self, kcal:float): 126 """ 127 Set the kcal start of the group 128 """ 129 self._kcal_start = kcal 130 131 @property 132 def kcal_end(self)->float: 133 """ 134 Return the kcal end of the group 135 """ 136 return self._kcal_end 137 138 @kcal_end.setter 139 def kcal_end(self, kcal:float): 140 """ 141 Set the kcal end of the group 142 """ 143 self._kcal_end = kcal 144 145 def update_kcals(self, start:float, stop:float, span:float): 146 "Update all the kcal properties at once" 147 self._kcal_start = start 148 self._kcal_end = stop 149 self._kcal_span = span 150 151 @property 152 def switch_state_structures(self)->EnsembleSwitchStateMFEStructs: 153 """ 154 Return the switch state structures that hold the 155 unbound and bound mfe structures 156 """ 157 return self._switch_state_structures 158 159 @switch_state_structures.setter 160 def switch_state_structures(self, structs:EnsembleSwitchStateMFEStructs): 161 """ 162 Set the switch state structures that hold the 163 unbound and bound mfe structures 164 """ 165 self._switch_state_structures = structs
Datatype that represents and hold the info for a single energy span group in the ensemble
Return the ensemble group as a sara2structurelist
Return the multi state mfe struct that holds the unbound and bound structs
82 def append_multi_state_mfe_data(self, structure: str, kcal: float): 83 """ 84 Appends structures to the multo state mfe data 85 """ 86 self._multi_state_mfe_struct.append(structure) 87 self._multi_state_mfe_kcal.append(kcal)
Appends structures to the multo state mfe data
145 def update_kcals(self, start:float, stop:float, span:float): 146 "Update all the kcal properties at once" 147 self._kcal_start = start 148 self._kcal_end = stop 149 self._kcal_span = span
Update all the kcal properties at once
Return the switch state structures that hold the unbound and bound mfe structures
167class MultipleEnsembleGroups(): 168 """" 169 Multiple Ensemble Groups class 170 """ 171 def __init__(self, switch_state_structures: EnsembleSwitchStateMFEStructs) -> None: 172 self._groups: List[SingleEnsembleGroup] = [] 173 self._raw_groups: List[Sara2StructureList] = [] 174 self._switch_state_structures: EnsembleSwitchStateMFEStructs = switch_state_structures 175 self._groups_dict: Dict[int, Sara2StructureList] = {} 176 self._group_values: List[float] = [] 177 self._num_groups: int = 0 178 self._group_kcal_ranges: List[KcalRanges] = [] 179 180 @property 181 def switch_state_structures(self)->EnsembleSwitchStateMFEStructs: 182 """ 183 Return the switch state structures for holdng the unbound and 184 bound mfe structs for analysis 185 """ 186 return self._switch_state_structures 187 188 @property 189 def num_groups(self)->int: 190 """ 191 Return the number of energy groups in the ensemble 192 """ 193 return self._num_groups 194 195 def add_group(self, group:SingleEnsembleGroup): 196 """ 197 Prefered way to add a ensemble group to the multi group class 198 """ 199 self._groups.append(group) 200 self._raw_groups.append(group.group) 201 self._groups_dict[self._num_groups]= group.group 202 self._group_values.append(group.kcal_start) 203 kcal_range: KcalRanges = KcalRanges(start=group.kcal_start, stop=group.kcal_end) 204 self._group_kcal_ranges.append(kcal_range) 205 self._num_groups = self._num_groups + 1 206 207 @property 208 def groups(self)->List[SingleEnsembleGroup]: 209 """ 210 Return the ensemble groupds as a list of 211 SingleEnsembleGroups 212 """ 213 return self._groups 214 215 @property 216 def raw_groups(self)->List[Sara2StructureList]: 217 """ 218 Return the raw ensembled groups as a list of 219 Sara2StructureLists 220 """ 221 return self._raw_groups 222 223 @property 224 def non_switch_state_structure(self)->Sara2SecondaryStructure: 225 """ 226 Return the unbound mfe secondary structure 227 """ 228 return self._switch_state_structures.non_switch_mfe_struct 229 230 @property 231 def switched_state_structure(self)->Sara2SecondaryStructure: 232 """ 233 Return the folded mfe secondary structure 234 """ 235 return self._switch_state_structures.switched_mfe_struct 236 237 @property 238 def groups_dict(self)->Dict[int, Sara2StructureList]: 239 """ 240 Return the groups dict for values and structures 241 """ 242 return self._groups_dict 243 244 @property 245 def group_values(self)->List[float]: 246 """ 247 Return the group values as a list of floats 248 """ 249 return self._group_values 250 251 @property 252 def group_kcal_ranges(self)->List[KcalRanges]: 253 """ 254 Return the list of kcal ranges 255 """ 256 return self._group_kcal_ranges 257 258 @property 259 def total_structures(self)->int: 260 """ 261 Return the total number of structures 262 """ 263 total:int = 0 264 for group in self.raw_groups: 265 total += group.num_structures 266 return total
" Multiple Ensemble Groups class
171 def __init__(self, switch_state_structures: EnsembleSwitchStateMFEStructs) -> None: 172 self._groups: List[SingleEnsembleGroup] = [] 173 self._raw_groups: List[Sara2StructureList] = [] 174 self._switch_state_structures: EnsembleSwitchStateMFEStructs = switch_state_structures 175 self._groups_dict: Dict[int, Sara2StructureList] = {} 176 self._group_values: List[float] = [] 177 self._num_groups: int = 0 178 self._group_kcal_ranges: List[KcalRanges] = []
Return the switch state structures for holdng the unbound and bound mfe structs for analysis
195 def add_group(self, group:SingleEnsembleGroup): 196 """ 197 Prefered way to add a ensemble group to the multi group class 198 """ 199 self._groups.append(group) 200 self._raw_groups.append(group.group) 201 self._groups_dict[self._num_groups]= group.group 202 self._group_values.append(group.kcal_start) 203 kcal_range: KcalRanges = KcalRanges(start=group.kcal_start, stop=group.kcal_end) 204 self._group_kcal_ranges.append(kcal_range) 205 self._num_groups = self._num_groups + 1
Prefered way to add a ensemble group to the multi group class
Return the ensemble groupds as a list of SingleEnsembleGroups
Return the raw ensembled groups as a list of Sara2StructureLists
Return the unbound mfe secondary structure
Return the folded mfe secondary structure
Return the groups dict for values and structures
268class MakeEnsembleGroups(): 269 """ 270 Class for generating the ensemble groups consumed by serena and sara 271 """ 272 273 def make_switch_mfe_states_from_secondary_strucures(self, switched_mfe_struc:Sara2SecondaryStructure, non_switch_mfe_struct:Sara2SecondaryStructure):#pylint: disable=line-too-long 274 """ 275 Make switch states 276 """ 277 return EnsembleSwitchStateMFEStructs(non_switch_mfe_struct=non_switch_mfe_struct, 278 switched_mfe_struct=switched_mfe_struc) 279 280 def make_singel_ensemble_group(self, ensemble_structures:Sara2StructureList, mfe_switch_structures:EnsembleSwitchStateMFEStructs, kcal_start:float, kcal_end:float):#pylint: disable=line-too-long 281 """ 282 Function to make a single ensemble group from a sara2structure list 283 """ 284 single_ensemble_group:SingleEnsembleGroup = SingleEnsembleGroup() 285 single_ensemble_group.group = ensemble_structures 286 single_ensemble_group.switch_state_structures = mfe_switch_structures 287 single_ensemble_group.kcal_start = kcal_start 288 single_ensemble_group.kcal_end = kcal_end 289 single_ensemble_group.kcal_span = kcal_end - kcal_start 290 return single_ensemble_group 291 292 def make_multiple_ensemple_groups(self, ensemble_groups:List[SingleEnsembleGroup], mfe_switch_structures:EnsembleSwitchStateMFEStructs):#pylint: disable=line-too-long 293 """ 294 Function to make a multi ensemble group from a list of single ensemble goups 295 """ 296 multi_group:MultipleEnsembleGroups = MultipleEnsembleGroups(switch_state_structures=mfe_switch_structures)#pylint: disable=line-too-long 297 for group in ensemble_groups: 298 multi_group.add_group(group=group) 299 return multi_group
Class for generating the ensemble groups consumed by serena and sara
273 def make_switch_mfe_states_from_secondary_strucures(self, switched_mfe_struc:Sara2SecondaryStructure, non_switch_mfe_struct:Sara2SecondaryStructure):#pylint: disable=line-too-long 274 """ 275 Make switch states 276 """ 277 return EnsembleSwitchStateMFEStructs(non_switch_mfe_struct=non_switch_mfe_struct, 278 switched_mfe_struct=switched_mfe_struc)
Make switch states
280 def make_singel_ensemble_group(self, ensemble_structures:Sara2StructureList, mfe_switch_structures:EnsembleSwitchStateMFEStructs, kcal_start:float, kcal_end:float):#pylint: disable=line-too-long 281 """ 282 Function to make a single ensemble group from a sara2structure list 283 """ 284 single_ensemble_group:SingleEnsembleGroup = SingleEnsembleGroup() 285 single_ensemble_group.group = ensemble_structures 286 single_ensemble_group.switch_state_structures = mfe_switch_structures 287 single_ensemble_group.kcal_start = kcal_start 288 single_ensemble_group.kcal_end = kcal_end 289 single_ensemble_group.kcal_span = kcal_end - kcal_start 290 return single_ensemble_group
Function to make a single ensemble group from a sara2structure list
292 def make_multiple_ensemple_groups(self, ensemble_groups:List[SingleEnsembleGroup], mfe_switch_structures:EnsembleSwitchStateMFEStructs):#pylint: disable=line-too-long 293 """ 294 Function to make a multi ensemble group from a list of single ensemble goups 295 """ 296 multi_group:MultipleEnsembleGroups = MultipleEnsembleGroups(switch_state_structures=mfe_switch_structures)#pylint: disable=line-too-long 297 for group in ensemble_groups: 298 multi_group.add_group(group=group) 299 return multi_group
Function to make a multi ensemble group from a list of single ensemble goups