4 # This program will read in an NMR derived PDB file containing
5 # multiple conformers, and will allow the user to extract either
6 # one or all of the models to separate files.
8 # Although the program will run interactively, the command line
9 # usage is "nmrsplit [input.file] [number of model to extract]"
13 # Written 13/12/00 by Simon Andrews (simon.andrews@bbsrc.ac.uk)
15 # Submitted to bioperl script project 2001/08/06
17 # Description: Script which reads an NMR-derived multiple structure
18 # PDB file, and will either extract a single structure from it, or
19 # will extract all of the structures into single files. This is
20 # useful when you want to work with a single representative structure
21 # from an NMR ensemble - especially in conjunction with the OLDERADO
22 # database (http://neon.chem.le.ac.uk/olderado/) which finds the
23 # most representative structure from an ensemble.
26 my $Input = $ARGV[0]; # File to be read
27 my $Pullout = $ARGV[1]; # Specific model to extract
28 my @Pdbfile; # Array for whole PDB file
29 my $Header = ""; # String to hold the PDB header
30 my $Model = ""; # String to hold individual models
31 my $Output; # Prefix for output files
32 my $Modno = 1; # Number of the model being processed
40 print "\"$Input\" does not exist, or could not be read\n";
44 print "\nEnter name of multiple PDB file: ";
56 if ($Pullout =~ /^\d+$/){
57 if ($Pullout == int $Pullout) {
60 print "\"$Pullout\" should be an integer\n";
63 print "\"$Pullout\" should be a number\n";
67 print "\nEnter number of specific model to extract (Return for none): ";
73 last unless ($Pullout);
78 ($Output = $Input) =~ s/\.\w*$//; # Take off everything after the last . to use as prefix
81 open (PDB
,$Input) || die "Can't open $Input because $!";
85 ########## Read the header information ####################
89 if (/^MODEL\b/){last;}
90 $Header = $Header . $_;
94 ######### Read the separate models #######################
100 if ($Model) { # Check if we're past the last model
101 if ($Pullout) { # Check if we're writing one or all
102 last if ($Modno > $Pullout);# No point continuing if we've got the one we want
113 --$Modno; # Correct last increment which didn't find a model
115 if (($Pullout) & ($Modno < $Pullout)) {
116 print "\nCannot find model $Pullout : Only $Modno models in this file\n";
119 #################### subroutines start here ##########################
125 if (/^(MODEL\b|END\b|MASTER\b)/){next;}
126 # Stops you getting MODEL... at the top of the output
127 # and makes sure there isn't a file containing just END or MASTER
129 if (/^ENDMDL\b/){last;} # Check for the end of the model
130 $Model = $Model . $_; # Append the line to $Model
134 sub writeout
{ # Used when all files are being written out
136 if (-e
"$Output\_$Modno.pdb"){ # Check whether we're overwriting anything
138 print "\n$Output\_$Modno.pdb already exists. Overwrite (y/n)? ";
139 my $Question = <STDIN
>;
140 unless ($Question =~ /^y/i) {
141 print "\nSkipping $Output\_$Modno.pdb";
146 open (OUT
,">$Output\_$Modno.pdb") || die "Can't open $Output\_$Modno.pdb because $!";
147 print "\nWriting $Output\_$Modno.pdb ...";
150 print OUT
"END\n"; # Adds and END statement to the PDB file
152 close OUT
|| die "Couldn't close $Output\_$Modno.pdb because $!";
158 if ($Modno == $Pullout) {
160 if (-e
"$Output\_$Modno.pdb") { # Check whether we're overwriting anything
162 print "\n$Output\_$Modno.pdb already exists. Overwrite (y/n)? ";
163 my $Question = <STDIN
>;
164 unless ($Question =~ /^y/i) {
165 print "\nModel not extracted\n";
171 open (OUT
,">$Output\_$Modno.pdb") || die "Can't open $Output\_$Modno.pdb because $!";
172 print "\nWriting $Output\_$Modno.pdb ...\n";
175 print OUT
"END\n"; # Adds and END statement to the PDB file
177 close OUT
|| die "Couldn't close $Output\_$Modno.pdb because $!";
179 $Model = ""; # Stops the reading after this model
181 print "\nReading Model $Modno ...";