#!/usr/bin/perl -w # gromacs.csh -force_field 0 -tmp /tmp -nokeeptmp # creates a temporary directory, and does a gromacs optimization # of the pdb file from stdin in that directory, and returns the # optimized pdb file to stdout. use strict; use File::Basename; use English; use Getopt::Long; # directory with starter files for gromacs my $gromacs_starter = "/projects/compbio/experiments/protein-predict/casp6/gromacs"; my $fixup_script = "/projects/compbio/experiments/protein-predict/casp6/scripts/fix-gromacs"; my $tmp_root = "/tmp"; my $force_field = 0; my $keep_tmp=0; GetOptions( "force_field=n" => \$force_field , "keeptmp!" => \$keep_tmp , "tmp=s" => \$tmp_root ); # create a name for the temporary directory my $user=`/usr/bin/whoami`; chomp $user; my $PROG = basename($0); my $rand = int(rand(99999999)); my $job_dir = "$tmp_root/$PROG-$user-$$-$rand"; mkdir $job_dir, 0775 or die "Error $PROG: could not make directory $job_dir\n"; print STDERR "$PROG running in $job_dir\n"; # copy the input PDB file to the temporary directory open PDBIN, "> $job_dir/tmp.pdb"; while() { print PDBIN $_; } close PDBIN; # copy the starter files foreach my $file ("em.mdp", "full.mdp", "mdout.mdp", "pr.mdp") { system("cp -pr $gromacs_starter/$file $job_dir")==0 || die "Couldn't copy $gromacs_starter/$file to $job_dir\n"; } my @commands=( "echo $force_field | pdb2gmx -ignh -f tmp.pdb -p tmp.top -o tmp.gro" , "editconf -f tmp -o -d 0.5 -c" , "genbox -cp out -cs -p tmp -o tmp.b4em" , "grompp -v -f em -c tmp.b4em -o tmp -p tmp" , "mdrun -v -s tmp -o tmp -c tmp.after_em -g tmp.emlog" , "echo 1 | trjconv -f tmp.after_em.gro -s tmp.tpr -o tmp.raw_gromacs.pdb" ); foreach my $command (@commands) { print STDERR "Running '$command'\n"; system("cd $job_dir; $command 2>>gromacs.stderr >> gromacs.stdout"); } system("$fixup_script < $job_dir/tmp.raw_gromacs.pdb")==0 || die "Error: $PROG couldn't copy output from $job_dir/tmp.raw_gromacs.pdb\n"; if (!$keep_tmp) { system("rm -rf $job_dir")==0 || die "Error: $PROG couldn't remove $job_dir\n"; } exit(0);