Exemplo n.º 1
0
def quest_4_3(acc, protLength):
    # Define protein
    protein = prot.Protein(protLength)

    # x and y-values to plot (temperature and avg. proteinlength)
    temp = np.linspace(1500, 1e-12, acc)
    Lvalues = np.zeros(len(temp))

    for i in range(len(temp)):
        # perform 600 twists at every temperature, record avg-energy at every temp
        T = temp[i]
        lengths = np.zeros(numTwists)
        for j in range(numTwists):
            # Twisting
            protein = prot.randomTwist(protein, T)
            # record max-diameter in current micro-state
            lengths[j] = protein.D
        # Add average max-diameter in this temperature to plotting-vector
        Lvalues[i] = np.average(lengths)
        # Print current state:
        print("Iter: ", i + 1, "/", acc, "\tTemp: ", T)

    plt.plot(temp,
             Lvalues,
             lw=0.6,
             label=r"%s monomers" % protein.n,
             color="crimson")
    plt.xlabel(r"$T$  [K]", size=20)
    plt.xlim(1500, 0)
    plt.ylabel(r"$\langle L \rangle$  [1]", size=20)
    plt.legend(loc="best")
    plt.grid()
    plt.show()
Exemplo n.º 2
0
def quest_2_1(acc):
	# Parameters for protein of length 15
	dmax = 10000
	s = 0.001

	# x-axis of plot
	Tvalues = np.linspace(Trange[0], Trange[1], acc)
	# y-axis of plot
	Evalues = np.zeros(acc)

	for i in range(acc):
		# Find number of twists necessary
		D = int(dmax * np.exp(-s * Tvalues[i]))
		# Define a new protein for each temperature
		P = prot.Protein(15)

		energies = np.zeros(D)
		print("\n\nTemperature:", Tvalues[i], "|| # Twists:", D, "|| Iter:", i + 1, "of", acc, "\n\n")

		for j in range(D):
			# Perform a single twist with energy and thermal fluctuation conserns
			P = prot.randomTwist(P, Tvalues[i])
			# Add energy to list
			energies[j] = P.E
		# Find the average given the temperature
		Evalues[i] = np.average(energies)

	# Plot
	plt.plot(Tvalues, Evalues, lw=3, label=r"15 monomers", color="crimson")
	plt.xlabel(r"$T$  [K]", size=20)
	plt.ylabel(r"$\langle E \rangle$  [J]", size=20)
	plt.legend(loc="best")
	plt.grid()
	plt.show()
Exemplo n.º 3
0
def quest_4_2(acc, protLength):
    #Define protein
    protein = prot.Protein(protLength)

    #x and y-values to plot (temperature and avg. energy)
    temp = np.linspace(1500, 1e-12, acc)
    Evalues = np.zeros(len(temp))

    for i in range(len(temp)):
        #perform 600 twists at every temperature, record avg-energy at every temp
        T = temp[i]
        energy = np.zeros(numTwists)
        for j in range(numTwists):
            #Twisting
            protein = prot.randomTwist(protein, T)
            #record energy in current micro-state
            energy[j] = protein.E
        #Add average energy in this temperature to plotting-vector
        Evalues[i] = np.average(energy)
        #Print current state:
        print("Iter: ", i + 1, "/", acc, "\tTemp: ", T)

    plt.plot(temp, Evalues, lw=0.5, label=r"15 monomers", color="crimson")
    plt.xlabel(r"$T$  [K]", size=20)
    plt.xlim(1500, 0)
    plt.ylabel(r"$\langle E \rangle$  [J]", size=20)
    plt.legend(loc="best")
    plt.grid()
    plt.show()
Exemplo n.º 4
0
def quest_2_2(acc):
	# x-axis of plot
	twistValues = np.linspace(0, 5000, acc)
	# y-axis of plot
	Evalues = np.zeros(acc)

	dist = int(twistValues[1] - twistValues[0])


	### T = 0 ###


	# Define a protein
	P = prot.Protein(15)

	for i in range(acc):
		for j in range(dist):
			P = prot.randomTwist(P, 10e-12)  # Cannot make temperature == 0 because of 0 division error
		Evalues[i] = P.E

		print("Iter: ", i+1, "/", acc)

	# Plot
	plt.plot(twistValues, Evalues, lw=3, label=r"$T$ = 0K", color="crimson")
	plt.xlabel(r"\textbf{Twists}", size=20)
	plt.ylabel(r"$E$  [J]", size=20)
	plt.legend(loc="best")
	plt.grid()
	plt.show()


	### T = 500 ###


	# Define another protein
	P = prot.Protein(15)

	for i in range(acc):
		for j in range(dist):
			P = prot.randomTwist(P, 500)
		Evalues[i] = P.E

		print("Iter: ", i+1, "/", acc)

	# Plot
	plt.plot(twistValues, Evalues, lw=3, label=r"$T$ = 500K", color="crimson")
	plt.xlabel(r"\textbf{Twists}", size=20)
	plt.ylabel(r"$E$  [J]", size=20)
	plt.legend(loc="best")
	plt.grid()
	plt.show()
