Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
alsinmr committed Jan 29, 2024
1 parent 04f6e06 commit 2dbb234
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 656 deletions.
Binary file modified .temp.xtc_offsets.npz
Binary file not shown.
39 changes: 30 additions & 9 deletions PCA/PCAmovies.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def setup_swp(self,zrange=None,nframes:int=300,framerate:int=15):

# return self.data.R@wt0


#%% xtc writers
def xtc_from_weight(self,wt,rho_index:int,filename:str='temp.xtc',
nframes:int=150,framerate:int=15,scaling:float=1):
"""
Expand Down Expand Up @@ -304,8 +304,8 @@ def xtc_from_PCamp(self,PCamp,rho_index:int,filename:str='temp.xtc',nframes:int=
framerate:int=15,scaling:float=1):

timescale=self.PCARef.sens.info['z0'][rho_index]
step=np.round(10**timescale*1e12/self.PCARef.source.select.traj.dt/framerate).astype(int)
step=1
step=np.round(10**timescale*1e12/self.PCARef.source.select.traj.dt/framerate/3).astype(int)
# step=1
if step==0:step=1
if step*nframes>PCamp.shape[1]:
step=np.round(PCamp.shape[1]/nframes).astype(int)
Expand All @@ -321,15 +321,15 @@ def xtc_from_PCamp(self,PCamp,rho_index:int,filename:str='temp.xtc',nframes:int=

self._xtc=filename

self.options.TimescaleIndicator(tau=np.ones(nframes)*step*self.pca.select.traj.dt)
self.options.TimescaleIndicator(tau=np.ones(nframes)*step*self.pca.select.traj.dt/1e3)

return self






#%% Display modes
def xtc_rho(self,rho_index:int,frac:float=0.75,filename:str='temp.xtc',
nframes:int=150,framerate:int=15,scaling:float=1):
"""
Expand Down Expand Up @@ -399,12 +399,14 @@ def xtc_bond(self,index:int,rho_index:int,frac:float=0.75,filename:str='temp.xtc

def xtc_impulse(self,index:int,rho_index:int,frac:float=0.75,filename:str='temp.xtc',
nframes:int=150,framerate:int=15,scaling:float=1):
PCamp=self.pca.Impulse.PCamp_bond(index)
PCamp=self.pca.Impulse.PCamp_bond(index)[:,1:]
wt=self.pca.Weighting.bond(index=index,rho_index=rho_index)

self.xtc_from_PCamp(PCamp=(PCamp.T*wt).T, rho_index=rho_index,filename=filename,
nframes=nframes,framerate=framerate,scaling=scaling)

self.options.commands=['~ribbon #{0}','show #{0}']

return self

def xtc_noweight(self,rho_index:int=None,mode_index:int=None,filename:str='temp.xtc',
Expand Down Expand Up @@ -685,9 +687,21 @@ class Options():
def __init__(self,pca_movie):
self.dict={}
self.pca_movie=pca_movie

self._commands=[]

@property
def commands(self):
return self._commands
@commands.setter
def commands(self,value):
if isinstance(value,str):
value=[value]
assert isinstance(value,list),'Commands must be a list'
self._commands=value

def __call__(self):
for f in self.dict.values():f()
self.run_commands()

def clear(self):
for k in self.dict:
Expand All @@ -708,6 +722,10 @@ def add_event(self,name,*args):

def remove_event(self,name):
self.CMX.remove_event(self.CMXid,name)

def run_commands(self):
for cmd in self.commands:
self.CMX.command_line(self.CMXid,cmd.format(self.pca_movie.molsys.movie.mdlnums[0]))

def TimescaleIndicator(self,tau=None,remove:bool=False):
"""
Expand All @@ -725,12 +743,15 @@ def TimescaleIndicator(self,tau=None,remove:bool=False):
None.
"""
if tau is None:tau=10**self.pca_movie.setup['tscale_swp']*1e9

if remove:
if __name__ in self.dict:self.dict.pop(__name__)
return
if tau is None:tau=10**self.pca_movie.setup['tscale_swp']*1e9
if tau is not None:
self.dict['TimescaleIndicator']=lambda tau=tau:self.add_event('TimescaleIndicator', tau)
self.dict['TimescaleIndicator']=\
lambda tau=tau:self.add_event('TimescaleIndicator', tau,
self.pca_movie.molsys.movie.mdlnums[1])
return self

def Detectors(self,index=None,rho_index=None,remove:bool=False):
Expand Down
2 changes: 1 addition & 1 deletion PCA/testPCA.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

pca=PCA(select)
pca.select_bond('15N',resids=np.concatenate([np.arange(225,248),np.arange(261,281)]))
pca.select_bond('15N')
# pca.select_bond('15N')
pca.select_atoms('all')


Expand Down
8 changes: 4 additions & 4 deletions chimeraX/CMXEvents.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ def cleanup(self):


class TimescaleIndicator():
def __init__(self, cmx, tau):
def __init__(self, cmx, tau, mn:int=-1):
self.cmx = cmx
self.session = cmx.session
self.model = self.session.models[-1]
self.model = self.session.models[mn]
self.tau = tau
self.i = -1
self.label = label_create(self.session, 'timescale', # Create a 2d label
text='1 s: {:.0f} ps'.format(self.tau[1] * 1e3),
text='1 s: {:.0f} ps'.format(self.tau[0] * 1e3),
xpos=0.02, ypos=.05, size=50)

def __call__(self):
i = self.model.active_coordset_id - 1
if i != self.i:
tau = self.tau[i] * 1e3
if i == 0 and False:
if i == 0:
text = '1 s: {:.0f} ps'.format(self.tau[1] * 1e3)
elif tau < 1e3:
text = '1 s: {:.0f} ps'.format(tau)
Expand Down
Binary file modified temp_pyDR/.temp.xtc_offsets.npz
Binary file not shown.
Loading

0 comments on commit 2dbb234

Please sign in to comment.