File: iwm.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 (43 lines) | stat: -rw-r--r-- 1,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import numpy as np

from ase.data import chemical_symbols
from ase.atoms import Atoms

iwm_symbols = {'1': 'C',
               '2': 'Au',
               '5': 'Ag'}


def read_iwm(fileobj, index=-1):
    if isinstance(fileobj, str):
        fileobj = open(fileobj)

    lines = fileobj.readlines()
    L1 = lines[1].split()
    if len(L1) == 1:
        del lines[:3]
        natoms = int(L1[0])
    else:
        natoms = len(lines)
    images = []

    positions = []
    symbols = []
    for line in lines[:natoms]:
        symbol, mass, x, y, z = line.split()[:5]
        if symbol in iwm_symbols:
            symbols.append(iwm_symbols[symbol])
        else:
            symbols.append(chemical_symbols[int(symbol)])
        positions.append([float(x), float(y), float(z)])
    
    del(lines[natoms:3 * natoms + 3])
    
    cell = []
    for line in lines[natoms:natoms + 3]:
        x, y, z = line.split()[:3]
        cell.append(np.array([float(x), float(y), float(z)]))
      
    images.append(Atoms(symbols=symbols, positions=positions, cell=cell))

    return images[index]