root / ase / io / sdf.py @ 17
Historique | Voir | Annoter | Télécharger (591 octet)
1 |
from math import pi, cos, sin, sqrt, acos |
---|---|
2 |
|
3 |
from ase.atoms import Atoms |
4 |
from ase.parallel import paropen |
5 |
|
6 |
def read_sdf(fileobj): |
7 |
if isinstance(fileobj, str): |
8 |
fileobj = open(fileobj)
|
9 |
|
10 |
lines = fileobj.readlines() |
11 |
# first three lines header
|
12 |
del lines[:3] |
13 |
|
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)
|