Esempio n. 1
0
def pd_isotopy(knot):
    cross_info = []
    ne = knot.nedges
    for a in knot.crossings:
        temp = [-1, -1, -1, -1, -1]
        for b in range(2):
            temp[a.overstrand_pos()[b]] = a.overstrand_indices()[b]
        for b in range(2):
            temp[a.understrand_pos()[b]] = a.understrand_indices()[b]
        temp[4] = a.sign
        cross_info.append(temp)
    verts = []
    for a in cross_info:
        new_vert = []
        for b in range(4):
            old_val = a[b]
            new_vert.append((old_val + 1) % ne)

        while new_vert[0] > new_vert[1] or new_vert[0] > new_vert[
                2] or new_vert[0] > new_vert[3]:
            new_vert = [new_vert[1], new_vert[2], new_vert[3], new_vert[0]]

        new_vert.append(a[4])
        verts.append(new_vert)
    verts.sort()
    knot2 = PlanarDiagram.from_pdcode(verts)
    for a in range(len(verts)):
        knot2.crossings[a].sign = verts[a][4]
    return knot2
Esempio n. 2
0
def run_homfly(link_set):
    '''
    runs homefly for each .pdstor 

    determines whether a harddrive is plugged in
    question = input("Is your external hard drive connected? (yes/no) ")
    if question == "yes":
        pass
    else:
        raise Exception("You need a hard drive for this computation!")

    '''
    if os.path.isfile("/home/hollis/dev/KnotModels/link_code/test2/master_link_index.txt"): 
        H = file_to_dict("/home/hollis/dev/KnotModels/link_code/test2/master_link_index.txt")
    else:
        H = {}
    #if os.path.isfile("/media/alexander/HollisExt30/master_link_index.txt"): 
    z = open(link_set)
    count = 0
    while True:
        if len(H.keys()) == 0:
            mx = 0
        if len(H.keys()) != 0:
            mx = int(max(H.keys()))
        
        count += 1
        if count %10000 == 0:
            print(count)
        try:

            shadows = []
            shad = PlanarDiagram.read(z)
            num_cross = shad.ncross
            nums = 2**num_cross

            typ = "{0:0" + str(num_cross) + "b}"
            cross_types = []
            for b in range(nums):
                cross_types.append(typ.format(b))
            
            for c in range(len(cross_types)):
                knot = copy.copy(shad)
                for d in range(num_cross):
                    knot.crossings[d].sign = int(cross_types[c][d])
                shadows.append(knot)

            for iter1 in range(len(shadows)):
                new_knot = shadows[iter1]
                
                homfly = str(new_knot.homfly())
                if homfly in H.values():
                    homfly_results(str(H.values().index(homfly)), new_knot)
                else:
                    mx += 1
                    H[mx] = homfly
                    master_index(str(H.values().index(homfly)), homfly)
                    homfly_results(str(H.values().index(homfly)), new_knot)
        except:
            z.close()
            break 
Esempio n. 3
0
def run_homfly(link_set):
    """
    # determines whether a harddrive is plugged in
    question = input("Is your external hard drive connected? (yes/no) ")
    if question == "yes":
        pass
    else:
        raise Exception("You need a hard drive for this computation!")
    """
    if os.path.isfile("/media/alexander/HollisExt30/master_link_index.txt"):
        H = file_to_dict(
            "/media/alexander/HollisExt30/master_link_index.txt").values()
    else:
        H = []
    #if os.path.isfile("/media/alexander/HollisExt30/master_link_index.txt"):
    z = open(link_set)
    count = 0
    while True:
        count += 1
        if count % 10000 == 0:
            print(count)
        try:
            new_knot = PlanarDiagram.read(z)
            homfly = str(new_knot.homfly())
            if homfly in H:
                homfly_results(str(H.index(homfly)), new_knot)
            else:
                H.append(homfly)
                master_index(str(H.index(homfly)), homfly)
                homfly_results(str(H.index(homfly)), new_knot)
        except:
            break
