Perl Script: Cmin

This is a simple perl script that will take a CHARMm energy minimisation request issued by Swiss-PdbViewer and process it. It requires that you have previously modified your .cshrc login script to include this
In any case, do not forget to alter the paths (
displayed in red) to point at the proper location on your system.


#!/usr/central/bin/perl # split PDB file from CHARMM command file # and preform the requested job # # version 1.0 # NG/97     $charmbase = $ENV{"CHARMHOME"};   # ------------------------------------- # -------- retrieve arguments --------- # ------------------------------------- if ($#ARGV == -1) { print "v1.0 usage: Cmin [-r] filename\n"; exit; } while ($#ARGV > 0) { if ($ARGV[0] eq "-r") { $cleanup++; shift(@ARGV); } } $pdbfile = @ARGV[0];     # ----------------------------------------- # -------- prepare some filenames --------- # ----------------------------------------- ($minifile) = split(/\./,$pdbfile);   $charmoutfile = $minifile . "_E.pdb"; $charmresult = $$.".charmm"; $infile = $$.".pdb"; $commandfile = $$.".cmd"; $tmpfile = $$.".tmp";   # --------------------------------------------------------------- # ------ Create an input file with proper line terminators ------ # ------ (for mac translate CR in LF; for pc remove CR) ------ # ---------------------------------------------------------------   # ---- figure out which kind of file we deal with ---   open (IN,"<$pdbfile") or die "** ERROR: file $pdbfile doesn't exist\n"; (@line) = split '', <IN>; $nbchar = $#line; if ($nbchar > 200) { $nbchar = 200; } for ($i=0; $i <= $nbchar; $i++) { if ($line[$i] eq "\n") { $lf = 1; } elsif ($line[$i] eq "\r") { $cr = 1; } } close IN;   # ----- do the appropriate conversion ---   open (IN,"<$pdbfile") or die; open (TMP,">$tmpfile") or die; while(<IN>) { if ($cr && $lf) { ~ s/[\r]//; } else { ~ tr/[\r]/[\n]/; } print TMP $_; } close TMP; close IN; if (-e "%$pdbfile") { unlink "%$pdbfile"; }   # ----------------------------------------------------------------------- # ------- Split input file in PDB and CHARMm command file --------- # ----------------------------------------------------------------------- open (TMP,"<$tmpfile") or die; open (PDB,">$infile") or die; open (CHARMM,">$commandfile") or die; while(<TMP>) { print PDB $_; if (substr($_,0,3) eq "END") { while(<TMP>) { $TAG = substr($_,0,3); $top = index($_,"_TOP"); $prm = index($_,"_PRM"); if ($top != -1) {$TAG = "_TP"; $linestart = substr($_,0,$top);} if ($prm != -1) {$TAG = "_PR"; $linestart = substr($_,0,$prm);} if ($TAG eq "_I_") { print CHARMM "\"".$infile."\n"; } elsif ($TAG eq "_O_") { print CHARMM "\"".$charmresult."\n";} elsif ($TAG eq "_TP") { print CHARMM $linestart."\"".$charmbase."/top.inp\n";} elsif ($TAG eq "_PR") { print CHARMM $linestart."\"".$charmbase."/param.inp\n";} else { print CHARMM $_; } } } } close CHARMM; close PDB; close TMP;   # ---------------------------------------------------- # -------- launch CHARMM and collect results --------- # ----------------------------------------------------   print "** MINIMIZING **\n"; open (CHARMOUT,">$charmoutfile") or die; open (CHARMM, "charmm < $commandfile |"); while(<CHARMM>) { $linestart = substr($_,0,4); # if (($linestart eq "MINI") || ($linestart eq "CONJ") || ($linestart eq "ABNR") || ($linestart eq " ---")) if (($linestart eq "MINI") || ($linestart eq " ---")) { print CHARMOUT "//".$_; } } close CHARMM;   # --------------------------------------- # -------- Prepare a nice PDB file ------ # ---------------------------------------   open(PDB, "<$charmresult"); while(<PDB>) { if (substr($_,0,4) eq "ATOM") { print CHARMOUT substr($_,0,21); print CHARMOUT substr($_,73,1); print CHARMOUT substr($_,22,44)."\n"; } } print CHARMOUT "END\n";   close PDB; close CHARMOUT;   # ----------------------------- # --------- clean up ---------- # ----------------------------- if (-e "fort.1") { system("\\rm fort.1"); } if ($cleanup) { system("\\rm $$.*"); }   exit;