long job names (40 char) no respa for D amino
[django_unres.git] / django_simple / todo / forms.py
index 8fda381..c279f08 100644 (file)
@@ -7,13 +7,43 @@ from .models import FF_CHOICE
 import json
 import urllib
 
-def pdb_missing_res(file):
+aa_3letter = [
+     'DPR','DLY','DAR','DHI','DAS','DGL','DSG','DGN','DSN','DTH',
+     'DAL','DTY','DTR','DVA','DLE','DIL','DPN','MED','DCY',
+     'CYS','MET','PHE','ILE','LEU','VAL','TRP','TYR','ALA','GLY','THR',
+     'SER','GLN','ASN','GLU','ASP','HIS','ARG','LYS','PRO',
+     'SME','AIB','ABU','DBZ']
+
+
+def pdb_code_chain(pdbid):
+
+    msg=''
+    chain=''
+    if len(pdbid)>4:
+       if pdbid[4]!=':':
+         return('use : between pdb code and chain id, like 5G3Q:B to select single chain')
+       chain=pdbid[5]
+       pdbid=pdbid[:4]    
+    
+    test=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb')     
+    if test.code != 200:
+          msg = 'wrong pdb code'
+    else:
+          msg=pdb_missing_res_chain(test,chain)
+    test.close()
+    return(msg)
+
+def pdb_missing_res_chain(file,chain):
    msg=''
    newchain = True
    ires=[]
    for line in file:
-      if line[0:6] == 'ATOM  ' and line[13:15] == 'CA':
+      if line[0:6] == 'ATOM  ' and line[13:15] == 'CA' and (line[21] == chain or chain==''):
                i = int(line[22:26])
+               ch = line[21]
+               if line[17:20] not in aa_3letter:
+                 msg='residue '+line[17:20]+' '+str(i)+' not recognized'
+                 return(msg)
                if ires and i==ires[-1]:
                  continue
                if newchain or i==ires[-1]+1:
@@ -21,16 +51,31 @@ def pdb_missing_res(file):
                  newchain = False
                else:
                  msg = 'chain breaks between residues '+\
-                   str(ires[-1])+' and '+str(i)+\
-                   ', server cannot add missing residues to PDB file'
+                   str(ires[-1])+' and '+str(i)+' of chain '+ch+\
+                   ', 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
    
+   if len(ires) == 0:
+        if chain == '':
+               msg='no CA atoms in this pdb'
+        else:
+               msg='wrong chain id'
    return(msg)
 
+
+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)
+
+
 class MultiWidgetBasic(forms.MultiWidget):
     def __init__(self, count, attrs=None):
         self.count=count
@@ -63,16 +108,16 @@ class MultiExampleField(forms.fields.MultiValueField):
 
 
 class TaskForm(forms.Form):
-    name = forms.CharField(max_length=20)
+    name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
 
 class TaskForm_min(forms.Form):
-     name = forms.CharField(max_length=20)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
      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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
 
      def clean(self):
              cleaned_data = super(TaskForm_min, self).clean()
@@ -85,28 +130,22 @@ class TaskForm_min(forms.Form):
                 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 != '':
+               msg=pdb_code_chain(pdbid)
+               if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
             
 class TaskForm_min_a(forms.Form):
-     name = forms.CharField(max_length=20)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
      unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
-                           label='Force Field',initial='E0LL2Y')
-     min_choice = forms.ChoiceField(choices=MIN_CHOICE,label='minimization algorithm')
+                           label='Force Field',initial='FF2')
+#     min_choice = forms.ChoiceField(choices=MIN_CHOICE,label='minimization algorithm')
      min_overlap = forms.BooleanField(required=False,label='remove overlap')
      min_searchsc = forms.BooleanField(required=False,label='MC for sidechain overlap')
      min_maxmin = forms.IntegerField(label='MAXMIN',initial=10000,
@@ -115,9 +154,9 @@ class TaskForm_min_a(forms.Form):
                   help_text='maximum number of function evaluations')
      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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
 
      min_unres_pdb = forms.BooleanField(required=False,label='uploaded input unres PDB',
                   help_text='(CA and CB atoms only, CB represents SC in UNRES)')
@@ -140,24 +179,18 @@ class TaskForm_min_a(forms.Form):
                 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)
+                 msg=pdb_code_chain(pdbid)
                  if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
 
 class TaskForm_md(forms.Form):
-     name = forms.CharField(max_length=20)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
      md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
                       label='starting structure',initial='extconf')
@@ -168,9 +201,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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')
      md_temp = forms.FloatField(label='temperature',initial=300,
                   help_text='bath temperature')
