Reputation: 1
I am very new to python. I have an xyz file that has the coordinates of all atoms in my system. my system consists of a few different molecules made from these atoms. I need to count the number of different molecules in this system, for eaxmple, the total number of molecule A, the total number of Molecule B, etc. I have included a snapshot of the file. The orange, yellow, and blue are the different molecules- similar to the orange section ( the PBIIII molecule) I also have a few that are PBIII. How can count the different molecules for each type from an xyz file?enter image description here
Upvotes: 0
Views: 324
Reputation: 531
import csv
elements = []
with open("compound.xyz", 'r') as csvfile:
csvreader = csv.reader(csvfile)
for i, row in enumerate(csvreader):
if i > 1:
elements.append(row[0].split()[0])
elementnames = set(elements)
counts = []
for elementname in elementnames:
counts.append(elements.count(elementname))
zipped = list(zip(elementnames, counts))
print(zipped)
Upvotes: 0