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):
18 ssbond=json.loads(ssbond)
22 list_sorted=sorted(list)
25 return str(len(list))+' '+' '.join(map(str,list_sorted))+'\n'+\
26 str(len(ssbond))+' '+' '.join(map(str,list))+'\n'
31 @receiver(post_save, sender=Task)
32 def write_on_task_save(sender, instance, **kwargs):
33 if instance.ready and not instance.done and instance.running==0:
34 if (not os.path.isdir(instance.jobdirname)):
35 os.mkdir(instance.jobdirname)
36 # os.chdir(instance.jobdirname)
40 #md=Template('nstep=$nstep ntwe=100 ntwx=100 dt=0.20 damax=10.0 lang=1'+
41 # 't_bath=300 reset_vel=0 respa ntime_split=1 maxtime_split=512 mdpdb')
42 #wrapper = textwrap.TextWrapper(width=70)
43 #word_list = wrapper.wrap(text=md.substitute(nstep=str(nstep)))
45 if instance.unres_ff =='E0LL2Y':
46 w="""WSC=1.00000 WSCP=1.23315 WELEC=0.84476 WBOND=1.00000 WANG=0.62954 &
47 WSCLOC=0.10554 WTOR=1.34316 WTORD=1.26571 WCORRH=0.19212 WCORR5=0.00000 &
48 WCORR6=0.00000 WEL_LOC=0.37357 WTURN3=1.40323 WTURN4=0.64673 WTURN6=0.00000 &
49 WVDWPP=0.23173 WHPB=1.00000 WSCCOR=0.25 &
50 CUTOFF=7.00000 WCORR4=0.00000
53 w="""WSC=0.82686 WSCP=0.96947 WELEC=0.79373 WBOND=1.00000 WANG=0.46542 &
54 WSCLOC=0.07969 WTOR=0.81684 WTORD=0.67806 WCORRH=0.00000 WCORR5=0.00000 &
55 WCORR6=0.00000 WEL_LOC=0.71100 WTURN3=2.30298 WTURN4=0.86517 WTURN6=0.00000 &
56 WSCCOR=0.14577 WVDWPP=0.17781 WHPB=1.00000 WSCP14=0.00000 &
57 CUTOFF=7.00000 WCORR4=0.00000
61 with open(instance.jobdirname+'/file.inp','w') as f:
62 f.write(instance.name + ' UNRES server job'+ '\n')
64 if instance.type == 'min' :
66 control_line = 'SEED='+str(instance.md_seed)+' ' \
67 + instance.min_choice \
68 + ' pdbstart pdbref BOXX=1000. BOXY=1000. BOXZ=1000. '
69 if not instance.min_overlap:
70 control_line = control_line+'overlap '
71 if not instance.min_searchsc:
72 control_line = control_line+'nosearchsc '
73 if instance.min_pdbout:
74 control_line = control_line+'pdbout '
75 if instance.min_unres_pdb:
76 control_line = control_line+'unres_pdb '
78 type_line = 'print_min_ini print_min_res print_min_stat'\
79 +' MAXMIN='+str(instance.min_maxmin)\
80 +' MAXFUN='+str(instance.min_maxfun)
83 seq=instance.md_seq.replace(" ","")
91 nogly ='CDSQKIPTFNHLRWAVEYM'
92 seq2 = ''.join([c for c in seq if c in nogly])
94 dimen3=(dimen3+len(seq2))*3
97 if instance.type == 'md' :
98 control_line = 'SEED='+str(instance.md_seed)+' '\
99 +instance.md_start +' md one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
100 if instance.md_pdbref:
101 control_line = control_line+'pdbref '
103 type_line = 'reset_vel=0'\
104 +' t_bath='+str(instance.md_temp)\
105 +' nstep='+str(instance.md_nstep)\
106 +' ntwe='+str(instance.md_ntwe)\
107 +' ntwx='+str(instance.md_ntwx)\
108 +' dt='+str(instance.md_dt)
109 if instance.md_lang == 'langevin':
110 type_line = type_line + ' lang=1 '
111 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
112 if instance.md_lang == 'berendsen':
113 type_line = type_line + ' lang=0 tbf '
114 type_line = type_line + 'tau_bath='+str(instance.md_tau)
115 if instance.md_respa:
116 type_line = type_line + ' respa '
117 if instance.md_mdpdb:
118 type_line = type_line + ' mdpdb '
120 if instance.type == 'remd' :
121 control_line = 'SEED='+str(instance.md_seed)+' '\
122 +instance.md_start +' re one_letter BOXX=1000. BOXY=1000. BOXZ=1000. '
123 if instance.md_pdbref:
124 control_line = control_line+'pdbref '
127 type_line = 'reset_vel='+ str(instance.remd_nstex)\
128 +' nstep='+str(instance.md_nstep)\
129 +' ntwe='+str(instance.md_ntwe)\
130 +' ntwx='+str(instance.md_ntwx)\
131 +' dt='+str(instance.md_dt)
132 if instance.md_lang == 'langevin':
133 type_line = type_line + ' lang=1 '
134 type_line = type_line + 'scal_fric='+str(instance.md_scal_fric)
135 if instance.md_lang == 'berendsen':
136 type_line = type_line + ' lang=0 tbf '
137 type_line = type_line + 'tau_bath='+str(instance.md_tau)
138 if instance.md_respa:
139 type_line = type_line + ' respa '
140 if instance.md_mdpdb:
141 type_line = type_line + ' mdpdb '
143 type_line2 = 'nrep='+str(instance.remd_nrep) \
144 +' nstex='+str(instance.remd_nstex) \
145 +' tlist mlist sync nsyn='+str(instance.remd_nstex)\
146 +' traj1file rest1file TRAJCACHE=200'
148 if instance.md_start == 'pdbstart':
149 type_line = type_line + ' preminim cart'
151 wrapper = textwrap.TextWrapper(width=70)
153 word_list = wrapper.wrap(text=control_line)
154 for element in word_list[:-1]:
155 f.write('{:79}'.format(element)+'&\n')
156 f.write(word_list[-1]+'\n')
158 word_list = wrapper.wrap(text=type_line)
159 for element in word_list[:-1]:
160 f.write('{:79}'.format(element)+'&\n')
161 f.write(word_list[-1]+'\n')
163 if instance.md_start == 'pdbstart':
164 f.write('print_min_ini print_min_res print_min_stat\n')
167 if instance.type == 'remd' :
168 word_list = wrapper.wrap(text=type_line2)
169 for element in word_list[:-1]:
170 f.write('{:79}'.format(element)+'&\n')
171 f.write(word_list[-1]+'\n')
173 tmp1=json.loads(instance.remd_multi_t)
175 word_list = wrapper.wrap(text=string1.join(tmp1))
176 for element in word_list[:-1]:
177 f.write('{:79}'.format(element)+'&\n')
178 f.write(word_list[-1]+'\n')
180 tmp1=json.loads(instance.remd_multi_m)
182 word_list = wrapper.wrap(text=string1.join(tmp1))
183 for element in word_list[:-1]:
184 f.write('{:79}'.format(element)+'&\n')
185 f.write(word_list[-1]+'\n')
190 if instance.type == 'min' or instance.md_start == 'pdbstart':
191 f.write('plik.pdb\n')
192 f.write(write_ssbond(instance.ssbond))
196 if instance.type == 'md' and instance.md_start != 'pdbstart':
198 if instance.md_pdbref:
199 f.write('plik.pdb\n')
200 f.write(str(len(seq))+'\n')
201 for i in range(0,len(seq),80):
202 f.write(seq[i:i+80]+'\n')
205 if instance.type == 'remd' and instance.md_start != 'pdbstart':
207 if instance.md_pdbref:
208 f.write('plik.pdb\n')
209 f.write(str(len(seq))+'\n')
210 for i in range(0,len(seq),80):
211 f.write(seq[i:i+80]+'\n')
217 if instance.type == 'min':
218 os.chdir(instance.jobdirname)
219 if instance.unres_ff =='E0LL2Y':
220 shutil.copy('../files/pbs.csh','.')
222 shutil.copy('../files/pbs_new.csh','pbs.csh')
223 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
225 elif instance.type == 'md':
226 os.chdir(instance.jobdirname)
227 if instance.unres_ff =='E0LL2Y':
228 f1 = open('../files/pbs_md.csh', 'r')
230 f1 = open('../files/pbs_md_new.csh', 'r')
231 f2 = open('pbs.csh', 'w')
233 f2.write(line.replace('$dimen3',str(dimen3) ))
237 f1 = open('file.seq', 'w')
238 for i in range(0,len(seq),80):
239 f1.write(seq[i:i+80]+'\n')
242 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
245 # instance.type == 'remd'
246 tmp1=json.loads(instance.remd_multi_m)
247 nreplicas=sum(map(int, tmp1))
248 # hardcoded for 4 core nodes with FGPROC=2
249 nodes=int(nreplicas*2/4)
250 reszta = nreplicas*2-nodes*4
252 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4'
254 pbs = '#PBS -l nodes='+str(nodes)+':ppn=4+1:ppn='+str(reszta)
256 os.chdir(instance.jobdirname)
257 if instance.unres_ff =='E0LL2Y':
258 f1 = open('../files/pbs8.csh', 'r')
260 f1 = open('../files/pbs8_new.csh', 'r')
261 f2 = open('pbs8.csh', 'w')
263 if '#PBS -l nodes=4:ppn=4' in line:
264 f2.write(line.replace('#PBS -l nodes=4:ppn=4', pbs))
266 tmp1=json.loads(instance.remd_multi_t)
267 f2.write(line.replace('$temperatures','"'+" ".join(tmp1)+'" '+str(nreplicas)))
272 # write wham & cluster input
273 with open(instance.jobdirname+'/file_wham.inp','w') as f:
274 if instance.md_nstep/instance.md_ntwx*nreplicas<=8000:
277 isampl=int(instance.md_nstep/instance.md_ntwx*nreplicas/8000)
279 if instance.md_pdbref:
280 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
281 ' einicheck=1 rescale=2 delta=0.02 cxfile classify\n')
283 f.write('SEED='+str(instance.md_seed)+' isampl='+str(isampl)+
284 ' einicheck=1 rescale=2 delta=0.02 cxfile\n')
285 f.write('nres='+str(len(seq))+' one_letter\n')
286 for i in range(0,len(seq),80):
287 f.write(seq[i:i+80]+'\n')
289 f.write(write_ssbond(instance.ssbond))
294 f.write('nt='+str(instance.remd_nrep)+' replica read_iset\n')
295 tmp1=json.loads(instance.remd_multi_t)
297 f.write('nr=1 temp='+element+' fi=0.0 0.0 0.0 0.0 0.0\n')
298 f.write('kh= 0.0 Q0=0.0\n')
299 rec=instance.md_nstep/instance.md_ntwx
300 f.write('nfile_cx=1 rec_start='+str(rec/10)
301 +' rec_end='+str(rec)+' totraj='+str(nreplicas)+'\n')
302 f.write('file_MD000\n')
303 if instance.md_pdbref:
305 f.write('plik.pdb\n')
308 with open(instance.jobdirname+'/file_cluster.inp','w') as f:
309 f.write(instance.name + ' UNRES server job'+ '\n')
310 f.write('nres='+str(len(seq))
311 +' one_letter rescale=2 PRINT_CART PDBOUT=1 iopt=1'
312 +' temper='+str(instance.remd_cluter_temp)+'\n')
314 for i in range(0,len(seq),80):
315 f.write(seq[i:i+80]+'\n')
316 f.write(write_ssbond(instance.ssbond))
318 os.chdir(instance.jobdirname)
319 ret_code = subprocess.Popen(' /opt/torque/bin/qsub pbs8.csh', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
322 print ret_code.stdout.readlines()
323 logger.warning("Dir \"%s\" has been saved." % instance.jobdirname)
325 @receiver(post_delete, sender=Task)
326 def delete_on_task_del(sender, instance, **kwargs):
327 if instance.jobdirname:
328 if os.path.isdir(instance.jobdirname):
329 shutil.rmtree(instance.jobdirname)
330 logger.warning("Dir \"%s\" has been rm." % instance.jobdirname)