in reply to Calc distance between atoms in pdb file
Here's a somewhat simpler and more idiomatic version of your code that does the same thing that may help you. Ask about anything you do not understand:
#!/usr/bin/perl -w use strict; my( @arrayx, @arrayy, @arrayz ); while (<>) { # Find x, y, z coordinates and store in separate arrays if ($_ =~ /^ATOM/) { my @line = $_ =~ m/^(.....).(.....).(....).(...)..(....)....(. +.......)(........)(........)/; ## using push mean you don't have to count because ... push @arrayx, $line[5]; push @arrayy, $line[6]; push @arrayz, $line[7]; } } close *ARGV; ## prevent confusing error message suffixes # Calculate distance between all atom coordinates ## ... $#xxx gives you the highest index in array @xxx foreach my $i ( 0 .. $#arrayx ) { foreach my $j ( $i + 1 .. $#arrayx ) { my $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); ## Adding $i and $j to your output will let you know what that + output is. print "$i <> $j : $dist\n"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Calc distance between atoms in pdb file
by Anonymous Monk on Nov 14, 2016 at 11:06 UTC | |
by soonix (Chancellor) on Nov 14, 2016 at 11:17 UTC | |
by Anonymous Monk on Nov 14, 2016 at 15:57 UTC | |
|
Re^2: Calc distance between atoms in pdb file
by Anonymous Monk on Nov 14, 2016 at 15:58 UTC |