T0882 example in advanced MREMD, checking of residue names in pdb
[django_unres.git] / django_simple / todo / forms.py
index 6d47368..22aef8d 100644 (file)
@@ -7,6 +7,13 @@ from .models import FF_CHOICE
 import json
 import urllib
 
+aa_3letter = [
+     'DPR','DLY','DAR','DHI','DAS','DGL','DSG','DGN','DSN','DTH',
+     'DYY','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']
+
+
 def pdb_code_chain(pdbid):
 
     msg=''
@@ -33,6 +40,9 @@ def pdb_missing_res_chain(file,chain):
       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:
@@ -49,6 +59,9 @@ def pdb_missing_res_chain(file,chain):
                break
    
    if len(ires) == 0:
+        if chain == '':
+               msg='no CA atoms in this pdb'
+        else:
                msg='wrong chain id'
    return(msg)
 
@@ -61,29 +74,6 @@ def code_2d(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):
@@ -144,7 +134,7 @@ class TaskForm_min(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
@@ -193,7 +183,7 @@ class TaskForm_min_a(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
@@ -249,7 +239,7 @@ class TaskForm_md(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
@@ -334,7 +324,7 @@ class TaskForm_md_a(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
              
@@ -391,7 +381,7 @@ class TaskForm_remd(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)
 
@@ -491,7 +481,7 @@ class TaskForm_remd_a(forms.Form):
                    self.add_error('pdbid',msg)
                
              if file1:
-                 msg=pdb_missing_res(file1)
+                 msg=pdb_missing_res_chain(file1,'')
                  if msg != '':
                    self.add_error('file1',msg)