Skip to content

Commit a28001e

Browse files
committed
Updates
1 parent d8c9139 commit a28001e

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

Data/Plotting.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ def append_data(self,data,style='plot',errorbars=True,index=None,rho_index=None,
8484
data.select.sel1=data.select.sel1[index]
8585
if data.select.sel2 is not None:
8686
data.select.sel2=data.select.sel2[index]
87-
# index=None
87+
# I just uncommented the line below (26.09.2024)
88+
# The reduced data from above no longer requires an index, so we set index to None
89+
index=None
8890

8991
self.data.append(data)
9092
self.rho_index.append(self.calc_rho_index() if rho_index is None else np.array(rho_index,dtype=int))
@@ -239,6 +241,8 @@ def plot_data(self,i=-1,errorbars=True,split=True,**kwargs):
239241
def comparex(self,i=-1):
240242
d0,di=self.data[0],self.data[i]
241243

244+
if len(d0)==len(di):return np.arange(len(d0)),np.arange(len(d0))
245+
242246
if d0.select is not None and di.select is not None and len(d0.select) and len(di.select):
243247
out=d0.select.compare(di.select)
244248
if len(out[0]):
@@ -260,9 +264,12 @@ def xindex(self,i=-1):
260264
"""
261265
i%=len(self)
262266
if i<len(self.index):return self.index[i] #Index already calculated
263-
if i==0:
267+
if i==0: #First data entry (plot everything)
264268
return np.arange(self.data[0].R.shape[0])
265269

270+
if len(self.data[i])==len(self.index[0]): #Matching lengths (plot everything)
271+
return np.arange(len(self.data[i]))
272+
266273
mode=self.mode
267274

268275
in1=self.comparex(i=i)[1]

Entropy/Entropy.py

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def reset(self):
9090
self._Scc=None
9191
self._CC=None
9292
self._CCpca=None
93+
self._Chi=None
9394

9495
return self
9596

@@ -342,6 +343,19 @@ def chi(self):
342343
self._chi=out
343344
return self._chi
344345

346+
@property
347+
def Chi(self):
348+
"""
349+
Index-able Chi
350+
351+
Returns
352+
-------
353+
np.array
354+
355+
"""
356+
if self._Chi is None:self._Chi=Chi(self)
357+
return self._Chi
358+
345359
@property
346360
def v_avg(self):
347361
"""
@@ -728,6 +742,7 @@ def plotCCpca(self,index=None,states:list=None,ax=None,**kwargs):
728742

729743
#%% Plotting
730744

745+
731746
def plotCC(self,index=None,ax=None,CCsum:bool=True,**kwargs):
732747
"""
733748
Make a CC plot for all residue pairs
@@ -748,10 +763,24 @@ def plotCC(self,index=None,ax=None,CCsum:bool=True,**kwargs):
748763
749764
"""
750765

766+
767+
768+
769+
751770
if index is None:index=np.ones(self.N,dtype=bool)
752771
if ax is None:
753772
ax=plt.subplots()[1]
754773

774+
index=np.array(index)
775+
if index.size==1 and np.issubdtype(index.dtype,np.integer):
776+
ax.plot(self.CC[index],**kwargs)
777+
ax.xaxis.set_major_locator(plt.MaxNLocator(30,integer=True))
778+
ax.xaxis.set_major_formatter(self._axis_formatter(np.arange(len(self.resids))))
779+
780+
ax.tick_params(axis='x', labelrotation=90)
781+
ax.set_ylabel('C.C')
782+
return ax
783+
755784

756785
if 'cmap' not in kwargs:
757786
kwargs['cmap']='binary'
@@ -852,7 +881,7 @@ def format_func(value,tick_number):
852881
return plt.FuncFormatter(format_func)
853882

854883

855-
def plotChi(self,index:int,ax:list=None,step:int=1):
884+
def plotChi(self,index:int,ax:list=None,step:int=1,cmap='tab10'):
856885
"""
857886
Creates one or more Ramachandran histogram plots, depending on the number
858887
of chi angles, i.e. 1D histogram for Valine, 1 Ramachandran plot for
@@ -868,6 +897,8 @@ def plotChi(self,index:int,ax:list=None,step:int=1):
868897
fig
869898
870899
"""
900+
chi=self.Chi[index]
901+
871902
index=np.array(index)
872903
if index.dtype==bool:index=np.argmax(index)
873904

@@ -878,10 +909,12 @@ def plotChi(self,index:int,ax:list=None,step:int=1):
878909
ax=np.atleast_1d(ax).flatten()
879910
assert len(ax)==nplots,f"Residue {self.resid[index].resname}{self.resid[index].resid} has {N} chi angles, and therefore requires {nplots} plots"
880911

881-
chi=[self.chi[k][self.index[k+3,:index].sum()][::step] for k in range(N-1,-1,-1)]
912+
# chi=[self.chi[k][self.index[k+3,:index].sum()][::step] for k in range(N-1,-1,-1)]
913+
914+
882915

883916
nstates=self.total_mult[index]
884-
cmap=plt.get_cmap('turbo').resampled(nstates)
917+
if isinstance(cmap,str):cmap=plt.get_cmap(cmap)
885918

886919
for a,k in zip(ax,range(N-1)):
887920
for m in range(nstates):
@@ -1083,9 +1116,19 @@ def save(self,filename:str,overwrite:bool=False):
10831116
with open(filename,'wb') as f:
10841117
write_EntropyCC(f,self)
10851118

1119+
1120+
class Chi():
1121+
def __init__(self,ECC):
1122+
self.ECC=ECC
10861123

1087-
1088-
1124+
def __getitem__(self,index):
1125+
ECC=self.ECC
1126+
index=np.array(index)
1127+
if index.dtype==bool:index=np.argmax(index)
1128+
1129+
N=ECC.index[3:,index].sum()
1130+
1131+
return np.array([ECC.chi[k][ECC.index[k+3,:index].sum()] for k in range(N-1,-1,-1)])
10891132

10901133

10911134
# Tools for selecting the correct atoms to get rotamers

PCA/CombinedPCA.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33

44
from . import PCA
5-
from ..Selection.MolSys import Trajectory
65
import numpy as np
76
import matplotlib.pyplot as plt
87
from matplotlib.colors import ListedColormap
@@ -24,7 +23,6 @@ def __init__(self,*pcas):
2423

2524
self.traj[0]
2625

27-
2826
@property
2927
def traj(self):
3028
return self._traj
@@ -54,12 +52,14 @@ def hist_by_traj(self,nmax:int=3,cmap='Reds',cmap0='jet',**kwargs):
5452
colors[:,-1]=np.linspace(0,1,257)[1:]**.25
5553
cm=ListedColormap(colors)
5654

55+
maxbin=np.abs(self.PCamp[:nmax+1]).max()
56+
5757
for q,ax0 in enumerate(ax.T):
5858
for ax00,n0,n1 in zip(ax0,range(nmax),range(1,nmax+1)):
59-
self.Hist.plot(n0,n1,ax=ax00,cmap=cmap0,**kwargs)
59+
self.Hist.plot(n0,n1,ax=ax00,cmap=cmap0,maxbin=maxbin,**kwargs)
6060
index=np.zeros(len(self.traj),dtype=bool)
6161
index[self.ranges[q][0]:self.ranges[q][1]]=True
62-
self.Hist.plot(n0,n1,ax=ax00,cmap=cm,index=index)
62+
self.Hist.plot(n0,n1,ax=ax00,cmap=cm,maxbin=maxbin,index=index)
6363

6464
fig.tight_layout()
6565

0 commit comments

Comments
 (0)