#
#
#

__author__ = "Magdalena A. Jonikas"
__version__ = "1.0"
__date__ = " 5/20/09 "
__doc__ = """ Fixes pdb files of RNA molecules for use with gromacs 
              Requires two arguments: 
              1. the name of the existing pdb file
              2. the desired name for the output pdb file"""


import sys

if __name__=='__main__':
    pdbIn = open(sys.argv[1]).readlines()
    pdbOut = open(sys.argv[2], 'w')
    for line in pdbIn:
        if line[0:4]=='ATOM':
            res= line[18:20]
            if res==' G': res='RG'
            if res==' U': res='RU'
            if res==' A': res='RA'
            if res==' C': res='RC'
            star = line[15:16]
            if star == '*': star = "'"
            atomType = line[13:16]
            if atomType=='O2 ': atomType='O  '
            newline = line[:13]+atomType[:2]+star+line[16:18]+res+line[20:]
            pdbOut.write(newline)
        else: pdbOut.write(line)
    pdbOut.close()
