コード例 #1
0
def test_array_shape(at):
    # Check that unashable data type in info does not break output
    at.info['bad-info'] = [[1, np.array([0, 1])], [2, np.array([0, 1])]]
    with no_warn():
        ase.io.write('to.xyz', at, format='extxyz')
    del at.info['bad-info']
    at.arrays['ns_extra_data'] = np.zeros((len(at), 1))
    assert at.arrays['ns_extra_data'].shape == (2, 1)

    ase.io.write('to_new.xyz', at, format='extxyz')
    at_new = ase.io.read('to_new.xyz')
    assert at_new.arrays['ns_extra_data'].shape == (2, )
コード例 #2
0
ファイル: extxyz.py プロジェクト: shuchingou/ase
import os

import numpy as np

import ase.io
from ase.io import extxyz
from ase.atoms import Atoms
from ase.build import bulk
from ase.test.testsuite import no_warn

# array data of shape (N, 1) squeezed down to shape (N, ) -- bug fixed
# in commit r4541
at = bulk('Si')
# Check that unashable data type in info does not break output
at.info['bad-info'] = [[1, np.array([0, 1])], [2, np.array([0, 1])]]
with no_warn():
    ase.io.write('to.xyz', at, format='extxyz', tolerant=True)
del at.info['bad-info']
at.arrays['ns_extra_data'] = np.zeros((len(at), 1))
assert at.arrays['ns_extra_data'].shape == (2, 1)

ase.io.write('to_new.xyz', at, format='extxyz')
at_new = ase.io.read('to_new.xyz')
assert at_new.arrays['ns_extra_data'].shape == (2, )

os.unlink('to.xyz')
os.unlink('to_new.xyz')

#test comment read/write with vec_cell
at.info['comment'] = 'test comment'
ase.io.write('comment.xyz', at, comment=at.info['comment'], vec_cell=True)