On 11/17/2012 03:04 PM, Rex Palmer wrote:
> I would like to specify a target atom in a pdb file and then isolate
> all atoms within a given distance of the target. The selected atoms
> are then to be placed in a new pdb file.
AWKward BASHing:
#! /bin/bash
read x y z <<<$(awk '{if(substr($0,1,4)=="ATOM" &&
int(substr($0,7,5))==75) print
substr($0,31,8),substr($0,39,8),substr($0,47,8);}' model.pdb)
awk -v x=$x -v y=$y -v z=$z '{if(substr($0,1,4)=="ATOM" &&
sqrt((substr($0,31,8)-x)^2+(substr($0,39,8)-y)^2+(substr($0,47,8)-z)^2)<4.0)
print;}' model.pdb > out.pdb
You did not specify your atom selection criteria, so I simply use the
atom serial number. To make it more flexible so that it takes model pdb
file name, atom serial number for selection, distance cutoff and output
file name, this should work
#! /bin/bash
read x y z <<<$(awk -v num=$2 '{if(substr($0,1,4)=="ATOM" &&
int(substr($0,7,5))==num) print
substr($0,31,8),substr($0,39,8),substr($0,47,8);}' $1)
awk -v cutoff=$3 -v x=$x -v y=$y -v z=$z '{if(substr($0,1,4)=="ATOM" &&
sqrt((substr($0,31,8)-x)^2+(substr($0,39,8)-y)^2+(substr($0,47,8)-z)^2)<cutoff)
print;}' $1 > $4
It takes about 27ms on a ~3000 atom model (core i7 [log in to unmask], running
precise pangolin). It's not hard to modify the atom selection, if
necessary. I wonder if this is, surprisingly, much faster than all
other options that rely on external programs. For example, it takes
over 120ms just to open and close pymol in batch mode, over 2 seconds
for coot. phenix.pdb_atom_selection takes about 2.5s.
Cheers,
Ed.
--
Oh, suddenly throwing a giraffe into a volcano to make water is crazy?
Julian, King of Lemurs
|