ribolands/pathfinder.py
def path_flooding(path, minh, maxlm = None):
    """ Use flooding algorithm to determine local minima on a folding path.
    
    Identifies the lowest energy of the local minimum, one representative
    stucture and "other structures" associated with that minimum. Beware that
    the "other structures" can contain saddle components when the function
    is applied to paths with degenerate saddle components.

    Args:
        path (list[(str, int)]): A list of tuples (structure, energy). 
            The energy must be an integer with unit dcal/mol.
        minh (int): Minimal height of an energy barrier separatig two
            basins [dcal/mol].
        maxlm (optional, int): The highest possible energy of a local minimum.

    Returns:
        [dict, dict]: properties of the local minima.
    """
    assert isinstance(minh, int) # dcal/mol
    assert isinstance(path[0][1], int) # dcal/mol
    indexpath = [[ss, en, step] for step, [ss, en] in enumerate(path)]
    sconf = sorted(indexpath, key = lambda x: x[1]) # by energy

    lmins = dict() # lmins[ss] = [en, set(steps)]
    ssmap = dict() # ssmap[step] = step
    for e, (ss, en, step) in enumerate(sconf):
        if step == 0 or step == len(path) - 1: # edge cases
            nbr = step + 1 if step == 0 else step - 1
            if nbr in ssmap:
                nbr = ssmap[nbr]
                lms, lme = path[nbr]
                assert en >= lme
                assert lme == lmins[lms][0]
                lmins[lms][1].add(step)
                ssmap[step] = nbr
            else:
                lmins[ss] = [en, set([step])]
                ssmap[step] = step
        else: 
            assert 0 < step < len(path)-1
            left, right = step-1, step+1
            if left in ssmap and right in ssmap: # let's connect!
                left, right = ssmap[left], ssmap[right]
                assert left != right # yay, saddle!
                lmsl, lmel = path[left]
                lmsr, lmer = path[right]
                [lower, higher] = [left, right] if lmel < lmer else [right, left]
                [lowlm, highlm] = [lmsl, lmsr] if lmel < lmer else [lmsr, lmsl]
                [lowen, highen] = [lmel, lmer] if lmel < lmer else [lmer, lmel]
                if en - highen < minh or (maxlm and highen > maxlm): # merge higher minimum into lower one.
                    lmins[lowlm][1] |= lmins[highlm][1] | set([step]) 
                    for hlm in lmins[highlm][1]:
                        ssmap[hlm] = lower
                    ssmap[step] = lower
                    del lmins[highlm]
                else: # keep them separated ...
                    ssmap[step] = [higher, lower]
            elif left in ssmap:
                lms, lme = path[ssmap[left]]
                assert en >= lme
                lmins[lms][1].add(step)
                ssmap[step] = ssmap[left]
            elif right in ssmap:
                lms, lme = path[ssmap[right]]
                assert en >= lme
                lmins[lms][1].add(step)
                ssmap[step] = ssmap[right]
            else:
                lmins[ss] = [en, set([step])]
                ssmap[step] = step
    return ssmap
 Use flooding algorithm to determine local minima on a folding path.
    
    Identifies the lowest energy of the local minimum, one representative
    stucture and "other structures" associated with that minimum. Beware that
    the "other structures" can contain saddle components when the function
    is applied to paths with degenerate saddle components.

    Args:
        path (list[(str, int)]): A list of tuples (structure, energy). 
            The energy must be an integer with unit dcal/mol.
        minh (int): Minimal height of an energy barrier separatig two
            basins [dcal/mol].
        maxlm (optional, int): The highest possible energy of a local minimum.

    Returns:
        [dict, dict]: properties of the local minima.
    
Use flooding algorithm to determine local minima on a folding path.
Identifies the lowest energy of the local minimum, one representative
stucture and "other structures" associated with that minimum. Beware that
the "other structures" can contain saddle components when the function
is applied to paths with degenerate saddle components.
Use flooding algorithm to determine local minima on a folding path . Identifies the lowest energy of the local minimum one representative stucture and " other structures " associated with that minimum . Beware that the " other structures " can contain saddle components when the function is applied to paths with degenerate saddle components .
def path_flooding(path, minh, maxlm = None):
    assert isinstance(minh, int) 
    assert isinstance(path[0][1], int) 
    indexpath = [[ss, en, step] for step, [ss, en] in enumerate(path)]
    sconf = sorted(indexpath, key = lambda x: x[1]) 
    lmins = dict() 
    ssmap = dict() 
    for e, (ss, en, step) in enumerate(sconf):
        if step == 0 or step == len(path) - 1: 
            nbr = step + 1 if step == 0 else step - 1
            if nbr in ssmap:
                nbr = ssmap[nbr]
                lms, lme = path[nbr]
                assert en >= lme
                assert lme == lmins[lms][0]
                lmins[lms][1].add(step)
                ssmap[step] = nbr
            else:
                lmins[ss] = [en, set([step])]
                ssmap[step] = step
        else: 
            assert 0 < step < len(path)-1
            left, right = step-1, step+1
            if left in ssmap and right in ssmap: 
                left, right = ssmap[left], ssmap[right]
                assert left != right 
                lmsl, lmel = path[left]
                lmsr, lmer = path[right]
                [lower, higher] = [left, right] if lmel < lmer else [right, left]
                [lowlm, highlm] = [lmsl, lmsr] if lmel < lmer else [lmsr, lmsl]
                [lowen, highen] = [lmel, lmer] if lmel < lmer else [lmer, lmel]
                if en - highen < minh or (maxlm and highen > maxlm): 
                    lmins[lowlm][1] |= lmins[highlm][1] | set([step]) 
                    for hlm in lmins[highlm][1]:
                        ssmap[hlm] = lower
                    ssmap[step] = lower
                    del lmins[highlm]
                else: 
                    ssmap[step] = [higher, lower]
            elif left in ssmap:
                lms, lme = path[ssmap[left]]
                assert en >= lme
                lmins[lms][1].add(step)
                ssmap[step] = ssmap[left]
            elif right in ssmap:
                lms, lme = path[ssmap[right]]
                assert en >= lme
                lmins[lms][1].add(step)
                ssmap[step] = ssmap[right]
            else:
                lmins[ss] = [en, set([step])]
                ssmap[step] = step
    return ssmap
