@@ -34,13 +34,13 @@ def __init__(self, dimensionality: int):
3434 dimensionality (int): The spatial dimension of the lattice (e.g., 1, 2, 3).
3535 """
3636 self ._dimensionality = dimensionality
37-
37+
3838 # --- Internal Data Structures (to be populated by subclasses) ---
3939 self ._indices : List [SiteIndex ] = []
4040 self ._identifiers : List [SiteIdentifier ] = []
4141 self ._coordinates : List [Coordinates ] = []
4242 self ._ident_to_idx : Dict [SiteIdentifier , SiteIndex ] = {}
43-
43+
4444 # Neighbor information, structured as {k: {site_index: [neighbor_indices]}}
4545 # k=1 for nearest neighbors, k=2 for next-nearest, etc.
4646 self ._neighbor_maps : Dict [int , NeighborMap ] = {}
@@ -58,14 +58,14 @@ def dimensionality(self) -> int:
5858 def __len__ (self ) -> int :
5959 """Returns the total number of sites, enabling `len(lattice)`."""
6060 return self .num_sites
61-
61+
6262 # Other common methods like get_site_info, get_neighbors can be added here.
6363
6464 @abc .abstractmethod
6565 def _build_lattice (self , * args , ** kwargs ):
6666 """
6767 Abstract method for subclasses to generate the lattice data.
68-
68+
6969 This method should populate the following internal lists and dicts:
7070 - self._indices
7171 - self._identifiers
@@ -90,7 +90,7 @@ def _build_neighbors(self, max_k: int = 1):
9090 def show (self , ** kwargs ):
9191 """
9292 Abstract method for visualizing the lattice structure.
93-
93+
9494 Subclasses should implement the specific plotting logic.
9595 """
9696 pass
@@ -100,22 +100,30 @@ class GeneralLattice(AbstractLattice):
100100 """
101101 A general lattice built from an explicit list of sites and coordinates.
102102 """
103- def __init__ (self ,
104- dimensionality : int ,
105- identifiers : List [SiteIdentifier ],
106- coordinates : List [Union [List [float ], np .ndarray ]]):
107-
103+
104+ def __init__ (
105+ self ,
106+ dimensionality : int ,
107+ identifiers : List [SiteIdentifier ],
108+ coordinates : List [Union [List [float ], np .ndarray ]],
109+ ):
110+
108111 super ().__init__ (dimensionality )
109- assert len (identifiers ) == len (coordinates ), "Identifiers and coordinates must have the same length."
112+ assert len (identifiers ) == len (
113+ coordinates
114+ ), "Identifiers and coordinates must have the same length."
110115
111116 # The lattice is built directly upon initialization.
112117 self ._build_lattice (identifiers = identifiers , coordinates = coordinates )
113-
118+
114119 # Neighbor relationships can be calculated later if needed.
115120 print (f"GeneralLattice with { self .num_sites } sites created." )
116121
117-
118- def _build_lattice (self , identifiers : List [SiteIdentifier ], coordinates : List [Union [List [float ], np .ndarray ]]):
122+ def _build_lattice (
123+ self ,
124+ identifiers : List [SiteIdentifier ],
125+ coordinates : List [Union [List [float ], np .ndarray ]],
126+ ):
119127 """Implements the lattice building for GeneralLattice."""
120128 self ._identifiers = list (identifiers )
121129 self ._coordinates = [np .array (c ) for c in coordinates ]
@@ -131,7 +139,7 @@ def _build_neighbors(self, max_k: int = 1):
131139 def show (self , show_indices : bool = True , show_bonds : bool = False , ** kwargs ):
132140 """
133141 A simple visualization of the lattice sites.
134-
142+
135143 Args:
136144 show_indices (bool): If True, display the identifier of each site.
137145 show_bonds (bool): If True, display lines connecting neighbors (not implemented yet).
@@ -148,19 +156,24 @@ def show(self, show_indices: bool = True, show_bonds: bool = False, **kwargs):
148156 return
149157
150158 coords = np .array (self ._coordinates )
151-
159+
152160 plt .figure (figsize = (6 , 6 ))
153-
161+
154162 if coords .size > 0 :
155163 plt .scatter (coords [:, 0 ], coords [:, 1 ], s = 100 , zorder = 2 )
156164
157165 if show_indices :
158166 for i in range (self .num_sites ):
159- plt .text (coords [i , 0 ] + 0.1 , coords [i , 1 ] + 0.1 , str (self ._identifiers [i ]), fontsize = 12 )
160-
161- plt .axis ('equal' )
167+ plt .text (
168+ coords [i , 0 ] + 0.1 ,
169+ coords [i , 1 ] + 0.1 ,
170+ str (self ._identifiers [i ]),
171+ fontsize = 12 ,
172+ )
173+
174+ plt .axis ("equal" )
162175 plt .grid (True )
163176 plt .title (f"{ self .__class__ .__name__ } ({ self .num_sites } sites)" )
164177 plt .xlabel ("x coordinate" )
165178 plt .ylabel ("y coordinate" )
166- plt .show ()
179+ plt .show ()
0 commit comments