I have to access a file and count the number of atoms of each element. That is, count the number of times of the last character.
For example, I have a file named 14ly.pdb with the following lines:
ATOM 211 N TYR A 27 4.697 8.290 -3.031 1.00 13.35 N
ATOM 212 CA TYR A 27 5.025 8.033 -1.616 0.51 11.29 C
ATOM 214 C TYR A 27 4.189 8.932 -0.730 1.00 10.87 C
ATOM 215 O TYR A 27 3.774 10.030 -1.101 1.00 12.90 O
I should get as a result: 'N':1, 'C':2, 'O':1
, that is, 1 atom of type N, 2 of type C and 1 of type O.
I have the following incomplete code that I need to complete:
import os
def count_atoms(pdb_file_name):
num_atoms = dict()
with open(pdb_file_name) as file_content:
##Here should go the code I need##
return num_atoms
result = count_atoms('14ly.pdb')
print(result)