示例#1
0
 def get_reduced_scell(self):
     """
     enforces the surface coverage criterion and generates
     the list all reduced lattice vectors that correspond to
     the computed supercell size and returns the one with similar
     lattice vector norms
     """
     scell, nlig = self.enforce_coverage()
     if scell and nlig:
         ab = [self.lattice.matrix[0,:], self.lattice.matrix[1,:]]
         uv_list, _ = reduced_supercell_vectors(ab, scell)
         norm_list = []
         for  uv in uv_list:
             unorm = np.linalg.norm(uv[0])
             vnorm = np.linalg.norm(uv[1])
             norm_list.append(abs(1. - unorm/vnorm))
         return nlig, uv_list[np.argmin(norm_list)]
     else:
         logger.warn("couldn't find supercell and number of ligands that satisfy the required surface coverage. exiting.")
         sys.exit()
示例#2
0
 def get_reduced_scell(self):
     """
     enforces the surface coverage criterion and generates
     the list all reduced lattice vectors that correspond to
     the computed supercell size and returns the one with similar
     lattice vector norms
     """
     scell, nlig = self.enforce_coverage()
     if scell and nlig:
         ab = [self.lattice.matrix[0, :], self.lattice.matrix[1, :]]
         uv_list, _ = reduced_supercell_vectors(ab, scell)
         norm_list = []
         for uv in uv_list:
             unorm = np.linalg.norm(uv[0])
             vnorm = np.linalg.norm(uv[1])
             norm_list.append(abs(1. - unorm / vnorm))
         return nlig, uv_list[np.argmin(norm_list)]
     else:
         logger.warn(
                 "couldn't find supercell and number of ligands that satisfy the required surface coverage. exiting.")
         sys.exit()
def get_matching_lattices(iface1,
                          iface2,
                          max_area=100,
                          max_mismatch=0.01,
                          max_angle_diff=1,
                          r1r2_tol=0.02):
    """
    computes a list of matching reduced lattice vectors that satify
    the max_area, max_mismatch and max_anglele_diff criteria
    """
    if iface1 is None and iface2 is None:
        # test : the numbers from the paper
        a1 = 5.653
        a2 = 6.481
        # for 100 plane
        ab1 = [[0, a1 / 2, -a1 / 2], [0, a1 / 2, a1 / 2]]
        ab2 = [[0, a2 / 2, -a2 / 2], [0, a2 / 2, a2 / 2]]
        area1 = a1**2 / 2
        area2 = a2**2 / 2

        # for 110 plane
        ab1 = [[a1 / 2, -a1 / 2, 0], [0, 0, a1]]
        ab2 = [[a2 / 2, -a2 / 2, 0], [0, 0, a2]]
        area1 = a1**2 / sqrt(2)
        area2 = a2**2 / sqrt(2)

        # for 111 surface
        # ab1 = [ [a1/2, 0, a1/2], [a1/2, a1/2, 0]]
        # ab2 = [ [a2/2, 0, a2/2], [a2/2, a2/2, 0]]
        # area1 = a1**2 * sqrt(3)/4 #/ 2 /sqrt(2)
        # area2 = a2**2 * sqrt(3)/4 #/ 2 / sqrt(2)
    else:
        area1 = iface1.surface_area
        area2 = iface2.surface_area

        # a, b vectors that define the surface
        ab1 = [iface1.lattice.matrix[0, :], iface1.lattice.matrix[1, :]]
        ab2 = [iface2.lattice.matrix[0, :], iface2.lattice.matrix[1, :]]

    print('area1, area2', area1, area2)
    r_list = get_r_list(area1, area2, max_area, tol=r1r2_tol)
    if not r_list:
        print(
            'r_list is empty. Try increasing the max surface area or/and the other tolerance paramaters'
        )
        sys.exit()
    for r1r2 in r_list:
        # print('r1, r2', r1r2, '\n')
        uv1_list = reduced_supercell_vectors(ab1, r1r2[0])
        uv2_list = reduced_supercell_vectors(ab2, r1r2[1])
        for uv1 in uv1_list:
            for uv2 in uv2_list:
                u_mismatch = get_mismatch(uv1[0], uv2[0])
                v_mismatch = get_mismatch(uv1[1], uv2[1])
                angle1 = get_angle(uv1[0], uv1[1])
                angle2 = get_angle(uv2[0], uv2[1])
                print('\nu1, u2', np.linalg.norm(uv1[0]),
                      np.linalg.norm(uv2[0]))
                print('v1, v2', np.linalg.norm(uv1[1]), np.linalg.norm(uv2[1]))
                print('angle1, angle2', angle1, angle2)
                print('u and v mismatches', u_mismatch, v_mismatch)
                if abs(u_mismatch) < max_mismatch and abs(
                        v_mismatch) < max_mismatch:
                    if abs(angle1 - angle2) < max_angle_diff:
                        print('\n FOUND ONE')
                        print('u mismatch in percentage = ', u_mismatch)
                        print('v mismatch in percentage = ', v_mismatch)
                        print('angle1, angle diff', angle1,
                              abs(angle1 - angle2))
                        print('uv1, uv2', uv1, uv2)
                        return uv1, uv2