Esempio n. 4
0
def vred(file_path):
    z = open(file_path)
    pdcodes = []
    while 1:
        try:
            pdcodes.append(PlanarDiagram.read(z))
        except:
            break
    human_reduced = []
    pl0 = pdcodes[0].as_spherogram().view()
    keep = [pdcodes.pop(0)]

    for a in range(len(pdcodes)):
        if type(pdcodes[a]) == int:
            continue
        pl = pdcodes[a].as_spherogram().view()
        delete = raw_input("isotopic? y/n : ")
        pl.done()
        if delete == 'y':
            human_reduced.append(pdcodes[a])
        if delete == 'n':
            keep.append(pdcodes[a])
    pl0.done()
    f1 = open(
        file_path[0:len(file_path) - 31] + "human_reduced/" +
        file_path[len(file_path) - 31:len(file_path)], "a")
    f2 = open(file_path[0:len(file_path) - 14] + ".pdstor", "a")
    for a in human_reduced:
        a.write(f1)
    for a in keep:
        a.write(f2)
    os.remove(file_path)
    f1.close()
    z.close()
    f2.close()
Esempio n. 5
0
def counter(file_name):
    fil = open(file_name)
    count = 0
    while 1:
        a = PlanarDiagram.read(fil)
        count += 1
        print count
Esempio n. 6
0
def isometry_reduce(file_path):
    z = open(file_path)
    pdcodes = []
    while 1:
        try:
            pdcodes.append(PlanarDiagram.read(z))
        except:
            break
    z.close()
    # Now I have all pd in ram

    splittable = []
    non_split = []
    isom_un = []
    non_un = []
    print len(pdcodes)
    for a in pdcodes:
        pot = a.simplify()
        if len(pot) != 1:
            splittable.append(a)
        if len(pot) == 1:
            knot = pot[0]
            knot.regenerate()
            non_split.append(knot)

    pdlist = list(non_split)
    if len(non_split) != 0:
        isom_un.append(pdlist[0])
        pdlist[0] = 0
    for a in range(len(pdlist)):
        for b in range(len(isom_un)):
            if type(pdlist[a]) != int and pdlist[a].isomorphic(isom_un[b]):
                non_un.append(pdlist[a])
                pdlist[a] = 0
            if type(pdlist[a]) != int and b == len(isom_un) - 1:
                isom_un.append(pdlist[a])
                pdlist[a] = 0

    f1 = open(file_path[0:len(file_path) - 7] + "_unique.pdstor", "a")
    f2 = open(
        file_path[0:len(file_path) - 24] + "non_unique/" +
        file_path[len(file_path) - 24:len(file_path) - 7] + "_isom.pdstor",
        "a")
    splitfile = open(
        file_path[0:len(file_path) - 24] + "non_unique/" +
        file_path[len(file_path) - 24:len(file_path) - 7] +
        "_splittable.pdstor", "a")
    os.remove(file_path)
    for a in isom_un:
        a.write(f1)
    for a in non_un:
        a.write(f2)
    for a in splittable:
        a.write(splitfile)
    f1.close()
    f2.close()
    splitfile.close()
    return
Esempio n. 7
0
def plink_write():
    z = ()
    c = raw_input("save file as: ")
    a = plink.LinkEditor()
    z = raw_input("Press Enter When Finished With Plink")
    a.zoom_to_fit()
    #a.save_as_eps('~/Desktop/Knot_Table/' +str(c) + '.eps' , 'gray') #saves picture
    b = PlanarDiagram.from_plink(a)
    e = open(str(c) + '.pdstor','w' )
    b.write(e)
    e.close()
    a.done
Esempio n. 8
0
def num_of_diagrams(filename):
    count = 0
    z = open(filename)
    print "Counting..."
    while 1:
        try:
            a = PlanarDiagram.read(z)
            count += 1
        except:
            break
        if count % 10000 == 0:
            print "Passed ", count, " diagrams."
    z.close()
    return count
Esempio n. 9
0
def run_simplify(file_path, length):
    pdcodes = []
    z = open(file_path)
    while 1:
        try:
            pdcodes.append(PlanarDiagram.read(z))
        except:
            break
    z.close()
    if len(pdcodes) == 1 and length != 24:

        f1 = open(file_path[0:len(file_path) - 14] + ".pdstor", "a")
        pdcodes[0].write(f1)
        f1.close()
        os.remove(file_path)
    if len(pdcodes) == 0:
        os.remove(file_path)

    return
Esempio n. 10
0
def random_diagram_parser(string):
    name = "/home/hollis/dev/randomdiagram/src/" + string
    pdcode = open(name)
    pdcode.readline()

    dest = open(
        "/home/hollis/dev/KnotModels/link_code/shadows/" + string[0:1] +
        ".pdstor", "a")
    count = 1
    while 1:
        try:
            diag = PlanarDiagram.read(pdcode)
            if diag.ncomps > 1:
                diag.write(dest)
        except:
            count += 1
            if count > 10:
                break

    pdcode.close()
    dest.close()

    print "Finished : "
