The Molecular Graphics Laboratory Forum
http://mgl.scripps.edu/forum/

I wrote script to automatically generate box around target
http://mgl.scripps.edu/forum/viewtopic.php?f=12&t=3342
Page 1 of 1

Author:  Vytautasrask [ Wed Nov 30, 2016 11:20 am ]
Post subject:  I wrote script to automatically generate box around target

I wrote Perl script to automatically generate box around target.
Maybe it will be useful for somebody else.
It reads pdbqt file with target and writes Vina configuration file with box and pdb file with same box, tested it on Chimera.
Code:
#!/usr/bin/perl
#autobox
#Generate box for AutoDock Vina automatically
#
#V.R.

use List::Util qw( min max );

die "Usage ./autobox.pl FILE.pdbqt\n" if(!defined($ARGV[0]));
open($fh, $ARGV[0]) or die "Could not open file '$filename' $!";
 
while (my $row = <$fh>) {
        if ($row =~ m/^ATOM/) {
                #print "$row";
                @line = split(/ +/, $row);
                push @x, $line[6];
                push @y, $line[7];
                push @z, $line[8];
  }
}
close $fh;

$maxx = max(@x);
$maxy = max(@y);
$maxz = max(@z);
$minx = min(@x);
$miny = min(@y);
$minz = min(@z);

#print "max(x): ", $maxx, "\n";
#print "max(y): ", $maxy, "\n";
#print "max(z): ", $maxz, "\n";
#print "min(x): ", $minx, "\n";
#print "min(y): ", $miny, "\n";
#print "min(z): ", $minz, "\n";

$size_x = ($maxx - $minx)/2;
$size_y = ($maxy - $miny)/2;
$size_z = ($maxz - $minz)/2;
$center_x = $maxx - $size_x;
$center_y = $maxy - $size_y;
$center_z = $maxz - $size_z;

open(my $fh, '>', 'box.pdb') or die "Could not open file '$filename' $!";
print $fh ("
HEADER    CORNERS OF BOX
REMARK    CENTER (X Y Z)   $center_x  $center_y  $center_z
REMARK    DIMENSIONS (X Y Z)   $size_x  $size_y  $size_z
ATOM      1  DUA BOX     1     $minx  $miny  $minz
ATOM      2  DUB BOX     1     $maxx  $miny  $minz
ATOM      3  DUC BOX     1     $maxx  $miny  $maxz
ATOM      4  DUD BOX     1     $minx  $miny  $maxz
ATOM      5  DUE BOX     1     $minx  $maxy  $minz
ATOM      6  DUF BOX     1     $maxx  $maxy  $minz
ATOM      7  DUG BOX     1     $maxx  $maxy  $maxz
ATOM      8  DUH BOX     1     $minx  $maxy  $maxz
CONECT    1    2    4    5
CONECT    2    1    3    6
CONECT    3    2    4    7
CONECT    4    1    3    8
CONECT    5    1    6    8
CONECT    6    2    5    7
CONECT    7    3    6    8
CONECT    8    4    5    7
");
close $fh;

open(my $fh, '>', 'conf.txt') or die "Could not open file '$filename' $!";
print $fh ("
center_x = $center_x
center_y = $center_y
center_z = $center_z
size_x = $size_x
size_y = $size_y
size_z = $size_z
");
close $fh;

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/