File: mol.py

package info (click to toggle)
python-ase 3.12.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,192 kB
  • ctags: 8,112
  • sloc: python: 93,375; sh: 99; makefile: 94
file content (20 lines) | stat: -rw-r--r-- 544 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
"""Reads chemical data in MDL Molfile format. 

See https://en.wikipedia.org/wiki/Chemical_table_file
"""
from ase.atoms import Atoms


def read_mol(fileobj):
    lines = fileobj.readlines()
    del(lines[:3])
    L1 = lines[0].split()
    del(lines[0])
    natoms = int(L1[0])
    positions = []
    symbols = []
    for line in lines[:natoms]:
            x, y, z, symbol = line.split()[:4]
            symbols.append(symbol)
            positions.append([float(x), float(y), float(z)])
    return Atoms(symbols=symbols, positions=positions)