Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alsinmr committed Oct 29, 2024
1 parent d8c9139 commit a28001e
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 11 deletions.
11 changes: 9 additions & 2 deletions Data/Plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def append_data(self,data,style='plot',errorbars=True,index=None,rho_index=None,
data.select.sel1=data.select.sel1[index]
if data.select.sel2 is not None:
data.select.sel2=data.select.sel2[index]
# index=None
# I just uncommented the line below (26.09.2024)
# The reduced data from above no longer requires an index, so we set index to None
index=None

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

if len(d0)==len(di):return np.arange(len(d0)),np.arange(len(d0))

if d0.select is not None and di.select is not None and len(d0.select) and len(di.select):
out=d0.select.compare(di.select)
if len(out[0]):
Expand All @@ -260,9 +264,12 @@ def xindex(self,i=-1):
"""
i%=len(self)
if i<len(self.index):return self.index[i] #Index already calculated
if i==0:
if i==0: #First data entry (plot everything)
return np.arange(self.data[0].R.shape[0])

if len(self.data[i])==len(self.index[0]): #Matching lengths (plot everything)
return np.arange(len(self.data[i]))

mode=self.mode

in1=self.comparex(i=i)[1]
Expand Down
53 changes: 48 additions & 5 deletions Entropy/Entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def reset(self):
self._Scc=None
self._CC=None
self._CCpca=None
self._Chi=None

return self

Expand Down Expand Up @@ -342,6 +343,19 @@ def chi(self):
self._chi=out
return self._chi

@property
def Chi(self):
"""
Index-able Chi
Returns
-------
np.array
"""
if self._Chi is None:self._Chi=Chi(self)
return self._Chi

@property
def v_avg(self):
"""
Expand Down Expand Up @@ -728,6 +742,7 @@ def plotCCpca(self,index=None,states:list=None,ax=None,**kwargs):

#%% Plotting


def plotCC(self,index=None,ax=None,CCsum:bool=True,**kwargs):
"""
Make a CC plot for all residue pairs
Expand All @@ -748,10 +763,24 @@ def plotCC(self,index=None,ax=None,CCsum:bool=True,**kwargs):
"""





if index is None:index=np.ones(self.N,dtype=bool)
if ax is None:
ax=plt.subplots()[1]

index=np.array(index)
if index.size==1 and np.issubdtype(index.dtype,np.integer):
ax.plot(self.CC[index],**kwargs)
ax.xaxis.set_major_locator(plt.MaxNLocator(30,integer=True))
ax.xaxis.set_major_formatter(self._axis_formatter(np.arange(len(self.resids))))

ax.tick_params(axis='x', labelrotation=90)
ax.set_ylabel('C.C')
return ax


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


def plotChi(self,index:int,ax:list=None,step:int=1):
def plotChi(self,index:int,ax:list=None,step:int=1,cmap='tab10'):
"""
Creates one or more Ramachandran histogram plots, depending on the number
of chi angles, i.e. 1D histogram for Valine, 1 Ramachandran plot for
Expand All @@ -868,6 +897,8 @@ def plotChi(self,index:int,ax:list=None,step:int=1):
fig
"""
chi=self.Chi[index]

index=np.array(index)
if index.dtype==bool:index=np.argmax(index)

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

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



nstates=self.total_mult[index]
cmap=plt.get_cmap('turbo').resampled(nstates)
if isinstance(cmap,str):cmap=plt.get_cmap(cmap)

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


class Chi():
def __init__(self,ECC):
self.ECC=ECC



def __getitem__(self,index):
ECC=self.ECC
index=np.array(index)
if index.dtype==bool:index=np.argmax(index)

N=ECC.index[3:,index].sum()

return np.array([ECC.chi[k][ECC.index[k+3,:index].sum()] for k in range(N-1,-1,-1)])


# Tools for selecting the correct atoms to get rotamers
Expand Down
8 changes: 4 additions & 4 deletions PCA/CombinedPCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


from . import PCA
from ..Selection.MolSys import Trajectory
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
Expand All @@ -24,7 +23,6 @@ def __init__(self,*pcas):

self.traj[0]


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

maxbin=np.abs(self.PCamp[:nmax+1]).max()

for q,ax0 in enumerate(ax.T):
for ax00,n0,n1 in zip(ax0,range(nmax),range(1,nmax+1)):
self.Hist.plot(n0,n1,ax=ax00,cmap=cmap0,**kwargs)
self.Hist.plot(n0,n1,ax=ax00,cmap=cmap0,maxbin=maxbin,**kwargs)
index=np.zeros(len(self.traj),dtype=bool)
index[self.ranges[q][0]:self.ranges[q][1]]=True
self.Hist.plot(n0,n1,ax=ax00,cmap=cm,index=index)
self.Hist.plot(n0,n1,ax=ax00,cmap=cm,maxbin=maxbin,index=index)

fig.tight_layout()

Expand Down

0 comments on commit a28001e

Please sign in to comment.