示例#4
0
def get_matching_lattices(
    iface1,
    iface2,
    max_area=100,
    max_mismatch=0.01,
    max_angle_diff=1,
    r1r2_tol=0.02,
    ):
    """
    computes a list of matching reduced lattice vectors that satify
    the max_area, max_mismatch and max_anglele_diff criteria
    """
    #| - get_matching_lattices
    if iface1 is None and iface2 is None:
        # | - iface1 and 2 is None
        # test : the numbers from the paper
        a1 = 5.653
        a2 = 6.481
        # for 100 plane
        ab1 = [[0, a1 / 2, -a1 / 2], [0, a1 / 2, a1 / 2]]
        ab2 = [[0, a2 / 2, -a2 / 2], [0, a2 / 2, a2 / 2]]
        area1 = a1 ** 2 / 2
        area2 = a2 ** 2 / 2
        # for 110 plane
        ab1 = [[a1 / 2, -a1 / 2, 0], [0, 0, a1]]
        ab2 = [[a2 / 2, -a2 / 2, 0], [0, 0, a2]]
        area1 = a1 ** 2 / sqrt(2)
        area2 = a2 ** 2 / sqrt(2)
        # for 111 surface
        # ab1 = [ [a1/2, 0, a1/2], [a1/2, a1/2, 0]]
        # ab2 = [ [a2/2, 0, a2/2], [a2/2, a2/2, 0]]
        # area1 = a1**2 * sqrt(3)/4 #/ 2 /sqrt(2)
        # area2 = a2**2 * sqrt(3)/4 #/ 2 / sqrt(2)
        #__|

    else:
        # | - else
        area1 = iface1.surface_area
        area2 = iface2.surface_area
        # a, b vectors that define the surface
        ab1 = [iface1.lattice.matrix[0, :], iface1.lattice.matrix[1, :]]
        ab2 = [iface2.lattice.matrix[0, :], iface2.lattice.matrix[1, :]]
        # __|

    #| - r_list
    print('initial values:\nuv1:\n{0}\nuv2:\n{1}\n '.format(ab1, ab2))
    r_list = get_r_list(area1, area2, max_area, tol=r1r2_tol)
    if not r_list:
        print(
            'r_list is empty.',
            ' Try increasing the max surface area or/and the other',
            ' tolerance paramaters',
            )
        sys.exit()
    #__|

    # | - Searching For-loop
    found = []
    print('searching ...')
    for r1r2 in r_list:
        uv1_list, tm1_list = reduced_supercell_vectors(ab1, r1r2[0])
        uv2_list, tm2_list = reduced_supercell_vectors(ab2, r1r2[1])
        if not uv1_list and not uv2_list:
            continue
        for i, uv1 in enumerate(uv1_list):
            for j, uv2 in enumerate(uv2_list):
                u_mismatch = get_mismatch(uv1[0], uv2[0])
                v_mismatch = get_mismatch(uv1[1], uv2[1])
                angle1 = get_angle(uv1[0], uv1[1])
                angle2 = get_angle(uv2[0], uv2[1])
                angle_mismatch = abs(angle1 - angle2)
                area1 = get_area(uv1)
                area2 = get_area(uv2)
                if abs(u_mismatch) < max_mismatch and abs(
                        v_mismatch) < max_mismatch:
                    max_angle = max(angle1, angle2)
                    min_angle = min(angle1, angle2)
                    mod_angle = max_angle % min_angle
                    is_angle_factor = False
                    if abs(mod_angle) < 0.001 or abs(
                            mod_angle - min_angle) < 0.001:
                        is_angle_factor = True
                    if angle_mismatch < max_angle_diff or is_angle_factor:
                        if angle_mismatch > max_angle_diff:
                            if angle1 > angle2:
                                uv1[1] = uv1[0] + uv1[1]
                                tm1_list[i][1] = tm1_list[i][0] + tm1_list[i][
                                    1]
                            else:
                                uv2[1] = uv2[0] + uv2[1]
                                tm2_list[j][1] = tm2_list[j][0] + tm2_list[j][
                                    1]

                        found.append(
                            (
                                uv1, uv2, min(area1, area2),
                                u_mismatch,
                                v_mismatch,
                                angle_mismatch,
                                tm1_list[i],
                                tm2_list[j],
                                )
                            )
    #__|

    if found:

        return(found)

        #| - If structure found
        # print('\nMATCH FOUND\n')
        # uv_opt = sorted(found, key=lambda x: x[2])[0]
        # print('optimum values:\nuv1:\n{0}\nuv2:\n{1}\narea:\n{2}\n'.format(
        #     uv_opt[0], uv_opt[1], uv_opt[2]))
        # print('optimum transition matrices:\ntm1:\n{0}\ntm2:\n{1}\n'.format(
        #     uv_opt[6], uv_opt[7]))
        # print('u,v & angle mismatches:\n{0}, {1}, {2}\n'.format(uv_opt[3],
        #                                                         uv_opt[4],
        #                                                         uv_opt[5]))
        # return uv_opt[0], uv_opt[1]
        #__|

    else:
        # | - else
        print('\n NO MATCH FOUND')
        return None, None
