root / ase / test / io.py @ 13
Historique | Voir | Annoter | Télécharger (1,4 ko)
1 |
import numpy as np |
---|---|
2 |
from ase import Atoms |
3 |
from ase.io import write, read |
4 |
|
5 |
a = 5.0
|
6 |
d = 1.9
|
7 |
c = a / 2
|
8 |
atoms = Atoms('AuH',
|
9 |
positions=[(c, c, 0), (c, c, d)],
|
10 |
cell=(a, a, 2 * d),
|
11 |
pbc=(0, 0, 1)) |
12 |
extra = np.array([ 2.3, 4.2 ]) |
13 |
atoms.set_array("extra", extra)
|
14 |
atoms *= (1, 1, 2) |
15 |
images = [atoms.copy(), atoms.copy()] |
16 |
r = ['xyz', 'traj', 'cube', 'pdb', 'cfg', 'struct'] |
17 |
w = r + ['xsf']
|
18 |
try:
|
19 |
import matplotlib |
20 |
except ImportError: |
21 |
pass
|
22 |
else:
|
23 |
w += ['png', 'eps'] |
24 |
|
25 |
for format in w: |
26 |
print format, 'O', |
27 |
fname1 = 'io-test.1.' + format
|
28 |
fname2 = 'io-test.2.' + format
|
29 |
write(fname1, atoms, format=format) |
30 |
if format not in ['cube', 'png', 'eps', 'cfg', 'struct']: |
31 |
write(fname2, images, format=format) |
32 |
|
33 |
if format in r: |
34 |
print 'I' |
35 |
a1 = read(fname1) |
36 |
assert np.all(np.abs(a1.get_positions() -
|
37 |
atoms.get_positions()) < 1e-6)
|
38 |
if format in ['traj', 'cube', 'cfg', 'struct']: |
39 |
assert np.all(np.abs(a1.get_cell() - atoms.get_cell()) < 1e-6) |
40 |
if format in ['cfg']: |
41 |
assert np.all(np.abs(a1.get_array('extra') - |
42 |
atoms.get_array('extra')) < 1e-6) |
43 |
if format not in ['cube', 'png', 'eps', 'cfg', 'struct']: |
44 |
a2 = read(fname2) |
45 |
a3 = read(fname2, index=0)
|
46 |
a4 = read(fname2, index=slice(None)) |
47 |
else:
|
48 |
print
|