Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Calc distance between atoms in pdb file

by BrowserUk (Patriarch)
on Apr 29, 2012 at 13:10 UTC ( [id://967931]=note: print w/replies, xml ) Need Help??


in reply to Calc distance between atoms in pdb file

"Use of uninitialized value in subtraction (-) at ./gas.pl line 42, <> line 14368" The line that it states is the last line of the pdb file, however i don't see why this line is involved in my calculations as this is not present in any of my arrays.

This: <> line 14368" is not relevant to the actual error. It simply mean that is the last line that was read from the last still open file. Perl appends it to the error message because the file is still open, and it might therefore be relevant. In this case, it isn't.

You can suppress that part of the error messages by close open files when you are done with them. In this case, the open file is the implicit file handle opened by the use of the diamond operator (while( <> ). To close it, follow the loop with:

# Count number of atoms if ($_ =~ /^ATOM/) { ++$count; } } close *ARGV; ## Add this.

The reason why you are getting the "uninitialised value" warnings is because your for loops are running off the end of your arrays.

The variable $count counts the number of elements in the arrays, but the indexes run from 0; so the last index will be one less than the number of elements!

Ie. An array that contains the 10 values 1 .. 10, will have indexes 0 .. 9:

@a = 1 .. 10; $a[0] = 1; $a[1] = 2; $a[2] = 3; ... $a[8] = 9; $a[9] = 10;

So, to prevent the error detected by the warnings, your for loops should run from 0 to $count - 1. Ie:

# Calculate distance between all atom coordinates foreach $i ( 0 .. $count-1 ) { foreach $j ( $i + 1 .. $count-1 ) { $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); print "$dist\n"; } }

That should get you going. There are several other changes that would make your life easier, but I'll leave that for other posts.

One thing that intrigues me though. How did @line get transmuted into (at)line in your post?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://967931]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-04-19 11:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found