program to calculate distance between 5 atoms


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting program to calculate distance between 5 atoms
# 1  
Old 10-01-2008
program to calculate distance between 5 atoms

Hello,

I am a beginner with perl. I have a perl program to calculate the distance between 5 atoms or more.

i have an array which looks like this:
6.324 32.707 50.379
5.197 32.618 46.826
4.020 36.132 46.259
7.131 38.210 45.919
6.719 38.935 42.270
2.986 39.221 41.892
-0.269 37.184 41.565

I want to assign these values with Xi(column 1), Yi(column 2)and Zi(column 3). Suppose the first row values are (Xi,Yi,Zi), then the second row values will be (Xj, Yj, Zj) I want to calculate the distance using the formula

$dist = sqrt(($Xi-$Xj)**2+($Yi-$Yj)**2+($Zi-$Zj)**2) between row1/row2, row1/row3, row1/row4 ......so on.... till row6/row7

so its an iterative calculation. probably i shud us a for loop, and another forloop within the previous for loop. i am totally stuck.

till now my perl program looks like this:

open(IN, "/Users/anu/out.pl") or die "$!";
while (my $line = <IN>) {
chomp($line);
my @array = (split (/\s+/, $line))[6, 7, 8];
print "@array\n";
}
close(IN);


I dnt know wat to do..please help

Thank you
# 2  
Old 10-01-2008
I use PHP, you can convert to Perl easily
Code:
<?php
$file = "file";
$handle = fopen($file,"r");
$base = explode(" ",trim(fgets($handle))); #get first line, put them into array

# get the rest of the line
while( !feof($handle)){
  $line = explode(" ",trim(fgets($handle,4096))); #put them to array 
  # do the formula
  $formula = sqrt(  sqrt( abs($base[0] - $line[0] ) ) +  sqrt( abs($base[1] - $line[1]))  + sqrt ( abs($base[2] - $line[2] ) ) );
  echo "formula $formula\n";  
}
fclose($handle);
?>

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Calculate average, azimut and distance

Gents, Please i will to get the distance and azimut from 2 coordinates: Usig excel formula i get the correct values, but i will like to do it using awk. Example A 35089.0 50345.016 9 75 1 2101774 77 70 79 483911.6 2380106.9 137.4 1 1 6 1 A 35089.0 50345.01620 75... (8 Replies)
Discussion started by: jiam912
8 Replies

2. Shell Programming and Scripting

finding distance between numbers

Hi, I have a file as ABC 1634230,1634284,1634349,1634468 1634272,1634301,1634356,1634534 What I want is to find distance between the numbers.. column 1 is the gene name and column 2 are starts and column 3 are their respective stops for the starts. So what I want is column 3 which has +1... (2 Replies)
Discussion started by: Diya123
2 Replies

3. Shell Programming and Scripting

Program to calculate the operation from file

Hi I have the file has some formulas how to create a program (per, ksh, awk) which calculate the operation and put the result on other file example data of source file - this has separate by ";"... (5 Replies)
Discussion started by: Miguel Gonzalez
5 Replies

4. Shell Programming and Scripting

Calculate age of a file | calculate time difference

Hello, I'm trying to create a shell script (#!/bin/sh) which should tell me the age of a file in minutes... I have a process, which delivers me all 15 minutes a new file and I want to have a monitoring script, which sends me an email, if the present file is older than 20 minutes. To do... (10 Replies)
Discussion started by: worm
10 Replies

5. UNIX for Dummies Questions & Answers

How to make a distance matrix

Hi, I'm trying to generate a distance matrix between sample pairs for use in a tree-drawing program (example below). The example below demonstrates what I'd like to get out of the data - essentially, to calculate the proportion of positions where two samples differ. Any help much appreciated!... (1 Reply)
Discussion started by: auburn
1 Replies

6. Shell Programming and Scripting

Calculate distance and azimuth

Hi all, I have a data file like this lat lon lat lon 12.000 25.125 14.235 25.012 14.200 81.000 25.584 25.014 45.023 25.365 25.152 35.222 I want to calculate distance and azimuth between this points eg:- 12.000,25.125 and 14.235,25.012 I want to use awk programming... (3 Replies)
Discussion started by: chamara
3 Replies

7. Shell Programming and Scripting

AWK code for finding distances between atoms in two different files

Hi:) I have two separate data files (.xyz) type and I want to see distances between the coordinates of atoms of the two files. For example:- My first files contains 1 1 1 11.50910000 5.17730000 16.49360000 3 1 2 11.21790000 6.36062000 15.60660000 6 1 2 ... (4 Replies)
Discussion started by: ananyob
4 Replies

8. UNIX for Dummies Questions & Answers

Script producing error, Program to calculate maximum number

Hi folks, Here i have written a shell script to calculate a maximum number from 10 numbers entered on command line. max=0 echo Enter 10 numbers , one at a time for i in 1 2 3 4 5 6 7 8 9 10 do read n max=`expr $max + $n` if --- At this last step there is some problem, it gives error... (5 Replies)
Discussion started by: rits
5 Replies

9. Programming

Converting distance list to distance matrix in R

Hi power user, I have this type of data (distance list): file1 A B 10 B C 20 C D 50I want output like this # A B C D A 0 10 30 80 B 10 0 20 70 C 30 20 0 50 D 80 70 50 0 Which is a distance matrix I have tried... (0 Replies)
Discussion started by: anjas
0 Replies
Login or Register to Ask a Question