def path_flooding ( path , minh , maxlm = None ) : assert isinstance ( minh , int ) assert isinstance ( path [ 0 ] [ 1 ] , int ) indexpath = [ [ ss , en , step ] for step , [ ss , en ] in enumerate ( path ) ] sconf = sorted ( indexpath , key = lambda x : x [ 1 ] ) lmins = dict ( ) ssmap = dict ( ) for e , ( ss , en , step ) in enumerate ( sconf ) : if step == 0 or step == len ( path ) - 1 : nbr = step + 1 if step == 0 else step - 1 if nbr in ssmap : nbr = ssmap [ nbr ] lms , lme = path [ nbr ] assert en >= lme assert lme == lmins [ lms ] [ 0 ] lmins [ lms ] [ 1 ] . add ( step ) ssmap [ step ] = nbr else : lmins [ ss ] = [ en , set ( [ step ] ) ] ssmap [ step ] = step else : assert 0 < step < len ( path ) - 1 left , right = step - 1 , step + 1 if left in ssmap and right in ssmap : left , right = ssmap [ left ] , ssmap [ right ] assert left != right lmsl , lmel = path [ left ] lmsr , lmer = path [ right ] [ lower , higher ] = [ left , right ] if lmel < lmer else [ right , left ] [ lowlm , highlm ] = [ lmsl , lmsr ] if lmel < lmer else [ lmsr , lmsl ] [ lowen , highen ] = [ lmel , lmer ] if lmel < lmer else [ lmer , lmel ] if en - highen < minh or ( maxlm and highen > maxlm ) : lmins [ lowlm ] [ 1 ] |= lmins [ highlm ] [ 1 ] | set ( [ step ] ) for hlm in lmins [ highlm ] [ 1 ] : ssmap [ hlm ] = lower ssmap [ step ] = lower del lmins [ highlm ] else : ssmap [ step ] = [ higher , lower ] elif left in ssmap : lms , lme = path [ ssmap [ left ] ] assert en >= lme lmins [ lms ] [ 1 ] . add ( step ) ssmap [ step ] = ssmap [ left ] elif right in ssmap : lms , lme = path [ ssmap [ right ] ] assert en >= lme lmins [ lms ] [ 1 ] . add ( step ) ssmap [ step ] = ssmap [ right ] else : lmins [ ss ] = [ en , set ( [ step ] ) ] ssmap [ step ] = step return ssmap
Use flooding algorithm to determine local minima on a folding path.
Use flooding algorithm to determine local minima on a folding path .
""" Use flooding algorithm to determine local minima on a folding path.
    
    Identifies the lowest energy of the local minimum, one representative
    stucture and "other structures" associated with that minimum. Beware that
    the "other structures" can contain saddle components when the function
    is applied to paths with degenerate saddle components.

    Args:
        path (list[(str, int)]): A list of tuples (structure, energy). 
            The energy must be an integer with unit dcal/mol.
        minh (int): Minimal height of an energy barrier separatig two
            basins [dcal/mol].
        maxlm (optional, int): The highest possible energy of a local minimum.

    Returns:
        [dict, dict]: properties of the local minima.
    """ # dcal/mol # dcal/mol # by energy # lmins[ss] = [en, set(steps)] # ssmap[step] = step # edge cases # let's connect! # yay, saddle! # merge higher minimum into lower one. # keep them separated ...
properties of the local minima.
properties of the local minima .
[dict, dict]
path
A list of tuples (structure, energy).
The energy must be an integer with unit dcal/mol.
A list of tuples ( structure energy ) . The energy must be an integer with unit dcal / mol .
minh
Minimal height of an energy barrier separatig two
basins [dcal/mol].
Minimal height of an energy barrier separatig two basins [ dcal / mol ] .
maxlm
The highest possible energy of a local minimum.
The highest possible energy of a local minimum .