Esempio n. 11
0
    # print M

    # plt.figure()
    # plt.gca().set_aspect('equal')
    # plt.triplot(xy[:,0], xy[:,1], triangles, 'go-')
    # plt.show()

#    import sys
#    sys.exit(0)


    #tref = PlanarDiagram.torus_knot(2,3)
    #tref = PlanarDiagram.unknot(1)
    #with open("6a5and6n1.kt") as f:
    #    tref = PlanarDiagram.read_knot_theory(f)
    tref = PlanarDiagram.db_link(6,2,True)
    mesh, real_edges = pdcode_to_mesh(tref)
    #print mesh.verts
    #print mesh.edges
    #print mesh.faces
    print mesh.chi()

    cpm = ThurstonCPMetric.from_triangle_mesh(mesh)
    print cpm.gb_chi()
    #print cpm.newton().gb_chi()

    dummy_bv = list(mesh.b_verts)
    real_bv = []
    for crossing in tref.crossings:
        i = crossing.index
        if i in dummy_bv:
Esempio n. 12
0
def odd_point_star(k, permutation=[]):
    # This function creates a simple odd pointed star diagram in the same
    # fashion as the Petaluma model.
    # odd_point_star(number of sticks , permutation) yields a Planar Diagram object.
    if permutation == []:
        permutation = numpy.random.permutation(k)
    SS = []
    p = permutation
    for e in range(k):
        for e1 in range(k):
            if (permutation[e] == permutation[e1]) and (e != e1):
                print 'This is not a correct permutation'
                return 'error'
    if len(p) != k:
        print 'This is not a correct permutation'
        return 'error'
    for m in range(k):
        for i in range((k - 3) / 2):
            SS.append((m + (k - 2 * i - 3)) % k)
        for i in range((k - 3) / 2):
            SS.append((m + (k - 2 * i - 2)) % k)
            Stick_crossing_order = {}
        for m in range(k):
            Stick_crossing_order[m] = SS[(((k - 3) * m)):((k - 3) * (m + 1))]
    ES = []
    for y in range(k):
        for x in range(k - 2):
            ES.append((x + (k - 3) * y) % (k * (k - 3)))
    edges_stick = {}
    for z in range(k):
        edges_stick[z] = ES[(z * (k - 2)):(z * (k - 2) + (k - 2))]

    nv = (((k * k) - (3 * k)) / 2)
    count = -1
    total = {}
    crossing_values = []
    for stick in range(k):
        for position in range(k - 3):
            x = Stick_crossing_order[Stick_crossing_order[stick]
                                     [position]].index(stick)
            if x < (k - 3) / 2:
                edge_and_next = [
                    edges_stick[Stick_crossing_order[stick][position]][x],
                    edges_stick[Stick_crossing_order[stick][position]][x + 1]
                ]
            if x >= (k - 3) / 2:
                edge_and_next = [
                    edges_stick[Stick_crossing_order[stick][position]][x + 1],
                    edges_stick[Stick_crossing_order[stick][position]][x]
                ]

            if stick < Stick_crossing_order[stick][position]:
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip1')
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip2')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip3')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip4')

            if stick > Stick_crossing_order[stick][position]:
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip5')
                if ((stick % 2) == 0) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip6')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 0):
                    if p[stick] < Stick_crossing_order[stick][position]:
                        edge_and_next.append(True)
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip7')
                if ((stick % 2) == 1) and (
                    (Stick_crossing_order[stick][position] % 2) == 1):
                    if p[stick] > p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(True)
                    if p[stick] < p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append(False)
                    if p[stick] == p[Stick_crossing_order[stick][position]]:
                        edge_and_next.append('skip8')

            if stick == Stick_crossing_order[stick][position]:
                edge_and_next.append('skip9')
            if len(edge_and_next) != 3:
                edge_and_next.append('skip10')
            count += 1
            total[count] = edge_and_next
    temp_vert = []
    verts = []
    for x in range(2 * nv):
        verts.append([
            x % (2 * nv), (total[x][0]) % (2 * nv), (x + 1) % (2 * nv),
            (total[x][1]) % (2 * nv), total[x][2]
        ])

    for z in range(2 * nv):
        if verts[z][4] == True:
            verts[z][4] = 1
        if verts[z][4] == False:
            verts[z][4] = 0
        if verts[z][4] == 'skip':
            print 'skipped'
            del (verts[z])
            verts.insert(z, [0, 0, 0, 0])
    for t in range(8 * nv):
        if (verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][1]) and (
                verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][2] and
            (verts[t % (2 * nv)][0] <= verts[t % (2 * nv)][3])):
            continue
        if (verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][1]) or (
                verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][2] or
            (verts[t % (2 * nv)][0] >= verts[t % (2 * nv)][3])):
            temp_vert = [
                verts[t % (2 * nv)][1], verts[t % (2 * nv)][2],
                verts[t % (2 * nv)][3], verts[t % (2 * nv)][0],
                verts[t % (2 * nv)][4]
            ]
            verts[t % (2 * nv)] = [
                temp_vert[0], temp_vert[1], temp_vert[2], temp_vert[3],
                temp_vert[4]
            ]
    ne = 2 * nv
    for clean_up in range(ne):
        for search in range(ne):
            if (([
                    verts[clean_up][0], verts[clean_up][1], verts[clean_up][2],
                    verts[clean_up][3]
            ] == [
                    verts[search][0], verts[search][1], verts[search][2],
                    verts[search][3]
            ]) and (clean_up != search)) and ([
                    verts[clean_up][0], verts[clean_up][1], verts[clean_up][2],
                    verts[clean_up][3]
            ] != [0, 0, 0, 0]):
                del (verts[search])
                verts.insert(search, [0, 0, 0, 0])
    count = 0
    for clean_up_2 in range(ne * ne):
        if verts[clean_up_2 % ne] == [0, 0, 0, 0]:
            del (verts[clean_up_2 % ne])
            verts.append([])
            count = 0
        count += 1
        if count >= (ne + 1):
            break
    del (verts[nv:ne])
    for r in range(nv):
        if verts[r][0] == 0 and r != 0:
            temp = verts[r]
            del (verts[r])
            verts.insert(0, temp)
    knot = PlanarDiagram.from_pdcode(verts)
    for v in range(nv):
        knot.crossings[v].sign = verts[v][4]
    return knot
