Example #1
0
    def __init__(self, master):
        print("room_gen_gui_002.py")
        print("\nGUI FUNCTION: __init__")
        self.builder = Builder()
        frame = Frame(master)
        frame.pack()

        Label(frame, text='MINECRAFT ROOM GENERATOR').grid(row=0, columnspan=3)

        Button(frame, text='SET CORNER',
               command=self.btn_findgold).grid(row=1, column=1)
        Label(frame, text='Blocks x').grid(row=2, column=0)
        self.x_var = IntVar()
        Entry(frame, textvariable=self.x_var).grid(row=2, column=1)
        Label(frame, text='Blocks y').grid(row=3, column=0)
        self.y_var = IntVar()
        Entry(frame, textvariable=self.y_var).grid(row=3, column=1)
        Label(frame, text='Blocks z').grid(row=4, column=0)
        self.z_var = IntVar()
        Entry(frame, textvariable=self.z_var).grid(row=4, column=1)

        Button(frame, text='LIST', command=self.btn_list).grid(row=5, column=0)

        Button(frame, text='BUILD', command=self.btn_build).grid(row=5,
                                                                 column=1)

        Button(frame, text='QUIT', command=exit).grid(row=5, column=2)

        self.reset_interface()
Example #2
0
def generate(toBuild, automata, paint):
    postfixer = Postfixer()
    if (toBuild == "AFD"):
        inFixRegEx = "(" + automata + ")"
        inFixRegEx += ".#"
        inFixRegEx = postfixer.to_postfix(inFixRegEx)
        builder = Builder(inFixRegEx)
    else:
        postfixRegex = postfixer.to_postfix(automata)
        builder = Builder(postfixRegex)
    #paso de generar tokens
    builder.generator()
    #array de tokens devuelto por
    tokens = builder.getTokenArr()
    parser = Parser()

    return parser.parse(tokens, toBuild, paint)
Example #3
0
 def SetBuilderByName(self, bder, name):
     if isinstance(bder, dict):
         bder = Builder(bder)
     dstIdx = -1
     for idx, elm in enumerate(self.builders):
         if elm["name"] == name:
             dstIdx = idx
             break
     if dstIdx != -1:
         self.builders[dstIdx] = bder.ToDict()
Example #4
0
    def __init__(self):
        self.builder = Builder.Builder()
        self.player = None
        self.areaList = list()
        self.turnCount = 0
        self.introText = ""
        self.backgroundMusic = None
        self.returnOnEnter = False

        self.builder.loadState(self)
Example #5
0
def startup():
    rospy.init_node('pr2_block_builder')

    # Register the services being provided
    rospy.Service('pr2_block_builder/Start', Start, start)
    rospy.Service('pr2_block_builder/Stop', Stop, stop)
    rospy.Service('pr2_block_builder/Restart', Restart, restart)

    # Create the builder
    global builder
    builder = Builder()
Example #6
0
def single(regex, hashType):
    postfixer = Postfixer()
    postfixRegex = postfixer.to_postfix(f"({regex}).#")
    builder = Builder(postfixRegex)
    #paso de generar tokens
    builder.generator()
    #array de tokens devuelto por
    tokens = builder.getTokenArr()
    print("Tokens -> Regex:", tokens)
    parser = Parser()
    return parser.parse(tokens, "AFD", False, hashType)
