Beispiel #1
0
def cut_transitions_square(filename, start, end, outfile, count="cut"):
    """Read transitions from file and cut out the piece start->end,
    so size NxN with N=end-start, row/col end is not included
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename, dim_trans)

    #L = end-start+1
    if 'edges' in header:
        edges = header['edges']
        edges = edges[start:end + 1]
    else:
        edges = None
    #count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    A = transmatrix[start:end, start:end]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A, outfile, lt, count, edges=edges, dt=dt, dn=dn)
Beispiel #2
0
def cyclic_permuation_transitions_square(
    filename,
    shift,
    outfile,
):  #count=None):
    """Shift indices periodically
    Read transitions from file and cut out the piece [shift:] and paste it behind [:shift],
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename, dim_trans)

    if 'edges' in header:
        edges = header['edges']
    else:
        edges = None
    count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    n = dim_trans
    A = np.zeros(transmatrix.shape, int)
    A[:(n - shift), :(n - shift)] = transmatrix[shift:, shift:]
    A[(n - shift):, :(n - shift)] = transmatrix[:shift, shift:]
    A[:(n - shift), (n - shift):] = transmatrix[shift:, :shift]
    A[(n - shift):, (n - shift):] = transmatrix[:shift, :shift]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A, outfile, lt, count, edges=edges, dt=dt, dn=dn)
Beispiel #3
0
def cut_transitions_square(filename,start,end,outfile,count="cut"):
    """Read transitions from file and cut out the piece start->end,
    so size NxN with N=end-start, row/col end is not included
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename,dim_trans)

    #L = end-start+1
    if 'edges' in header:
        edges = header['edges']
        edges = edges[start:end+1]
    else:
        edges = None
    #count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    A = transmatrix[start:end,start:end]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A,outfile,lt,count,edges=edges,dt=dt,dn=dn)
Beispiel #4
0
def cyclic_permuation_transitions_square(filename,shift,outfile,): #count=None):
    """Shift indices periodically
    Read transitions from file and cut out the piece [shift:] and paste it behind [:shift],
    counting starts from 0"""
    #from mcdiff.reading import read_transition_square, read_transition_header
    from mcdiff.tools.functionsextract import write_Tmat_square
    dim_trans = guess_dim_transition_square(filename)
    header = read_transition_header(filename)
    transmatrix = read_transition_square(filename,dim_trans)

    if 'edges' in header:
        edges = header['edges']
    else:
        edges = None
    count = header['count']
    lt = header['lt']
    dt = header['dt']
    dn = header['dn']

    n = dim_trans
    A = np.zeros(transmatrix.shape,int)
    A[:(n-shift),:(n-shift)] = transmatrix[shift:,shift:]
    A[(n-shift):,:(n-shift)] = transmatrix[:shift,shift:]
    A[:(n-shift),(n-shift):] = transmatrix[shift:,:shift]
    A[(n-shift):,(n-shift):] = transmatrix[:shift,:shift]

    assert filename != outfile  # do not overwrite
    write_Tmat_square(A,outfile,lt,count,edges=edges,dt=dt,dn=dn)
Beispiel #5
0
def merge_transitions(
    trans,
    outfile,
):
    """combine the different trans matrices in Transitions matrix

    Function works if all trans matrices have equal lag times,
    this can happen if Transitions object combines the trans
    matrices of different runs of the same system."""

    from mcdiff.tools.functionsextract import write_Tmat_square, write_Tmat_cube

    # make sure to have equal lag times
    assert (trans.list_lt - trans.list_lt[0]).all() == 0
    dn = trans.list_dn[0]
    dt = trans.list_dt[0]
    lt = trans.list_lt[0]
    # edges will be checked to be equal when trans object is created
    edges = trans.edges
    count = trans.count
    A = np.rint(np.sum(trans.list_trans, 0)).astype(int)
    if len(trans.list_trans.shape) == 3:
        write_Tmat_square(A, outfile, lt, count, edges=edges, dt=dt, dn=dn)
    elif len(trans.list_trans.shape) == 4:
        write_Tmat_cube(A,
                        outfile,
                        lt,
                        count,
                        edges=edges,
                        dt=dt,
                        dn=dn,
                        redges=trans.redges)
    else:
        raise ValueError(
            "list_trans does not have expected dimension (3 or 4): %i" %
            len(trans.list_trans.shape))
Beispiel #6
0
def merge_transitions(trans,outfile,):
    """combine the different trans matrices in Transitions matrix

    Function works if all trans matrices have equal lag times,
    this can happen if Transitions object combines the trans
    matrices of different runs of the same system."""

    from mcdiff.tools.functionsextract import write_Tmat_square,write_Tmat_cube

    # make sure to have equal lag times
    assert (trans.list_lt-trans.list_lt[0]).all() == 0
    dn = trans.list_dn[0]
    dt = trans.list_dt[0]
    lt = trans.list_lt[0]
    # edges will be checked to be equal when trans object is created
    edges = trans.edges
    count = trans.count
    A = np.rint(np.sum(trans.list_trans,0)).astype(int)
    if len(trans.list_trans.shape) == 3:
        write_Tmat_square(A,outfile,lt,count,edges=edges,dt=dt,dn=dn)
    elif len(trans.list_trans.shape) == 4:
        write_Tmat_cube(A,outfile,lt,count,edges=edges,dt=dt,dn=dn,redges=trans.redges)
    else: raise ValueError("list_trans does not have expected dimension (3 or 4): %i" 
                 %len(trans.list_trans.shape))