8 integer*4 :: i,j,m,n,iloc,pos,iter,maxiter,numarg,tmplen
9 integer*4 :: WybierzOsobnika,Najlepszy,ZnajdzPodobnego,FindWorst
11 integer*4 :: mnoznik = 10
12 character*16 :: mode,argn,argi,dir_nam
13 character*15 :: filename
14 real*8 :: loc,fc,sumfitness,sump,avrp,maxfc
17 real*8 :: FunkcjaCeluB, FunkcjaCeluB2, FunkcjaCeluR
18 character(80),dimension(5) :: wagi
19 logical :: searching = .false.
20 logical :: logdata = .true.
21 logical :: fileex = .false.
22 logical :: retry = .false.
23 logical :: dir_ex = .false.
24 logical :: debug = .true.
25 character*200 :: text, tmptext,tmptext2
26 character(len=*), parameter :: FMT = "(19F10.5,E15.7,F10.5)"
28 c =======================================================================
30 c =======================================================================
33 call ReadInput(status)
34 if ((maxminstep.gt.0).and.(generation.eq.0)) then
40 write(*,*) "There ware input file errors - check log."
45 r = rand(timeArray(1)*10000+timeArray(2)*100+timeArray(3))
50 c-------------------------------------------------------
51 c bank & populacja arrays store this
53 c 20 - energy obtained from zscore
55 c-------------------------------------------------------
56 allocate (bank(banksize,21))
57 allocate (populacja(BANK_MULTIPLIER*banksize,21))
58 allocate (pairs(BANK_MULTIPLIER*banksize))
62 do i=1,BANK_MULTIPLIER*banksize
75 inquire(FILE=ostatefn,EXIST=fileex)
76 c No. Prepere next generation
78 open(ostate,file=ostatefn)
79 read(ostate,'(I4)') generation
80 read(ostate,'(L2)') do_optima
81 read(ostate,'(L2)') do_ga
82 read(ostate,'(F7.5)') avrd
85 call write2log("Doing GA in this step")
87 if (.not.do_optima) then
89 call write2log("ZSCORE weights minimalization disabled for now")
90 generation=generation+1
92 write(tmptext,'(I4)') generation
93 call write2log("This is genaration "//tmptext)
94 call ReadOptimaW(BANK_MULTIPLIER*banksize,populacja)
96 c Yes. Generate random zero-population
98 call GenPopulation(BANK_MULTIPLIER*banksize,populacja)
99 write(tmptext,'(I4)') generation
100 call write2log("This is genaration "//tmptext)
105 c End of "first time here?" code
109 c Do we actual use a Genetic Algorithm?
112 if (do_ga.eqv..true.) then
114 c Yes. This is only done when doing second pass with ZSCORE (without weight minimalizaton)
115 c or with weight minimalization disabled (maxmin=0) just to obtain final score)
117 c \\---//================================================================c
119 c "// Genetic Algorithm code starts here c
121 c =//---\\===============================================================c
123 call ReadZEnergy(BANK_MULTIPLIER*banksize,populacja)
124 do i=1,BANK_MULTIPLIER*banksize
125 c populacja(i,20)=FunkcjaCeluR(populacja(i,20))
126 write(*,*) "Ind ",i,populacja(i,20)
129 call write2log("==[ Doing GA now ]=============================")
132 c Populate bank depending on algorithm
136 call GetNBest(populacja,bank,banksize)
138 call GetNBest(populacja,bank,banksize)
140 call GetNBest(populacja,bank,banksize)
142 c --- debug begin ---
144 write(*,*) "generation: ",generation
145 write(*,*) "maxminstep: ",maxminstep
146 write(*,*) "do_ga: ",do_ga
147 write(*,*) "do_optima: ",do_optima
148 write(*,*) "do_fs: ",do_fs
149 c write(*,*) "cicutoff: ", cicutoff
156 c Fill the bank just after the first time we get the score
158 if (((generation.eq.1).and.(maxminstep.eq.0)).or.((generation.eq&
159 &.1).and.(maxminstep.gt.0))) then
161 c --- debug begin ---
163 write(*,*) "Calling GetNBest..."
166 call GetNBest(populacja,bank,banksize)
167 call CalcAvgDist(bank,avrd)
168 write(tmptext,'(F7.5)') avrd
169 call write2log("Average distance between individuals in initial&
170 & bank is "//trim(tmptext))
174 csacutoff=(maxco*avrd)-generation*avrd*(maxco-minco)/maxgen
175 write(tmptext,'(F7.5)') csacutoff
176 call write2log("CSA cutoff is now set to "//trim(tmptext))
177 c csacutoff=maxco*avrd
181 c --- debug begin ---
184 write(*,FMT) bank(i,:)
189 call CalcFitness(bank,sumfitness)
197 c --- debug begin ---
199 write(*,*) "Szukam podobnego"
204 write(tmptext,'(F7.5)') avrd
205 call write2log("Average distance in bank is "//trim(tmptext))
207 csacutoff=maxco*avrd-generation*avrd*(maxco-minco)/maxgen
208 write(tmptext,'(F7.5)') csacutoff
209 call write2log("CSA cutoff is now set to "//trim(tmptext))
211 do i=1,BANK_MULTIPLIER*banksize
212 write(tmptext,'(I4)') i
213 call write2log("Checking ind "//trim(tmptext))
214 j=ZnajdzPodobnego(banksize,bank,populacja(i,:),csacutoff)
215 if (j.gt.0) then ! W banku jest podobny
216 if (populacja(i,20).lt.bank(j,20)) then
217 write(tmptext,'(I4)') j
218 write(tmptext2,'(I4)') i
219 call write2log(" Swaping ind"//trim(tmptext)//" from bank t&
220 &o ind "//trim(tmptext2)//" from population")
221 write(tmptext2,'(19F8.5,E15.7,F8.5)') bank(j,:)
222 call write2log(" BANK"//trim(tmptext)//":"//trim(tmptext2))
224 write(tmptext,'(I4)') i
225 write(tmptext2,'(19F8.5,E15.7,F8.5)') populacja(i,:)
226 call write2log(" POP "//trim(tmptext)//":"//trim(tmptext2))
228 bank(j,:)=populacja(i,:)
230 call write2log(" Found simialar but not better")
232 else ! W banku nie ma podobnego
233 j=FindWorst(banksize,bank)
234 write(tmptext2,'(I4)') j
235 if (populacja(i,20).lt.bank(j,20)) then
236 call write2log(" Worst in bank is "//trim(tmptext2))
237 write(tmptext,'(I4)') i
238 call write2log(" Swaping worst ind in bank to "//trim(tmpte&
240 write(tmptext,'(I4)') j
241 write(tmptext2,'(19F8.5,E15.7,F8.5)') bank(j,:)
242 call write2log(" BANK"//trim(tmptext)//":"//trim(tmptext2))
243 write(tmptext,'(I4)') i
244 write(tmptext2,'(19F8.5,E15.7,F8.5)') populacja(i,:)
245 call write2log(" POP "//trim(tmptext)//":"//trim(tmptext2))
246 bank(j,:)=populacja(i,:)
248 call write2log(" The worst in bank is better then this Ind"&
254 c -----------------------------------------------------------------------
255 c Calculate fitness for reproduction
256 c -----------------------------------------------------------------------
257 call CalcFitness(bank,sumfitness)
259 c --- debug begin ---
261 write (*,*) "Dumping bank: "
263 write(*,FMT) bank(i,:)
265 write (*,*) "Sumfitness: ", sumfitness
273 write(*,*) "Well this is not implemented yet"
280 c Have we done last generation ?
281 if (generation.eq.maxgen) then
282 call write2log("Maximum number of genarations reached. QUITING.")
285 c Prapering for next generation so increase counter
288 c -----------------------------------------------------------------------
290 c -----------------------------------------------------------------------
291 call write2log("==[ Reproducting ]============================")
294 do i=1,BANK_MULTIPLIER*banksize
295 m=WybierzOsobnika(banksize,bank)
296 write(tmptext,'(I4)') m
297 write(tmptext2,'(I4)') i
298 call write2log("Reproducting individual "//trim(tmptext)//" from&
299 & bank as new individual "//trim(tmptext2))
300 populacja(i,:)=bank(m,:)
302 case('better','betterv2')
303 populacja(1,:)=bank(1,:)
304 call write2log("Reproducting first (best) individual")
305 do i=2,BANK_MULTIPLIER*banksize
306 m=WybierzOsobnika(banksize,bank)
307 write(tmptext,'(I4)') m
308 write(tmptext2,'(I4)') i
309 call write2log("Reproducting individual "//trim(tmptext)//" from&
310 & bank as new individual "//trim(tmptext2))
311 populacja(i,:)=bank(m,:)
315 c -----------------------------------------------------------------------
317 c -----------------------------------------------------------------------
318 do i=1,BANK_MULTIPLIER*banksize
322 do i=1,BANK_MULTIPLIER*banksize
323 if (pairs(i).eq.0) then
324 210 pos=1+int(rand(0)/(1/real(BANK_MULTIPLIER*banksize)))
329 if (pairs(j).eq.pos) then
337 call write2log("==[ Pairing ]==============================")
338 do i=1,BANK_MULTIPLIER*banksize
339 write(tmptext,'(A11,I3.3,A5,I3.3,A21)') "Individual ",i," and ",p&
340 &airs(i)," will be crossed over"
341 call write2log(trim(tmptext))
344 c -----------------------------------------------------------------------
346 c -----------------------------------------------------------------------
347 call write2log("==[ Crossing ]==============================")
348 do i=1,BANK_MULTIPLIER*banksize
349 if (pairs(i) .gt. i) then
350 call CrossoverS(populacja(i,:),populacja(pairs(i),:))
355 call write2log(" WLONG WSCP WELEC WBOND WANG &
356 &WSCLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC WT&
357 &URN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR")
358 do i=1,BANK_MULTIPLIER*banksize
361 write(text,'(A4,I3.3,A2)') "Ind",i,": "
363 write(tmptext,'(F7.5)') populacja(i,j)
364 text = text(1:tmplen) // tmptext
367 call write2log(trim(text))
370 c -----------------------------------------------------------------------
372 c -----------------------------------------------------------------------
374 call write2log("==[ Mutating ]==============================")
376 if (IGNORE_WEIGHT(i).eq.1) then
377 write(tmptext,'(I2)') i
378 call write2log("Parameter "//trim(WNAME(i))//" will be ignored")
381 do i=1,BANK_MULTIPLIER*banksize
382 call MutationV(populacja(i,:),i,MUTRATIO)
384 c for betterv2 and csa restore best individual
386 case('betterv2','csa')
387 populacja(1,:)=bank(1,:)
391 c Genetic Algorithm blokcode stops here
395 c ---------------------------------
396 c Do some final stuff
397 c ---------------------------------
399 c Set the variables before writing to state file
401 if ((.not.do_ga).and.(.not.do_optima)) then
411 do_optima=.not.do_optima
412 if (generation.eq.0) then
425 c Write te current state and population
432 write(tmptext,'(I3)') generation+1
433 call write2log("Preparing inputs for next generation ("//trim(adju&
435 call CreateInputs(BANK_MULTIPLIER*banksize,populacja)
437 c All done? Then let's quit.
443 c ======================================================================
445 c MAIN CODE ENDS HERE
447 c ======================================================================
451 2000 deallocate(populacja)
456 c ======================================================================
457 c Clustering subroutines
458 c ======================================================================
460 include 'cluster.inc'
463 c ======================================================================
464 c Write2log subroutine
465 c ======================================================================
467 c ----------------------------------------------------------------------
469 subroutine Write2log(text)
472 character*200 :: tmptext
473 character(len=*) :: text
475 call itime(timeArray)
476 inquire(file=ologfn,exist=ex)
478 open(olog, file=ologfn, access="append")
479 write(olog,"(A)") "==============================================&
481 tmptext = "= UNRES weights optimizer version "//version
482 write(olog,"(A)") tmptext
483 write(olog,"(A)") info
484 write(olog,"(A)") "==============================================&
488 open(olog, file = ologfn , access = "append")
489 write(olog,"(I2.2,A1,I2.2,A1,I2.2,A2,A)") timeArray(1),":",timeAr&
490 &ray(2),":",timeArray(3),": ",text
492 end subroutine Write2log
494 c ======================================================================
495 c GetNBest subroutine
496 c ======================================================================
497 c Fills up the bank population up to banksize with individuals from
498 c inputpop having the best(lowest) score
499 c ----------------------------------------------------------------------
501 subroutine GetNBest(inputpop,bank,banksize)
502 integer*4 :: banksize, i,j,idx
503 real*8 :: inputpop, bank, best, last
505 dimension inputpop(banksize*BANK_MULTIPLIER,21)
506 dimension bank(banksize,21)
512 do i=1,banksize*BANK_MULTIPLIER
513 if ((inputpop(i,20).lt.best).and.(inputpop(i,20).gt.last)) then
518 bank(j,:)=inputpop(idx,:)
521 end subroutine GetNBest
523 c ======================================================================
524 c FindWorst subroutine
525 c ======================================================================
526 c Finds the worst (highest score) individual in population
527 c ----------------------------------------------------------------------
529 integer*4 function FindWorst(rozmiar,pop)
530 integer*4 :: rozmiar, i, idx
532 dimension pop(rozmiar,21)
537 if (pop(i,20).gt.last) then
546 c ======================================================================
547 c GenPopulation subroutine
548 c ======================================================================
549 c Generates a population (pop) of nind individuals with 19 random
550 c wights from a set of ranges (see GA.inc).
551 c ----------------------------------------------------------------------
553 subroutine GenPopulation(nind,pop)
554 integer*4 :: i,j,nind
556 dimension pop(nind,21)
562 pop(j,1)=WLONG_LOW+(rand(0)*(WLONG_HI-WLONG_LOW))
564 pop(j,2)=WSCP_LOW+(rand(0)*(WSCP_HI-WSCP_LOW))
566 pop(j,3)=WELEC_LOW+(rand(0)*(WELEC_HI-WELEC_LOW))
568 pop(j,4)=WBOND_LOW+(rand(0)*(WBOND_HI-WBOND_LOW))
570 pop(j,5)=WANG_LOW+(rand(0)*(WANG_HI-WANG_LOW))
572 pop(j,6)=WSCLOC_LOW+(rand(0)*(WSCLOC_HI-WSCLOC_LOW))
574 pop(j,7)=WTOR_LOW+(rand(0)*(WTOR_HI-WTOR_LOW))
576 pop(j,8)=WTORD_LOW+(rand(0)*(WTORD_HI-WTORD_LOW))
578 pop(j,9)=WCORRH_LOW+(rand(0)*(WCORRH_HI-WCORRH_LOW))
580 pop(j,10)=WCORR4_LOW+(rand(0)*(WCORR4_HI-WCORR4_LOW))
582 pop(j,11)=WCORR5_LOW+(rand(0)*(WCORR5_HI-WCORR5_LOW))
584 pop(j,12)=WCORR6_LOW+(rand(0)*(WCORR6_HI-WCORR6_LOW))
586 pop(j,13)=WEL_LOC_LOW+(rand(0)*(WEL_LOC_HI-WEL_LOC_LOW))
588 pop(j,14)=WTURN3_LOW+(rand(0)*(WTURN3_HI-WTURN3_LOW))
590 pop(j,15)=WTURN4_LOW+(rand(0)*(WTURN4_HI-WTURN4_LOW))
592 pop(j,16)=WTURN6_LOW+(rand(0)*(WTURN6_HI-WTURN6_LOW))
594 pop(j,17)=WVDWPP_LOW+(rand(0)*(WVDWPP_HI-WVDWPP_LOW))
596 pop(j,18)=WHPB_LOW+(rand(0)*(WHPB_HI-WHPB_LOW))
598 pop(j,19)=WSCCOR_LOW+(rand(0)*(WSCCOR_HI-WSCCOR_LOW))
602 end subroutine GenPopulation
604 c ======================================================================
605 c CrossoverS subroutine
606 c ======================================================================
607 c Does a simple value crossing-over on a pair
608 c of two given individuals, giving two new individuals.
609 c ----------------------------------------------------------------------
611 subroutine CrossoverS(ind1,ind2)
612 real*8 :: ind1(19),ind2(19),temp(19)
614 loc = 1 + int(rand(0)/(1/18.0))
620 end subroutine CrossoverS
622 c ======================================================================
623 c MutationV subroutine
624 c ======================================================================
625 c Does a value mutation for the given individual (ind) with the
626 c given mutation ratio (mratio).
627 c ----------------------------------------------------------------------
629 subroutine MutationV(ind,id,mratio)
635 character*100 :: tmptext
636 character*150 :: logtext
639 if (IGNORE_WEIGHT(i).eq.1) then
640 c write(tmptext,'(I2)') i
641 c call write2log("Skipping weight "//trim(tmptext))
644 if (rand(0)<mratio) then
648 ind(1)=WLONG_LOW+(rand(0)*(WLONG_HI-WLONG_LOW))
651 ind(2)=WSCP_LOW+(rand(0)*(WSCP_HI-WSCP_LOW))
654 ind(3)=WELEC_LOW+(rand(0)*(WELEC_HI-WELEC_LOW))
657 ind(4)=WBOND_LOW+(rand(0)*(WBOND_HI-WBOND_LOW))
660 ind(5)=WANG_LOW+(rand(0)*(WANG_HI-WANG_LOW))
663 ind(6)=WSCLOC_LOW+(rand(0)*(WSCLOC_HI-WSCLOC_LOW))
666 ind(7)=WTOR_LOW+(rand(0)*(WTOR_HI-WTOR_LOW))
669 ind(8)=WTORD_LOW+(rand(0)*(WTORD_HI-WTORD_LOW))
672 ind(9)=WCORRH_LOW+(rand(0)*(WCORRH_HI-WCORRH_LOW))
675 ind(10)=WCORR4_LOW+(rand(0)*(WCORR4_HI-WCORR4_LOW))
678 ind(11)=WCORR5_LOW+(rand(0)*(WCORR5_HI-WCORR5_LOW))
681 ind(12)=WCORR6_LOW+(rand(0)*(WCORR6_HI-WCORR6_LOW))
684 ind(13)=WEL_LOC_LOW+(rand(0)*(WEL_LOC_HI-WEL_LOC_LOW))
687 ind(14)=WTURN3_LOW+(rand(0)*(WTURN3_HI-WTURN3_LOW))
690 ind(15)=WTURN4_LOW+(rand(0)*(WTURN4_HI-WTURN4_LOW))
693 ind(16)=WTURN6_LOW+(rand(0)*(WTURN6_HI-WTURN6_LOW))
696 ind(17)=WVDWPP_LOW+(rand(0)*(WVDWPP_HI-WVDWPP_LOW))
699 ind(18)=WHPB_LOW+(rand(0)*(WHPB_HI-WHPB_LOW))
702 ind(19)=WSCCOR_LOW+(rand(0)*(WSCCOR_HI-WSCCOR_LOW))
704 write(tmptext,'(I4,A13,I2,A7,F7.5,A5,F7.5)') id," at position "&
705 &,i," from: ",ti," to: ",ind(i)
706 logtext = "Mutation occured in individual "//tmptext
707 call write2log (logtext)
713 c ======================================================================
714 c FunkcjaCeluB function
715 c ======================================================================
716 c Simple (dummy) scoring function
717 c ----------------------------------------------------------------------
719 real*8 function FunkcjaCeluB(osobnik)
721 real*8 :: osobnik(20)
723 FunkcjaCeluB = 20 -exp(-abs(WLONG-osobnik(1))) &
724 & - exp(-abs(WSCP-osobnik(2))) &
725 & - exp(-abs(WELEC-osobnik(3))) &
726 & - exp(-abs(WBOND-osobnik(4))) &
727 & - exp(-abs(WANG-osobnik(5))) &
728 & - exp(-abs(WSCLOC-osobnik(6))) &
729 & - exp(-abs(WTOR-osobnik(7))) &
730 & - exp(-abs(WTORD-osobnik(8))) &
731 & - exp(-abs(WCORRH-osobnik(9))) &
732 & - exp(-abs(WCORR4-osobnik(10))) &
733 & - exp(-abs(WCORR5-osobnik(11))) &
734 & - exp(-abs(WCORR6-osobnik(12))) &
735 & - exp(-abs(WEL_LOC-osobnik(13))) &
736 & - exp(-abs(WTURN3-osobnik(14))) &
737 & - exp(-abs(WTURN4-osobnik(15))) &
738 & - exp(-abs(WTURN6-osobnik(16))) &
739 & - exp(-abs(WVDWPP-osobnik(17))) &
740 & - exp(-abs(WHPB-osobnik(18))) &
741 & - exp(-abs(WSCCOR-osobnik(19)))
745 c ======================================================================
746 c FunkcjaCeluB2 function
747 c ======================================================================
748 c Simple (dummy) scoring function
749 c ----------------------------------------------------------------------
751 real*8 function FunkcjaCeluB2(osobnik)
753 real*8 :: osobnik(20)
755 FunkcjaCeluB2 = 1 + 4*(WLONG-osobnik(1))**2 &
756 & + 4*(WSCP-osobnik(2))**2 &
757 & + 4*(WELEC-osobnik(3))**2 &
758 & + 4*(WBOND-osobnik(4))**2 &
759 & + 4*(WANG-osobnik(5))**2 &
760 & + 4*(WSCLOC-osobnik(6))**2 &
761 & + 4*(WTOR-osobnik(7))**2 &
762 & + 4*(WTORD-osobnik(8))**2 &
763 & + 4*(WCORRH-osobnik(9))**2 &
764 & + 4*(WCORR4-osobnik(10))**2 &
765 & + 4*(WCORR5-osobnik(11))**2 &
766 & + 4*(WCORR6-osobnik(12))**2 &
767 & + 4*(WEL_LOC-osobnik(13))**2 &
768 & + 4*(WTURN3-osobnik(14))**2 &
769 & + 4*(WTURN4-osobnik(15))**2 &
770 & + 4*(WTURN6-osobnik(16))**2 &
771 & + 4*(WVDWPP-osobnik(17))**2 &
772 & + 4*(WHPB-osobnik(18))**2 &
773 & + 4*(WSCCOR-osobnik(19))**2
777 c ======================================================================
778 c Weights2str subroutine
779 c ======================================================================
780 c Writes weights of individual(osobnik) to string (lista)
781 c ----------------------------------------------------------------------
783 subroutine Weights2Str(osobnik,coff,lista)
784 real*8, dimension(19) :: osobnik
788 character(80) :: lista
796 write(a,"(A6,F7.5,A6,F7.5,A7,F7.5,A7,F7.5,A6,F7.5,A)") "WLONG=",os&
797 &obnik(1)," WSCP=",osobnik(2)," WELEC=",osobnik(3)," WBOND=",osobni&
798 &k(4)," WANG=",osobnik(5)," &"
800 write(a,"(A7,F7.5,A6,F7.5,A7,F7.5,A8,F7.5,A8,F7.5,A)") "WSCLOC=",o&
801 &sobnik(6)," WTOR=",osobnik(7)," WTORD=",osobnik(8)," WCORRH=",osob&
802 &nik(9),"WCORR5=",osobnik(11)," &"
804 write(a,"(A7,F7.5,A9,F7.5,A8,F7.5,A8,F7.5,A8,F7.5,A)") "WCORR6=",o&
805 &sobnik(12)," WEL_LOC=",osobnik(13)," WTURN3=",osobnik(14)," WTURN4&
806 &=",osobnik(15),"WTURN6=",osobnik(16)," &"
808 write(a,"(A7,F7.5,A6,F7.5,A8,F7.5,A)") "WVDWPP=",osobnik(17)," WHP&
809 &B=",osobnik(18)," WSCCOR=",osobnik(19)," &
812 write(a,"(A7,F7.5,A8,F7.5)") "CUTOFF=",coff," WCORR4=",osobnik(10)
817 c ======================================================================
818 c FunkcjaCeluR function
819 c ======================================================================
820 c Real scoring function
821 c ----------------------------------------------------------------------
823 real*8 function FunkcjaCeluR(zscore)
825 if (zscore.eq.0) then
828 FunkcjaCeluR = 1/zscore
833 c ======================================================================
834 c ReadInput subroutine
835 c ======================================================================
837 subroutine ReadInput(status)
844 character*100 :: wiersz,tmp
845 inquire(FILE=inpfn,EXIST=ex)
849 call write2log('==[ Reading main input ]======================')
853 read(inp, '(A)', iostat=stat) wiersz
856 if ((wiersz(1:4).eq.'PDB=').or.(wiersz(1:4).eq.'pdb=')) then
858 tmp = wiersz(5:len_trim(wiersz))
860 if (tmp(i:i).eq.' ') then
864 if (npdb.gt.maxnpdb) then
865 call write2log("Number of input PDB exceeds maxnpdb!")
870 if (index(trim(tmp),' ').gt.0) then
871 pdbfiles(i)=tmp(1:index(trim(tmp),' '))
873 pdbfiles(i)=tmp(1:len_trim(tmp))
875 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
877 endif ! Koniec czytania "PDB="
880 if ((wiersz(1:4).eq.'ALG=').or.(wiersz(1:4).eq.'alg=')) then
881 alg=wiersz(5:len_trim(wiersz))
884 call write2log ("Using 'simple' algorithm")
886 call write2log ("Using 'better' algorithm")
888 call write2log ("Using 'betterv2' algorithm")
890 call write2log ("Using 'CSA' algorithm")
892 call write2log ("Using 'Clustering CSA' algorithm")
895 call write2log ("Unknown algorithm. Using 'csa' as default")
900 select case (wiersz(1:12))
901 case('GENERATIONS=','generations=')
902 tmp = wiersz(13:len_trim(wiersz))
903 read(tmp,'(I4)') maxgen
907 c select case(wiersz(1:9))
908 c case('CICUTOFF=','cicutoff=')
909 c tmp = wiersz(10:len_trim(wiersz))
910 c read(tmp(1:len_trim(tmp)),'(F7.5)') cicutoff
911 c call write2log("Initial CSA cutoff is set to "//tmp)
915 select case(wiersz(1:6))
916 case('MINCO=','minco=')
917 tmp = wiersz(7:len_trim(wiersz))
918 read(tmp(1:len_trim(tmp)),'(F7.5)') minco
919 call write2log("Minimal CSA cutoff factor is set to "//tmp)
923 select case(wiersz(1:6))
924 case('MAXCO=','maxco=')
925 tmp = wiersz(7:len_trim(wiersz))
926 read(tmp(1:len_trim(tmp)),'(F7.5)') maxco
927 call write2log("Maximal CSA cutoff factor is set to "//tmp)
932 select case(wiersz(1:11))
933 case('POPULATION=','population=')
934 tmp = wiersz(12:len_trim(wiersz))
935 read(tmp,'(I4)') banksize
936 call write2log("Bank size is set to "//tmp)
940 select case(wiersz(1:13))
941 case('WHAMTEMPLATE=','whamtemplate=')
942 tmp = wiersz(14:len_trim(wiersz))
945 if (tmp(i:i).eq.' ') then
949 if (ntwham.gt.maxnpdb) then
950 call write2log("Number of WHAM templates exceeds maxnpdb!")
955 if (index(trim(tmp),' ').gt.0) then
956 whamtemplate(i)=tmp(1:index(trim(tmp),' '))
958 whamtemplate(i)=tmp(1:len_trim(tmp))
960 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
965 select case(wiersz(1:14))
966 case('MREMDTEMPLATE=','mremdtemplate=')
967 tmp = wiersz(15:len_trim(wiersz))
970 if (tmp(i:i).eq.' ') then
974 if (ntmremd.gt.maxnpdb) then
975 call write2log("Number of MREMD templates exceeds maxnpdb!")
980 if (index(trim(tmp),' ').gt.0) then
981 mremdtemplate(i)=tmp(1:index(trim(tmp),' '))
983 mremdtemplate(i)=tmp(1:len_trim(tmp))
985 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
990 select case(wiersz(1:7))
991 case('MAXMIN=','maxmin=')
992 tmp = wiersz(8:len_trim(wiersz))
993 read(tmp,'(I4)') maxminstep
994 if (maxminstep.gt.0) then
995 call write2log("ZSCORE weights minimalization set to "//tmp)
998 call write2log("ZSCORE weights minimalization disabled")
1004 select case(wiersz(1:8))
1005 case('SCRIPTS=','scripts=')
1007 tmp = wiersz(9:len_trim(wiersz))
1008 do i=1,len_trim(tmp)
1009 if (tmp(i:i).eq.' ') then
1013 if (nscripts.gt.maxscripts) then
1014 call write2log("Number of scripts exceeds maxscripts!")
1019 if (index(trim(tmp),' ').gt.0) then
1020 scripts(i)=tmp(1:index(trim(tmp),' '))
1022 scripts(i)=tmp(1:len_trim(tmp))
1024 call write2log("Script will be used: "//scripts(i))
1025 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
1027 end select ! Koniec czytania "scripts="
1032 c write additional info to log
1033 write(tmp,'(F8.5)') MUTRATIO
1034 call write2log("Mutation ratio is set to "//tmp)
1035 write(tmp,'(I2)') BANK_MULTIPLIER
1036 call write2log("Bank multiplier is set to "//tmp)
1037 write(tmp,'(I5)') BANK_MULTIPLIER*banksize
1039 call write2log("Trail population size will be "//trim(tmp)//" in&
1042 call write2log("Input file unresga.inp does not exist!!")
1043 write(*,*) "Input file unresga.inp does not exist!!"
1047 c Checking set parameters after reading input
1051 call write2log("Can't find 'PDB=' entry in input file")
1055 inquire(FILE=trim(pdbfiles(i)),EXIST=ex)
1057 call write2log("Can't find file "//trim(pdbfiles(i)))
1064 if (maxgen.eq.0) then
1065 call write2log("Couldn't find GENERATIONS= entry in input file")
1070 if (banksize.eq.0) then
1071 call write2log("Can't find POPULATION= entry in input file")
1073 elseif(mod(banksize,2).eq.1) then
1074 call write2log("POPULATION has to be a even number.")
1079 if (ntwham.ne.npdb) then
1080 call write2log("Number of WHAM templates and PDB files is not equ&
1086 if (ntmremd.ne.npdb) then
1087 call write2log("Number of MREMD templates and PDB files is not eq&
1093 if (nscripts.gt.0) then
1095 inquire(FILE=trim(scripts(i)),EXIST=ex)
1097 call write2log("Can't find file "//trim(scripts(i)))
1104 end subroutine ReadInput
1107 c ======================================================================
1108 c CreateInputs subroutine
1109 c ======================================================================
1110 c Creates input files for MREMD, WHAM and ZSCORE.
1111 c ----------------------------------------------------------------------
1113 subroutine CreateInputs(rozmiar,pop)
1116 include 'common.inc'
1117 character(80),dimension(5) :: wagi
1118 integer*4 :: rozmiar,i,j,k
1120 dimension pop(rozmiar,21)
1121 !character*50 :: pdbfiles(maxnpdb)
1122 character*50 :: command,tmptext, prefix
1123 character*256 :: line,plik
1124 integer :: gdzie = 0
1125 character(len=*), parameter :: FMT = "(F9.5,F8.5,F8.5,F8.5,F8.5,F&
1126 &8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8&
1128 !write(tmptext,'(I10)') banksize
1129 !call write2log(trim(tmptext))
1132 prefix=pdbfiles(j)(1:len_trim(pdbfiles(j))-4)
1133 c Create MREMD input
1134 open(imremd, file = mremdtemplate(j))
1135 plik=trim(prefix)//"_"//omremdfn
1136 call write2log(trim("Creating MREMD input: "//plik))
1137 open(omremd, file = plik)
1138 3000 read(imremd, '(A)', end = 3010) line
1139 gdzie = index (line, '{PREFIX}')
1140 if (gdzie .ne. 0) then
1141 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+8:))
1142 write(omremd,"(A)") trim(line)
1143 elseif (index(line,'{POPSIZE}') .ne. 0) then
1144 gdzie = index (line, '{POPSIZE}')
1145 write(tmptext,'(I4)') rozmiar
1146 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(
1148 write(omremd,"(A)") trim(line)
1149 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1150 gdzie = index (line, '{WEIGHTS}')
1152 call Weights2Str(pop(i,:),CUTOFF,wagi)
1153 write(omremd,"(A)") wagi(1)
1154 write(omremd,"(A)") wagi(2)
1155 write(omremd,"(A)") wagi(3)
1156 write(omremd,"(A)") wagi(4)
1157 write(omremd,"(A)") wagi(5)
1160 write(omremd,"(A)") trim(line)
1169 open(iwham, file = whamtemplate(j))
1170 plik=trim(prefix)//"_"//owhamfn
1171 call write2log(trim("Creating WHAM input: "//plik))
1172 open(owham, file = plik)
1173 3015 read(iwham, '(A)', end = 3020) line
1174 gdzie = index (line, '{PREFIX}')
1175 if (gdzie .ne. 0) then
1176 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+8:))
1177 write(owham,"(A)") trim(line)
1178 elseif (index(line,'{POPSIZE}') .ne. 0) then
1179 gdzie = index (line, '{POPSIZE}')
1180 write(tmptext,'(I4)') rozmiar
1181 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1183 write(owham,"(A)") trim(line)
1184 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1185 gdzie = index (line, '{WEIGHTS}')
1187 call Weights2Str(pop(i,:),CUTOFF,wagi)
1188 write(owham,"(A)") wagi(1)
1189 write(owham,"(A)") wagi(2)
1190 write(owham,"(A)") wagi(3)
1191 write(owham,"(A)") wagi(4)
1192 write(owham,"(A)") wagi(5)
1193 write(owham,"(A)") ''
1196 write(owham,"(A)") trim(line)
1204 c Create ZSCORE input
1205 open(izscore, file = izscorefn)
1206 call write2log(trim("Creating ZSCORE input: "//ozscorefn))
1207 open(ozscore, file = ozscorefn)
1208 3025 read(izscore, '(A)', end = 3030) line
1209 gdzie = index (line, '{PREFIX')
1210 if (gdzie .ne. 0) then
1211 read(line(gdzie+7:gdzie+9),'(I2.2)') k
1212 prefix=pdbfiles(k)(1:len_trim(pdbfiles(k))-4)
1213 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+10:)&
1216 write(ozscore,"(A)") trim(line)
1217 elseif (index(line,'{PARAM') .ne. 0) then
1218 gdzie=index(line,'{PARAM')
1219 read(line(gdzie+6:gdzie+8),'(I2.2)') k
1220 prefix=pdbfiles(k)(1:len_trim(pdbfiles(k))-4)
1222 write(tmptext,'(I3.3)') i
1223 line=trim(line(1:gdzie-1))//trim(prefix)//"_wham_par"//tmptex&
1225 write(ozscore,"(A)") trim(line)
1227 elseif (index(line,'{POPSIZE}') .ne. 0) then
1228 gdzie = index (line, '{POPSIZE}')
1229 write(tmptext,'(I4)') rozmiar
1230 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1232 write(ozscore,"(A)") trim(line)
1233 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1234 gdzie = index (line, '{WEIGHTS}')
1236 call Weights2Str(pop(i,:),CUTOFF,wagi)
1237 write(ozscore,"(A)") wagi(1)
1238 write(ozscore,"(A)") wagi(2)
1239 write(ozscore,"(A)") wagi(3)
1240 write(ozscore,"(A)") wagi(4)
1241 write(ozscore,"(A)") trim(wagi(5))
1242 write(ozscore,"(A)") ''
1244 elseif (index(line,'{MAXMIN}') .ne. 0) then
1245 gdzie = index (line, '{MAXMIN}')
1246 write(tmptext,'(I4)') maxminstep
1247 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1249 write(ozscore,"(A)") trim(line)
1251 write(ozscore,"(A)") trim(line)
1260 call write2log('Copying scripts is disabled.')
1262 c ! Open output file
1263 c plik=trim(prefix)//"/"//trim(scripts(i))
1264 c open(oscript, file = plik)
1266 c plik=trim(scripts(i))
1267 c open(iscript, file = plik)
1268 c ! rewrite from input to output
1269 c3030 read(iscript, '(A)', end = 3035) line
1270 c write(oscript,'(A)') trim(line)
1278 c ==========================================
1280 c ==========================================
1283 c write(ow,'(I4)') generation
1284 c write(ow,'(200A)') "# WLONG WSCP WELEC WBOND WANG WSC&
1285 c &LOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC WTURN&
1286 c &3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR"
1288 c write(ow,FMT) pop(i,1),pop(i,2),pop(i,3),pop(i,4), pop(i,5),pop&
1289 c &(i,6),pop(i,7),pop(i,8),pop(i,9),pop(i,10),pop(i,11),pop(i,12),pop&
1290 c &(i,13),pop(i,14),pop(i,15),pop(i,16),pop(i,17),pop(i,18),pop(i,19)
1294 end subroutine CreateInputs
1297 c ======================================================================
1298 c ZnajdzPodobnego function
1299 c ======================================================================
1300 c Finds the most similar individual to osobnik in population(populacja)
1301 c and returns his position in the population
1302 c ----------------------------------------------------------------------
1304 integer*4 function ZnajdzPodobnego(rozmiar,populacja,osobnik,csacu&
1306 integer*4 :: rozmiar,pozycja
1307 real*8 :: delta,mindelta,csacutoff
1309 real*8, dimension(rozmiar,21) :: populacja
1310 real*8, dimension(21) :: osobnik
1312 mindelta = csacutoff
1313 c mindelta = 10000.0
1319 delta=delta+(populacja(i,j)-osobnik(j))**2
1321 c write(tmp,'(2F7.5 )') delta,csacutoff
1322 c call write2log("Delta is "//tmp)
1324 if (delta.lt.mindelta) then
1327 write(tmp,'(F7.5,X,I4)') delta,pozycja
1328 call write2log(" Delta is "//tmp)
1332 ZnajdzPodobnego = pozycja
1335 c ======================================================================
1336 c WybierzOsobnika function
1337 c ======================================================================
1338 c Selects individual from population using roulette method
1339 c ----------------------------------------------------------------------
1341 integer*4 function WybierzOsobnika(rozmiar,populacja)
1342 integer*4 :: osobnik, rozmiar
1343 real*8 :: los, partsum
1345 real*8, dimension(rozmiar,21) :: populacja
1351 osobnik = osobnik + 1
1352 partsum = partsum + populacja(osobnik,21)
1353 if ((osobnik.eq.rozmiar).or.(partsum.ge.los)) exit
1356 WybierzOsobnika = osobnik
1360 c ======================================================================
1361 c Najlepszy function
1362 c ======================================================================
1363 c Selects the individual with the best score from population
1364 c ----------------------------------------------------------------------
1366 integer*4 function Najlepszy(rozmiar, maks, populacja)
1367 integer*4 :: rozmiar
1369 real*8, dimension(rozmiar,21) :: populacja
1372 if (populacja(i,20).eq.maks) then
1379 c ======================================================================
1380 c WriteState subroutine
1381 c ======================================================================
1382 c Writes current state of calculations in case jobs have to be
1384 c ----------------------------------------------------------------------
1386 subroutine WriteState()
1389 include 'common.inc'
1391 open(ostate,file=ostatefn)
1392 write(ostate,'(I4)') generation
1393 write(ostate,'(L2)') do_optima
1394 write(ostate,'(L2)') do_ga
1395 write(ostate,'(F7.5)') avrd
1397 end subroutine WriteState
1399 c ======================================================================
1400 c ReadPopulation subroutine
1401 c ======================================================================
1402 c Reads population from population.summary file
1403 c ----------------------------------------------------------------------
1405 subroutine ReadPopulation(nind,pop)
1408 character*8 :: dummy
1409 dimension pop(nind,21)
1412 character(len=*), parameter :: FMT = "(F9.5,F8.5,F8.5,F8.5,F8.5,F&
1413 &8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8&
1415 read(opopsum,'(A)') dummy
1417 read(opopsum,FMT) pop(i,1),pop(i,2),pop(i,3),pop(i,4), pop(i,5),p&
1418 &op(i,6),pop(i,7),pop(i,8),pop(i,9),pop(i,10),pop(i,11),pop(i,12),p&
1419 &op(i,13),pop(i,14),pop(i,15),pop(i,16),pop(i,17),pop(i,18),pop(i,1&
1422 end subroutine ReadPopulation
1424 c ======================================================================
1425 c ReadOptimaW subroutine
1426 c ======================================================================
1427 c Reads weights from zscore generated weights_opt.zscorepar_XXX files
1429 c nind - number of individuals/files to read
1430 c pop - array where weights are stored
1431 c ----------------------------------------------------------------------
1433 subroutine ReadOptimaW(nind,pop)
1434 integer*4 :: i,nind,stat
1437 character*40 :: filename
1438 character*200 :: tmptxt
1439 dimension pop(nind,21)
1444 c Cosmetic stuff for pretty log
1445 call write2log("==[ Reading weights from zscore files ]=======")
1446 call write2log("# WLONG WSCP WELEC WBOND WANG WS&
1447 &CLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_L&
1448 &OC WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR")
1450 c Actual weight read and error handling
1453 write(tmptxt,'(I3.3)') i
1454 filename = "weights_opt.zscorepar_"//trim(tmptxt)
1455 open(izsoptw, file = filename)
1456 read(izsoptw,"(A4,F7.5,A6,F7.5,A7,F7.5,A7,F7.5,A6,F7.5,A)",iosta&
1457 &t=stat) tmptxt,pop(i,1),tmptxt,pop(i,2),tmptxt,pop(i,3),tmptxt,pop&
1458 &(i,4),tmptxt,pop(i,5)
1461 call write2log("-- ERROR while reading "//trim(filename)//"--")
1467 read(izsoptw,"(A7,F7.5,A6,F7.5,A7,F7.5,A8,F7.5,A8,F7.5,A)",iosta&
1468 &t=stat) tmptxt,pop(i,6),tmptxt,pop(i,7),tmptxt,pop(i,8),tmptxt,pop&
1469 &(i,9),tmptxt,pop(i,11)
1472 call write2log("-- ERROR while reading "//trim(filename)//"--")
1478 read(izsoptw,"(A7,F7.5,A9,F7.5,A8,F7.5,A8,F7.5,A8,F7.5,A)",iosta&
1479 &t=stat) tmptxt,pop(i,12),tmptxt,pop(i,13),tmptxt,pop(i,14),tmptxt,&
1480 &pop(i,15),tmptxt,pop(i,16)
1483 call write2log("-- ERROR while reading "//trim(filename)//"--")
1489 read(izsoptw,"(A7,F7.5,A8,F7.5,A6,F7.5,A)",iostat=stat) tmptxt, &
1490 &pop(i,19),tmptxt,pop(i,17),tmptxt,pop(i,18),tmptxt
1493 call write2log("-- ERROR while reading "//trim(filename)//"--")
1499 read(izsoptw,"(A22,F7.5)",iostat=stat) tmptxt, pop(i,10)
1502 call write2log("-- ERROR while reading "//trim(filename)//"--")
1509 write(tmptxt,'(19F9.5)') (pop(i,j),j=1,19)
1510 call write2log(trim(tmptxt))
1515 end subroutine ReadOptimaW
1518 c ======================================================================
1519 c ReadZEnergy subroutine
1520 c ======================================================================
1521 c Reads Energy from ZSCORE output files zscore_out_parXXX_GB000
1522 c ----------------------------------------------------------------------
1524 subroutine ReadZEnergy(nind,pop)
1528 character*40 :: filename,tmptxt,tmptxt2
1529 character*100 :: wiersz
1530 dimension pop(nind,21)
1533 call write2log("==[ Reading Final Function Value from zscore ]===&
1536 write(tmptxt,'(I3.3)') i
1538 filename=trim(izenergyfn)//trim(tmptxt)//"_GB000"
1539 open(izenergy, file = filename)
1541 read(izenergy, '(A)', iostat=stat) wiersz
1543 if (wiersz(1:22).eq.' Final function value:') then
1544 tmptxt=trim(adjustl(wiersz(23:48)))
1545 read(tmptxt,'(F16.5)') pop(i,20)
1546 write(tmptxt2,'(E15.7)') pop(i,20)
1547 call write2log("Reading score from "//filename//" : "//tmptxt/&
1551 if (pop(i,20).eq.0) then
1552 c Setting FFV to a realy big valiue or otherwise CalcFittness will have problems
1553 pop(i,20)=huge(0.0d0)
1554 call write2log("ERROR while reading FFV from "//filename)
1559 end subroutine ReadZEnergy
1561 c =======================================================================
1562 c WritePopSum subroutine
1563 c =======================================================================
1564 c Writes whole individuals (weights, score, ID, generation) to file
1565 c population.summary This file can be used to plot evolution of the
1566 c weights and scores over time.
1567 c -----------------------------------------------------------------------
1568 subroutine WritePopSum()
1569 logical :: jestplik = .false.
1570 character*5 :: tmptext
1573 c dimension bank(nind,21)
1575 include 'common.inc'
1578 c write(*,*) banksize
1580 write(tmptext,'(I3.3)') generation
1581 inquire(file=opopsumfn, exist=jestplik)
1582 if (.not. jestplik) then
1583 open(opopsum, file = opopsumfn)
1584 write(opopsum, "(A189)") "# WLONG WSCP WELEC WBOND WANG &
1585 & WSCLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC&
1586 & WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR SCO&
1591 open(opopsum, file = opopsumfn, access = "append")
1592 c call ReadPopulation(banksize,populacja)
1593 write(opopsum, "(A189)") "# ==== Generation "//trim(tmptext)//" ==&
1594 &==================================================================&
1595 &==================================================================&
1596 &================================="
1597 c call write2log(banksize)
1600 c write(opopsum,"(F9.5,2F8.5)") populacja(i,1),populacja(i,2),popu&
1602 write(opopsum,"(F9.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,&
1603 &F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F20.5,I8,I8)") bank(i&
1604 &,1),bank(i,2),bank(i,3),bank(i,4),bank(i,5),bank(i,6),bank(i,7),ba&
1605 &nk(i,8),bank(i,9),bank(i,10),bank(i,11),bank(i,12),bank(i,13),bank&
1606 &(i,14),bank(i,15),bank(i,16),bank(i,17),bank(i,18),bank(i,19),bank&
1612 end subroutine WritePopSum
1614 c ======================================================================
1615 c WriteBank subroutine
1616 c ======================================================================
1617 c Writes CSA BANK to file
1618 c ----------------------------------------------------------------------
1619 subroutine WriteBank(b)
1621 include 'common.inc'
1622 real*8,dimension(banksize,21) :: b
1623 character*250 :: tmptext
1624 character*250 :: header
1627 header="# WLONG WSCP WELEC WBOND WANG WSC&
1628 &LOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 &
1629 &WEL_LOC WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCO&
1632 call write2log("Writing Bank to file "//iobankfn)
1633 open(iobank, file = iobankfn)
1634 write(iobank, "(A)") trim(adjustl(header))
1637 write(iobank,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1638 write(tmptext,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1639 call write2log(trim(tmptext))
1644 c ======================================================================
1645 c WriteBankHistory subroutine
1646 c ======================================================================
1647 c Writes CSA BANK History to file
1648 c ----------------------------------------------------------------------
1649 subroutine WriteBankHistory(b)
1651 include 'common.inc'
1652 real*8,dimension(banksize,21) :: b
1653 character*250 :: tmptext
1654 character*250 :: header
1657 header="# WLONG WSCP WELEC WBOND WANG WSC&
1658 &LOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 &
1659 &WEL_LOC WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCO&
1662 call write2log("Writing Bank history to file "//obankhfn)
1663 open(obankh, file = obankhfn)
1664 write(iobank, "(A)") trim(adjustl(header))
1667 write(obankh,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1668 write(tmptext,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1669 call write2log(trim(tmptext))
1675 c ======================================================================
1676 c ReadBank subroutine
1677 c ======================================================================
1678 c Read CSA BANK from file
1679 c ----------------------------------------------------------------------
1680 subroutine ReadBank(b)
1682 include 'common.inc'
1683 real*8,dimension(banksize,21) :: b
1684 character*250 :: tmptext
1686 call write2log("Reading Bank from file "//iobankfn)
1687 open(iobank, file = iobankfn)
1689 read(iobank,"(A)") tmptext
1691 read(iobank,"(19F10.5,E15.7,F10.5)") (b(i,j),j=1,21)
1692 write(tmptext,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1693 call write2log(trim(tmptext))
1698 c ======================================================================
1699 c CalcFitness subroutine
1700 c ======================================================================
1701 c Calculates fitness of every individual in the bank
1702 c ----------------------------------------------------------------------
1703 subroutine CalcFitness(b,fitn)
1704 include 'common.inc'
1705 real*8,dimension(banksize,21) :: b
1706 real*8 :: fitn, sumfitn
1712 fitn=fitn+(1/b(i,20))
1713 sumfitn=sumfitn+b(i,20)
1716 b(i,21)=1/(b(i,20)*fitn)
1717 c b(i,21)=b(i,20)/fitn
1722 c ======================================================================
1723 c CalcAvgDist subroutine
1724 c ======================================================================
1725 c Calculates average distance between individuals in the bank
1726 c ----------------------------------------------------------------------
1727 subroutine CalcAvgDist(b,avgd)
1728 include 'common.inc'
1729 real*8,dimension(banksize,21) :: b
1734 nd = (banksize-1)*banksize/2 ! number of distances to calculate
1739 d=d+(b(i,w)-b(j,w))**2
1746 c -----------------------------------------------------------------------