Statistiques
| Révision :

root / ase / io / plt.py @ 15

Historique | Voir | Annoter | Télécharger (884 octet)

1
import numpy as np
2

    
3
from ase.atoms import Atoms
4

    
5
def write_plt(filename, atoms, data):
6
    if isinstance(atoms, Atoms):
7
        cell = atoms.get_cell()
8
    else:
9
        cell = np.asarray(atoms, float)
10

    
11
    if cell.ndim == 2:
12
        c = cell.copy()
13
        cell = c.diagonal()
14
        c.flat[::4] = 0.0
15
        if c.any():
16
            raise ValueError('Unit cell must be orthorhombic!')
17

    
18
    f = open(filename, 'w')
19
    np.array([3, 4], np.int32).tofile(f)
20

    
21
    dims = np.array(data.shape, np.int32)
22
    dims[::-1].tofile(f)
23

    
24
    for n, L in zip(dims[::-1], cell[::-1]):
25
        if n % 2 == 0:
26
            d = L / n
27
            np.array([0.0, L - d], np.float32).tofile(f)
28
        else:
29
            d = L / (n + 1)
30
            np.array([d, L - d], np.float32).tofile(f)
31

    
32
    if data.dtype == complex:
33
        data = np.abs(data)
34
    data.astype(np.float32).T.tofile(f)
35
    f.close()