2013-09-25 72 views
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() 

計數器從這個代碼我得到的輸出文件這樣如何插入在python

1------10 11-----20 21------30-----so on 
123456789
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 

我要插入計數器的每一行「斛」和輸出這樣

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計數。

在此先感謝

回答

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包含串行爲該行)

編輯

d。如果你的意思是真正的行序列號,那麼你也應該補充:

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])) 
+0

感謝Ofir以色列。因爲我是初學者。我如何在我的輸出文件中指定每一列。 – awanit

+0

什麼? :)我不明白 –

+0

像我想指定每一列。對於ATOM來說,1-6爲13-16,OW爲13-16,HOH爲18-20,21爲空間,22爲X,23-26爲序列號,31-38爲pcord [0],39-46爲pcord [ 1],37-57爲pcord [2]。這是PDB文件的標準格式。 – awanit

0

我想你的意思

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

,然後計數器是你的櫃檯。