Exemplo n.º 1
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
Exemplo n.º 2
0
def counter(file_name):
    fil = open(file_name)
    count = 0
    while 1:
        a = PlanarDiagram.read(fil)
        count += 1
        print count
Exemplo n.º 3
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 
Exemplo 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()
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
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 : "
Exemplo n.º 9
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
Exemplo n.º 10
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()