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-'
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()
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)
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)')
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)
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')
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)
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')
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)
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')
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)
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')
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)
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)
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"]
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"]
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"]
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"]
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"]
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"]