@@ -202,27 +235,21 @@ class TaskForm_md(forms.Form):
                 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)
+                 msg=pdb_code_chain(pdbid)
                  if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
                         
 class TaskForm_md_a(forms.Form):
-     name = forms.CharField(max_length=20)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
      unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
-                           label='Force Field',initial='E0LL2Y')
+                           label='Force Field',initial='FF2')
      md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
                       label='starting structure',initial='extconf')
      md_seq = forms.CharField(label='Sequence',
@@ -230,11 +257,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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_temp = forms.FloatField(label='temperature',initial=300,
                   help_text='bath temperature')
@@ -248,12 +280,13 @@ class TaskForm_md_a(forms.Form):
      md_ntwx = forms.IntegerField(label='NTWX',initial=1000,
                help_text='write trajectory every ntwe steps')
      md_dt = forms.FloatField(label='DT',initial=0.2,
-                  help_text='time step [mtu]')
+                  help_text='time step [mtu=48.9 fs]')
      md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
      md_tau = forms.FloatField(label='tau_bath',initial=1.0,
                   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,
@@ -271,6 +304,7 @@ class TaskForm_md_a(forms.Form):
              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 or pdbid):
                 msg = 'pdbstart with no PDB file or code'
@@ -286,24 +320,22 @@ class TaskForm_md_a(forms.Form):
                 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)
+                 msg=pdb_code_chain(pdbid)
                  if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(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)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
      md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
                       label='starting structure',initial='extconf')
@@ -314,9 +346,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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
                   help_text='total number of steps')
@@ -345,27 +377,21 @@ class TaskForm_remd(forms.Form):
                 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)
+                 msg=pdb_code_chain(pdbid)
                  if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
                              
 class TaskForm_remd_a(forms.Form):
-     name = forms.CharField(max_length=20)
+     name = forms.CharField(max_length=40,widget=forms.TextInput(attrs={'size':40, 'maxlength':40}))
 
      unres_ff = forms.ChoiceField(choices=FF_CHOICE,widget=forms.RadioSelect,
-                           label='Force Field',initial='E0LL2Y')
+                           label='Force Field',initial='FF2')
      md_start = forms.ChoiceField(choices=MD_START,widget=forms.RadioSelect,
                       label='starting structure',initial='extconf')
      md_seq = forms.CharField(label='Sequence',
@@ -373,11 +399,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')                   
+     pdbid = forms.CharField(min_length=4,max_length=6,required=False,
+      widget=forms.TextInput(attrs={'size':6, 'maxlength':6, 'title':'PDB code or PDB code:chain id'}),
+      label='or PDB code (:chain)')                   
      md_pdbref = forms.BooleanField(required=False,label='PDB reference structure')                  
      md_nstep = forms.IntegerField(label='NSTEP',initial=200000,
                   help_text='total number of steps')
@@ -386,12 +416,15 @@ class TaskForm_remd_a(forms.Form):
      md_ntwe = forms.IntegerField(label='NTWE',initial=1000,
                help_text='write statfile every ntwe steps')
      md_dt = forms.FloatField(label='DT',initial=0.2,
-                  help_text='time step [mtu]')
+                  help_text='time step [mtu = 48.9 fs]')
      md_lang = forms.ChoiceField(choices=MD_LANG,label='thermostat')
      md_tau = forms.FloatField(label='tau_bath',initial=1.0,
                   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)')
+     min_maxfun = forms.IntegerField(label='MAXFUN',initial=5000,
+                  help_text='preminim maximum number of function evaluations<br>'+
+                  'used for start from pdb or random start')
      remd_nrep = forms.IntegerField(label='NREP',initial=8,
                   help_text='number of replicas')
      remd_nstex = forms.IntegerField(label='NSTEX',initial=1000,
@@ -403,6 +436,8 @@ 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')
 
+     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,
@@ -411,6 +446,16 @@ class TaskForm_remd_a(forms.Form):
                        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()
 
@@ -419,6 +464,7 @@ class TaskForm_remd_a(forms.Form):
              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 or pdbid):
                 msg = 'pdbstart with no PDB file or code'
@@ -434,25 +480,24 @@ class TaskForm_remd_a(forms.Form):
                 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)
+                 msg=pdb_code_chain(pdbid)
                  if msg != '':
                    self.add_error('pdbid',msg)
-               test.close()
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(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)
+    name = forms.CharField(max_length=40,disabled=True,required=False)
     nrep = forms.IntegerField(disabled=True,required=False,label='NREP')
 
     def __init__(self, count, *args, **kwargs):