use pdbid to load pdb and set all examples
authorCezary Czaplewski <czarek@chem.univ.gda.pl>
Mon, 20 Nov 2017 21:43:07 +0000 (22:43 +0100)
committerCezary Czaplewski <czarek@chem.univ.gda.pl>
Mon, 20 Nov 2017 21:43:07 +0000 (22:43 +0100)
django_simple/todo/forms.py
django_simple/todo/templates/details.html
django_simple/todo/templates/details1.html
django_simple/todo/views.py

index c8d2671..bfbd094 100644 (file)
@@ -80,8 +80,11 @@ class TaskForm_min_a(forms.Form):
                   help_text='maximum number of iterations')
      min_maxfun = forms.IntegerField(label='MAXFUN',initial=15000,
                   help_text='maximum number of function evaluations')
-     file1 = forms.FileField(label='Upload a PDB file',
+     file1 = forms.FileField(label='Upload a PDB file',required=False,
         help_text='continuous (without breaks) protein chains,use TER to divide chains')
+     pdbid = forms.CharField(min_length=4,max_length=4,required=False,
+      widget=forms.TextInput(attrs={'size':4, 'maxlength':4, 'title':'PDB code'}),
+      label='or PDB code')                   
 
      min_unres_pdb = forms.BooleanField(required=False,label='uploaded input unres PDB',
                   help_text='(CA and CB atoms only, CB represents SC in UNRES)')
@@ -93,6 +96,23 @@ class TaskForm_min_a(forms.Form):
      boxz = forms.FloatField(label='Box Z',initial=1000.0,
                        help_text='box z dimension')
 
+     def clean(self):
+             cleaned_data = super(TaskForm_min_a, self).clean()
+
+             pdbid = cleaned_data.get("pdbid") 
+             file1 = cleaned_data.get("file1")
+              
+             if not pdbid and not file1:
+                msg = 'provide pdb file or pdb code'
+                self.add_error('file1', msg)
+              
+             if pdbid:
+               test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+               if test.code != 200:
+                 msg = 'wrong pdb code'
+                 self.add_error('pdbid', msg)
+               test.close()
+
 
 class TaskForm_md(forms.Form):
      name = forms.CharField(max_length=20)
@@ -106,6 +126,9 @@ class TaskForm_md(forms.Form):
                      widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
      file1 = forms.FileField(label='Upload a PDB file',required=False,
                   help_text='starting structure for pdbstart/reference structure')
+     pdbid = forms.CharField(min_length=4,max_length=4,required=False,
+      widget=forms.TextInput(attrs={'size':4, 'maxlength':4, 'title':'PDB code'}),
+      label='or PDB code')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
      md_temp = forms.FloatField(label='temperature',initial=300,
                   help_text='bath temperature')
@@ -119,15 +142,16 @@ class TaskForm_md(forms.Form):
 
              md_start = cleaned_data.get("md_start") 
              file1 = cleaned_data.get("file1")
+             pdbid = cleaned_data.get("pdbid")
              md_seq = cleaned_data.get("md_seq")
              md_pdbref = cleaned_data.get("md_pdbref")
               
-             if md_start == 'pdbstart' and not file1:
-                msg = 'pdbstart with no PDB file'
+             if md_start == 'pdbstart' and not (file1 or pdbid):
+                msg = 'pdbstart with no PDB file or code'
                 self.add_error('file1', msg)
 
-             if md_pdbref and not file1:
-                msg = 'pdbref with no PDB file'
+             if md_pdbref and not (file1 or pdbid):
+                msg = 'pdbref with no PDB file or code'
                 self.add_error('file1', msg)
 
 
@@ -135,6 +159,13 @@ class TaskForm_md(forms.Form):
                 msg = 'extended/random chain with no sequence'
                 self.add_error('md_seq', msg)
 
+             if pdbid:
+               test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+               if test.code != 200:
+                 msg = 'wrong pdb code'
+                 self.add_error('pdbid', msg)
+               test.close()
+
                         
 class TaskForm_md_a(forms.Form):
      name = forms.CharField(max_length=20)
@@ -150,6 +181,9 @@ class TaskForm_md_a(forms.Form):
                      widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
      file1 = forms.FileField(label='Upload a PDB file',required=False,
                   help_text='starting structure for pdbstart/reference structure')
+     pdbid = forms.CharField(min_length=4,max_length=4,required=False,
+      widget=forms.TextInput(attrs={'size':4, 'maxlength':4, 'title':'PDB code'}),
+      label='or PDB code')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_temp = forms.FloatField(label='temperature',initial=300,
                   help_text='bath temperature')
@@ -183,15 +217,16 @@ class TaskForm_md_a(forms.Form):
 
              md_start = cleaned_data.get("md_start") 
              file1 = cleaned_data.get("file1")
+             pdbid = cleaned_data.get("pdbid")
              md_seq = cleaned_data.get("md_seq")
              md_pdbref = cleaned_data.get("md_pdbref")
               
-             if md_start == 'pdbstart' and not file1:
-                msg = 'pdbstart with no PDB file'
+             if md_start == 'pdbstart' and not (file1 or pdbid):
+                msg = 'pdbstart with no PDB file or code'
                 self.add_error('file1', msg)
 
-             if md_pdbref and not file1:
-                msg = 'pdbref with no PDB file'
+             if md_pdbref and not (file1 or pdbid):
+                msg = 'pdbref with no PDB file or code'
                 self.add_error('file1', msg)
 
 
@@ -199,6 +234,13 @@ class TaskForm_md_a(forms.Form):
                 msg = 'extended/random chain with no sequence'
                 self.add_error('md_seq', msg)
 
+             if pdbid:
+               test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+               if test.code != 200:
+                 msg = 'wrong pdb code'
+                 self.add_error('pdbid', msg)
+               test.close()
+
 
 class TaskForm_remd(forms.Form):
      name = forms.CharField(max_length=20)
@@ -212,6 +254,9 @@ class TaskForm_remd(forms.Form):
                      widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
      file1 = forms.FileField(label='Upload a PDB file',required=False,
                   help_text='starting structure for pdbstart/reference structure')
+     pdbid = forms.CharField(min_length=4,max_length=4,required=False,
+      widget=forms.TextInput(attrs={'size':4, 'maxlength':4, 'title':'PDB code'}),
+      label='or PDB code')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
                   help_text='total number of steps')
