Statistiques
| Révision :

root / ase / io / vnl.py @ 19

Historique | Voir | Annoter | Télécharger (1,01 ko)

1
import numpy as np
2

    
3
from ase.atoms import Atoms
4

    
5

    
6
class VNL:
7
    def __setstate__(self, data):
8
        self.data = data
9

    
10
def ac(shape, typecode, data, endian):
11
    x = np.fromstring(data, typecode)
12
    try:
13
        x.shape = shape
14
    except ValueError:
15
        x = x[::2].copy()
16
        x.shape = shape
17
        
18
    if np.LittleEndian != endian: 
19
        return x.byteswap() 
20
    else: 
21
        return x 
22

    
23
class VNLUnpickler(pickle.Unpickler):
24
    def find_class(self, module, name):
25
        if module == 'VNLATKStorage.Core.Sample':
26
            return VNL
27
        if name == 'array_constructor':
28
            return ac
29
        return pickle.Unpickler.find_class(self, module, name)
30
    
31
def read_vnl(filename):
32
    from cStringIO import StringIO
33
    vnl = VNLUnpickler(StringIO(ZipFile(filename).read('0_object'))).load()
34
    conf = vnl.data['__properties__']['Atomic Configuration'].data
35
    numbers = conf['_dataarray_']
36
    positions = conf['_positions_'].data['_dataarray_']
37
    return Atoms(numbers=numbers, positions=positions)