def genAndPrint(numOfPaths, toggle): simulation_temperature = 50.0 print "Building the statespace from traces for reaction: " + toggle + " at T = %.1f C " % simulation_temperature myBuilder = Builder(doReaction, [numOfPaths, test8mer, simulation_temperature, toggle]) myBuilder.genAndSavePathsFile() myBuilder.genAndSavePathsFile() print myBuilder builderRate = BuilderRate(myBuilder) if not (toggle == str_dissociation or toggle == str_threeway_strand_displacement): time = builderRate.averageTimeFromInitial(bimolecular=False) print "\nRate = %.2f /s \n" % (1.0 / time) else: time = builderRate.averageTimeFromInitial(bimolecular=True) print "\nRate = %.2f /M/s \n" % (1.0 / time) """ Fields you could look at: """ if False: print builderRate.stateIndex print builderRate.rate_matrix_csr.toarray() print "Initial States" print builderRate.initial_states print "Final States" print builderRate.final_states print str(builderRate) times = builderRate.averageTime() print str(times)
def statespace_threewaybm(form_f): strand_seq = form_f['sequence'] ltoehold = form_f['ltoehold'] rtoehold = form_f['rtoehold'] ''' do not set the initial state -- allow builder to do this ''' def getOptions(arguments): o = standardOptions() o.simulation_mode = Literals.trajectory o.num_simulations = B_MULT * form_f["trajectories"] o.sodium = form_f['sodium'] o.magnesium = form_f['magnesium'] o.temperature = float(form_f['temperature']) o.simulation_time = BUILDER_TIMEOUT o.join_concentration = BUILDER_CONC if "RNA" == form_f['substrate']: o.substrate_type = Literals.substrateRNA endComplex = arguments[0] stopSuccess = StopCondition(Literals.success, [(endComplex, Literals.exact_macrostate, 0)]) o.stop_conditions = [stopSuccess] return o startStates = threewaybmString(ltoehold, strand_seq, rtoehold) endState = startStates[-1] Builder.verbosity = True myBuilder = Builder(getOptions, [endState[0]]) ''' setting the precision to just 2 states will ensure the builder stops after a single iteration. ''' startTime = time.time() myBuilder.genAndSavePathsFromString(startStates[:(len(startStates) - 1)]) # myBuilder.fattenStateSpace() buildTime = time.time() - startTime bRate = BuilderRate(myBuilder) return bRate , buildTime
def main(): b = Builder(test0, []) b.genAndSavePathsFile(inspecting=True) print b b = Builder(test1, []) b.genAndSavePathsFile(inspecting=True) print b
def timings(settings): output = ResultsHybridization() for i in range(NUM_OF_REPEATS): startTime = time.time() myBuilder = Builder(settings.function, settings.arguments) if DO_CONVERGENCE: myBuilder.genUntilConvergence(CONVERGENCE_CRIT) else: myBuilder.genAndSavePathsFile() builderRate = BuilderRate(myBuilder) output.buildTime.append(time.time() - startTime) startTime = time.time() output.rates.append( np.log10(1.0 / builderRate.averageTimeFromInitial(bimolecular=True))) output.matrixTime.append(time.time() - startTime) output.nStates.append(builderRate.n_states) output.nTransitions.append(builderRate.n_transitions) return output """Produce the required plots here"""
def genAndPrint(numOfPaths, toggle): global sumTime print "Building the statespace from traces for reaction: " + toggle startStates = getString([toggle, test15mer]) endState = startStates[-1] myBuilder = Builder(getOptions, [endState[0]]) ''' setting the precision to just 2 states will ensure the builder stops after a single iteration. ''' startTime = time.time() # Builder.verbosity = False myBuilder.genAndSavePathsFromString(startStates[:(len(startStates) - 1)]) # Builder.verbosity = True myBuilder.fattenStateSpace() buildTime = time.time() - startTime print "Build time was %.2f s" % buildTime sumTime += buildTime print myBuilder builderRate = BuilderRate(myBuilder) if not (toggle == str_dissociation or toggle == str_threeway_strand_displacement): compTime = builderRate.averageTimeFromInitial(bimolecular=False) print "\nRate = %.2f /s \n" % (1.0 / compTime) else: compTime = builderRate.averageTimeFromInitial(bimolecular=True) print "\nRate = %.2f /M/s \n" % (1.0 / compTime) """ Fields you could look at: """ if False: print builderRate.stateIndex print builderRate.rate_matrix_csr.toarray() print "Initial States" print builderRate.initial_states print "Final States" print builderRate.final_states print str(builderRate) times = builderRate.averageTime() print str(times)
def timings(seq, nTrials, deltaPruning=None): output = ResultsHybridization() def association_comparison(seq, endComplex): return Settings(associationNoInit, [nTrials, suyamaT, suyamaC, endComplex], enum_hybridization, title_hybridization) if EXP_TOGGLE == 1: startStates = hybridizationString(seq) if EXP_TOGGLE == 2: startStates = threewaybmString("A", seq, "ACTAGG") if EXP_TOGGLE == 3: startStates = dissociationString(seq) endState = startStates[-1] sett = association_comparison(seq, endState[0]) for i in range(NUM_OF_REPEATS): startTime = time.time() BuilderRate.solveToggle = 0 myBuilder = Builder(sett.function, sett.arguments) Builder.verbosity = True myBuilder.genAndSavePathsFromString(startStates[:(len(startStates) - 1)]) print myBuilder myBuilder.fattenStateSpace() print myBuilder # myBuilder.genUntilConvergenceWithInitialState(10000, startStates[:(len(startStates) - 1)], printMeanTime=True) if not deltaPruning == None: print "Going to delta prune with %.2E" % deltaPruning myBuilder.deltaPruning(deltaPruning, printCount=True) maxRange = 1 if TEST_RATE_LIMIT: maxRange = 5 for i in range(maxRange): builderRate = BuilderRate(myBuilder) builderRate.rateLimit = builderRate.rateLimit * (10**i) if i == (maxRange - 1): builderRate.rateLimit = 0.0 print "rateLimit = " + str(builderRate.rateLimit) builderRate.setMatrix() output.buildTime.append(time.time() - startTime) startTime = time.time() biCheck = (EXP_TOGGLE == 1 or EXP_TOGGLE == 2) output.rates.append( np.log10( 1.0 / builderRate.averageTimeFromInitial(bimolecular=biCheck))) pruned_mfpt = builderRate.averageTimeFromInitial(bimolecular=False) print "Rate = %.2E, MFPT = %.2E, compute_time = %.2f \n\n " % ( output.rates[-1], pruned_mfpt, output.buildTime[-1]) output.matrixTime.append(time.time() - startTime) output.nStates.append(len(builderRate.statespace)) return output
def call_Builder(self, num_simulations): myBuilder = Builder(doReaction, [ num_simulations, self.simulation_time, self.reaction_type, self.dataset_type, self.strands_list, self.sodium, self.magnesium, self.kinetic_parameters_simulation, self.bimolecular_reaction, self.temperature, self.temperature_change, self.join_concentration_change, self.join_concentration, rate_method, self.use_initialfinalfrompathway, self.startStates ]) start_time = timeit.default_timer() if self.num_simulations > 0: myBuilder.genAndSavePathsFile( supplyInitialState=self.startStates[0]) builderpath = self.dataset_path + "/" + myenums.Permanent_Folder.MYBUILDER.value + "/" + myenums.Permanent_Folder.MYBUILDER.value + str( self.docID) lenp = len(myBuilder.protoSpace) start = 0 myBuilder.protoSpacebackup = copy.deepcopy(myBuilder.protoSpace) pathuniqueid = builderpath + myenums.EDITIONAL.UNIQUEID.value with open(pathuniqueid, "wb") as p: pickle.dump(myBuilder.uniqueID_number, p) pathspace = builderpath + myenums.EDITIONAL.PROTOSPACEBACKUP.value with open(pathspace, "wb") as p: pickle.dump(myBuilder.protoSpacebackup, p) pathsequences = builderpath + myenums.EDITIONAL.PROTOSEQUENCES.value with open(pathsequences, "wb") as p: pickle.dump(myBuilder.protoSequences, p) pathoptions = builderpath + myenums.EDITIONAL.PATHOPTIONS.value with open(pathoptions, "wb") as p: pickle.dump(myBuilder.optionsArgs, p) batchsize = 2000 while start < lenp: st = timeit.default_timer() end = min(lenp, start + batchsize) print "progress ", str(end), " / ", str(lenp), self.docID # There was some memory leak issues when I used the fattenStateSpace function in builder.py, so I added fatten helper to avoid the memory issues by saving intermediate results, restarting Multistrand, and restoring the intermediate results command = [ "python", "fattenhelper.py", str(start), str(end), builderpath, pathspace, pathsequences, pathoptions, pathuniqueid ] shell = call(command) ft = timeit.default_timer() #print "making fatten state space time" , ft-st del shell with open( builderpath + myenums.EDITIONAL.TEMPSTATESPACE.value + str(start) + "-" + str(end), "rb") as p: tempstatespace = pickle.load(p) with open( builderpath + myenums.EDITIONAL.TEMPTRANSITIONS.value + str(start) + "-" + str(end), "rb") as p: temptransitions = pickle.load(p) os.remove(builderpath + myenums.EDITIONAL.TEMPSTATESPACE.value + str(start) + "-" + str(end)) os.remove(builderpath + myenums.EDITIONAL.TEMPTRANSITIONS.value + str(start) + "-" + str(end)) myBuilder.mergeSet(myBuilder.protoSpace, tempstatespace) myBuilder.mergeSet(myBuilder.protoTransitions_FPEI, temptransitions) start = end with open(pathuniqueid, "rb") as p: myBuilder.uniqueID_number = pickle.load(p) os.remove(pathuniqueid) os.remove(pathspace) os.remove(pathsequences) os.remove(pathoptions) del myBuilder.protoSpacebackup del myBuilder.uniqueID_number print "Statistics: ", "statespace: ", len( myBuilder.protoSpace), "finalstates: ", len( myBuilder.protoFinalStates), "initialstates: ", len( myBuilder.protoInitialStates) return myBuilder
start = sys.argv[1] end = sys.argv[2] pathbuilder = sys.argv[3] pathspace = sys.argv[4] pathsequences = sys.argv[5] pathoptions = sys.argv[6] pathuniqueid = sys.argv[7] mytime = open("times_log_remove.txt", "a") mytime.write(pathbuilder + " start " + str(start) + "end " + str(end) + "\n") st = time.time() with open(pathoptions, "rb") as p: optionsArg = pickle.load(p) myBuilder = Builder(parent.doReaction, optionsArg) with open(pathspace, "rb") as p: myBuilder.protoSpacebackup = pickle.load(p) with open(pathuniqueid, "rb") as p: myBuilder.uniqueID_number = pickle.load(p) with open(pathsequences, "rb") as p: myBuilder.protoSequences = pickle.load(p) mytime.write("load time " + str(time.time() - st) + "\n") st = time.time() myBuilder.fattenStateSpace(start=int(start), end=int(end))