@@ -953,7 +953,7 @@ def write_pdb(self,n:int=0,A:float=None,PCamp:list=None,from_traj:bool=True,sele
953
953
it exists or in the same folder as the original topology.
954
954
PCamp : list-like, optional
955
955
List of amplitudes for the first len(PCamp) principal components.
956
- If this is provided, then 'n' and 'std ' are ignored.
956
+ If this is provided, then 'n' and 'A ' are ignored.
957
957
The default is None.
958
958
from_traj : bool, optional
959
959
Extracts a frame from the trajectory that is closest given PCamps
@@ -973,11 +973,14 @@ def write_pdb(self,n:int=0,A:float=None,PCamp:list=None,from_traj:bool=True,sele
973
973
folder = self .project .directory if self .project is not None and self .project .directory is not None \
974
974
else os .path .split (self .pca .select .molsys .topo )[0 ]
975
975
filename = os .path .join (folder ,'pca.pdb' )
976
- atoms = self .pca .uni .atoms .select_atoms (select_str ) if from_traj else self .atoms
976
+ atoms = self .pca .uni .atoms .select_atoms (select_str ) if ( from_traj and PCamp is not None ) else self . pca .atoms
977
977
if PCamp is not None :
978
978
if from_traj :
979
979
i = self .PC2index (PCamp )
980
980
self .pca .traj [i ]
981
+ if hasattr (self .pca .traj ,'traj_index' ):
982
+ q = self .pca .traj .traj_index
983
+ print (f'Extracting frame { self .pca .traj .trajs [q ].frame } from trajectory { q } ' )
981
984
atoms .positions = self .pca .align (self .pca .ref_pos ,
982
985
self .pca .uni .select_atoms (self .pca .align_ref ),
983
986
atoms )
@@ -992,7 +995,7 @@ def write_pdb(self,n:int=0,A:float=None,PCamp:list=None,from_traj:bool=True,sele
992
995
self .pca .traj [frame0 ]
993
996
return filename
994
997
995
- def chimera (self ,n :int = 0 ,std :float = 1 ,PCamp :list = None ,from_traj :bool = True ,select_str :str = 'protein' ):
998
+ def chimera (self ,n :int = 0 ,std :float = 1 ,PCamp :list = None ,from_traj :bool = True ,select_str :str = 'protein' , cmap_ch = 'tab10' ):
996
999
"""
997
1000
Plots the change in a structure for a given principal component. That is,
998
1001
if n=0, then we plot the mean structure with +/-sigma for the n=0
@@ -1028,12 +1031,13 @@ def chimera(self,n:int=0,std:float=1,PCamp:list=None,from_traj:bool=True,select_
1028
1031
self
1029
1032
1030
1033
"""
1034
+ if isinstance (cmap_ch ,str ):cmap_ch = plt .get_cmap (cmap_ch )
1031
1035
if PCamp is not None :
1032
1036
filename = self .write_pdb (n = n ,PCamp = PCamp ,from_traj = from_traj ,select_str = select_str )
1033
1037
if self .project .chimera .current is None :self .project .chimera .current = 0
1034
1038
self .project .chimera .command_line ('open "{0}"' .format (filename ))
1035
1039
mdls = self .project .chimera .CMX .how_many_models (self .project .chimera .CMXid )
1036
- clr = [int (c * 100 ) for c in plt . get_cmap ( 'tab10' ) (mdls - 1 )[:- 1 ]]
1040
+ clr = [int (c * 100 ) for c in cmap_ch (mdls - 1 )[:- 1 ]]
1037
1041
if from_traj :
1038
1042
self .project .chimera .command_line (['ribbon #{0}' ,'~show #{0}' ,'color #{0} {1},{2},{3}' .format (mdls ,clr [0 ],clr [1 ],clr [2 ])])
1039
1043
else :
@@ -1055,13 +1059,13 @@ def chimera(self,n:int=0,std:float=1,PCamp:list=None,from_traj:bool=True,select_
1055
1059
if self .project .chimera .current is None :self .project .chimera .current = 0
1056
1060
self .project .chimera .command_line ('open "{0}"' .format (filename ))
1057
1061
mdls = self .project .chimera .CMX .how_many_models (self .project .chimera .CMXid )
1058
- clr = [int (c * 100 ) for c in plt . get_cmap ( 'tab10' ) (mdls - 1 )[:- 1 ]]
1062
+ clr = [int (c * 100 ) for c in cmap_ch (mdls - 1 )[:- 1 ]]
1059
1063
self .project .chimera .command_line (['~ribbon' ,'show' ,'color #{0} {1},{2},{3}' .format (mdls ,clr [0 ],clr [1 ],clr [2 ])])
1060
1064
self .project .chimera .command_line (self .project .chimera .saved_commands )
1061
1065
1062
1066
return self
1063
1067
1064
- def hist2struct (self ,nmax :int = 4 ,from_traj :bool = True ,select_str :str = 'protein' ,ref_struct :bool = False ,ax = None ,** kwargs ):
1068
+ def hist2struct (self ,nmax :int = 4 ,from_traj :bool = True ,select_str :str = 'protein' ,ref_struct :bool = False ,ax = None ,cmap_ch = 'tab10' , n_colors = 10 , ** kwargs ):
1065
1069
"""
1066
1070
Interactively view structures corresponding to positions on the
1067
1071
histogram plots. Specify the maximum principle component to display. Then,
@@ -1091,6 +1095,10 @@ def hist2struct(self,nmax:int=4,from_traj:bool=True,select_str:str='protein',ref
1091
1095
None.
1092
1096
1093
1097
"""
1098
+
1099
+
1100
+ if isinstance ('cmap_ch' ,str ):cmap_ch = plt .get_cmap (cmap_ch ).resampled (n_colors )
1101
+
1094
1102
x ,y = int (np .ceil (np .sqrt (nmax ))),int (np .ceil (np .sqrt (nmax )))
1095
1103
if (x - 1 )* y >= nmax :x -= 1
1096
1104
@@ -1109,12 +1117,13 @@ def hist2struct(self,nmax:int=4,from_traj:bool=True,select_str:str='protein',ref
1109
1117
if ref_struct :
1110
1118
self .chimera (PCamp = [0 ])
1111
1119
mdls = self .project .chimera .CMX .how_many_models (self .project .chimera .CMXid )
1112
- clr = plt . get_cmap ( 'tab10' ) (mdls - 1 )
1120
+ clr = cmap_ch ( (mdls - 1 ) % n_colors )
1113
1121
for k ,a in enumerate (ax ):
1114
1122
a .scatter (0 ,0 ,marker = 'x' ,color = clr )
1115
1123
1116
1124
PCamp = [None for _ in range (nmax + 1 )]
1117
1125
markers = ['x' ,'o' ,'+' ,'v' ,'>' ,'s' ,'1' ,'*' ]
1126
+ mkr_hdls = []
1118
1127
def onclick (event ):
1119
1128
if event .inaxes :
1120
1129
ax0 = event .inaxes
@@ -1145,12 +1154,15 @@ def onclick(event):
1145
1154
PCamp0 = self .pca .PCamp [:len (PCamp )][:,i ] #Set PCamp to the nearest value in trajectory
1146
1155
else :
1147
1156
PCamp0 = PCamp
1148
- self .chimera (PCamp = PCamp0 ,from_traj = from_traj )
1157
+ self .chimera (PCamp = PCamp0 ,from_traj = from_traj , cmap_ch = cmap_ch )
1149
1158
for k ,a in enumerate (ax ):
1150
1159
mdls = self .project .chimera .CMX .how_many_models (self .project .chimera .CMXid )
1151
- clr = plt . get_cmap ( 'tab10' )(( mdls - 1 )% 10 )
1160
+ clr = cmap_ch (( mdls - 1 )% n_colors )
1152
1161
1153
- a .scatter (PCamp0 [k ],PCamp0 [k + 1 ],100 ,marker = markers [(mdls - 1 )% len (markers )],linewidth = 3 ,color = clr )
1162
+ if mdls == 0 :
1163
+ while mkr_hdls :mkr_hdls .pop ().remove ()
1164
+
1165
+ mkr_hdls .append (a .scatter (PCamp0 [k ],PCamp0 [k + 1 ],100 ,marker = markers [(mdls - 1 )% len (markers )],linewidth = 3 ,color = clr ))
1154
1166
1155
1167
#Clear the positions in the plot
1156
1168
for k in range (len (PCamp )):PCamp [k ]= None
@@ -1159,6 +1171,10 @@ def onclick(event):
1159
1171
h0 .set_visible (False )
1160
1172
plt .pause (0.01 )
1161
1173
else : #Clicking outside the axes clears out the positions
1174
+
1175
+ if self .project .chimera .CMX .how_many_models (self .project .chimera .CMXid )== 0 :
1176
+ while mkr_hdls :mkr_hdls .pop ().remove ()
1177
+
1162
1178
for k in range (len (PCamp )):PCamp [k ]= None
1163
1179
for h in hdls :
1164
1180
for h0 in h :
@@ -1308,6 +1324,19 @@ def plot(self,ax=None,skip:int=10,maxbin:float=None,nbins:int=None,cmap='binary'
1308
1324
1309
1325
return ax
1310
1326
1327
+ def plot_t_depend (self ,ax = None ):
1328
+ if ax is None :ax = plt .subplots ()[1 ]
1329
+ ax .scatter (self .pca .t ,self .state ,3 ,marker = 'o' ,color = 'black' )
1330
+ ax .set_ylim ([- .5 ,self .n_clusters - .5 ])
1331
+ if len (self .pca .traj .lengths )> 1 :
1332
+ lengths = self .pca .traj .lengths
1333
+ for k in range (len (lengths )- 1 ):
1334
+ ax .plot (np .sum (lengths [:k + 1 ])* np .ones (2 ),ax .get_ylim (),color = 'grey' ,linestyle = ':' )
1335
+
1336
+ return ax
1337
+
1338
+
1339
+
1311
1340
@property
1312
1341
def PCavg (self ):
1313
1342
"""
0 commit comments