From: Cezary Czaplewski Date: Mon, 10 May 2021 09:28:01 +0000 (+0200) Subject: Rafal's code for NMR restraints X-Git-Url: http://mmka.chem.univ.gda.pl/gitweb/?a=commitdiff_plain;h=1b9e4cd5192fafe2213b582fadd19556fb2ecf3a;p=django_unres.git Rafal's code for NMR restraints --- diff --git a/django_simple/todo/forms.py b/django_simple/todo/forms.py index 74779e2..c857602 100644 --- a/django_simple/todo/forms.py +++ b/django_simple/todo/forms.py @@ -5,6 +5,9 @@ from .models import MD_START from .models import MD_LANG from .models import FF_CHOICE from django.utils.safestring import mark_safe +#---v +from django.core.files import File +#---^ import json import urllib @@ -67,6 +70,36 @@ def pdb_missing_res_chain(file,chain): msg='wrong chain id' return(msg) +#---v +def nmr_bad_cols(file): + msg='' + for line in file: + line=line.rstrip() + if line: + data = line.split() + for x in (0, 1, 2): + lg = data[x].isdigit() + if not lg: + msg = 'NMR shifts data column '+repr(x+1)+' must be integer, not: '+data[x] + return(msg) + dlug = len(data) + if (dlug < 5): + msg = 'There have to be 5 or more columns in NMR shifts data file' + return(msg) + promien = data[3].replace('.', '') + lg2 = promien.isdigit() + if not lg2: + msg ='NMR shifts 4th data column must be decimal or integer radius, not: '+data[3] + return(msg) + lg3 = data[4].startswith('H') or data[4].startswith('Q') + if not lg3: + msg = 'NMR shifts 5th data column must be proton designation, not: '+data[4] + return(msg) + else: + msg = 'NMR shifts data contains blank lines. Remove them.' + return(msg) +#---^ + def code_2d(line): msg='' @@ -263,8 +296,17 @@ class TaskForm_md_a(forms.Form): required=False, widget=forms.Textarea(attrs={'cols': 70, 'rows': 2})) +#---v + use_nmr = forms.BooleanField(required=False,label='use NMR restraints', + help_text='this option requires the next four fields to be set.') + file3 = forms.FileField(label='Upload a NMR restraints file',required=False, + help_text='at least 5 columns required: 49 22 1 5.0 HD2 H; Hint: if you are using NMR example data then the field will be filled out automatically') + nmr_scal = forms.IntegerField(label='NMR option: scal_peak',initial=20) + nmr_fordepth = forms.FloatField(label='NMR option: FORDEPTH_PEAK',initial=0.5) + nmr_slope = forms.FloatField(label='NMR option: SLOPE_PEAK',initial=0.05) file1 = forms.FileField(label='Upload a PDB file',required=False, - help_text='starting structure for pdbstart/reference structure') + help_text='starting structure for pdbstart/reference structure; Hint: if you are using NMR example data then the field will be filled out automatically') +#---^ 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)') @@ -300,13 +342,43 @@ class TaskForm_md_a(forms.Form): def clean(self): cleaned_data = super(TaskForm_md_a, self).clean() +#---v + md_seq = cleaned_data.get("md_seq") + if (md_seq == 'TDELLERLRQLFEELHERGTEIVVEVHINGERDEIRVRNISKEELKKLLERIREKIEREGSSEVEVNVHSGGQTWTFNEK'): + reopn1 = open('files/6msp-from-THR.pdb', 'r') + file1 = File(reopn1) + else: +#---^ + file1 = cleaned_data.get("file1") md_start = cleaned_data.get("md_start") - file1 = cleaned_data.get("file1") 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") +#---v + if (md_seq == 'TDELLERLRQLFEELHERGTEIVVEVHINGERDEIRVRNISKEELKKLLERIREKIEREGSSEVEVNVHSGGQTWTFNEK'): + reopn = open('files/N1008_AmbiR-trunc.txt', 'r') + file3 = File(reopn) + else: + file3 = cleaned_data.get("file3") + unres_ff = cleaned_data.get("unres_ff") + use_nmr = cleaned_data.get("use_nmr") + nmr_scal = cleaned_data.get("nmr_scal") + nmr_fordepth = cleaned_data.get("nmr_fordepth") + nmr_slope = cleaned_data.get("nmr_slope") + if (use_nmr and file3): + msg=nmr_bad_cols(file3) + if msg != '': + self.add_error('file3',msg) + else: + if (use_nmr and not file3): + self.add_error('file3','"Use NMR restarints" and "Upload a NMR restr. file" must be used together') + + if (use_nmr and (unres_ff != 'NEWCT-9P')): + self.add_error('unres_ff','"Use NMR restarints" requires NEWCT-9P force field') + +#---^ if md_start == 'pdbstart' and not (file1 or pdbid): msg = 'pdbstart with no PDB file or code' self.add_error('file1', msg) @@ -404,8 +476,17 @@ class TaskForm_remd_a(forms.Form): help_text='single letter code: H helix, E extended/beta, C or - no restraints', required=False, widget=forms.Textarea(attrs={'cols': 70, 'rows': 2})) +#---v + use_nmr = forms.BooleanField(required=False,label='use NMR restraints', + help_text='this option requires the next four fields to be set.') + file3 = forms.FileField(label='Upload a NMR restraints file',required=False, + help_text='at least 5 columns required: 49 22 1 5.0 HD2 H; Hint: if you are using NMR example data then the field will be filled out automatically') + nmr_scal = forms.IntegerField(label='NMR option: scal_peak',initial=20) + nmr_fordepth = forms.FloatField(label='NMR option: FORDEPTH_PEAK',initial=0.5) + nmr_slope = forms.FloatField(label='NMR option: SLOPE_PEAK',initial=0.05) +#---^ file1 = forms.FileField(label='Upload a PDB file',required=False, - help_text='starting structure for pdbstart/reference structure') + help_text='starting structure for pdbstart/reference structure; Hint: if you are using NMR example data then the field will be filled out automatically') 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)') @@ -461,12 +542,40 @@ class TaskForm_remd_a(forms.Form): cleaned_data = super(TaskForm_remd_a, self).clean() md_start = cleaned_data.get("md_start") - file1 = cleaned_data.get("file1") - pdbid = cleaned_data.get("pdbid") +#---v md_seq = cleaned_data.get("md_seq") + if (md_seq == 'TDELLERLRQLFEELHERGTEIVVEVHINGERDEIRVRNISKEELKKLLERIREKIEREGSSEVEVNVHSGGQTWTFNEK'): + reopn1 = open('files/6msp-from-THR.pdb', 'r') + file1 = File(reopn1) + else: + file1 = cleaned_data.get("file1") +#---^ + pdbid = cleaned_data.get("pdbid") md_pdbref = cleaned_data.get("md_pdbref") md_2d = cleaned_data.get("md_2d") - +#---v + if (md_seq == 'TDELLERLRQLFEELHERGTEIVVEVHINGERDEIRVRNISKEELKKLLERIREKIEREGSSEVEVNVHSGGQTWTFNEK'): + reopn = open('files/N1008_AmbiR-trunc.txt', 'r') + file3 = File(reopn) + else: + file3 = cleaned_data.get("file3") + unres_ff = cleaned_data.get("unres_ff") + use_nmr = cleaned_data.get("use_nmr") + nmr_scal = cleaned_data.get("nmr_scal") + nmr_fordepth = cleaned_data.get("nmr_fordepth") + nmr_slope = cleaned_data.get("nmr_slope") + if (use_nmr and file3): + msg=nmr_bad_cols(file3) + if msg != '': + self.add_error('file3',msg) + else: + if (use_nmr and not file3): + self.add_error('file3','"Use NMR restarints" and "Upload a NMR restr. file" must be used together') + + if (use_nmr and (unres_ff != 'NEWCT-9P')): + self.add_error('unres_ff','"Use NMR restarints" requires NEWCT-9P force field') + +#---^ if md_start == 'pdbstart' and not (file1 or pdbid): msg = 'pdbstart with no PDB file or code' self.add_error('file1', msg) @@ -671,5 +780,3 @@ class TaskForm_list(forms.Form): self.fields['temperatures'] = MultiExampleField(self.count) self.fields['multiplexing'] = MultiExampleField(self.count) - - \ No newline at end of file diff --git a/django_simple/todo/jobfiles.py b/django_simple/todo/jobfiles.py index e2f0829..c6ab414 100644 --- a/django_simple/todo/jobfiles.py +++ b/django_simple/todo/jobfiles.py @@ -155,6 +155,10 @@ CUTOFF=7.00000 WCORR4=0.00000""" if instance.md_pdbref: control_line = control_line+'pdbref ' +#---v + if instance.use_nmr: + control_line = control_line+' constr_dist=12 ' +#---^ if instance.unres_ff =='NEWCT-9P': control_line = control_line+'tormode=2 cart' @@ -190,6 +194,10 @@ CUTOFF=7.00000 WCORR4=0.00000""" if instance.unres_ff =='NEWCT-9P': control_line = control_line+'tormode=2 cart' +#---v + if instance.use_nmr: + control_line = control_line+' constr_dist=12 ' +#---^ cntrl_saxs='' if instance.saxs_data != '': @@ -307,6 +315,22 @@ CUTOFF=7.00000 WCORR4=0.00000""" f.write(seq_2d_write_50(seq_2d_xx(instance.md_2d,seq))) else: f.write(seq_2d_write(seq_2d_xx(instance.md_2d,seq))) +#---v + if instance.use_nmr: + f.write('ndist='+repr(instance.linijek_nmr)+' restr_type=12 scal_peak=') + f.write(repr(instance.nmr_scal)+' fordepth_peak='+repr(instance.nmr_fordepth)) + f.write(' slope_peak='+repr(instance.nmr_slope)+'\n') + if (instance.myfile3=='files/N1008_AmbiR-trunc.txt'): + fnmr = open(instance.jobdirname+'/../files/N1008_AmbiR-trunc.txt', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() + else: + fnmr = open(instance.jobdirname+'/plik3.nmr', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() +#---^ if instance.type == 'remd' and instance.md_start != 'pdbstart': @@ -324,6 +348,22 @@ CUTOFF=7.00000 WCORR4=0.00000""" f.write(seq_2d_write_50(seq_2d_xx(instance.md_2d,seq))) else: f.write(seq_2d_write(seq_2d_xx(instance.md_2d,seq))) +#---v + if instance.use_nmr: + f.write('ndist='+repr(instance.linijek_nmr)+' restr_type=12 scal_peak=') + f.write(repr(instance.nmr_scal)+' fordepth_peak='+repr(instance.nmr_fordepth)) + f.write(' slope_peak='+repr(instance.nmr_slope)+'\n') + if (instance.myfile3=='files/N1008_AmbiR-trunc.txt'): + fnmr = open(instance.jobdirname+'/../files/N1008_AmbiR-trunc.txt', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() + else: + fnmr = open(instance.jobdirname+'/plik3.nmr', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() +#---^ if instance.saxs_data != '': @@ -446,6 +486,10 @@ rm tmp_plik2.pdb act.rebuilt.pdb\n""") isampl=1 else: isampl=int(instance.md_nstep/instance.md_ntwx*nreplicas/8000) +#---v + if instance.use_nmr: + f.write('{:79}'.format('with_dist_constr constr_dist=12')+'&\n') +#---^ f.write('{:79}'.format(' isampl='+str(isampl))+'&\n') if instance.md_pdbref: f.write('{:79}'.format('SEED='+str(instance.md_seed)+ @@ -468,6 +512,23 @@ rm tmp_plik2.pdb act.rebuilt.pdb\n""") f.write(write_ssbond(instance.ssbond)) +#---v + if instance.use_nmr: + f.write('ndist='+repr(instance.linijek_nmr)+' restr_type=12 scal_peak=') + f.write(repr(instance.nmr_scal)+' fordepth_peak='+repr(instance.nmr_fordepth)) + f.write(' slope_peak='+repr(instance.nmr_slope)+'\n') + if (instance.myfile3=='files/N1008_AmbiR-trunc.txt'): + fnmr = open(instance.jobdirname+'/../files/N1008_AmbiR-trunc.txt', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() + else: + fnmr = open(instance.jobdirname+'/plik3.nmr', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() +#---^ + if instance.type == 'dock': f.write('HOMOL_DIST=0.1 HOMOL_ANGLE=1.0 HOMOL_THETA=1.0 HOMOL_SCD=1.0 DIST_CUT=15.0 &\n') f.write('READ2SIGMA \n') @@ -528,6 +589,10 @@ rm tmp_plik2.pdb act.rebuilt.pdb\n""") +' nclust='+str(instance.remd_cluster_n))+'&\n') if instance.md_2d != '': f.write('{:79}'.format(' WITH_DIHED_CONSTR')+'&\n') +#---v + if instance.use_nmr: + f.write('{:79}'.format('constr_dist=12 ')+'&\n') +#---^ if instance.type == 'dock': f.write('{:79}'.format(' CONSTR_HOMOL=24')+'&\n') if instance.unres_ff =='NEWCT-9P': @@ -538,6 +603,24 @@ rm tmp_plik2.pdb act.rebuilt.pdb\n""") for i in range(0,len(seq),80): f.write(seq[i:i+80]+'\n') f.write(write_ssbond(instance.ssbond)) + +#---v + if instance.use_nmr: + f.write('ndist='+repr(instance.linijek_nmr)+' restr_type=12 scal_peak=') + f.write(repr(instance.nmr_scal)+' fordepth_peak='+repr(instance.nmr_fordepth)) + f.write(' slope_peak='+repr(instance.nmr_slope)+'\n') + if (instance.myfile3=='files/N1008_AmbiR-trunc.txt'): + fnmr = open(instance.jobdirname+'/../files/N1008_AmbiR-trunc.txt', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() + else: + fnmr = open(instance.jobdirname+'/plik3.nmr', 'r') + for linmr in fnmr: + f.write(linmr) + fnmr.close() +#---^ + if instance.type == 'dock': f.write('HOMOL_DIST=0.1 HOMOL_ANGLE=1.0 HOMOL_THETA=1.0 HOMOL_SCD=1.0 DIST_CUT=15.0 &\n') f.write('READ2SIGMA \n') @@ -619,4 +702,4 @@ def delete_on_task_del(sender, instance, **kwargs): logger.warning("QDEL \"%s\" " % output) shutil.rmtree(instance.jobdirname) logger.warning("Dir \"%s\" has been rm." % instance.jobdirname) - \ No newline at end of file + diff --git a/django_simple/todo/models.py b/django_simple/todo/models.py index c235012..2ff42b0 100644 --- a/django_simple/todo/models.py +++ b/django_simple/todo/models.py @@ -21,6 +21,9 @@ def user_directory_path2(instance, filename): # file will be uploaded to MEDIA_ROOT//plik2.pdb return '{0}/{1}'.format(instance.jobdirname, 'plik2.pdb') +def user_directory_path3(instance, filename): + # file will be uploaded to MEDIA_ROOT//plik3.nmr + return '{0}/{1}'.format(instance.jobdirname, 'plik3.nmr') # Create your models here. class Task(models.Model): @@ -98,6 +101,14 @@ class Task(models.Model): pdbcode2 = models.CharField(max_length=6,default='') dock_peptide = models.BooleanField(default=False) md_seq2 = models.TextField(max_length=2000,default='') + +#nmr + use_nmr = models.BooleanField(default=False) + myfile3 = models.FileField(default='',upload_to=user_directory_path3) + nmr_scal = models.FloatField(default=20.0) + nmr_fordepth = models.FloatField(default=0.5) + nmr_slope = models.FloatField(default=0.05) + linijek_nmr=models.IntegerField(default=0) # system ready = models.BooleanField(default=False) diff --git a/django_simple/todo/templates/details.html b/django_simple/todo/templates/details.html index c6bfd20..5ca3187 100644 --- a/django_simple/todo/templates/details.html +++ b/django_simple/todo/templates/details.html @@ -245,6 +245,14 @@ Created {{ task.created_date }}
starting
{{ task.md_start}}
+ + {% if task.type == "remd" %} +
  • +
    input pdb3
    +
    {{ task.myfile3 }}
    +
  • + {% endif %} +
  • input pdb
    @@ -672,6 +680,32 @@ Created {{ task.created_date }} href="/myfiles/download-file/{{task.jobdirname}}/{{MODELi}}">Download
  • + + {% if task.use_nmr %} +
  • +
    + +
    +
    + select model +
    +
    + +
    +
  • +
  • +
    + + {% with temper=task.remd_cluter_temp|add:"0" %} + NMR contacts of best NMR fitted family representative model + (clustered in {{temper}}K). Model number {{iii}}: +
    +
  • + {% endwith %} + {% endif %} + {% endwith %} {% endwith %} diff --git a/django_simple/todo/templates/details1.html b/django_simple/todo/templates/details1.html index be13e07..8494d96 100644 --- a/django_simple/todo/templates/details1.html +++ b/django_simple/todo/templates/details1.html @@ -149,6 +149,13 @@ Created {{ task.created_date }}
    {{ task.md_start}}
    + +
  • +
    input pdb3
    +
    {{ task.myfile3 }}
    +
  • + +
  • input pdb
    {{ task.myfile1 }}
    @@ -236,6 +243,13 @@ Created {{ task.created_date }}
    starting
    {{ task.md_start}}
  • + + {% if task.type == "remd" %} +
  • +
    input pdb3
    +
    {{ task.myfile3 }}
    +
  • +
  • input pdb
    diff --git a/django_simple/todo/templates/edit.html b/django_simple/todo/templates/edit.html index 9e7ce80..d9128a0 100644 --- a/django_simple/todo/templates/edit.html +++ b/django_simple/todo/templates/edit.html @@ -73,7 +73,6 @@ - {% endif %}

    @@ -91,7 +90,13 @@ Calculation type {{ p_type }} + {% if p_type == "molecular dynamics - advanced options" %} + + {% endif %} {% if p_type == "replica exchange molecular dynamics - advanced options" %} +