restart for md and remd
authorCezary Czaplewski <czarek@chem.univ.gda.pl>
Tue, 10 Apr 2018 21:13:28 +0000 (23:13 +0200)
committerCezary Czaplewski <czarek@chem.univ.gda.pl>
Tue, 10 Apr 2018 21:13:28 +0000 (23:13 +0200)
django_simple/todo/jobfiles.py
django_simple/todo/models.py
django_simple/todo/templates/details.html
django_simple/todo/urls.py
django_simple/todo/views.py
files/matplotlib_fit_hist.py
files/matplotlib_hist.py

index 6328f4e..61d2c45 100644 (file)
@@ -147,7 +147,7 @@ CUTOFF=7.00000 WCORR4=0.00000"""
           if instance.md_pdbref:
              control_line = control_line+'pdbref '
             
-          type_line = 'reset_vel=0'\
+          type_line = 'restart reset_vel=0'\
              +' t_bath='+str(instance.md_temp)\
              +' nstep='+str(instance.md_nstep)\
              +' ntwe='+str(instance.md_ntwe)\
@@ -187,7 +187,7 @@ CUTOFF=7.00000 WCORR4=0.00000"""
              cntrl_saxs=' nsaxs='+str(nsaxs)+' scal_rad='+str(instance.scal_rad) 
              control_line += cntrl_saxs             
             
-          type_line = 'reset_vel='+ str(instance.remd_nstex)\
+          type_line = 'restart reset_vel='+ str(instance.remd_nstex)\
              +' nstep='+str(instance.md_nstep)\
              +' ntwe='+str(instance.md_ntwe)\
              +' ntwx='+str(instance.md_ntwx)\
