Skip to content

Commit aca5c84

Browse files
committed
MIsc. updates
1 parent 094de4c commit aca5c84

File tree

4 files changed

+78
-11
lines changed

4 files changed

+78
-11
lines changed

Entropy/Entropy.py

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ def v_avg(self):
359359
out=[]
360360
for v,chi,mult in zip(self.vt,self.chi,self.mult):
361361
v=copy(v)
362+
vout=np.zeros(v.shape[:-1])
362363

363364
for q in [2,3]:
364365
for angle in [m*360/q for m in range(1,q)]:
@@ -367,9 +368,23 @@ def v_avg(self):
367368
v1=-v[0,i]*np.sin(2*np.pi/q)+v[1,i]*np.cos(2*np.pi/q)
368369
v[0,i]=v0
369370
v[1,i]=v1
370-
v=v.mean(-1)
371-
v/=np.sqrt(v[0]**2+v[1]**2) #Renormalization
372-
out.append(v)
371+
372+
for q in [2,3]:
373+
i=mult==q
374+
angle=np.arctan2(v[1,i],v[0,i])*q
375+
v0=np.median(np.cos(angle),axis=-1)
376+
v1=np.median(np.sin(angle),axis=-1)
377+
378+
angle=np.arctan2(v1,v0)/q
379+
380+
vout[0,i]=-np.cos(angle)
381+
vout[1,i]=-np.sin(angle)
382+
383+
384+
# v=v.mean(-1)
385+
# v/=np.sqrt(v[0]**2+v[1]**2) #Renormalization
386+
# out.append(v)
387+
out.append(vout)
373388
self._v_avg=out
374389

375390
return self._v_avg
@@ -399,6 +414,7 @@ def state0(self):
399414
overlap.append(v[0,i].T*vref[0]+v[1,i].T*vref[1])
400415

401416
state[-1][i]=np.argmax(overlap,axis=0).T
417+
402418
self._state0=state
403419
return self._state0
404420

@@ -831,6 +847,52 @@ def format_func(value,tick_number):
831847

832848
return plt.FuncFormatter(format_func)
833849

850+
851+
def plotChi(self,index:int,ax:list=None,step:int=1):
852+
"""
853+
Creates one or more Ramachandran histogram plots, depending on the number
854+
of chi angles, i.e. 1D histogram for Valine, 1 Ramachandran plot for
855+
Isoleucine, 2 plots for Glutamine, etc.
856+
857+
Parameters
858+
----------
859+
index : int
860+
DESCRIPTION.
861+
862+
Returns
863+
-------
864+
fig
865+
866+
"""
867+
index=np.array(index)
868+
if index.dtype==bool:index=np.argmax(index)
869+
870+
N=self.index[3:,index].sum()
871+
nplots=max([1,N-1])
872+
if ax is None:
873+
fig,ax=plt.subplots(1,nplots)
874+
ax=np.atleast_1d(ax).flatten()
875+
assert len(ax)==nplots,f"Residue {self.resid[index].resname}{self.resid[index].resid} has {N} chi angles, and therefore requires {nplots} plots"
876+
877+
chi=[self.chi[k][self.index[k+3,:index].sum()][::step] for k in range(N-1,-1,-1)]
878+
879+
nstates=self.total_mult[index]
880+
cmap=plt.get_cmap('turbo').resampled(nstates)
881+
882+
for a,k in zip(ax,range(N-1)):
883+
for m in range(nstates):
884+
i=self.state[index][::step]==m
885+
a.scatter(chi[k][i],chi[k+1][i],color=cmap(m),s=1)
886+
a.set_xlim([0,360])
887+
a.set_ylim([0,360])
888+
a.set_xlabel(rf'$\chi_{k+1}$ / $^\circ$')
889+
a.set_ylabel(rf'$\chi_{k+2}$ / $^\circ$')
890+
891+
fig.tight_layout()
892+
return ax
893+
894+
895+
834896
#%% Chimera functions
835897
def chimera(self,index=None,scaling:float=None,norm:bool=True,color=[1,0,0,1]):
836898
"""

PCA/PCAclean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def align(ref0,ref,atoms):
419419
Ut=U.T
420420

421421
R=V@Ut
422-
return (R@pos.T).T
422+
return (R.T@pos.T).T
423423

424424

425425
# def align(self):

PCA/PCAsubs.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,11 +1209,13 @@ def project(self):
12091209

12101210
@property
12111211
def n_clusters(self):
1212+
#Changing order here because some algorithms do not take n_clusters as argument
1213+
if self._output is not None and hasattr(self._output,'n_clusters'):
1214+
return self._output.n_clusters
1215+
12121216
if 'n_clusters' in self.cluster_kwargs:
12131217
return self.cluster_kwargs['n_clusters']
12141218

1215-
if self._output is not None and hasattr(self._output,'n_clusters'):
1216-
return self._output.n_clusters
12171219
return None
12181220

12191221
@n_clusters.setter
@@ -1308,11 +1310,12 @@ def plot(self,ax=None,skip:int=10,maxbin:float=None,nbins:int=None,cmap='binary'
13081310
for q in range(self.n_clusters):
13091311
a.scatter(self.pca.PCamp[self.index[k]][self.state==q][::skip],
13101312
self.pca.PCamp[self.index[k+1]][self.state==q][::skip],s=.1,color=cmap0(q))
1311-
a.scatter(self.pca.PCamp[self.index[k]][self.state==q].mean(),
1312-
self.pca.PCamp[self.index[k+1]][self.state==q].mean(),s=25,
1313-
color='black',marker='^')
1314-
13151313
if percent:
1314+
a.scatter(self.pca.PCamp[self.index[k]][self.state==q].mean(),
1315+
self.pca.PCamp[self.index[k+1]][self.state==q].mean(),s=25,
1316+
color='black',marker='^')
1317+
1318+
13161319
a.text(self.pca.PCamp[self.index[k]][self.state==q].mean(),
13171320
self.pca.PCamp[self.index[k+1]][self.state==q].mean(),
13181321
f'{self.populations[q]*100:.1f}%',

Selection/MolSys.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ def lengths(self):
427427
l=(self.mda_traj.total_times/self.mda_traj.dt).astype(int)
428428
l[0]-=self.t0
429429
l[-1]-=self.__tf-self.tf
430-
return l
430+
return (l/self.step).astype(int)
431431

432432

433433
@property
@@ -1083,6 +1083,8 @@ def chimera(self,color:tuple=(1.,0.,0.,1.),x=None,index=None,norm:bool=False):
10831083
if index is None:index=np.arange(len(self))
10841084

10851085
if np.max(color)>1:color=[float(c/255) for c in color]
1086+
if len(color)==3:color=[*color,1.]
1087+
10861088

10871089
if self.project is not None and self.project.chimera.saved_commands is not None:
10881090
for cmd in self.project.chimera.saved_commands:

0 commit comments

Comments
 (0)