Ejemplo n.º 1
0
def findBestPermutationListOPTIM(X1, X2, atomlist, boxl=None):
    """
    use OPTIM's minperm() routine to calculate the optimum permutation
    """    
    #deal with periodic boundary conditions
    periodic = boxl is not None
    if not periodic:
        #it must have a value for passing to fortran 
        boxl = 1.
    sx = sy = sz = boxl
    
    X1 = X1.reshape([-1,3])
    X2 = X2.reshape([-1,3])
    atomlist = np.array(atomlist)
    X13 = X1[atomlist,:].reshape(-1)
    X23 = X2[atomlist,:].reshape(-1)
    
    #run the minperm algorithm
    perm, dist, worstdist, worstradius = minperm.minperm(X13, X23, sx, sy, sz, periodic)
    perm -= 1 #fortran indexing

    #note, dist returned by minperm comes will only be accurate to 6 decimal places at best.
    #if we want a more accurate distance we should calculate it from the coordinates

    # apply the permutation
    newperm = np.array(atomlist[perm])
    X2new = np.copy(X2)
    X2new[atomlist,:] = X2[newperm,:]

    dist = np.sqrt(dist)
    return dist, X1.reshape(-1), X2new.reshape(-1)
Ejemplo n.º 2
0
def find_permutations_OPTIM(X1, X2, box_lengths=None, make_cost_matrix=None):
    """
    use OPTIM's minperm() routine to calculate the optimum permutation
    """

    if make_cost_matrix is not _make_cost_matrix and make_cost_matrix is not None:
        raise RuntimeError(
            "cannot use a custom cost matrix with findBestPermutationListOPTIM"
        )

    # deal with periodic boundary conditions
    periodic = box_lengths is not None
    if not periodic:
        # it must have a value for passing to fortran
        box_lengths = [1., 1., 1.]
    sx, sy, sz = box_lengths

    # run the minperm algorithm
    perm, dist, worstdist, worstradius = minperm.minperm(
        X1.ravel(), X2.ravel(), sx, sy, sz, periodic)
    perm -= 1  # fortran indexing

    # note, dist returned by minperm comes will only be accurate to 6 decimal places at best.
    # if we want a more accurate distance we should calculate it from the coordinates

    dist = np.sqrt(dist)
    return dist, perm
Ejemplo n.º 3
0
def findBestPermutationListOPTIM(X1, X2, atomlist, boxl=None):
    """
    use OPTIM's minperm() routine to calculate the optimum permutation
    """    
    #deal with periodic boundary conditions
    periodic = boxl is not None
    if not periodic:
        #it must have a value for passing to fortran 
        boxl = 1.
    sx = sy = sz = boxl
    
    X1 = X1.reshape([-1,3])
    X2 = X2.reshape([-1,3])
    atomlist = np.array(atomlist)
    X13 = X1[atomlist,:].reshape(-1)
    X23 = X2[atomlist,:].reshape(-1)
    
    #run the minperm algorithm
    perm, dist, worstdist, worstradius = minperm.minperm(X13, X23, sx, sy, sz, periodic)
    perm -= 1 #fortran indexing

    #note, dist returned by minperm comes will only be accurate to 6 decimal places at best.
    #if we want a more accurate distance we should calculate it from the coordinates

    # apply the permutation
    newperm = np.array(atomlist[perm])
    X2new = np.copy(X2)
    X2new[atomlist,:] = X2[newperm,:]

    dist = np.sqrt(dist)
    return dist, X1.reshape(-1), X2new.reshape(-1)
Ejemplo n.º 4
0
def find_permutations_OPTIM(X1, X2, box_lengths=None, make_cost_matrix=None):
    """
    use OPTIM's minperm() routine to calculate the optimum permutation
    """    
    #print "Using OPTIM minperm"
    if make_cost_matrix is not _make_cost_matrix and make_cost_matrix is not None:
        raise RuntimeError("cannot use a custom cost matrix with findBestPermutationListOPTIM")

    # deal with periodic boundary conditions
    periodic = box_lengths is not None
    if not periodic:
        # it must have a value for passing to fortran 
        box_lengths = [1., 1., 1.]
    sx, sy, sz = box_lengths
#     print "passing in periodic:", periodic
#     print "box lengths", sx, sy, sz    
    # run the minperm algorithm
    #print "Starting minperm call"
    perm, dist, worstdist, worstradius = minperm.minperm(X1.ravel(), X2.ravel(), sx, sy, sz, periodic)
    #print "Returned from minperm"
    perm -= 1 # fortran indexing

    # note, dist returned by minperm comes will only be accurate to 6 decimal places at best.
    # if we want a more accurate distance we should calculate it from the coordinates

    dist = np.sqrt(dist)
    return dist, perm