Difference between revisions of "Split NMR-style multiple model pdb files into individual models"

From CCP4 wiki
Jump to navigationJump to search
(Created page with 'This assumes that you have a correctly formatted pdb file that contains both MODEL and ENDMDL records. It gets split into individual pdb files names model_###.pdb. grep -n 'MOD…')
 
Line 1: Line 1:
This assumes that you have a correctly formatted pdb file that contains both MODEL and ENDMDL records.  It gets split into individual pdb files names model_###.pdb.
+
This assumes that you have a correctly formatted pdb file that contains both MODEL and ENDMDL records.   
 +
 
 +
 
 +
 
 +
== Bash/awk one-liner ==
 +
 
 +
 
 +
This one-liner splits the file models.pdb into individual pdb files names model_###.pdb.
  
 
grep -n 'MODEL\|ENDMDL' models.pdb |  
 
grep -n 'MODEL\|ENDMDL' models.pdb |  
Line 5: Line 12:
 
awk '{if(NR%2) printf "sed -n %d,",$1+1; else printf "%dp > model_%03d.pdb\n", $1-1,NR/2;}' |  
 
awk '{if(NR%2) printf "sed -n %d,",$1+1; else printf "%dp > model_%03d.pdb\n", $1-1,NR/2;}' |  
 
bash -sf
 
bash -sf
 +
 +
== Perl script ==
 +
 +
$base='1g9e';open(IN,"<$base.pdb");@indata = <IN>;$i=0;
 +
 +
foreach $line(@indata) {
 +
 +
if($line =~ /^MODEL/) {++$i;$file="${base}_$i.pdb";open(OUT,">$file");next}
 +
 +
if($line =~ /^ENDMDL/) {next}
 +
 +
if($line =~ /^ATOM/ || $line =~ /^HETATM/) {print OUT "$line"}
 +
 +
}

Revision as of 14:42, 14 December 2010

This assumes that you have a correctly formatted pdb file that contains both MODEL and ENDMDL records.


Bash/awk one-liner

This one-liner splits the file models.pdb into individual pdb files names model_###.pdb.

grep -n 'MODEL\|ENDMDL' models.pdb | cut -d: -f 1 | awk '{if(NR%2) printf "sed -n %d,",$1+1; else printf "%dp > model_%03d.pdb\n", $1-1,NR/2;}' | bash -sf

Perl script

$base='1g9e';open(IN,"<$base.pdb");@indata = <IN>;$i=0;

foreach $line(@indata) {

if($line =~ /^MODEL/) {++$i;$file="${base}_$i.pdb";open(OUT,">$file");next}

if($line =~ /^ENDMDL/) {next}

if($line =~ /^ATOM/ || $line =~ /^HETATM/) {print OUT "$line"}

}