-
-
Notifications
You must be signed in to change notification settings - Fork 60
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
More convenient way to convert python objects to sisl #282
Comments
By the way, just to give a bit more background: this thought was because I would like to accept different python objects as values for a given setting in the viz module. E.g.: a |
I think this would be a nice addition. It would solve a couple of problems:
How to exactly implement this is something we should consider. This dispatcher should react to types. So something like: def __call__(self, *args, **kwargs):
obj = args[0]
return self._dispatchs[type(obj)](*args, **kwargs) and these dispatch methods are just simple methods (no need for dispatchers). However, with actual Now comes the problematic part. By using |
Oh... second problem... |
I think siles are great for standarizing the input of files into sisl, but there's no such infrastructure for python objects.
Maybe the creation and register of "converters" would help. Each converter would look something like this:
And it would be registered into the corresponding class (in this case,
Geometry
). Then, thefrom
andto
dispatchers would be implemented, and one could do:One thing that I would particularly like is that I wouldn't need to call the
from
dispatcher. The class would check on call whether it is being passed an object that has been registered as "convertible" and use it. That is:would work as the current
Edit: Maybe
sisl.Geometry.from(ase_obj)
is enough so that we don't interfere in normal geometry creationThis would probably give the ability for a class to implement as many parsers as wanted without overpopulating with methods (which was one of your concerns for
Geometry
).PS: I would love a converter from strings because it would save me some repetitive code:
The text was updated successfully, but these errors were encountered: