Skip to content

Commit

Permalink
fixed optimize_nsc calls in geometry finalization
Browse files Browse the repository at this point in the history
Added rest of the typing.

Signed-off-by: Nick Papior <nickpapior@gmail.com>
  • Loading branch information
zerothi committed Nov 2, 2023
1 parent c74de1f commit 2df3a49
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
9 changes: 5 additions & 4 deletions src/sisl/geom/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
def geometry_define_nsc(geometry, periodic=(True, True, True)):
"""Define the number of supercells for a geometry based on the periodicity """
if np.all(geometry.maxR(True) > 0.):
geometry.optimize_nsc()
# strip away optimizing nsc for the non-periodic directions
axes = [i for i, p in enumerate(periodic) if p]

geometry.optimize_nsc(axes)
for d, per in zip("abc", periodic):
if per:
geometry.lattice.set_boundary_condition(**{d: "Periodic"})
else:
if not per:
geometry.set_nsc(**{d: 1})
else:
nsc = [3 if p else 1 for p in periodic]
Expand Down
12 changes: 10 additions & 2 deletions src/sisl/geom/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,12 @@ def graphene(bond: float=1.42,
atoms = Atom(Z=6, R=bond * 1.01)
return honeycomb(bond, atoms, orthogonal)


@set_module("sisl.geom")
def honeycomb_flake(shells: int, bond: float, atoms, vacuum: float = 20.) -> Geometry:
def honeycomb_flake(shells: int,
bond: float,
atoms,
vacuum: float = 20.) -> Geometry:
"""Hexagonal flake of a honeycomb lattice, with zig-zag edges.
Parameters
Expand Down Expand Up @@ -165,8 +169,12 @@ def _minimal_op(shells):

return geom


@set_module("sisl.geom")
def graphene_flake(shells: int, bond: float = 1.42, atoms=None, vacuum: float = 20.) -> Geometry:
def graphene_flake(shells: int,
bond: float = 1.42,
atoms=None,
vacuum: float = 20.) -> Geometry:
"""Hexagonal flake of graphene, with zig-zag edges.
Parameters
Expand Down
24 changes: 13 additions & 11 deletions src/sisl/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from math import acos
from numbers import Integral, Real
from pathlib import Path
from typing import TYPE_CHECKING, Iterator, List, Optional, Tuple, Union
from typing import TYPE_CHECKING, Iterator, List, Optional, Sequence, Tuple, Union

import numpy as np
from numpy import (
Expand Down Expand Up @@ -1762,7 +1762,7 @@ def update_flag(kw, arg, val):
return self.sub(atoms_flat)

def optimize_nsc(self,
axis=None,
axes: Optional[Union[int, Sequence[int]]]=None,
R: Optional[float]=None) -> ndarray:
""" Optimize the number of supercell connections based on ``self.maxR()``
Expand All @@ -1772,15 +1772,17 @@ def optimize_nsc(self,
Parameters
----------
axis : int or array_like, optional
only optimize the specified axis (default to all)
axes :
only optimize the specified axes (default to all)
R :
the maximum connection radius for each atom
"""
if axis is None:
axis = [0, 1, 2]
if axes is None:
axes = [0, 1, 2]
else:
axis = _a.asarrayi(axis).ravel()
axes = _a.asarrayi(axes).ravel()
if len(axes) == 0:
return self.nsc

if R is None:
R = self.maxR() + 0.001
Expand All @@ -1802,12 +1804,12 @@ def optimize_nsc(self,
# I don't think we need anything other than this.
# However, until I am sure that this wouldn't change, regardless of the
# cell. I will keep it.
Rimcell = R * fnorm(imcell)[axis]
nsc[axis] = (floor(Rimcell) + ceil(Rimcell % 0.5 - 0.5)).astype(np.int32)
Rimcell = R * fnorm(imcell)[axes]
nsc[axes] = (floor(Rimcell) + ceil(Rimcell % 0.5 - 0.5)).astype(np.int32)
# Since for 1 it is not sure that it is a connection or not, we limit the search by
# removing it.
nsc[axis] = np.where(nsc[axis] > 1, nsc[axis], 0)
for i in axis:
nsc[axes] = np.where(nsc[axes] > 1, nsc[axes], 0)
for i in axes:
# Initialize the isc for this direction
# (note we do not take non-orthogonal directions
# into account)
Expand Down

0 comments on commit 2df3a49

Please sign in to comment.