3 from django.db.models.signals import post_save, post_delete
4 from django.dispatch import receiver
5 from .models import Task
10 from string import Template
14 logger = logging.getLogger(__name__)
16 def write_ssbond(ssbond):
19 ssbond=json.loads(ssbond)
23 list_sorted=sorted(list)
26 return str(len(list))+' '+' '.join(map(str,list_sorted))+'\n'+\
27 str(len(ssbond))+' '+' '.join(map(str,list))+'\n'
32 @receiver(post_save, sender=Task)
33 def write_on_task_save(sender, instance, **kwargs):
34 if instance.ready and not instance.done and instance.running==0:
35 if (not os.path.isdir(instance.jobdirname)):
36 os.mkdir(instance.jobdirname)
37 # os.chdir(instance.jobdirname)
41 #md=Template('nstep=$nstep ntwe=100 ntwx=100 dt=0.20 damax=10.0 lang=1'+
42 # 't_bath=300 reset_vel=0 respa ntime_split=1 maxtime_split=512 mdpdb')
43 #wrapper = textwrap.TextWrapper(width=70)
44 #word_list = wrapper.wrap(text=md.substitute(nstep=str(nstep)))
46 if instance.unres_ff =='E0LL2Y':
47 w="""WSC=1.00000 WSCP=1.23315 WELEC=0.84476 WBOND=1.00000 WANG=0.62954 &
48 WSCLOC=0.10554 WTOR=1.34316 WTORD=1.26571 WCORRH=0.19212 WCORR5=0.00000 &
49 WCORR6=0.00000 WEL_LOC=0.37357 WTURN3=1.40323 WTURN4=0.64673 WTURN6=0.00000 &
50 WVDWPP=0.23173 WHPB=1.00000 WSCCOR=0.25 &
51 CUTOFF=7.00000 WCORR4=0.00000
54 w="""WSC=0.82686 WSCP=0.96947 WELEC=0.79373 WBOND=1.00000 WANG=0.46542 &
55 WSCLOC=0.07969 WTOR=0.81684 WTORD=0.67806 WCORRH=0.00000 WCORR5=0.00000 &
56 WCORR6=0.00000 WEL_LOC=0.71100 WTURN3=2.30298 WTURN4=0.86517 WTURN6=0.00000 &
57 WSCCOR=0.14577 WVDWPP=0.17781 WHPB=1.00000 WSCP14=0.00000 &
58 CUTOFF=7.00000 WCORR4=0.00000
62 with open(instance.jobdirname+'/file.inp','w') as f:
63 f.write(instance.name + ' UNRES server job'+ '\n')
65 if instance.type == 'min' :
67 control_line = 'SEED='+str(instance.md_seed)+' ' \
68 + instance.min_choice \
69 + ' pdbstart pdbref BOXX=1000. BOXY=1000. BOXZ=1000. '
70 if not instance.min_overlap:
71 control_line = control_line+'overlap '
72 if not instance.min_searchsc:
73 control_line = control_line+'nosearchsc '
74 if instance.min_pdbout:
75 control_line = control_line+'pdbout '
76 if instance.min_unres_pdb:
77 control_line = control_line+'unres_pdb '
79 type_line = 'print_min_ini print_min_res print_min_stat'\
80 +' MAXMIN='+str(instance.min_maxmin)\
81 +' MAXFUN='+str(instance.min_maxfun)
84 seq=instance.md_seq.replace(" ","")
92 nogly ='CDSQKIPTFNHLRWAVEYM'
93 seq2 = ''.join([c for c in seq if c in nogly])
95 dimen3=(dimen3+len(seq2))*3
98 if instance.type == 'md' :
99 control_line = 'SEED='+str(instance.md_seed)+' '\
100 +instance.md_start +' md one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
101 if instance.md_pdbref:
102 control_line = control_line+'pdbref '
104 type_line = 'reset_vel=0'\
105 +' t_bath='+str(instance.md_temp)\
106 +' nstep='+str(instance.md_nstep)\
107 +' ntwe='+str(instance.md_ntwe)\
108 +' ntwx='+str(instance.md_ntwx)\
109 +' dt='+str(instance.md_dt)
110 if instance.md_lang == 'langevin':
111 type_line = type_line + ' lang=1 '
112 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
113 if instance.md_lang == 'berendsen':
114 type_line = type_line + ' lang=0 tbf '
115 type_line = type_line + 'tau_bath='+str(instance.md_tau)
116 if instance.md_respa:
117 type_line = type_line + ' respa '
118 if instance.md_mdpdb:
119 type_line = type_line + ' mdpdb '
121 if instance.type == 'remd' :
122 control_line = 'SEED='+str(instance.md_seed)+' '\
123 +instance.md_start +' re one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
124 if instance.md_pdbref:
125 control_line = control_line+'pdbref '
128 type_line = 'reset_vel='+ str(instance.remd_nstex)\
129 +' nstep='+str(instance.md_nstep)\
130 +' ntwe='+str(instance.md_ntwe)\
131 +' ntwx='+str(instance.md_ntwx)\
132 +' dt='+str(instance.md_dt)
133 if instance.md_lang == 'langevin':
134 type_line = type_line + ' lang=1 '
135 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
136 if instance.md_lang == 'berendsen':
137 type_line = type_line + ' lang=0 tbf '
138 type_line = type_line + 'tau_bath='+str(instance.md_tau)
139 if instance.md_respa:
140 type_line = type_line + ' respa '
141 if instance.md_mdpdb:
142 type_line = type_line + ' mdpdb '
144 type_line2 = 'nrep='+str(instance.remd_nrep) \
145 +' nstex='+str(instance.remd_nstex) \
146 +' tlist mlist sync nsyn='+str(instance.remd_nstex)\
147 +' traj1file rest1file TRAJCACHE=200'
149 if instance.md_start == 'pdbstart':
150 type_line = type_line + ' preminim cart'
152 wrapper = textwrap.TextWrapper(width=70)
154 word_list = wrapper.wrap(text=control_line)
155 for element in word_list[:-1]:
156 f.write('{:79}'.format(element)+'&\n')
157 f.write(word_list[-1]+'\n')
159 word_list = wrapper.wrap(text=type_line)
160 for element in word_list[:-1]:
161 f.write('{:79}'.format(element)+'&\n')
162 f.write(word_list[-1]+'\n')
164 if instance.md_start == 'pdbstart':
165 f.write('print_min_ini print_min_res print_min_stat\n')
168 if instance.type == 'remd' :
169 word_list = wrapper.wrap(text=type_line2)
170 for element in word_list[:-1]:
171 f.write('{:79}'.format(element)+'&\n')
172 f.write(word_list[-1]+'\n')
174 tmp1=json.loads(instance.remd_multi_t)
176 word_list = wrapper.wrap(text=string1.join(tmp1))
177 for element in word_list[:-1]:
178 f.write('{:79}'.format(element)+'&\n')
179 f.write(word_list[-1]+'\n')
181 tmp1=json.loads(instance.remd_multi_m)
183 word_list = wrapper.wrap(text=string1.join(tmp1))
184 for element in word_list[:-1]:
185 f.write('{:79}'.format(element)+'&\n')
186 f.write(word_list[-1]+'\n')
191 if instance.type == 'min' or instance.md_start == 'pdbstart':
192 f.write('plik.pdb\n')
193 f.write(write_ssbond(instance.ssbond))
197 if instance.type == 'md' and instance.md_start != 'pdbstart':
199 if instance.md_pdbref:
200 f.write('plik.pdb\n')
201 f.write(str(len(seq))+'\n')
202 for i in range(0,len(seq),80):
203 f.write(seq[i:i+80]+'\n')
206 if instance.type == 'remd' and instance.md_start != 'pdbstart':
208 if instance.md_pdbref:
209 f.write('plik.pdb\n')
210 f.write(str(len(seq))+'\n')
211 for i in range(0,len(seq),80):
212 f.write(seq[i:i+80]+'\n')
218 if instance.type == 'min':
219 os.chdir(instance.jobdirname)
220 if instance.unres_ff =='E0LL2Y':
221 shutil.copy('../files/pbs.csh','.')
223 shutil.copy('../files/pbs_new.csh','pbs.csh')
224 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
226 elif instance.type == 'md':
227 os.chdir(instance.jobdirname)
228 if instance.unres_ff =='E0LL2Y':
229 f1 = open('../files/pbs_md.csh', 'r')
231 f1 = open('../files/pbs_md_new.csh', 'r')
232 f2 = open('pbs.csh', 'w')
234 f2.write(line.replace('$dimen3',str(dimen3) ))
238 f1 = open('file.seq', 'w')
239 for i in range(0,len(seq),80):
240 f1.write(seq[i:i+80]+'\n')
243 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
246 # instance.type == 'remd'
247 tmp1=json.loads(instance.remd_multi_m)
248 nreplicas=sum(map(int, tmp1))
249 # hardcoded for 4 core nodes with FGPROC=2
250 nodes=int(nreplicas*2/4)
251 reszta = nreplicas*2-nodes*4
253 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4'
255 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4+1:ppn='+str(reszta)
257 os.chdir(instance.jobdirname)
258 if instance.unres_ff =='E0LL2Y':
259 f1 = open('../files/pbs8.csh', 'r')
261 f1 = open('../files/pbs8_new.csh', 'r')
262 f2 = open('pbs8.csh', 'w')
264 if '#PBS -l nodes=4:ppn=4' in line:
265 f2.write(line.replace('#PBS -l nodes=4:ppn=4', pbs))
267 tmp1=json.loads(instance.remd_multi_t)
268 f2.write(line.replace('$temperatures','"'+" ".join(tmp1)+'" '+str(nreplicas)))
273 # write wham & cluster input
274 with open(instance.jobdirname+'/file_wham.inp','w') as f:
275 if instance.md_nstep/instance.md_ntwx*nreplicas<=8000:
278 isampl=int(instance.md_nstep/instance.md_ntwx*nreplicas/8000)
280 if instance.md_pdbref:
281 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
282 ' einicheck=1 rescale=2 delta=0.02 cxfile classify\n')
284 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
285 ' einicheck=1 rescale=2 delta=0.02 cxfile\n')
286 f.write('nres='+str(len(seq))+' one_letter\n')
287 for i in range(0,len(seq),80):
288 f.write(seq[i:i+80]+'\n')
290 f.write(write_ssbond(instance.ssbond))
295 f.write('nt='+str(instance.remd_nrep)+' replica read_iset\n')
296 tmp1=json.loads(instance.remd_multi_t)
298 f.write('nr=1 temp='+element+' fi=0.0 0.0 0.0 0.0 0.0\n')
299 f.write('kh= 0.0 Q0=0.0\n')
300 rec=instance.md_nstep/instance.md_ntwx
301 f.write('nfile_cx=1 rec_start='+str(rec/10)
302 +' rec_end='+str(rec)+' totraj='+str(nreplicas)+'\n')
303 f.write('file_MD000\n')
304 if instance.md_pdbref:
306 f.write('plik.pdb\n')
309 with open(instance.jobdirname+'/file_cluster.inp','w') as f:
310 f.write(instance.name + ' UNRES server job'+ '\n')
311 f.write('nres='+str(len(seq))
312 +' one_letter rescale=2 PRINT_CART PDBOUT=1 iopt=1'
313 +' temper='+str(instance.remd_cluter_temp)+'\n')
315 for i in range(0,len(seq),80):
316 f.write(seq[i:i+80]+'\n')
317 f.write(write_ssbond(instance.ssbond))
319 os.chdir(instance.jobdirname)
320 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
323 print ret_code.stdout.readlines()
324 logger.warning("Dir \"%s\" has been saved." % instance.jobdirname)
326 @receiver(post_delete, sender=Task)
327 def delete_on_task_del(sender, instance, **kwargs):
328 if instance.jobdirname:
329 if os.path.isdir(instance.jobdirname):
330 shutil.rmtree(instance.jobdirname)
331 logger.warning("Dir \"%s\" has been rm." % instance.jobdirname)