0
votes

I'm using a protein structure modelling tool called "Modeller" that's based on Python and I keep getting this error

ValueError: too many values to unpack

When I try to run the following script:

from modeller import *

env = environ()
aln = alignment(env)
for (pdb, chain) in (('tseq1', 'A')):
    m = model(env, file=pdb, model_segment=('FIRST:'+chain, 'LAST:'+chain))
    aln.append_model(m, atom_files=pdb, align_codes=pdb+chain)
aln.malign()
aln.malign3d()
aln.compare_structures()
aln.id_table(matrix_file='family.mat')
env.dendrogram(matrix_file='family.mat', cluster_cut=-1.0)

I've tried changing 'tseq1' (template sequence), just in case I got the wrong file and it's supposed to be qseq1, which is my query sequence. But it doesn't make a difference and I keep getting the same error. I read somewhere that this error occurs when I try to unpack too many values into an object that's not got enough variables to unpack them to, but I can't see where 'tseq1' is going in this script. When I run this code in terminal I use the following command (just in case that has something to do with it, which I doubt):

mod9.14 script2.py 

Can anyone help?

3
First, put the complete error message in your question... Also add which version of python you are using. - Eric Levieil
post the complete error message along. - Barun Sharma
to me, the problem lies in the tuple you are extracting in the for loop - Pynchia

3 Answers

2
votes

The error must be in this line:

for (pdb, chain) in (('tseq1', 'A')):

You are trying to unpack tseq1 into two variables pdb and chain. Since Python strings are iterable, what happens is that pdb gets the 't' and chain the 's', but the interpreter does not know where to unpack the rest of the sequence (therefore the too many values to unpack).

What may be confusing you is that (('tseq1', 'A')) is pretty much the same as ('tseq1', 'A'), i.e. it is not a sequence of tuples, it is just a 2-element tuple.

If you change the outer brackets to square brackets, you are converting the tuple into a list with only one tuple, and your code should not fail. (alternatively you can add a comma after the tuple to create a tuple of tuples (('tseq1', 'A'), )). However, I can't know if this is what you expect it to do:

for (pdb, chain) in [('tseq1', 'A')]:

By the way, the brackets for the unpacking are not necessary. This is the same:

for pdb, chain in [('tseq1', 'A')]:
0
votes

I upvoted the prev answer, but as an alternative you might want to add a comma to make the tuple work, if that is what you expect your code to do:

for (pdb, chain) in (('tseq1', 'A'),):
    print pdb, chain

produces:

tseq1 A
0
votes

try to this.

inv_type = (('tseq1', 'A'))
pdb, chain = inv_type if isinstance(inv_type, tuple) else [inv_type]
print pdb, chain