-
-
Notifications
You must be signed in to change notification settings - Fork 58
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
Slicing read_* methods #584
Comments
open("/tmp/test.file", 'w').write("""1
C 0.00000000 0.00000000 0.00000000
2
C 0.00000000 0.00000000 0.00000000
C 1.000000 0.00000000 0.00000000
3
C 0.00000000 0.00000000 0.00000000
C 1.000000 0.00000000 0.00000000
C 2.00000 0.00000000 0.00000000
""")
from sisl.io import xyzSile
sile = xyzSile("/tmp/test.file")
print(sile.read_geometry(), help(sile.read_geometry))
print(sile.read_geometry[0](), help(sile.read_geometry[0]))
print(sile.read_geometry[1]())
print(sile.read_geometry[1:]()) It isn't complete, but just to get an idea? Originally posted by @zerothi in #578 (comment) |
@tfrederiksen @pfebrer lets continue the discussion here. Please see the updated branch 584-sile-slicer, it contains more functionality and patches the documentation. @pfebrer did the changes correspond to your remarks? |
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
Ok, it is there now! :) I think this should be fully functional! :) Perhaps we should discuss how it should work. :)
|
I was thinking that in the future you could have something like
I believe for now it's better to keep it simple and don't allow double slicing.
If there are no negative indices (or you know the length of the data), I think it would be nice to stop reading when you reach the last requested item.
I don't know what's the best name, but I think there should be a method, for if you need to pass more arguments than just the selection of indices. I can't tell right now what would I use this method for, but it's probably a good idea to have it. Maybe we can include it later when it is more clear what would it be useful for.
If the dict contains arguments for the function, I think it's better not to do it because it feels very hacky. Instead, one should go through the method discussed above, since it feels much more natural to pass arguments to a function. |
Oh by the way, I think it would be cool if the |
Agreed!
Agreed, I really also think this is a corner case, but it could be useful for passing around objects that reads geometries
Agreed, lets try this as well.
Ok, we'll wait
Agreed.
Hmm. That might be a bit complicated. I think the interface would result in something like this: for read in read_geometry[:10]:
geom = read() or similar? would this be expected? |
For the iterator, I was thinking that it could already call the reader and yield the output. Although I noticed the problem that then you can't pass extra arguments. Is that why you suggested the interface? Perhaps the method Although now that you wrote it like that, I kind of like the functionality too. Hmm now I don' know what do I prefer 😅 |
Yeah, my problem was the arguments, hence that solution. Well, to my taste I don't particularly see the big need, doing: for geom in read_geometry[:10]():
... looks fine to me, albeit there may be some initial overhead. |
Yes, but that is not the same, because it will read all the geometries. For example you can't Another application of taking geometries on the fly could be to generate animations of trajectories. |
Agreed. But the interface looks a bit complicated to me. Lets first start with the other things, and we can continue down the rabbit hole later ;) |
@tfrederiksen would you be ok with abandoning #578 and continue down this path outlined here? I do believe that this might be more versatile in the long run, and a bit simpler for end-users, no weird arguments, just slices. |
Sorry, I didn't find time to study your proposal today. But from what I've seen in your exchange it looks good to me too. |
It seems clean and clear enough for me to specify the iterator externally (slicing,
multi
,slice
,apply
...), just as it is done with the BZ methods for example. If some method is very common to use withall=True
, there could be an extra method with the plural word, i.e.read_energy
->read_energies
as an alternative forread_energy[:]
.Originally posted by @pfebrer in #578 (comment)
The text was updated successfully, but these errors were encountered: