root / ase / test / trajectory.py @ 4
Historique | Voir | Annoter | Télécharger (753 octet)
| 1 |
import os |
|---|---|
| 2 |
from ase import Atom, Atoms |
| 3 |
from ase.io import PickleTrajectory |
| 4 |
|
| 5 |
co = Atoms([Atom('C', (0, 0, 0)), |
| 6 |
Atom('O', (0, 0, 1.2))]) |
| 7 |
traj = PickleTrajectory('1.traj', 'w', co) |
| 8 |
for i in range(5): |
| 9 |
co.positions[:, 2] += 0.1 |
| 10 |
traj.write() |
| 11 |
del traj
|
| 12 |
traj = PickleTrajectory('1.traj', 'a') |
| 13 |
co = traj[-1]
|
| 14 |
print co.positions
|
| 15 |
co.positions[:] += 1
|
| 16 |
traj.write(co) |
| 17 |
del traj
|
| 18 |
t = PickleTrajectory('1.traj', 'a') |
| 19 |
print t[-1].positions |
| 20 |
print '.--------' |
| 21 |
for a in t: |
| 22 |
print 1, a.positions[-1,2] |
| 23 |
co.positions[:] += 1
|
| 24 |
t.write(co) |
| 25 |
for a in t: |
| 26 |
print 2, a.positions[-1,2] |
| 27 |
assert len(t) == 7 |
| 28 |
|
| 29 |
# append to a nonexisting file
|
| 30 |
fname = '2.traj'
|
| 31 |
if os.path.isfile(fname):
|
| 32 |
os.remove(fname) |
| 33 |
t = PickleTrajectory(fname, 'a', co)
|
| 34 |
del(t)
|
| 35 |
os.remove(fname) |
| 36 |
|