Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
pfebrer committed Oct 31, 2023
1 parent 356295d commit 0c7bc3f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[build-system]
requires = [
"setuptools_scm[toml]>=6.2",
"scikit-build-core[pyproject]",
"scikit-build-core[pyproject]==0.5.1",
"Cython>=0.29.28",
# see https://github.com/scipy/oldest-supported-numpy/
# should fix #310
Expand Down
70 changes: 62 additions & 8 deletions src/sisl/geom/flat.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,39 @@ def graphene(bond=1.42, atoms=None, orthogonal=False):
atoms = Atom(Z=6, R=bond * 1.01)
return honeycomb(bond, atoms, orthogonal)

def honeycomb_flake(shells: int, bond: float, atoms) -> Geometry:
def honeycomb_flake(shells: int, bond: float, atoms, vaccuum: float = 20.) -> Geometry:
"""Hexagonal flake of a honeycomb lattice, with zig-zag edges.
Parameters
----------
shells:
Number of shells in the flake. 0 means a single hexagon, and subsequent
shells add hexagon units surrounding the previous shell.
bond:
bond length between atoms (*not* lattice constant)
atoms:
the atom (or atoms) that the honeycomb lattice consists of
vaccuum:
Amount of vacuum to add to the cell on all directions
"""

# Function that generates one of the six triangular portions of the
# hexagonal flake. The rest of the portions are obtained by rotating
# this one by 60, 120, 180, 240 and 300 degrees.
def _minimal_op(shells):

Check warning on line 96 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L96

Added line #L96 was not covered by tests

# The function is based on the horizontal lines of the hexagon,
# which are made of a pair of atoms.
# For each shell, we first need to complete the incomplete horizontal
# lines of the previous shell, and then branch them up and down to create
# the next horizontal lines.

# Displacement from the end of one horizontal pair to the beggining of the next
branch_displ_x = bond * np.cos(np.radians(60))
branch_displ_y = bond * np.sin(np.radians(60))

Check warning on line 106 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L105-L106

Added lines #L105 - L106 were not covered by tests

# Iterate over shells. We also keep track of the atom types, in case
# we have two different atoms in the honeycomb lattice.
op = np.array([[bond, 0, 0]])
types = np.array([0])
for shell in range(shells):
Expand All @@ -102,24 +128,52 @@ def _minimal_op(shells):

return op, types

Check warning on line 129 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L129

Added line #L129 was not covered by tests

# Get the coordinates of 1/6 of the hexagon for the requested number of shells.
op, types = _minimal_op(shells)

Check warning on line 132 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L132

Added line #L132 was not covered by tests

# Get the first two of the six portions of the hexagon. If there are two
# atom types, then we need to reverse the order of the atoms of the second portion.
single_atom_type = isinstance(str, atoms) or len(atoms) == 1
single_atom_type = isinstance(atoms, (str, Atom)) or len(atoms) == 1

Check warning on line 134 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L134

Added line #L134 was not covered by tests

# Create a geometry from the coordinates.
ats = atoms if single_atom_type else np.asarray(atoms)[types]
geom = Geometry(op, atoms=ats)

Check warning on line 138 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L137-L138

Added lines #L137 - L138 were not covered by tests

# The second portion of the hexagon is obtained by rotating the first one by 60 degrees.
# However, if there are two different atoms in the honeycomb lattice, we need to reverse the types.
next_triangle = geom if single_atom_type else Geometry(op, atoms=np.asarray(atoms)[types - 1])
geom += next_triangle.rotate(60, [0,0,1])

Check warning on line 143 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L142-L143

Added lines #L142 - L143 were not covered by tests

# Then just rotate the two triangles by 120 and 240 degrees to get the full hexagon
# Then just rotate the two triangles by 120 and 240 degrees to get the full hexagon.
geom += geom.rotate(120, [0,0,1]) + geom.rotate(240, [0,0,1])

Check warning on line 146 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L146

Added line #L146 was not covered by tests

return geom
# Set the cell according to the requested vacuum
max_x = np.max(geom.xyz[:,0])
geom.cell[0,0] = max_x * 2 + vaccuum
geom.cell[1,1] = max_x * 2 + vaccuum
geom.cell[2,2] = 20.

Check warning on line 152 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L149-L152

Added lines #L149 - L152 were not covered by tests

# Center the flake and return
return geom.translate(geom.center(what="cell"))

Check warning on line 155 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L155

Added line #L155 was not covered by tests

def graphene_flake(shells: int, bond: float = 1.42, atoms=None, vaccuum: float = 20.) -> Geometry:
"""Hexagonal flake of graphene, with zig-zag edges.
def graphene_flake(shells: int, bond: float = 1.42, atoms=None) -> Geometry:
Parameters
----------
shells:
Number of shells in the flake. 0 means a single hexagon, and subsequent
shells add hexagon units surrounding the previous shell.
bond:
bond length between atoms (*not* lattice constant)
atoms:
the atom (or atoms) that the honeycomb lattice consists of.
Default to Carbon atom.
vaccuum:
Amount of vacuum to add to the cell on all directions
See Also
--------
honeycomb_flake: the equivalent of this, but with non-default atoms.
"""
if atoms is None:
atoms = Atom(Z=6, R=bond * 1.01)
return honeycomb_flake(shells, bond, atoms)
return honeycomb_flake(shells, bond, atoms, vaccuum)

Check warning on line 179 in src/sisl/geom/flat.py

View check run for this annotation

Codecov / codecov/patch

src/sisl/geom/flat.py#L177-L179

Added lines #L177 - L179 were not covered by tests

0 comments on commit 0c7bc3f

Please sign in to comment.