Skip to content

Commit b633ea2

Browse files
committed
Updates
1 parent 2386ce5 commit b633ea2

File tree

5 files changed

+106
-5
lines changed

5 files changed

+106
-5
lines changed

Data/Data.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import numpy as np
1111
from pyDR import Defaults,clsDict
1212
from ..IO import write_file
13-
from .Plotting import plot_fit,DataPlots
13+
from .Plotting import plot_fit,DataPlots,plot_fit_md
1414
from ..Fitting import fit,opt2dist
1515
from matplotlib.figure import Figure
1616
from copy import copy
@@ -426,7 +426,6 @@ def plot(self, errorbars=False, style='canvas', fig=None, index=None,
426426

427427

428428
def plot_fit(self,index=None, exp_index=None, fig=None):
429-
# todo maybe worth to remove the args and put them all into kwargs? -K
430429
assert self.src_data is not None and hasattr(self, 'Rc') and self.Rc is not None,\
431430
"Plotting a fit requires the source data(src_data) and Rc"
432431
info = self.src_data.info.copy()
@@ -437,6 +436,10 @@ def plot_fit(self,index=None, exp_index=None, fig=None):
437436
Rin=np.concatenate((Rin,np.atleast_2d(1-self.src_data.S2).T),axis=1)
438437
Rc=np.concatenate((Rc,np.atleast_2d(1-self.S2c).T),axis=1)
439438
Rin_std=np.concatenate((Rin_std,np.atleast_2d(self.src_data.S2std).T),axis=1)
439+
440+
if self.src_data.sens.__class__.__name__=='MD':
441+
return plot_fit_md(lbl,Rin,Rc,index=index,info=info)
442+
440443

441444
return plot_fit(lbl=lbl,Rin=Rin,Rc=Rc,Rin_std=Rin_std,\
442445
info=info,index=index,exp_index=exp_index,fig=fig)

Data/Plotting.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,37 @@ def plot_fit(lbl,Rin,Rc,Rin_std=None,info=None,index=None,exp_index=None,fig=Non
602602
string=r'$\nu_r$={0} kHz, $\nu_1$={1} kHz'.format(i['vr'],i['v1'])
603603
a.text(np.min(lbl),a.get_ylim()[1]*0.73,string,fontsize=8)
604604
# fig.show()
605-
return ax
605+
return ax
606+
607+
def plot_fit_md(lbl,Rin,Rc,info=None,index=None,fig=None):
608+
609+
if index is not None:
610+
lbl=lbl[index]
611+
Rin=Rin[index]
612+
Rc=Rc[index]
613+
614+
if fig is None:
615+
fig=plt.figure(figsize=[12,9])
616+
ax,*_=subplot_setup(len(lbl),fig)
617+
618+
t=info['t']
619+
620+
for lbl0,Rin0,Rc0,a in zip(lbl,Rin,Rc,ax):
621+
a.plot(t,Rin0,color='red')
622+
a.plot(t,Rc0,color='black',linestyle=':')
623+
a.text(t[1],0.1,lbl0)
624+
a.set_ylim([-.1,1])
625+
if a.is_first_col():
626+
a.set_ylabel(r'$C(t)$')
627+
else:
628+
a.set_yticklabels('')
629+
if a.is_last_row():
630+
a.set_xlabel(r'$t$ / ns')
631+
else:
632+
a.set_xticklabels('')
633+
634+
return ax
635+
606636

607637
def subplot_setup(nexp,fig=None):
608638
"""

Fitting/fit.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ._fitfun import fit0,dist_opt
1414
from copy import copy
1515
from pyDR.misc.tools import linear_ex
16+
from ..misc import ProgressBar
1617

1718
dtype=Defaults['dtype']
1819

@@ -375,8 +376,9 @@ def model_free(data,nz:int=None,fixz:list=None,fixA:list=None,Niter:int=None,inc
375376
A.append(np.array(fixA[k]) if hasattr(fixA[k],'__len__') else np.ones(nb)*fixA[k])
376377

377378
zswp=np.linspace(z0[0],z0[-1],nsteps);
379+
ProgressBar(0, Niter,prefix='Iterations',suffix=f' of {Niter} steps',length=30,decimals=0)
378380
for q in range(Niter):
379-
print('{0} of {1} iterations'.format(q+1,Niter))
381+
# print('{0} of {1} iterations'.format(q+1,Niter))
380382
for k in range(nz):
381383
R0=np.zeros(R.shape)
382384
for m in range(nz):
@@ -429,6 +431,7 @@ def model_free(data,nz:int=None,fixz:list=None,fixA:list=None,Niter:int=None,inc
429431
else:
430432
#All parameters fixed (no operations)
431433
pass
434+
ProgressBar(q+1, Niter,prefix='Iterations',suffix=f' of {Niter} steps')
432435
#Calculate the fit
433436

434437
Rc=np.zeros(data.R.shape)

Frames/user_frames.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,67 @@ def sub()
8080
from pyDR.MDtools import vft
8181
from pyDR.Selection import select_tools as selt
8282

83+
def bondXY(molecule,sel1=1,sel2=2,resids=None,segids=None,filter_str:str=None,sigma:float=0):
84+
"""
85+
86+
87+
Parameters
88+
----------
89+
molecule : TYPE
90+
Selection object.
91+
sel1 : TYPE, optional
92+
First atom defining the bond. The default is 1.
93+
sel2 : TYPE, optional
94+
Second atom defining the bond. The default is 2.
95+
resids : TYPE, optional
96+
List of residues for which we should return aromatic planes.
97+
The default is None.
98+
segids : TYPE, optional
99+
List of segments for which we should return aromatic planes.
100+
The default is None.
101+
filter_str : str, optional
102+
string which filters the selection using MDAnalysis format.
103+
The default is None.
104+
sigma : float, optional
105+
Parameter to determine Gaussian moving average in post processing.
106+
The default is 0 (no post processing).
107+
108+
Returns
109+
-------
110+
None.
111+
112+
"""
113+
114+
if not(hasattr(sel1,'__len__')):
115+
sel1=(sel1+sel1)[:1]
116+
if not(hasattr(sel2,'__len__')):
117+
sel2=(sel2+sel2)[:1]
118+
119+
sel1=selt.sel_simple(molecule,sel1,resids,segids,filter_str)
120+
sel2=selt.sel_simple(molecule,sel2,resids,segids,filter_str)
121+
122+
123+
124+
125+
if len(sel1)==1:
126+
frame_index=np.zeros(len(molecule.sel1),dtype=int)
127+
elif len(sel1)==len(molecule.sel1):
128+
frame_index=np.arange(len(sel1))
129+
else:
130+
frame_index=None
131+
132+
def sub():
133+
box=molecule.box
134+
vXZ=sel1.positions-sel2.positions
135+
vXZ[:,2]=0
136+
vXZ=vft.pbc_corr(vXZ.T,box)
137+
vZ=np.zeros(vXZ.shape)
138+
vZ[2]=1
139+
return vZ,vXZ
140+
141+
return sub,frame_index,{'PPfun':'AvgGauss','sigma':sigma}
142+
143+
144+
145+
146+

Selection/MolSys.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ def __init__(self,topo:str,traj_files:list=None,t0:int=0,tf:int=None,step:int=1,
8787
self._traj=Trajectory(self.uni.trajectory,t0=t0,tf=tf,step=step,dt=dt) \
8888
if hasattr(self.uni,'trajectory') else None
8989

90+
self.project=project
9091
self.make_pdb()
9192

92-
self.project=project
93+
9394

9495
self._movie=None
9596

0 commit comments

Comments
 (0)