[ase-users] Question about calculators

Ask Hjorth Larsen asklarsen at gmail.com
Mon Nov 10 08:59:57 CET 2014


(Writing from phone, excuse terseness)
El 10/11/2014 08:57, "Ask Hjorth Larsen" <asklarsen at gmail.com> escribió:

> Hello
>
> What if an unrelated attribute error happens in the function call? This
> function seems very broken still. Should the calculator object not be the
> one to raise notimpl.?
>
> Or one could separately do meth = calc.get_charges then meth() to catch
> the exception correctly.
>
> Best regards
> Ask
> El 10/11/2014 08:23, "Jakob Schiøtz" <schiotz at fysik.dtu.dk> escribió:
>
>> Your first edit, the return statement, is of course correct.  The fix has
>> apparently already been made in the code (quite recent change, the return
>> statement is inside the try clause, but that is ok).
>>
>> The second is not correct.  You need the two selfs, the first one
>> self._calc identifies the calculator.  The second self is passed as an
>> argument to the calculator, as one calculator may be used for several
>> atoms, so it needs to know which atoms it is operating on.
>>
>> Thank you very much for your bug report!
>>
>> Best regards
>>
>> Jakob
>>
>>
>>
>> On 10 Nov 2014, at 3:13, Eric Smoll ericsmoll at gmail.com wrote:
>>
>> > Hello ASE users,
>> >
>> > There are two errors in the "get_charges" method of the "Atoms" class
>> that prevents calculators from returning charge information to the atoms
>> class via the calculator "get_charge()" method.
>> >
>> > This is the original:
>> >
>> >  601     def get_charges(self):
>> >  602         """Get calculated charges."""
>> >  603         if self._calc is None:
>> >  604             raise RuntimeError('Atoms object has no calcula
>> >  605         try:
>> >  606             charges = self._calc.get_charges(self)
>> >  607         except AttributeError:
>> >  608             raise NotImplementedError
>> >
>> > This is a corrected version:
>> >
>> >  601     def get_charges(self):
>> >  602         """Get calculated charges."""
>> >  603         if self._calc is None:
>> >  604             raise RuntimeError('Atoms object has no calcula
>> >  605         try:
>> >  606             charges = self._calc.get_charges()
>> >  607         except AttributeError:
>> >  608             raise NotImplementedError
>> >  609         return charges
>> >
>> > I made two edits. 1.) There was no return statement so even if a
>> NotImplementedError was not thrown, nothing was returned.
>> > 2.) the "get_charges" method on line 606 has 2 references to "self."
>> >
>> > Best,
>> > Eric
>> > _______________________________________________
>> > ase-users mailing list
>> > ase-users at listserv.fysik.dtu.dk
>> > https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>>
>> --
>> 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
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listserv.fysik.dtu.dk/pipermail/ase-users/attachments/20141110/7a8f199e/attachment.html>


More information about the ase-users mailing list