-
-
Notifications
You must be signed in to change notification settings - Fork 61
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
Lattice is now owning the boundary conditions #629
Conversation
This should be a first step towards moving the nsc attribute from Lattice to somewhere more appropriate. This also makes the boundary conditions in the Grid more manageable since it is the lattice which keeps the information. Simplified reading xyz files since the boundary conditions are now explicit. Signed-off-by: Nick Papior <[email protected]>
@@ -14,8 +15,8 @@ | |||
from ._help import dtype_complex_to_real, wrap_filterwarnings | |||
from ._internal import set_module | |||
from .geometry import Geometry | |||
from .lattice import LatticeChild | |||
from .messages import SislError, deprecate_argument | |||
from .lattice import BoundaryCondition, LatticeChild |
Check notice
Code scanning / CodeQL
Cyclic import
@@ -30,6 +31,10 @@ | |||
|
|||
__all__ = ['Grid', 'sgrid'] | |||
|
|||
_log = logging.getLogger("sisl") | |||
_log.info(f"adding logger: {__name__}") | |||
_log = logging.getLogger(__name__) |
Check notice
Code scanning / CodeQL
Unused global variable
|
||
def __repr__(self): | ||
a, b, c, alpha, beta, gamma = map(lambda r: round(r, 4), self.parameters()) | ||
return f"<{self.__module__}.{self.__class__.__name__} a={a}, b={b}, c={c}, α={alpha}, β={beta}, γ={gamma}, nsc={self.nsc}>" | ||
BC = BoundaryCondition | ||
bc = self.boundary_condition |
Check warning
Code scanning / CodeQL
Variable defined multiple times
Added a small code-snippet in the top post. |
Great! Some comments:
|
|
@pfebrer oh now I see your point in 4. I'll amend. |
I think this looks good. Just some simple observations:
>>> sisl.Lattice(1, boundary_condition=True)
<sisl.Lattice a=1.0, b=1.0, c=1.0, α=90.0, β=90.0, γ=90.0, bc=[U, U, U], nsc=[1 1 1]>
>>> sisl.geom.graphene().lattice
<sisl.Lattice a=2.4595, b=2.4595, c=14.2, α=90.0, β=90.0, γ=60.0, bc=[P, P, P], nsc=[3 3 1]>
|
I like Thomas' third point :) But I don't know if it deviates too much from the approach you were taking. |
Thanks for discovering this, I'll amend some checks.
Yes, this should be incorporated into the
I don't like that... With @pfebrer addition one can do strings, but they should be part of a list. right now (not committed) this would work: lattice.set_boundary_condition(a="per", b="un") # uses `BC.name.startswith(key.upper())`
# your proposal would be:
boundary_condition=list("ppu") Basically:
|
You made the same point to me when |
Here it is a bit more generic... In |
Actually, startswith is equally bad... But it would encourage more than 1 letter words. I'll add so 1 letter words are not accepted. |
There are also more complex axes like a specific direction |
Yeah I would just specify explicitly a shorthand string for each case, as you do with spins (I think). |
What about: |
I think a list is better than commas in a string, so as a first thought I wouldn't say it would help with usage :) |
But what is the most common cases? The only non-common thing is "UNKNOWN"...
Ok, I think I can accept that |
I think more than 90 % of the time people will use periodic or open. But maybe I'm wrong. |
I didn't realise there was |
No, it is a placeholder for something the user doesn't know. It could be unspecified, or simply "unknown".
Hmm, I think the others could be equally nice. :) |
sisl.geom geometries intrinsically sets the PBC single string for short setting them is now doable Signed-off-by: Nick Papior <[email protected]>
I have amended your requests, could you have a look. |
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #629 +/- ##
==========================================
+ Coverage 87.68% 87.73% +0.05%
==========================================
Files 361 362 +1
Lines 48080 48302 +222
==========================================
+ Hits 42158 42378 +220
- Misses 5922 5924 +2
☔ View full report in Codecov by Sentry. |
But for example, if the user asks to compute neighbours, what should happen? |
I agree, that is one of the points that needs resolution, but perhaps this is more appropriately solved with #553? The whole point is that |
I don't agree with this. Boundary conditions should control the search space. Otherwise it's very confusing because the boundary conditions can be meaningless... (e.g. open boundary conditions with nsc=[3, 3, 3]). |
Or periodic boundary conditions with |
One could do a transiesta calculation with |
If it is not periodic, then |
no, but that could be used to limit the interaction range (intentionally). That is currently a flexibility in I am very much pro making this intuitive, and sustainable, but the way things are moving, #553 in particular, makes me wonder how we actually should implement these constraints, because users could do: H.geometry.lattice.set_boundary_condition(...) and the Hamiltonian wouldn't know anything about it...
I agree. But... The way the objects are interacting is probably not the best, I just can't see how we should move things around. See e.g. the above example which disrupts the full |
I agree the flexibility is nice. But it should be an opt-in thing. I remember being very confused at the beggining when I created a geometry and
I think you shouldn't be able to modify a |
So in practical terms maybe the method that sets boundary conditions should create a new |
That's what
I agree, but I don't know how to do this simply. Many of the routines does things in-place, so essentially all changing things should return a new object. |
I played a bit around with this and it looks good to me. |
@tfrederiksen what do you think about the names? Is it too long? Should we do with |
I don't like |
Thanks, lets keep it for now! :) |
This should make users aware of some inconsistencies in the functionality of the objects. Signed-off-by: Nick Papior <[email protected]>
@pfebrer the latest commit adds an informational warning that is shown when a boundary condition is changed from This is then a place-holder to inform users of inconsistencies, but users are expected to correct it them-selves. |
Yes I also agree it should be either
Ok, let's see how you make |
Hehe, ok, yes, lets play with that as well. The main constraint is that the offsets in the sparse matrix is a 1-1 correspondence with the offsets. |
I'll keep the current state and merge, thanks a lot for your feedback! |
This should be a first step towards moving the
nsc attribute from Lattice to somewhere more
appropriate.
This also makes the boundary conditions in the
Grid more manageable since it is the lattice which keeps the information.
Simplified reading xyz files since the boundary
conditions are now explicit.
@tfrederiksen and @pfebrer a review please. :)
Lattice.boundary_cond
boundary conditions for the lattice #626 DefaultLattice.nsc
and relation to periodic/nonperiodic directions #625isort .
at top--leveldocs/
CHANGELOG.md
A small snippet showing its use: