From: Cezary Czaplewski Date: Mon, 22 Jan 2018 22:31:18 +0000 (+0100) Subject: pdbid:chain added X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=commitdiff_plain;h=eeae2b9c6d4e5ed6710a03adef882ab09ba4a5f3;p=django_unres.git pdbid:chain added --- diff --git a/django_simple/todo/forms.py b/django_simple/todo/forms.py index e87cdcc..6d47368 100644 --- a/django_simple/todo/forms.py +++ b/django_simple/todo/forms.py @@ -7,6 +7,52 @@ from .models import FF_CHOICE import json import urllib +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' and (line[21] == chain or chain==''): + i = int(line[22:26]) + ch = line[21] + 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)+' 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: + msg='wrong chain id' + return(msg) + + def code_2d(line): msg='' set ='HEC-' @@ -78,9 +124,9 @@ class TaskForm_min(forms.Form): name = forms.CharField(max_length=20) 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() @@ -93,15 +139,9 @@ 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) @@ -123,9 +163,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)') @@ -148,15 +188,9 @@ 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) @@ -176,9 +210,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') @@ -210,15 +244,9 @@ 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) @@ -245,9 +273,9 @@ class TaskForm_md_a(forms.Form): 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') @@ -301,15 +329,9 @@ 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) @@ -333,9 +355,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') @@ -364,15 +386,9 @@ 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) @@ -398,9 +414,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') + 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') @@ -470,15 +486,9 @@ 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) diff --git a/django_simple/todo/models.py b/django_simple/todo/models.py index 2103d7f..bc2fac6 100644 --- a/django_simple/todo/models.py +++ b/django_simple/todo/models.py @@ -30,7 +30,7 @@ class Task(models.Model): # return json.loads(self.ssbond) unres_ff = models.CharField(max_length=20,choices=FF_CHOICE,default='FF2') - pdbcode = models.CharField(max_length=4,default='') + pdbcode = models.CharField(max_length=6,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/views.py b/django_simple/todo/views.py index 3d959f1..7045a7c 100644 --- a/django_simple/todo/views.py +++ b/django_simple/todo/views.py @@ -29,6 +29,27 @@ res_codes = [ three_to_one = dict(res_codes) +def load_pdbid(pdbid,dirname): + os.mkdir(dirname) + if len(pdbid)==4: + file,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', + dirname+'/plik.pdb') + else: + chain=pdbid[5] + pdbid=pdbid[:4] + pdb_tmp=urllib.urlopen('http://files.rcsb.org/download/'+pdbid+'.pdb') + with open(dirname+'/plik.pdb', 'w') as outfile: + for line in pdb_tmp: + if line[0:6] == 'SSBOND' and line[15] == chain and line[29] == chain: + outfile.write(line) + if line[0:6] == 'ATOM ' and line[21] == chain: + outfile.write(line) + pdb_tmp.close() + file=dirname+'/plik.pdb' + + return(file) + + def seq_2d_from_pdb(seq_2d,seq): if seq_2d =='': return(seq_2d) @@ -171,9 +192,7 @@ def add_min(request,task_id): 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.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"] @@ -222,9 +241,7 @@ def add_min_a(request,task_id): pdbid=form.cleaned_data["pdbid"] if pdbid: - os.mkdir(task.jobdirname) - task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', - task.jobdirname+'/plik.pdb') + task.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"] @@ -278,9 +295,7 @@ def add_md(request,task_id): pdbid=form.cleaned_data["pdbid"] if pdbid: - os.mkdir(task.jobdirname) - task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', - task.jobdirname+'/plik.pdb') + task.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"] @@ -332,9 +347,7 @@ def add_md_a(request,task_id): pdbid=form.cleaned_data["pdbid"] if pdbid: - os.mkdir(task.jobdirname) - task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', - task.jobdirname+'/plik.pdb') + task.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"] @@ -407,9 +420,7 @@ def add_remd(request,task_id): pdbid=form.cleaned_data["pdbid"] if pdbid: - os.mkdir(task.jobdirname) - task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', - task.jobdirname+'/plik.pdb') + task.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"] @@ -512,9 +523,7 @@ def add_remd_a(request,task_id): pdbid=form.cleaned_data["pdbid"] if pdbid: - os.mkdir(task.jobdirname) - task.myfile1,header=urllib.urlretrieve('http://files.rcsb.org/download/'+pdbid+'.pdb', - task.jobdirname+'/plik.pdb') + task.myfile1=load_pdbid(pdbid,task.jobdirname) task.pdbcode=pdbid else: task.myfile1=form.cleaned_data["file1"]