ribolands/pathfinder.py
def local_flooding(fc, lmin, basinh = 2, rates = True, RT = None, k0 = None):
    """ Enumerate microstates within basin and the first steps out of the basin.

    Args:
        fc: The fold compound object.
        lmin: The local minimum representative secondary structure.
        basinh (kcal/mol): a local elevation higher than minh is considered a first step.
        rates (bool, optional): Get exit rates for all microtransitions.
    """
    macro = dict() # macro[ss] = [dG, P_ss] elevation and probability
    fstep = dict() # fstep[ss] = [(m1,k_ms), (m2,k_ms), ...] neighbors in macrostate and microrate

    dcbasinh = int(round(basinh*100))
    def local_nbrs(ss, refen):
        assert ss in macro # obvious, this was just assigned!
        for [nb, dcal] in get_neighbors(fc, ss):
            if dcal + refen >= dcbasinh:
                if nb in fstep:
                    fstep[nb].append((ss, round(dcal/100, 2)))
                else:
                    fstep[nb] = [(ss, round(dcal/100, 2))]
                continue
            if nb in macro:
                continue
            yield [nb, dcal]

    news = [(lmin, 0)]
    while news:
        newnews = set()
        for (newss, newen) in news:
            if newen < 0:
                #rlog.warning('Found a lower energy neighbor!')
                return None, newss
            assert newss not in fstep # this is going to be in macrostate!
            macro[newss] = [round(newen/100, 2), None] # elevation, probability
            for [nbr, dcal] in local_nbrs(newss, newen):
                newnews.add((nbr, newen+dcal))
        news = list(newnews)

    if rates:
        assert k0 is not None
        assert RT is not None
        # Alright, so we calculate the probabilities of states in the macrostate:
        x = np.array([m[0] for m in macro.values()])
        Z = sum(math.e**(-x/RT))
        for m in macro.keys():
            macro[m][1] = (math.e**(-macro[m][0]/RT))/Z 
        k_exit = 0
        for fs, ms in fstep.items():
            k_mj = 0
            P_mj = 0
            for [m, dG] in ms:
                k_ij = k0 * math.e**(-dG/RT)
                P_i = macro[m][1]
                k_mj += P_i * k_ij
                k_exit += P_i * k_ij
            fstep[fs] = [P_mj, k_mj]
        for fs, [P_mj, k_mj] in fstep.items():
            assert P_mj == 0
            fstep[fs][0] = fstep[fs][1]/k_exit
    return macro, fstep
 Enumerate microstates within basin and the first steps out of the basin.

    Args:
        fc: The fold compound object.
        lmin: The local minimum representative secondary structure.
        basinh (kcal/mol): a local elevation higher than minh is considered a first step.
        rates (bool, optional): Get exit rates for all microtransitions.
    
Enumerate microstates within basin and the first steps out of the basin.
Enumerate microstates within basin and the first steps out of the basin .
def local_flooding(fc, lmin, basinh = 2, rates = True, RT = None, k0 = None):
    macro = dict() 
    fstep = dict() 
    dcbasinh = int(round(basinh*100))
    def local_nbrs(ss, refen):
        assert ss in macro 
        for [nb, dcal] in get_neighbors(fc, ss):
            if dcal + refen >= dcbasinh:
                if nb in fstep:
                    fstep[nb].append((ss, round(dcal/100, 2)))
                else:
                    fstep[nb] = [(ss, round(dcal/100, 2))]
                continue
            if nb in macro:
                continue
            yield [nb, dcal]
    news = [(lmin, 0)]
    while news:
        newnews = set()
        for (newss, newen) in news:
            if newen < 0:
                return None, newss
            assert newss not in fstep 
            macro[newss] = [round(newen/100, 2), None] 
            for [nbr, dcal] in local_nbrs(newss, newen):
                newnews.add((nbr, newen+dcal))
        news = list(newnews)
    if rates:
        assert k0 is not None
        assert RT is not None
        x = np.array([m[0] for m in macro.values()])
        Z = sum(math.e**(-x/RT))
        for m in macro.keys():
            macro[m][1] = (math.e**(-macro[m][0]/RT))/Z 
        k_exit = 0
        for fs, ms in fstep.items():
            k_mj = 0
            P_mj = 0
            for [m, dG] in ms:
                k_ij = k0 * math.e**(-dG/RT)
                P_i = macro[m][1]
                k_mj += P_i * k_ij
                k_exit += P_i * k_ij
            fstep[fs] = [P_mj, k_mj]
        for fs, [P_mj, k_mj] in fstep.items():
            assert P_mj == 0
            fstep[fs][0] = fstep[fs][1]/k_exit
    return macro, fstep
