jcklasseter has asked for the wisdom of the Perl Monks concerning the following question:
and I'm trying to analyze the distance between the xyz coordinates located betweenSCF DONE 1.000000000000000 30.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 30.0000000000000000 0.0000000000000000 0.0000000000000000 0.0000000000000000 30.0000000000000000 Ti O 2 4 Direct 0.6464566666666656 0.6448333333333309 0.6278799999999976 0.6868766666666630 0.6884999999999977 0.7054533333333310 0.6853766666666701 0.6920033333333322 0.6431533333333306 0.7078133333333341 0.7139733333333353 0.7533000000000030 0.6234800000000007 0.6190766666666647 0.5814200000000014 0.6493600000000015 0.6410499999999999 0.6899299999999968 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00 0.00000000E+00
andDirect
So far, this is what I have.0.00000000E+00
In the output file, this :#!/usr/bin/perl use strict; use warnings; use diagnostics; my $source = "./CONTCAR"; my $destination = "./OUTPUT"; open(IN, '<', $source) or die "Couldn't open $source: $!\n"; open(OUT, '>', $destination) or die "Couldn't write to $destinatio +n: $!\n"; my @data = map [ split ], grep /\S/, <IN>; foreach (@data) { print "$_\n"; } for my $i (0 .. $#data) { for my $j (0 .. $#data) { next if $i == $j; my @coords_i = @{$data[$i]}[0,1,2]; my @coords_j = @{$data[$j]}[0,1,2]; printf OUT "%s to %s Distance=%.5f\n", $data[$i][0], $data[$j][0], $data[$i][2], $data[$j][2], distance(\@coords_i, \@coords_j); } } sub distance { my ($aa, $bb) = @_; my ($x, $y, $z) = map { $aa->[$_] - $bb->[$_] } 0 .. $#$aa; return sqrt(($x - $x)**2 + ($y - $y)**2 + ($z - $z)**2); } close IN; close OUT; print "Done.\n";
is printed. I'm not quite sure if I'm calling the distance wrong, or if my formula is messed up, or all of the above. Any help is appreciated. EDIT: I know the script I have won't analyze the sample input I gave. I have a test file (./CONTCAR) that is literally justto 2 Distance=1.00000 1 to 3 Distance=1.00000 1 to 4 Distance=1.00000 1 to 5 Distance=1.00000 2 to 1 Distance=2.00000 2 to 3 Distance=2.00000 2 to 4 Distance=2.00000 2 to 5 Distance=2.00000 3 to 1 Distance=3.00000 3 to 2 Distance=3.00000 3 to 4 Distance=3.00000 3 to 5 Distance=3.00000 4 to 1 Distance=4.00000 4 to 2 Distance=4.00000 4 to 3 Distance=4.00000 4 to 5 Distance=4.00000 5 to 1 Distance=5.00000 5 to 2 Distance=5.00000 5 to 3 Distance=5.00000 5 to 4 Distance=5.00000
To try and get the main loop even working. EDIT: Updated info1 2 3 1 2 3 1 2 3 1 2 3
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XYZ Manipulation
by toolic (Bishop) on Jun 15, 2015 at 17:14 UTC | |
by jcklasseter (Sexton) on Jun 15, 2015 at 17:48 UTC | |
by toolic (Bishop) on Jun 15, 2015 at 17:59 UTC | |
by jcklasseter (Sexton) on Jun 15, 2015 at 18:07 UTC | |
|
Re: XYZ Manipulation
by BrowserUk (Patriarch) on Jun 15, 2015 at 17:21 UTC | |
by jcklasseter (Sexton) on Jun 15, 2015 at 17:54 UTC | |
by Aldebaran (Curate) on Jun 16, 2015 at 08:27 UTC | |
|
Re: XYZ Manipulation
by RichardK (Parson) on Jun 15, 2015 at 17:18 UTC | |
by jcklasseter (Sexton) on Jun 15, 2015 at 17:49 UTC | |
|
Re: XYZ Manipulation
by salva (Canon) on Jun 16, 2015 at 08:15 UTC | |
|
Re: XYZ Manipulation
by segaknight (Initiate) on Jun 16, 2015 at 16:55 UTC | |
|
Re: XYZ Manipulation
by segaknight (Initiate) on Jun 16, 2015 at 16:30 UTC |