#!/usr/bin/perl -w

if (@ARGV != 1) {
    print <<BLOCK_ATOM_USAGE;
===========================================================================
SYNOPSIS
    block_atom PDBFILE
DESCRIPTION
    Gets an ALCHEMY data file which combines both atomic and block
    representation from a PDB input file. The output file has the
    same base name but with the ".alc" extension.
EXAMPLES
    block_atom bdl084.pdb
    rasmol -alchemy -noconnect bdl084.alc
AUTHOR
    Xiang-Jun Lu in the Laboratory of Wilma K. Olson at Rutgers Univ.
    Check URL: http://rutchem.rutgers.edu/~xiangjun/3DNA/
    Report bugs to <xiangjun\@rutchem.rutgers.edu>
===========================================================================
BLOCK_ATOM_USAGE
    die "\n";
}

$pdbfile = $ARGV[0];
-e $pdbfile or die "PDB file <$pdbfile> does NOT exist!\n";
$k = rindex($pdbfile, '.');     # from the last
$k = length($pdbfile) if ($k == -1); # no '.' found
$bname = substr($pdbfile, 0, $k);

# DIRECTORY CONTAINING 3DNA BINARIES: change this line as appropriate
$BDIR = $ENV{X3DNA};
if ($BDIR) {                # X3DNA
    $BDIR =~ s/.$// if (substr($BDIR, -1) eq '/');
    $X3DNA_BIN = "$BDIR/bin";
} else {
    $X3DNA_BIN = "$ENV{HOME}/X3DNA/bin"; # define it manually
}

system "$X3DNA_BIN/r3d_atom $pdbfile temp1";
system "$X3DNA_BIN/pdb2img $pdbfile temp2";
system "$X3DNA_BIN/comb_str atom_lkg.alc bblk_lkg.alc $bname.alc";