@@ -223,21 +268,29 @@ class TaskForm_remd(forms.Form):
 
              md_start = cleaned_data.get("md_start") 
              file1 = cleaned_data.get("file1")
+             pdbid = cleaned_data.get("pdbid")
              md_seq = cleaned_data.get("md_seq")
              md_pdbref = cleaned_data.get("md_pdbref")
               
-             if md_start == 'pdbstart' and not file1:
-                msg = 'pdbstart with no PDB file'
+             if md_start == 'pdbstart' and not (file1 or pdbid):
+                msg = 'pdbstart with no PDB file or code'
                 self.add_error('file1', msg)
 
-             if md_pdbref and not file1:
-                msg = 'pdbref with no PDB file'
+             if md_pdbref and not (file1 or pdbid):
+                msg = 'pdbref with no PDB file or code'
                 self.add_error('file1', msg)
 
              if md_start != 'pdbstart' and not md_pdbref and not md_seq:
                 msg = 'extended/random chain with no sequence'
                 self.add_error('md_seq', msg)
 
+             if pdbid:
+               test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+               if test.code != 200:
+                 msg = 'wrong pdb code'
+                 self.add_error('pdbid', msg)
+               test.close()
+
                              
 class TaskForm_remd_a(forms.Form):
      name = forms.CharField(max_length=20)
@@ -253,6 +306,9 @@ class TaskForm_remd_a(forms.Form):
                      widget=forms.Textarea(attrs={'cols': 70, 'rows': 2}))
      file1 = forms.FileField(label='Upload a PDB file',required=False,
                   help_text='starting structure for pdbstart/reference structure')
