Useful Python Scripts: Difference between revisions
Jump to navigation
Jump to search
import>Ho246 No edit summary |
import>Ho246 No edit summary |
||
Line 1: | Line 1: | ||
On this script you will find (and can add!) Python scripts, that may be useful in any work-related way. |
On this script you will find (and can add!) Python scripts, that may be useful in any work-related way. |
||
== Converting .pdb files from vmd to xleap readable format == |
|||
This script takes a filename as command line argument reads the respective .pdb file and converts it to an xleap |
|||
readable format. The initial file is overwritten, but the original file is retained in filename.orig. |
|||
<pre> |
|||
#!/usr/bin/env python |
|||
# -*- coding: latin1 -*- |
|||
import sys |
|||
def main(): |
|||
fname = sys.argv[1] |
|||
fin = open( fname, "r") |
|||
lines = fin.readlines() |
|||
fin.close() |
|||
lin2=[] |
|||
foumod=open( fname+".orig","w") |
|||
fomod=open( fname,"w") |
|||
counter=1 |
|||
first=True |
|||
oldnum="" |
|||
for l in lines: |
|||
if l.find( "CRYST")==-1: |
|||
l2=l.replace( " X ", " ") |
|||
if len( l2)>16: |
|||
if l2[13].isdigit(): |
|||
subs=l2[12:16] |
|||
subs2=l2[13:17] |
|||
l2=l2.replace( subs, subs2) |
|||
if (not first) and len( l2)>25: |
|||
if oldnum!=l2[25]: |
|||
oldnum=l2[25] |
|||
print oldnum |
|||
lin2.append( "TER\n") |
|||
counter+=1 |
|||
first=False |
|||
lin2.append( l2) |
|||
else: |
|||
counter-=1 |
|||
lin2.insert(-1,"TER\n") |
|||
for i in range( counter): |
|||
lines.append( "") |
|||
for l,l2 in zip( lines, lin2): |
|||
foumod.write( l) |
|||
fomod.write( l2) |
|||
if __name__ == "__main__": |
|||
main() |
|||
</pre> |
Revision as of 13:41, 19 August 2008
On this script you will find (and can add!) Python scripts, that may be useful in any work-related way.
Converting .pdb files from vmd to xleap readable format
This script takes a filename as command line argument reads the respective .pdb file and converts it to an xleap readable format. The initial file is overwritten, but the original file is retained in filename.orig.
#!/usr/bin/env python # -*- coding: latin1 -*- import sys def main(): fname = sys.argv[1] fin = open( fname, "r") lines = fin.readlines() fin.close() lin2=[] foumod=open( fname+".orig","w") fomod=open( fname,"w") counter=1 first=True oldnum="" for l in lines: if l.find( "CRYST")==-1: l2=l.replace( " X ", " ") if len( l2)>16: if l2[13].isdigit(): subs=l2[12:16] subs2=l2[13:17] l2=l2.replace( subs, subs2) if (not first) and len( l2)>25: if oldnum!=l2[25]: oldnum=l2[25] print oldnum lin2.append( "TER\n") counter+=1 first=False lin2.append( l2) else: counter-=1 lin2.insert(-1,"TER\n") for i in range( counter): lines.append( "") for l,l2 in zip( lines, lin2): foumod.write( l) fomod.write( l2) if __name__ == "__main__": main()