As part of parsing a PDB file, I've extracted a set of coordinates (x, y, z) for particular atoms that I want to exist as floats. However, I also need to know how many sets of coordinates I have extracted.
Below is my code through the coordinate extraction, and what I thought would produce the count of how many sets of three coordinates I've extracted.
When using len(coordinates), I unfortunately get back that each set of coordinates contains 3 tuples (the x, y, and z coordinates.
Any insight into how to properly count the number of sets would be helpful. I'm quite new to Python and am still in the stage of being unsure about if I am even asking this correctly!
from sys import argv
with open(argv[1]) as pbd:
print()
for line in pbd:
if line[:4] == 'ATOM':
atom_type = line[13:16]
if atom_type == "CA" or "N" or "C":
x = float(line[31:38])
y = float(line[39:46])
z = float(line[47:54])
coordinates = (x, y, z)
# printing (coordinates) gives
# (36.886, 53.177, 21.887)
# (38.323, 52.817, 21.996)
# (38.493, 51.553, 22.83)
# (37.73, 51.314, 23.77)
print(len(coordinates))
# printing len(coordinates)) gives
# 3
# 3
# 3
# 3
Thank you for any insight!