Perl: Calculating distance between atoms in pdb file?
-
Hi, I am creating a program that calculates the distance between the x, y, z coordinates of atoms listed in a pdb file. So far i have this: #!/usr/bin/perl -w $num = 0; $count = 0; while (<>) { # Find x, y, z coordinates and store in separate arrays if ($_ =~ /^ATOM/) { @line = $_ =~ m/^(.....).(.....).(....).(...)..(....).… $x = $line[5]; $arrayx[$num] = $x; $y = $line[6]; $arrayy[$num] = $y; $z = $line[7]; $arrayz[$num] = $z; ++$num; } # Count number of atoms if ($_ =~ /^ATOM/) { ++$count; } } # Calculate distance between all atom coordinates foreach $i (0..$count) { foreach $j ($i + 1..$count) { $dist = sqrt( ($arrayx[$i] - $arrayx[$j])**2 + ($arrayy[$i] - $arrayy[$j])**2 + ($arrayz[$i] - $arrayz[$j])**2 ); print "$dist\n" } } When I run the program i get this message popping up for some of the lines and I don't know what to do to fix it: "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. The pdb file I'm using is located here : http://www.rcsb.org/pdb/explore.do?structureId=3PBL Any help would be much appreciated as I am VERY new to Perl. Thanks
-
Answer:
First of all, add the following to the top of your program, it's common courtesy BEFORE coming here and bothering the world: use strict; use warnings; Second, what is line 42 of your program? Third, do you not know the most basic techniques of debugging? Add some "print" statements so you know what exactly is going on. Like what is the value of $i, $j, what exactly is in your array, etc.
monica at Yahoo! Answers Visit the source
Related Q & A:
- How to call shell script into perl?Best solution by Stack Overflow
- How to get line number from .NET pdb?Best solution by Stack Overflow
- How do you convert MOLES to MOLECULES? and MOLES to ATOMS?Best solution by Yahoo! Answers
- What type of bond exists between atoms?Best solution by Yahoo! Answers
- Can some atoms make both ionic and covalent bonds?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.