+     pdbid = forms.CharField(min_length=4,max_length=4,required=False,
+      widget=forms.TextInput(attrs={'size':4, 'maxlength':4, 'title':'PDB code'}),
+      label='or PDB code')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
                   help_text='total number of steps')
@@ -291,15 +347,16 @@ class TaskForm_remd_a(forms.Form):
 
              md_start = cleaned_data.get("md_start") 
              file1 = cleaned_data.get("file1")
+             pdbid = cleaned_data.get("pdbid")
              md_seq = cleaned_data.get("md_seq")
              md_pdbref = cleaned_data.get("md_pdbref")
               
-             if md_start == 'pdbstart' and not file1:
-                msg = 'pdbstart with no PDB file'
+             if md_start == 'pdbstart' and not (file1 or pdbid):
+                msg = 'pdbstart with no PDB file or code'
                 self.add_error('file1', msg)
 
-             if md_pdbref and not file1:
-                msg = 'pdbref with no PDB file'
+             if md_pdbref and not (file1 or pdbid):
+                msg = 'pdbref with no PDB file or code'
                 self.add_error('file1', msg)
 
 
@@ -307,6 +364,14 @@ class TaskForm_remd_a(forms.Form):
                 msg = 'extended/random chain with no sequence'
                 self.add_error('md_seq', msg)
 
+             if pdbid:
+               test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+               if test.code != 200:
+                 msg = 'wrong pdb code'
+                 self.add_error('pdbid', msg)
+               test.close()
+
+
 
 class TaskForm_list(forms.Form):
     name = forms.CharField(max_length=20,disabled=True,required=False)
index 3945f84..54485c6 100644 (file)
@@ -128,6 +128,10 @@ Created {{ task.created_date  }}
                            <div class="col-xs-10">{{ task.myfile1 }}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-xs-10"> pdb code</div>
+                           <div class="col-xs-10">{{ task.pdbcode }}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-xs-10"> seed </div>
                            <div class="col-xs-10">{{ task.md_seed}}</div>
                        </li>           
@@ -202,6 +206,10 @@ Created {{ task.created_date  }}
                            <div class="col-xs-10">{{ task.myfile1 }}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-xs-10"> pdb code</div>
+                           <div class="col-xs-10">{{ task.pdbcode }}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-xs-10"> seed </div>
                            <div class="col-xs-10">{{ task.md_seed}}</div>
                        </li>           
index abe2f11..92e3252 100644 (file)
@@ -108,6 +108,10 @@ Created {{ task.created_date  }}
                            <div class="col-xs-10">{{ task.myfile1 }}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-xs-10"> pdb code</div>
+                           <div class="col-xs-10">{{ task.pdbcode }}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-xs-10"> unres_pdb</div>
                            <div class="col-xs-10">{{ task.min_unres_pdb }}</div>
                        </li>           
@@ -124,6 +128,10 @@ Created {{ task.created_date  }}
                            <div class="col-xs-10">{{ task.myfile1 }}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-xs-10"> pdb code</div>
+                           <div class="col-xs-10">{{ task.pdbcode }}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-xs-10"> seed </div>
                            <div class="col-xs-10">{{ task.md_seed}}</div>
                        </li>           
@@ -198,6 +206,10 @@ Created {{ task.created_date  }}
                            <div class="col-xs-10">{{ task.myfile1 }}</div>
                        </li>           
                        <li class="list-group-item task-item">
+                           <div class="col-xs-10"> pdb code</div>
+                           <div class="col-xs-10">{{ task.pdbcode }}</div>
+                       </li>           
+                       <li class="list-group-item task-item">
                            <div class="col-xs-10"> seed </div>
                            <div class="col-xs-10">{{ task.md_seed}}</div>
                        </li>           
index df3fb4d..d02f588 100644 (file)
@@ -169,6 +169,10 @@ def add_min(request,task_id):
 def add_min_a(request,task_id):
     task = get_object_or_404(Task, id=task_id)
     if request.method == 'POST':
