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 MDL Molfile format.
3See https://en.wikipedia.org/wiki/Chemical_table_file
4"""
5from ase.atoms import Atoms
8def read_mol(fileobj):
9 lines = fileobj.readlines()
10 L1 = lines[3]
12 # The V2000 dialect uses a fixed field length of 3, which means there
13 # won't be space between the numbers if there are 100+ atoms, and
14 # the format doesn't support 1000+ atoms at all.
15 if L1.rstrip().endswith('V2000'):
16 natoms = int(L1[:3].strip())
17 else:
18 natoms = int(L1.split()[0])
19 positions = []
20 symbols = []
21 for line in lines[4:4 + natoms]:
22 x, y, z, symbol = line.split()[:4]
23 symbols.append(symbol)
24 positions.append([float(x), float(y), float(z)])
25 return Atoms(symbols=symbols, positions=positions)