X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=blobdiff_plain;f=django_simple%2Ftodo%2Fviews.py;h=f545f1e286f0bd164532a56e926277c2d25ee096;hb=53f1728daa2b4d8d67349c048822ccd04e819d48;hp=2d888e21e8d8bd780e0c38c931e7c1769f590f6a;hpb=24edb3b7df05bb07af2ab27ecffe328640be618f;p=django_unres.git diff --git a/django_simple/todo/views.py b/django_simple/todo/views.py index 2d888e2..f545f1e 100644 --- a/django_simple/todo/views.py +++ b/django_simple/todo/views.py @@ -6,6 +6,7 @@ from .models import Task import datetime import os import subprocess +import json res_codes = [ # 20 canonical amino acids @@ -34,18 +35,47 @@ def seq_add_x(sequence): def from_pdb(file): sequence = [] ssbond = [] + ssbond_ch = [] + ires = [] + chain_start = {} + chain_end = {} + unres_shift = {} + chain=[] + ichain=0 + newchain = True + for line in file: + if line[0:6] == 'COMPND' and line[11:17] == 'CHAIN:': + tmp=line[18:] + chain_=tmp.split(', ') + chain_[-1]=chain_[-1][0] + chain.extend(chain_) + if line[0:6] == 'ATOM ' and line[13:15] == 'CA': aa = three_to_one.get(line[17:20]) - sequence.append(aa) + i = int(line[22:26]) + if newchain or i!=ires[-1]: + sequence.append(aa) + ires.append(i) + if newchain: + if len(chain)>0: + chain_start[chain[ichain]]=i + newchain = False if line[0:3] == 'TER': sequence.append('XX') + if len(chain)>0: + chain_end[chain[ichain]]=i + ichain=ichain+1 + newchain = True if line[0:6] == 'SSBOND': b=[] b.append(int(line[17:21])) b.append(int(line[31:35])) ssbond.append(b) - + c = [] + c.append((line[15:16])) + c.append((line[29:30])) + ssbond_ch.append(c) if line[0:3] == 'END': break while sequence[-1] == 'XX': @@ -56,13 +86,21 @@ def from_pdb(file): if sequence[-1] != 'G': sequence.append('X') seq=''.join(sequence) - return seq,ssbond +# if ires[0] != 1: +# ssbond=[ [e[0]-ires[0]+1,e[1]-ires[0]+1] for e in ssbond] + i=0 + for c in chain: + unres_shift[c]=i+chain_start[c] + i=i-(chain_end[c]-chain_start[c])-3 + ssbond=[ [e[0]-unres_shift[c[0]]+1,e[1]-unres_shift[c[1]]+1] for e,c in zip(ssbond,ssbond_ch)] + + return seq,json.dumps(ssbond) @login_required def index(request): user = request.user - tasks = Task.objects.filter(owner=user) + tasks = Task.objects.filter(owner=user).order_by('-created_date') variable = '' return render(request, "index.html", { 'tasks': tasks @@ -125,6 +163,7 @@ def add_min_a(request,task_id): task.min_pdbout=form.cleaned_data["min_pdbout"] task.myfile1=form.cleaned_data["file1"] task.min_unres_pdb=form.cleaned_data["min_unres_pdb"] + task.unres_ff=form.cleaned_data["unres_ff"] seq,task.ssbond=from_pdb(task.myfile1) task.md_seq="" @@ -222,7 +261,7 @@ def add_md_a(request,task_id): task.md_tau=form.cleaned_data["md_tau"] task.md_scal_fric=form.cleaned_data["md_scal_fric"] task.md_mdpdb=form.cleaned_data["md_mdpdb"] - + task.unres_ff=form.cleaned_data["unres_ff"] task.ready=True basename = str(task.owner) @@ -249,6 +288,7 @@ def add_remd(request,task_id): task.md_start=form.cleaned_data["md_start"] task.myfile1=form.cleaned_data["file1"] task.md_pdbref=form.cleaned_data["md_pdbref"] + task.md_ntwx=task.remd_nstex task.md_seq="" if task.md_start == "pdbstart" or task.md_pdbref: @@ -312,10 +352,13 @@ def add_remd_a(request,task_id): task.md_scal_fric=form.cleaned_data["md_scal_fric"] task.remd_nrep=form.cleaned_data["remd_nrep"] task.remd_nstex=form.cleaned_data["remd_nstex"] + task.md_ntwx=form.cleaned_data["md_ntwx"] + task.md_ntwe=form.cleaned_data["md_ntwe"] # task.remd_traj1file=form.cleaned_data["remd_traj1file"] # task.remd_rest1file=form.cleaned_data["remd_rest1file"] task.remd_cluter_temp=form.cleaned_data["remd_cluter_temp"] + task.unres_ff=form.cleaned_data["unres_ff"] basename = str(task.owner) suffix = datetime.datetime.now().strftime("%y%m%d_%H%M%S") @@ -365,7 +408,7 @@ def delete(request, task_id): @login_required def refresh_done(request): user = request.user - tasks = Task.objects.filter(owner=user) + tasks = Task.objects.filter(owner=user).order_by('-created_date') for task in tasks: if os.path.isfile(task.jobdirname+'/finished') and not task.done: task.done=True @@ -410,6 +453,7 @@ def refresh_done(request): if task.md_pdbref and task.type=='remd': for i in range(1,6): + try: with open(task.jobdirname+'/file_wham_T'+str(int(task.remd_cluter_temp))+'K_000'+str(i)+'.pdb', 'r') as f: line=f.readline() if i==1: @@ -422,7 +466,8 @@ def refresh_done(request): task.remd_model4=' '.join(line.split()[-6:]) elif i==5: task.remd_model5=' '.join(line.split()[-6:]) - + except EnvironmentError: + print 'file_wham_T*pdb open error' for i in range(1,6): with open(task.jobdirname+'/tmscore'+str(i)+'.out', 'r') as f: text=''