Example #7
0
def main():
    """
builds a new set of coords from three atoms in a pdbfile and a given distance, angle and torsion
	"""

    parser = OptionParser()
    parser.add_option("-p", dest="pdbfile", help="pdbfile")
    parser.add_option("-i",
                      dest="indices",
                      help="atom indices (comma delimited)")
    parser.add_option("-v",
                      dest="values",
                      help="dist,ang,tor (comma delimited)")
    parser.set_description(main.__doc__)
    (options, args) = parser.parse_args()

    if not options.pdbfile:
        parser.print_help()
        sys.exit()

    if not options.indices or not options.values:
        parser.print_help()
        sys.exit()

    indices = options.indices.split(",")
    if len(indices) != 3:
        print "must supply 3 indices separated by a comma"
        sys.exit()

    values = options.values.split(",")
    if len(values) != 3:
        print "must supply 3 values separated by a comma"
        sys.exit()

    protein = Molecule()
    protein.readPDB(options.pdbfile)

    A = protein.getAtom(int(indices[0]))
    B = protein.getAtom(int(indices[1]))
    C = protein.getAtom(int(indices[2]))

    if A == None or B == None or C == None:
        print "cannot find all 3 atoms"
        sys.exit()

    length = float(values[0])
    ang = float(values[1])
    tor = float(values[2])

    billder = Builder()
    crd = billder.dbuildAtom(A, B, C, length, ang, tor)
    print '%8.3f%8.3f%8.3f' % (crd[0], crd[1], crd[2])
Example #8
0
def test():
    postfixer = Postfixer()
    postfixRegex = postfixer.to_postfix(
        f'(((+)δ(-))γ"0γ1γ2γ3γ4γ5γ6γ7γ8γ9")("0γ1γ2γ3γ4γ5γ6γ7γ8γ9")αδ{BuilderEnum.HASH.value}'
    )
    builder = Builder(postfixRegex)
    #paso de generar tokens
    builder.generator()
    #array de tokens devuelto por
    tokens = builder.getTokenArr()
    print("Tokens -> Regex:", tokens)
    parser = Parser()
    return parser.parse(tokens, "AFD", True)
Example #9
0
def main():
    """
builds new atoms onto existing pdbfiles.  EXPERIMENTAL AND UNTESTED
	"""

    parser = OptionParser()
    parser.add_option("-p", dest="pdbfile", help="pdbfile")
    parser.add_option("-o", dest="outfile", help="outfile")
    parser.add_option("--dist", dest="distance", help="distance")
    parser.add_option("--ang", dest="angle", help="angle")
    parser.add_option("--tor", dest="torsion", help="torsion")
    parser.add_option("-s", "--selection", dest="selection", help="selection")
    parser.add_option("-b", "--build", dest="build", help="build")
    parser.set_description(main.__doc__)
    (options, args) = parser.parse_args()

    if not options.pdbfile or not options.selection:
        parser.print_help()
        sys.exit()

    if not options.outfile:
        parser.print_help()
        sys.exit()

    mol = Molecule()
    mol.readPDB(options.pdbfile)

    selector = Selection()
    selector.makeSelection(options.selection)
    mysel = selector.apply_selection(mol)

    builder = Builder()

    atomlist = mysel.atomList()
    if len(atomlist) != 3:
        print "must select three atoms. ", len(atomlist)

    newatom = Atom()
    newatom.name = "new"
    dist = float(options.distance)
    ang = float(options.angle)
    tor = float(options.torsion)
    builder.buildAtom(newatom, atomlist[0], atomlist[1], atomlist[2], dist,
                      ang, tor)

    mol.chain[0].residue[0].addAtom(newatom)
    mol.writePDB(options.outfile)
Example #10
0
    def run(self, inState):
        inState.mBuilder = Builder.Builder(inState.getView())

        hierarchy = Trees.getMeshHierarchy(inState.getView().getOutputNode())
        hierarchy = hierarchy.filterByShape(['mesh'])
        if hierarchy is None:
            raise Exception(
                'Filtered hierarchy contains no valid mesh elements!')

        hierarchy.mDataBuilder = None

        # The pivot root isn't always going to be the primary root of the object, so ensure it's invalidated
        if len(hierarchy.mChildren) <= 1:
            hierarchy.mChildren[0].iterate(
                inState.getBuilder().fillHierarchyInfo)
        else:
            hierarchy.iterate(inState.getBuilder().fillHierarchyInfo)

        inState.mCachedHierarchy = hierarchy