Esempio n. 13
0
    #     M[k] = v
    # print M

    # plt.figure()
    # plt.gca().set_aspect('equal')
    # plt.triplot(xy[:,0], xy[:,1], triangles, 'go-')
    # plt.show()

#    import sys
#    sys.exit(0)

#tref = PlanarDiagram.torus_knot(2,3)
#tref = PlanarDiagram.unknot(1)
#with open("6a5and6n1.kt") as f:
#    tref = PlanarDiagram.read_knot_theory(f)
    tref = PlanarDiagram.db_link(6, 2, True)
    mesh, real_edges = pdcode_to_mesh(tref)
    #print mesh.verts
    #print mesh.edges
    #print mesh.faces
    print mesh.chi()

    cpm = ThurstonCPMetric.from_triangle_mesh(mesh)
    print cpm.gb_chi()
    #print cpm.newton().gb_chi()

    dummy_bv = list(mesh.b_verts)
    real_bv = []
    for crossing in tref.crossings:
        i = crossing.index
        if i in dummy_bv:
Esempio n. 14
0
    j = a
	fil1 = open(name)
	
	num = 1


	all_links = []
	#fil = open("/media/alexander/HollisExt30/link_data/data/" + str(a) + "/"+ str(a)+"_links.pdstor","a")
    fil = open("/media/hollis/HollisExtTB/link_data/data/" + str(a) + "/"+ str(a)+"_links.pdstor","a")

	count = 0

	print "Starting"
	while num:
		try:
			a = PlanarDiagram.read(fil1)
			num_cross = a.ncross
			nums = 2**num_cross
			typ = "{0:0" + str(num_cross) + "b}"
			cross_types = []
			for b in range(nums):
				cross_types.append(typ.format(b))
			for c in range(len(cross_types)):
				for d in range(num_cross):
					a.crossings[d].sign = int(cross_types[c][d])
				a.write(fil)
			count += 1
			if count%1000 == 0:
				print "finished " + str(count)
		except EOFError:
			num = 0
