예제 #1
0
        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)
예제 #2
0
    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))
예제 #3
0
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)
예제 #4
0
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
예제 #5
0
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 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 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
예제 #8
0
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 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()
예제 #10
0
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)
예제 #11
0
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 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
예제 #13
0
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)
예제 #14
0
    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)))
예제 #15
0
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."
예제 #16
0
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
예제 #17
0
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
예제 #18
0
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)        
예제 #19
0
        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)
예제 #20
0
 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)
예제 #23
0
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_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 test_run_system_several_times(self):
        """ Test [System]: Create three system objects, then run each in sequence

        We run a system several times (using the same options object, but in sequence)
        Needs changing in the future."""
        system = SimSystem(self.options)
        system.start()

        MI_System_Object_TestCase.str_run_system_several_times = "First run results:\n{0}\n".format(str(self.options.interface))
        
        system2 = SimSystem(self.options)
        system2.start()

        MI_System_Object_TestCase.str_run_system_several_times += "Second run results [different system]:\n{0}\n".format(str(self.options.interface))

        system3 = SimSystem(self.options)
        system3.start()
        
        MI_System_Object_TestCase.str_run_system_several_times += "Third run results [yet another system]:\n{0}\n".format(str(self.options.interface))
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)
예제 #27
0
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 first step mode simulations for %s (with Boltzmann sampling)..." % (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()
    dataset = o.interface.results

    # You might be interested in examining the data manually when num_traj < 10
    # for i in dataset:
    #    print i.type_name
    #    print i
    
    # Extract the timing information for successful and failed runs

    print
    print "Inferred rate constants with analytical error bars:"
    N_forward, N_reverse, kcoll, forward_kcoll, reverse_kcoll, k1, k2, k1prime, k2prime, keff, zcrit = compute_rate_constants(dataset,concentration)

    # Bootstrapping is a technique that estimates statistical properties by assuming that the given samples adequately represent the true distribution,
    # and then resampling from that distribution to create as many mock data sets as you want.  The variation of statistical quantities 
    # in the mock data sets are often a good estimate of the true values.
    # We rely on bootstrapping to get error bars for k_eff, and to validate our estimated error bars for k2 and k2prime.

    Nfs, Nrs, kcfs, kcrs, k1s, k2s, k1primes, k2primes, keffs, zcrits = ([],[],[],[],[],[],[],[],[],[])
    for i in range(1000):
        t_dataset = resample_with_replacement(dataset,len(dataset))
        t_N_forward, t_N_reverse, t_kcoll, t_forward_kcoll, t_reverse_kcoll, t_k1, t_k2, t_k1prime, t_k2prime, t_keff, t_zcrit = \
            compute_rate_constants(t_dataset, concentration, printit=False)
        Nfs.append(t_N_forward)
        Nrs.append(t_N_reverse)
        kcfs.append(t_forward_kcoll)
        kcrs.append(t_reverse_kcoll)
        k1s.append(t_k1)
        k2s.append(t_k2)
        k1primes.append(t_k1prime)
        k2primes.append(t_k2prime)
        keffs.append(t_keff)
        zcrits.append(t_zcrit)

    std_Nfs = np.std(Nfs)
    std_Nrs = np.std(Nrs)
    std_kcfs = np.std(kcfs)
    std_kcrs = np.std(kcrs)
    std_k1 = np.std(k1s)
    std_k2 = np.std(k2s)
    std_k1prime = np.std(k1primes)
    std_k2prime = np.std(k2primes)
    std_keff = np.std(keffs)        
    std_zcrit = np.std(zcrits)        

    print
    print "Re-sampled rate constants with bootstrapped error bars:"
    if True:
        print "N_forward = %d +/- %g" % (t_N_forward, std_Nfs)
        print "N_reverse = %d +/- %g" % (t_N_reverse, std_Nrs)
        print "k_collision_forward = %g +/- %g /M/s (i.e. +/- %g %%)" % (t_forward_kcoll, std_kcfs, 100*std_kcfs/forward_kcoll)
        print "k_collision_reverse = %g +/- %g /M/s (i.e. +/- %g %%)" % (t_reverse_kcoll, std_kcrs, 100*std_kcrs/reverse_kcoll)
        print "k1                  = %g +/- %g /M/s (i.e. +/- %g %%)" % (t_k1,std_k1,100*std_k1/k1)
        print "k2                  = %g +/- %g /s   (i.e. +/- %g %%)" % (t_k2,std_k2,100*std_k2/k2)
        print "k1prime             = %g +/- %g /M/s (i.e. +/- %g %%)" % (t_k1prime,std_k1prime,100*std_k1prime/k1prime)
        print "k2prime             = %g +/- %g /s   (i.e. +/- %g %%)" % (t_k2prime,std_k2prime,100*std_k2prime/k2prime)
        print "k_eff               = %g +/- %g /M/s (i.e. +/- %g %%) at %s" % (t_keff,std_keff,100*std_keff/keff,concentration_string(concentration)) 
        print "z_crit              = %s +/- %s (i.e. +/- %g %%)" % (concentration_string(t_zcrit),concentration_string(std_zcrit),100*std_zcrit/zcrit)
    print

    return [N_forward, N_reverse, k1, k1prime, k2, k2prime, keff, zcrit, o]   