def get_matching_lattices(iface1, iface2, max_area = 100,
                          max_mismatch = 0.01, max_angle_diff = 1,
                          r1r2_tol= 0.02):
    """
    computes a list of matching reduced lattice vectors that satify
    the max_area, max_mismatch and max_anglele_diff criteria
    """
    if iface1 is None and iface2 is None:
        #test : the numbers from the paper
        a1 = 5.653
        a2 = 6.481
        #for 100 plane
        ab1 = [ [0, a1/2, -a1/2], [0, a1/2,a1/2]]
        ab2 = [ [0, a2/2, -a2/2], [0, a2/2,a2/2]]
        area1 = a1**2 / 2
        area2 = a2**2 / 2
    
        #for 110 plane
        ab1 = [ [a1/2,-a1/2,0], [0, 0,a1]]
        ab2 = [ [a2/2,-a2/2,0], [0, 0,a2]]    
        area1 = a1**2 / sqrt(2)
        area2 = a2**2 / sqrt(2)
    
        #for 111 surface
        #ab1 = [ [a1/2, 0, a1/2], [a1/2, a1/2, 0]]
        #ab2 = [ [a2/2, 0, a2/2], [a2/2, a2/2, 0]]
        #area1 = a1**2 * sqrt(3)/4 #/ 2 /sqrt(2)
        #area2 = a2**2 * sqrt(3)/4 #/ 2 / sqrt(2)
    else:
        area1 = iface1.surface_area
        area2 = iface2.surface_area
    
        #a, b vectors that define the surface    
        ab1 = [ iface1.lattice.matrix[0,:] , iface1.lattice.matrix[1,:] ]
        ab2 = [ iface2.lattice.matrix[0,:] , iface2.lattice.matrix[1,:] ]
    
    print('area1, area2', area1, area2)
    r_list = get_r_list(area1, area2, max_area, tol=r1r2_tol)
    if not r_list:
        print('r_list is empty. Try increasing the max surface area or/and the other tolerance paramaters')
        sys.exit()
    for r1r2 in r_list:
        #print('r1, r2', r1r2, '\n')
        uv1_list = reduced_supercell_vectors(ab1, r1r2[0])
        uv2_list = reduced_supercell_vectors(ab2, r1r2[1])
        for uv1 in uv1_list:
            for uv2 in uv2_list:                
                u_mismatch = get_mismatch(uv1[0], uv2[0])
                v_mismatch = get_mismatch(uv1[1], uv2[1])
                angle1 = get_angle(uv1[0], uv1[1])
                angle2 = get_angle(uv2[0], uv2[1])
                print('\nu1, u2', np.linalg.norm(uv1[0]), np.linalg.norm(uv2[0]))
                print('v1, v2', np.linalg.norm(uv1[1]), np.linalg.norm(uv2[1]))
                print('angle1, angle2', angle1, angle2)
                print('u and v mismatches', u_mismatch, v_mismatch)
                if  abs(u_mismatch) < max_mismatch and abs(v_mismatch) < max_mismatch:
                    if  abs(angle1 - angle2) < max_angle_diff:
                        print('\n FOUND ONE')
                        print('u mismatch in percentage = ', u_mismatch)
                        print('v mismatch in percentage = ', v_mismatch)
                        print('angle1, angle diff', angle1, abs(angle1 - angle2))
                        print('uv1, uv2', uv1, uv2)
                        return uv1, uv2