def main2(): o1 = create_setup_interal(toehold_t, toehold_dd, domain_R, 25) s = SimSystem(o1) s.initialInfo() print "Testing loop internals"
def genAndSavePathsFromString(self, pathway, printMeanTime=False): startTime = time.time() """ Load up the energy model with a near zero-length simulation """ myOptions = self.optionsFunction(copy.deepcopy(self.optionsArgs)) myOptions.simulation_mode = Literals.trajectory myOptions.activestatespace = False myOptions.simulation_time = 0.0000000001 myOptions.start_state = pathway[0] # s = SimSystem(myOptions) s.start() """ Only the first state will count towards the set of initial states """ ignoreInitial = False for state in pathway: otherBuilder = Builder(self.optionsFunction, self.optionsArgs) otherBuilder.genAndSavePathsFile(supplyInitialState=state, ignoreInitialState=ignoreInitial) ignoreInitial = True self.mergeBuilder(otherBuilder) del otherBuilder if self.verbosity or printMeanTime: print("Size = %i --- bytesize = %i " % (len(self.protoSpace), sys.getsizeof(self.protoSpace))) print("Size T = %i --- bytesize = %i " % (len( self.protoTransitions), sys.getsizeof(self.protoTransitions))) print("Time = %f" % (time.time() - startTime))
def main(): # o1 = create_test0() # just a fully hybridized strand. # o1 = create_test0B() # just a fully hybridized strand. # o1 = create_test0C() # just a fully hybridized strand. # o1 = create_test1() # testing open-loop # o1 = create_test1B() # testing open-loop with the initialiation penalty # o1 = create_test2() # a very simple test # o1 = create_test3() # this is the bi-molecular test # o1 = create_test4() # this is the lightbulb # o1 = create_test5() # testing multi-loop code # o1 = create_test6() # interior loop. # o1 = create_test6B() # small interior loop. # o1 = create_test7() # Bulge loop. # o1 = create_test8() # Hairpin loop. # o1 = create_test9() # Small open-loop code # o1 = create_test10() # half open duplex o1 = create_test11() # Oscillator gate # setArrheniusConstantsNM1(o1) s = SimSystem(o1) # s.start() s.initialInfo()
def doSim(myFactory, aFactory, list0, list1, instanceSeed, nForwardIn, nReverseIn): myOptions = myFactory.new(instanceSeed) myOptions.num_simulations = self.trialsPerThread s = SimSystem(myOptions) s.start() myFSR = self.settings.rateFactory(myOptions.interface.results) nForwardIn.value += myFSR.nForward + myFSR.nForwardAlt nReverseIn.value += myFSR.nReverse for result in myOptions.interface.results: list0.append(result) for endState in myOptions.interface.end_states: list1.append(endState) if self.settings.debug: self.printTrajectories(myOptions) if not (aFactory == None): aFactory.doAnalysis(myOptions)
def doSims(strandSeq, numTraj=2): curr = time.time() o1 = standardOptions(tempIn=36.95) o1.num_simulations = numTraj o1.output_time = 0.0004 # output every .4 ms o1.simulation_time = 0.35 # unit: second o1.gt_enable = 1 o1.substrate_type = Literals.substrateRNA o1.simulation_mode = Literals.trajectory o1.cotranscriptional = True # enables the strand growing on the 3' end. onedomain = Domain(name="mydomain", sequence=strandSeq) top = Strand(name="top", domains=[onedomain]) startTop = Complex(strands=[top], structure=".") o1.start_state = [startTop] o1.DNA23Arrhenius() # o1.initial_seed = 1777+6 s = SimSystem(o1) s.start() printTrajectory(o1) print "Exe time is " + str(time.time() - curr)
def timings(seq, nTrials): output = ResultsHybridization() def association_comparison(seq): return Settings(doReactionAssociation, [nTrials, suyamaT, suyamaC, seq], enum_hybridization, title_hybridization) sett = association_comparison(seq) for i in range(NUM_OF_REPEATS): startTime = time.time() o1 = sett.function(sett.arguments) ssystem = SimSystem(o1) ssystem.start() myRates = FirstPassageRate(o1.interface.results) k1 = myRates.kEff(o1.join_concentration) output.buildTime.append(time.time() - startTime) output.rates.append(np.log10(k1)) output.nStates.append(100) output.matrixTime.append(10.0) return output
def doSims(numTraj=2): o1 = standardOptions() o1.simulation_mode = Options.firstStep o1.num_simulations = numTraj o1.output_interval = 1 o1.simulation_time = ATIME_OUT myComplex1 = makeComplex(["GTCACTGCTTTT"], "............") myComplex2 = makeComplex(["GTCACTGC", "GCAGTGAC"], ".(((((((+))))))).") o1.start_state = [myComplex1, myComplex2] # myComplex = makeComplex(["GTCACTGCTTTT","GTCACTGC","GCAGTGAC"], "..(.........+).((((((+))))))..") # o1.start_state = [myComplex] # no stop conditions, just timeout. o1.initial_seed = time.time() * 1000000 # o1. initial_seed = 1501710503137097 s = SimSystem(o1) s.start() printTrajectory(o1)
def main(): # o1 = create_test0() # just a fully hybridized strand. # o1 = create_test0B() # just a fully hybridized strand. # o1 = create_test0C() # just a fully hybridized strand. # o1 = create_test1() # testing open-loop # o1 = create_test1B() # testing open-loop with the initialiation penalty # o1 = create_test2() # a very simple test being .(.+.). o1 = create_test2B() # a very simple test being .(.+.). # o1.bimolecular_scaling = 777.0 o1.DNA23Metropolis() # o1 = create_test3() # this is the bi-molecular test # o1 = create_test4() # this is the lightbulb # o1 = create_test5() # testing multi-loop code # o1 = create_test6() # interior loop. # o1 = create_test6B() # small interior loop. # o1 = create_test7() # Bulge loop. # o1 = create_test8() # Hairpin loop. # o1 = create_test9() # Small open-loop code # o1 = create_test10() # half open duplex # o1 = create_test11() # Oscillator gate # o1 = create_test12() # displacement situation. # o1 = create_test13() # this is a test for dissociation # setArrheniusConstantsNM1(o1) # o1.DNA23Metropolis() s = SimSystem(o1) # s.start() s.initialInfo()
def test_run_system(self): """ Test [System]: Create a system object and then run the system This test creates a SimulationSystem and then runs it, printing the options object after completion.""" system = SimSystem(self.options) system.start() MI_System_Object_TestCase.str_run_system = str(self.options.interface)
def test_create_system_repeated(self): """ Test [System]: Create three distinct system objects Note that this uses the /same/ options object for each, which is theoretically a really bad idea - an options object should be tied to a system in future versions.""" system1 = SimSystem(self.options) system2 = SimSystem(self.options) system3 = SimSystem(self.options)
def doSims(strandSeq, numTraj=2): o1 = standardOptions() o1.simulation_mode = Options.trajectory o1.num_simulations = numTraj o1.output_interval = 1 o1.simulation_time = ATIME_OUT SHORT_SEQ1 = "ACCTCT" SHORT_SEQ2 = "TCTTTA" SHORT_SEQ7 = "ACATCC" SHORT_SEQ5 = "TACTAC" SHORT_SEQ6 = "ACCATT" SHORT_SEQT = "CTCT" LONG_SEQ2 = "CCAAACAAAACCTAT" LONG_SEQ5 = "AACCACCAAACTTAT" LONG_SEQ6 = "CCTAACACAATCACT" # some ive made up, but these shouldn't make much difference LONG_SEQ7 = "CCACAAAACAAAACT" LONG_SEQ1 = "CATCCATTCAACTAT" LONG_SEQT = SHORT_SEQT CL_LONG_S18 = "TCTTCTAACAT" CL_LONG_S5 = "CCACCAAACTT" CL_LONG_S6 = "TAACACAATCA" CL_LONG_S29 = "CCAATACTCCT" CL_LONG_S53 = "TATCTAATCTC" CL_LONG_S44 = "AAACTCTCTCT" CL_LONG_SEQT = "TCT" CLAMP_SEQ = "CA" SHORT_GATE_A_SEQ = [SHORT_SEQ1, SHORT_SEQ2, SHORT_SEQ5, SHORT_SEQ7, SHORT_SEQT] SHORT_GATE_B_SEQ = [SHORT_SEQ2, SHORT_SEQ5, SHORT_SEQ6, SHORT_SEQ7, SHORT_SEQT] LONG_GATE_A_SEQ = [LONG_SEQ1, LONG_SEQ2, LONG_SEQ5, LONG_SEQ7, LONG_SEQT] LONG_GATE_B_SEQ = [LONG_SEQ2, LONG_SEQ5, LONG_SEQ6, LONG_SEQ7, LONG_SEQT] CL_LONG_GATE_A_SEQ = [CL_LONG_S44, CL_LONG_S18, CL_LONG_S5, CL_LONG_S29, CL_LONG_SEQT, CLAMP_SEQ] CL_LONG_GATE_B_SEQ = [CL_LONG_S53, CL_LONG_S5, CL_LONG_S6, CL_LONG_S29, CL_LONG_SEQT, CLAMP_SEQ] clamped_gate_output_leak(o1, CL_LONG_GATE_A_SEQ, 10) o1.initial_seed = 1777 s = SimSystem(o1) s.start() printTrajectory(o1)
def first_step_simulation(strand_seq, trials, T=25, material="DNA"): print "Running %d first step mode simulations for %s (with Boltzmann sampling)..." % (trials, strand_seq) # Using domain representation makes it easier to write secondary structures. onedomain = Domain(name="itall",sequence=strand_seq) top = Strand(name="top",domains=[onedomain]) bot = top.C # Note that the structure is specified to be single stranded, but this will be over-ridden when Boltzmann sampling is turned on. start_complex_top = Complex(strands=[top],structure=".") start_complex_bot = Complex(strands=[bot],structure=".") start_complex_top.boltzmann_count = trials start_complex_bot.boltzmann_count = trials start_complex_top.boltzmann_sample = True start_complex_bot.boltzmann_sample = True # Turns Boltzmann sampling on for this complex and also does sampling more efficiently by sampling 'trials' states. # Stop when the exact full duplex is achieved. (No breathing!) success_complex = Complex(strands=[top, bot],structure="(+)") success_stop_condition = StopCondition("SUCCESS",[(success_complex,Exact_Macrostate,0)]) # Declare the simulation unproductive if the strands become single-stranded again. failed_complex = Complex(strands = [top], structure=".") failed_stop_condition = StopCondition("FAILURE",[(failed_complex,Dissoc_Macrostate,0)]) o = Options(simulation_mode="First Step",parameter_type="Nupack", substrate_type=material, rate_method = "Metropolis", num_simulations = trials, simulation_time=1.0, dangles = "Some", temperature = T, rate_scaling = "Calibrated", verbosity = 0) o.start_state = [start_complex_top, start_complex_bot] o.stop_conditions = [success_stop_condition,failed_stop_condition] # Now go ahead and run the simulations. initialize_energy_model(o) # concentration changes, so we must make sure energies are right s = SimSystem(o) s.start() dataset = o.interface.results # Now determine the reaction model parameters from the simulation results. (Simplified from hybridization_first_step_mode.py.) collision_rates = np.array( [i.collision_rate for i in dataset] ) was_success = np.array([1 if i.tag=="SUCCESS" else 0 for i in dataset]) was_failure = np.array([0 if i.tag=="SUCCESS" else 1 for i in dataset]) forward_times = np.array( [i.time for i in dataset if i.tag == "SUCCESS"] ) reverse_times = np.array( [i.time for i in dataset if i.tag == "FAILURE" or i.tag == None] ) # Calculate first-order rate constants for the duration of the reactions (both productive and unproductive). k2 = 1.0/np.mean(forward_times) k2prime = 1.0/np.mean(reverse_times) # Calculate second-order rate constants for productive and unproductive reactions. k1 = np.mean( collision_rates * was_success ) k1prime = np.mean( collision_rates * was_failure ) return k1, k2, k1prime, k2prime
def actual_simulation(toehold_length, num_traj, rate_method_k_or_m, index): print "Starting %d simulations for toehold length %d and %s kinetics." % (num_traj, toehold_length, rate_method_k_or_m) o = create_setup(toehold_length, num_traj, rate_method_k_or_m) s = SimSystem(o) s.start() prefix = "Data_toehold_{0}".format(toehold_length) filename = "DATA_{0}_{1}_{2:04}.dat".format(rate_method_k_or_m, toehold_length, index) full_filename = os.path.join(prefix, filename) f = open(full_filename, 'wb') cPickle.dump(o.interface.results, f, protocol=-1) f.close()
def first_step_simulation(strand_seq, num_traj, T=25, rate_method_k_or_m="Metropolis", concentration=50e-9, material="DNA"): # Run the simulations print "Running %d first step mode simulations for %s (with Boltzmann sampling)..." % (num_traj,strand_seq) o = create_setup(strand_seq, num_traj, T, rate_method_k_or_m, material) initialize_energy_model(o) # Prior simulations could have been for different temperature, material, etc. # But Multistrand "optimizes" by sharing the energy model parameters from sim to sim. # So if in the same python session you have changed parameters, you must re-initialize. s = SimSystem(o) s.start() return o
def debugTester(): """" Debug tester. """ options = simulationRickettsia(trialsIn=1) options.simulation_mode = Literals.trajectory options.output_interval = 10000 options.temperature = 25.0 options.simulation_time = 5.0e-1 options.join_concentration = 0.1 s = SimSystem(options) s.start() printTrajectory(options)
def first_passage_dissociation(strand_seq, trials, T=25, material="DNA"): print "Running %d first passage time simulations for dissociation of %s..." % ( trials, strand_seq) # Using domain representation makes it easier to write secondary structures. onedomain = Domain(name="itall", sequence=strand_seq) top = Strand(name="top", domains=[onedomain]) bot = top.C single_strand_top = Complex(strands=[top], structure=".") single_strand_bot = Complex(strands=[bot], structure=".") duplex_complex = Complex(strands=[top, bot], structure="(+)") # Declare the simulation complete if the strands become single-stranded again. success_stop_condition = StopCondition( "SUCCESS", [(single_strand_top, Dissoc_Macrostate, 0)]) o = Options( simulation_mode="First Passage Time", parameter_type="Nupack", substrate_type=material, rate_method="Metropolis", num_simulations=trials, simulation_time=10.0, join_concentration= 1e-6, # 1 uM concentration, but doesn't matter for dissociation dangles="Some", temperature=T, rate_scaling="Calibrated", verbosity=0) o.start_state = [duplex_complex] o.stop_conditions = [success_stop_condition] # Now go ahead and run the simulations. initialize_energy_model( o) # concentration changes, so we must make sure energies are right s = SimSystem(o) s.start() dataset = o.interface.results times = np.array([i.time for i in dataset]) timeouts = [i for i in dataset if not i.tag == 'SUCCESS'] if len(timeouts) > 0: print "Warning: %d of %d dissociation trajectories did not finishin allotted %g seconds..." % ( len(timeouts), len(times), 10.0) for i in timeouts: assert (i.tag == Literals.time_out) assert (i.time >= 10.0) krev = 1.0 / np.mean(times) return krev
def doSims(strandSeq, numTraj=2): o1 = standardOptions() o1.num_simulations = numTraj o1.output_interval = 1 hybridization(o1, strandSeq) o1.initial_seed = 1777 s = SimSystem(o1) s.start() printTrajectory(o1)
def printTrajectory(self): instanceSeed = self.seed + (time.time() * 10000) % (math.pow(2, 32) - 1) o1 = self.factory.new(instanceSeed) o1.num_simulations = 1 o1.output_interval = 1 s = SimSystem(o1) s.start() seqstring = " " for i in range(len(o1.full_trajectory)): timeT = 1e3 * o1.full_trajectory_times[i] states = o1.full_trajectory[i] ids = [] newseqs = [] structs = [] dG = 0.0 pairTypes = [] for state in states: ids += [str(state[2])] newseqs += [ state[3] ] # extract the strand sequences in each complex (joined by "+" for multistranded complexes) structs += [ state[4] ] # similarly extract the secondary structures for each complex dG += dG + state[5] newseqstring = ' '.join( newseqs ) # make a space-separated string of complexes, to represent the whole tube system sequence tubestruct = ' '.join( structs ) # give the dot-paren secondary structure for the whole test tube if not newseqstring == seqstring: print(newseqstring) seqstring = newseqstring # because strand order can change upon association of dissociation, print it when it changes print(tubestruct + (' t=%.6f ms, dG=%3.2f kcal/mol ' % (timeT, dG)))
def first_step_simulation(strand_seq, trials, T=25, material="DNA"): print ("Running %i first step mode simulations for %s (with Boltzmann sampling)..." % (trials, strand_seq)) # Using domain representation makes it easier to write secondary structures. onedomain = Domain(name="onedomain", sequence=strand_seq) gdomain = Domain(name="gdomain", sequence="TTTT") top = Strand(name="top", domains=[onedomain]) bot = top.C dangle = Strand(name="Dangle", domains=[onedomain, gdomain]) duplex_complex = Complex(strands=[top, bot], structure="(+)") invader_complex = Complex(strands=[dangle], structure="..") duplex_invaded = Complex(strands=[dangle, bot], structure="(.+)") # Declare the simulation complete if the strands become a perfect duplex. success_stop_condition = StopCondition(Options.STR_SUCCESS, [(duplex_invaded, Options.exactMacrostate, 0)]) failed_stop_condition = StopCondition(Options.STR_FAILURE, [(duplex_complex, Options.dissocMacrostate, 0)]) for x in [duplex_complex, invader_complex]: x.boltzmann_count = trials x.boltzmann_sample = True # the first argument has to be trials. def getOptions(trials, material, duplex_complex, dangle, success_stop_condition, failed_stop_condition): o = Options(simulation_mode="First Step", substrate_type=material, rate_method="Metropolis", num_simulations=trials, simulation_time=ATIME_OUT, temperature=T) o.start_state = [duplex_complex, dangle] o.stop_conditions = [success_stop_condition, failed_stop_condition] # FD: The result of this script depend significantly on JS or DNA23 parameterization. o.unimolecular_scaling = 5.0e6; o.bimolecular_scaling = 1.4e6; return o myOptions = getOptions(trials,material, duplex_complex, invader_complex, success_stop_condition, failed_stop_condition) s = SimSystem(myOptions) s.start() print "debug_mac2 finished running."
def first_passage_association(strand_seq, trials, concentration, T=25, material="DNA"): print "Running %d first passage time simulations for association of %s at %s..." % (trials, strand_seq, concentration_string(concentration)) # Using domain representation makes it easier to write secondary structures. onedomain = Domain(name="itall",sequence=strand_seq) top = Strand(name="top",domains=[onedomain]) bot = top.C duplex_complex = Complex(strands=[top, bot],structure="(+)") single_strand_top = Complex(strands=[top],structure=".") single_strand_bot = Complex(strands=[bot],structure=".") # Start with Boltzmann-sampled single-strands... it only seems fair. single_strand_top.boltzmann_count = trials single_strand_bot.boltzmann_count = trials single_strand_top.boltzmann_sample = True single_strand_bot.boltzmann_sample = True # Declare the simulation complete if the strands become a perfect duplex. success_stop_condition = StopCondition("SUCCESS",[(duplex_complex,Exact_Macrostate,0)]) o = Options(simulation_mode="First Passage Time",parameter_type="Nupack", substrate_type=material, rate_method = "Metropolis", num_simulations = trials, simulation_time=10.0, join_concentration=concentration, dangles = "Some", temperature = T, rate_scaling = "Calibrated", verbosity = 0) o.start_state = [single_strand_top, single_strand_bot] o.stop_conditions = [success_stop_condition] # Now go ahead and run the simulations. initialize_energy_model(o) # concentration changes, so we must make sure energies are right s = SimSystem(o) s.start() dataset = o.interface.results times = np.array([i.time for i in dataset]) timeouts = [i for i in dataset if not i.tag == 'SUCCESS'] if len(timeouts)>0 : print "some association trajectories did not finish..." for i in timeouts : assert (i.type_name=='Time') assert (i.tag == None ) assert (i.time >= 10.0) print "average completion time = %g seconds at %s" % (np.mean(times),concentration_string(concentration)) keff = 1.0/np.mean( times )/concentration return keff
def transition_mode_simulation(strand_seq, duration, concentration, T=25, material="DNA"): print "Running %g seconds of transition mode simulations of %s at %s..." % (duration, strand_seq, concentration_string(concentration)) # Using domain representation makes it easier to write secondary structures. onedomain = Domain(name="itall",sequence=strand_seq) top = Strand(name="top",domains=[onedomain]) bot = top.C duplex_complex = Complex(strands=[top, bot],structure="(+)") single_strand_top = Complex(strands=[top],structure=".") single_strand_bot = Complex(strands=[bot],structure=".") # Declare macrostates single_stranded_macrostate = Macrostate("SINGLE",[(single_strand_top,Dissoc_Macrostate,0)]) duplex_macrostate = Macrostate("DUPLEX",[(duplex_complex,Loose_Macrostate,4)]) o = Options(simulation_mode="Transition",parameter_type="Nupack", substrate_type=material, rate_method = "Metropolis", num_simulations = 1, simulation_time=float(duration), # time must be passed as float, not int join_concentration=concentration, dangles = "Some", temperature = T, rate_scaling = "Calibrated", verbosity = 0) o.start_state = [single_strand_top, single_strand_bot] o.stop_conditions = [single_stranded_macrostate, duplex_macrostate] # not actually stopping, just tracking # Now go ahead and run the simulations until time-out. initialize_energy_model(o) # concentration changes, so we must make sure energies are right s = SimSystem(o) s.start() # Now make sense of the results. transition_dict = parse_transition_lists(o.interface.transition_lists) print_transition_dict( transition_dict, o ) # A is SINGLE, B is DUPLEX N_AtoA = float(len( transition_dict['A -> A'] )) if 'A -> A' in transition_dict else 0 dT_AtoA = np.mean( transition_dict['A -> A'] ) if N_AtoA > 0 else 1 # will be mult by zero in that case N_AtoB = float(len( transition_dict['A -> B'] )) if 'A -> B' in transition_dict else 0 dT_AtoB = np.mean( transition_dict['A -> B'] ) if N_AtoB > 0 else 1 N_BtoB = float(len( transition_dict['B -> B'] )) if 'B -> B' in transition_dict else 0 dT_BtoB = np.mean( transition_dict['B -> B'] ) if N_BtoB > 0 else 1 N_BtoA = float(len( transition_dict['B -> A'] )) if 'B -> A' in transition_dict else 0 dT_BtoA = np.mean( transition_dict['B -> A'] ) if N_BtoA > 0 else 1 keff = 1.0/(dT_AtoB + (N_AtoA/N_AtoB)*dT_AtoA)/concentration if N_AtoB > 0 else None krev = 1.0/(dT_BtoA + (N_BtoB/N_BtoA)*dT_BtoB) if N_BtoA > 0 else None return keff, krev
def doSims(strandSeq, numTraj=2): o1 = standardOptions() o1.num_simulations = numTraj o1.output_interval = 1 o1.simulation_time = ATIME_OUT # o1.substrate_type = Options.substrateRNA hybridization(o1, strandSeq ) o1.initial_seed = 1777+6 s = SimSystem(o1) s.start() printTrajectory(o1)
def doSim(myFactory, aFactory, list0, list1, instanceSeed, nForwardIn, nReverseIn): try: myOptions = myFactory.new(instanceSeed) myOptions.num_simulations = self.trialsPerThread except: self.exceptionFlag.value = False return """ Overwrite the result factory method if we are not using First Step Mode. By default, the results object is a First Step object. """ if not myOptions.simulation_mode == Literals.first_step: self.settings.rateFactory.first_passage_time = MergeSimSettings.RESULTTYPE3 try: s = SimSystem(myOptions) s.start() except: self.exceptionFlag.value = False return myFSR = self.settings.rateFactory(myOptions.interface.results) nForwardIn.value += myFSR.nForward + myFSR.nForwardAlt nReverseIn.value += myFSR.nReverse for result in myOptions.interface.results: list0.append(result) for endState in myOptions.interface.end_states: list1.append(endState) if self.settings.debug: self.printTrajectories(myOptions) if not (aFactory == None): aFactory.doAnalysis(myOptions)
def find_meanfirstpassagetime_Gillespie(self): startime = timeit.default_timer() options = doReaction([ self.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 ]) #options.output_interval = 1 #to store all the transitions!!!!!!!!!!!!!!!!!! s = SimSystem(options) s.start() myRates = FirstPassageRate(options.interface.results) del s finishtime = timeit.default_timer() #print "average sampling time is " , str ( (finishtime -startime ) / self.num_simulations ) mfpt = myRates.k1() del myRates gc.collect() return mfpt
def doSims(strandSeq, numTraj=2): o1 = standardOptions() o1.simulation_mode = Literals.trajectory o1.num_simulations = numTraj o1.output_interval = 1 o1.join_concentration = 1.0e-9 # o1.join_concentration = 1.0 o1.simulation_time = 0.000005 o1.DNA23Metropolis() seq1 = "ACTGACTGACTG" seq2 = "ACTG" seq3 = "CATTCAGTACAGT" struct = "((((((.((.(.+).((+)).)).)).))))" # # Using domain representation makes it easier to write secondary structures. # domain1 = Domain(name="d1", sequence=seq1) # domain2 = Domain(name="d2", sequence=seq2) # domain3 = Domain(name="d3", sequence=seq3) # # strand1 = Strand(name="s1", domains=[domain1]) # strand2 = Strand(name="s2", domains=[domain2]) # strand3 = Strand(name="s3", domains=[domain3]) myComplex = makeComplex([seq1, seq2, seq3], struct) print myComplex o1.start_state = [myComplex] # Note: no stopping conditions o1.initial_seed = 1777 + 6 s = SimSystem(o1) s.start() printTrajectory(o1)
def doSims(strandSeq, numTraj=2): curr = time.time() o1 = standardOptions(tempIn=36.95) o1.num_simulations = numTraj o1.output_time = 0.0004 # 0.2 ms output o1.simulation_time = 0.52 # 10 ms o1.gt_enable = 1 o1.substrate_type = Literals.substrateRNA o1.simulation_mode = Literals.trajectory o1.cotranscriptional = True # enables the strand growing on the 3' end. # onedomain = Domain(name="itall", sequence="GGAACCGUCUCCCUCUGCCAAAAGGUAGAGGGAGAUGGAGCAUCUCUCUCUACGAAGCAGAGAGAGACGAAGG") # onedomain = Domain(name="itall", sequence="GGAACCGTCTCCCTCTGCCAAAAGGTAGAGGGAGATGGAGCATCTCTCTCTACGAAGCAGAGAGAGACGAAGG") # onedomain = Domain(name="itall", sequence="GGAACCGTCTCCCTCTGCCAAAAGGTAGAGGGAGATGGAGCATCTCTCTCTACGAAGCAGAGAGAGACGAAGGGGAACCGTCTCCCTCTGCCAAAAGGTAGAGGGAGATGGAGCATCTCTCTCTACGAAGCAGAGAGAGACGAAGG") # onedomain = Domain(name="itall", sequence="ATTCCGGTTGATCCTGCCGGAGGTCATTGCTATTGGGGTCCGATTTAGCCATGCTAGTTGCACGAGTTCATACTCGTGGCGAAAAGCTCAGTAACACGTGGCCAAACTACCCTACAGAGAACGATAACCTCGGGAAACTGAGGCTAATAGTTCATACGGGAGTCATGCTGGAATGCCGACTCCCCGAAACGCTCAGGCGCTGTAGGATGTGGCTGCGGCCGATTAGGTAGACGGTGGGGTAACGGCCCACCGTGCCGATAATCGGTACGGGTTGTGAGAGCAAGAGCCCGGAGACGGAATCTGAGACAAGATTCCGGGCCCTACGGGGCGCAGCAGGCGCGAAACCTTTACACTGCACGCAAGTGCGATAAGGGGACCCCAAGTGCGAGGGCATATAGTCCTCGCTTTTCTCGACCGTAAGGCGGTCGAGGAATAAGAGCTGGGCAAGACCGGTGCCAGCCGCCGCGGTAATACCGGCAGCTCAAGTGATGACCGATATTATTGGGCCTAAAGCGTCCGTAGCCGGCCACGAAGGTTCATCGGGAAATCCGCCAGCTCAACTGGCGGGCGTCCGGTGAAAACCACGTGGCTTGGGACCGGAAGGCTCGAGGGGTACGTCCGGGGTAGGAGTGAAATCCCGTAATCCTGGACGGACCACCGATGGCGAAAGCACCTCGAGAAGACGGATCCGACGGTGAGGGACGAAAGCTAGGGTCTCGAACCGGATTAGATACCCGGGTAGTCCTAGCTGTAAACGATGCTCGCTAGGTGTGACACAGGCTACGAGCCTGTGTTGTGCCGTAGGGAAGCCGAGAAGCGAGCCGCCTGGGAAGTACGTCCGCAAGGATGAAACTTAAAGGAATTGGCGGGGGAGCACTACAACCGGAGGAGCCTGCGGTTTAATTGGACTCAACGCCGGACATCTCACCAGCTCCGACTACAGTGATGACGATCAGGTTGATGACCTTATCACGACGCTGTAGAGAGGAGGTGCATGGCCGCCGTCAGCTCGTACCGTGAGGCGTCCTGTTAAGTCAGGCAACGAGCGAGACCCGCACTTCTAATTGCCAGCAGCAGTTTCGACTGGCTGGGTACATTAGAAGGACTGCCGCTGCTAAAGCGGAGGAAGGAACGGGCAACGGTAGGTCAGTATGCCCCGAATGAGCTGGGCTACACGCGGGCTACAATGGTCGAGACAATGGGTTGCTATCTCGAAAGAGAACGCTAATCTCCTAAACTCGATCGTAGTTCGGATTGAGGGCTGAAACTCGCCCTCATGAAGCTGGATTCGGTAGTAATCGCATTTCAATAGAGTGCGGTGAATACGTCCCTGCTCCTTGCACACACCGCCCGTCAAAGCACCCGAGTGAGGTCCGGATGAGGCCACCACACGGTGGTCGAATCTGGGCTTCGCAAGGGGGCTTAAGTCGTAACAAGGTAGCCGTAGGGGAATCTGCGGCTGGATCACCTCCTG") # onedomain = Domain(name="itall", sequence="ATTCCGGTTGATCCTGCCGGAGGTCATTGCTATTGGGGTCCGATTTAGCCATGCTAGTTGCACGAGTTCATACTCGTGGCGAAAAGCTCAGTAACACGTGGCCAAACTACCCTACAGAGAACGATAACCTCGGGAAACTGAGGCTAATAGTTCATACGGGAGTCATGCTGGAATGCCGACTCCCCGAAACGCTCAGGCGCTGTAGGATGTGGCTGCGGCCGATTAGGTAGACGGTGGGGTAACGGCCCACCGTGCCGATAATCGGTACGGGTTGTGAGAGCAAGAGCCCGGAGACGGAATCTGAGACAAGATTCCGGGCCCTA") #CGGGGCGCAGCAGGCGCGAAACCTTTACACTGCACGCAAGTGCGATAAGGGGACCCCAAGTGCGAGGGCATATAGTCCTCGCTTTTCTCGACCGTAAGGCGGTCGAGGAATAAGAGCTGGGCAAGACCGGTGCCAGCCGCCGCGGTAATACCGGCAGCTCAAGTGATGACCGATATTATTGGGCCTAAAGCGTCCGTAGCCGGCCACGAAGGTTCATCGGGAAATCCGCCAGCTCAACTGGCGGGCGTCCGGTGAAAACCACGTGGCTTGGGACCGGAAGGCTCGAGGGGTACGTCCGGGGTAGGAGTGAAATCCCGTAATCCTGGACGGACCACCGATGGCGAAAGCACCTCGAGAAGACGGATCCGACGGTGAGGGACGAAAGCTAGGGTCTCGAACCGGATTAGATACCCGGGTAGTCCTAGCTGTAAACGATGCTCGCTAGGTGTGACACAGGCTACGAGCCTGTGTTGTGCCGTAGGGAAGCCGAGAAGCGAGCCGCCTGGGAAGTACGTCCGCAAGGATGAAACTTAAAGGAATTGGCGGGGGAGCACTACAACCGGAGGAGCCTGCGGTTTAATTGGACTCAACGCCGGACATCTCACCAGCTCCGACTACAGTGATGACGATCAGGTTGATGACCTTATCACGACGCTGTAGAGAGGAGGTGCATGGCCGCCGTCAGCTCGTACCGTGAGGCGTCCTGTTAAGTCAGGCAACGAGCGAGACCCGCACTTCTAATTGCCAGCAGCAGTTTCGACTGGCTGGGTACATTAGAAGGACTGCCGCTGCTAAAGCGGAGGAAGGAACGGGCAACGGTAGGTCAGTATGCCCCGAATGAGCTGGGCTACACGCGGGCTACAATGGTCGAGACAATGGGTTGCTATCTCGAAAGAGAACGCTAATCTCCTAAACTCGATCGTAGTTCGGATTGAGGGCTGAAACTCGCCCTCATGAAGCTGGATTCGGTAGTAATCGCATTTCAATAGAGTGCGGTGAATACGTCCCTGCTCCTTGCACACACCGCCCGTCAAAGCACCCGAGTGAGGTCCGGATGAGGCCACCACACGGTGGTCGAATCTGGGCTTCGCAAGGGGGCTTAAGTCGTAACAAGGTAGCCGTAGGGGAATCTGCGGCTGGATCACCTCCTG") onedomain = Domain( name="itall", sequence= "ATTCCGGTTGATCCTGCCGGAGGTCATTGCTATTGGGGTCCGATTTAGCCATGCTAGTTGCACGAGTTCATACTCGTGGCGAAAAGCTCAGTAACACGTGGCCAAACTACCCTACAGAGAACGATAACCTCGGGAAACTGAGGCTAATAGTTCATACGGGAGTCATGCTGGAATGCCGACTCCCCGAAACGCTCAGGCGCTGTAGGATGTGGCTGCGGCCGATTAGGTAGACGGTGGGGTAACGGCCCACCGTGCCGATAATCGGTACGGGTTGTGAGAGCAAGAGCCCGGAGACGGAATCTGAGACAAGATTCCGGGCCCTACGGGGCGCAGCAGGCGCGAAACCTTTACACTGCACGCAAGTGCGATAAGGGGACCCCAAGTGCGAGGGCATATAGTCCTCGCTTTTCTCGACCGTAAGGCGGTCGAGGAATAAGAGCTGGGCAAGACCGGTGCCAGCCGCCGCGGTAATACCGGCAGCTCAAGTGATGA" ) #CCGATATTATTGGGCCTAAAGCGTCCGTAGCCGGCCACGAAGGTTCATCGGGAAATCCGCCAGCTCAACTGGCGGGCGTCCGGTGAAAACCACGTGGCTTGGGACCGGAAGGCTCGAGGGGTACGTCCGGGGTAGGAGTGAAATCCCGTAATCCTGGACGGACCACCGATGGCGAAAGCACCTCGAGAAGACGGATCCGACGGTGAGGGACGAAAGCTAGGGTCTCGAACCGGATTAGATACCCGGGTAGTCCTAGCTGTAAACGATGCTCGCTAGGTGTGACACAGGCTACGAGCCTGTGTTGTGCCGTAGGGAAGCCGAGAAGCGAGCCGCCTGGGAAGTACGTCCGCAAGGATGAAACTTAAAGGAATTGGCGGGGGAGCACTACAACCGGAGGAGCCTGCGGTTTAATTGGACTCAACGCCGGACATCTCACCAGCTCCGACTACAGTGATGACGATCAGGTTGATGACCTTATCACGACGCTGTAGAGAGGAGGTGCATGGCCGCCGTCAGCTCGTACCGTGAGGCGTCCTGTTAAGTCAGGCAACGAGCGAGACCCGCACTTCTAATTGCCAGCAGCAGTTTCGACTGGCTGGGTACATTAGAAGGACTGCCGCTGCTAAAGCGGAGGAAGGAACGGGCAACGGTAGGTCAGTATGCCCCGAATGAGCTGGGCTACACGCGGGCTACAATGGTCGAGACAATGGGTTGCTATCTCGAAAGAGAACGCTAATCTCCTAAACTCGATCGTAGTTCGGATTGAGGGCTGAAACTCGCCCTCATGAAGCTGGATTCGGTAGTAATCGCATTTCAATAGAGTGCGGTGAATACGTCCCTGCTCCTTGCACACACCGCCCGTCAAAGCACCCGAGTGAGGTCCGGATGAGGCCACCACACGGTGGTCGAATCTGGGCTTCGCAAGGGGGCTTAAGTCGTAACAAGGTAGCCGTAGGGGAATCTGCGGCTGGATCACCTCCTG") top = Strand(name="top", domains=[onedomain]) startTop = Complex(strands=[top], structure=".") o1.start_state = [startTop] setArrParams(o1, 92) # o1.initial_seed = 1777+6 s = SimSystem(o1) s.start() printTrajectory(o1) print "Exe time is " + str(time.time() - curr)
def run_sims2(): print "Performing simulations..." # compare closing of stems based on possible kinetic traps trial_numbers = 10 o1 = create_setup(trial_numbers, toehold_t, toehold_d, domain_1) o2 = create_setup(trial_numbers, toehold_t, toehold_d, domain_2) for o in [o1, o2]: s = SimSystem(o) s.start() # all these simulations are at the same join_concentration and temperature, # so there's no need to re-initialize the energy model before each one. all_results = [o.interface.results for o in [o1, o2]] all_seqs = ["one", "two"] print "Plotting results..." plot_histograms(all_results, figure=1, labels=all_seqs) plot_completion_graph(all_results, figure=2, labels=all_seqs)
def run_trajectory(o): s = SimSystem(o) print "finished simsystem. now starting..." s.start() print "after call to start."
def run_sims(): print("Performing simulations...") # compare closing of stems based on possible kinetic traps o1 = setup_options_hairpin( trials=1000, stem_seq="GCATGC", hairpin_seq="TTTT") # 2-base misaligned GC pairing possible o2 = setup_options_hairpin( trials=1000, stem_seq="GGCGGC", hairpin_seq="TTTT") # 3-base misaligned GGC pairing possible o3 = setup_options_hairpin( trials=1000, stem_seq="GCCGCG", hairpin_seq="TTTT" ) # strong stem, but no significant misaligned pairing o4 = setup_options_hairpin( trials=1000, stem_seq="ATTATA", hairpin_seq="TTTT") # weak stem, no significant misaligned pairing s = SimSystem(o1) s.start() s = SimSystem(o2) s.start() s = SimSystem(o3) s.start() s = SimSystem(o4) s.start() # all these simulations are at the same join_concentration and temperature, # so there's no need to re-initialize the energy model before each one. all_results = [o.interface.results for o in [o1, o2, o3, o4]] all_seqs = [o.start_state[0].sequence for o in [o1, o2, o3, o4]] print("Plotting results...") plot_histograms(all_results, figure=1, labels=all_seqs) plot_completion_graph(all_results, figure=2, labels=all_seqs) # conclusions: # weak stem forms slowly, but without traps. # stronger stems form quickly, but if 3-base misalignment is possible, it may take a long time special = 'fastest' # or 'slowest', if you wish, but these trajectories involve many many steps! print("Showing the %s trajectories for each hairpin sequence..." % special) show_interesting_trajectories(all_results, all_seqs, special)
def show_interesting_trajectories(result_lists, seqs, type='fastest'): mintimes = [] maxtimes = [] slowseeds = [] fastseeds = [] for n in range(len(result_lists)): times = 1e6 * np.array([ i.time for i in result_lists[n] ]) # convert from seconds to microseconds units. slowseeds.append(result_lists[n][np.argmax( times)].seed) # find the seed used for the slowest simulation fastseeds.append(result_lists[n][np.argmin( times)].seed) # find the seed used for the fastest simulation mintimes.append(np.min(times)) maxtimes.append(np.max(times)) # taken from hairpin_trajectories.py def print_trajectory(o): print(o.full_trajectory[0][0][3]) # the strand sequence print(o.start_state[0].structure) for i in range(len(o.full_trajectory)): time = 1e6 * o.full_trajectory_times[i] state = o.full_trajectory[i][0] struct = state[4] dG = state[5] print(struct + ' t=%11.9f microseconds, dG=%6.2f kcal/mol' % (time, dG)) # take a look at the fastest folds. to take a look at the more interesting slowest folds, # change "mintimes" to "maxtimes" and change "fastseeds" to "slowseeds"; do this based on 'type' argument seeds = fastseeds if type == 'fastest' else slowseeds times = mintimes if type == 'fastest' else maxtimes for (seq, seed, time) in zip(seqs, seeds, times): s1 = Strand(name="hairpin", sequence=seq) c1 = Complex(strands=[s1], structure=16 * '.') # hard-coded length 16 c2 = Complex(strands=[s1], structure="((((((....))))))" ) # hard-coded stem length 6, loop length 4 sc = StopCondition("CLOSED", [(c2, Exact_Macrostate, 0)]) # For future reference, StopConditions and Macrostates (same thing) are provided as a list of match conditions, # all of which must be matched. I.e. there is an implicit AND being evaluated. E.g. # sc = StopCondition( "EXAMPLE", [(c2,Loose_Macrostate,8), (c1,Loose_Macrostate,4)] # would specify the intersection of those two macrostates, i.e. any 2 base pairs of the helix (and maybe more). o = Options( temperature=310.15, dangles='Some', start_state=[c1], simulation_time= 0.1, # 0.1 seconds (lots more time than hairpin_trajectories, to accommodate slow folds) num_simulations=1, # don't play it again, Sam output_interval=1, # record every single step rate_method= 'Metropolis', # the default is 'Kawasaki' (numerically, these are 1 and 2 respectively) rate_scaling= 'Calibrated', # this is the same as 'Default'. 'Unitary' gives values 1.0 to both. simulation_mode='Trajectory' ) # numerically 128. See interface/_options/constants.py for more info about all this. o.stop_conditions = [sc] # don't wait for the time-out o.initial_seed = seed # start with the same random seed as before... s = SimSystem(o) s.start() print_trajectory(o) print("Original run's time: %g microseconds" % time)