''' Implementation of the model reported in Wilson SP and Glancy J (2016) How Self-Organisation Can Guide Evolution. Royal Society Open Science. Recreates Figures 1 and 2 from the main text. ''' import numpy as np import matplotlib.pyplot as pl import os # Define model parameters n = np.array([1,2,4,8]) # Litter size N = 500 # Population size T = 2000 # Number of generations Ta = 20. # Ambient temperature Mmax = 37. # Maximum metabolic rate Cmax = 2. # Maximum thermal conductance initial = 0.8 # Initial scaling of m and c sigma = 0.1 # Extent of mutation p = 0.1 # Probability of mutation Tp = Mmax # Preferred temperature params = ' '+str(N)+' '+str(T)+' '+str(Ta)+' '+str(Mmax)+' '+str(Cmax)+' '+str(initial)+' '+str(sigma)+' '+str(p) # Initialize plots F1 = pl.figure(1,figsize=(6,6)) f1 = F1.add_subplot(111) F2 = pl.figure(2,figsize=(12,12)) for i in range(len(n)): # Run the model to generate log files seed = str(i) cmd = './model '+seed+' '+str(n[i])+params print cmd os.system('rm log*') os.system(cmd) # Extract data from log files F = np.genfromtxt('logF.txt', delimiter=',',comments="#")[:-1] m = np.genfromtxt('logM.txt', delimiter=',',comments="#")[:-1] c = np.genfromtxt('logC.txt', delimiter=',',comments="#")[:-1] t1 = np.genfromtxt('logt1.txt', delimiter=',',comments="#")[:-1] tT = np.genfromtxt('logtT.txt', delimiter=',',comments="#")[:-1] t1 = t1.reshape([t1.size/2,2]) tT = tT.reshape([tT.size/2,2]) # Plot figure 1 f1.plot(F) f1.axis(np.array([0,T,0,1])) f1.set_aspect(np.diff(f1.get_xlim())/np.diff(f1.get_ylim())) f1.set_axisbelow(True) f1.set_xlabel(r"$t$",fontsize=30); f1.set_ylabel(r"$F$",fontsize=30); # Plot figure 2 f2 = F2.add_subplot(2,2,i+1) f2.scatter(t1[:,0]*Mmax,t1[:,1]*Cmax,s=3,marker='o',facecolor=(0,1,0),lw=0) f2.scatter(tT[:,0]*Mmax,tT[:,1]*Cmax,s=3,marker='o',facecolor=(1,0,0),lw=0) f2.plot(m*Mmax,c*Cmax,color=(0,0,1)) f2.plot([0,50.],[0,50./(Tp-Ta)],'--',color=(0,0,0)) f2.plot([0,50.],[0,50./((Tp-Ta)*n[i]**(-1./4))],'-',color=(0,0,0)) f2.set_xlabel(r"$M$",fontsize=30); f2.set_ylabel(r"$C$",fontsize=30); f2.axis(np.array([0,Mmax,0,Cmax])) # Add legend k = [] for i in n: k = np.hstack([k,r"$n="+str(i)+"$"]) f1.legend(k,frameon=False,prop={'size':20}) # Save PDF figures F1.savefig("Figure1.pdf",format='pdf') F2.savefig("Figure2.pdf",format='pdf')