1 subroutine read_constr_homology
4 include 'DIMENSIONS.ZSCOPT'
5 include 'DIMENSIONS.FREE'
10 include 'COMMON.CONTROL'
11 include 'COMMON.CHAIN'
12 include 'COMMON.IOUNITS'
14 include 'COMMON.INTERACT'
15 include 'COMMON.NAMES'
16 include 'COMMON.HOMRESTR'
17 include 'COMMON.HOMOLOGY'
22 c include 'include_unres/COMMON.VAR'
25 c double precision odl_temp,sigma_odl_temp,waga_theta,waga_d,
27 c common /przechowalnia/ odl_temp(maxres,maxres,max_template),
28 c & sigma_odl_temp(maxres,maxres,max_template)
30 character*24 model_ki_dist, model_ki_angle
31 character*500 controlcard
32 integer ki, i, j, k, l, ii_in_use(maxdim),i_tmp,idomain_tmp
33 integer idomain(max_template,maxres)
37 logical unres_pdb,liiflag
39 c FP - Nov. 2014 Temporary specifications for new vars
41 double precision rescore_tmp,x12,y12,z12,rescore2_tmp
42 double precision, dimension (max_template,maxres) :: rescore
43 double precision, dimension (max_template,maxres) :: rescore2
44 character*24 tpl_k_rescore
45 c -----------------------------------------------------------------
46 c Reading multiple PDB ref structures and calculation of retraints
47 c not using pre-computed ones stored in files model_ki_{dist,angle}
49 c -----------------------------------------------------------------
52 c Alternative: reading from input
53 call card_concat(controlcard,.true.)
54 call reada(controlcard,"HOMOL_DIST",waga_dist,1.0d0)
55 call reada(controlcard,"HOMOL_ANGLE",waga_angle,1.0d0)
56 call reada(controlcard,"HOMOL_THETA",waga_theta,1.0d0) ! new
57 call reada(controlcard,"HOMOL_SCD",waga_d,1.0d0) ! new
58 call reada(controlcard,'DIST_CUT',dist_cut,5.0d0) ! for diff ways of calc sigma
59 call reada(controlcard,'DIST2_CUT',dist2_cut,9999.0d0)
60 call readi(controlcard,"HOMOL_NSET",homol_nset,1)
61 read2sigma=(index(controlcard,'READ2SIGMA').gt.0)
62 call readi(controlcard,"IHSET",ihset,1)
63 if (homol_nset.gt.1)then
64 call card_concat(controlcard,.true.)
65 read(controlcard,*) (waga_homology(i),i=1,homol_nset)
66 if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
67 write(iout,*) "iset homology_weight "
69 c write(iout,*) i,waga_homology(i)
72 iset=mod(kolor,homol_nset)+1
77 c write(iout,*) "waga_homology(",iset,")",waga_homology(iset)
79 cd write (iout,*) "nnt",nnt," nct",nct
91 c Reading HM global scores (prob not required)
94 do k=1,constr_homology
98 c open (4,file="HMscore")
99 c do k=1,constr_homology
100 c read (4,*,end=521) hmscore_tmp
101 c hmscore(k)=hmscore_tmp ! Another transformation can be used
102 c write(*,*) "Model", k, ":", hmscore(k)
113 c write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
115 if (read_homol_frag) then
116 call read_klapaucjusz
119 do k=1,constr_homology
121 read(inp,'(a)') pdbfile
122 c Next stament causes error upon compilation (?)
123 c if(me.eq.king.or. .not. out1file)
124 c write (iout,'(2a)') 'PDB data will be read from file ',
125 c & pdbfile(:ilen(pdbfile))
126 write (iout,'(a,5x,a)') 'HOMOL: Opening PDB file',
127 & pdbfile(:ilen(pdbfile))
128 open(ipdbin,file=pdbfile,status='old',err=33)
130 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
131 & pdbfile(:ilen(pdbfile))
134 c print *,'Begin reading pdb data'
136 c Files containing res sim or local scores (former containing sigmas)
139 write(kic2,'(bz,i2.2)') k
141 tpl_k_rescore="template"//kic2//".sco"
152 write (iout,'(i5,3f8.3,5x,3f8.3)') i,(crefjlee(j,i),j=1,3),
153 & (crefjlee(j,i+nres),j=1,3)
156 write (iout,*) "read_constr_homology: after reading pdb file"
160 c Distance restraints
163 C Copy the coordinates from reference coordinates (?)
167 c write (iout,*) "c(",j,i,") =",c(j,i)
171 c From read_dist_constr (commented out 25/11/2014 <-> res sim)
173 c write(iout,*) "tpl_k_rescore - ",tpl_k_rescore
174 open (ientin,file=tpl_k_rescore,status='old')
175 if (nnt.gt.1) rescore(k,1)=0.0d0
176 do irec=nnt,nct ! loop for reading res sim
178 read (ientin,*,end=1401) i_tmp,rescore2_tmp,rescore_tmp,
181 idomain(k,i_tmp)=idomain_tmp
182 rescore(k,i_tmp)=rescore_tmp
183 rescore2(k,i_tmp)=rescore2_tmp
184 write(iout,'(a7,i5,2f10.5,i5)') "rescore",
185 & i_tmp,rescore2_tmp,rescore_tmp,
189 read (ientin,*,end=1401) rescore_tmp
191 c rescore(k,irec)=rescore_tmp+1.0d0 ! to avoid 0 values
192 rescore(k,irec)=0.5d0*(rescore_tmp+0.5d0) ! alt transf to reduce scores
193 c write(iout,*) "rescore(",k,irec,") =",rescore(k,irec)
198 if (waga_dist.ne.0.0d0) then
206 distal=dsqrt(x12*x12+y12*y12+z12*z12)
207 c write (iout,*) k,i,j,distal,dist2_cut
209 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
210 & .and. distal.le.dist2_cut ) then
216 c write (iout,*) "k",k
217 c write (iout,*) "i",i," j",j," constr_homology",
225 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
227 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
228 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
229 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
231 if (odl(k,ii).le.dist_cut) then
232 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
235 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
236 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
238 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
239 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
243 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
253 c Theta, dihedral and SC retraints
255 if (waga_angle.gt.0.0d0) then
256 c open (ientin,file=tpl_k_sigma_dih,status='old')
257 c do irec=1,maxres-3 ! loop for reading sigma_dih
258 c read (ientin,*,end=1402) i,j,ki,l,sigma_dih(k,i+nnt-1) ! j,ki,l what for?
259 c if (i+nnt-1.gt.lim_dih) lim_dih=i+nnt-1 ! right?
260 c sigma_dih(k,i+nnt-1)=sigma_dih(k,i+nnt-1)* ! not inverse because of use of res. similarity
261 c & sigma_dih(k,i+nnt-1)
266 if (idomain(k,i).eq.0) then
270 dih(k,i)=phiref(i) ! right?
271 c read (ientin,*) sigma_dih(k,i) ! original variant
272 c write (iout,*) "dih(",k,i,") =",dih(k,i)
273 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
274 c & "rescore(",k,i-1,") =",rescore(k,i-1),
275 c & "rescore(",k,i-2,") =",rescore(k,i-2),
276 c & "rescore(",k,i-3,") =",rescore(k,i-3)
278 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
279 & rescore(k,i-2)+rescore(k,i-3))/4.0
280 c if (read2sigma) sigma_dih(k,i)=sigma_dih(k,i)/4.0
281 c write (iout,*) "Raw sigmas for dihedral angle restraints"
282 c write (iout,'(i5,10(2f8.2,4x))') i,sigma_dih(k,i)
283 c sigma_dih(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
284 c rescore(k,i-2)*rescore(k,i-3) ! right expression ?
285 c Instead of res sim other local measure of b/b str reliability possible
286 if (sigma_dih(k,i).ne.0)
287 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
288 c sigma_dih(k,i)=sigma_dih(k,i)*sigma_dih(k,i)
293 if (waga_theta.gt.0.0d0) then
294 c open (ientin,file=tpl_k_sigma_theta,status='old')
295 c do irec=1,maxres-2 ! loop for reading sigma_theta, right bounds?
296 c read (ientin,*,end=1403) i,j,ki,sigma_theta(k,i+nnt-1) ! j,ki what for?
297 c sigma_theta(k,i+nnt-1)=sigma_theta(k,i+nnt-1)* ! not inverse because of use of res. similarity
298 c & sigma_theta(k,i+nnt-1)
303 do i = nnt+2,nct ! right? without parallel.
304 c do i = i=1,nres ! alternative for bounds acc to readpdb?
305 c do i=ithet_start,ithet_end ! with FG parallel.
306 if (idomain(k,i).eq.0) then
310 thetatpl(k,i)=thetaref(i)
311 c write (iout,*) "thetatpl(",k,i,") =",thetatpl(k,i)
312 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
313 c & "rescore(",k,i-1,") =",rescore(k,i-1),
314 c & "rescore(",k,i-2,") =",rescore(k,i-2)
315 c read (ientin,*) sigma_theta(k,i) ! 1st variant
316 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
317 & rescore(k,i-2))/3.0
318 c if (read2sigma) sigma_theta(k,i)=sigma_theta(k,i)/3.0
319 if (sigma_theta(k,i).ne.0)
320 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
322 c sigma_theta(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
323 c rescore(k,i-2) ! right expression ?
324 c sigma_theta(k,i)=sigma_theta(k,i)*sigma_theta(k,i)
328 if (waga_d.gt.0.0d0) then
329 c open (ientin,file=tpl_k_sigma_d,status='old')
330 c do irec=1,maxres-1 ! loop for reading sigma_theta, right bounds?
331 c read (ientin,*,end=1404) i,j,sigma_d(k,i+nnt-1) ! j,ki what for?
332 c sigma_d(k,i+nnt-1)=sigma_d(k,i+nnt-1)* ! not inverse because of use of res. similarity
333 c & sigma_d(k,i+nnt-1)
337 do i = nnt,nct ! right? without parallel.
338 c do i=2,nres-1 ! alternative for bounds acc to readpdb?
339 c do i=loc_start,loc_end ! with FG parallel.
340 if (itype(i).eq.10) cycle
341 if (idomain(k,i).eq.0 ) then
348 c write (iout,*) "xxtpl(",k,i,") =",xxtpl(k,i)
349 c write (iout,*) "yytpl(",k,i,") =",yytpl(k,i)
350 c write (iout,*) "zztpl(",k,i,") =",zztpl(k,i)
351 c write(iout,*) "rescore(",k,i,") =",rescore(k,i)
352 sigma_d(k,i)=rescore(k,i) ! right expression ?
353 if (sigma_d(k,i).ne.0)
354 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
356 c sigma_d(k,i)=hmscore(k)*rescore(k,i) ! right expression ?
357 c sigma_d(k,i)=sigma_d(k,i)*sigma_d(k,i)
358 c read (ientin,*) sigma_d(k,i) ! 1st variant
363 c remove distance restraints not used in any model from the list
364 c shift data in all arrays
366 if (waga_dist.ne.0.0d0) then
372 if (ii_in_use(ii).eq.0.and.liiflag) then
376 if (ii_in_use(ii).ne.0.and..not.liiflag.or.
377 & .not.liiflag.and.ii.eq.lim_odl) then
378 if (ii.eq.lim_odl) then
384 do ki=iistart,lim_odl-iishift
385 ires_homo(ki)=ires_homo(ki+iishift)
386 jres_homo(ki)=jres_homo(ki+iishift)
387 ii_in_use(ki)=ii_in_use(ki+iishift)
388 do k=1,constr_homology
389 odl(k,ki)=odl(k,ki+iishift)
390 sigma_odl(k,ki)=sigma_odl(k,ki+iishift)
391 l_homo(k,ki)=l_homo(k,ki+iishift)
395 lim_odl=lim_odl-iishift
401 endif ! .not. klapaucjusz
403 if (constr_homology.gt.0) call homology_partition
404 if (constr_homology.gt.0) call init_int_table
405 cd write (iout,*) "homology_partition: lim_theta= ",lim_theta,
406 cd & "lim_xx=",lim_xx
407 c write (iout,*) "ithet_start =",ithet_start,"ithet_end =",ithet_end
408 c write (iout,*) "loc_start =",loc_start,"loc_end =",loc_end
412 if (.not.lprn) return
413 cd write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
414 if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
415 write (iout,*) "Distance restraints from templates"
417 write(iout,'(3i5,100(2f8.2,1x,l1,4x))')
418 & ii,ires_homo(ii),jres_homo(ii),
419 & (odl(ki,ii),1.0d0/dsqrt(sigma_odl(ki,ii)),l_homo(ki,ii),
420 & ki=1,constr_homology)
422 write (iout,*) "Dihedral angle restraints from templates"
424 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
425 & (rad2deg*dih(ki,i),
426 & rad2deg/dsqrt(sigma_dih(ki,i)),ki=1,constr_homology)
428 write (iout,*) "Virtual-bond angle restraints from templates"
430 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
431 & (rad2deg*thetatpl(ki,i),
432 & rad2deg/dsqrt(sigma_theta(ki,i)),ki=1,constr_homology)
434 write (iout,*) "SC restraints from templates"
436 write(iout,'(i5,100(4f8.2,4x))') i,
437 & (xxtpl(ki,i),yytpl(ki,i),zztpl(ki,i),
438 & 1.0d0/dsqrt(sigma_d(ki,i)),ki=1,constr_homology)
441 c -----------------------------------------------------------------
444 c----------------------------------------------------------------------
445 subroutine read_klapaucjusz
448 include 'DIMENSIONS.ZSCOPT'
449 include 'DIMENSIONS.FREE'
453 include 'COMMON.SETUP'
454 include 'COMMON.CONTROL'
455 include 'COMMON.CHAIN'
456 include 'COMMON.IOUNITS'
458 include 'COMMON.INTERACT'
459 include 'COMMON.NAMES'
460 include 'COMMON.HOMRESTR'
461 character*256 fragfile
462 integer ninclust(maxclust),inclust(max_template,maxclust),
463 & nresclust(maxclust),iresclust(maxres,maxclust)
466 character*24 model_ki_dist, model_ki_angle
467 character*500 controlcard
468 integer ki, i, j, k, l, ii_in_use(maxdim),i_tmp,idomain_tmp
469 integer idomain(max_template,maxres)
470 logical lprn /.true./
473 logical unres_pdb,liiflag
476 double precision rescore_tmp,x12,y12,z12,rescore2_tmp
477 double precision, dimension (max_template,maxres) :: rescore
478 double precision, dimension (max_template,maxres) :: rescore2
479 character*24 tpl_k_rescore
486 double precision chomo(3,maxres2+2,max_template)
487 call getenv("FRAGFILE",fragfile)
488 open(ientin,file=fragfile,status="old",err=10)
489 read(ientin,*) constr_homology,nclust
495 do k=1,constr_homology
496 read(ientin,'(a)') pdbfile
497 write (iout,'(a,5x,a)') 'KLAPAUCJUSZ: Opening PDB file',
498 & pdbfile(:ilen(pdbfile))
499 open(ipdbin,file=pdbfile,status='old',err=33)
501 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
502 & pdbfile(:ilen(pdbfile))
519 read(ientin,*) ninclust(i),nresclust(i)
520 read(ientin,*) (inclust(k,i),k=1,ninclust(i))
521 read(ientin,*) (iresclust(k,i),k=1,nresclust(i))
527 do ll = 1,ninclust(l)
535 idomain(k,iresclust(i,l)+1) = 1
537 idomain(k,iresclust(i,l)) = 1
541 c Distance restraints
544 C Copy the coordinates from reference coordinates (?)
548 c write (iout,*) "c(",j,i,") =",c(j,i)
551 call int_from_cart(.true.,.false.)
552 call sc_loc_geom(.false.)
557 if (waga_dist.ne.0.0d0) then
565 distal=dsqrt(x12*x12+y12*y12+z12*z12)
566 c write (iout,*) k,i,j,distal,dist2_cut
568 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
569 & .and. distal.le.dist2_cut ) then
575 c write (iout,*) "k",k
576 c write (iout,*) "i",i," j",j," constr_homology",
584 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
586 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
587 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
588 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
590 if (odl(k,ii).le.dist_cut) then
591 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
594 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
595 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
597 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
598 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
602 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
605 c l_homo(k,ii)=.false.
612 c Theta, dihedral and SC retraints
614 if (waga_angle.gt.0.0d0) then
616 if (idomain(k,i).eq.0) then
621 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
622 & rescore(k,i-2)+rescore(k,i-3))/4.0
623 c write (iout,*) "k",k," l",l," i",i," rescore",rescore(k,i),
624 c & " sigma_dihed",sigma_dih(k,i)
625 if (sigma_dih(k,i).ne.0)
626 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
631 if (waga_theta.gt.0.0d0) then
633 if (idomain(k,i).eq.0) then
634 c sigma_theta(k,i)=0.0
637 thetatpl(k,i)=thetaref(i)
638 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
639 & rescore(k,i-2))/3.0
640 if (sigma_theta(k,i).ne.0)
641 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
645 if (waga_d.gt.0.0d0) then
647 if (itype(i).eq.10) cycle
648 if (idomain(k,i).eq.0 ) then
655 sigma_d(k,i)=rescore(k,i)
656 if (sigma_d(k,i).ne.0)
657 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
658 if (i-nnt+1.gt.lim_xx) lim_xx=i-nnt+1
664 c remove distance restraints not used in any model from the list
665 c shift data in all arrays
667 if (waga_dist.ne.0.0d0) then
673 if (ii_in_use(ii).eq.0.and.liiflag) then
677 if (ii_in_use(ii).ne.0.and..not.liiflag.or.
678 & .not.liiflag.and.ii.eq.lim_odl) then
679 if (ii.eq.lim_odl) then
685 do ki=iistart,lim_odl-iishift
686 ires_homo(ki)=ires_homo(ki+iishift)
687 jres_homo(ki)=jres_homo(ki+iishift)
688 ii_in_use(ki)=ii_in_use(ki+iishift)
689 do k=1,constr_homology
690 odl(k,ki)=odl(k,ki+iishift)
691 sigma_odl(k,ki)=sigma_odl(k,ki+iishift)
692 l_homo(k,ki)=l_homo(k,ki+iishift)
696 lim_odl=lim_odl-iishift
703 10 stop "Error infragment file"