[ase-users] Atoms.set_calculator() deprecated?
Ask Hjorth Larsen
asklarsen at gmail.com
Wed May 20 19:15:35 CEST 2020
Dear Jakob,
Am Mi., 20. Mai 2020 um 18:03 Uhr schrieb Jakob Schiøtz via ase-users
<ase-users at listserv.fysik.dtu.dk>:
>
> Hi all,
>
> What was the reason for deprecating Atoms.set_calculator() in favor of just setting the .calc attribute? It is still a function that is being called.
Having only one is better than having both. We regularly take some
flak for having multiple ways of doing the same thing. So I suggested
it in an issue which got 5 thumbs up, which is the current high score.
>
> And more importantly: How the !€#% do I call that "function" (which is not a function, but a property) of the Atoms class, when I have a subclass that now has to overload the .calc property but needs to call the original not-quite-a-function. With functions that is easy, but my Python-fu is insufficient to do this with properties. I end up with infinite recursions no matter what I try.
Huh, that's kind of strange. It isn't exactly user-friendly. I
rummaged around and got to this:
from ase import Atoms
class MyAtoms(Atoms):
@property
def calc(self):
print('fget')
return Atoms.calc.fget(self)
@calc.setter
def calc(self, calc):
print('fset')
Atoms.calc.fset(self, calc)
atoms = MyAtoms()
atoms.calc = 'hello'
print(atoms.calc)
The ugly part being that you'd expect properties to be kind of
transparent, rather than requiring subclasses to *know* that they're
properties.
>
> Or would anybody object to partly reverting this change, un-deprecate Atoms.set_calculator() and letting Atoms.calc be a property calling the get/set functions which actually do the work?
I think it might be okay to have getters/setters to help subclasses,
but I prefer to still deprecate the old API. As long as remains clear
to users what the purpose of each thing is.
A real issue is that it's not clear what the subclassing rules are for
Atoms. Subclassing complex objects is always finicky, having a
tendency to break abstractions that otherwise work. So I always
prefer delegation.
Hmmm ...
Best regards
Ask
>
> Best regards
>
> Jakob
>
> --
> Jakob Schiøtz, professor, Ph.D.
> Department of Physics
> Technical University of Denmark
> DK-2800 Kongens Lyngby, Denmark
> http://www.fysik.dtu.dk/~schiotz/
>
>
>
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
More information about the ase-users
mailing list