#!/usr/local/bin/gawk -f # # Gawk script that read and write ATOM records in pdb files # # Format descriprion of ATOM records: # from http://www.rcsb.org/pdb/docs/format/pdbguide2.2/guide2.2_frame.html # #COLUMNS DATA TYPE FIELD DEFINITION #--------------------------------------------------------------------------------- # 1 - 6 Record name "ATOM " # 7 - 11 Integer serial Atom serial number. #13 - 16 Atom name Atom name. #17 Character altLoc Alternate location indicator. #18 - 20 Residue name resName Residue name. #22 Character chainID Chain identifier. #23 - 26 Integer resSeq Residue sequence number. #27 AChar iCode Code for insertion of residues. #31 - 38 Real(8.3) x Orthogonal coordinates for X in #39 - 46 Real(8.3) y Orthogonal coordinates for Y in #47 - 54 Real(8.3) z Orthogonal coordinates for Z in #55 - 60 Real(6.2) occupancy Occupancy. #61 - 66 Real(6.2) tempFactor Temperature factor. #73 - 76 LString(4) segID Segment identifier, left-justified. #77 - 78 LString(2) element Element symbol, right-justified. #79 - 80 LString(2) charge Charge on the atom. # # # { if (/^ATOM/){ # # Get data from ATOM line # ATOM = substr($0,1,6); serial = substr($0,7,4); name = substr($0,13,4); altLoc = substr($0,17,1); resName = substr($0,18,3); chainID = substr($0,22,1); resSeq = substr($0,23,4); iCode = substr($0,27,1); x = substr($0,31,8)*1.0; y = substr($0,39,8)*1.0; z = substr($0,47,8)*1.0; occupancy = substr($0,55,6)*1.0; tempFactor = substr($0,61,6); segID = substr($0,73,4); element = substr($0,77,2); charge = substr($0,79,2); # # Print data from ATOM line # printf("%6s%5d %4s%1s%3s %s%4d%1s %8.3f%8.3f%8.3f%6.2f%6.2f%4s%2s%2s\n", ATOM, serial, name, altLoc, resName, chainID, resSeq, iCode, x, y, z, occupancy, tempFactor, segID, element, charge) } }