I have an .xyz file of H2S and if I read the file like so:
with open('H2S.xyz','r') as stream:
for line in stream:
print(line)
I get this:
3
XYZ file of the hydrogen sulphide molecule
S 0.00000000 0.00000000 0.10224900
H 0.00000000 0.96805900 -0.81799200
H 0.00000000 -0.96805900 -0.81799200
The first line gives the number of atoms and the last 3 lines the coordinates of those atoms.
I am supposed to write some code to extract the position of each atom in the molecule, in the form of a list where each element is another list with the atom coordinates.
If I do this:
with open('H2S.xyz','r') as stream:
new=list(stream)
new
I get each line as an element in the list, and if I do this:
with open('H2S.xyz','r') as stream:
new_list=[]
for line in stream:
new_list=new_list+line.split()
new_list
I get every single element seperately:
['3','XYZ','file','of','the','hydrogen','sulphide','molecule','S',
'0.00000000','0.00000000','0.10224900','H','0.00000000','0.96805900',
'-0.81799200','H','0.00000000','-0.96805900','-0.81799200']
Which I don't want. The list I want looks like this:
[['0.00000000','0.00000000','0.10224900'],
['0.00000000','0.96805900','-0.81799200'],
['0.00000000','-0.96805900','-0.81799200']]
But I'm not sure how to code for this.