Skip to content

Commit

Permalink
Update commensurability warning
Browse files Browse the repository at this point in the history
  • Loading branch information
kavanase committed Oct 26, 2023
1 parent 037c09a commit fd31dd2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions easyunfold/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,33 @@ def generate(pc_file, code, sc_file, matrix, kpoints, time_reversal, out_file, n

primitive = read(pc_file)
supercell = read(sc_file)
_quantitative_inaccuracy_warning = (
'Warning: There is a lattice parameter mismatch in the range 2-5% between the primitive (multiplied by the '
'transformation matrix) and the supercell. This will lead to some quantitative inaccuracies in the Brillouin '
'Zone spacing (and thus effective masses) of the unfolded band structures.')
_incommensurate_warning = (
'Warning: the super cell and the primitive cell are not commensurate (lattice parameter difference >5%). This '
'will likely lead to severe inaccuracies in the results! You should double check the correct transformation '
'matrix, primitive and super cells have been provided.')

if matrix:
transform_matrix = matrix_from_string(matrix)
if not np.allclose(primitive.cell @ transform_matrix, supercell.cell):
click.echo('Warning: the super cell and the the primitive cell are not commensure.')
click.echo('Proceed with the assumed tranform matrix')
if not np.allclose(primitive.cell @ transform_matrix, supercell.cell, rtol=2e-2): # 2% mismatch tolerance
if np.allclose(primitive.cell @ transform_matrix, supercell.cell, rtol=5e-2): # 2-5% mismatch
click.echo(_quantitative_inaccuracy_warning)
else:
click.echo(_incommensurate_warning)
click.echo('Proceeding with the assumed transformation matrix.')
click.echo(f'Transform matrix:\n{transform_matrix.tolist()}')
else:
tmp = supercell.cell @ np.linalg.inv(primitive.cell)
transform_matrix = np.rint(tmp)
if not np.allclose(tmp, transform_matrix):
click.echo('The super cell and the the primitive cell are not commensure.')
raise click.Abort()
if not np.allclose(tmp, transform_matrix, rtol=2e-2): # 2% mismatch tolerance
if np.allclose(primitive.cell @ transform_matrix, supercell.cell, rtol=5e-2): # 2-5% mismatch
click.echo(_quantitative_inaccuracy_warning)
else:
click.echo(_incommensurate_warning)
raise click.Abort()

click.echo(f'(Guessed) Transform matrix:\n{transform_matrix.tolist()}')

Expand Down

0 comments on commit fd31dd2

Please sign in to comment.