[ase-users] Fwd: error with isinstance
Ask Hjorth Larsen
asklarsen at gmail.com
Thu Jan 26 20:44:41 CET 2017
Hi Oscar
2017-01-13 3:45 GMT+01:00 Oscar Xavier Guerrero via ase-users
<ase-users at listserv.fysik.dtu.dk>:
> Forgot to include ase-users
>
> ---------- Forwarded message ----------
> From: Oscar Xavier Guerrero <oscarxavier.ox at gmail.com>
> Date: 2017-01-12 20:42 GMT-06:00
> Subject: Re: [ase-users] error with isinstance
> To: Gaël Donval <G.Donval at bath.ac.uk>
>
>
> Hi,
> I'm using Anaconda's editor Spyder, I found out that the 'error' occurs when
> ase.atom is reloaded. When the script is rerun it reloads that module, was
> able to reproduce it with the reload function.
>
> Here's an example with Anaconda and without of Anaconda:
>
>> Python 3.5.2 |Anaconda 4.1.1 (64-bit)| (default, Jul 2 2016, 17:53:06)
>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> from imp import reload
>> >>> import ase
>> >>> from ase.atom import Atom
>> >>> a = Atom()
>> >>> isintance(a, Atom)
>> True
>> >>> reload(ase.atom)
>> <module 'ase.atom' from
>> '/software/easybuild/software/ASE/3.9.1.4567-intel-2015B-Python-2.7.10/lib/python2.7/site-packages/ase/atom.py'>
>> >>> from ase.atom import Atom
>> >>> isintance(a, Atom)
>> False
This is slightly funny, but expected. When you reload the module, the
class is defined again. This creates a new class-object, also called
Atoms, which may or may not be functionally identical to the previous
one. Your previous Atoms object is still an instance of the previous
class which still exists somewhere in memory. Try printing the
address, e.g. print id(a.__class__) and you will see the two classes
are stored in different locations in memory. Also, you can manipulate
those two classes independently (e.g. you can monkeypatch one of
them), and that would make them differ functionally. Since that would
affect instances of the two classes differently, they cannot be
considered to be of the same class - just like two empty lists are
different objects even though they are momentarily identical.
Best regards
Ask
>
>
>
>> Python 2.7.10 (default, May 17 2016, 10:28:57)
>> [GCC Intel(R) C++ gcc 4.8 mode] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>> >>> from imp import reload
>> >>> import ase
>> >>> from ase.atom import Atom
>> >>> a = Atom()
>> >>> isintance(a, Atom)
>> True
>> >>> reload(ase.atom)
>> <module 'ase.atom' from
>> '/software/easybuild/software/ASE/3.9.1.4567-intel-2015B-Python-2.7.10/lib/python2.7/site-packages/ase/atom.py'>
>> >>> from ase.atom import Atom
>> >>> isintance(a, Atom)
>> False
>
>
>
>
>
>
>
> 2017-01-12 4:24 GMT-06:00 Gaël Donval via ase-users
> <ase-users at listserv.fysik.dtu.dk>:
>>
>> Hi,
>> > I'm writing some code and I'm getting errors caused by a wrongful
>> > evaluation of the isinstance function in the ase code. The error
>> > occurs
>> > when I have an ase.atoms.Atom object, lets call it atom, and I rerun
>> > a
>> > script that reloads ase modules, then isinstance(atom,
>> > ase.atoms.Atom) will
>> > return False.
>>
>> Would it be possible to provide a minimum (non-)working example?
>>
>> Gaël
>> _______________________________________________
>> ase-users mailing list
>> ase-users at listserv.fysik.dtu.dk
>> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users
>
>
>
>
> _______________________________________________
> 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