X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=django_simple%2Ftodo%2Fforms.py;h=c0b16674c71c0d85a51d89389083242d888c214b;hb=a6e111e381a874bd15dd6dcb33fdeb18079e3286;hp=987887b56306a1ef1ba1b359405d1ebca968cb72;hpb=533934d3ce690cbee495617d193c7560960e55d5;p=django_unres.git diff --git a/django_simple/todo/forms.py b/django_simple/todo/forms.py index 987887b..c0b1667 100644 --- a/django_simple/todo/forms.py +++ b/django_simple/todo/forms.py @@ -5,6 +5,39 @@ from .models import MD_START from .models import MD_LANG from .models import FF_CHOICE import json +import urllib + +def code_2d(line): + msg='' + set ='HEC-' + line2 = ''.join([c for c in line if c in set]) + if line2 != line: + msg='use only H,E,C or - letters' + return(msg) + +def pdb_missing_res(file): + msg='' + newchain = True + ires=[] + for line in file: + if line[0:6] == 'ATOM ' and line[13:15] == 'CA': + i = int(line[22:26]) + if ires and i==ires[-1]: + continue + if newchain or i==ires[-1]+1: + ires.append(i) + newchain = False + else: + msg = 'chain breaks between residues '+\ + str(ires[-1])+' and '+str(i)+\ + ', server cannot add missing residues to PDB file - please repair the structure using e.g. Modeller' + break + if line[0:3] == 'TER': + newchain = True + if line[0:3] == 'END': + break + + return(msg) class MultiWidgetBasic(forms.MultiWidget): def __init__(self, count, attrs=None): @@ -43,9 +76,38 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) + class TaskForm_min_a(forms.Form): name = forms.CharField(max_length=20) @@ -59,12 +121,47 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) class TaskForm_md(forms.Form): @@ -79,6 +176,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 +192,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 +209,22 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) + class TaskForm_md_a(forms.Form): name = forms.CharField(max_length=20) @@ -121,8 +238,16 @@ class TaskForm_md_a(forms.Form): 'field is ignored when uploading starting/reference PDB file', required=False, widget=forms.Textarea(attrs={'cols': 70, 'rows': 2})) + md_2d = forms.CharField(label='Secondary structure restraints', + help_text='single letter code: H - helix, E - extended/beta, C or - no restraints', + required=False, + 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') @@ -142,22 +267,32 @@ class TaskForm_md_a(forms.Form): help_text='coupling to the thermal bath (Berendsen)') md_scal_fric = forms.FloatField(label='scal_froc',initial=0.02, help_text='scaling of the friction coefficients (Langevin)') + md_respa = forms.BooleanField(required=False,initial=True,label='RESPA') 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") + md_2d = cleaned_data.get("md_2d") - 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 +300,26 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) + + if md_2d: + msg=code_2d(md_2d) + if msg != '': + self.add_error('md_2d',msg) class TaskForm_remd(forms.Form): name = forms.CharField(max_length=20) @@ -178,6 +333,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 +347,38 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) + class TaskForm_remd_a(forms.Form): name = forms.CharField(max_length=20) @@ -217,8 +392,15 @@ class TaskForm_remd_a(forms.Form): 'field is ignored when uploading starting/reference PDB file', required=False, widget=forms.Textarea(attrs={'cols': 70, 'rows': 2})) + md_2d = forms.CharField(label='Secondary structure restraints', + help_text='single letter code: H - helix, E - extended/beta, C or - no restraints', + required=False, + 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') @@ -237,25 +419,49 @@ class TaskForm_remd_a(forms.Form): help_text='number of replicas') remd_nstex = forms.IntegerField(label='NSTEX',initial=1000, help_text='exchange and write trajectory every nstex steps') + md_ntwx = forms.IntegerField(label='NTWX',initial=1000, + help_text='write trajectory every ntwx steps') remd_cluter_temp = forms.FloatField(label='TEMPER', help_text='temperature for cluster analysis',initial=280) # remd_traj1file = forms.BooleanField(required=False,label='single trajectory file',initial='true') # remd_rest1file = forms.BooleanField(required=False,label='single restart file',initial='true') + md_respa = forms.BooleanField(required=False,initial=True,label='RESPA') + + 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') + + + wsaxs = forms.FloatField(label='SAXS weight',initial=100.0, + help_text='weight for SAXS restraint term') + scal_rad = forms.FloatField(label='Scal_rad (SAXS)',initial=1.0, + help_text='downscaling factor of residue radii used in SAXS restraints') + saxs_data = forms.CharField(label='P(r) SAXS data', + help_text='distance distribution from SAXS, two columns: r and P(r)', + required=False, + widget=forms.Textarea(attrs={'cols': 25, 'rows': 20})) + + 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") + md_2d = cleaned_data.get("md_2d") - 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) @@ -263,6 +469,28 @@ 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) + else: + msg=pdb_missing_res(test) + if msg != '': + self.add_error('pdbid',msg) + test.close() + + if file1: + msg=pdb_missing_res(file1) + if msg != '': + self.add_error('file1',msg) + + if md_2d: + msg=code_2d(md_2d) + if msg != '': + self.add_error('md_2d',msg) + + class TaskForm_list(forms.Form): name = forms.CharField(max_length=20,disabled=True,required=False)