Example #11
0
def changeDihedral(A=None, B=None, C=None, D=None, tor=0.0):
	
	"""
	changes the position of an atom (A) by changing the torsion angle
	uses the previous distance and angle	
	(angles should be in degrees)
	"""

	if A == None or B == None or C == None or D == None:
		return	

	dist = A.distance(B)
	ang  = vector3d.angle3(A.coord,B.coord,C.coord)

	billder = Builder()
	crd = billder.dbuildAtom(B,C,D, dist, ang, tor)

	A.coord.x = crd[0]
	A.coord.y = crd[1]
	A.coord.z = crd[2]
Example #12
0
def whole_regex(arrRegex, dictionary, draw):
    main_tree = ""
    for regex in arrRegex:
        main_tree += "(" + regex + ")" + f"{BuilderEnum.CONCAT.value}{BuilderEnum.HASH.value}" + f"{BuilderEnum.OR.value}"
    #delete last or..
    main_tree = main_tree[0:-1]
    print("Main tree is: ", main_tree)
    postfixer = Postfixer()
    postfixRegex = postfixer.to_postfix(main_tree)
    builder = Builder(postfixRegex, dictionary=dictionary)
    #paso de generar tokens
    builder.generator()
    #array de tokens devuelto por
    tokens = builder.getTokenArr()
    print("Tokens -> Regex:", tokens)
    parser = Parser()
    if draw:
        return parser.parse(tokens, "AFD", True)
    else:
        return parser.parse(tokens, "AFD", False)
Example #13
0
    def populate(self):
        """adds all the people and make sure they don't go all ape shit
        """
        FARMER_COUNT = 4
        VILLAGER_COUNT = 5
        BUILDER_COUNT = 1

        lumber1 = Building.LumberYard(self, self.lumberyard_img)
        lumber1.location = vector2.Vector2(self.w / 2, self.h / 2)
        lumber1.tile_x, lumber1.tile_y = 4, 4
        self.add_entity(lumber1)

        for Villager_no in xrange(VILLAGER_COUNT):
            """Adds all Wood Cutters
            """
            villager = Lumberjack.Lumberjack(self, self.lumberjack_img)
            villager.location = lumber1.location.copy()
            villager.LastLumberYard = lumber1
            villager.brain.set_state("Searching")
            self.add_entity(villager)
            self.population += 1

        for Building_no in xrange(BUILDER_COUNT):
            builder = Builder.Builder(self, self.builder_img, lumber1)
            builder.location = lumber1.location.copy()
            builder.brain.set_state("Idle")
            self.add_entity(builder)
            self.population += 1

        for FARMER in xrange(FARMER_COUNT):
            """Adds all the farmers
            """
            farmer = Farmer.Farmer(self, self.farmer_img)
            farmer.location = vector2.Vector2(20, 20)
            farmer.brain.set_state("Planting")
            self.add_entity(farmer)
            self.population += 1
Example #14
0
def switchHisTautomer(his=None):
	
	"""
	switches the histidine tautomer by changing the HNE to a HND or vice versa
	takes in a residue object
	"""

	if his.name != "HIS":
		return

	billder = Builder()
	# --- check to see if it's an HID or HIE --- #
	if his.atomExists(" HE2"):
		H = his.getAtom(" HE2")
		A = his.getAtom(" ND1")
		B = his.getAtom(" CG ")
		C = his.getAtom(" CD2")
		name = " HD1"
	elif his.atomExists(" HD1"):
		H = his.getAtom(" HD1")
		A = his.getAtom(" NE2")
		B = his.getAtom(" CD2")
		C = his.getAtom(" CG ")
		name = " HE2"
	else:
		return

	if H == None or A == None or B == None or C == None:
		print "cannot find base atoms for switching tautomer"
		return

	crd = billder.dbuildAtom(A, B, C, 1.01, 126, 180)
	H.coord.x = crd[0]
	H.coord.y = crd[1]
	H.coord.z = crd[2]
	H.name = name
    return net

