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)
예제 #2
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
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))

mytime.write("fatten time time " + str(time.time() - st) + "\n")

st = time.time()

with open(pathuniqueid, "wb") as p:
    pickle.dump(myBuilder.uniqueID_number, p)

with open(
        pathbuilder + myenums.EDITIONAL.TEMPSTATESPACE.value + str(start) +
        "-" + str(end), "wb") as p:
    pickle.dump(myBuilder.tempstatespace, p)

with open(
        pathbuilder + myenums.EDITIONAL.TEMPTRANSITIONS.value + str(start) +