Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ValueErrors in the CoherentInterfaceBuilder #4047

Closed
nightroxide opened this issue Sep 6, 2024 · 1 comment
Closed

ValueErrors in the CoherentInterfaceBuilder #4047

nightroxide opened this issue Sep 6, 2024 · 1 comment
Labels
bug duplicate Duplicate issue

Comments

@nightroxide
Copy link

Python version

Python 3.12.5

Pymatgen version

2024.8.9

Operating system version

Windows 11

Current behavior

Value error when trying to make interfaces

Expected Behavior

A list of possible homojunction structures

Minimal example

from pymatgen.analysis.interfaces import CoherentInterfaceBuilder
from pymatgen.core.structure import Structure
from mp_api.client import MPRester

id = "mp-13"
mpapi_key="key here"
with MPRester(mpapi_key, mute_progress_bars=True) as mpr:
    # get substrate data
    summary = mpr.materials.summary.search(material_ids=id)[0]
    s = substrate_summary.structure

# make a simple homojunction
cib=CoherentInterfaceBuilder(s,s,(1,0,0),(1,1,1))
homojunctions=cib.get_interfaces(cib.terminations[0],film_thickness=8,substrate_thickness=8)

Relevant files to reproduce this bug


ValueError Traceback (most recent call last)
Cell In[7], line 12
9 summary = mpr.materials.summary.search(material_ids=id)[0]
10 s = substrate_summary.structure
---> 12 cib=CoherentInterfaceBuilder(s,s,(1,0,0),(1,1,1))
13 homojunctions=cib.get_interfaces(cib.terminations[0],film_thickness=8,substrate_thickness=8)

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\analysis\interfaces\coherent_interfaces.py:53, in CoherentInterfaceBuilder.init(self, substrate_structure, film_structure, film_miller, substrate_miller, zslgen)
50 self.substrate_miller = substrate_miller
51 self.zslgen = zslgen or ZSLGenerator(bidirectional=True)
---> 53 self._find_matches()
54 self._find_terminations()

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\analysis\interfaces\coherent_interfaces.py:82, in CoherentInterfaceBuilder._find_matches(self)
60 film_sg = SlabGenerator(
61 self.film_structure,
62 self.film_miller,
(...)
68 reorient_lattice=False, # This is necessary to not screw up the lattice
69 )
71 sub_sg = SlabGenerator(
72 self.substrate_structure,
73 self.substrate_miller,
(...)
79 reorient_lattice=False, # This is necessary to not screw up the lattice
80 )
---> 82 film_slab = film_sg.get_slab(shift=0)
83 sub_slab = sub_sg.get_slab(shift=0)
85 film_vectors = film_slab.lattice.matrix

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\core\surface.py:1147, in SlabGenerator.get_slab(self, shift, tol, energy)
1145 # Center the slab layer around the vacuum
1146 if self.center_slab:
-> 1147 struct = center_slab(struct)
1149 # Reduce to primitive cell
1150 if self.primitive:

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\core\surface.py:762, in center_slab(slab)
759 all_indices = list(range(len(slab)))
761 # Get a reasonable cutoff radius to sample neighbors
--> 762 bond_dists = sorted(nn[1] for nn in slab.get_neighbors(slab[0], 10) if nn[1] > 0)
763 # TODO (@DanielYang59): magic number for cutoff radius (would 3 be too large?)
764 cutoff_radius = bond_dists[0] * 3

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\core\structure.py:1662, in IStructure.get_neighbors(self, site, r, include_index, include_image)
1641 def get_neighbors(
1642 self,
1643 site: PeriodicSite,
(...)
1646 include_image: bool = False,
1647 ) -> list[PeriodicNeighbor]:
1648 """Get all neighbors to a site within a sphere of radius r. Excludes the
1649 site itself.
1650
(...)
1660 PeriodicNeighbor
1661 """
-> 1662 return self.get_all_neighbors(r, include_index=include_index, include_image=include_image, sites=[site])[0]

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\core\structure.py:1997, in IStructure.get_all_neighbors(self, r, include_index, include_image, sites, numerical_tol)
1995 if sites is None:
1996 sites = self.sites
-> 1997 center_indices, points_indices, images, distances = self.get_neighbor_list(
1998 r=r, sites=sites, numerical_tol=numerical_tol
1999 )
2000 if len(points_indices) < 1:
2001 return [[]] * len(sites)

File c:\Users\pavarga\AppData\Local\miniconda3\envs\mapi\Lib\site-packages\pymatgen\core\structure.py:1782, in IStructure.get_neighbor_list(self, r, sites, numerical_tol, exclude_self)
1780 lattice_matrix = np.ascontiguousarray(self.lattice.matrix, dtype=float)
1781 pbc = np.ascontiguousarray(self.pbc, dtype=int)
-> 1782 center_indices, points_indices, images, distances = find_points_in_spheres(
1783 cart_coords,
1784 site_coords,
1785 r=r,
1786 pbc=pbc,
1787 lattice=lattice_matrix,
1788 tol=numerical_tol,
1789 )
1790 cond = np.array([True] * len(center_indices))
1791 if exclude_self:

File src\pymatgen\optimization\neighbors.pyx:48, in pymatgen.optimization.neighbors.find_points_in_spheres()

ValueError: Buffer dtype mismatch, expected 'const int64_t' but got 'long'

@nightroxide nightroxide added the bug label Sep 6, 2024
@nightroxide nightroxide changed the title Datatype errors in the CoherentInterfaceBuilder Value errors in the CoherentInterfaceBuilder Sep 6, 2024
@DanielYang59
Copy link
Contributor

Hi @nightroxide thanks for reporting this. This is a duplicate of #3990 and has been fixed by #3992.

@janosh janosh added the duplicate Duplicate issue label Sep 7, 2024
@janosh janosh closed this as completed Sep 7, 2024
@janosh janosh changed the title Value errors in the CoherentInterfaceBuilder ValueErrors in the CoherentInterfaceBuilder Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug duplicate Duplicate issue
Projects
None yet
Development

No branches or pull requests

3 participants