in reply to Re: XYZ Manipulation
in thread XYZ Manipulation

I obtained parts of it from
http://stackoverflow.com/questions/20741484/calculating-distance-betwe +en-atoms-by-atomic-coordinates?rq=1
. <> Replaced. I got error messages with  print ....., as well as  print......, ; as well as their printf deviations. Updated original post with corrections. The getting stuck part makes sense, however. Thanks.

Replies are listed 'Best First'.
Re^3: XYZ Manipulation
by Aldebaran (Curate) on Jun 16, 2015 at 08:27 UTC

    Hello jck, as I look at the code on the link and the code on this node, I see discrepancies. At some point, you can't go back and "fix" the original post, as it appears you're trying to reconcile 2 distance functions which are similar in that they both measure distance, but dissimilar in that they have different variables and indices. It's nothing that can't be ironed out, but at some point, you're gonna have to choose what you're gonna go with, so that we can all be on the same page. Let's take a look at the main control of your (updated?) original post:

    for my $i (0 .. $#data) { for my $j (0 .. $#data) { next if $i == $j; my @coords_i = @{$data[$i]}[1,2,3]; my @coords_j = @{$data[$j]}[1,2,3]; print OUT "%s to %s Distance-%.5f\n", ####( ; )?? $data[$i][1], $data[$j][1], $data[$i][11], $data[$j][11], distance(\@coords_i, \@coords_j); } }

    We have an explicit double loop, which will allow the ordered enumeration you desire to occur, but I can see that it goes over the entire array twice, which doesn't gybe with the fields at the link you posted. When I run your program, I get this to confirm my suspicion:

    C:\Users\Fred\Desktop\pm>perl dis1.pl Argument "CA" isn't numeric in subtraction (-) at dis1.pl line 38, <IN +> line 4 ( #1) (W numeric) The indicated string was fed as an argument to an oper +ator that expected a numeric value instead. If you're fortunate the me +ssage will identify which operator was so unfortunate. Argument "N" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Argument "MSE" isn't numeric in subtraction (-) at dis1.pl line 38, <I +N> line 4 (#1) Argument "C" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Argument "O" isn't numeric in subtraction (-) at dis1.pl line 38, <IN> + line 4 (# 1) Done.

    That's perl saying "you can't subtract strings." You need to adjust your indices. If you showed your actual input, actual script, and actual output between code tags on perlmonks, then I'm pretty sure that your troubles are ephemeral. Other than that, you're not all that far from what you want because the output is well-formed:

    %s to %s Distance-%.5f 12NC1%s to %s Distance-%.5f 13NC2%s to %s Distance-%.5f 14NO3%s to %s Distance-%.5f 21CN1%s to %s Distance-%.5f 23CC1%s to %s Distance-%.5f 24CO2%s to %s Distance-%.5f 31CN2%s to %s Distance-%.5f 32CC1%s to %s Distance-%.5f 34CO1%s to %s Distance-%.5f 41ON3%s to %s Distance-%.5f 42OC2%s to %s Distance-%.5f 43OC1

    Best of luck and many happy adventures with perl.