예제 #28
0
        def runPaths(optionsF, optionsArgs, space, transitions, initStates,
                     finalStates, sequences):

            myOptions = optionsF(optionsArgs)
            myOptions.activestatespace = True
            myOptions.output_interval = 1

            if not supplyInitialState == None:
                myOptions.start_state = supplyInitialState
            """ Set longer searching time for the initial state. """
            if not ignoreInitialState:
                myOptions.simulation_time = myOptions.simulation_time * 10.0

            simTime = time.time()

            s = SimSystem(myOptions)
            ''' a specialized routine that ends after taking all transitions'''
            if inspecting == True:
                s.localTransitions()
            else:
                s.start()  # after this line, the computation is finished.

            if self.verbosity:
                print("Multistrand simulation is now done,      time = %.2f" %
                      (time.time() - simTime))
            """ load the space """
            myFile = open(
                self.the_dir + str(myOptions.interface.current_seed) +
                "/protospace.txt", "r")

            for line in myFile:

                uniqueID, energyvals, seqs = self.parseState(
                    line, myOptions._temperature_kelvin,
                    myOptions.join_concentration)

                if not uniqueID in sequences:
                    sequences[uniqueID] = seqs

                if not uniqueID in space:

                    space[uniqueID] = energyvals

                elif not space[uniqueID] == energyvals:

                    print("My hashmap contains " + str(uniqueID) +
                          " with Energy " + str(space[uniqueID]) +
                          " but found: " + str(energyvals))
                    print("Line = " + line)
            """ load the transitions """
            myFile = open(
                self.the_dir + str(myOptions.interface.current_seed) +
                "/prototransitions.txt", "r")

            index = 0
            go_on = True

            myLines = []

            for line in myFile:
                myLines.append(line)

            while go_on:

                line1 = myLines[index]
                line2 = myLines[index + 1]
                line3 = myLines[index + 2]

                index = index + 4  # note the whitespace

                go_on = len(myLines) > index

                uID1, ev1, seq1 = self.parseState(
                    line2, myOptions._temperature_kelvin,
                    myOptions.join_concentration)
                uID2, ev2, seq2 = self.parseState(
                    line3, myOptions._temperature_kelvin,
                    myOptions.join_concentration)

                transitionPair = (uID1, uID2)

                if not transitionPair in transitions:

                    transitionList = list()

                    n_complex1 = int(line2.split()[0])
                    n_complex2 = int(line3.split()[0])

                    if n_complex1 == n_complex2:
                        transitionList.append(transitiontype.unimolecular)

                    if n_complex1 > n_complex2:
                        transitionList.append(transitiontype.bimolecularIn)

                    if n_complex2 > n_complex1:
                        transitionList.append(transitiontype.bimolecularOut)

                    if myOptions.rate_method == Literals.arrhenius:
                        # decode the transition and add it
                        transitionList.extend(codeToDesc(int(float(line1))))

                    transitions[transitionPair] = transitionList
            """ load the initial states """
            myFile = open(
                self.the_dir + str(myOptions.interface.current_seed) +
                "/protoinitialstates.txt", "r")

            myLines = []

            for line in myFile:
                myLines.append(line)

            index = 0
            go_on = True

            if len(myLines) == 0:
                print("No initial states found!")

            while go_on:

                line1 = myLines[index]
                line2 = myLines[index + 1]

                index = index + 2  # note the whitespace
                go_on = len(myLines) > index

                uID1, ev1, seq1 = self.parseState(
                    line2, myOptions._temperature_kelvin,
                    myOptions.join_concentration)
                count = int(line1.split()[0])

                if not uID1 in initStates:

                    newEntry = InitCountFlux()
                    newEntry.count = count
                    newEntry.flux = 777777  # arrType is the flux, and is unique to the initial state

                    initStates[uID1] = newEntry
            """ load the final states """
            myFile = open(
                self.the_dir + str(myOptions.interface.current_seed) +
                "/protofinalstates.txt", "r")

            myLines = []

            for line in myFile:
                myLines.append(line)

            index = 0
            go_on = True

            if len(myLines) == 0:
                #                 raise ValueError("No succesful final states found -- mean first passage time would be infinite ")
                go_on = False

            while go_on:

                line1 = myLines[index]
                line2 = myLines[index + 1]
                index = index + 2

                go_on = len(myLines) > (index + 1)

                uID1, ev1, seq1 = self.parseState(
                    line1, myOptions._temperature_kelvin,
                    myOptions.join_concentration)
                tag = line2.split()[0]

                if not uID1 in finalStates:
                    finalStates[uID1] = tag
            """ Now delete the files as they can get quite large """
            os.remove(self.the_dir + str(myOptions.interface.current_seed) +
                      "/protospace.txt")
            os.remove(self.the_dir + str(myOptions.interface.current_seed) +
                      "/prototransitions.txt")
            os.remove(self.the_dir + str(myOptions.interface.current_seed) +
                      "/protoinitialstates.txt")
            os.remove(self.the_dir + str(myOptions.interface.current_seed) +
                      "/protofinalstates.txt")
            os.rmdir(self.the_dir + str(myOptions.interface.current_seed))
def run_trajectory(o):
  s = SimSystem(o)
  print "finished simsystem. now starting..."
  s.start()
  print "after call to start."
예제 #30
0
        print(times[-1])
        print(times[-2])

        print(tubestructs[-1])
        print(tubestructs[-2])

        print(energies[-1])
        print(energies[-2])

        #         print(round(times[-1], nVal) == round(2.00311181181e-06, nVal))
        #         print(round(times[-2], nVal) == round(1.99980667462e-06, nVal))
        #
        #         print(tubestructs[-1] == "((.(.(....).)...))...(((((+))))).((((((((((((((((((((+))))))))))))))))))))")
        #         print(tubestructs[-2] == "((.(.(....).)...))..((((((+))))))((((((((((((((((((((+))))))))))))))))))))")
        #
        #         print(round(energies[-1], 2) == round(-31.7, 2))
        #         print(round(energies[-2], 2) == round(-32.13, 2))

        print


# Perform the simulations

o2 = create_setup(seed=19)
s2 = SimSystem(o2)
s2.start()
# see below about the energy model

# process_trajectory(o2, False)
process_trajectory(o2, True, 19)