~dhogan/ift

b889baf213c8c85a5461343a41f3973fe9e21f01 — Daniel Hogan 3 years ago f378a9d
add multiprocessing code
2 files changed, 118 insertions(+), 0 deletions(-)

A mp.py
A plot.py
A mp.py => mp.py +46 -0
@@ 0,0 1,46 @@
#!/usr/bin/env python

import kinesin
import numpy as np
import multiprocessing as mp
import argparse

def simulate_parallel_times(xypair):
	error = kinesin.simulate(xypair[0], xypair[1], simulations=simulations, steps=steps)
	with open('/home/dhogan/data', 'a') as f:
		f.write(str(xypair[0]) + '\t' + str(xypair[1]) + '\t' + str(error) + '\n')

if __name__ == "__main__":
	parser = argparse.ArgumentParser(description='Multiprocess KIF3AB, KIF17 on rate simulations')
	parser.add_argument('-p', help='number of processes', required=True)
	parser.add_argument('--kif3start', help='starting KIF3 on rate', required=True)
	parser.add_argument('--kif17start', help='starting KIF17 on rate', required=True)
	parser.add_argument('--kif3resolution', help='KIF3 on rate resolution', required=True)
	parser.add_argument('--kif17resolution', help='KIF17 on rate resolution', required=True)
	parser.add_argument('--kif3points', help='KIF3 number of points', required=True)
	parser.add_argument('--kif17points', help='KIF17 number of points', required=True)
	parser.add_argument('--simulations', help='number of simulations', required=True)
	parser.add_argument('--steps', help='number of steps', required=True)
	args = parser.parse_args()
	
	p = int(args.p)
	kif3start = float(args.kif3start)
	kif17start = float(args.kif17start)
	resolution3 = float(args.kif3resolution)
	resolution17 = float(args.kif17resolution)
	numpnts3 = int(args.kif3points)
	numpnts17 = int(args.kif17points)
	simulations = int(args.simulations)
	steps = int(args.steps)
	
	xy = []
	kif3array  = np.arange(kif3start,  kif3start+(numpnts3*resolution3),    resolution3)
	kif17array = np.arange(kif17start, kif17start+(numpnts17*resolution17), resolution17)
	for x in kif3array:
		for y in kif17array:
			xy.append((x,y))
	
	pool = mp.Pool(processes=p)
	res = pool.map(simulate_parallel_times, xy)
	pool.close()
	pool.join()

A plot.py => plot.py +72 -0
@@ 0,0 1,72 @@
#!/usr/bin/env python3

import matplotlib.pyplot as plt
import numpy as np

sherlock1 = np.genfromtxt('data',delimiter='\t')

sherlockSSE = sherlock1[:, 2]

numpnts = 141
kif3start = 0.19
kif17start = 0.19
resolution3 = 0.001
resolution17 = 0.001
kif3array  = np.arange(kif3start,  kif3start+(numpnts*resolution3),
resolution3)
kif17array = np.arange(kif17start, kif17start+(numpnts*resolution17),
resolution17)

imgx = np.append(kif3array, np.amax(kif3array)+resolution3)-resolution3/2
imgy = np.append(kif17array,
np.amax(kif17array)+resolution17)-resolution17/2


numpnts = 141
z = np.resize(sherlockSSE, [numpnts, numpnts])

zratio = z/np.amin(z)

minindex = np.unravel_index(np.argmax(1/zratio), (1/zratio).shape)


levels=[0.95]


# Plot
plt.viridis()
fig = plt.figure(figsize=(8,8))
fig.subplots_adjust(bottom=0.1, left=0.1)
plt.pcolormesh(imgx, imgy, 1/zratio)
plt.colorbar( shrink=0.80)
plt.plot(kif3array[minindex[1]], kif17array[minindex[0]], 'ow' )
plt.contour(kif3array, kif17array, 1/zratio, levels, linewidths=2,
colors=('w', 'w'))
plt.rcParams.update({'font.size': 14})
plt.ylabel(r'$K_{ON, KIF17}$'+' (s' +r'$^{-1}$' + ')')
plt.xlabel(r'$K_{ON, KIF3}$'+' (s' +r'$^{-1}$' + ')')
plt.xticks([0.23, 0.27, 0.31])
plt.yticks([0.23, 0.27, 0.31])
plt.axis([0.2195, 0.3305, 0.2195, 0.3305])
plt.axes().set_aspect('equal')
plt.savefig('sherlock_40_20000_5perc.pdf')


# Find indices for min values along contour
zbelow =((1/zratio)<0.9)+0
minkif3index = np.argmin(np.amin(zbelow, axis=0)) -1
maxkif3index = 141 - np.argmin(np.amin(zbelow, axis=0)[::-1])
minkif17index = np.argmin(np.amin(zbelow, axis=1)) - 1
maxkif17index = 141 - np.argmin(np.amin(zbelow, axis=1)[::-1])

# Confidence intervals
print(kif3array[minkif3index])
print(kif3array[maxkif3index])
print(kif17array[minkif17index])
print(kif17array[maxkif17index])

# Errors
kif3array[minkif3index]-kif3array[minindex[1]]
kif3array[maxkif3index]-kif3array[minindex[1]]
kif17array[minkif17index]-kif17array[minindex[0]]
kif17array[maxkif17index]-kif17array[minindex[0]]