def local_flooding ( fc , lmin , basinh = 2 , rates = True , RT = None , k0 = None ) : macro = dict ( ) fstep = dict ( ) dcbasinh = int ( round ( basinh * 100 ) ) def local_nbrs ( ss , refen ) : assert ss in macro for [ nb , dcal ] in get_neighbors ( fc , ss ) : if dcal + refen >= dcbasinh : if nb in fstep : fstep [ nb ] . append ( ( ss , round ( dcal / 100 , 2 ) ) ) else : fstep [ nb ] = [ ( ss , round ( dcal / 100 , 2 ) ) ] continue if nb in macro : continue yield [ nb , dcal ] news = [ ( lmin , 0 ) ] while news : newnews = set ( ) for ( newss , newen ) in news : if newen < 0 : return None , newss assert newss not in fstep macro [ newss ] = [ round ( newen / 100 , 2 ) , None ] for [ nbr , dcal ] in local_nbrs ( newss , newen ) : newnews . add ( ( nbr , newen + dcal ) ) news = list ( newnews ) if rates : assert k0 is not None assert RT is not None x = np . array ( [ m [ 0 ] for m in macro . values ( ) ] ) Z = sum ( math . e ** ( - x / RT ) ) for m in macro . keys ( ) : macro [ m ] [ 1 ] = ( math . e ** ( - macro [ m ] [ 0 ] / RT ) ) / Z k_exit = 0 for fs , ms in fstep . items ( ) : k_mj = 0 P_mj = 0 for [ m , dG ] in ms : k_ij = k0 * math . e ** ( - dG / RT ) P_i = macro [ m ] [ 1 ] k_mj += P_i * k_ij k_exit += P_i * k_ij fstep [ fs ] = [ P_mj , k_mj ] for fs , [ P_mj , k_mj ] in fstep . items ( ) : assert P_mj == 0 fstep [ fs ] [ 0 ] = fstep [ fs ] [ 1 ] / k_exit return macro , fstep
Enumerate microstates within basin and the first steps out of the basin.
Enumerate microstates within basin and the first steps out of the basin .
""" Enumerate microstates within basin and the first steps out of the basin.

    Args:
        fc: The fold compound object.
        lmin: The local minimum representative secondary structure.
        basinh (kcal/mol): a local elevation higher than minh is considered a first step.
        rates (bool, optional): Get exit rates for all microtransitions.
    """ # macro[ss] = [dG, P_ss] elevation and probability # fstep[ss] = [(m1,k_ms), (m2,k_ms), ...] neighbors in macrostate and microrate # obvious, this was just assigned! #rlog.warning('Found a lower energy neighbor!') # this is going to be in macrostate! # elevation, probability # Alright, so we calculate the probabilities of states in the macrostate:
fc
The fold compound object.
The fold compound object .
lmin
The local minimum representative secondary structure.
The local minimum representative secondary structure .
basinh
a local elevation higher than minh is considered a first step.
a local elevation higher than minh is considered a first step .
rates
Get exit rates for all microtransitions.
Get exit rates for all microtransitions .
RT
k0