X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=django_simple%2Ftodo%2Fforms.py;h=bfbd0945fbde8d785b4f4abc321d6d8f27d4b0a5;hb=0f5d683edc824468ab5da53d015b39e91fe2766d;hp=beff5825bbacd66e6f25fa58d1e5d0c8417b50bc;hpb=6fb77f4e05910e0a6682df3f0bbc72af8776988d;p=django_unres.git diff --git a/django_simple/todo/forms.py b/django_simple/todo/forms.py index beff582..bfbd094 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) @@ -59,12 +80,38 @@ 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)') min_pdbout = forms.BooleanField(required=False,label='output PDB',initial='true') + boxx = forms.FloatField(label='Box X',initial=1000.0, + help_text='box x dimension') + boxy = forms.FloatField(label='Box Y',initial=1000.0, + help_text='box y dimension') + 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): @@ -79,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') @@ -92,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) @@ -108,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) @@ -123,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') @@ -144,20 +205,28 @@ class TaskForm_md_a(forms.Form): help_text='scaling of the friction coefficients (Langevin)') md_mdpdb = forms.BooleanField(required=False,label='trajectory as PDB') + boxx = forms.FloatField(label='Box X',initial=1000.0, + help_text='box x dimension') + boxy = forms.FloatField(label='Box Y',initial=1000.0, + help_text='box y dimension') + boxz = forms.FloatField(label='Box Z',initial=1000.0, + help_text='box z dimension') + def clean(self): cleaned_data = super(TaskForm_md_a, self).clean() 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) @@ -165,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) @@ -178,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') @@ -189,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) @@ -219,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') @@ -244,20 +334,29 @@ class TaskForm_remd_a(forms.Form): # remd_traj1file = forms.BooleanField(required=False,label='single trajectory file',initial='true') # remd_rest1file = forms.BooleanField(required=False,label='single restart file',initial='true') + boxx = forms.FloatField(label='Box X',initial=1000.0, + help_text='box x dimension') + boxy = forms.FloatField(label='Box Y',initial=1000.0, + help_text='box y dimension') + boxz = forms.FloatField(label='Box Z',initial=1000.0, + help_text='box z dimension') + + def clean(self): cleaned_data = super(TaskForm_remd_a, self).clean() 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) @@ -265,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)