def Simulate(): record_path = '/Users/matthewbakalar/projects/VASP/latticerecord2.dat' simulation_steps = 100 initial_size = 10 max_size = 10000 c_steps = 10 c_multiplier = 10 c_range = sp.zeros(c_steps) c_range[0] = .0001 for i in range(1,c_steps): c_range[i] = c_range[i-1] * c_multiplier error = sp.zeros(c_range.size) a = sp.zeros(c_range.size) b = sp.zeros(c_range.size) count = 0 for conc in c_range: lattice = LatticeModel(initial_size, max_size) simulation = VaspSimulation(lattice) record = SimulationRecord(record_path, simulation, 'w') record.open_file() VaspSimulation.VASP_ON = VaspSimulation.VASP_ON_BASE * conc for i in range(0, simulation_steps): simulation.advance_simulation() record.save_state() record.close_file() record = SimulationRecord(record_path, simulation, 'r') time_recon = TimeReconstruction(record) lvt = time_recon.length_vs_time() #Linear regressison -polyfit - polyfit can be used other orders polys n = lvt[0].size (ar,br)=polyfit(lvt[0],lvt[1],1) xr=polyval([ar,br],lvt[0]) #compute the mean square error err=sp.sqrt(sum((xr-lvt[1])**2)/n) print('Linear regression using polyfit') print('parameters: regression: a=%.2f b=%.2f, ms error= %.3f' % (ar,br,err)) pyplot.plot(lvt[0], lvt[1], 'g') pyplot.plot(lvt[0], xr, 'r') pyplot.show() a[count] = ar b[count] = br error[count] = err count+=1 print 'Count = %(count)d' % {'count':count}
def Report(): imgname = 'polymethodsgrowth.png' slopename = 'slopes.txt' slopes = sp.zeros([len(Experiment.runs), len(Experiment.conc)]) i = 0 j = 0 pyplot.figure(1) for sim, fname in Experiment.runs: for conc in Experiment.conc[0:6]: print 'Concentration: ', str(conc) fname_conc = fname + '_c=' + str(conc) pth = os.path.join(Experiment.datafolder, fname_conc) record = SimulationRecord(pth, sim, 'r') recon = TimeReconstruction(record) data = recon.length_vs_time() if fname == 'processive.txt': color = 'r' elif fname == 'non_processive.txt': color = 'g' else: color = 'b' pyplot.plot(data[0], data[1], color) (ar,br)=polyfit(data[0],data[1],1) slopes[i, j] = ar j += 1 j = 0 i += 1 # length versus time pyplot.legend(('Processive', 'Non-processive', 'Detach'), 'upper left', shadow=True, fancybox=False) pyplot.xlabel('Time (s)') pyplot.ylabel('Filament length') pyplot.savefig(os.path.join(Experiment.datafolder, imgname)) slope_fname = os.path.join(Experiment.datafolder, slopename) sp.savetxt(slopename, slopes) # slope vs concentration pyplot.figure(2) pyplot.plot(Experiment.conc, slopes[0]) pyplot.plot(Experiment.conc, slopes[1]) pyplot.plot(Experiment.conc, slopes[2]) pyplot.legend(('Processive', 'Non-processive', 'Detach'), 'upper left', shadow=True, fancybox=False) # pyplot.xscale('log') pyplot.xlabel('Concentration') pyplot.ylabel('Average Growth Rate') pyplot.show() return slopes