Skip to content

Singular film supercell transformation matrix when calling get_interfaces for CoherentInterfaceBuilder #4651

Description

@tfhughes

Python version

Python 3.11.4

Pymatgen version

2023.9.10

Operating system version

Mac Tahoe 26.2 (25C56)

Current behavior

Not sure if this is a known pymatgen issue when building interfaces but I can’t find a GitHub issue for it. Printing some information from CoherentInterfaceBuilder.get_interfaces shows the following:

film_shift 0.08333336181879059
sub_shift 0.12499996873087585
film_slab.lattice.matrix[:2]
[[-1.96204495 5.88613486 -6.26018476]
[ 5.88613486 5.88613486 6.26018476]]
match.film_sl_vectors
[[ -7.84817982 0. 0. ]
[ -3.92408991 -11.77226973 -12.52036953]]
super_film_transform
[[ 0 0 0]
[ 0 -2 0]
[ 0 0 1]]

I think that last transform, a film supercell transform, is the issue since there should never be a zero along the diagonal.

Here is a script to reproduce the issue:

import numpy
from pymatgen.analysis.interfaces.zsl import ZSLGenerator
from pymatgen.core.structure import Structure as PMGStructure
from pymatgen.analysis.interfaces.coherent_interfaces import CoherentInterfaceBuilder

pbc1 = [
    [3.816817045211792, 0.0, 0.0],
    [0.0, 3.816817045211792, 0.0],
    [0.0, 0.0, 3.816817045211792]]
ans1 = [57, 27, 8, 8, 8]
xyz1 = numpy.array([
    [1.908409, 1.908409, 1.908409],
    [0.0, 0.0, 0.0],
    [1.908409, 0.0, 0.0],
    [0.0, 1.908409, 0.0],
    [0.0, 0.0, 1.908409]])
sub_st = PMGStructure(pbc1, ans1, xyz1, charge=0,
    validate_proximity=False, to_unit_cell=False,
    coords_are_cartesian=True, site_properties=None)

pbc2 = [
    [3.9240899085998535, 0.0, 0.0],
    [0.0, 3.9240899085998535, 0.0],
    [0.0, 0.0, 12.520369529724121]]
ans2 = [57, 57, 57, 57, 28, 28, 8, 8, 8, 8, 8, 8, 8, 8]
xyz2 = numpy.array([
    [0.0, 0.0, 4.550816],
    [1.962045, 1.962045, 1.709368],
    [1.962045, 1.962045, 10.811001],
    [0.0, 0.0, 7.969553],
    [0.0, 0.0, 0.0],
    [1.962045, 1.962045, 6.260185],
    [0.0, 0.0, 2.241059],
    [1.962045, 1.962045, 4.019126],
    [1.962045, 0.0, 0.0],
    [0.0, 1.962045, 0.0],
    [1.962045, 1.962045, 8.501243],
    [0.0, 0.0, 10.279311],
    [0.0, 1.962045, 6.260185],
    [1.962045, 0.0, 6.260185]])
film_st = PMGStructure(pbc2, ans2, xyz2, charge=0,
    validate_proximity=False, to_unit_cell=False,
    coords_are_cartesian=True, site_properties=None)

kwargs = {'max_area': 450.0}
film_hkl = (3, 2, 3)
sub_hkl = (2, 1, 0)
term = ('La_C2/m_1', 'CoO2_P2/m_3')

zslgen = ZSLGenerator(**kwargs)
builder = CoherentInterfaceBuilder(sub_st, film_st, film_hkl, sub_hkl, zslgen=zslgen)
inters = builder.get_interfaces(term, gap=1.0, vacuum_over_film=10.0,
    film_thickness=4.0, substrate_thickness=4.0, in_layers=True)
print(len(list(inters)))

Throws the following traceback:

Traceback (most recent call last):
  File "/Users/hughes/pymatgen_test/test.py", line 54, in <module>
    print(len(list(inters)))
              ^^^^^^^^^^^^
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/pymatgen/analysis/interfaces/coherent_interfaces.py", line 200, in get_interfaces
    film_sl_slab.make_supercell(super_film_transform)
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/pymatgen/core/structure.py", line 4115, in make_supercell
    supercell = struct * scaling_matrix
                ~~~~~~~^~~~~~~~~~~~~~~~
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/pymatgen/core/structure.py", line 1320, in __mul__
    f_lat = lattice_points_in_supercell(scale_matrix)
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/pymatgen/util/coord.py", line 295, in lattice_points_in_supercell
    frac_points = np.dot(all_points, np.linalg.inv(supercell_matrix))
                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<__array_function__ internals>", line 200, in inv
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/numpy/linalg/linalg.py", line 538, in inv
    ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/hughes/scr/bld_26-3/internal/lib/python3.11/site-packages/numpy/linalg/linalg.py", line 89, in _raise_linalgerror_singular
    raise LinAlgError("Singular matrix")
numpy.linalg.LinAlgError: Singular matrix

Expected Behavior

I expect to get an interface back with no traceback.

Minimal example

Relevant files to reproduce this bug

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions