Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""Reads chemical data in SDF format (wraps the molfile format). 

2 

3See https://en.wikipedia.org/wiki/Chemical_table_file#SDF 

4""" 

5from ase.atoms import Atoms 

6from ase.utils import reader 

7 

8 

9@reader 

10def read_sdf(fileobj): 

11 lines = fileobj.readlines() 

12 # first three lines header 

13 del lines[:3] 

14 

15 L1 = lines.pop(0).split() 

16 natoms = int(L1[0]) 

17 positions = [] 

18 symbols = [] 

19 for line in lines[:natoms]: 

20 x, y, z, symbol = line.split()[:4] 

21 symbols.append(symbol) 

22 positions.append([float(x), float(y), float(z)]) 

23 return Atoms(symbols=symbols, positions=positions)