1 subroutine read_constr_homology
5 include 'DIMENSIONS.ZSCOPT'
6 include 'DIMENSIONS.FREE'
10 include 'COMMON.SETUP'
11 include 'COMMON.CONTROL'
12 include 'COMMON.CHAIN'
13 include 'COMMON.IOUNITS'
15 include 'COMMON.INTERACT'
16 include 'COMMON.NAMES'
17 include 'COMMON.HOMRESTR'
18 include 'COMMON.HOMOLOGY'
23 c include 'include_unres/COMMON.VAR'
26 c double precision odl_temp,sigma_odl_temp,waga_theta,waga_d,
28 c common /przechowalnia/ odl_temp(maxres,maxres,max_template),
29 c & sigma_odl_temp(maxres,maxres,max_template)
31 character*24 model_ki_dist, model_ki_angle
32 character*500 controlcard
33 integer ki,i,ii,ik,j,k,l,ii_in_use(maxdim),i_tmp,idomain_tmp,
34 & lim_theta,lim_xx,irec,iistart,iishift,i10,i01
35 double precision distal
36 integer idomain(max_template,maxres)
43 c FP - Nov. 2014 Temporary specifications for new vars
45 double precision rescore_tmp,x12,y12,z12,rescore2_tmp,
47 double precision, dimension (max_template,maxres) :: rescore
48 double precision, dimension (max_template,maxres) :: rescore2
49 double precision, dimension (max_template,maxres) :: rescore3
50 character*24 tpl_k_rescore
51 c -----------------------------------------------------------------
52 c Reading multiple PDB ref structures and calculation of retraints
53 c not using pre-computed ones stored in files model_ki_{dist,angle}
55 c -----------------------------------------------------------------
58 c Alternative: reading from input
59 call card_concat(controlcard,.true.)
60 call reada(controlcard,"HOMOL_DIST",waga_dist,1.0d0)
61 call reada(controlcard,"HOMOL_ANGLE",waga_angle,1.0d0)
62 call reada(controlcard,"HOMOL_THETA",waga_theta,1.0d0) ! new
63 call reada(controlcard,"HOMOL_SCD",waga_d,1.0d0) ! new
64 call reada(controlcard,'DIST_CUT',dist_cut,5.0d0) ! for diff ways of calc sigma
65 call reada(controlcard,'DIST2_CUT',dist2_cut,9999.0d0)
66 dist1cut=(index(controlcard,'DIST1CUT').gt.0)
67 call readi(controlcard,"HOMOL_NSET",homol_nset,1)
68 read2sigma=(index(controlcard,'READ2SIGMA').gt.0)
69 call readi(controlcard,"IHSET",ihset,1)
70 if (homol_nset.gt.1)then
71 call card_concat(controlcard,.true.)
72 read(controlcard,*) (waga_homology(i),i=1,homol_nset)
73 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
74 c write(iout,*) "iset homology_weight "
76 c write(iout,*) i,waga_homology(i)
79 iset=mod(kolor,homol_nset)+1
84 c write(iout,*) "waga_homology(",iset,")",waga_homology(iset)
86 cd write (iout,*) "nnt",nnt," nct",nct
98 c Reading HM global scores (prob not required)
101 do k=1,constr_homology
105 c open (4,file="HMscore")
106 c do k=1,constr_homology
107 c read (4,*,end=521) hmscore_tmp
108 c hmscore(k)=hmscore_tmp ! Another transformation can be used
109 c write(*,*) "Model", k, ":", hmscore(k)
120 c write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
122 if (read_homol_frag) then
123 call read_klapaucjusz
126 do k=1,constr_homology
128 read(inp,'(a)') pdbfile
129 c Next stament causes error upon compilation (?)
130 c if(me.eq.king.or. .not. out1file)
131 c write (iout,'(2a)') 'PDB data will be read from file ',
132 c & pdbfile(:ilen(pdbfile))
133 write (iout,'(a,5x,a)') 'HOMOL: Opening PDB file',
134 & pdbfile(:ilen(pdbfile))
135 open(ipdbin,file=pdbfile,status='old',err=33)
137 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
138 & pdbfile(:ilen(pdbfile))
141 c print *,'Begin reading pdb data'
143 c Files containing res sim or local scores (former containing sigmas)
146 write(kic2,'(bz,i2.2)') k
148 tpl_k_rescore="template"//kic2//".sco"
153 call readpdb_template(k)
162 do i=1,2*nres_chomo(k)
169 write (iout,'(i5,3f8.3,5x,3f8.3)') i,(crefjlee(j,i),j=1,3),
170 & (crefjlee(j,i+nres),j=1,3)
172 write (iout,*) "read_constr_homology: after reading pdb file"
177 c Distance restraints
180 C Copy the coordinates from reference coordinates (?)
181 do i=1,2*nres_chomo(k)
184 c write (iout,*) "c(",j,i,") =",c(j,i)
188 c From read_dist_constr (commented out 25/11/2014 <-> res sim)
190 c write(iout,*) "tpl_k_rescore - ",tpl_k_rescore
191 open (ientin,file=tpl_k_rescore,status='old')
192 if (nnt.gt.1) rescore(k,1)=0.0d0
193 do irec=nnt,nct ! loop for reading res sim
195 read (ientin,*,end=1401) i_tmp,rescore2_tmp,rescore_tmp,
196 & rescore3_tmp,idomain_tmp
198 idomain(k,i_tmp)=idomain_tmp
199 rescore(k,i_tmp)=rescore_tmp
200 rescore2(k,i_tmp)=rescore2_tmp
201 rescore3(k,i_tmp)=rescore3_tmp
202 write(iout,'(a7,i5,3f10.5,i5)') "rescore",
203 & i_tmp,rescore2_tmp,rescore_tmp,
204 & rescore3_tmp,idomain_tmp
207 read (ientin,*,end=1401) rescore_tmp
209 c rescore(k,irec)=rescore_tmp+1.0d0 ! to avoid 0 values
210 rescore(k,irec)=0.5d0*(rescore_tmp+0.5d0) ! alt transf to reduce scores
211 c write(iout,*) "rescore(",k,irec,") =",rescore(k,irec)
216 if (waga_dist.ne.0.0d0) then
224 distal=dsqrt(x12*x12+y12*y12+z12*z12)
225 c write (iout,*) k,i,j,distal,dist2_cut
226 if (dist1cut .and. k.gt.1) then
228 if (l_homo(1,ii)) then
234 sigma_odl(k,ii)=sigma_odl(1,ii)
239 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
240 & .and. distal.le.dist2_cut ) then
246 c write (iout,*) "k",k
247 c write (iout,*) "i",i," j",j," constr_homology",
255 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
257 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
258 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
259 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
261 if (odl(k,ii).le.dist_cut) then
262 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
265 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
266 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
268 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
269 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
273 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
276 ct l_homo(k,ii)=.false.
283 c write (iout,*) "Distance restraints set"
286 c Theta, dihedral and SC retraints
288 if (waga_angle.gt.0.0d0) then
289 c open (ientin,file=tpl_k_sigma_dih,status='old')
290 c do irec=1,maxres-3 ! loop for reading sigma_dih
291 c read (ientin,*,end=1402) i,j,ki,l,sigma_dih(k,i+nnt-1) ! j,ki,l what for?
292 c if (i+nnt-1.gt.lim_dih) lim_dih=i+nnt-1 ! right?
293 c sigma_dih(k,i+nnt-1)=sigma_dih(k,i+nnt-1)* ! not inverse because of use of res. similarity
294 c & sigma_dih(k,i+nnt-1)
299 if (idomain(k,i).eq.0) then
303 dih(k,i)=phiref(i) ! right?
304 c read (ientin,*) sigma_dih(k,i) ! original variant
305 c write (iout,*) "dih(",k,i,") =",dih(k,i)
306 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
307 c & "rescore(",k,i-1,") =",rescore(k,i-1),
308 c & "rescore(",k,i-2,") =",rescore(k,i-2),
309 c & "rescore(",k,i-3,") =",rescore(k,i-3)
311 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
312 & rescore(k,i-2)+rescore(k,i-3))/4.0
313 c if (read2sigma) sigma_dih(k,i)=sigma_dih(k,i)/4.0
314 c write (iout,*) "Raw sigmas for dihedral angle restraints"
315 c write (iout,'(i5,10(2f8.2,4x))') i,sigma_dih(k,i)
316 c sigma_dih(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
317 c rescore(k,i-2)*rescore(k,i-3) ! right expression ?
318 c Instead of res sim other local measure of b/b str reliability possible
319 if (sigma_dih(k,i).ne.0)
320 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
321 c sigma_dih(k,i)=sigma_dih(k,i)*sigma_dih(k,i)
325 c write (iout,*) "Dihedral angle restraints set"
328 if (waga_theta.gt.0.0d0) then
329 c open (ientin,file=tpl_k_sigma_theta,status='old')
330 c do irec=1,maxres-2 ! loop for reading sigma_theta, right bounds?
331 c read (ientin,*,end=1403) i,j,ki,sigma_theta(k,i+nnt-1) ! j,ki what for?
332 c sigma_theta(k,i+nnt-1)=sigma_theta(k,i+nnt-1)* ! not inverse because of use of res. similarity
333 c & sigma_theta(k,i+nnt-1)
338 do i = nnt+2,nct ! right? without parallel.
339 c do i = i=1,nres ! alternative for bounds acc to readpdb?
340 c do i=ithet_start,ithet_end ! with FG parallel.
341 if (idomain(k,i).eq.0) then
345 thetatpl(k,i)=thetaref(i)
346 c write (iout,*) "thetatpl(",k,i,") =",thetatpl(k,i)
347 c write(iout,*) "rescore(",k,i,") =",rescore(k,i),
348 c & "rescore(",k,i-1,") =",rescore(k,i-1),
349 c & "rescore(",k,i-2,") =",rescore(k,i-2)
350 c read (ientin,*) sigma_theta(k,i) ! 1st variant
351 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
352 & rescore(k,i-2))/3.0
353 c if (read2sigma) sigma_theta(k,i)=sigma_theta(k,i)/3.0
354 if (sigma_theta(k,i).ne.0)
355 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
357 c sigma_theta(k,i)=hmscore(k)*rescore(k,i)*rescore(k,i-1)*
358 c rescore(k,i-2) ! right expression ?
359 c sigma_theta(k,i)=sigma_theta(k,i)*sigma_theta(k,i)
362 c write (iout,*) "Angle restraints set"
365 if (waga_d.gt.0.0d0) then
366 c open (ientin,file=tpl_k_sigma_d,status='old')
367 c do irec=1,maxres-1 ! loop for reading sigma_theta, right bounds?
368 c read (ientin,*,end=1404) i,j,sigma_d(k,i+nnt-1) ! j,ki what for?
369 c sigma_d(k,i+nnt-1)=sigma_d(k,i+nnt-1)* ! not inverse because of use of res. similarity
370 c & sigma_d(k,i+nnt-1)
374 do i = nnt,nct ! right? without parallel.
375 c do i=2,nres-1 ! alternative for bounds acc to readpdb?
376 c do i=loc_start,loc_end ! with FG parallel.
377 if (itype(i).eq.10) cycle
378 if (idomain(k,i).eq.0 ) then
385 c write (iout,*) "xxtpl(",k,i,") =",xxtpl(k,i)
386 c write (iout,*) "yytpl(",k,i,") =",yytpl(k,i)
387 c write (iout,*) "zztpl(",k,i,") =",zztpl(k,i)
388 c write(iout,*) "rescore(",k,i,") =",rescore(k,i)
389 sigma_d(k,i)=rescore3(k,i) ! right expression ?
390 if (sigma_d(k,i).ne.0)
391 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
393 c sigma_d(k,i)=hmscore(k)*rescore(k,i) ! right expression ?
394 c sigma_d(k,i)=sigma_d(k,i)*sigma_d(k,i)
395 c read (ientin,*) sigma_d(k,i) ! 1st variant
399 c write (iout,*) "SC restraints set"
402 c remove distance restraints not used in any model from the list
403 c shift data in all arrays
405 c write (iout,*) "waga_dist",waga_dist," nnt",nnt," nct",nct
406 if (waga_dist.ne.0.0d0) then
413 c if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
414 c & .and. distal.le.dist2_cut ) then
415 c write (iout,*) "i",i," j",j," ii",ii
417 if (ii_in_use(ii).eq.0.and.liiflag.or.
418 & ii_in_use(ii).eq.1.and.liiflag.and.ii.eq.lim_odl) then
425 if(i10.eq.lim_odl) i10=i10+1
427 ires_homo(iistart+ki)=ires_homo(ki+i01)
428 jres_homo(iistart+ki)=jres_homo(ki+i01)
429 ii_in_use(iistart+ki)=ii_in_use(ki+i01)
430 do k=1,constr_homology
431 odl(k,iistart+ki)=odl(k,ki+i01)
432 sigma_odl(k,iistart+ki)=sigma_odl(k,ki+i01)
433 l_homo(k,iistart+ki)=l_homo(k,ki+i01)
436 iistart=iistart+i10-i01
439 if (ii_in_use(ii).ne.0.and..not.liiflag) then
447 c write (iout,*) "Removing distances completed"
449 endif ! .not. klapaucjusz
451 if (constr_homology.gt.0) call homology_partition
452 c write (iout,*) "After homology_partition"
454 if (constr_homology.gt.0) call init_int_table
455 c write (iout,*) "After init_int_table"
457 c write (iout,*) "ithet_start =",ithet_start,"ithet_end =",ithet_end
458 c write (iout,*) "loc_start =",loc_start,"loc_end =",loc_end
462 if (.not.out_template_restr) return
463 cd write(iout,*) "waga_theta",waga_theta,"waga_d",waga_d
464 c if(me.eq.king .or. .not. out1file .and. fg_rank.eq.0) then
465 write (iout,*) "Distance restraints from templates"
467 write(iout,'(3i5,100(2f8.2,1x,l1,4x))')
468 & ii,ires_homo(ii),jres_homo(ii),
469 & (odl(ki,ii),1.0d0/dsqrt(sigma_odl(ki,ii)),l_homo(ki,ii),
470 & ki=1,constr_homology)
472 write (iout,*) "Dihedral angle restraints from templates"
474 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
475 & (rad2deg*dih(ki,i),
476 & rad2deg/dsqrt(sigma_dih(ki,i)),ki=1,constr_homology)
478 write (iout,*) "Virtual-bond angle restraints from templates"
480 write (iout,'(i5,a4,100(2f8.2,4x))') i,restyp(itype(i)),
481 & (rad2deg*thetatpl(ki,i),
482 & rad2deg/dsqrt(sigma_theta(ki,i)),ki=1,constr_homology)
484 write (iout,*) "SC restraints from templates"
486 write(iout,'(i5,100(4f8.2,4x))') i,
487 & (xxtpl(ki,i),yytpl(ki,i),zztpl(ki,i),
488 & 1.0d0/dsqrt(sigma_d(ki,i)),ki=1,constr_homology)
491 c -----------------------------------------------------------------
494 c----------------------------------------------------------------------
495 subroutine read_klapaucjusz
498 include 'DIMENSIONS.ZSCOPT'
499 include 'DIMENSIONS.FREE'
503 include 'COMMON.SETUP'
504 include 'COMMON.CONTROL'
505 include 'COMMON.HOMOLOGY'
506 include 'COMMON.CHAIN'
507 include 'COMMON.IOUNITS'
509 include 'COMMON.INTERACT'
510 include 'COMMON.NAMES'
511 include 'COMMON.HOMRESTR'
512 character*256 fragfile
513 integer ninclust(maxclust),inclust(max_template,maxclust),
514 & nresclust(maxclust),iresclust(maxres,maxclust)
517 character*24 model_ki_dist, model_ki_angle
518 character*500 controlcard
519 integer i,ii,ik,ki,j,k,l,ll,ii_in_use(maxdim),i_tmp,idomain_tmp,
520 & nclust,iistart,iishift,lim_xx
522 integer idomain(max_template,maxres)
523 double precision distal
524 logical lprn /.true./
530 double precision rescore_tmp,x12,y12,z12,rescore2_tmp
531 double precision, dimension (max_template,maxres) :: rescore
532 double precision, dimension (max_template,maxres) :: rescore2
533 character*24 tpl_k_rescore
540 call getenv("FRAGFILE",fragfile)
541 open(ientin,file=fragfile,status="old",err=10)
542 read(ientin,*) constr_homology,nclust
549 do k=1,constr_homology
550 read(ientin,'(a)') pdbfile
551 write (iout,'(a,5x,a)') 'KLAPAUCJUSZ: Opening PDB file',
552 & pdbfile(:ilen(pdbfile))
553 open(ipdbin,file=pdbfile,status='old',err=33)
555 33 write (iout,'(a,5x,a)') 'Error opening PDB file',
556 & pdbfile(:ilen(pdbfile))
561 call readpdb_template(k)
566 c chomo(j,i,k)=c(j,i)
576 read(ientin,*) ninclust(i),nresclust(i)
577 read(ientin,*) (inclust(k,i),k=1,ninclust(i))
578 read(ientin,*) (iresclust(k,i),k=1,nresclust(i))
584 c write (iout,*) "CLUSTER",l," members:",ninclust(l)
585 do ll = 1,ninclust(l)
593 idomain(k,iresclust(i,l)+1) = 1
595 idomain(k,iresclust(i,l)) = 1
599 c Distance restraints
602 C Copy the coordinates from reference coordinates (?)
603 c write (iout,*) "k",k
609 c write (iout,*) "c(",j,i,") =",c(j,i)
612 c write (iout,*) "read_klapaucjusz: calling int_from_cart"
614 c write (iout,*) "idomain"
615 c write (iout,'(2i5)') (i,idomain(k,i),i=1,nres)
616 call int_from_cart(.true.,.false.)
617 call sc_loc_geom(.false.)
618 c write (iout,*) "en"
624 if (waga_dist.ne.0.0d0) then
632 distal=dsqrt(x12*x12+y12*y12+z12*z12)
633 c write (iout,*) k,i,j,distal,dist2_cut
635 if (idomain(k,i).eq.idomain(k,j).and.idomain(k,i).ne.0
636 & .and. distal.le.dist2_cut ) then
642 c write (iout,*) "k",k
643 c write (iout,*) "i",i," j",j," constr_homology",
651 sigma_odl(k,ii)=sigma_odl(k,ii)+rescore2(k,ik)
653 sigma_odl(k,ii)=sigma_odl(k,ii)/(j-i+1)
654 if (odl(k,ii).gt.dist_cut) sigma_odl(k,ii) =
655 & sigma_odl(k,ii)*dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
657 if (odl(k,ii).le.dist_cut) then
658 sigma_odl(k,ii)=rescore(k,i)+rescore(k,j)
661 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
662 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2)
664 sigma_odl(k,ii)=(rescore(k,i)+rescore(k,j))*
665 & dexp(0.5d0*(odl(k,ii)/dist_cut)**2-0.5d0)
669 sigma_odl(k,ii)=1.0d0/(sigma_odl(k,ii)*sigma_odl(k,ii))
672 c l_homo(k,ii)=.false.
679 c Theta, dihedral and SC retraints
681 if (waga_angle.gt.0.0d0) then
683 if (idomain(k,i).eq.0) then
688 sigma_dih(k,i)=(rescore(k,i)+rescore(k,i-1)+
689 & rescore(k,i-2)+rescore(k,i-3))/4.0
690 c write (iout,*) "k",k," l",l," i",i," rescore",rescore(k,i),
691 c & " sigma_dihed",sigma_dih(k,i)
692 if (sigma_dih(k,i).ne.0)
693 & sigma_dih(k,i)=1.0d0/(sigma_dih(k,i)*sigma_dih(k,i))
698 if (waga_theta.gt.0.0d0) then
700 if (idomain(k,i).eq.0) then
701 c sigma_theta(k,i)=0.0
704 thetatpl(k,i)=thetaref(i)
705 sigma_theta(k,i)=(rescore(k,i)+rescore(k,i-1)+
706 & rescore(k,i-2))/3.0
707 if (sigma_theta(k,i).ne.0)
708 & sigma_theta(k,i)=1.0d0/(sigma_theta(k,i)*sigma_theta(k,i))
712 if (waga_d.gt.0.0d0) then
714 if (itype(i).eq.10) cycle
715 if (idomain(k,i).eq.0 ) then
722 sigma_d(k,i)=rescore(k,i)
723 if (sigma_d(k,i).ne.0)
724 & sigma_d(k,i)=1.0d0/(sigma_d(k,i)*sigma_d(k,i))
725 if (i-nnt+1.gt.lim_xx) lim_xx=i-nnt+1
731 c remove distance restraints not used in any model from the list
732 c shift data in all arrays
734 if (waga_dist.ne.0.0d0) then
740 if (ii_in_use(ii).eq.0.and.liiflag) then
744 if (ii_in_use(ii).ne.0.and..not.liiflag.or.
745 & .not.liiflag.and.ii.eq.lim_odl) then
746 if (ii.eq.lim_odl) then
752 do ki=iistart,lim_odl-iishift
753 ires_homo(ki)=ires_homo(ki+iishift)
754 jres_homo(ki)=jres_homo(ki+iishift)
755 ii_in_use(ki)=ii_in_use(ki+iishift)
756 do k=1,constr_homology
757 odl(k,ki)=odl(k,ki+iishift)
758 sigma_odl(k,ki)=sigma_odl(k,ki+iishift)
759 l_homo(k,ki)=l_homo(k,ki+iishift)
763 lim_odl=lim_odl-iishift
769 write (iout,*) "ires_homo and jres_homo arrays, lim_odl",lim_odl
771 write (iout,*) i,ires_homo(i),jres_homo(i)
775 10 stop "Error in fragment file"