Entering edit mode
4.4 years ago
srdjanmasirevic2
▴
10
I have used bash so far to generate two files:
File one
contains coordinates of C atoms of protein divided by space:
C2[0] C2[1] C2[2]
13.717 10.109 8.591
13.306 9.421 7.294
12.004 8.673 7.519
13.163 10.412 6.155
15.876 11.528 12.222
17.300 11.385 12.712
14.936 10.789 13.182
13.481 10.875 12.771
12.703 11.969 13.122
12.890 9.875 12.010
11.376 12.078 12.725
11.556 9.961 11.612
10.803 11.067 11.970
19.044 12.341 14.078
19.906 12.922 12.973
File two
contains C atom coordinates of the ligand:
C1[0] C1[1] C1[2]
0.510 -3.329 3.463
1.664 -2.694 4.189
1.864 -6.031 5.380
2.956 -6.810 4.984
4.038 -7.028 5.832
1.887 -5.446 6.650
2.974 -5.663 7.501
4.066 -6.436 7.093
5.204 -6.724 8.010
6.532 -6.775 7.600
7.539 -7.095 8.513
7.222 -7.396 9.831
5.894 -7.377 10.238
4.894 -7.058 9.331
How could I use foreach loop in python to calculate the distance of first line in file two
, to each line in file one
(this would generate 15 numbers as there are 15 lines in file one);
then second line of file two
, to each line in file one
.
To calculate the distance I need to use:
import math
def distance(c1, c2):
x_dist = (c1[0] - c2[0])**2
y_dist = (c1[1] - c2[1])**2
z_dist = (c1[2] - c2[2])**2
return math.sqrt(x_dist + y_dist + z_dist)
Now how to put the formula into foreach loop?
Does the approach here solve what you're trying to do?: C: Biopython to compute the distance between residues
The code in that comment will calculate all the pairwise differences, you would just need to modify the code to use elements other than the alpha Carbon, if that's what you want to do.
You can parse directly from your file if you like instead of going from the PDB file as I did.