1 subroutine read_constr_homology
8 include 'COMMON.CONTROL'
10 include 'COMMON.IOUNITS'
12 include 'COMMON.INTERACT'
13 include 'COMMON.NAMES'
14 include 'COMMON.HOMRESTR'
15 include 'COMMON.HOMOLOGY'
20 c include 'include_unres/COMMON.VAR'
23 c double precision odl_temp,sigma_odl_temp,waga_theta,waga_d,
25 c common /przechowalnia/ odl_temp(maxres,maxres,max_template),
26 c & sigma_odl_temp(maxres,maxres,max_template)
28 character*24 model_ki_dist, model_ki_angle
29 character*500 controlcard
30 integer ki,i,ii,ik,j,k,l,ii_in_use(maxdim),i_tmp,idomain_tmp,
31 & lim_theta,lim_xx,irec,iistart,iishift,i10,i01
32 double precision distal
33 integer idomain(max_template,maxres)
40 c FP - Nov. 2014 Temporary specifications for new vars
42 double precision rescore_tmp,x12,y12,z12,rescore2_tmp,
44 double precision, dimension (max_template,maxres) :: rescore
45 double precision, dimension (max_template,maxres) :: rescore2
46 double precision, dimension (max_template,maxres) :: rescore3
47 character*24 tpl_k_rescore
48 c -----------------------------------------------------------------
49 c Reading multiple PDB ref structures and calculation of retraints
50 c not using pre-computed ones stored in files model_ki_{dist,angle}
52 c -----------------------------------------------------------------
55 c Alternative: reading from input
56 call card_concat(controlcard)
57 call reada(controlcard,"HOMOL_DIST",waga_dist,1.0d0)
58 call reada(controlcard,"HOMOL_ANGLE",waga_angle,1.0d0)
59 call reada(controlcard,"HOMOL_THETA",waga_theta,1.0d0) ! new
60 call reada(controlcard,"HOMOL_SCD",waga_d,1.0d0) ! new
61 call reada(controlcard,'DIST_CUT',dist_cut,5.0d0) ! for diff ways of calc sigma
62 call reada(controlcard,'DIST2_CUT',dist2_cut,9999.0d0)
63 call readi(controlcard,"HOMOL_NSET",homol_nset,1)
64 read2sigma=(index(controlcard,'READ2SIGMA').gt.0)
65 call readi(controlcard,"IHSET",ihset,1)
66 write (iout,*) "homol_nset ",homol_nset
67 if (homol_nset.gt.1)then
68 call card_concat(controlcard)
69 read(controlcard,*) (waga_homology(i),i=1,homol_nset)
70 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
71 c write(iout,*) "iset homology_weight "
73 c write(iout,*) i,waga_homology(i)
76 iset=mod(kolor,homol_nset)+1
81 c write(iout,*) "waga_homology(",iset,")",waga_homology(iset)
83 cd write (iout,*) "nnt",nnt," nct",nct
95 c Reading HM global scores (prob not required)
98 do k=1,constr_homology
102 c open (4,file="HMscore")
103 c do k=1,constr_homology
104 c read (4,*,end=521) hmscore_tmp
105 c hmscore(k)=hmscore_tmp ! Another transformation can be used
106 c write(*,*) "Model", k, ":", hmscore(k)
117 c write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
119 if (read_homol_frag) then
120 call read_klapaucjusz
123 do k=1,constr_homology
125 read(inp,'(a)') pdbfile
126 c Next stament causes error upon compilation (?)
127 c if(me.eq.king.or. .not. out1file)
128 c write (iout,'(2a)') 'PDB data will be read from file ',
129 c & pdbfile(:ilen(pdbfile))
130 write (iout,'(a,5x,a)') 'HOMOL: Opening PDB file',
131 & pdbfile(:ilen(pdbfile))
132 open(ipdbin,file=pdbfile,status='old',err=33)
134 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
135 & pdbfile(:ilen(pdbfile))
138 c print *,'Begin reading pdb data'
140 c Files containing res sim or local scores (former containing sigmas)
143 write(kic2,'(bz,i2.2)') k
145 tpl_k_rescore="template"//kic2//".sco"
150 call readpdb_template(k)
153 call readpdb(out_template_coord)
166 write (iout,'(i5,3f8.3,5x,3f8.3)') i,(crefjlee(j,i),j=1,3),
167 & (crefjlee(j,i+nres),j=1,3)
169 write (iout,*) "read_constr_homology: after reading pdb file"
174 c Distance restraints
177 C Copy the coordinates from reference coordinates (?)
178 do i=1,2*nres_chomo(k)
181 c write (iout,*) "c(",j,i,") =",c(j,i)
185 c From read_dist_constr (commented out 25/11/2014 <-> res sim)
187 c write(iout,*) "tpl_k_rescore - ",tpl_k_rescore
188 open (ientin,file=tpl_k_rescore,status='old')
189 if (nnt.gt.1) rescore(k,1)=0.0d0
190 do irec=nnt,nct ! loop for reading res sim
192 read (ientin,*,end=1401) i_tmp,rescore2_tmp,rescore_tmp,
193 & rescore3_tmp,idomain_tmp
195 idomain(k,i_tmp)=idomain_tmp
196 rescore(k,i_tmp)=rescore_tmp
197 rescore2(k,i_tmp)=rescore2_tmp
198 rescore3(k,i_tmp)=rescore3_tmp
199 write(iout,'(a7,i5,3f10.5,i5)') "rescore",
200 & i_tmp,rescore2_tmp,rescore_tmp,
201 & rescore3_tmp,idomain_tmp
204 read (ientin,*,end=1401) rescore_tmp
206 c rescore(k,irec)=rescore_tmp+1.0d0 ! to avoid 0 values
207 rescore(k,irec)=0.5d0*(rescore_tmp+0.5d0) ! alt transf to reduce scores
208 c write(iout,*) "rescore(",k,irec,") =",rescore(k,irec)
213 if (waga_dist.ne.0.0d0) then
221 distal=dsqrt(x12*x12+y12*y12+z12*z12)
222 c write (iout,*) k,i,j,distal,dist2_cut
224 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
225 & .and. distal.le.dist2_cut ) then
231 c write (iout,*) "k",k
232 c write (iout,*) "i",i," j",j," constr_homology",
240 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
242 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
243 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
244 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
246 if (odl(k,ii).le.dist_cut) then
247 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
250 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
251 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
253 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
254 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
258 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
267 c write (iout,*) "Distance restraints set"
270 c Theta, dihedral and SC retraints
272 if (waga_angle.gt.0.0d0) then
273 c open (ientin,file=tpl_k_sigma_dih,status='old')
274 c do irec=1,maxres-3 ! loop for reading sigma_dih
275 c read (ientin,*,end=1402) i,j,ki,l,sigma_dih(k,i+nnt-1) ! j,ki,l what for?
276 c if (i+nnt-1.gt.lim_dih) lim_dih=i+nnt-1 ! right?
277 c sigma_dih(k,i+nnt-1)=sigma_dih(k,i+nnt-1)* ! not inverse because of use of res. similarity
278 c & sigma_dih(k,i+nnt-1)
283 if (idomain(k,i).eq.0) then
287 dih(k,i)=phiref(i) ! right?
288 c read (ientin,*) sigma_dih(k,i) ! original variant
289 c write (iout,*) "dih(",k,i,") =",dih(k,i)
290 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
291 c & "rescore(",k,i-1,") =",rescore(k,i-1),
292 c & "rescore(",k,i-2,") =",rescore(k,i-2),
293 c & "rescore(",k,i-3,") =",rescore(k,i-3)
295 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
296 & rescore(k,i-2)+rescore(k,i-3))/4.0
297 c if (read2sigma) sigma_dih(k,i)=sigma_dih(k,i)/4.0
298 c write (iout,*) "Raw sigmas for dihedral angle restraints"
299 c write (iout,'(i5,10(2f8.2,4x))') i,sigma_dih(k,i)
300 c sigma_dih(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
301 c rescore(k,i-2)*rescore(k,i-3) ! right expression ?
302 c Instead of res sim other local measure of b/b str reliability possible
303 if (sigma_dih(k,i).ne.0)
304 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
305 c sigma_dih(k,i)=sigma_dih(k,i)*sigma_dih(k,i)
309 c write (iout,*) "Dihedral angle restraints set"
312 if (waga_theta.gt.0.0d0) then
313 c open (ientin,file=tpl_k_sigma_theta,status='old')
314 c do irec=1,maxres-2 ! loop for reading sigma_theta, right bounds?
315 c read (ientin,*,end=1403) i,j,ki,sigma_theta(k,i+nnt-1) ! j,ki what for?
316 c sigma_theta(k,i+nnt-1)=sigma_theta(k,i+nnt-1)* ! not inverse because of use of res. similarity
317 c & sigma_theta(k,i+nnt-1)
322 do i = nnt+2,nct ! right? without parallel.
323 c do i = i=1,nres ! alternative for bounds acc to readpdb?
324 c do i=ithet_start,ithet_end ! with FG parallel.
325 if (idomain(k,i).eq.0) then
329 thetatpl(k,i)=thetaref(i)
330 c write (iout,*) "thetatpl(",k,i,") =",thetatpl(k,i)
331 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
332 c & "rescore(",k,i-1,") =",rescore(k,i-1),
333 c & "rescore(",k,i-2,") =",rescore(k,i-2)
334 c read (ientin,*) sigma_theta(k,i) ! 1st variant
335 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
336 & rescore(k,i-2))/3.0
337 c if (read2sigma) sigma_theta(k,i)=sigma_theta(k,i)/3.0
338 if (sigma_theta(k,i).ne.0)
339 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
341 c sigma_theta(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
342 c rescore(k,i-2) ! right expression ?
343 c sigma_theta(k,i)=sigma_theta(k,i)*sigma_theta(k,i)
346 c write (iout,*) "Angle restraints set"
349 if (waga_d.gt.0.0d0) then
350 c open (ientin,file=tpl_k_sigma_d,status='old')
351 c do irec=1,maxres-1 ! loop for reading sigma_theta, right bounds?
352 c read (ientin,*,end=1404) i,j,sigma_d(k,i+nnt-1) ! j,ki what for?
353 c sigma_d(k,i+nnt-1)=sigma_d(k,i+nnt-1)* ! not inverse because of use of res. similarity
354 c & sigma_d(k,i+nnt-1)
358 do i = nnt,nct ! right? without parallel.
359 c do i=2,nres-1 ! alternative for bounds acc to readpdb?
360 c do i=loc_start,loc_end ! with FG parallel.
361 if (itype(i).eq.10) cycle
362 if (idomain(k,i).eq.0 ) then
369 c write (iout,*) "xxtpl(",k,i,") =",xxtpl(k,i)
370 c write (iout,*) "yytpl(",k,i,") =",yytpl(k,i)
371 c write (iout,*) "zztpl(",k,i,") =",zztpl(k,i)
372 c write(iout,*) "rescore(",k,i,") =",rescore(k,i)
373 sigma_d(k,i)=rescore3(k,i) ! right expression ?
374 if (sigma_d(k,i).ne.0)
375 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
377 c sigma_d(k,i)=hmscore(k)*rescore(k,i) ! right expression ?
378 c sigma_d(k,i)=sigma_d(k,i)*sigma_d(k,i)
379 c read (ientin,*) sigma_d(k,i) ! 1st variant
383 c write (iout,*) "SC restraints set"
386 c remove distance restraints not used in any model from the list
387 c shift data in all arrays
389 c write (iout,*) "waga_dist",waga_dist," nnt",nnt," nct",nct
390 if (waga_dist.ne.0.0d0) then
397 c if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
398 c & .and. distal.le.dist2_cut ) then
399 c write (iout,*) "i",i," j",j," ii",ii
401 if (ii_in_use(ii).eq.0.and.liiflag.or.
402 & ii_in_use(ii).eq.1.and.liiflag.and.ii.eq.lim_odl) then
409 if(i10.eq.lim_odl) i10=i10+1
411 ires_homo(iistart+ki)=ires_homo(ki+i01)
412 jres_homo(iistart+ki)=jres_homo(ki+i01)
413 ii_in_use(iistart+ki)=ii_in_use(ki+i01)
414 do k=1,constr_homology
415 odl(k,iistart+ki)=odl(k,ki+i01)
416 sigma_odl(k,iistart+ki)=sigma_odl(k,ki+i01)
417 l_homo(k,iistart+ki)=l_homo(k,ki+i01)
420 iistart=iistart+i10-i01
423 if (ii_in_use(ii).ne.0.and..not.liiflag) then
431 c write (iout,*) "Removing distances completed"
433 endif ! .not. klapaucjusz
435 if (constr_homology.gt.0) call homology_partition
436 c write (iout,*) "After homology_partition"
438 if (constr_homology.gt.0) call init_int_table
439 c write (iout,*) "After init_int_table"
441 c write (iout,*) "ithet_start =",ithet_start,"ithet_end =",ithet_end
442 c write (iout,*) "loc_start =",loc_start,"loc_end =",loc_end
446 if (.not.out_template_restr) return
447 cd write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
448 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
449 write (iout,*) "Distance restraints from templates"
451 write(iout,'(3i5,100(2f8.2,1x,l1,4x))')
452 & ii,ires_homo(ii),jres_homo(ii),
453 & (odl(ki,ii),1.0d0/dsqrt(sigma_odl(ki,ii)),l_homo(ki,ii),
454 & ki=1,constr_homology)
456 write (iout,*) "Dihedral angle restraints from templates"
458 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
459 & (rad2deg*dih(ki,i),
460 & rad2deg/dsqrt(sigma_dih(ki,i)),ki=1,constr_homology)
462 write (iout,*) "Virtual-bond angle restraints from templates"
464 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
465 & (rad2deg*thetatpl(ki,i),
466 & rad2deg/dsqrt(sigma_theta(ki,i)),ki=1,constr_homology)
468 write (iout,*) "SC restraints from templates"
470 write(iout,'(i5,100(4f8.2,4x))') i,
471 & (xxtpl(ki,i),yytpl(ki,i),zztpl(ki,i),
472 & 1.0d0/dsqrt(sigma_d(ki,i)),ki=1,constr_homology)
475 c -----------------------------------------------------------------
478 c----------------------------------------------------------------------
479 subroutine read_klapaucjusz
485 include 'COMMON.SETUP'
486 include 'COMMON.CONTROL'
487 include 'COMMON.HOMOLOGY'
488 include 'COMMON.CHAIN'
489 include 'COMMON.IOUNITS'
491 include 'COMMON.INTERACT'
492 include 'COMMON.NAMES'
493 include 'COMMON.HOMRESTR'
494 character*256 fragfile
495 integer ninclust(maxclust),inclust(max_template,maxclust),
496 & nresclust(maxclust),iresclust(maxres,maxclust)
499 character*24 model_ki_dist, model_ki_angle
500 character*500 controlcard
501 integer ki, i, j, k, l, ii_in_use(maxdim),i_tmp,idomain_tmp
502 integer idomain(max_template,maxres)
504 logical lprn /.true./
511 double precision rescore_tmp,x12,y12,z12,rescore2_tmp
512 double precision, dimension (max_template,maxres) :: rescore
513 double precision, dimension (max_template,maxres) :: rescore2
514 character*24 tpl_k_rescore
521 call getenv("FRAGFILE",fragfile)
522 write (iout,*) "read_klapaucjusz ",fragfile
523 open(ientin,file=fragfile,status="old",err=10)
524 read(ientin,*) constr_homology,nclust
530 do k=1,constr_homology
531 read(ientin,'(a)') pdbfile
532 write (iout,'(a,5x,a)') 'KLAPAUCJUSZ: Opening PDB file',
533 & pdbfile(:ilen(pdbfile))
534 open(ipdbin,file=pdbfile,status='old',err=33)
536 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
537 & pdbfile(:ilen(pdbfile))
542 call readpdb_template(k)
547 c chomo(j,i,k)=c(j,i)
557 read(ientin,*) ninclust(i),nresclust(i)
558 read(ientin,*) (inclust(k,i),k=1,ninclust(i))
559 read(ientin,*) (iresclust(k,i),k=1,nresclust(i))
566 do ll = 1,ninclust(l)
574 idomain(k,iresclust(i,l)+1) = 1
576 idomain(k,iresclust(i,l)) = 1
580 c Distance restraints
583 C Copy the coordinates from reference coordinates (?)
589 c write (iout,*) "c(",j,i,") =",c(j,i)
592 call int_from_cart(.true.,.false.)
593 call sc_loc_geom(.false.)
599 if (waga_dist.ne.0.0d0) then
607 distal=dsqrt(x12*x12+y12*y12+z12*z12)
608 c write (iout,*) k,i,j,distal,dist2_cut
610 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
611 & .and. distal.le.dist2_cut ) then
617 c write (iout,*) "k",k
618 c write (iout,*) "i",i," j",j," constr_homology",
626 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
628 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
629 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
630 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
632 if (odl(k,ii).le.dist_cut) then
633 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
636 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
637 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
639 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
640 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
644 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
647 c l_homo(k,ii)=.false.
654 c Theta, dihedral and SC retraints
656 if (waga_angle.gt.0.0d0) then
658 if (idomain(k,i).eq.0) then
663 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
664 & rescore(k,i-2)+rescore(k,i-3))/4.0
665 c write (iout,*) "k",k," l",l," i",i," rescore",rescore(k,i),
666 c & " sigma_dihed",sigma_dih(k,i)
667 if (sigma_dih(k,i).ne.0)
668 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
673 if (waga_theta.gt.0.0d0) then
675 if (idomain(k,i).eq.0) then
676 c sigma_theta(k,i)=0.0
679 thetatpl(k,i)=thetaref(i)
680 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
681 & rescore(k,i-2))/3.0
682 if (sigma_theta(k,i).ne.0)
683 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
687 if (waga_d.gt.0.0d0) then
689 if (itype(i).eq.10) cycle
690 if (idomain(k,i).eq.0 ) then
697 sigma_d(k,i)=rescore(k,i)
698 if (sigma_d(k,i).ne.0)
699 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
700 if (i-nnt+1.gt.lim_xx) lim_xx=i-nnt+1
706 c remove distance restraints not used in any model from the list
707 c shift data in all arrays
709 if (waga_dist.ne.0.0d0) then
715 if (ii_in_use(ii).eq.0.and.liiflag) then
719 if (ii_in_use(ii).ne.0.and..not.liiflag.or.
720 & .not.liiflag.and.ii.eq.lim_odl) then
721 if (ii.eq.lim_odl) then
727 do ki=iistart,lim_odl-iishift
728 ires_homo(ki)=ires_homo(ki+iishift)
729 jres_homo(ki)=jres_homo(ki+iishift)
730 ii_in_use(ki)=ii_in_use(ki+iishift)
731 do k=1,constr_homology
732 odl(k,ki)=odl(k,ki+iishift)
733 sigma_odl(k,ki)=sigma_odl(k,ki+iishift)
734 l_homo(k,ki)=l_homo(k,ki+iishift)
738 lim_odl=lim_odl-iishift
744 write (iout,*) "ires_homo and jres_homo arrays, lim_odl",lim_odl
746 write (iout,*) i,ires_homo(i),jres_homo(i)
750 10 stop "Error in fragment file"