Beispiel #1
0
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 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)
Beispiel #3
0
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