Exemplo n.º 5
0
def main():
    fs = glob(cfg['protdir'] + '/*.txt')
    steps = getsteps(cfg)

    for step in steps:
        outfile = os.path.join(cfg['outdir'], 'step{}'.format(step),
                               'rotations.pkl')
        if os.path.exists(outfile):
            print('{} already exists.'.format(outfile))
            continue
        of = os.path.join(cfg['optsdir'], 'step{}_opts'.format(step))
        opt = Option.Option(of)
        patrot = {}
        for f in fs:
            protid = os.path.splitext(os.path.basename(f))[0]
            tertf = os.path.join(cfg['tertdir'], protid + '.txt')
            if not os.path.exists(tertf):
                # Corresponding tertiary file may not be present...
                tertf = None
            prot = Protein.Protein(protid)
            prot.fromfiles(f, tertf)
            for bond in prot.hbonds:
                pat = str(prot.findpattern2(bond, opt))
                if pat in patrot:
                    patrot[pat].append(tuple(bond.rotation))
                else:
                    patrot[pat] = [tuple(bond.rotation)]
            del prot

        with open(outfile, 'wb') as o:
            cPickle.dump(patrot, o, protocol=-1)
Exemplo n.º 6
0
    def test_buildSVMProteinVector(self):
        """ Tests the buildProteinVector function """
        
        name = 'TestProtein'
        primaryStructure = ['ALA', 'ARG', 'ASN', 'ASP', 'CYS', 'GLU', 'GLN', 'GLY', 'HIS', 'ILE', 'LEU', 'LYS', 'MET', 'PHE', 'PRO', 'SER', 'THR', 'TRP', 'TYR', 'VAL', 'ALA', 'ARG']
        secondaryStructure = ['N', 'N', 'N', 'N', 'N', 'N', 'H', 'H', 'H', 'H', 'H', 'H', 'H', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S', 'S']
        protein = Protein.Protein(name, 'hydrolase',primaryStructure, secondaryStructure)

        codification = Codification.Codification()
        actual_str_nohash1 = codification.buildSVMProteinVector(protein, 0, 'PS', 44)
        actual_str_nohash2 = codification.buildSVMProteinVector(protein, 0, 'SP', 44)
        actual_str_nohash3 = codification.buildSVMProteinVector(protein, 0, 'PS', 88)
    
        actual_str_hash1 = codification.buildSVMProteinVector(protein, 2, 'PS', 44)
        actual_str_hash2 = codification.buildSVMProteinVector(protein, 3, 'PS', 44)


        self.assertEqual(actual_str_nohash1, '3 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 9:9.0 10:10.0 11:11.0 12:12.0 13:13.0 14:14.0 15:15.0 16:16.0 17:17.0 18:18.0 19:19.0 20:20.0 21:1.0 22:2.0 23:21.0 24:21.0 25:21.0 26:21.0 27:21.0 28:21.0 29:22.0 30:22.0 31:22.0 32:22.0 33:22.0 34:22.0 35:22.0 36:23.0 37:23.0 38:23.0 39:23.0 40:23.0 41:23.0 42:23.0 43:23.0 44:23.0')
    
        self.assertEqual(actual_str_nohash2, '3 1:21.0 2:21.0 3:21.0 4:21.0 5:21.0 6:21.0 7:22.0 8:22.0 9:22.0 10:22.0 11:22.0 12:22.0 13:22.0 14:23.0 15:23.0 16:23.0 17:23.0 18:23.0 19:23.0 20:23.0 21:23.0 22:23.0 23:1.0 24:2.0 25:3.0 26:4.0 27:5.0 28:6.0 29:7.0 30:8.0 31:9.0 32:10.0 33:11.0 34:12.0 35:13.0 36:14.0 37:15.0 38:16.0 39:17.0 40:18.0 41:19.0 42:20.0 43:1.0 44:2.0')
    
        self.assertEqual(actual_str_nohash3, '3 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 9:9.0 10:10.0 11:11.0 12:12.0 13:13.0 14:14.0 15:15.0 16:16.0 17:17.0 18:18.0 19:19.0 20:20.0 21:1.0 22:2.0 23:21.0 24:21.0 25:21.0 26:21.0 27:21.0 28:21.0 29:22.0 30:22.0 31:22.0 32:22.0 33:22.0 34:22.0 35:22.0 36:23.0 37:23.0 38:23.0 39:23.0 40:23.0 41:23.0 42:23.0 43:23.0 44:23.0 88:0.0')

        self.assertEqual(actual_str_hash1, '3 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 9:9.0 10:10.0 11:1.0 12:11.0 13:11.0 14:11.0 15:12.0 16:12.0 17:12.0 18:13.0 19:14.0 20:14.0 21:14.0 22:14.0')
        self.assertEqual(actual_str_hash2, '3 1:1.0 2:2.0 3:3.0 4:4.0 5:5.0 6:6.0 7:7.0 8:8.0 9:9.0 10:10.0 11:11.0 12:12.0 13:13.0 14:13.0 15:14.0')
Exemplo n.º 7
0
def main(pf, steps, od):
    pid = os.path.splitext(os.path.basename(pf))[0]
    if '-' in steps:
        s, e = steps.split('-')
        s = int(s)
        e = int(e)
    else:
        s = int(steps)
        e = s

    outfile = os.path.join(od, '{}.patrot'.format(pid))
    res = []

    for step in range(s, e + 1):
        of = os.path.join(cfg['optsdir'], 'step{}_opts'.format(step))
        opt = Option.Option(of)
        tertf = os.path.join(cfg['tertdir'], pid + '.txt')
        if not os.path.exists(tertf):
            # Corresponding tertiary file may not be present...
            tertf = None
        prot = Protein.Protein(pid)
        prot.fromfiles(pf, tertf)

        for bond in prot.hbonds:
            pat = str(prot.findpattern2(bond, opt))
            res.append('\t'.join(
                [str(step), pat, '{},{},{}:{}'.format(*bond.rotation)]))

        del prot

    with open(outfile, 'w') as fh:
        fh.write('\n'.join(res))
Exemplo n.º 8
0
 def set_list_of_proteins(self, file):
     with open(file, "r") as f:
         for line in f:
             protein_as_a_list = line.split("\t")
             domains_list = []
             for i in range(2, len(protein_as_a_list), 4):
                 domains_list.append(Domain(protein_as_a_list[i], protein_as_a_list[i + 1], protein_as_a_list[i+2],
                                            protein_as_a_list[i+3]))
             self.proteins.append(Protein(protein_as_a_list[0], protein_as_a_list[1], domains_list))
Exemplo n.º 9
0
    def createClass(self, classNumber, classSize):
        """ Create a protein list for testing """
        proteinList = []

        for index in range(0, classSize):
            name = 'pc' + classNumber + '-' + str(index)
            proteinList.append(Protein.Protein(name, '',[], []))

        return proteinList
Exemplo n.º 10
0
def generateProtein(pdb):
    identifier = pdb[1]['identifier']
    authors = pdb[1]['authors']
    experiment = pdb[1]['experiment']
    classification = pdb[1]['classification']
    deposition_date = pdb[1]['deposition_date']
    version = pdb[1]['version']
    title = pdb[1]['title']
    residues = getListResidue(pdb)
    return Protein(identifier, title, authors, version, deposition_date,
                   experiment, residues)
Exemplo n.º 11
0
def quest_4_4(acc, protLength, numbOfCoolDowns):
    #Do several cool-downs on a protein, and draw the protein

    # Define protein
    protein = prot.Protein(protLength)

    # Temperature-range
    temp = np.linspace(1500, 1e-12, acc)

    for k in range(numbOfCoolDowns):
        for i in range(len(temp)):
            # perform 600 twists at every temperature, record avg-energy at every temp
            T = temp[i]
            lengths = np.zeros(numTwists)
            for j in range(numTwists):
                # Twisting
                protein = prot.randomTwist(protein, T)
            # Print current state:
            print("Iter: ", i + 1, "/", len(temp), "\tTemp: ", T)
    protein.draw()
Exemplo n.º 12
0
def quest_4_1(acc, protLength):
    # Define a protein
    P = prot.Protein(protLength)
    # x-axis of plot
    twistValues = np.linspace(0, 30000, acc)
    # y-axis of plot
    Evalues = np.zeros(acc)

    dist = int(twistValues[1] - twistValues[0])

    T = 1500 + 10e-12  # Initializing temperature
    counter = 0  # Initializing the increment between each temperature level

    # Plot while temperature is positive
    while T > 0:
        # For every plotting point
        for i in range(acc):
            # Inbetween plotting points
            for j in range(dist):
                # Check if temperature needs to be updated
                if counter == numTwists:
                    T -= Tincrement
                    counter = 0
                P = prot.randomTwist(P, T)
                counter += 1
            Evalues[i] = P.E

            print("Iter: ", i + 1, "/", acc)

    # Plot
    plt.plot(twistValues, Evalues, lw=1, label=r"15 monomers", color="crimson")

    changeTempPoints = np.linspace(0, 30000, int(1500 / Tincrement))
    for point in changeTempPoints:
        plt.axvline(x=point)

    plt.xlabel(r"\textbf{Twists}", size=20)
    plt.ylabel(r"$E$  [J]", size=20)
    plt.legend(loc="best")
    plt.grid()
    plt.show()
Exemplo n.º 13
0
def quest_3_long(acc):
	# Parameters for protein of length 30
	dmax = 20000
	s = 0.001

	# x-axis of plot
	Tvalues = np.linspace(Trange[0], Trange[1], acc)
	# y-axis of plot
	Dvalues = np.zeros(acc)

	# For each temperature
	for i in range(acc):
		# Find number of twists necessary
		D = int(dmax * np.exp(-s * Tvalues[i]))
		diameters = np.zeros(D)

		# Define a new protein for each temperature
		P = prot.Protein(30)
		print("\n\nTemperature:", Tvalues[i], "|| # Twists:", D, "|| Iter:", i + 1, "of", acc, "\n\n")

		# Perform twists and find the diameter after each twist
		for j in range(D):
			# Perform a single twist with energy and thermal fluctuation conserns
			P = prot.randomTwist(P, Tvalues[i])
			# Add to diameter list
			diameters[j] = P.D
		# Find the average diameter for the given temperature
		Dvalues[i] = np.average(diameters)

	# Plot
	plt.plot(Tvalues, Dvalues, lw=3, label=r"30 monomers", color="crimson")
	plt.xlabel(r"$T$  [K]", size=20)
	plt.ylabel(r"$\langle L \rangle$  [1]", size=20)
	plt.legend(loc="best")
	plt.grid()
	plt.show()
Exemplo n.º 14
0
    def createProtein(self, proteinFileName):
        """ Create a protein object with the given file """

        proteinFile = open(self.classFolder + proteinFileName, 'r')
        primaryStructure = self.buildPrimaryStructure(proteinFile)
        proteinFile.close()

        proteinFile = open(self.classFolder + proteinFileName, 'r')
        secondaryStructure = self.buildSecondaryStructure(
            proteinFile, len(primaryStructure),
            proteinFileName)  #tirar ultimo par
        proteinFile.close()

        return Protein.Protein(
            os.path.basename(proteinFileName).replace('.txt', ''),
            self.proteinClass, primaryStructure, secondaryStructure)
Exemplo n.º 15
0
def predict(pf, ad, optd, od, nth):
    # Load protein
    pid = os.path.splitext(os.path.basename(pf))[0]
    prot = Protein.Protein(pid)
    prot.fromfiles(pf, None)

    # Load assess files into dict {(step, pat): (rot, #obs, score)}
    adic = loadassess(ad)

    optd = optd.rstrip('/')
    opts = []
    for step in range(MAXSTEP + 1):
        of = '{}/step{}_opts'.format(optd, step)
        opt = Option.Option(of)
        opts.append(opt)

    results = []
    for bond in prot.hbonds:
        preds = []
        for step in range(MAXSTEP + 1):
            pat = str(prot.findpattern2(bond, opts[step]))
            try:
                rot, _, score = adic[(step, pat)]
            except KeyError:
                continue
            preds.append((step, pat, score, rotdif(bond.rotation, rot)))
        # We don't want ambiguous clusters
        preds = [pred for pred in preds if pred[2] > 10]
        preds.reverse()
        preds.sort(key=itemgetter(3))
        try:
            step, pat, score, dif = preds[nth - 1]
        except IndexError:
            step, pat, score, dif = preds[-1]
        line = '{}\t{}\t{}\t{}\t{}\t{}'.format(pid, bond.lineno, step, pat,
                                               score, dif)
        if not od:
            print(line)
            continue

        results.append(line)

    fn = 'predch{}.{}.txt'.format(nth, pid)
    outf = os.path.join(od, fn)
    with open(outf, 'w') as fh:
        fh.write('\n'.join(results))
Exemplo n.º 16
0
def main(protdir, lstf, optfile, outfile):
    pfiles = []
    with open(lstf) as fh:
        for line in fh:
            pfiles.append('{}/{}'.format(os.path.normpath(protdir),
                                         line.strip()))
    opt = Option.Option(optfile)

    # Build dict of {(protid, lineno): pattern}
    bonds = {}
    for pfile in pfiles:
        pid = os.path.splitext(os.path.basename(pfile))[0]
        prot = Protein.Protein(pid)
        prot.fromfiles(pfile, None)
        for bnd in prot.hbonds:
            bonds[(pid, bnd.lineno)] = str(prot.findpattern2(bnd, opt))

    with open(outfile, 'wb') as fh:
        cPickle.dump(bonds, fh, -1)
Exemplo n.º 17
0
def findpatterns(step, data):
    """
    Find local patterns for the given step & data.
    :param step: int; step number
    :param data: list of prot file names to process.
    :return: dict of {pattern: list of rotations}
    """
    import os
    import uuid
    import cPickle
    import Protein
    import Option
    from config import cfg

    sdir = os.environ['SCRATCH']
    of = os.path.join(cfg['optsdir'], 'step{}_opts'.format(step))
    opt = Option.Option(of)
    patrot = {}
    for f in data:
        protid = os.path.splitext(os.path.basename(f))[0]
        tertf = os.path.join(cfg['tertdir'], protid + '.txt')
        if (not os.path.exists(tertf)) or (cfg['max_tbond_level'] == -1):
            # Corresponding tertiary file may not be present...
            tertf = None
        prot = Protein.Protein(protid)
        prot.fromfiles(f, tertf)
        for bond in prot.hbonds:
            pat = str(prot.findpattern2(bond, opt))
            if pat in patrot:
                patrot[pat].append(tuple(bond.rotation))
            else:
                patrot[pat] = [tuple(bond.rotation)]
        del prot

    outfile = os.path.join(sdir,
                           'step{}_{}.pkl'.format(step, uuid.uuid4().hex))
    with open(outfile, 'wb') as o:
        cPickle.dump(patrot, o, -1)
Exemplo n.º 18
0
def main():
    protein_folder = 'proteins/final/'
    protein_dict = {}
    beam_range = [160, 170, 180, 190, 200]
    for beam_size in beam_range:
        # for hp in os.listdir('proteins/final/'):
        hp = 'HP_100'
        finals = []
        protein_length = int(hp.split('_')[1])
        for protein in open(protein_folder + hp, 'r'):

            p_obj = p.Protein2D(protein)
            score = p_obj.get_score(p_obj.coors, protein)

            bm = b.Beam2D(beam_size=beam_size)
            coors, scores = bm.run_beam(protein, score, p_obj.coors)
            finals.append([protein, coors[0], scores[0]])
        print(beam_size, finals[-1][-1])

        with open(f'results/{hp}_bs{bm.bs}_beamResults.csv', 'w') as f:
            writer = csv.writer(f)
            for result in finals:
                writer.writerow(result)
Exemplo n.º 19
0
def parse_file(path):
    """
    cleans the vm file lines from garbage (didnt clean the spaces)
    :param path:
    :return:
    """

    #states
    aa_state = False
    group_state = False
    states_state = False
    keywords_state = False

    proteins = []
    name = "No one"
    aa_seq = ""
    group_seq = ""
    structure = ""
    keywords = ""

    file = open(path)
    for line in file:
        if aa_state:
            if line[0] in aa_set:
                aa_seq += line
            else:
                aa_state = False
                group_state = True
                group_seq += line

        elif group_state:
            char = line[0]
            if char.isdigit():
                group_seq += line
            else:
                group_state = False
                states_state = True
                structure += line
        elif states_state:
            if re.fullmatch(
                    states_pattern, line
            ):  # maybe we can make more efficient with adding a special symbol like '$' at the beginning of each states line
                structure += line
            else:
                states_state = False
                keywords_state = True
                keywords += line

        elif keywords_state:
            if line.startswith('++'):
                keywords_state = False
                protein = Protein.Protein(name, aa_seq, group_seq, keywords,
                                          structure)
                if not protein.to_drop:
                    proteins.append(protein)
                name = None
                aa_seq = ""
                group_seq = ""
                structure = ""
                keywords = ""
            else:
                keywords += line

        elif line.startswith('protein:'):
            name = line[8:]
            aa_state = True

        else:
            raise ValueError("Wrong string pattern!")

    return proteins
Exemplo n.º 20
0
def parse_file(path):
    """
    cleans the vm file lines from garbage (didnt clean the spaces)
    :param path:
    :return:
    """

    #states
    aa_state = False
    group_state = False
    states_state = False
    keywords_state = False

    proteins = []
    name = "No one"
    aa_seq = ""
    group_seq = ""
    structure = ""
    keywords = ""

    #print(name)

    with open(path) as file:
        for line in file.readlines():
            #print(line)
            line = line.strip()
            if aa_state:
                if all(aa in aa_set for aa in line):
                    aa_seq += line
                else:
                    aa_state = False
                    group_state = True
                    group_seq += line

            elif group_state:
                char = line[0]
                if char.isdigit():
                    group_seq += line
                else:
                    group_state = False
                    states_state = True
                    structure += replace_symbols(line)
            elif states_state:
                if re.fullmatch(
                        states_pattern, line
                ):  # maybe we can make more efficient with adding a special symbol like '$' at the beginning of each states line
                    structure += replace_symbols(line)
                else:
                    states_state = False
                    keywords_state = True
                    keywords += line

            elif keywords_state:
                if line.startswith('++'):
                    keywords_state = False
                    # print("I'm Here")
                    # print(name)
                    # print(aa_seq)
                    # print(group_seq)
                    # print(structure)
                    assert group_seq.isdigit(), 'assert 1 ' + group_seq
                    assert all(s in 'ABTO' for s in structure), 'assert 2'
                    protein = Protein.Protein(name, aa_seq, group_seq,
                                              keywords, structure)
                    if not protein.to_drop:
                        proteins.append(protein)
                    name = None
                    aa_seq = ""
                    group_seq = ""
                    structure = ""
                    keywords = ""
                else:
                    keywords += line

            elif line.startswith('protein:'):
                name = line[8:]
                print(name)
                aa_state = True

            else:
                raise ValueError("Wrong string pattern!")

    return proteins
Exemplo n.º 21
0
    transitions = init_transitions(p_train, True)
    emissions_matrix = emission_to_matrix(emissions)
    transitions_matrix = transition_to_matrix(transitions)

    # seq = "0112233446"
    # posterior = calculate_posterior(seq, transitions_matrix, emissions_matrix)
    # print(posterior, "\n")

    true = []
    pred = []
    for p in p_test:
        matrix = calculate_posterior_group(p.group_seq, transitions_matrix,
                                           emissions_matrix)
        trace = trace_states(p.group_seq, matrix)
        # matrix, trace = calculate_viterbi(p.group_seq, transitions_matrix, emissions_matrix)
        trace = Protein.revert_structure3(trace)
        pred.append(trace)
        true.append(p.structure)
        try:
            print(trace[:60])
            print(p.structure[:60])
            print("======================================")
        except IndexError:
            continue

    err = evaluate(true, pred)
    print(err)

    # test_p = p_list[-2:]
    # train_p = p_list[:-2]
    # hmm = apply_hmm.HMM(train_p, test_p)
Exemplo n.º 22
0
'''
We chose some specific rotations to better show off that the protein folding code worked
To chose randomly, we would write something like:

import random
num = random.randint(1, SIZE)
clockwise = random.randint(0, 1)

Inserting num and clockwise as parameters for the protein twist, then generating some new num and
clockwise, and inserting them again. 
'''

SIZE = 10

# Initialize
P = prot.Protein(SIZE)

# Show the initial state. present() plots the protein with matplotlib, and draw() prints the matrix to output
P.present()
P.draw()
print()

# Show state after 1 twist
P.twist(8, False)
P.present()
P.draw()
print()

# Show state after 2 twists
P.twist(6, True)
P.present()