SharedProjectRosa / Molecules / inlezen.pyOpen in CoCalc
import sys

filename = sys.argv[1] #leest eerste xyz file in
datafile = open(filename)

lines = list(datafile.readlines())

initial_molecule=[]

for line in lines: #lines bestaat uit een lijst met elk atoom en zijn coordinaten als apart element in deze lijst
    initial_molecule.append(map(str, line.split()))

molecule_length=[]
molecule_length.append(int(lines.pop(0).rstrip()))

initial_molecule.pop(0)
initial_molecule.pop(0)

#print (initial_molecule)
#print (molecule_length)
list_letters = []

for lijsten in initial_molecule:
    list_letters.append(lijsten[0])

coordinates={}
    
for unique_letter in sorted(set(list_letters)):
    coordinates[unique_letter] = []

#print (initial_molecule)
print ("\n")


for lijsten in initial_molecule:
    lijsten[1:4] = [' '.join(lijsten[1:4])]
    lijsten[1]= lijsten[1].split()
    for index, elementen in enumerate(lijsten[1]):
        lijsten[1][index] = float(elementen)
        
#print (initial_molecule) 

for key in coordinates:
    for index, lists in enumerate(initial_molecule):
        if key == lists[0]:
            coordinates[key].append(lists[1])
            initial_molecule.pop(index)

print (coordinates)











#coordinaten= {"c":[["x","y","z"]]}