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):
21 list_sorted=sorted(list)
24 return str(len(list))+' '+' '.join(map(str,list_sorted))+'\n'+\
25 str(len(ssbond))+' '+' '.join(map(str,list))+'\n'
30 @receiver(post_save, sender=Task)
31 def write_on_task_save(sender, instance, **kwargs):
32 if instance.ready and not instance.done and instance.running==0:
33 if (not os.path.isdir(instance.jobdirname)):
34 os.mkdir(instance.jobdirname)
35 # os.chdir(instance.jobdirname)
39 #md=Template('nstep=$nstep ntwe=100 ntwx=100 dt=0.20 damax=10.0 lang=1'+
40 # 't_bath=300 reset_vel=0 respa ntime_split=1 maxtime_split=512 mdpdb')
41 #wrapper = textwrap.TextWrapper(width=70)
42 #word_list = wrapper.wrap(text=md.substitute(nstep=str(nstep)))
44 if instance.unres_ff =='E0LL2Y':
45 w="""WSC=1.00000 WSCP=1.23315 WELEC=0.84476 WBOND=1.00000 WANG=0.62954 &
46 WSCLOC=0.10554 WTOR=1.34316 WTORD=1.26571 WCORRH=0.19212 WCORR5=0.00000 &
47 WCORR6=0.00000 WEL_LOC=0.37357 WTURN3=1.40323 WTURN4=0.64673 WTURN6=0.00000 &
48 WVDWPP=0.23173 WHPB=1.00000 WSCCOR=0.25 &
49 CUTOFF=7.00000 WCORR4=0.00000
52 w="""WSC=0.82686 WSCP=0.96947 WELEC=0.79373 WBOND=1.00000 WANG=0.46542 &
53 WSCLOC=0.07969 WTOR=0.81684 WTORD=0.67806 WCORRH=0.00000 WCORR5=0.00000 &
54 WCORR6=0.00000 WEL_LOC=0.71100 WTURN3=2.30298 WTURN4=0.86517 WTURN6=0.00000 &
55 WSCCOR=0.14577 WVDWPP=0.17781 WHPB=1.00000 WSCP14=0.00000 &
56 CUTOFF=7.00000 WCORR4=0.00000
60 with open(instance.jobdirname+'/file.inp','w') as f:
61 f.write(instance.name + ' UNRES server job'+ '\n')
63 if instance.type == 'min' :
65 control_line = 'SEED='+str(instance.md_seed)+' ' \
66 + instance.min_choice \
67 + ' pdbstart pdbref BOXX=1000. BOXY=1000. BOXZ=1000. '
68 if not instance.min_overlap:
69 control_line = control_line+'overlap '
70 if not instance.min_searchsc:
71 control_line = control_line+'nosearchsc '
72 if instance.min_pdbout:
73 control_line = control_line+'pdbout '
74 if instance.min_unres_pdb:
75 control_line = control_line+'unres_pdb '
77 type_line = 'print_min_ini print_min_res print_min_stat'\
78 +' MAXMIN='+str(instance.min_maxmin)\
79 +' MAXFUN='+str(instance.min_maxfun)
82 seq=instance.md_seq.replace(" ","")
90 nogly ='CDSQKIPTFNHLRWAVEYM'
91 seq2 = ''.join([c for c in seq if c in nogly])
93 dimen3=(dimen3+len(seq2))*3
96 if instance.type == 'md' :
97 control_line = 'SEED='+str(instance.md_seed)+' '\
98 +instance.md_start +' md one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
99 if instance.md_pdbref:
100 control_line = control_line+'pdbref '
102 type_line = 'reset_vel=0'\
103 +' t_bath='+str(instance.md_temp)\
104 +' nstep='+str(instance.md_nstep)\
105 +' ntwe='+str(instance.md_ntwe)\
106 +' ntwx='+str(instance.md_ntwx)\
107 +' dt='+str(instance.md_dt)
108 if instance.md_lang == 'langevin':
109 type_line = type_line + ' lang=1 '
110 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
111 if instance.md_lang == 'berendsen':
112 type_line = type_line + ' lang=0 tbf '
113 type_line = type_line + 'tau_bath='+str(instance.md_tau)
114 if instance.md_respa:
115 type_line = type_line + ' respa '
116 if instance.md_mdpdb:
117 type_line = type_line + ' mdpdb '
119 if instance.type == 'remd' :
120 control_line = 'SEED='+str(instance.md_seed)+' '\
121 +instance.md_start +' re one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
122 if instance.md_pdbref:
123 control_line = control_line+'pdbref '
126 type_line = 'reset_vel='+ str(instance.remd_nstex)\
127 +' nstep='+str(instance.md_nstep)\
128 +' ntwe='+str(instance.md_ntwe)\
129 +' ntwx='+str(instance.remd_nstex)\
130 +' dt='+str(instance.md_dt)
131 if instance.md_lang == 'langevin':
132 type_line = type_line + ' lang=1 '
133 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
134 if instance.md_lang == 'berendsen':
135 type_line = type_line + ' lang=0 tbf '
136 type_line = type_line + 'tau_bath='+str(instance.md_tau)
137 if instance.md_respa:
138 type_line = type_line + ' respa '
139 if instance.md_mdpdb:
140 type_line = type_line + ' mdpdb '
142 type_line2 = 'nrep='+str(instance.remd_nrep) \
143 +' nstex='+str(instance.remd_nstex) \
144 +' tlist mlist sync nsyn='+str(instance.remd_nstex)\
145 +' traj1file rest1file '
147 if instance.md_start == 'pdbstart':
148 type_line = type_line + ' preminim cart'
150 wrapper = textwrap.TextWrapper(width=70)
152 word_list = wrapper.wrap(text=control_line)
153 for element in word_list[:-1]:
154 f.write('{:79}'.format(element)+'&\n')
155 f.write(word_list[-1]+'\n')
157 word_list = wrapper.wrap(text=type_line)
158 for element in word_list[:-1]:
159 f.write('{:79}'.format(element)+'&\n')
160 f.write(word_list[-1]+'\n')
162 if instance.md_start == 'pdbstart':
163 f.write('print_min_ini print_min_res print_min_stat\n')
166 if instance.type == 'remd' :
167 word_list = wrapper.wrap(text=type_line2)
168 for element in word_list[:-1]:
169 f.write('{:79}'.format(element)+'&\n')
170 f.write(word_list[-1]+'\n')
172 tmp1=json.loads(instance.remd_multi_t)
174 word_list = wrapper.wrap(text=string1.join(tmp1))
175 for element in word_list[:-1]:
176 f.write('{:79}'.format(element)+'&\n')
177 f.write(word_list[-1]+'\n')
179 tmp1=json.loads(instance.remd_multi_m)
181 word_list = wrapper.wrap(text=string1.join(tmp1))
182 for element in word_list[:-1]:
183 f.write('{:79}'.format(element)+'&\n')
184 f.write(word_list[-1]+'\n')
189 if instance.type == 'min' or instance.md_start == 'pdbstart':
190 f.write('plik.pdb\n')
191 f.write(write_ssbond(instance.ssbond))
195 if instance.type == 'md' and instance.md_start != 'pdbstart':
197 if instance.md_pdbref:
198 f.write('plik.pdb\n')
199 f.write(str(len(seq))+'\n')
200 for i in range(0,len(seq),80):
201 f.write(seq[i:i+80]+'\n')
204 if instance.type == 'remd' and instance.md_start != 'pdbstart':
206 if instance.md_pdbref:
207 f.write('plik.pdb\n')
208 f.write(str(len(seq))+'\n')
209 for i in range(0,len(seq),80):
210 f.write(seq[i:i+80]+'\n')
216 if instance.type == 'min':
217 os.chdir(instance.jobdirname)
218 if instance.unres_ff =='E0LL2Y':
219 shutil.copy('../files/pbs.csh','.')
221 shutil.copy('../files/pbs_new.csh','pbs.csh')
222 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
224 elif instance.type == 'md':
225 os.chdir(instance.jobdirname)
226 if instance.unres_ff =='E0LL2Y':
227 f1 = open('../files/pbs_md.csh', 'r')
229 f1 = open('../files/pbs_md_new.csh', 'r')
230 f2 = open('pbs.csh', 'w')
232 f2.write(line.replace('$dimen3',str(dimen3) ))
236 f1 = open('file.seq', 'w')
237 for i in range(0,len(seq),80):
238 f1.write(seq[i:i+80]+'\n')
241 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
244 # instance.type == 'remd'
245 tmp1=json.loads(instance.remd_multi_m)
246 nreplicas=sum(map(int, tmp1))
247 # hardcoded for 4 core nodes with FGPROC=2
248 nodes=int(nreplicas*2/4)
249 reszta = nreplicas*2-nodes*4
251 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4'
253 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4+1:ppn='+str(reszta)
255 os.chdir(instance.jobdirname)
256 if instance.unres_ff =='E0LL2Y':
257 f1 = open('../files/pbs8.csh', 'r')
259 f1 = open('../files/pbs8_new.csh', 'r')
260 f2 = open('pbs8.csh', 'w')
262 if '#PBS -l nodes=4:ppn=4' in line:
263 f2.write(line.replace('#PBS -l nodes=4:ppn=4', pbs))
265 tmp1=json.loads(instance.remd_multi_t)
266 f2.write(line.replace('$temperatures','"'+" ".join(tmp1)+'" '+str(nreplicas)))
271 # write wham & cluster input
272 with open(instance.jobdirname+'/file_wham.inp','w') as f:
273 if instance.md_nstep/instance.remd_nstex*nreplicas<=8000:
276 isampl=int(instance.md_nstep/instance.remd_nstex*nreplicas/8000)
278 if instance.md_pdbref:
279 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
280 ' einicheck=1 rescale=2 delta=0.02 cxfile classify\n')
282 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
283 ' einicheck=1 rescale=2 delta=0.02 cxfile\n')
284 f.write('nres='+str(len(seq))+' one_letter\n')
285 for i in range(0,len(seq),80):
286 f.write(seq[i:i+80]+'\n')
288 f.write(write_ssbond(instance.ssbond))
293 f.write('nt='+str(instance.remd_nrep)+' replica read_iset\n')
294 tmp1=json.loads(instance.remd_multi_t)
296 f.write('nr=1 temp='+element+' fi=0.0 0.0 0.0 0.0 0.0\n')
297 f.write('kh= 0.0 Q0=0.0\n')
298 rec=instance.md_nstep/instance.remd_nstex
299 f.write('nfile_cx=1 rec_start='+str(rec/10)
300 +' rec_end='+str(rec)+' totraj='+str(nreplicas)+'\n')
301 f.write('file_MD000\n')
302 if instance.md_pdbref:
304 f.write('plik.pdb\n')
307 with open(instance.jobdirname+'/file_cluster.inp','w') as f:
308 f.write(instance.name + ' UNRES server job'+ '\n')
309 f.write('nres='+str(len(seq))
310 +' one_letter rescale=2 PRINT_CART PDBOUT=1 iopt=1'
311 +' temper='+str(instance.remd_cluter_temp)+'\n')
313 for i in range(0,len(seq),80):
314 f.write(seq[i:i+80]+'\n')
315 f.write(write_ssbond(instance.ssbond))
317 os.chdir(instance.jobdirname)
318 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
321 print ret_code.stdout.readlines()
322 logger.warning("Dir \"%s\" has been saved." % instance.jobdirname)
324 @receiver(post_delete, sender=Task)
325 def delete_on_task_del(sender, instance, **kwargs):
326 if instance.jobdirname:
327 if os.path.isdir(instance.jobdirname):
328 shutil.rmtree(instance.jobdirname)
329 logger.warning("Dir \"%s\" has been rm." % instance.jobdirname)