HackaMol

 view release on metacpan or  search on metacpan

examples/Capsid/capsid.pl  view on Meta::CPAN

######################################################################
#  capsid.pl
#
#  generate all coordinates for a viral capsid (1QGT)
#
######################################################################
use Modern::Perl;
use HackaMol;
use Math::Vector::Real;

my $pdbid = '1QGT';

my $mol = HackaMol->new()->pdbid_mol($pdbid);

my @symops = <DATA>;

my %sym_op = (); # a hash to store all symmetry operations
foreach my $line ( grep {m/BIOMT|SMTRY/} @symops ) {
    my @entries = split(' ', $line);
    push @{$sym_op{$entries[3]}}, V(@entries[4,5,6,7]);
}

# let's create a another molecule containing Hg atoms to map out a coarser represention of the capsid
my $hg_ball = HackaMol::Molecule->new(name => 'Hg Ball') ;

foreach my $symop (keys %sym_op){
    my @mat_d = @{$sym_op{$symop}};
    my $cx = V(map{$_->[0]} @mat_d); 
    my $cy = V(map{$_->[1]} @mat_d);
    my $cz = V(map{$_->[2]} @mat_d);
    my $dxyz = V(map{$_->[3]} @mat_d);
# hg
    my $COM = $mol->COM; # center of mass
    my $COM_transform = $COM->[0]*$cx + $COM->[1]*$cy + $COM->[2]*$cz + $dxyz;
    $hg_ball->push_atoms( HackaMol::Atom->new(symbol => 'Hg', coords =>[$COM_transform]));
# the protein
    foreach my $atom ($mol->all_atoms){
        my ($x,$y,$z) = @{$atom->xyz};
        my $xyz_new = $x*$cx + $y*$cy + $z*$cz + $dxyz;  
        $atom->push_coords($xyz_new);
    }    
}

# add a hg to the middle of the capsid using the Hg representation
my $hg      = HackaMol::Atom->new(symbol => 'Hg', coords =>[ $hg_ball->COM ] );
$hg_ball->push_atoms($hg);  # push on the center of mass Hg

$hg_ball->print_xyz;

foreach my $t (1 .. $mol->tmax) {
    $mol->t($t);
    say "$pdbid\_$t.pdb";
    $mol->print_pdb("$pdbid\_$t.pdb"); 
}

__DATA__
REMARK 350   BIOMT1   1  1.000000  0.000000  0.000000        0.00000            
REMARK 350   BIOMT2   1  0.000000  1.000000  0.000000        0.00000            
REMARK 350   BIOMT3   1  0.000000  0.000000  1.000000        0.00000            
REMARK 350   BIOMT1   2  0.458930 -0.507750  0.729091        0.00000            
REMARK 350   BIOMT2   2  0.846163  0.500000 -0.184413        0.00000            
REMARK 350   BIOMT3   2 -0.270909  0.701562  0.659104        0.00000            
REMARK 350   BIOMT1   3 -0.416540  0.024606  0.908784        0.00000            
REMARK 350   BIOMT2   3  0.861370 -0.309017  0.403175        0.00000            
REMARK 350   BIOMT3   3  0.290750  0.950738  0.107523        0.00000            
REMARK 350   BIOMT1   4 -0.416540  0.861370  0.290750        0.00000            
REMARK 350   BIOMT2   4  0.024606 -0.309017  0.950738        0.00000            



( run in 0.542 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )