| Hosted by CoCalc | Download
1
import sys
2
3
filename = sys.argv[1] #leest eerste xyz file in
4
datafile = open(filename)
5
6
lines = list(datafile.readlines())
7
8
initial_molecule=[]
9
10
for line in lines: #lines bestaat uit een lijst met elk atoom en zijn coordinaten als apart element in deze lijst
11
initial_molecule.append(map(str, line.split()))
12
13
molecule_length=[]
14
molecule_length.append(int(lines.pop(0).rstrip()))
15
16
initial_molecule.pop(0)
17
initial_molecule.pop(0)
18
19
#print (initial_molecule)
20
#print (molecule_length)
21
list_letters = []
22
23
for lijsten in initial_molecule:
24
list_letters.append(lijsten[0])
25
26
coordinates={}
27
28
for unique_letter in sorted(set(list_letters)):
29
coordinates[unique_letter] = []
30
31
#print (initial_molecule)
32
print ("\n")
33
34
35
for lijsten in initial_molecule:
36
lijsten[1:4] = [' '.join(lijsten[1:4])]
37
lijsten[1]= lijsten[1].split()
38
for index, elementen in enumerate(lijsten[1]):
39
lijsten[1][index] = float(elementen)
40
41
#print (initial_molecule)
42
43
for key in coordinates:
44
for index, lists in enumerate(initial_molecule):
45
if key == lists[0]:
46
coordinates[key].append(lists[1])
47
initial_molecule.pop(index)
48
49
print (coordinates)
50
51
52
53
54
55
56
57
58
59
60
61
#coordinaten= {"c":[["x","y","z"]]}
62