[Tutor] just one question
vince spicer
vinces1979 at gmail.com
Wed Jul 15 16:44:09 CEST 2009
one way is:
import re
infile = open("test.txt", "r") #: open read mode
outfile = open("out.tx", "w") #: open write mode
for line in infile:
values = re.split("\s+", line) # split values on spaces EX: ['47', '8',
'ALA', 'H', 'H', '7.85', '0.02', '1']
outfile.write("%s %s C = %s CA = %s CB = %s" % (values[1],
values[2], values[5], values[6], values[7]))
infile.close()
outfile.close()
not tested but should work
Vince
On Wed, Jul 15, 2009 at 6:24 AM, <amrita at iisermohali.ac.in> wrote:
> Hi,
>
> i want to ask one thing that suppose i have a .txt file having content
> like:---
>
>
> 47 8 ALA H H 7.85 0.02 1
> 48 8 ALA HA H 2.98 0.02 1
> 49 8 ALA HB H 1.05 0.02 1
> 50 8 ALA C C 179.39 0.3 1
> 51 8 ALA CA C 54.67 0.3 1
> 52 8 ALA CB C 18.85 0.3 1
> 53 8 ALA N N 123.95 0.3 1
> 107 15 ALA H H 8.05 0.02 1
> 108 15 ALA HA H 4.52 0.02 1
> 109 15 ALA HB H 1.29 0.02 1
> 110 15 ALA C C 177.18 0.3 1
> 111 15 ALA CA C 52.18 0.3 1
> 112 15 ALA CB C 20.64 0.3 1
> 113 15 ALA N N 119.31 0.3 1
> 154 21 ALA H H 7.66 0.02 1
> 155 21 ALA HA H 4.05 0.02 1
> 156 21 ALA HB H 1.39 0.02 1
> 157 21 ALA C C 179.35 0.3 1
> 158 21 ALA CA C 54.33 0.3 1
>
> now what i want that i will make another .txt file in which first it will
> write the position of ALA lets say 8, 15, 21 then its name ALA and then
> the fifth column value for only three atoms C,CA and CB.
>
> Means it will be someting like:
>
> 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 =
>
> if some value is not there then it will leave that as blank.I am new in
> python but this is what we want, so how can i do it using python script.
>
>
>
>
>
> Amrita Kumari
> Research Fellow
> IISER Mohali
> Chandigarh
> INDIA
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090715/aec746af/attachment-0001.htm>
More information about the Tutor
mailing list