0
outfile2 = open('cordrandm.pdb', 'w')
for kk in text1:
if kk != '':
    outfile2.write(kk)
    outfile2.write('\n')

for alcord in alistcoord:
    uacoord = alcord[1]
    for blcord in blistcoord:
        ubcoord = blcord[1]    
        for arang in range(1000):
            arang = arang + 1
            x,y,z = uacoord
            x1,y1,z1 = (uniform(x-3.5,x+3.5), uniform(y-3.5,y+3.5), uniform(z-3.5,z+3.5))
            pacord = [x1,y1,z1]

            dist_pap = euDist(uacoord, pacord)
            if  3.5 > dist_pap > 2.5: 
               dist_pap1 = dist_pap

    outfile2.write('ATOM         OW  HOH X          %6.3f  %6.3f  %6.3f\n' % (pacord[0],  pacord[1],  pacord[2]))

outfile2.close()

从这段代码我得到这样的输出文件

1------10 11-----20 21------30-----so on
123456789012345678901234567890123456789012345678901234
ATOM         OW  HOH X          10.533  22.567  61.777
ATOM         OW  HOH X           5.655  23.758  61.221
ATOM         OW  HOH X          10.125  20.476  68.503
ATOM         OW  HOH X          11.222  16.810  69.267
ATOM         OW  HOH X           4.351  18.904  66.256
ATOM         OW  HOH X           9.194  22.065  67.714
ATOM         OW  HOH X           4.347  16.527  68.278

我想为每一行“HOH”插入计数器并像这样输出

ATOM         OW  HOH X   1      10.533  22.567  61.777
ATOM         OW  HOH X   2       5.655  23.758  61.221
ATOM         OW  HOH X  10      10.125  20.476  68.503
ATOM         OW  HOH X 100      11.222  16.810  69.267
ATOM         OW  HOH X 101       4.351  18.904  66.256
ATOM         OW  HOH X 102       9.194  22.065  67.714
ATOM         OW  HOH X1000       4.347  16.527  68.278

表示列范围 23-26 指定 HOH 的序列号。我将如何在不会​​改变我的输出 fromat 的特定列中插入 HOH 的计数。

提前致谢

4

2 回答 2

1

就像您关于 pacord 的上一个问题一样。只需将行更改为:

outfile2.write('ATOM OW HOH X%4s %6.3f %6.3f %6.3f\n' % (hoh_serial, pacord[0], pacord[1], pacord[2]))

(考虑hoh_serial包含该行的序列号)

编辑

如果您的意思是该行的序列号,那么您还应该添加:

from itertools import count
...
hoh_serial = count(1)
...
...
outfile2.write('ATOM         OW  HOH X%4s      %6.3f  %6.3f  %6.3f\n' % (hoh_serial.next(), pacord[0],  pacord[1],  pacord[2]))
于 2013-09-25T09:58:30.483 回答
0

我想你的意思是

for counter, blcord in enumerate(blistcoord):
    ...
    outfile2.write('ATOM ...', (counter,...) )

然后柜台是你的柜台。

于 2013-09-25T09:59:19.083 回答