1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
def test_dmol():
from ase.build import bulk, molecule
from ase.io import read, write
from ase.calculators.dmol import find_transformation
import numpy as np
def check(atoms, ref_atoms, dist_tol=1e-6):
# check pbc conditions
assert all(atoms.pbc == ref_atoms.pbc), (atoms.pbc, ref_atoms.pbc)
# check cell
if all(atoms.pbc):
assert abs(atoms.cell - ref_atoms.cell).max() < dist_tol, \
(atoms.cell - ref_atoms.cell)
# check positions
assert abs(atoms.positions - ref_atoms.positions).max() < dist_tol, \
(atoms.positions - ref_atoms.positions)
# check symbols
assert atoms.get_chemical_symbols() == ref_atoms.get_chemical_symbols()
ref_molecule = molecule('H2O')
ref_bulk = bulk('Si', 'diamond')
ref_molecule_images = [ref_molecule, ref_molecule]
ref_bulk_images = [ref_bulk, ref_bulk]
# .car format
fname = 'dmol_tmp.car'
write(fname, ref_molecule, format='dmol-car')
for atoms in [read(fname, format='dmol-car'), read(fname)]:
check(atoms, ref_molecule)
fname = 'dmol_tmp.car'
write(fname, ref_bulk, format='dmol-car')
for atoms in [read(fname, format='dmol-car'), read(fname)]:
R, _ = find_transformation(atoms, ref_bulk)
atoms.cell = np.dot(atoms.cell, R)
atoms.positions = np.dot(atoms.positions, R)
check(atoms, ref_bulk)
# .incoor format
fname = 'dmol_tmp.incoor'
write(fname, ref_bulk, format='dmol-incoor')
atoms = read(fname, format='dmol-incoor')
check(atoms, ref_bulk)
# .arc format
fname = 'dmol_tmp.arc'
write(fname, ref_molecule_images, format='dmol-arc')
images = read(fname, index=':', format='dmol-arc')
for image, ref_image in zip(images, ref_molecule_images):
check(image, ref_image)
fname = 'dmol_tmp.arc'
write(fname, ref_bulk_images, format='dmol-arc')
images = read(fname, index=':', format='dmol-arc')
for image, ref_image in zip(images, ref_bulk_images):
R, _ = find_transformation(image, ref_image)
image.cell = np.dot(image.cell, R)
image.positions = np.dot(image.positions, R)
check(image, ref_image)
|