0

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

  • What's a way to distinguish between molecules using just the dataset? – Ashok Arora May 12 '21 at 21:07
  • molecule A will have a unique atom- O , molecule B will contain a unique atom- N4. The others are tricky, they contain the same atom types, just different numbers of the, for example, PbII, PbIII, PbIII. The Pb-I distance if it is part of that molecule will be less than 3 angstroms – user15726128 May 12 '21 at 21:26

1 Answers1

0
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)
Eftal Gezer
  • 191
  • 1
  • 8