Esempio n. 15
0
def complex_star(number_of_sticks, *args):

    # First I want to create the equations of each line of the shadows.
    sticks = {
    }  # Creating a dictionary to keep track of which stick goes with which equation.
    k = number_of_sticks
    n = (k - 1) / 2
    permutation_1 = []
    permutation_2 = []
    mapping = []
    if 'args' in locals():
        for ar in range(len(args)):
            if type(args[ar]) == list and permutation_1 == [] and len(
                    args[ar]) == k:
                permutation_1 = args[ar]
            elif type(args[ar]) == list and permutation_1 != [] and len(
                    args[ar]) == k:
                permutation_2 = args[ar]
            elif type(args[ar]) == list:
                print "Incorrect Permutations"
            else:
                mapping = int(args[ar])
    if mapping == []:
        mapping = n
    else:
        mapping = int(mapping)
    if permutation_1 == []:
        permutation_1 = numpy.random.permutation(k)
    if permutation_2 == []:
        permutation_2 = numpy.random.permutation(k)
    delt_ang = (2 * pi) / k
    # Creates the change in angle to find the points.
    x_1 = {}
    x_2 = {}
    y_1 = {}
    y_2 = {}
    z_1 = {}
    z_2 = {}
    m = {}
    delt_x = {}
    delt_y = {}
    delt_z = {}
    circ_points = {}
    for p in range(k):
        x_1[p] = 10000 * cos(((mapping * p) % k) * delt_ang)
        x_2[p] = 10000 * cos(((mapping * p + mapping) % k) * delt_ang)
        y_1[p] = 10000 * sin(((mapping * p) % k) * delt_ang)
        y_2[p] = 10000 * sin(((mapping * p + mapping) % k) * delt_ang)
        z_1[p] = permutation_1[p]
        z_2[p] = permutation_2[p]
        delt_x[p] = x_2[p] - x_1[p]
        delt_y[p] = y_2[p] - y_1[p]
        delt_z[p] = z_2[p] - z_1[p]
        m[p] = (y_2[p] - y_1[p]) / (x_2[p] - x_1[p])
        circ_points[p] = [
            10000 * cos(p * delt_ang), 100000 * sin(p * delt_ang)
        ]

    def find_int_xy(
        a, b, m, x_1, y_1, circ_points, k
    ):  #To find the intersection between two sticks a and b *add in stick numbering errors and gives the
        if m[a] == m[b]:
            print 'AHHH', a, b
        x = (m[a] * x_1[a] - m[b] * x_1[b] + y_1[b] - y_1[a]) / (m[a] - m[b])
        y = m[a] * (x - x_1[a]) + y_1[a]
        point = [x, y]
        return point

    stick_pairs_heights = {}
    vertex_positions = {}
    t_value_y = {}
    heights_for_inter = {}
    t_values = {}
    stick_ints = {}
    for pair in range(k):
        for pair2 in range(
                k - 3
        ):  #this would be a nice place to order the intersections in the correct order...
            #The mapping MUST come into play here as well, solution is to find the intersection of EACH combination.
            vertex_positions[str(pair) + ',' + str(
                (pair + pair2 + 2) % k
            )] = find_int_xy(
                pair,
                (pair + pair2 + 2) %
                k, m, x_1, y_1, circ_points,
                k
            )  #the order        t_value_x[str(pair)+','+str((pair + pair2 + 2)%k)] = (vertex_positions[str(pair)+','+str((pair + pair2 + 2)%k)][0]-x_1[pair])/(x_2[pair]-x_1[pair])
            t_value_y[str(pair) + ',' + str(
                (pair + pair2 + 2) %
                k)] = (vertex_positions[str(pair) + ',' + str(
                    (pair + pair2 + 2) % k)][1] - y_1[pair]) / (y_2[pair] -
                                                                y_1[pair])
            t_value_x = t_value_y
            # Note: the t value for each stick "Should" be consistent regardless of x,y, or z..
        t_values[pair] = []
        for pair2 in range(k - 3):
            t_values[pair].append((t_value_x[str(pair) + ',' + str(
                (pair + pair2 + 2) % k)], (pair + pair2 + 2) % k))
            stick_pairs_heights[str(pair) + ',' + str(
                (pair + pair2 + 2) % k)] = (z_1[pair] +
                                            t_value_x[str(pair) + ',' + str(
                                                (pair + pair2 + 2) % k)] *
                                            (delt_z[pair]),
                                            z_1[(pair + pair2 + 2) % k] +
                                            t_value_x[str(pair) + ',' + str(
                                                (pair + pair2 + 2) % k)] *
                                            (delt_z[(pair + pair2 + 2) % k]))
        t_values[pair].sort()
        stick_ints[pair] = []
        for stick in range(len(t_values[pair])):
            stick_ints[pair].append(t_values[pair][stick][1])
    #Now to create the edge information for each stick..
    edges_per_stick = []
    ne = k * k - 3 * k
    for stick in range(k):
        temp = []
        for edge in range(k - 2):
            temp.append((stick * (k - 3) + edge) % ne)
        edges_per_stick.append(temp)
    #Now that we have all of the information needed let's create the vertices!
    vertices = []
    count = 0
    for stick in range(k):
        for position in range(k - 3):
            if ((stick_ints[stick][position] % 2 == 0 and stick % 2 == 0) or
                (stick % 2 == 1 and stick_ints[stick][position] % 2 == 1)):
                x = 1
                y = 0
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] < stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 1
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] > stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 0
            if (stick_ints[stick][position] % 2 == 0 and stick % 2 == 1) or (
                    stick % 2 == 0 and stick_ints[stick][position] % 2 == 1):
                x = 0
                y = 1
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] < stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 0
                if stick_pairs_heights[str(stick) + ',' + str(
                        stick_ints[stick][position])][0] > stick_pairs_heights[
                            str(stick) + ',' +
                            str(stick_ints[stick][position])][1]:
                    v = 1
            vertices.append([
                edges_per_stick[stick][position],
                edges_per_stick[t_values[stick][position][1]][
                    stick_ints[t_values[stick][position][1]].index(stick) + x],
                edges_per_stick[stick][position + 1],
                edges_per_stick[t_values[stick][position][1]]
                [stick_ints[t_values[stick][position][1]].index(stick) + y], v
            ])
    final_verts = []
    for cutting in range((k * (k - 3)) / 2):
        final_verts.append(vertices[cutting])
    while final_verts[(k * (k - 3)) / 2 - 1][0] != 0:
        final_verts[(k * (k - 3)) / 2 - 1] = [
            final_verts[(k * (k - 3)) / 2 - 1][1],
            final_verts[(k * (k - 3)) / 2 - 1][2],
            final_verts[(k * (k - 3)) / 2 - 1][3],
            final_verts[(k * (k - 3)) / 2 - 1][0],
            final_verts[(k * (k - 3)) / 2 - 1][4]
        ]
    final_verts.insert(0, final_verts[(k * (k - 3)) / 2 - 1])
    final_verts.pop((k * (k - 3)) / 2)
    knot = PlanarDiagram.from_pdcode(final_verts)
    return knot
