def potentialEnergyplot(): q0 = RCLPolymer(**polymerParams) dt = 0.01 T = 120 numSteps = int(T / dt) cutoffs = np.array([0.5, 1., 1.5, 2., 2.5, 3.]) * 0.2 numRealisations = 100 for cutoff in cutoffs: p0 = q0.copy() kappa = 3 * 0.008 / (p0.b**2) repulsionForce = lambda polymer: -kappa * ExcludedVolume( polymer, cutoff) p0.addnewForce(repulsionForce) energy = np.zeros((numRealisations, numSteps)) for i in range(numRealisations): for j in range(numSteps): p0.step(1, dt, 0.008) energy[i][j] = p0.potentialEnergy() meanEnergy = np.mean(energy, axis=0) plt.plot(np.linspace(0, T, numSteps), meanEnergy, label='Cut-off: %s $\mu$m' % cutoff) plt.axvline(x=p0.relaxTime(0.008), color='r') plt.legend() plt.show()
def proba_v_gNc(polymerParams, simulationParams, x_g, x_Nc, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_gNc_withVE' + '.csv' first_time = True N = polymerParams['numMonomers'] with open('results/' + filename, 'w') as csvfile: for i, g in enumerate(x_g): print("Simulation for g = %s " % g) simulationParams['genomicDistance'] = g for j, nc in enumerate(x_Nc): print("Simulation for Nc = %s " % nc) polymerParams['Nc'] = nc ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (nc + simulationParams['Nc_inDamageFoci']) / ( (N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) # simulationParams['excludedVolumeCutOff'] = 3*simulationParams['encounterDistance'] ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 simulationParams['numMaxSteps'] = int(60 // simulationParams['dt']) print("ε = %s" % (simulationParams['encounterDistance'])) p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def trackAlpha_vsNc(x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackAlphaAfterDSB_vsNc' with open('results/' + filename + '.csv', 'w') as csvfile: first_time = True for i, Nc in enumerate(x_Nc): polymerParams['Nc'] = Nc p0 = RCLPolymer(**polymerParams) # Waiting time will be relaxation time (Nc dependant) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) simulationParams['VE_waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, trackAlpha) if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False os.makedirs('results/' + filename + '_figures') writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) # Save MSD raw data with open( 'results/' + filename + '_figures/nc' + str(Nc) + 'msd_data.csv', 'w') as rawdata: rowwriter = csv.writer(rawdata) for msd_data in mc.results['monomersMSD'].transpose(): rowwriter.writerow(msd_data) # Save MSD curve plt.figure() plt.plot(mc.results['monomersMSD'].transpose()) legend = ['_o'] * polymerParams['numMonomers'] legend[simulationParams['A1']] = 'a1' legend[simulationParams['A1'] + 1] = 'a2' legend[simulationParams['B1']] = 'b1' legend[simulationParams['B1'] + 1] = 'b2' legend = tuple(legend) plt.legend(legend) plt.savefig('results/' + filename + '_figures/nc' + str(Nc) + '.png') plt.close()
def proba_vs_encounterDistance(numRealisations): probas = [] demiCI = [] testDistances = np.arange(0.001, 0.004, 0.00025) date = strftime("%Y_%m_%d_%H_%M") plt.figure() plt.xlabel('Encounter distance ($\mu$ m)') plt.ylabel('$\mathbb{P}$(Repair)') for epsilon in testDistances: p0 = RCLPolymer(nb_monomers, dimension, b, numConectors) mc = EncounterSimulation(dt, diffusionCte, p0, dt_relax, numRealisations, maxIterationsPerExperiment, 2, genomicDistance, epsilon, waitingSteps) mc.run() probas.append(mc.repairProba[0]) demiCI.append(mc.repairProba[1]) probas = np.array(probas) output = np.zeros((3, len(probas))) output[0] = testDistances output[1] = probas output[2] = demiCI np.save( 'results/proba_vs_encounterDistance__' + str(nb_monomers) + 'monomers_' + str(numRealisations) + 'iterations_' + date + '.npy', output) plt.plot(testDistances, probas, '-o') plt.show()
def trackDefinedDSBtrajectory(polymerParams, simulationParams, x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackDSB_fixedDSBs' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nc in enumerate(x_Nc): print("\n Simulation for Nc = %s CLs " % Nc) polymerParams['Nc'] = Nc # ### ADAPTIVE ENCOUNTER DISTANCE # xi = 2*(Nc)/((N-1)*(N-2)) ## scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) # simulationParams['encounterDistance'] = adaptiveEpsilon(xi, N, polymerParams['b']) # # simulationParams['distanceThreshold'] = simulationParams['encounterDistance'] p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results})
def proba_v_sigma(polymerParams, simulationParams, x_sigma): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_msrg-v_sigma' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, keepCL in enumerate([True]): polymerParams['keepCL'] = keepCL for j, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} if sigma == 0: expName = "measureMSRG" else: expName = "measureMSRG" mc = Experiment(p0, results, simulationParams, expName) if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def FET_Simulation(polymerParams, simulationParams): # date = strftime("%Y_%m_%d_%H_%M") date = strftime("%Y_%m_%d_%H_%M") filename = date + '__FETSimulationResults' + '.csv' p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") ### SAVE RESULTS with open('results/' + filename, 'w') as csvfile: fieldnames = list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({**mc.results}) ### PLOT RESULTS plotFET(mc) halfCI = 1.96 * np.nanstd(mc.results['FETs']) / np.sqrt( simulationParams['numRealisations']) print('Mean FTE : ' + str(np.nanmean(mc.results['FETs'])) + ' ± ' + str(halfCI)) events = mc.results['eventsCounter'] plot_bar_from_counter(events) plt.show() # filepath = 'results/FET_Distribution_Experiment_'+date+'.pkl' # with open(filepath, 'wb') as output: # pickle.dump(mc, output, pickle.HIGHEST_PROTOCOL) return mc
def FET_Simulation(polymerParams, simulationParams): date = strftime("%Y_%m_%d_%H_%M") p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "Encounter_withExcludedVolume") plotFET(mc) halfCI = 1.96 * np.std(mc.results['FETs']) / np.sqrt( simulationParams['numRealisations']) print('Mean FTE : ' + str(np.mean(mc.results['FETs'])) + ' ± ' + str(halfCI)) events = mc.results['eventsCounter'] plot_bar_from_counter(events) plt.show() filepath = 'results/FET_Distribution_Experiment_' + date + '.pkl' with open(filepath, 'wb') as output: pickle.dump(mc, output, pickle.HIGHEST_PROTOCOL) return mc
def FET_Simulation(encounterDistance, waitingSteps, numRealisations, keepCL): date = strftime("%Y_%m_%d_%H_%M") p0 = RCLPolymer(nb_monomers, dimension, b, numConectors, keepCL) mc = EncounterSimulation(dt, diffusionCte, p0, dt_relax, numRealisations, maxIterationsPerExperiment, 2, genomicDistance, encounterDistance, waitingSteps) mc.run() plotFET(mc) halfCI = 1.96 * np.std(mc.FETs) / np.sqrt(numRealisations) print('Mean FTE : ' + str(np.mean(mc.FETs)) + ' ± ' + str(halfCI)) # events = mc.events plot_bar_from_counter(events) plt.show() filepath = 'results/FET_Distribution__'+'keepCL_'+str(keepCL)+\ str(nb_monomers)+'monomers_'+str(numRealisations)+'iterations'+\ date+'.pkl' with open(filepath, 'wb') as output: pickle.dump(mc, output, pickle.HIGHEST_PROTOCOL)
def proba_vs_genomicDistance(nb_monomers, gmax, gStep, test_epsilons, numRealisations, errorbars=False): # gmax = nb_monomers - 3 gmin = 2 probas = [] demiCI = [] plt.figure() plt.xlabel('genomic distance (in number of monomers)') plt.ylabel(r'$\mathbb{P}$(Repair)') xg = np.arange(gmin, gmax, gStep, dtype=int) date = strftime("%Y_%m_%d_%H_%M") output = np.empty((len(test_epsilons), 3, len(xg))) for i, eps in enumerate(test_epsilons): probas = [] demiCI = [] for g in xg: p0 = RCLPolymer(nb_monomers, dimension, b, numConectors) mc = EncounterSimulation(dt, diffusionCte, p0, dt_relax, numRealisations, maxIterationsPerExperiment, 2, g, eps, waitingSteps) mc.run() probas.append(mc.repairProba[0]) demiCI.append(mc.repairProba[1]) probas = np.array(probas) demiCI = np.array(demiCI) output[i][0] = xg output[i][1] = probas output[i][2] = demiCI if errorbars: plt.errorbar(x=xg, y=probas, yerr=demiCI, fmt='-o', label=r'$\varepsilon = $ ' + str(eps), capsize=4) else: plt.plot(xg, probas, '-o', label=r'$\varepsilon = $ ' + str(eps)) np.save( 'results/proba_vs_genomicDistance__' + str(nb_monomers) + 'monomers_' + str(numRealisations) + 'iterations_' + date + '.npy', output) plt.legend() plt.show()
def proba_vs_conectorsNumber(test_genomic_distances, x_Nc, keepCL, errorbars=False): probas = [] demiCI = [] output = np.zeros((len(test_genomic_distances), 3, len(x_Nc))) date = strftime("%Y_%m_%d_%H_%M") plt.figure() for i, genomicDistance in enumerate(test_genomic_distances): probas = [] demiCI = [] for Nc in x_Nc: results = {} p0 = RCLPolymer(100, 3, 0.2, Nc, keepCL) params['genomicDistance'] = genomicDistance mc = Experiment(p0, results, params, "EncounterSimulation") probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) probas = np.array(probas) demiCI = np.array(demiCI) output[i][0] = x_Nc output[i][1] = probas output[i][2] = demiCI np.save( 'results/proba_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(100) + 'monomers_' + str(numRealisations) + 'iterations' + date + '.npy', output) if errorbars: plt.errorbar(x=x_Nc, y=probas, yerr=demiCI, fmt='-o', label=r'$g = $ ' + str(genomicDistance), capsize=4) else: plt.plot(x_Nc, probas, '-o', label=r'$g = $ ' + str(genomicDistance)) np.save( 'results/proba_vs_conectorsNumber__' + 'keepCL_' + str(keepCL) + str(100) + 'monomers_' + str(numRealisations) + 'iterations' + date + '.npy', output) plt.legend() plt.show()
def proba_v_NlrandSizes(polymerParams, simulationParams, x_Nlr, x_TADsizes): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_Nlr_TADsize' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, nlr in enumerate(x_Nlr): print("Simulation for Nlr = %s " % nlr) polymerParams['Nc'][0, 1] = polymerParams['Nc'][1, 0] = nlr for j, tadsize in enumerate(x_TADsizes): print("Simulation for a parasyte of size %s " % tadsize) polymerParams['numMonomers'][1] = tadsize N = polymerParams['numMonomers'].sum() ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (polymerParams['Nc'].sum()) / ((N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 print("ε = %s" % (simulationParams['encounterDistance'])) p0 = RCLPolymer(**polymerParams) results = { **polymerParams, **simulationParams, **{ 'Nlr': polymerParams['Nc'][0, 1], 'TADsize': polymerParams['numMonomers'][1] } } mc = Experiment(p0, results, simulationParams, "oneTAD_Repair") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def DSBclustering(polymerParams, simulationParams): """ Tracks the breaks positions assuming they are persistent """ date = strftime("%Y_%m_%d_%H_%M") filename = date + '_interbreakdistances' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'large'}) plt.xlabel('Time (sec)') plt.ylabel('Distance between A1 and A2') #(r'$\mathbb{P}$(Repair)') first_time = True for i, VolumeExclusion in enumerate([False]): if VolumeExclusion: labelkeep = 'Excluding volume with a cutoff of ' + str( simulationParams['excludedVolumeCutOff']) + ' μm' else: labelkeep = 'Without excluded volume' simulationParams['excludedVolumeCutOff'] = 0 p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'persistentDSB') if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) plt.title(labelkeep) time = np.arange(simulationParams['numSteps'] + 1) * simulationParams['dt'] from itertools import combinations z = combinations([ chr(97 + i // 2) + str(1 + i % 2) for i in range(2 * len(p0.subDomainnumMonomers)) ], r=2) names = [i for i in z] for i in range(15): distanceA2B1 = mc.results['MeanInterBreakDistance'][:, i] plt.plot(time, distanceA2B1, '-', label='d(%s, %s)' % names[i]) plt.legend() plt.show()
def proba_v_sigma(polymerParams, simulationParams, x_sigma, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_sigma' + '.csv' # plt.figure() # rcParams.update({'axes.labelsize' : 'xx-large'}) # rcParams.update({'legend.fontsize': 'xx-large'}) # rcParams.update({'xtick.labelsize': 'xx-large'}) # rcParams.update({'ytick.labelsize': 'xx-large'}) # plt.xlabel('Number of connectors in DF') # plt.ylabel('Mean FET (sec)') #('Mean first encounter time (sec)') # first_time = True with open('results/' + filename, 'w') as csvfile: for i, keepCL in enumerate([True]): # if keepCL: # labelkeep = "Keeping CLs in DF" # # else: # labelkeep = 'Removing CLs in DF' polymerParams['keepCL'] = keepCL # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) # p = np.zeros(len(x_sigma)) # dp = np.zeros(len(x_sigma)) for j, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} if sigma == 0: expName = "EncounterSimulation" else: expName = "Encounter_withRepairSphere" mc = Experiment(p0, results, simulationParams, expName) # p[j] = mc.results['repair_probability'] # dp[j] = mc.results['repair_CIhalflength'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def proba_vs_genomicDistance_andVE(polymerParams, simulationParams, x_sigma, gmax, gStep, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_VE_proba_vs_genomicDistance_' + '.csv' with open('results/' + filename, 'w') as csvfile: gmin = 2 # plt.figure() # rcParams.update({'axes.labelsize': 'xx-large'}) # plt.xlabel('genomic distance (in number of monomers)') # plt.ylabel(r'$\mathbb{P}$(Repair)') xg = np.arange(gmin, gmax, gStep, dtype=int) for i, sigma in enumerate(x_sigma): if sigma == 0: labelkeep = 'Without excluded volume' experimentName = "EncounterSimulation" simulationParams['excludedVolumeCutOff'] = 0 else: labelkeep = r"Excluding volume ($\sigma = %s $)" % sigma experimentName = "Encounter_withRepairSphere" simulationParams['excludedVolumeCutOff'] = sigma probas = np.zeros(len(xg)) demiCI = np.zeros(len(xg)) for j, g in enumerate(xg): print("Simulation for g =", g, "and ", labelkeep) p0 = RCLPolymer(**polymerParams) simulationParams['genomicDistance'] = g results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, experimentName) # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] if i == 0 and g == gmin: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def stats_vs_Nb(polymerParams, simulationParams, x_Nb, x_g): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_StatsVsNb' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nb in enumerate(x_Nb): print("Simulation for Nb = %s breaks " % Nb) simulationParams['Nb'] = Nb for j, g in enumerate(x_g): simulationParams['genomicDistance'] = g print("and g = %s . " % g) p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + "_" + str(j) }, **mc.results })
def proba_v_interDomainDistance(polymerParams, simulationParams, TAD_size, test_distances, errorbars): """ Probability vs interDomainDistance """ plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) plt.xlabel('genomic distance between TADs') plt.ylabel(r'$\mathbb{P}$(Repair)') xg = test_distances date = strftime("%Y_%m_%d_%H_%M") output = np.empty((3, len(xg))) probas = [] demiCI = [] for g in xg: print("Simulation for 2 TADs of size %s, at a distance % s" % (TAD_size, g)) tad1_right = 50 - np.ceil(g / 2).astype(int) tad2_left = 50 + np.floor(g / 2).astype(int) polymerParams['TADs'] = [(tad1_right - TAD_size, tad1_right), (tad2_left, tad2_left + TAD_size)] p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "TAD_Repair") probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) probas = np.array(probas) demiCI = np.array(demiCI) output[0] = xg output[1] = probas output[2] = demiCI if errorbars: plt.errorbar(x=xg, y=probas, yerr=demiCI, fmt='-o', capsize=4) else: plt.plot(xg, probas, '-o') np.save('results/proba_vs_interTADdistance__' + date + '.npy', output) plt.legend() plt.show() return mc
def measureProba(g): probas = np.zeros(len(x_Nc)) halfCI = np.zeros(len(x_Nc)) params['genomicDistance'] = g for i, Nc in enumerate(x_Nc): results = {} np.random.seed() p0 = RCLPolymer(100, 3, 0.2, Nc, False) mc = Experiment(p0, results, params, "EncounterSimulation") probas[i] = mc.results['repair_probability'] halfCI[i] = mc.results['repair_CIhalflength'] return (probas, halfCI)
def trackAlpha_v_gNc(polymerParams, simulationParams, x_g, x_Nc): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackMSD' + '.csv' first_time = True N = polymerParams['numMonomers'] with open('results/' + filename, 'w') as csvfile: for i, g in enumerate(x_g): print("Simulation for g = %s " % g) simulationParams['genomicDistance'] = g for j, nc in enumerate(x_Nc): print("Simulation for Nc = %s " % nc) polymerParams['Nc'] = nc p0 = RCLPolymer(**polymerParams) simulationParams['waitingSteps'] = np.ceil( p0.relaxTime(simulationParams['diffusionConstant']) / simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackMSD") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def makeExperiment(numrealisations): p0 = RCLPolymer(100, 3, 0.2, 3) params = dict( dt_relax=0.5, diffusionConstant=0.008, # numSteps = 100, dt=0.1, genomicDistance=2, Nb=2, waitingSteps=200, numMaxSteps=600, encounterDistance=0.1) results = {} params['numRealisations'] = numrealisations np.random.seed() return Experiment(p0, results, params, "EncounterSimulation")
def proba_vs_ExclusioncutoffRadius(polymerParams, simulationParams, test_cutoffs, errorbars=False): Allresults = [] probas = [] demiCI = [] date = strftime("%Y_%m_%d_%H_%M") plt.figure() plt.xlabel('Cutoff radius (micron)') plt.ylabel(r'$\mathbb{P}$(Correct repair)') for threshold in test_cutoffs: print('Simulation for a cutoff of', threshold) p0 = RCLPolymer(**polymerParams) simulationParams['excludedVolumeCutOff'] = threshold results = {} mc = Experiment(p0, results, simulationParams, "Encounter_withExcludedVolume") Allresults.append(mc.results) probas.append(mc.results['repair_probability_CI'][0]) demiCI.append(mc.results['repair_probability_CI'][1]) if errorbars: plt.errorbar(x=test_cutoffs, y=probas, yerr=demiCI, fmt='-o', capsize=4) else: plt.plot(test_cutoffs, probas, '-o') filepath = 'results/Proba_vs_cutoffs__' + date + '.pkl' saveasPickle(filepath, Allresults) # plt.legend() plt.show()
def DSBclustering(polymerParams, simulationParams): """This experiment""" date = strftime("%Y_%m_%d_%H_%M") filename = date + '_interbreakdistances' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'large'}) plt.xlabel('Time (sec)') plt.ylabel('Distance between A1 and A2') #(r'$\mathbb{P}$(Repair)') first_time = True for i, VolumeExclusion in enumerate([True, False]): if VolumeExclusion: labelkeep = 'Excluding volume with a cutoff of ' + str( simulationParams['excludedVolumeCutOff']) + ' μm' else: labelkeep = 'Without excluded volume' simulationParams['excludedVolumeCutOff'] = 0 p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, 'persistentDSB') if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({**{'experimentSetID': str(i)}, **mc.results}) distanceA2B1 = mc.results['MeanInterBreakDistance'][:, 0] time = np.arange(simulationParams['numSteps'] + 1) * simulationParams['dt'] plt.plot(time, distanceA2B1, '-', label=labelkeep) plt.legend() plt.show()
def proba_vs_DSBNumber(numRealisations=500, nb_monomers=50, genomicDistance=4): probas = [] demiCI = [] NbMax = 1 + int((nb_monomers - 1) / (genomicDistance + 1)) for Nb in range(1, NbMax): p0 = RCLPolymer(nb_monomers, dimension, b, numConectors) mc = EncounterSimulation(dt, diffusionCte, p0, dt_relax, numRealisations, maxIterationsPerExperiment, Nb, genomicDistance, encounterDistance, waitingSteps) mc.run() probas.append(mc.repairProba[0]) demiCI.append(mc.repairProba[1]) probas = np.array(probas) plt.figure() plt.plot(np.arange(1, NbMax), probas) plt.plot(np.arange(1, NbMax), probas - demiCI, 'r--', lw=0.4) plt.plot(np.arange(1, NbMax), probas + demiCI, 'r--', lw=0.4) plt.show()
def trackDistanceDistribution(polymerParams, simulationParams, x_Nc, x_g): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_trackDSB' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, Nc in enumerate(x_Nc): print("Simulation for Nc = %s CLs " % Nc) polymerParams['Nc'] = Nc for j, g in enumerate(x_g): simulationParams['genomicDistance'] = g print("and g = %s . " % g) p0 = RCLPolymer(**polymerParams) # simulationParams['waitingSteps'] = np.ceil(p0.relaxTime(simulationParams['diffusionConstant'])/simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + "_" + str(j) }, **mc.results })
def proba_v_VEkappa(polymerParams, simulationParams, x_sigma, x_kappa, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + '_proba-v_kappa' + '.csv' first_time = True with open('results/' + filename, 'w') as csvfile: for i, sigma in enumerate(x_sigma): print("Simulation for σ = %s " % sigma) simulationParams['excludedVolumeCutOff'] = sigma for j, kappa in enumerate(x_kappa): print("Simulation for κ = %s " % kappa) simulationParams['excludedVolumeSpringConstant'] = kappa p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "Encounter_withRepairSphere") if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results })
def watchOneSimulation(polymerParams, simulationParams): p0 = RCLPolymer(**polymerParams) results = {} mc = Experiment(p0, results, simulationParams, "watchEncounter") print(mc.results['FET']) return mc
if __name__ == "__main__": ## trackDistanceDistribution(polymerParams, simulationParams, x_Nc, x_g) # # x_Nc = np.arange(5,90,5) # x_g = [5,40] # trackDistanceDistribution(polymerParams, simulationParams, x_Nc, x_g) # x_Nc = np.arange(20,60,5) simulationParams['A1'] = 30 simulationParams['B1'] = 59 # trackDefinedDSBtrajectory(polymerParams, simulationParams, x_Nc) # p0 = RCLPolymer(**polymerParams) # simulationParams['waitingSteps'] = np.ceil(p0.relaxTime(simulationParams['diffusionConstant'])/simulationParams['dt_relax']).astype(int) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "trackDSB") above = mc.results['aboveTimes'] below = mc.results['belowTimes'] plt.figure() plt.hist(below['a1-a2']) aboveTimes = { 'a1-a2':
from modules.Polymers import RCLPolymer nb_monomers = 50 numRealisations = 200 numConectors = 0 #number of added connectors numSteps = 100 dt = 0.005 dt_relax = 0.05 dimension = 3 diffusionCte = 0.008 b = 0.2 p0 = RCLPolymer(nb_monomers, dimension, b, numConectors) mc = Simulation(numSteps, dt, diffusionCte, p0, dt_relax, numRealisations) mc.run() msd = mc.get_msd_per_monomer() mmsd = mc.get_avg_msd() msrg = mc.get_msrg() b2e = mc.get_b2e() # Function to fit to the MSD f = lambda t, A, alpha: A * t**alpha # Fitted parameters fit_params = mc.MSD_fit_mean()
excludedVolumeCutOff = 5 * 0.2 ############################################################################ ############################################################################ ############################################################################ # TESTS #################################################################### ############################################################################ if __name__ == '__main__': ### SIMPLE SIMULATIONS WITH EXCLUDED VOLUME # Polymer parameters p0 = RCLPolymer(**polymerParams) # Add excluded volume # First define the potential gradient # It should depend on the polymer only !! kappa = 3 * 0.008 / (p0.b**2) # Loci dependant kappa breakPoints = [5, 6, 10, 11, 70, 71] # amplitude = np.ones(p0.numMonomers)/10. # amplitude[breakPoints] = 1. # kappa = kappa * amplitude # repulsionForce = lambda polymer : (ExcludedVolume(polymer, excludedVolumeCutOff, method='spring-like').T * -kappa).T repulsionForce = lambda polymer: -kappa * LocalExcludedVolume(
def proba_vs_keepDFCL(polymerParams, simulationParams, x_Nc, errorbars=False): date = strftime("%Y_%m_%d_%H_%M") filename = date + 'proba_VE_vs_Nc_NcinDF_adptEPSILONandSIGMA' + '.csv' with open('results/' + filename, 'w') as csvfile: plt.figure() rcParams.update({'axes.labelsize': 'xx-large'}) rcParams.update({'legend.fontsize': 'xx-large'}) rcParams.update({'xtick.labelsize': 'large'}) plt.xlabel('Number of connectors in DF') plt.ylabel( r'$\mathbb{P}$(Repair)') #('Mean first encounter time (sec)') # first_time = True N = polymerParams['numMonomers'] for i, keepCL in enumerate([True, False]): if keepCL: labelkeep = "Keeping CLs in DF" else: labelkeep = 'Removing CLs in DF' polymerParams['keepCL'] = keepCL # mfet = np.zeros(len(x_Nc)) # efet = np.zeros(len(x_Nc)) probas = np.zeros(len(x_Nc)) demiCI = np.zeros(len(x_Nc)) for j, Nc in enumerate(x_Nc): print("Simulation for %s CL in DF" % Nc) simulationParams['Nc_inDamageFoci'] = Nc ### ADAPTIVE ENCOUNTER DISTANCE xi = 2 * (polymerParams['Nc'] + Nc) / ((N - 1) * (N - 2)) # scaleFactor = np.sqrt( (1-xi0)*np.sqrt(xi0) / ((1-xi)*np.s1qrt(xi)) ) simulationParams['encounterDistance'] = adaptiveEpsilon( xi, N, polymerParams['b']) # ### ADAPTIVE CUTOFF RADIUS # simulationParams['excludedVolume'] = 2 * adaptiveEpsilon(xi, N, polymerParams['b']) # ### ADAPTIVE dt simulationParams['dt'] = np.round( (0.2 * simulationParams['encounterDistance'])**2 / (2 * simulationParams['diffusionConstant']), decimals=4) - 0.0001 print("ε = %s and σ = %s" % (simulationParams['encounterDistance'], simulationParams['excludedVolumeCutOff'])) p0 = RCLPolymer(**polymerParams) results = {**polymerParams, **simulationParams} mc = Experiment(p0, results, simulationParams, "EncounterSimulation") # oneTAD_Repair probas[j] = mc.results['repair_probability'] demiCI[j] = mc.results['repair_CIhalflength'] # mfet[j] = mc.results['meanFET'] # efet[j] = mc.results['halfCI_FET'] if first_time: fieldnames = ['experimentSetID'] + list(mc.results) writer = csv.DictWriter(csvfile, fieldnames=fieldnames) writer.writeheader() first_time = False writer.writerow({ **{ 'experimentSetID': str(i) + '_' + str(j) }, **mc.results }) if errorbars: plt.errorbar(x=x_Nc, y=probas, yerr=demiCI, fmt='-o', label=labelkeep, capsize=4) else: plt.plot(x_Nc, probas, '-o', label=labelkeep) plt.legend() plt.show()