root / ase / io / iwm.py @ 1
Historique | Voir | Annoter | Télécharger (1,13 ko)
1 |
from math import pi, cos, sin, sqrt, acos |
---|---|
2 |
import numpy as np |
3 |
|
4 |
from ase.data import chemical_symbols |
5 |
from ase.atoms import Atoms |
6 |
from ase.parallel import paropen |
7 |
|
8 |
iwm_symbols = {'1' : 'C', |
9 |
'2' : 'Au', |
10 |
'5' : 'Ag'} |
11 |
|
12 |
def read_iwm(fileobj, index=-1): |
13 |
if isinstance(fileobj, str): |
14 |
fileobj = open(fileobj)
|
15 |
|
16 |
lines = fileobj.readlines() |
17 |
L1 = lines[1].split()
|
18 |
if len(L1) == 1: |
19 |
del lines[:3] |
20 |
natoms = int(L1[0]) |
21 |
else:
|
22 |
natoms = len(lines)
|
23 |
images = [] |
24 |
|
25 |
positions = [] |
26 |
symbols = [] |
27 |
for line in lines[:natoms]: |
28 |
symbol, mass, x, y, z = line.split()[:5]
|
29 |
if symbol in iwm_symbols: |
30 |
symbols.append(iwm_symbols[symbol]) |
31 |
else:
|
32 |
symbols.append(chemical_symbols[int(symbol)])
|
33 |
positions.append([float(x), float(y), float(z)]) |
34 |
|
35 |
del(lines[natoms:3 * natoms + 3]) |
36 |
|
37 |
cell = [] |
38 |
for line in lines[natoms:natoms+3]: |
39 |
x, y, z = line.split()[:3]
|
40 |
cell.append(np.array([float(x), float(y), float(z)])) |
41 |
|
42 |
images.append(Atoms(symbols=symbols, positions=positions, cell=cell)) |
43 |
|
44 |
return images[index]
|
45 |
|