+     if '_example' in request.POST:
+        data= {'name':task.name,'pdbid':'1EI0'}
+        form = TaskForm_min_a(initial=data)     
+     else:
         form = TaskForm_min_a(request.POST,request.FILES)
         if form.is_valid():
              task.name=form.cleaned_data["name"]
@@ -179,7 +183,20 @@ def add_min_a(request,task_id):
              task.min_maxmin=form.cleaned_data["min_maxmin"]
              task.min_maxfun=form.cleaned_data["min_maxfun"]
              task.min_pdbout=form.cleaned_data["min_pdbout"]
-             task.myfile1=form.cleaned_data["file1"]
+
+             basename = str(task.owner)
+             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
+             task.jobdirname = "_".join([basename, suffix])
+             
+             pdbid=form.cleaned_data["pdbid"]
+             if pdbid:
+              os.mkdir(task.jobdirname)
+              task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb',
+                     task.jobdirname+'/plik.pdb')     
+              task.pdbcode=pdbid
+             else:
+              task.myfile1=form.cleaned_data["file1"]
+
              task.min_unres_pdb=form.cleaned_data["min_unres_pdb"]
              task.unres_ff=form.cleaned_data["unres_ff"]
              task.boxx=form.cleaned_data["boxx"]
@@ -191,11 +208,7 @@ def add_min_a(request,task_id):
              for i in range(0,len(seq),40):
                 task.md_seq=task.md_seq+seq[i:i+40]+" "
                                                            
-
              task.ready=True
-             basename = str(task.owner)
-             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
-             task.jobdirname = "_".join([basename, suffix])
              
              task.save()
              if is_lazy_user(request.user):
@@ -213,6 +226,11 @@ def add_min_a(request,task_id):
 def add_md(request,task_id):
     task = get_object_or_404(Task, id=task_id)
     if request.method == 'POST':
+     if '_example' in request.POST:
+        data= {'name':task.name,'pdbid':'1IGD','md_start':'pdbstart',
+        'md_pdbref':True,'md_temp':250}
+        form = TaskForm_md(initial=data)     
+     else:
         form = TaskForm_md(request.POST,request.FILES)
         if form.is_valid():
              task.name=form.cleaned_data["name"]
@@ -221,8 +239,19 @@ 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.myfile1=form.cleaned_data["file1"]
+
+             basename = str(task.owner)
+             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
+             task.jobdirname = "_".join([basename, suffix])
+
+             pdbid=form.cleaned_data["pdbid"]
+             if pdbid:
+              os.mkdir(task.jobdirname)
+              task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb',
+                     task.jobdirname+'/plik.pdb')     
+              task.pdbcode=pdbid
+             else:
+              task.myfile1=form.cleaned_data["file1"]
              task.md_pdbref=form.cleaned_data["md_pdbref"]             
 
              task.md_seq=""
@@ -238,9 +267,6 @@ def add_md(request,task_id):
                 task.ssbond=''
 
              task.ready=True
-             basename = str(task.owner)
-             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
-             task.jobdirname = "_".join([basename, suffix])
              
              task.save()
              if is_lazy_user(request.user):
@@ -258,12 +284,28 @@ def add_md(request,task_id):
 def add_md_a(request,task_id):
     task = get_object_or_404(Task, id=task_id)
     if request.method == 'POST':
+     if '_example' in request.POST:
+        data= {'name':task.name,'pdbid':'1FSD','md_start':'extconf',
+         'md_pdbref':True,'md_lang':'berendsen'}
+        form = TaskForm_md_a(initial=data)     
+     else:
         form = TaskForm_md_a(request.POST,request.FILES)
         if form.is_valid():
              task.name=form.cleaned_data["name"]
              task.type="md"
 
