[Tutor] just one question
Rich Lovely
roadierich at googlemail.com
Thu Jul 16 14:18:33 CEST 2009
Please use reply-all, so that emails go to the list as well.
2009/7/16 <amrita at iisermohali.ac.in>:
> Thankyou for help it is working and giving the result but the only problem
> is that it is making a very big file as it is searching for each position
> of ALA and first writting its C value then CA then CB like that, is it
> possible that it will do all these things but in the output it will give
> only the possible of C, CA and CB for each position of ALA:..
>
> Like instead of giving all these:---
>
> 23 ALA C = CA = CB =
> 21 ALA C = 179.35 CA = 54.33 CB = 17.87
> 15 ALA C = 177.18 CA = 52.18 CB = 20.64
> 8 ALA C = 179.39 CA = 54.67 CB = 18.85
> 23 ALA C = CA = CB =
> 21 ALA C = 179.35 CA = 54.33 CB = 17.87
> .....
>
> it will only give:----
>
> 8 ALA C = 179.39 CA = 54.67 CB = 18.85
> 15 ALA C = 177.18 CA = 52.18 CB = 20.64
> 21 ALA C = 179.35 CA = 54.33 CB = 17.87
> 23 ALA C = 179.93 CA = 55.84 CB = 17.55
> 33 ALA C = 179.24 CA = 55.58 CB = 19.75
> 38 ALA C = 178.95 CA = 54.33 CB = 18.30
>
>
> Thanks,
> Amrita
>
>
>
>
>
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> INDIA
>
>
Either you're not entering the code correctly, or the input file is
different to what you've shown us so far.
I think you need to send me a copy of the input file - or at least a
larger sample than we've had so far so we can see what we're dealing
with.
The code should be:
from __future__ import with_statement
from collections import defaultdict
from decimal import Decimal
atoms = defaultdict(dict)
with open("file1.txt") as f:
for line in f:
try:
n, pos, ala, at, symb, weight, rad, count = line.split()
except ValueError:
continue
else:
atoms[int(pos)][at] = Decimal(weight)
#modify these lines to fit your needs:
positionsNeeded = (8, 15, 21)
atomsNeeded = ("C", "CA", "CB")
for k, v in atoms.iteritems():
print k, "ALA C = %s CA = %s CB = %s" % tuple(v.get(a,"") for a in
atomsNeeded)
Check you've got the indentation (the spaces at the start of lines)
correct, exactly how it is above: this is VERY important in python.
--
Rich "Roadie Rich" Lovely
There are 10 types of people in the world: those who know binary,
those who do not, and those who are off by one.
More information about the Tutor
mailing list