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 dist1cut=(index(controlcard,'DIST1CUT').gt.0)
64 call readi(controlcard,"HOMOL_NSET",homol_nset,1)
65 read2sigma=(index(controlcard,'READ2SIGMA').gt.0)
66 call readi(controlcard,"IHSET",ihset,1)
67 write (iout,*) "homol_nset ",homol_nset
68 if (homol_nset.gt.1)then
69 call card_concat(controlcard)
70 read(controlcard,*) (waga_homology(i),i=1,homol_nset)
71 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
72 c write(iout,*) "iset homology_weight "
74 c write(iout,*) i,waga_homology(i)
77 iset=mod(kolor,homol_nset)+1
82 c write(iout,*) "waga_homology(",iset,")",waga_homology(iset)
84 cd write (iout,*) "nnt",nnt," nct",nct
96 c Reading HM global scores (prob not required)
99 do k=1,constr_homology
103 c open (4,file="HMscore")
104 c do k=1,constr_homology
105 c read (4,*,end=521) hmscore_tmp
106 c hmscore(k)=hmscore_tmp ! Another transformation can be used
107 c write(*,*) "Model", k, ":", hmscore(k)
118 c write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
120 if (read_homol_frag) then
121 call read_klapaucjusz
124 do k=1,constr_homology
126 read(inp,'(a)') pdbfile
127 c Next stament causes error upon compilation (?)
128 c if(me.eq.king.or. .not. out1file)
129 c write (iout,'(2a)') 'PDB data will be read from file ',
130 c & pdbfile(:ilen(pdbfile))
131 write (iout,'(a,5x,a)') 'HOMOL: Opening PDB file',
132 & pdbfile(:ilen(pdbfile))
133 open(ipdbin,file=pdbfile,status='old',err=33)
135 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
136 & pdbfile(:ilen(pdbfile))
139 c print *,'Begin reading pdb data'
141 c Files containing res sim or local scores (former containing sigmas)
144 write(kic2,'(bz,i2.2)') k
146 tpl_k_rescore="template"//kic2//".sco"
151 call readpdb_template(k)
154 call readpdb(out_template_coord)
167 write (iout,'(i5,3f8.3,5x,3f8.3)') i,(crefjlee(j,i),j=1,3),
168 & (crefjlee(j,i+nres),j=1,3)
170 write (iout,*) "read_constr_homology: after reading pdb file"
175 c Distance restraints
178 C Copy the coordinates from reference coordinates (?)
179 do i=1,2*nres_chomo(k)
182 c write (iout,*) "c(",j,i,") =",c(j,i)
186 c From read_dist_constr (commented out 25/11/2014 <-> res sim)
188 c write(iout,*) "tpl_k_rescore - ",tpl_k_rescore
189 open (ientin,file=tpl_k_rescore,status='old')
190 if (nnt.gt.1) rescore(k,1)=0.0d0
191 do irec=nnt,nct ! loop for reading res sim
193 read (ientin,*,end=1401) i_tmp,rescore2_tmp,rescore_tmp,
194 & rescore3_tmp,idomain_tmp
196 idomain(k,i_tmp)=idomain_tmp
197 rescore(k,i_tmp)=rescore_tmp
198 rescore2(k,i_tmp)=rescore2_tmp
199 rescore3(k,i_tmp)=rescore3_tmp
200 write(iout,'(a7,i5,3f10.5,i5)') "rescore",
201 & i_tmp,rescore2_tmp,rescore_tmp,
202 & rescore3_tmp,idomain_tmp
205 read (ientin,*,end=1401) rescore_tmp
207 c rescore(k,irec)=rescore_tmp+1.0d0 ! to avoid 0 values
208 rescore(k,irec)=0.5d0*(rescore_tmp+0.5d0) ! alt transf to reduce scores
209 c write(iout,*) "rescore(",k,irec,") =",rescore(k,irec)
214 if (waga_dist.ne.0.0d0) then
222 distal=dsqrt(x12*x12+y12*y12+z12*z12)
223 c write (iout,*) k,i,j,distal,dist2_cut
224 if (dist1cut .and. k.gt.1) then
226 if (l_homo(1,ii)) then
232 sigma_odl(k,ii)=sigma_odl(1,ii)
237 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
238 & .and. distal.le.dist2_cut ) then
244 c write (iout,*) "k",k
245 c write (iout,*) "i",i," j",j," constr_homology",
253 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
255 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
256 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
257 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
259 if (odl(k,ii).le.dist_cut) then
260 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
263 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
264 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
266 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
267 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
271 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
274 ct l_homo(k,ii)=.false.
281 c write (iout,*) "Distance restraints set"
284 c Theta, dihedral and SC retraints
286 if (waga_angle.gt.0.0d0) then
287 c open (ientin,file=tpl_k_sigma_dih,status='old')
288 c do irec=1,maxres-3 ! loop for reading sigma_dih
289 c read (ientin,*,end=1402) i,j,ki,l,sigma_dih(k,i+nnt-1) ! j,ki,l what for?
290 c if (i+nnt-1.gt.lim_dih) lim_dih=i+nnt-1 ! right?
291 c sigma_dih(k,i+nnt-1)=sigma_dih(k,i+nnt-1)* ! not inverse because of use of res. similarity
292 c & sigma_dih(k,i+nnt-1)
297 if (idomain(k,i).eq.0) then
301 dih(k,i)=phiref(i) ! right?
302 c read (ientin,*) sigma_dih(k,i) ! original variant
303 c write (iout,*) "dih(",k,i,") =",dih(k,i)
304 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
305 c & "rescore(",k,i-1,") =",rescore(k,i-1),
306 c & "rescore(",k,i-2,") =",rescore(k,i-2),
307 c & "rescore(",k,i-3,") =",rescore(k,i-3)
309 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
310 & rescore(k,i-2)+rescore(k,i-3))/4.0
311 c if (read2sigma) sigma_dih(k,i)=sigma_dih(k,i)/4.0
312 c write (iout,*) "Raw sigmas for dihedral angle restraints"
313 c write (iout,'(i5,10(2f8.2,4x))') i,sigma_dih(k,i)
314 c sigma_dih(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
315 c rescore(k,i-2)*rescore(k,i-3) ! right expression ?
316 c Instead of res sim other local measure of b/b str reliability possible
317 if (sigma_dih(k,i).ne.0)
318 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
319 c sigma_dih(k,i)=sigma_dih(k,i)*sigma_dih(k,i)
323 c write (iout,*) "Dihedral angle restraints set"
326 if (waga_theta.gt.0.0d0) then
327 c open (ientin,file=tpl_k_sigma_theta,status='old')
328 c do irec=1,maxres-2 ! loop for reading sigma_theta, right bounds?
329 c read (ientin,*,end=1403) i,j,ki,sigma_theta(k,i+nnt-1) ! j,ki what for?
330 c sigma_theta(k,i+nnt-1)=sigma_theta(k,i+nnt-1)* ! not inverse because of use of res. similarity
331 c & sigma_theta(k,i+nnt-1)
336 do i = nnt+2,nct ! right? without parallel.
337 c do i = i=1,nres ! alternative for bounds acc to readpdb?
338 c do i=ithet_start,ithet_end ! with FG parallel.
339 if (idomain(k,i).eq.0) then
343 thetatpl(k,i)=thetaref(i)
344 c write (iout,*) "thetatpl(",k,i,") =",thetatpl(k,i)
345 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
346 c & "rescore(",k,i-1,") =",rescore(k,i-1),
347 c & "rescore(",k,i-2,") =",rescore(k,i-2)
348 c read (ientin,*) sigma_theta(k,i) ! 1st variant
349 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
350 & rescore(k,i-2))/3.0
351 c if (read2sigma) sigma_theta(k,i)=sigma_theta(k,i)/3.0
352 if (sigma_theta(k,i).ne.0)
353 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
355 c sigma_theta(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
356 c rescore(k,i-2) ! right expression ?
357 c sigma_theta(k,i)=sigma_theta(k,i)*sigma_theta(k,i)
360 c write (iout,*) "Angle restraints set"
363 if (waga_d.gt.0.0d0) then
364 c open (ientin,file=tpl_k_sigma_d,status='old')
365 c do irec=1,maxres-1 ! loop for reading sigma_theta, right bounds?
366 c read (ientin,*,end=1404) i,j,sigma_d(k,i+nnt-1) ! j,ki what for?
367 c sigma_d(k,i+nnt-1)=sigma_d(k,i+nnt-1)* ! not inverse because of use of res. similarity
368 c & sigma_d(k,i+nnt-1)
372 do i = nnt,nct ! right? without parallel.
373 c do i=2,nres-1 ! alternative for bounds acc to readpdb?
374 c do i=loc_start,loc_end ! with FG parallel.
375 if (itype(i).eq.10) cycle
376 if (idomain(k,i).eq.0 ) then
383 c write (iout,*) "xxtpl(",k,i,") =",xxtpl(k,i)
384 c write (iout,*) "yytpl(",k,i,") =",yytpl(k,i)
385 c write (iout,*) "zztpl(",k,i,") =",zztpl(k,i)
386 c write(iout,*) "rescore(",k,i,") =",rescore(k,i)
387 sigma_d(k,i)=rescore3(k,i) ! right expression ?
388 if (sigma_d(k,i).ne.0)
389 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
391 c sigma_d(k,i)=hmscore(k)*rescore(k,i) ! right expression ?
392 c sigma_d(k,i)=sigma_d(k,i)*sigma_d(k,i)
393 c read (ientin,*) sigma_d(k,i) ! 1st variant
397 c write (iout,*) "SC restraints set"
400 c remove distance restraints not used in any model from the list
401 c shift data in all arrays
403 c write (iout,*) "waga_dist",waga_dist," nnt",nnt," nct",nct
404 if (waga_dist.ne.0.0d0) then
411 c if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
412 c & .and. distal.le.dist2_cut ) then
413 c write (iout,*) "i",i," j",j," ii",ii
415 if (ii_in_use(ii).eq.0.and.liiflag.or.
416 & ii_in_use(ii).eq.1.and.liiflag.and.ii.eq.lim_odl) then
423 if(i10.eq.lim_odl) i10=i10+1
425 ires_homo(iistart+ki)=ires_homo(ki+i01)
426 jres_homo(iistart+ki)=jres_homo(ki+i01)
427 ii_in_use(iistart+ki)=ii_in_use(ki+i01)
428 do k=1,constr_homology
429 odl(k,iistart+ki)=odl(k,ki+i01)
430 sigma_odl(k,iistart+ki)=sigma_odl(k,ki+i01)
431 l_homo(k,iistart+ki)=l_homo(k,ki+i01)
434 iistart=iistart+i10-i01
437 if (ii_in_use(ii).ne.0.and..not.liiflag) then
445 c write (iout,*) "Removing distances completed"
447 endif ! .not. klapaucjusz
449 if (constr_homology.gt.0) call homology_partition
450 c write (iout,*) "After homology_partition"
452 if (constr_homology.gt.0) call init_int_table
453 c write (iout,*) "After init_int_table"
455 c write (iout,*) "ithet_start =",ithet_start,"ithet_end =",ithet_end
456 c write (iout,*) "loc_start =",loc_start,"loc_end =",loc_end
460 if (.not.out_template_restr) return
461 cd write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
462 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
463 write (iout,*) "Distance restraints from templates"
465 write(iout,'(3i5,100(2f8.2,1x,l1,4x))')
466 & ii,ires_homo(ii),jres_homo(ii),
467 & (odl(ki,ii),1.0d0/dsqrt(sigma_odl(ki,ii)),l_homo(ki,ii),
468 & ki=1,constr_homology)
470 write (iout,*) "Dihedral angle restraints from templates"
472 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
473 & (rad2deg*dih(ki,i),
474 & rad2deg/dsqrt(sigma_dih(ki,i)),ki=1,constr_homology)
476 write (iout,*) "Virtual-bond angle restraints from templates"
478 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
479 & (rad2deg*thetatpl(ki,i),
480 & rad2deg/dsqrt(sigma_theta(ki,i)),ki=1,constr_homology)
482 write (iout,*) "SC restraints from templates"
484 write(iout,'(i5,100(4f8.2,4x))') i,
485 & (xxtpl(ki,i),yytpl(ki,i),zztpl(ki,i),
486 & 1.0d0/dsqrt(sigma_d(ki,i)),ki=1,constr_homology)
489 c -----------------------------------------------------------------
492 c----------------------------------------------------------------------
493 subroutine read_klapaucjusz
499 include 'COMMON.SETUP'
500 include 'COMMON.CONTROL'
501 include 'COMMON.HOMOLOGY'
502 include 'COMMON.CHAIN'
503 include 'COMMON.IOUNITS'
505 include 'COMMON.INTERACT'
506 include 'COMMON.NAMES'
507 include 'COMMON.HOMRESTR'
508 character*256 fragfile
509 integer ninclust(maxclust),inclust(max_template,maxclust),
510 & nresclust(maxclust),iresclust(maxres,maxclust)
513 character*24 model_ki_dist, model_ki_angle
514 character*500 controlcard
515 integer ki, i, j, k, l, ii_in_use(maxdim),i_tmp,idomain_tmp
516 integer idomain(max_template,maxres)
518 logical lprn /.true./
525 double precision rescore_tmp,x12,y12,z12,rescore2_tmp
526 double precision, dimension (max_template,maxres) :: rescore
527 double precision, dimension (max_template,maxres) :: rescore2
528 character*24 tpl_k_rescore
535 call getenv("FRAGFILE",fragfile)
536 write (iout,*) "read_klapaucjusz ",fragfile
537 open(ientin,file=fragfile,status="old",err=10)
538 read(ientin,*) constr_homology,nclust
544 do k=1,constr_homology
545 read(ientin,'(a)') pdbfile
546 write (iout,'(a,5x,a)') 'KLAPAUCJUSZ: Opening PDB file',
547 & pdbfile(:ilen(pdbfile))
548 open(ipdbin,file=pdbfile,status='old',err=33)
550 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
551 & pdbfile(:ilen(pdbfile))
556 call readpdb_template(k)
561 c chomo(j,i,k)=c(j,i)
571 read(ientin,*) ninclust(i),nresclust(i)
572 read(ientin,*) (inclust(k,i),k=1,ninclust(i))
573 read(ientin,*) (iresclust(k,i),k=1,nresclust(i))
580 do ll = 1,ninclust(l)
588 idomain(k,iresclust(i,l)+1) = 1
590 idomain(k,iresclust(i,l)) = 1
594 c Distance restraints
597 C Copy the coordinates from reference coordinates (?)
603 c write (iout,*) "c(",j,i,") =",c(j,i)
606 call int_from_cart(.true.,.false.)
607 call sc_loc_geom(.false.)
613 if (waga_dist.ne.0.0d0) then
621 distal=dsqrt(x12*x12+y12*y12+z12*z12)
622 c write (iout,*) k,i,j,distal,dist2_cut
624 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
625 & .and. distal.le.dist2_cut ) then
631 c write (iout,*) "k",k
632 c write (iout,*) "i",i," j",j," constr_homology",
640 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
642 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
643 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
644 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
646 if (odl(k,ii).le.dist_cut) then
647 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
650 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
651 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
653 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
654 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
658 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
661 c l_homo(k,ii)=.false.
668 c Theta, dihedral and SC retraints
670 if (waga_angle.gt.0.0d0) then
672 if (idomain(k,i).eq.0) then
677 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
678 & rescore(k,i-2)+rescore(k,i-3))/4.0
679 c write (iout,*) "k",k," l",l," i",i," rescore",rescore(k,i),
680 c & " sigma_dihed",sigma_dih(k,i)
681 if (sigma_dih(k,i).ne.0)
682 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
687 if (waga_theta.gt.0.0d0) then
689 if (idomain(k,i).eq.0) then
690 c sigma_theta(k,i)=0.0
693 thetatpl(k,i)=thetaref(i)
694 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
695 & rescore(k,i-2))/3.0
696 if (sigma_theta(k,i).ne.0)
697 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
701 if (waga_d.gt.0.0d0) then
703 if (itype(i).eq.10) cycle
704 if (idomain(k,i).eq.0 ) then
711 sigma_d(k,i)=rescore(k,i)
712 if (sigma_d(k,i).ne.0)
713 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
714 if (i-nnt+1.gt.lim_xx) lim_xx=i-nnt+1
720 c remove distance restraints not used in any model from the list
721 c shift data in all arrays
723 if (waga_dist.ne.0.0d0) then
729 if (ii_in_use(ii).eq.0.and.liiflag) then
733 if (ii_in_use(ii).ne.0.and..not.liiflag.or.
734 & .not.liiflag.and.ii.eq.lim_odl) then
735 if (ii.eq.lim_odl) then
741 do ki=iistart,lim_odl-iishift
742 ires_homo(ki)=ires_homo(ki+iishift)
743 jres_homo(ki)=jres_homo(ki+iishift)
744 ii_in_use(ki)=ii_in_use(ki+iishift)
745 do k=1,constr_homology
746 odl(k,ki)=odl(k,ki+iishift)
747 sigma_odl(k,ki)=sigma_odl(k,ki+iishift)
748 l_homo(k,ki)=l_homo(k,ki+iishift)
752 lim_odl=lim_odl-iishift
758 write (iout,*) "ires_homo and jres_homo arrays, lim_odl",lim_odl
760 write (iout,*) i,ires_homo(i),jres_homo(i)
764 10 stop "Error in fragment file"