Esempio n. 16
0
def link_reduce(homfly):
    z = open(path + "homfly_storage/" + homfly)
    split_file = open(
        path + "reduced_homfly_storage" + "/splittable_" + homfly, 'a')
    unsplit_file = open(
        path + "reduced_homfly_storage" + "/unsplittable_" + homfly, 'a')
    count = 0
    knots = []
    while True:
        count += 1
        if count % 10000 == 0:
            print(count)
        try:
            knot = PlanarDiagram.read(z)
            linking_num = []
            is_written = 0

            for comp1 in range(knot.ncomps):
                for comp2 in range(knot.ncomps):
                    ln = knot.linking_number(comp1, comp2)
                    if comp1 != comp2:
                        linking_num.append(ln)
            if linking_num.count(0) == 0:
                num_isotopies = 0

                if len(knots) == 0:
                    knots.append(knot)
                    continue
                for a in knots:
                    if a.isotopic(knot):
                        num_isotopies += 1
                        break

                if num_isotopies == 0:
                    knots.append(knot)
                    #                    knots.write(unsplit_file)
                    is_written = 1

            if linking_num.count(0) != 0:
                if len(knot.simplify()) == 1:
                    num_isotopies = 0

                    if len(knots) == 0:
                        knots.append(knot)
                        continue

                    for a in knots:
                        if a.isotopic(knot):
                            num_isotopies += 1
                            break

                    if num_isotopies == 0:
                        knots.append(knot)
                        #                        knots.write(unsplit_file)
                        is_written = 1

            if (not is_written):
                knot.write(split_file)

        except:
            break
    knots.write(unsplit_file)
    #    print "Number of knots :", len(knots)
    #    reduced = isotopic_reduce2(knots)
    split_file.close()
    unsplit_file.close()