def improve_weights(net,learning_rate,size):
    net.weight_layers = [w-(learning_rate/size)*nw
                        for w, nw in zip(net.weight_layers, net.weight_errors)]
    return net

def cost_funcion(prediction, answer):
    return (1/2)(answer-prediction)**2

def derivative_cost(prediction, answer):
    return (prediction-answer)
    
if __name__ == "__main__":
    layers = [3,3,3]
    builder = Builder(layers)
    net = builder.generate_net()

    num = 300
    size = 100
    
    for i in range(num):
        for j in range(size):
            lst = [0,0,0]
            lst[0] = random.randint(0,1)
            lst[1] = random.randint(0,1)
            lst[2] = random.randint(0,1)
            net.set_inputs(lst)
            net = propagate(net)
            net = output_error(net,np.array(lst))
            net = hidden_error(net)
Example #16
0
 def GetBuilderByName(self, name):
     '''返回的是基类实例'''
     for i in self.builders:
         if i["name"] == name:
             return Builder.Builder(i)
     return None
Example #17
0
def main():
    """
solvates a histidine
	"""

    parser = OptionParser()
    parser.add_option("-p", dest="pdbfile", help="pdbfile")
    parser.add_option("-P", dest="pdblist", help="pdblist")
    parser.add_option("-o", dest="outfile", help="outfile")
    parser.add_option("-O", dest="outlist", help="outlist")
    parser.add_option("-r",
                      dest="replace",
                      help="replace",
                      action="store_true")
    parser.add_option("-c", dest="catalytic", help="catalytic")
    parser.set_description(main.__doc__)
    (options, args) = parser.parse_args()

    pdbfiles = []
    if options.pdblist:
        pdbfiles = files_from_list(options.pdblist)
    elif options.pdbfile:
        pdbfiles.append(options.pdbfile)
    else:
        parser.print_help()
        sys.exit()

    outfiles = []
    if options.outlist:
        outfiles = files_from_list(options.outlist)
    elif options.outfile:
        outfiles.append(options.outfile)
    elif options.replace:
        for file in pdbfiles:
            outfiles.append(file)
    else:
        parser.print_help()
        sys.exit()

    if len(outfiles) != len(pdbfiles):
        print "number of input and output files differ"
        sys.exit()

    if not options.catalytic:
        parser.print_help()
        sys.exit()

    icat = int(options.catalytic) - 1
    protein = Enzyme()
    for i in range(len(pdbfiles)):
        protein.readPDB(pdbfiles[i])
        if icat < 0 or icat >= len(protein.catalytic):
            print "accessing catalytic residue out of bounds"
            sys.exit()

        cat = protein.catalytic[icat]
        if cat.name != "HIS":
            print "catalytic residue is not a histidine"
            sys.exit()

        # check protonation state
        if cat.getAtom(" HD1") != None:
            A = cat.getAtom(" NE2")
            B = cat.getAtom(" CD2")
            C = cat.getAtom(" CG ")
        elif cat.getAtom(" HE2") != None:
            A = cat.getAtom(" ND1")
            B = cat.getAtom(" CE1")
            C = cat.getAtom(" NE2")
        else:
            print "unable to determine protonation state"
            sys.exit()

        if A == None or B == None or C == None:
            print "cannot find all 3 atoms"
            sys.exit()

        length = 2.98
        ang = 125.0
        tor = 180.0

        billder = Builder()
        crd = billder.dbuildAtom(A, B, C, length, ang, tor)
        newres = protein.chain[1].newResidue()
        newres.name = "LG2"

        newatm = newres.newAtom()
        newatm.coord.x = crd[0]
        newatm.coord.y = crd[1]
        newatm.coord.z = crd[2]
        newatm.name = "HOH "
        newatm.kind = "HETATM"

        protein.writePDB(outfiles[i])
        protein.clear()