Sanim Rahman
Sanim Rahman

Reputation: 11

How to extract lines that are within radius of cartesian coordinates

I have a data file that has the format of the following:

ATOM      4  N   ASP A   1     105.665  49.507  41.867  1.00 71.64           N  
ATOM      5  CA  ASP A   1     105.992  48.589  42.982  1.00 70.20           C  
ATOM      6  C   ASP A   1     107.024  49.191  43.936  1.00 69.70           C  

In row 1 the numbers (105.665, 49.507, and 41.867) are the columns of the coordinates (x,y,z). How do I extract the entire line with coordinates that are within a specified radius and output them in another file? The equation to correlate the coordinates to the radius is:

radius= SQRT(x^2 + y^2 +z^2)

Upvotes: 0

Views: 47

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207728

I think you mean this:

awk -v R=124.44 '($7^2)+($8^2)+($9^2) < R^2' YourFile

Change the R=124.44 to match your radius.

Sample Output

ATOM      4  N   ASP A   1     105.665  49.507  41.867  1.00 71.64           N  
ATOM      5  CA  ASP A   1     105.992  48.589  42.982  1.00 70.20           C 

Upvotes: 2

Related Questions