Commit d110d12c authored by Ask Hjorth Larsen's avatar Ask Hjorth Larsen

Merge branch 'fix-kpts2kpts' into 'master'

Fix kpts2kpts

See merge request ase/ase!1347
parents c8c91144 21b8810d
Pipeline #100975972 passed with stages
in 7 minutes and 2 seconds
......@@ -6,7 +6,8 @@ from math import pi, sqrt
import numpy as np
from ase.utils import jsonable
from ase.dft.kpoints import bandpath, monkhorst_pack
from ase.dft.kpoints import monkhorst_pack
from ase.cell import Cell
class CalculatorError(RuntimeError):
......@@ -322,8 +323,8 @@ def kpts2kpts(kpts, atoms=None):
if 'kpts' in kpts:
return KPoints(kpts['kpts'])
if 'path' in kpts:
path = bandpath(cell=atoms.cell, **kpts)
return path
cell = Cell.ascell(atoms.cell)
return cell.bandpath(pbc=atoms.pbc, **kpts)
size, offsets = kpts2sizeandoffsets(atoms=atoms, **kpts)
return KPoints(monkhorst_pack(size) + offsets)
......
......@@ -1422,7 +1422,7 @@ def get_2d_bravais_lattice(origcell, eps=2e-4, *, pbc=True):
return finallat, finalop.T
def all_variants():
def all_variants(include_blunt_angles=True):
"""For testing and examples; yield all variants of all lattices."""
a, b, c = 3., 4., 5.
alpha = 55.0
......@@ -1510,5 +1510,9 @@ def all_variants():
yield CRECT(a, alpha=alpha)
yield HEX2D(a)
yield SQR(a)
yield LINE(a)
if include_blunt_angles:
beta = 110
yield OBL(a, b, alpha=beta)
yield CRECT(a, alpha=beta)
from ase.calculators.calculator import kpts2kpts
from ase.lattice import all_variants
from ase import Atoms
# This function tests whether giving a bandpath
# and an atoms object with a completed cell to
# kpts2kpts actually produces a band path with
# the same special points in the end. If this
# isn't fulfilled then it means that something
# has gone wrong (most likely that the bravais
# lattice wasn't correctly identified).
for lat in all_variants():
print()
print(lat)
bandpath = lat.bandpath()
a = Atoms()
a.cell = lat.tocell().complete()
a.pbc[:lat.ndim] = True
path = {'path': bandpath.path}
bandpath2 = kpts2kpts(path, atoms=a)
print('cell', a.cell)
print('Original', bandpath)
print('path', path)
print('Produced by kpts2kpts', bandpath2)
sp = set(bandpath.special_points)
sp2 = set(bandpath2.special_points)
msg = ('Input and output bandpath from kpts2kpts dont agree!\n'
'Input: {}\n Output: {}'.format(bandpath, bandpath2))
assert sp == sp2, msg
......@@ -29,7 +29,7 @@ entry = """\
with open('bztable.rst', 'w') as fd:
print(header, file=fd)
for i, lat in enumerate(all_variants()):
for i, lat in enumerate(all_variants(include_blunt_angles=False)):
id = '{:02d}.{}'.format(i, lat.variant)
imagefname = '{}.svg'.format(id)
txt = entry.format(name=lat.variant,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment