From e86b92f83ec41f47f7592d8f3efb7123a122ea90 Mon Sep 17 00:00:00 2001 From: Cezary Czaplewski Date: Mon, 20 Nov 2017 19:44:30 +0100 Subject: [PATCH] use pdbid to load pdb and set example input test using min only --- django_simple/todo/forms.py | 27 ++++++++++++++++++++++++--- django_simple/todo/models.py | 1 + django_simple/todo/templates/details.html | 4 ++++ django_simple/todo/templates/edit.html | 1 + django_simple/todo/views.py | 21 +++++++++++++++++---- 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/django_simple/todo/forms.py b/django_simple/todo/forms.py index 7ca4ce3..c8d2671 100644 --- a/django_simple/todo/forms.py +++ b/django_simple/todo/forms.py @@ -5,6 +5,8 @@ from .models import MD_START from .models import MD_LANG from .models import FF_CHOICE import json +import urllib + class MultiWidgetBasic(forms.MultiWidget): def __init__(self, count, attrs=None): @@ -43,9 +45,28 @@ class TaskForm(forms.Form): class TaskForm_min(forms.Form): name = forms.CharField(max_length=20) - file1 = forms.FileField(label='Upload a PDB file', - help_text='continuous (without breaks) protein chains,use TER to divide chains') - + 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') + + def clean(self): + cleaned_data = super(TaskForm_min, 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_min_a(forms.Form): name = forms.CharField(max_length=20) diff --git a/django_simple/todo/models.py b/django_simple/todo/models.py index c377e48..e74eca0 100644 --- a/django_simple/todo/models.py +++ b/django_simple/todo/models.py @@ -30,6 +30,7 @@ class Task(models.Model): # return json.loads(self.ssbond) unres_ff = models.CharField(max_length=20,choices=FF_CHOICE,default='E0LL2Y') + pdbcode = models.CharField(max_length=4,default='') # minimization min_choice = models.CharField(max_length=20,choices=MIN_CHOICE,default='minimize cart') min_overlap = models.BooleanField(default=False) diff --git a/django_simple/todo/templates/details.html b/django_simple/todo/templates/details.html index fcfb8d4..3945f84 100644 --- a/django_simple/todo/templates/details.html +++ b/django_simple/todo/templates/details.html @@ -108,6 +108,10 @@ Created {{ task.created_date }}
{{ task.myfile1 }}
  • +
    pdb code
    +
    {{ task.pdbcode }}
    +
  • +
  • unres_pdb
    {{ task.min_unres_pdb }}
  • diff --git a/django_simple/todo/templates/edit.html b/django_simple/todo/templates/edit.html index c1ab55c..90cec38 100644 --- a/django_simple/todo/templates/edit.html +++ b/django_simple/todo/templates/edit.html @@ -76,6 +76,7 @@ Calculation type {{ p_type }} {{ form.as_table }} + diff --git a/django_simple/todo/views.py b/django_simple/todo/views.py index 521a300..df3fb4d 100644 --- a/django_simple/todo/views.py +++ b/django_simple/todo/views.py @@ -124,11 +124,27 @@ def add(request): def add_min(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':'1BDD'} + form = TaskForm_min(initial=data) + else: form = TaskForm_min(request.POST,request.FILES) if form.is_valid(): task.name=form.cleaned_data["name"] task.type="min" - task.myfile1=form.cleaned_data["file1"] + pdbid=form.cleaned_data["pdbid"] + + basename = str(task.owner) + suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S") + task.jobdirname = "_".join([basename, suffix]) + + 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"] seq,task.ssbond=from_pdb(task.myfile1) task.md_seq="" @@ -136,9 +152,6 @@ def add_min(request,task_id): 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): -- 1.7.9.5