Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8919759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:06:21+00:00 2026-06-15T06:06:21+00:00

I have a text file as shown below ATOM 920 CA GLN A 203

  • 0

I have a text file as shown below

ATOM    920  CA  GLN A 203      39.292 -13.354  17.416  1.00 55.76           C 
ATOM    929  CA  HIS A 204      38.546 -15.963  14.792  1.00 29.53           C
ATOM    939  CA  ASN A 205      39.443 -17.018  11.206  1.00 54.49           C  
ATOM    947  CA  GLU A 206      41.454 -13.901  10.155  1.00 26.32           C
ATOM    956  CA  VAL A 207      43.664 -14.041  13.279  1.00 40.65           C 
.
.
.

ATOM    963  CA  GLU A 208      45.403 -17.443  13.188  1.00 40.25           C  

I would like to calculate the distance between two alpha carbon atoms i.e calculate the distance between first and second atom and then between second and third atom and so on….. The distance between two atoms can be expressed as:distance = sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2) .

The columns 7,8 and 9 represents x,y and z co-ordinates respectively.I need to print the distance and the corresponding residue pairs(column 4) as shown below.(the values of distance are not real)

GLN-HIS   4.5
HIS-ASN   3.2
ASN-GLU   2.5

How can I do this calculation with perl or python?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T06:06:21+00:00Added an answer on June 15, 2026 at 6:06 am

    If your data is separated by whitespace, a simple split can do the job. Buffering the lines to compare them to each other sequentially.

    use strict;
    use warnings;
    
    my @line;
    while (<>) {
        push @line, $_;            # add line to buffer
        next if @line < 2;         # skip unless buffer is full
        print proc(@line), "\n";   # process and print 
        shift @line;               # remove used line 
    }
    
    sub proc {
        my @a = split ' ', shift;   # line 1
        my @b = split ' ', shift;   # line 2
        my $x = ($a[6]-$b[6]);      # calculate the diffs
        my $y = ($a[7]-$b[7]);
        my $z = ($a[8]-$b[8]);
        my $dist = sprintf "%.1f",                # format the number
                       sqrt($x**2+$y**2+$z**2);   # do the calculation
        return "$a[3]-$b[3]\t$dist"; # return the string for printing
    }
    

    Output (with the sample data):

    GLN-HIS 3.8
    HIS-ASN 3.8
    ASN-GLU 3.9
    GLU-VAL 3.8
    

    If your data is tab separated, you can split on /\t/ instead of ' '.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file (called print_1012720.txt ) that looks like the text shown below.
hey i have text file shown as below. 11/2/2010     cat    6 11/2/2010   
I have a text file as shown below. I need only PDB IDs after
I have a pipe delimited text file as shown below, which I need to
I have a file name foo. That file contains some text (shown below). Can
i have text files as shown below ex: file 1: yamaha gladiator bike file
I have a text file which contains protein sequences(200 sequences) as shown below. >ptn1
This is the data in my text file: (I have shown 10 rows out
I have a text file, I am told the delimiter is as quoted below.
I have a XML file with the structure as shown below: <x> <y/> <y/>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.