-
-
Notifications
You must be signed in to change notification settings - Fork 68
Function to build heteroribbons #421
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
0dafb02
new paradigm
pfebrer 201c953
bug: less buggy way of shifting the cell
pfebrer 331d3e4
bug: corrected some bugs on valid shifts
pfebrer 076e18d
fixed tests after rebasing
zerothi 628cee4
fixed tests and docs
zerothi 22c51e1
rebase isort fixes
zerothi 1915527
renamed section class names
zerothi eefa952
added CompositeGeometrySection to docs
zerothi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| from abc import abstractmethod | ||
| from dataclasses import copy, dataclass, fields | ||
|
|
||
| from sisl.messages import SislError, warn | ||
|
|
||
| __all__ = ["composite_geometry", "CompositeGeometrySection"] | ||
|
|
||
|
|
||
| @dataclass | ||
| class CompositeGeometrySection: | ||
|
|
||
| @abstractmethod | ||
| def build_section(self, geometry): | ||
| ... | ||
|
|
||
| @abstractmethod | ||
| def add_section(self, geometry, geometry_addition): | ||
| ... | ||
Check noticeCode scanning / CodeQL Statement has no effect
This statement has no effect.
|
||
|
|
||
| def _junction_error(self, prev, msg, what): | ||
| """Helper function to raise an error if the junction is not valid. | ||
|
|
||
| It extends the error by specifying details about the sections that | ||
| are being joined. | ||
| """ | ||
| msg = f"Error at junction between sections {prev} and {self}. {msg}" | ||
| if what == "raise": | ||
| raise SislError(msg) | ||
| elif what == "warn": | ||
| warn(msg) | ||
|
|
||
|
|
||
| def composite_geometry(sections, section_cls, **kwargs): | ||
| """Creates a composite geometry from a list of sections. | ||
|
|
||
| The sections are added one after another in the provided order. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| sections: array-like of (_geom_section or tuple or dict) | ||
| A list of sections to be added to the ribbon. | ||
|
|
||
| Each section is either a `composite_geometry.section` or something that will | ||
| be parsed to a `composite_geometry.section`. | ||
| section_cls: class, optional | ||
| The class to use for parsing sections. | ||
| **kwargs: | ||
| Keyword arguments used as defaults for the sections when the . | ||
| """ | ||
| # Parse sections into Section objects | ||
| def conv(s): | ||
| # If it is some arbitrary type, convert it to a tuple | ||
| if not isinstance(s, (section_cls, tuple, dict)): | ||
| s = (s, ) | ||
| # If we arrived here with a tuple, convert it to a dict | ||
| if isinstance(s, tuple): | ||
| s = {field.name: val for field, val in zip(fields(section_cls), s)} | ||
| # At this point it is either a dict or already a section object. | ||
| if isinstance(s, dict): | ||
| return section_cls(**{**kwargs, **s}) | ||
|
|
||
| return copy.copy(s) | ||
|
|
||
| # Then loop through all the sections. | ||
| geom = None | ||
| prev = None | ||
| for i, section in enumerate(sections): | ||
| section = conv(section) | ||
|
|
||
| new_addition = section.build_section(prev) | ||
|
|
||
| if i == 0: | ||
| geom = new_addition | ||
| else: | ||
| geom = section.add_section(geom, new_addition) | ||
|
|
||
| prev = section | ||
|
|
||
| return geom | ||
|
|
||
|
|
||
| composite_geometry.section = CompositeGeometrySection | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Statement has no effect