NAMD Wiki: dsv-crd2pdb
#!/usr/bin/python # This script converts a Discovery Studio crd file to a PDB file. # # EPF 25-09-2007 # import sys,struct,os if len(sys.argv) < 2: print "usage: crd2pdb crd-file > pdb-file" os._exit(0) crdfile = sys.argv[1] f=open(crdfile) print 'REMARK Converted from '+crdfile buffer = f.readline() while buffer[0:1] == "*": buffer = f.readline() numofatoms = float(buffer[0:11]) j = 0 m = 0 atomnr = 0 while buffer != "": buffer = f.readline() if buffer != "": atomnr = int(buffer[0:m+10]) resnr = int(buffer[m+11:m+20]) residue = buffer[m+22:m+26] atom = buffer[m+32:m+36] x = float(buffer[m+45:m+60]) y = float(buffer[m+65:m+80]) z = float(buffer[m+80:m+100]) segment = buffer[m+102:m+106] reschain = buffer[m+108:m+113] bfactor = float(buffer[m+126:m+140]) if reschain[0:1].isalpha(): chain = reschain[0:1] else: chain = " " if resnr<10000: atomdata =(atomnr,atom,residue,chain,resnr,x,y,z,0.0,bfactor) pdbline = 'ATOM %6i %3s%4s%c%4i %8.3f%8.3f%8.3f%6.2f%6.2f' % atomdata else: atomdata =(atomnr,atom,residue,resnr,x,y,z,0.0,bfactor) pdbline = 'ATOM %6i %3s%4s%5i %8.3f%8.3f%8.3f%6.2f%6.2f' % atomdata print pdbline j += 1 if atomnr == 99999: m = 1 print "REMARK There are %s atoms in this file" % j if j != numofatoms: print "REMARK Actual number of atoms does not match the number given in crd file (%s)" % numofatoms