-             task.myfile1=form.cleaned_data["file1"]
+             basename = str(task.owner)
+             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
+             task.jobdirname = "_".join([basename, suffix])
+
+             pdbid=form.cleaned_data["pdbid"]
+             if pdbid:
+              os.mkdir(task.jobdirname)
+              task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb',
+                     task.jobdirname+'/plik.pdb')     
+              task.pdbcode=pdbid
+             else:
+              task.myfile1=form.cleaned_data["file1"]
              task.md_start=form.cleaned_data["md_start"]
              task.md_pdbref=form.cleaned_data["md_pdbref"]             
 
@@ -296,9 +338,6 @@ def add_md_a(request,task_id):
 
              
              task.ready=True
-             basename = str(task.owner)
-             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
-             task.jobdirname = "_".join([basename, suffix])
              
              task.save()
              if is_lazy_user(request.user):
@@ -316,12 +355,28 @@ def add_md_a(request,task_id):
 def add_remd(request,task_id):
     task = get_object_or_404(Task, id=task_id)
     if request.method == 'POST':
+     if '_example' in request.POST:
+        data= {'name':task.name,'pdbid':'1L2Y','md_pdbref':True}
+        form = TaskForm_remd(initial=data)     
+     else:
         form = TaskForm_remd(request.POST,request.FILES)
         if form.is_valid():
              task.name=form.cleaned_data["name"]
              task.type="remd"
              task.md_start=form.cleaned_data["md_start"]
-             task.myfile1=form.cleaned_data["file1"]
+
+             basename = str(task.owner)
+             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
+             task.jobdirname = "_".join([basename, suffix])
+
+             pdbid=form.cleaned_data["pdbid"]
+             if pdbid:
+              os.mkdir(task.jobdirname)
+              task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb',
+                     task.jobdirname+'/plik.pdb')     
+              task.pdbcode=pdbid
+             else:
+              task.myfile1=form.cleaned_data["file1"]
              task.md_pdbref=form.cleaned_data["md_pdbref"]
              task.md_ntwx=task.remd_nstex 
 
@@ -343,9 +398,6 @@ def add_remd(request,task_id):
 
              task.ready=True
              
-             basename = str(task.owner)
-             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
-             task.jobdirname = "_".join([basename, suffix])
              
              task.save()
              if is_lazy_user(request.user):
@@ -363,12 +415,28 @@ def add_remd(request,task_id):
 def add_remd_a(request,task_id):
     task = get_object_or_404(Task, id=task_id)
     if request.method == 'POST':
+     if '_example' in request.POST:
+        data= {'name':task.name,'pdbid':'1E0G','md_pdbref':True,
+         'md_nstep':500000,'md_lang':'berendsen','unres_ff':'opt-wtfsa-2'}
+        form = TaskForm_remd_a(initial=data)     
+     else:
         form = TaskForm_remd_a(request.POST,request.FILES)
         if form.is_valid():
              task.name=form.cleaned_data["name"]
              task.type="remd"
 
-             task.myfile1=form.cleaned_data["file1"]
+             basename = str(task.owner)
+             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
+             task.jobdirname = "_".join([basename, suffix])
+
+             pdbid=form.cleaned_data["pdbid"]
+             if pdbid:
+              os.mkdir(task.jobdirname)
+              task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb',
+                     task.jobdirname+'/plik.pdb')     
+              task.pdbcode=pdbid
+             else:
+              task.myfile1=form.cleaned_data["file1"]
              task.md_start=form.cleaned_data["md_start"]  
              task.md_pdbref=form.cleaned_data["md_pdbref"]                        
 
@@ -400,14 +468,9 @@ def add_remd_a(request,task_id):
              task.boxy=form.cleaned_data["boxy"]             
              task.boxz=form.cleaned_data["boxz"]             
 
-
              task.remd_cluter_temp=form.cleaned_data["remd_cluter_temp"]
              task.unres_ff=form.cleaned_data["unres_ff"]
              
-             basename = str(task.owner)
-             suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S")
-             task.jobdirname = "_".join([basename, suffix])
-             
              task.save()
              return redirect('addmlist',task_id=task.id)
     else: