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 "fisrst 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))
171 csacutoff=(maxco*avrd)-generation*avrd*(maxco-minco)/maxgen
172 write(tmptext,'(F7.5)') csacutoff
173 call write2log("CSA cutoff is now set to "//trim(tmptext))
174 c csacutoff=maxco*avrd
178 c --- debug begin ---
181 write(*,FMT) bank(i,:)
186 call CalcFitness(bank,sumfitness)
194 c --- debug begin ---
196 write(*,*) "Szukam podobnego"
201 write(tmptext,'(F7.5)') avrd
202 call write2log("Average distance in bank is "//trim(tmptext))
204 csacutoff=maxco*avrd-generation*avrd*(maxco-minco)/maxgen
205 write(tmptext,'(F7.5)') csacutoff
206 call write2log("CSA cutoff is now set to "//trim(tmptext))
208 do i=1,BANK_MULTIPLIER*banksize
209 write(tmptext,'(I4)') i
210 call write2log("Checking ind "//trim(tmptext))
211 j=ZnajdzPodobnego(banksize,bank,populacja(i,:),csacutoff)
212 if (j.gt.0) then ! W banku jest podobny
213 if (populacja(i,20).lt.bank(j,20)) then
214 write(tmptext,'(I4)') j
215 write(tmptext2,'(I4)') i
216 call write2log(" Swaping ind"//trim(tmptext)//" from bank t&
217 &o ind "//trim(tmptext2)//" from population")
218 write(tmptext2,'(19F8.5,E15.7,F8.5)') bank(j,:)
219 call write2log(" BANK"//trim(tmptext)//":"//trim(tmptext2))
221 write(tmptext,'(I4)') i
222 write(tmptext2,'(19F8.5,E15.7,F8.5)') populacja(i,:)
223 call write2log(" POP "//trim(tmptext)//":"//trim(tmptext2))
225 bank(j,:)=populacja(i,:)
227 call write2log(" Found simialar but not better")
229 else ! W banku nie ma podobnego
230 j=FindWorst(banksize,bank)
231 write(tmptext2,'(I4)') j
232 if (populacja(i,20).lt.bank(j,20)) then
233 call write2log(" Worst in bank is "//trim(tmptext2))
234 write(tmptext,'(I4)') i
235 call write2log(" Swaping worst ind in bank to "//trim(tmpte&
237 write(tmptext,'(I4)') j
238 write(tmptext2,'(19F8.5,E15.7,F8.5)') bank(j,:)
239 call write2log(" BANK"//trim(tmptext)//":"//trim(tmptext2))
240 write(tmptext,'(I4)') i
241 write(tmptext2,'(19F8.5,E15.7,F8.5)') populacja(i,:)
242 call write2log(" POP "//trim(tmptext)//":"//trim(tmptext2))
243 bank(j,:)=populacja(i,:)
245 call write2log(" The worst in bank is better then this Ind"&
251 c -----------------------------------------------------------------------
252 c Calculate fitness for reproduction
253 c -----------------------------------------------------------------------
254 call CalcFitness(bank,sumfitness)
256 c --- debug begin ---
258 write (*,*) "Dumping bank: "
260 write(*,FMT) bank(i,:)
262 write (*,*) "Sumfitness: ", sumfitness
270 write(*,*) "Some stuff here in the future"
277 c Have we done last generation ?
278 if (generation.eq.maxgen) then
279 call write2log("Maximum number of genarations reached. QUITING.")
282 c Prapering for next generation so increase counter
285 c -----------------------------------------------------------------------
287 c -----------------------------------------------------------------------
288 call write2log("==[ Reproducting ]============================")
291 do i=1,BANK_MULTIPLIER*banksize
292 m=WybierzOsobnika(banksize,bank)
293 write(tmptext,'(I4)') m
294 write(tmptext2,'(I4)') i
295 call write2log("Reproducting individual "//trim(tmptext)//" from&
296 & bank as new individual "//trim(tmptext2))
297 populacja(i,:)=bank(m,:)
299 case('better','betterv2')
300 populacja(1,:)=bank(1,:)
301 call write2log("Reproducting first (best) individual")
302 do i=2,BANK_MULTIPLIER*banksize
303 m=WybierzOsobnika(banksize,bank)
304 write(tmptext,'(I4)') m
305 write(tmptext2,'(I4)') i
306 call write2log("Reproducting individual "//trim(tmptext)//" from&
307 & bank as new individual "//trim(tmptext2))
308 populacja(i,:)=bank(m,:)
312 c -----------------------------------------------------------------------
314 c -----------------------------------------------------------------------
315 do i=1,BANK_MULTIPLIER*banksize
319 do i=1,BANK_MULTIPLIER*banksize
320 if (pairs(i).eq.0) then
321 210 pos=1+int(rand(0)/(1/real(BANK_MULTIPLIER*banksize)))
326 if (pairs(j).eq.pos) then
334 call write2log("==[ Pairing ]==============================")
335 do i=1,BANK_MULTIPLIER*banksize
336 write(tmptext,'(A11,I3.3,A5,I3.3,A21)') "Individual ",i," and ",p&
337 &airs(i)," will be crossed over"
338 call write2log(trim(tmptext))
341 c -----------------------------------------------------------------------
343 c -----------------------------------------------------------------------
344 call write2log("==[ Crossing ]==============================")
345 do i=1,BANK_MULTIPLIER*banksize
346 if (pairs(i) .gt. i) then
347 call CrossoverS(populacja(i,:),populacja(pairs(i),:))
352 call write2log(" WLONG WSCP WELEC WBOND WANG &
353 &WSCLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC WT&
354 &URN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR")
355 do i=1,BANK_MULTIPLIER*banksize
358 write(text,'(A4,I3.3,A2)') "Ind",i,": "
360 write(tmptext,'(F7.5)') populacja(i,j)
361 text = text(1:tmplen) // tmptext
364 call write2log(trim(text))
367 c -----------------------------------------------------------------------
369 c -----------------------------------------------------------------------
371 call write2log("==[ Mutating ]==============================")
373 if (IGNORE_WEIGHT(i).eq.1) then
374 write(tmptext,'(I2)') i
375 call write2log("Parameter "//trim(WNAME(i))//" will be ignored")
378 do i=1,BANK_MULTIPLIER*banksize
379 call MutationV(populacja(i,:),i,MUTRATIO)
381 c for betterv2 and csa restore best individual
383 case('betterv2','csa')
384 populacja(1,:)=bank(1,:)
388 c Genetic Algorithm blokcode stops here
392 c ---------------------------------
393 c Do some final stuff
394 c ---------------------------------
396 c Set the variables before writing to state file
398 if ((.not.do_ga).and.(.not.do_optima)) then
408 do_optima=.not.do_optima
409 if (generation.eq.0) then
422 c Write te current state and population
429 write(tmptext,'(I3)') generation+1
430 call write2log("Preparing inputs for next generation ("//trim(adju&
432 call CreateInputs(BANK_MULTIPLIER*banksize,populacja)
434 c All done? Then let's quit.
440 c ======================================================================
442 c MAIN CODE ENDS HERE
444 c ======================================================================
448 2000 deallocate(populacja)
453 c ======================================================================
454 c Clustering subroutines
455 c ======================================================================
457 include 'cluster.inc'
460 c ======================================================================
461 c Write2log subroutine
462 c ======================================================================
464 c ----------------------------------------------------------------------
466 subroutine Write2log(text)
469 character*200 :: tmptext
470 character(len=*) :: text
472 call itime(timeArray)
473 inquire(file=ologfn,exist=ex)
475 open(olog, file=ologfn, access="append")
476 write(olog,"(A)") "==============================================&
478 tmptext = "= UNRES weights optimizer version "//version
479 write(olog,"(A)") tmptext
480 write(olog,"(A)") info
481 write(olog,"(A)") "==============================================&
485 open(olog, file = ologfn , access = "append")
486 write(olog,"(I2.2,A1,I2.2,A1,I2.2,A2,A)") timeArray(1),":",timeAr&
487 &ray(2),":",timeArray(3),": ",text
489 end subroutine Write2log
491 c ======================================================================
492 c GetNBest subroutine
493 c ======================================================================
494 c Fills up the bank population up to banksize with individuals from
495 c inputpop having the best(lowest) score
496 c ----------------------------------------------------------------------
498 subroutine GetNBest(inputpop,bank,banksize)
499 integer*4 :: banksize, i,j,idx
500 real*8 :: inputpop, bank, best, last
502 dimension inputpop(banksize*BANK_MULTIPLIER,21)
503 dimension bank(banksize,21)
509 do i=1,banksize*BANK_MULTIPLIER
510 if ((inputpop(i,20).lt.best).and.(inputpop(i,20).gt.last)) then
515 bank(j,:)=inputpop(idx,:)
518 end subroutine GetNBest
520 c ======================================================================
521 c FindWorst subroutine
522 c ======================================================================
523 c Finds the worst (highest score) individual in population
524 c ----------------------------------------------------------------------
526 integer*4 function FindWorst(rozmiar,pop)
527 integer*4 :: rozmiar, i, idx
529 dimension pop(rozmiar,21)
534 if (pop(i,20).gt.last) then
543 c ======================================================================
544 c GenPopulation subroutine
545 c ======================================================================
546 c Generates a population (pop) of nind individuals with 19 random
547 c wights from a set of ranges (see GA.inc).
548 c ----------------------------------------------------------------------
550 subroutine GenPopulation(nind,pop)
551 integer*4 :: i,j,nind
553 dimension pop(nind,21)
559 pop(j,1)=WLONG_LOW+(rand(0)*(WLONG_HI-WLONG_LOW))
561 pop(j,2)=WSCP_LOW+(rand(0)*(WSCP_HI-WSCP_LOW))
563 pop(j,3)=WELEC_LOW+(rand(0)*(WELEC_HI-WELEC_LOW))
565 pop(j,4)=WBOND_LOW+(rand(0)*(WBOND_HI-WBOND_LOW))
567 pop(j,5)=WANG_LOW+(rand(0)*(WANG_HI-WANG_LOW))
569 pop(j,6)=WSCLOC_LOW+(rand(0)*(WSCLOC_HI-WSCLOC_LOW))
571 pop(j,7)=WTOR_LOW+(rand(0)*(WTOR_HI-WTOR_LOW))
573 pop(j,8)=WTORD_LOW+(rand(0)*(WTORD_HI-WTORD_LOW))
575 pop(j,9)=WCORRH_LOW+(rand(0)*(WCORRH_HI-WCORRH_LOW))
577 pop(j,10)=WCORR4_LOW+(rand(0)*(WCORR4_HI-WCORR4_LOW))
579 pop(j,11)=WCORR5_LOW+(rand(0)*(WCORR5_HI-WCORR5_LOW))
581 pop(j,12)=WCORR6_LOW+(rand(0)*(WCORR6_HI-WCORR6_LOW))
583 pop(j,13)=WEL_LOC_LOW+(rand(0)*(WEL_LOC_HI-WEL_LOC_LOW))
585 pop(j,14)=WTURN3_LOW+(rand(0)*(WTURN3_HI-WTURN3_LOW))
587 pop(j,15)=WTURN4_LOW+(rand(0)*(WTURN4_HI-WTURN4_LOW))
589 pop(j,16)=WTURN6_LOW+(rand(0)*(WTURN6_HI-WTURN6_LOW))
591 pop(j,17)=WVDWPP_LOW+(rand(0)*(WVDWPP_HI-WVDWPP_LOW))
593 pop(j,18)=WHPB_LOW+(rand(0)*(WHPB_HI-WHPB_LOW))
595 pop(j,19)=WSCCOR_LOW+(rand(0)*(WSCCOR_HI-WSCCOR_LOW))
599 end subroutine GenPopulation
601 c ======================================================================
602 c CrossoverS subroutine
603 c ======================================================================
604 c Does a simple value crossing-over on a pair
605 c of two given individuals, giving two new individuals.
606 c ----------------------------------------------------------------------
608 subroutine CrossoverS(ind1,ind2)
609 real*8 :: ind1(19),ind2(19),temp(19)
611 loc = 1 + int(rand(0)/(1/18.0))
617 end subroutine CrossoverS
619 c ======================================================================
620 c MutationV subroutine
621 c ======================================================================
622 c Does a value mutation for the given individual (ind) with the
623 c given mutation ratio (mratio).
624 c ----------------------------------------------------------------------
626 subroutine MutationV(ind,id,mratio)
632 character*100 :: tmptext
633 character*150 :: logtext
636 if (IGNORE_WEIGHT(i).eq.1) then
637 c write(tmptext,'(I2)') i
638 c call write2log("Skipping weight "//trim(tmptext))
641 if (rand(0)<mratio) then
645 ind(1)=WLONG_LOW+(rand(0)*(WLONG_HI-WLONG_LOW))
648 ind(2)=WSCP_LOW+(rand(0)*(WSCP_HI-WSCP_LOW))
651 ind(3)=WELEC_LOW+(rand(0)*(WELEC_HI-WELEC_LOW))
654 ind(4)=WBOND_LOW+(rand(0)*(WBOND_HI-WBOND_LOW))
657 ind(5)=WANG_LOW+(rand(0)*(WANG_HI-WANG_LOW))
660 ind(6)=WSCLOC_LOW+(rand(0)*(WSCLOC_HI-WSCLOC_LOW))
663 ind(7)=WTOR_LOW+(rand(0)*(WTOR_HI-WTOR_LOW))
666 ind(8)=WTORD_LOW+(rand(0)*(WTORD_HI-WTORD_LOW))
669 ind(9)=WCORRH_LOW+(rand(0)*(WCORRH_HI-WCORRH_LOW))
672 ind(10)=WCORR4_LOW+(rand(0)*(WCORR4_HI-WCORR4_LOW))
675 ind(11)=WCORR5_LOW+(rand(0)*(WCORR5_HI-WCORR5_LOW))
678 ind(12)=WCORR6_LOW+(rand(0)*(WCORR6_HI-WCORR6_LOW))
681 ind(13)=WEL_LOC_LOW+(rand(0)*(WEL_LOC_HI-WEL_LOC_LOW))
684 ind(14)=WTURN3_LOW+(rand(0)*(WTURN3_HI-WTURN3_LOW))
687 ind(15)=WTURN4_LOW+(rand(0)*(WTURN4_HI-WTURN4_LOW))
690 ind(16)=WTURN6_LOW+(rand(0)*(WTURN6_HI-WTURN6_LOW))
693 ind(17)=WVDWPP_LOW+(rand(0)*(WVDWPP_HI-WVDWPP_LOW))
696 ind(18)=WHPB_LOW+(rand(0)*(WHPB_HI-WHPB_LOW))
699 ind(19)=WSCCOR_LOW+(rand(0)*(WSCCOR_HI-WSCCOR_LOW))
701 write(tmptext,'(I4,A13,I2,A7,F7.5,A5,F7.5)') id," at position "&
702 &,i," from: ",ti," to: ",ind(i)
703 logtext = "Mutation occured in individual "//tmptext
704 call write2log (logtext)
710 c ======================================================================
711 c FunkcjaCeluB function
712 c ======================================================================
713 c Simple (dummy) scoring function
714 c ----------------------------------------------------------------------
716 real*8 function FunkcjaCeluB(osobnik)
718 real*8 :: osobnik(20)
720 FunkcjaCeluB = 20 -exp(-abs(WLONG-osobnik(1))) &
721 & - exp(-abs(WSCP-osobnik(2))) &
722 & - exp(-abs(WELEC-osobnik(3))) &
723 & - exp(-abs(WBOND-osobnik(4))) &
724 & - exp(-abs(WANG-osobnik(5))) &
725 & - exp(-abs(WSCLOC-osobnik(6))) &
726 & - exp(-abs(WTOR-osobnik(7))) &
727 & - exp(-abs(WTORD-osobnik(8))) &
728 & - exp(-abs(WCORRH-osobnik(9))) &
729 & - exp(-abs(WCORR4-osobnik(10))) &
730 & - exp(-abs(WCORR5-osobnik(11))) &
731 & - exp(-abs(WCORR6-osobnik(12))) &
732 & - exp(-abs(WEL_LOC-osobnik(13))) &
733 & - exp(-abs(WTURN3-osobnik(14))) &
734 & - exp(-abs(WTURN4-osobnik(15))) &
735 & - exp(-abs(WTURN6-osobnik(16))) &
736 & - exp(-abs(WVDWPP-osobnik(17))) &
737 & - exp(-abs(WHPB-osobnik(18))) &
738 & - exp(-abs(WSCCOR-osobnik(19)))
742 c ======================================================================
743 c FunkcjaCeluB2 function
744 c ======================================================================
745 c Simple (dummy) scoring function
746 c ----------------------------------------------------------------------
748 real*8 function FunkcjaCeluB2(osobnik)
750 real*8 :: osobnik(20)
752 FunkcjaCeluB2 = 1 + 4*(WLONG-osobnik(1))**2 &
753 & + 4*(WSCP-osobnik(2))**2 &
754 & + 4*(WELEC-osobnik(3))**2 &
755 & + 4*(WBOND-osobnik(4))**2 &
756 & + 4*(WANG-osobnik(5))**2 &
757 & + 4*(WSCLOC-osobnik(6))**2 &
758 & + 4*(WTOR-osobnik(7))**2 &
759 & + 4*(WTORD-osobnik(8))**2 &
760 & + 4*(WCORRH-osobnik(9))**2 &
761 & + 4*(WCORR4-osobnik(10))**2 &
762 & + 4*(WCORR5-osobnik(11))**2 &
763 & + 4*(WCORR6-osobnik(12))**2 &
764 & + 4*(WEL_LOC-osobnik(13))**2 &
765 & + 4*(WTURN3-osobnik(14))**2 &
766 & + 4*(WTURN4-osobnik(15))**2 &
767 & + 4*(WTURN6-osobnik(16))**2 &
768 & + 4*(WVDWPP-osobnik(17))**2 &
769 & + 4*(WHPB-osobnik(18))**2 &
770 & + 4*(WSCCOR-osobnik(19))**2
774 c ======================================================================
775 c Weights2str subroutine
776 c ======================================================================
777 c Writes weights of individual(osobnik) to string (lista)
778 c ----------------------------------------------------------------------
780 subroutine Weights2Str(osobnik,coff,lista)
781 real*8, dimension(19) :: osobnik
785 character(80) :: lista
793 write(a,"(A6,F7.5,A6,F7.5,A7,F7.5,A7,F7.5,A6,F7.5,A)") "WLONG=",os&
794 &obnik(1)," WSCP=",osobnik(2)," WELEC=",osobnik(3)," WBOND=",osobni&
795 &k(4)," WANG=",osobnik(5)," &"
797 write(a,"(A7,F7.5,A6,F7.5,A7,F7.5,A8,F7.5,A8,F7.5,A)") "WSCLOC=",o&
798 &sobnik(6)," WTOR=",osobnik(7)," WTORD=",osobnik(8)," WCORRH=",osob&
799 &nik(9),"WCORR5=",osobnik(11)," &"
801 write(a,"(A7,F7.5,A9,F7.5,A8,F7.5,A8,F7.5,A8,F7.5,A)") "WCORR6=",o&
802 &sobnik(12)," WEL_LOC=",osobnik(13)," WTURN3=",osobnik(14)," WTURN4&
803 &=",osobnik(15),"WTURN6=",osobnik(16)," &"
805 write(a,"(A7,F7.5,A6,F7.5,A8,F7.5,A)") "WVDWPP=",osobnik(17)," WHP&
806 &B=",osobnik(18)," WSCCOR=",osobnik(19)," &
809 write(a,"(A7,F7.5,A8,F7.5)") "CUTOFF=",coff," WCORR4=",osobnik(10)
814 c ======================================================================
815 c FunkcjaCeluR function
816 c ======================================================================
817 c Real scoring function
818 c ----------------------------------------------------------------------
820 real*8 function FunkcjaCeluR(zscore)
822 if (zscore.eq.0) then
825 FunkcjaCeluR = 1/zscore
830 c ======================================================================
831 c ReadInput subroutine
832 c ======================================================================
834 subroutine ReadInput(status)
841 character*100 :: wiersz,tmp
842 inquire(FILE=inpfn,EXIST=ex)
846 call write2log('==[ Reading main input ]======================')
850 read(inp, '(A)', iostat=stat) wiersz
853 if ((wiersz(1:4).eq.'PDB=').or.(wiersz(1:4).eq.'pdb=')) then
855 tmp = wiersz(5:len_trim(wiersz))
857 if (tmp(i:i).eq.' ') then
861 if (npdb.gt.maxnpdb) then
862 call write2log("Number of input PDB exceeds maxnpdb!")
867 if (index(trim(tmp),' ').gt.0) then
868 pdbfiles(i)=tmp(1:index(trim(tmp),' '))
870 pdbfiles(i)=tmp(1:len_trim(tmp))
872 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
874 endif ! Koniec czytania "PDB="
877 if ((wiersz(1:4).eq.'ALG=').or.(wiersz(1:4).eq.'alg=')) then
878 alg=wiersz(5:len_trim(wiersz))
881 call write2log ("Using 'simple' algorithm")
883 call write2log ("Using 'better' algorithm")
885 call write2log ("Using 'betterv2' algorithm")
887 call write2log ("Using 'CSA' algorithm")
889 call write2log ("Using 'Clustering CSA' algorithm")
892 call write2log ("Unknown algorithm. Using 'csa' as default")
897 select case (wiersz(1:12))
898 case('GENERATIONS=','generations=')
899 tmp = wiersz(13:len_trim(wiersz))
900 read(tmp,'(I4)') maxgen
904 c select case(wiersz(1:9))
905 c case('CICUTOFF=','cicutoff=')
906 c tmp = wiersz(10:len_trim(wiersz))
907 c read(tmp(1:len_trim(tmp)),'(F7.5)') cicutoff
908 c call write2log("Initial CSA cutoff is set to "//tmp)
912 select case(wiersz(1:6))
913 case('MINCO=','minco=')
914 tmp = wiersz(7:len_trim(wiersz))
915 read(tmp(1:len_trim(tmp)),'(F7.5)') minco
916 call write2log("Minimal CSA cutoff factor is set to "//tmp)
920 select case(wiersz(1:6))
921 case('MAXCO=','maxco=')
922 tmp = wiersz(7:len_trim(wiersz))
923 read(tmp(1:len_trim(tmp)),'(F7.5)') maxco
924 call write2log("Maximal CSA cutoff factor is set to "//tmp)
929 select case(wiersz(1:11))
930 case('POPULATION=','population=')
931 tmp = wiersz(12:len_trim(wiersz))
932 read(tmp,'(I4)') banksize
933 call write2log("Bank size is set to "//tmp)
937 select case(wiersz(1:13))
938 case('WHAMTEMPLATE=','whamtemplate=')
939 tmp = wiersz(14:len_trim(wiersz))
942 if (tmp(i:i).eq.' ') then
946 if (ntwham.gt.maxnpdb) then
947 call write2log("Number of WHAM templates exceeds maxnpdb!")
952 if (index(trim(tmp),' ').gt.0) then
953 whamtemplate(i)=tmp(1:index(trim(tmp),' '))
955 whamtemplate(i)=tmp(1:len_trim(tmp))
957 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
962 select case(wiersz(1:14))
963 case('MREMDTEMPLATE=','mremdtemplate=')
964 tmp = wiersz(15:len_trim(wiersz))
967 if (tmp(i:i).eq.' ') then
971 if (ntmremd.gt.maxnpdb) then
972 call write2log("Number of MREMD templates exceeds maxnpdb!")
977 if (index(trim(tmp),' ').gt.0) then
978 mremdtemplate(i)=tmp(1:index(trim(tmp),' '))
980 mremdtemplate(i)=tmp(1:len_trim(tmp))
982 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
987 select case(wiersz(1:7))
988 case('MAXMIN=','maxmin=')
989 tmp = wiersz(8:len_trim(wiersz))
990 read(tmp,'(I4)') maxminstep
991 if (maxminstep.gt.0) then
992 call write2log("ZSCORE weights minimalization set to "//tmp)
995 call write2log("ZSCORE weights minimalization disabled")
1001 select case(wiersz(1:8))
1002 case('SCRIPTS=','scripts=')
1004 tmp = wiersz(9:len_trim(wiersz))
1005 do i=1,len_trim(tmp)
1006 if (tmp(i:i).eq.' ') then
1010 if (nscripts.gt.maxscripts) then
1011 call write2log("Number of scripts exceeds maxscripts!")
1016 if (index(trim(tmp),' ').gt.0) then
1017 scripts(i)=tmp(1:index(trim(tmp),' '))
1019 scripts(i)=tmp(1:len_trim(tmp))
1021 call write2log("Script will be used: "//scripts(i))
1022 tmp=tmp(index(trim(tmp),' ')+1:len_trim(tmp))
1024 end select ! Koniec czytania "scripts="
1029 c write additional info to log
1030 write(tmp,'(F8.5)') MUTRATIO
1031 call write2log("Mutation ratio is set to "//tmp)
1032 write(tmp,'(I2)') BANK_MULTIPLIER
1033 call write2log("Bank multiplier is set to "//tmp)
1034 write(tmp,'(I5)') BANK_MULTIPLIER*banksize
1036 call write2log("Trail population size will be "//trim(tmp)//" in&
1039 call write2log("Input file unresga.inp does not exist!!")
1040 write(*,*) "Input file unresga.inp does not exist!!"
1044 c Checking set parameters after reading input
1048 call write2log("Can't find 'PDB=' entry in input file")
1052 inquire(FILE=trim(pdbfiles(i)),EXIST=ex)
1054 call write2log("Can't find file "//trim(pdbfiles(i)))
1061 if (maxgen.eq.0) then
1062 call write2log("Couldn't find GENERATIONS= entry in input file")
1067 if (banksize.eq.0) then
1068 call write2log("Can't find POPULATION= entry in input file")
1070 elseif(mod(banksize,2).eq.1) then
1071 call write2log("POPULATION has to be a even number.")
1076 if (ntwham.ne.npdb) then
1077 call write2log("Number of WHAM templates and PDB files is not equ&
1083 if (ntmremd.ne.npdb) then
1084 call write2log("Number of MREMD templates and PDB files is not eq&
1090 if (nscripts.gt.0) then
1092 inquire(FILE=trim(scripts(i)),EXIST=ex)
1094 call write2log("Can't find file "//trim(scripts(i)))
1101 end subroutine ReadInput
1104 c ======================================================================
1105 c CreateInputs subroutine
1106 c ======================================================================
1107 c Creates input files for MREMD, WHAM and ZSCORE.
1108 c ----------------------------------------------------------------------
1110 subroutine CreateInputs(rozmiar,pop)
1113 include 'common.inc'
1114 character(80),dimension(5) :: wagi
1115 integer*4 :: rozmiar,i,j,k
1117 dimension pop(rozmiar,21)
1118 !character*50 :: pdbfiles(maxnpdb)
1119 character*50 :: command,tmptext, prefix
1120 character*256 :: line,plik
1121 integer :: gdzie = 0
1122 character(len=*), parameter :: FMT = "(F9.5,F8.5,F8.5,F8.5,F8.5,F&
1123 &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&
1125 !write(tmptext,'(I10)') banksize
1126 !call write2log(trim(tmptext))
1129 prefix=pdbfiles(j)(1:len_trim(pdbfiles(j))-4)
1130 c Create MREMD input
1131 open(imremd, file = mremdtemplate(j))
1132 plik=trim(prefix)//"_"//omremdfn
1133 call write2log(trim("Creating MREMD input: "//plik))
1134 open(omremd, file = plik)
1135 3000 read(imremd, '(A)', end = 3010) line
1136 gdzie = index (line, '{PREFIX}')
1137 if (gdzie .ne. 0) then
1138 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+8:))
1139 write(omremd,"(A)") trim(line)
1140 elseif (index(line,'{POPSIZE}') .ne. 0) then
1141 gdzie = index (line, '{POPSIZE}')
1142 write(tmptext,'(I4)') rozmiar
1143 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(
1145 write(omremd,"(A)") trim(line)
1146 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1147 gdzie = index (line, '{WEIGHTS}')
1149 call Weights2Str(pop(i,:),CUTOFF,wagi)
1150 write(omremd,"(A)") wagi(1)
1151 write(omremd,"(A)") wagi(2)
1152 write(omremd,"(A)") wagi(3)
1153 write(omremd,"(A)") wagi(4)
1154 write(omremd,"(A)") wagi(5)
1157 write(omremd,"(A)") trim(line)
1166 open(iwham, file = whamtemplate(j))
1167 plik=trim(prefix)//"_"//owhamfn
1168 call write2log(trim("Creating WHAM input: "//plik))
1169 open(owham, file = plik)
1170 3015 read(iwham, '(A)', end = 3020) line
1171 gdzie = index (line, '{PREFIX}')
1172 if (gdzie .ne. 0) then
1173 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+8:))
1174 write(owham,"(A)") trim(line)
1175 elseif (index(line,'{POPSIZE}') .ne. 0) then
1176 gdzie = index (line, '{POPSIZE}')
1177 write(tmptext,'(I4)') rozmiar
1178 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1180 write(owham,"(A)") trim(line)
1181 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1182 gdzie = index (line, '{WEIGHTS}')
1184 call Weights2Str(pop(i,:),CUTOFF,wagi)
1185 write(owham,"(A)") wagi(1)
1186 write(owham,"(A)") wagi(2)
1187 write(owham,"(A)") wagi(3)
1188 write(owham,"(A)") wagi(4)
1189 write(owham,"(A)") wagi(5)
1190 write(owham,"(A)") ''
1193 write(owham,"(A)") trim(line)
1201 c Create ZSCORE input
1202 open(izscore, file = izscorefn)
1203 call write2log(trim("Creating ZSCORE input: "//ozscorefn))
1204 open(ozscore, file = ozscorefn)
1205 3025 read(izscore, '(A)', end = 3030) line
1206 gdzie = index (line, '{PREFIX')
1207 if (gdzie .ne. 0) then
1208 read(line(gdzie+7:gdzie+9),'(I2.2)') k
1209 prefix=pdbfiles(k)(1:len_trim(pdbfiles(k))-4)
1210 line=trim(line(1:gdzie-1))//trim(prefix)//trim(line(gdzie+10:)&
1213 write(ozscore,"(A)") trim(line)
1214 elseif (index(line,'{PARAM') .ne. 0) then
1215 gdzie=index(line,'{PARAM')
1216 read(line(gdzie+6:gdzie+8),'(I2.2)') k
1217 prefix=pdbfiles(k)(1:len_trim(pdbfiles(k))-4)
1219 write(tmptext,'(I3.3)') i
1220 line=trim(line(1:gdzie-1))//trim(prefix)//"_wham_par"//tmptex&
1222 write(ozscore,"(A)") trim(line)
1224 elseif (index(line,'{POPSIZE}') .ne. 0) then
1225 gdzie = index (line, '{POPSIZE}')
1226 write(tmptext,'(I4)') rozmiar
1227 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1229 write(ozscore,"(A)") trim(line)
1230 elseif (index(line,'{WEIGHTS}') .ne. 0) then
1231 gdzie = index (line, '{WEIGHTS}')
1233 call Weights2Str(pop(i,:),CUTOFF,wagi)
1234 write(ozscore,"(A)") wagi(1)
1235 write(ozscore,"(A)") wagi(2)
1236 write(ozscore,"(A)") wagi(3)
1237 write(ozscore,"(A)") wagi(4)
1238 write(ozscore,"(A)") trim(wagi(5))
1239 write(ozscore,"(A)") ''
1241 elseif (index(line,'{MAXMIN}') .ne. 0) then
1242 gdzie = index (line, '{MAXMIN}')
1243 write(tmptext,'(I4)') maxminstep
1244 line=trim(line(1:gdzie-1))//trim(adjustl(tmptext))//trim(line(&
1246 write(ozscore,"(A)") trim(line)
1248 write(ozscore,"(A)") trim(line)
1257 call write2log('Copying scripts is disabled.')
1259 c ! Open output file
1260 c plik=trim(prefix)//"/"//trim(scripts(i))
1261 c open(oscript, file = plik)
1263 c plik=trim(scripts(i))
1264 c open(iscript, file = plik)
1265 c ! rewrite from input to output
1266 c3030 read(iscript, '(A)', end = 3035) line
1267 c write(oscript,'(A)') trim(line)
1275 c ==========================================
1277 c ==========================================
1280 c write(ow,'(I4)') generation
1281 c write(ow,'(200A)') "# WLONG WSCP WELEC WBOND WANG WSC&
1282 c &LOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC WTURN&
1283 c &3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR"
1285 c write(ow,FMT) pop(i,1),pop(i,2),pop(i,3),pop(i,4), pop(i,5),pop&
1286 c &(i,6),pop(i,7),pop(i,8),pop(i,9),pop(i,10),pop(i,11),pop(i,12),pop&
1287 c &(i,13),pop(i,14),pop(i,15),pop(i,16),pop(i,17),pop(i,18),pop(i,19)
1291 end subroutine CreateInputs
1294 c ======================================================================
1295 c ZnajdzPodobnego function
1296 c ======================================================================
1297 c Finds the most similar individual to osobnik in population(populacja)
1298 c and returns his position in the population
1299 c ----------------------------------------------------------------------
1301 integer*4 function ZnajdzPodobnego(rozmiar,populacja,osobnik,csacu&
1303 integer*4 :: rozmiar,pozycja
1304 real*8 :: delta,mindelta,csacutoff
1306 real*8, dimension(rozmiar,21) :: populacja
1307 real*8, dimension(21) :: osobnik
1309 mindelta = csacutoff
1310 c mindelta = 10000.0
1316 delta=delta+(populacja(i,j)-osobnik(j))**2
1318 c write(tmp,'(2F7.5 )') delta,csacutoff
1319 c call write2log("Delta is "//tmp)
1321 if (delta.lt.mindelta) then
1324 write(tmp,'(F7.5,X,I4)') delta,pozycja
1325 call write2log(" Delta is "//tmp)
1329 ZnajdzPodobnego = pozycja
1332 c ======================================================================
1333 c WybierzOsobnika function
1334 c ======================================================================
1335 c Selects individual from population using roulette method
1336 c ----------------------------------------------------------------------
1338 integer*4 function WybierzOsobnika(rozmiar,populacja)
1339 integer*4 :: osobnik, rozmiar
1340 real*8 :: los, partsum
1342 real*8, dimension(rozmiar,21) :: populacja
1348 osobnik = osobnik + 1
1349 partsum = partsum + populacja(osobnik,21)
1350 if ((osobnik.eq.rozmiar).or.(partsum.ge.los)) exit
1353 WybierzOsobnika = osobnik
1357 c ======================================================================
1358 c Najlepszy function
1359 c ======================================================================
1360 c Selects the individual with the best score from population
1361 c ----------------------------------------------------------------------
1363 integer*4 function Najlepszy(rozmiar, maks, populacja)
1364 integer*4 :: rozmiar
1366 real*8, dimension(rozmiar,21) :: populacja
1369 if (populacja(i,20).eq.maks) then
1376 c ======================================================================
1377 c WriteState subroutine
1378 c ======================================================================
1379 c Writes current state of calculations in case jobs have to be
1381 c ----------------------------------------------------------------------
1383 subroutine WriteState()
1386 include 'common.inc'
1388 open(ostate,file=ostatefn)
1389 write(ostate,'(I4)') generation
1390 write(ostate,'(L2)') do_optima
1391 write(ostate,'(L2)') do_ga
1392 write(ostate,'(F7.5)') avrd
1394 end subroutine WriteState
1396 c ======================================================================
1397 c ReadPopulation subroutine
1398 c ======================================================================
1399 c Reads population from population.summary file
1400 c ----------------------------------------------------------------------
1402 subroutine ReadPopulation(nind,pop)
1405 character*8 :: dummy
1406 dimension pop(nind,21)
1409 character(len=*), parameter :: FMT = "(F9.5,F8.5,F8.5,F8.5,F8.5,F&
1410 &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&
1412 read(opopsum,'(A)') dummy
1414 read(opopsum,FMT) pop(i,1),pop(i,2),pop(i,3),pop(i,4), pop(i,5),p&
1415 &op(i,6),pop(i,7),pop(i,8),pop(i,9),pop(i,10),pop(i,11),pop(i,12),p&
1416 &op(i,13),pop(i,14),pop(i,15),pop(i,16),pop(i,17),pop(i,18),pop(i,1&
1419 end subroutine ReadPopulation
1421 c ======================================================================
1422 c ReadOptimaW subroutine
1423 c ======================================================================
1424 c Reads weights from zscore generated weights_opt.zscorepar_XXX files
1426 c nind - number of individuals/files to read
1427 c pop - array where weights are stored
1428 c ----------------------------------------------------------------------
1430 subroutine ReadOptimaW(nind,pop)
1431 integer*4 :: i,nind,stat
1434 character*40 :: filename
1435 character*200 :: tmptxt
1436 dimension pop(nind,21)
1441 c Cosmetic stuff for pretty log
1442 call write2log("==[ Reading weights from zscore files ]=======")
1443 call write2log("# WLONG WSCP WELEC WBOND WANG WS&
1444 &CLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_L&
1445 &OC WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR")
1447 c Actual weight read and error handling
1450 write(tmptxt,'(I3.3)') i
1451 filename = "weights_opt.zscorepar_"//trim(tmptxt)
1452 open(izsoptw, file = filename)
1453 read(izsoptw,"(A4,F7.5,A6,F7.5,A7,F7.5,A7,F7.5,A6,F7.5,A)",iosta&
1454 &t=stat) tmptxt,pop(i,1),tmptxt,pop(i,2),tmptxt,pop(i,3),tmptxt,pop&
1455 &(i,4),tmptxt,pop(i,5)
1458 call write2log("-- ERROR while reading "//trim(filename)//"--")
1464 read(izsoptw,"(A7,F7.5,A6,F7.5,A7,F7.5,A8,F7.5,A8,F7.5,A)",iosta&
1465 &t=stat) tmptxt,pop(i,6),tmptxt,pop(i,7),tmptxt,pop(i,8),tmptxt,pop&
1466 &(i,9),tmptxt,pop(i,11)
1469 call write2log("-- ERROR while reading "//trim(filename)//"--")
1475 read(izsoptw,"(A7,F7.5,A9,F7.5,A8,F7.5,A8,F7.5,A8,F7.5,A)",iosta&
1476 &t=stat) tmptxt,pop(i,12),tmptxt,pop(i,13),tmptxt,pop(i,14),tmptxt,&
1477 &pop(i,15),tmptxt,pop(i,16)
1480 call write2log("-- ERROR while reading "//trim(filename)//"--")
1486 read(izsoptw,"(A7,F7.5,A8,F7.5,A6,F7.5,A)",iostat=stat) tmptxt, &
1487 &pop(i,19),tmptxt,pop(i,17),tmptxt,pop(i,18),tmptxt
1490 call write2log("-- ERROR while reading "//trim(filename)//"--")
1496 read(izsoptw,"(A22,F7.5)",iostat=stat) tmptxt, pop(i,10)
1499 call write2log("-- ERROR while reading "//trim(filename)//"--")
1506 write(tmptxt,'(19F9.5)') (pop(i,j),j=1,19)
1507 call write2log(trim(tmptxt))
1512 end subroutine ReadOptimaW
1515 c ======================================================================
1516 c ReadZEnergy subroutine
1517 c ======================================================================
1518 c Reads Energy from ZSCORE output files zscore_out_parXXX_GB000
1519 c ----------------------------------------------------------------------
1521 subroutine ReadZEnergy(nind,pop)
1525 character*40 :: filename,tmptxt,tmptxt2
1526 character*100 :: wiersz
1527 dimension pop(nind,21)
1530 call write2log("==[ Reading Final Function Value from zscore ]===&
1533 write(tmptxt,'(I3.3)') i
1535 filename=trim(izenergyfn)//trim(tmptxt)//"_GB000"
1536 open(izenergy, file = filename)
1538 read(izenergy, '(A)', iostat=stat) wiersz
1540 if (wiersz(1:22).eq.' Final function value:') then
1541 tmptxt=trim(adjustl(wiersz(23:48)))
1542 read(tmptxt,'(F16.5)') pop(i,20)
1543 write(tmptxt2,'(E15.7)') pop(i,20)
1544 call write2log("Reading score from "//filename//" : "//tmptxt/&
1548 if (pop(i,20).eq.0) then
1549 c Setting FFV to a realy big valiue or otherwise CalcFittness will have problems
1550 pop(i,20)=huge(0.0d0)
1551 call write2log("ERROR while reading FFV from "//filename)
1556 end subroutine ReadZEnergy
1558 c =======================================================================
1559 c WritePopSum subroutine
1560 c =======================================================================
1561 c Writes whole individuals (weights, score, ID, generation) to file
1562 c population.summary This file can be used to plot evolution of the
1563 c weights and scores over time.
1564 c -----------------------------------------------------------------------
1565 subroutine WritePopSum()
1566 logical :: jestplik = .false.
1567 character*5 :: tmptext
1570 c dimension bank(nind,21)
1572 include 'common.inc'
1575 c write(*,*) banksize
1577 write(tmptext,'(I3.3)') generation
1578 inquire(file=opopsumfn, exist=jestplik)
1579 if (.not. jestplik) then
1580 open(opopsum, file = opopsumfn)
1581 write(opopsum, "(A189)") "# WLONG WSCP WELEC WBOND WANG &
1582 & WSCLOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 WEL_LOC&
1583 & WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCOR SCO&
1588 open(opopsum, file = opopsumfn, access = "append")
1589 c call ReadPopulation(banksize,populacja)
1590 write(opopsum, "(A189)") "# ==== Generation "//trim(tmptext)//" ==&
1591 &==================================================================&
1592 &==================================================================&
1593 &================================="
1594 c call write2log(banksize)
1597 c write(opopsum,"(F9.5,2F8.5)") populacja(i,1),populacja(i,2),popu&
1599 write(opopsum,"(F9.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,&
1600 &F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F8.5,F20.5,I8,I8)") bank(i&
1601 &,1),bank(i,2),bank(i,3),bank(i,4),bank(i,5),bank(i,6),bank(i,7),ba&
1602 &nk(i,8),bank(i,9),bank(i,10),bank(i,11),bank(i,12),bank(i,13),bank&
1603 &(i,14),bank(i,15),bank(i,16),bank(i,17),bank(i,18),bank(i,19),bank&
1609 end subroutine WritePopSum
1611 c ======================================================================
1612 c WriteBank subroutine
1613 c ======================================================================
1614 c Writes CSA BANK to file
1615 c ----------------------------------------------------------------------
1616 subroutine WriteBank(b)
1618 include 'common.inc'
1619 real*8,dimension(banksize,21) :: b
1620 character*250 :: tmptext
1621 character*250 :: header
1624 header="# WLONG WSCP WELEC WBOND WANG WSC&
1625 &LOC WTOR WTORD WCORRH WCORR4 WCORR5 WCORR6 &
1626 &WEL_LOC WTURN3 WTURN4 WTURN6 WVDWPP WHPB WSCCO&
1629 call write2log("Writing Bank to file "//iobankfn)
1630 open(iobank, file = iobankfn)
1631 write(iobank, "(A)") trim(adjustl(header))
1634 write(iobank,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1635 write(tmptext,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1636 call write2log(trim(tmptext))
1641 c ======================================================================
1642 c ReadBank subroutine
1643 c ======================================================================
1644 c Read CSA BANK from file
1645 c ----------------------------------------------------------------------
1646 subroutine ReadBank(b)
1648 include 'common.inc'
1649 real*8,dimension(banksize,21) :: b
1650 character*250 :: tmptext
1652 call write2log("Reading Bank from file "//iobankfn)
1653 open(iobank, file = iobankfn)
1655 read(iobank,"(A)") tmptext
1657 read(iobank,"(19F10.5,E15.7,F10.5)") (b(i,j),j=1,21)
1658 write(tmptext,'(19F10.5,E15.7,F10.5)') (b(i,j),j=1,21)
1659 call write2log(trim(tmptext))
1664 c ======================================================================
1665 c CalcFitness subroutine
1666 c ======================================================================
1667 c Calculates fitness of every individual in the bank
1668 c ----------------------------------------------------------------------
1669 subroutine CalcFitness(b,fitn)
1670 include 'common.inc'
1671 real*8,dimension(banksize,21) :: b
1672 real*8 :: fitn, sumfitn
1678 fitn=fitn+(1/b(i,20))
1679 sumfitn=sumfitn+b(i,20)
1682 b(i,21)=1/(b(i,20)*fitn)
1683 c b(i,21)=b(i,20)/fitn
1688 c ======================================================================
1689 c CalcAvgDist subroutine
1690 c ======================================================================
1691 c Calculates average distance between individuals in the bank
1692 c ----------------------------------------------------------------------
1693 subroutine CalcAvgDist(b,avgd)
1694 include 'common.inc'
1695 real*8,dimension(banksize,21) :: b
1700 nd = (banksize-1)*banksize/2 ! number of distances to calculate
1705 d=d+(b(i,w)-b(j,w))**2
1712 c -----------------------------------------------------------------------