#!/usr/bin/perl # template file for reading in pdb file and performing some operation # on one of the columns of data and then writing it back out. # For example, to change chainid, or renumber AA sequence, etc. while () { # loop over input lines $keyword = substr($_,0,6); # look for ATOM record if ($keyword eq "ATOM ") { # dissect line into parts chop; $num = substr($_,6,5); $atom = substr($_,12,4); $res = substr($_,17,3); $chainid = substr($_,21,1); $resn = substr($_,22,4); $xcor = substr($_,30,8); $ycor = substr($_,38,8); $zcor = substr($_,46,8); $occ = substr($_,54,6); $bfac = substr($_,60,6); $segid = substr($_,72,4); $elm = substr($_,76,2); $charge = substr($_,78,2); # do whatever we want with different fields # print ATOM line printf "ATOM %5d %4s %3s %1s%4d %8.3f%8.3f%8.3f%6.2f%6.2f %4s%2s%2s\n", $num,$atom,$res,$chainid,$resn,$xcor,$ycor,$zcor,$occ,$bfac,$segid,$elm,$charge; } # not ATOM record so print whatever we find there else { print $_; } # end of while loop }