@@ -400,12 +400,12 @@ CUTOFF=7.00000 WCORR4=0.00000"""
               isampl=1
           else:
               isampl=int(instance.md_nstep/instance.md_ntwx*nreplicas/8000)
-
+          f.write('{:79}'.format(' isampl='+str(isampl))+'&\n')
           if instance.md_pdbref:
-            f.write('{:79}'.format('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
+            f.write('{:79}'.format('SEED='+str(instance.md_seed)+
                ' einicheck=1 rescale=2 delta=0.02 cxfile classify')+'&\n')
           else:    
-            f.write('{:79}'.format('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
+            f.write('{:79}'.format('SEED='+str(instance.md_seed)+
               ' einicheck=1 rescale=2 delta=0.02 cxfile')+'&\n')
           if instance.md_2d != '':
                f.write('{:79}'.format(' WITH_DIHED_CONSTR')+'&\n')
index fc0f358..0291472 100644 (file)
@@ -70,6 +70,7 @@ class Task(models.Model):
     md_mdpdb = models.BooleanField(default=False)
     md_seq = models.TextField(max_length=2000,default='')
     md_2d = models.TextField(max_length=2000,default='')
+    md_total_steps = models.IntegerField(default=200000)
     
 #remd
     remd_nrep = models.IntegerField(default=8)
index 783ed7e..d32f9fe 100644 (file)
@@ -43,6 +43,18 @@ Created {{ task.created_date  }}
                                <div class="col-md-8">
                                        {% if task.done %}
                                                <span class="fa fa-check-square-o"></span>
+                                           {% if task.type == "md" or task.type == "remd" %}
+                                             <form action="restart/"
+                                               method="get"
+                                               style="text-align;float:right;">
+                                               {% csrf_token %}
+                                                <input type="submit" 
+                                                class="btn btn-default" 
+                                                value="Restart"
+                                                name="restartbtn">
+                                                </button>
+                                              </form>
+                                            {% endif %}  
                                        {% else %}
                                          {% if task.running > 0  %}
                                                <span class="fa fa-spinner
@@ -165,6 +177,10 @@ Created {{ task.created_date  }}
                            <div class="col-md-6">{{ task.md_nstep}}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-md-6"> total steps (with restarts) </div>
+                           <div class="col-md-6">{{ task.md_total_steps}}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-md-6"> ntwe </div>
                            <div class="col-md-6">{{ task.md_ntwe}}</div>
                        </li>           
@@ -262,6 +278,10 @@ Created {{ task.created_date  }}
                            <div class="col-md-6">{{ task.md_nstep}}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-md-6"> total steps (with restarts) </div>
+                           <div class="col-md-6">{{ task.md_total_steps}}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-md-6"> ntwe </div>
                            <div class="col-md-6">{{ task.md_ntwe}}</div>
                        </li>           
@@ -427,7 +447,8 @@ Created {{ task.created_date  }}
                            <div class="col-md-2"> Movie </div>
                            <div class="col-md-10"> 
 
-                            <video width="500" height="400" preload controls>
+                            <video width="500" height="400"
+                            preload="auto" controls="controls">
                             <source
                             src="/myfiles/download-file/{{task.jobdirname}}/md.ogv"
                             type="video/ogg; codecs=theora"> </source>
@@ -445,7 +466,7 @@ Created {{ task.created_date  }}
                        </li>
                         <li class="list-group-item task-item">
                <div class="col-md-6">
-<input id="clipRange" type="range" value=0 min=0 max= {% widthratio task.md_nstep task.md_ntwx 1 %} step=1 ></input><span id="clipRange_val">0</span> frame
+<input id="clipRange" type="range" value=0 min=0 max= {% widthratio task.md_total_steps task.md_ntwx 1 %} step=1 ></input><span id="clipRange_val">0</span> frame
 </div>
 <div class="col-md-6">
 <button id="toggleRunMDs">run/pause MD</button>  
@@ -980,8 +1001,7 @@ $(document).ready(function() {
   setTimeout(worker, 30000);
 });
 </script>
-{% endif %} 
-       
+{% endif %}    
 
 {% if task.type == "min" %}
 <script>
index e6d65b7..8f9d702 100644 (file)
@@ -19,6 +19,7 @@ urlpatterns = [
        url(r'^add_dock/(?P<task_id>\d+)/adv/$', views.add_dock_a,name='add_dock_a'),                   
        url(r'^add_mlist/(?P<task_id>\d+)/$', views.addmlist,name='addmlist'),          
         url(r'^details/(?P<task_id>\d+)/$', views.details,name='details'),
+        url(r'^details/(?P<task_id>\d+)/restart/$', views.restart,name='restart'),        
         url(r'^details1/(?P<user_id>\w+)/(?P<task_id>\d+)/$', views.details1,name='details1'),        
        url(r'^delete/(?P<task_id>\d+)/$', views.delete),
 ]
index 8ad5060..d9525b0 100644 (file)
@@ -292,6 +292,7 @@ def add_md(request,task_id):
              task.md_start=form.cleaned_data["md_start"]
              task.md_temp=form.cleaned_data["md_temp"]
              task.md_nstep=form.cleaned_data["md_nstep"]
+             task.md_total_steps=task.md_nstep
 
              basename = str(task.owner)
              suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
@@ -380,6 +381,7 @@ def add_md_a(request,task_id):
 
              task.md_temp=form.cleaned_data["md_temp"]
              task.md_nstep=form.cleaned_data["md_nstep"]
+             task.md_total_steps=task.md_nstep
              task.md_ntwe=form.cleaned_data["md_ntwe"]
              task.md_ntwx=form.cleaned_data["md_ntwx"]
              task.md_dt=form.cleaned_data["md_dt"]
@@ -452,6 +454,7 @@ def add_remd(request,task_id):
              task.md_seed=form.cleaned_data["md_seed"]
 
              task.md_nstep=form.cleaned_data["md_nstep"]
+             task.md_total_steps=task.md_nstep
 
              if any(c.islower() for c in seq):
               task.md_respa=False
@@ -669,6 +672,7 @@ def add_remd_a(request,task_id):
 
              task.md_seed=form.cleaned_data["md_seed"]
              task.md_nstep=form.cleaned_data["md_nstep"]
+             task.md_total_steps=task.md_nstep
              task.md_dt=form.cleaned_data["md_dt"]
              task.md_lang=form.cleaned_data["md_lang"]
              task.md_tau=form.cleaned_data["md_tau"]
@@ -901,6 +905,44 @@ def delete(request, task_id):
     Task.objects.get(id=task_id).delete()
     return redirect('/')
 
+@login_required
+def restart(request, task_id):
+    task = get_object_or_404(Task, id=task_id)
+    if os.path.isfile(task.jobdirname+'/finished'):    
+      os.remove(task.jobdirname+'/finished')
+    task.running =1
+    task.done=False
+    task.md_total_steps = task.md_total_steps+task.md_nstep
+    task.save()
+    if task.type == 'md':
+      os.chdir(task.jobdirname)
+      ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)            
+      os.chdir('..')
+    elif task.type == 'remd':
+      os.chdir(task.jobdirname)
+      tmp1=json.loads(task.remd_multi_m)
+      nreplicas=sum(map(int, tmp1))
+      with open('file_wham.inp','r') as f1, open ('file_wham.tmp','w') as f2:
+        for line in f1:
+          if 'rec_end=' in line:
+            rec=task.md_total_steps/task.md_ntwx
+            f2.write('nfile_cx=1 rec_start='+str(rec/10)
+               +' rec_end='+str(rec)+' totraj='+str(nreplicas)+'\n')
+          elif 'isampl=' in line:
+            if task.md_total_steps/task.md_ntwx*nreplicas<=8000:
+                isampl=1
+            else:
+                isampl=int(task.md_total_steps/task.md_ntwx*nreplicas/8000)
+            f2.write('{:79}'.format(' isampl='+str(isampl))+'&\n')
+          else:
+            f2.write(line)
+      os.remove('file_wham.inp')
+      os.rename('file_wham.tmp','file_wham.inp')
+      ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)            
+      os.chdir('..')
+    return redirect('/')
+
+
 def refresh_done1(request, task_id):
     task = get_object_or_404(Task, id=task_id)
     user = task.owner
index f431e31..b31025e 100755 (executable)
@@ -29,11 +29,14 @@ with open('md.stat','r') as f:
   ncolumns=len(line.split())
 
 if ncolumns==14:  
- x,y= np.loadtxt('md.stat',usecols=(0,10),skiprows=10,unpack=True)
- x1,e,r,gy,nc= np.loadtxt('md.stat',usecols=(0,3,5,12,6),skiprows=0,unpack=True)
+ x,y= np.loadtxt('md.stat',usecols=(1,10),skiprows=10,unpack=True)
+ x1,e,r,gy,nc= np.loadtxt('md.stat',usecols=(1,3,5,12,6),skiprows=0,unpack=True)
 else:
- x,y= np.loadtxt('md.stat',usecols=(0,6),skiprows=10,unpack=True)
- x1,e,gy= np.loadtxt('md.stat',usecols=(0,3,8),skiprows=0,unpack=True)
+ x,y= np.loadtxt('md.stat',usecols=(1,6),skiprows=10,unpack=True)
+ x1,e,gy= np.loadtxt('md.stat',usecols=(1,3,8),skiprows=0,unpack=True)
+
+x=x*0.0489
+x1=x1*0.0489
  
 h,bin=np.histogram(y,bins=50,density=True)
 
@@ -61,26 +64,26 @@ plt.savefig('temp_hist.png')
 #plt.show()   
 
 plt.clf()
-plt.xlabel('step')
+plt.xlabel('time [ps]')
 plt.ylabel('potential energy')
 plt.plot(x1,e,'.')
 plt.savefig('md_ene.png')
 
 plt.clf()
-plt.xlabel('step')
+plt.xlabel('time [ps]')
 plt.ylabel('radius of gyration')
 plt.plot(x1,gy,'.')
 plt.savefig('md_gyr.png')
 
 if ncolumns==14:
  plt.clf()
- plt.xlabel('step')
+ plt.xlabel('time [ps]')
  plt.ylabel('RMSD')
  plt.plot(x1,r,'.')
  plt.savefig('md_rms.png')
 
  plt.clf()
- plt.xlabel('step')
+ plt.xlabel('time [ps]')
  plt.ylabel('fraction of native side-chain concacts')
  plt.plot(x1,nc,'.')
  plt.savefig('md_fracn.png')
index 168195b..69bf5b0 100755 (executable)
@@ -13,12 +13,14 @@ with open('remd_all.stat','r') as f:
   ncolumns=len(line.split())
 
 if ncolumns==14:  
- x,y,s,r,ek,rms= np.loadtxt('remd_all.stat',usecols=(11,3,0,13,2,5),unpack=True)
- x0,s0,r0,rms0= np.loadtxt('remd_all0.stat',usecols=(11,0,13,5),unpack=True) 
+ x,y,s,r,ek,rms= np.loadtxt('remd_all.stat',usecols=(11,3,1,13,2,5),unpack=True)
+ x0,s0,r0,rms0= np.loadtxt('remd_all0.stat',usecols=(11,1,13,5),unpack=True) 
 else:
- x,y,s,r= np.loadtxt('remd_all.stat',usecols=(7,3,0,9),unpack=True)
- x0,s0,r0= np.loadtxt('remd_all0.stat',usecols=(7,0,9),unpack=True) 
+ x,y,s,r= np.loadtxt('remd_all.stat',usecols=(7,3,1,9),unpack=True)
+ x0,s0,r0= np.loadtxt('remd_all0.stat',usecols=(7,1,9),unpack=True) 
 
+s=s*0.0489
+s0=s0*0.0489
 hall,binall=np.histogram(y,bins=40,density=False)
 
 plt.xlim(min(binall), max(binall[hall>4]))
@@ -59,7 +61,7 @@ plt.savefig('remd_Tene.png')
 
 plt.clf()
 plt.ylabel('bath temperature [K]')
-plt.xlabel('step*replica')
+plt.xlabel('time*replica')
 
 replica=range(int(sys.argv[2]))
 #colors = cm.rainbow(np.linspace(0, 1, len(replica)))
@@ -88,7 +90,7 @@ if ncolumns==14:
   plt.savefig('remd_ene_rms.png')
 
   plt.clf()
-  plt.xlabel('step*replica')
+  plt.xlabel('time*replica')
   plt.ylabel('rmsd')
   for i in replica:
     yt=rms0[r0==i]