Esempio n. 1
0
def main():
    nnodes = 100
    # an easy way to set up the graph is to make
    # a dictionary of rates
    rates = dict()
    for i in range(nnodes):
        for j in range(i+1,nnodes):
            rates[(i,j)] = float(i+j) / (i+1)
            rates[(j,i)] = float(i+j) / (j+1)

    # we want to compute rates from node 0 to node 1
    A = [0 ,1, 2]
    B = [3, 4]
    x = 2
    
    weights=dict([(a,1.) for a in A+B])
    weights[2] = 5e3


    ngt = NGT(rates, A, B)
    ngt.compute()
    kAB = ngt.get_rate_AB()
    kBA = ngt.get_rate_BA()
    print "rate AB", kAB
    print "rate BA", kBA
    
    graph = kmcgraph_from_rates(rates)
    pyngt = GraphReduction(graph, A, B)
    pyngt.compute_rates()
    print "pyngt rate AB", pyngt.get_rate_AB()
    print "pyngt rate AB", pyngt.get_rate_BA()
Esempio n. 2
0
def main():
    """the main loop"""
    tstart =  time.clock()
    parser = argparse.ArgumentParser(description=description)

    parser.add_argument("-d", type=str, default=".",
                        help="directory with the min.data, ts.data files")
    parser.add_argument("-T", type=float, default=1., help="Temperature")
    args = parser.parse_args()
    print "temperature", args.T
    directory = args.d
    print "reading from directory:", os.path.abspath(directory)
    
    A = read_minA(directory+"/min.A")
    B = read_minA(directory+"/min.B")
    rate_constants, Peq, knorm = make_rates(args.d, args.T)
            

    if True:
        fname = "out.rate_consts"
        print "saving rate constants to", fname
        with open(fname, "w") as fout:
            for (u,v), k in sorted(rate_constants.iteritems()):
                fout.write("%6d %6d %s\n" % (u,v,k/knorm))

    print "checking and reducing the graph structure"
    try:
        rate_constants = reduce_rates(rate_constants, B, A=A)
    except Exception:
        analyze_graph_error(rate_constants, A, B)
        raise
    
    write_dat_files(rate_constants, A, B, Peq)
    
    print "computing mean first passage times"
    calculator = NGT(rate_constants, A, B, weights=Peq)#, check_rates=False)
    calculator.compute()
    print "computing rates"
    kAB = calculator.get_rate_AB()
    print "k(B<-A)", kAB / knorm
    kBA = calculator.get_rate_BA()
    print "k(A<-B)", kBA / knorm
    
#    if True:
#        fname = "out.mfpt"
#        print "saving mean first passage times for all minima to reach B to file", fname
#        mfpt = sorted([(m, t) for m, t in 
#                       calculator.mfpt_computer.mfpt_dict.iteritems()])
#        with open(fname, "w") as fout:
#            for i, t in mfpt:
#                fout.write("%d %.12g\n" % (i, t * knorm))
#
#    print "computing committor probabilities"
#    sys.stdout.flush()
#    calculator.compute_committors()
#    print "computing steady state rates"
#    kSS = calculator.get_rate_AB_SS() / knorm
#    print "kSS(B<-A)", kSS
#    
#    if True:
#        fname = "out.committors"
#        print "saving committor probabilities for all minima to file", fname
#        coms = sorted([(m, c) for m, c in 
#                       calculator.committor_computer.committor_dict.iteritems()])
#        with open(fname, "w") as fout:
#            for i, c in coms:
#                fout.write("%d %.12g\n" % (i, c))
#    
    time_solve = calculator.time_solve #+ calculator.committor_computer.time_solve
    print "time spent solving linear equations", time_solve, "seconds"
    print "total time", time.clock() - tstart