我尝试使用pickle来转储MDAnalysis.universe对象,但是我得到了错误mmessage,如
Traceback (most recent call last):
File "convert.py", line 9, in <module>
blob = pickle.dumps(u)
File "/usr/lib/python2.7/pickle.py", line 1374, in dumps
Pickler(file, protocol).dump(obj)
File "/usr/lib/python2.7/pickle.py", line 224, in dump
self.save(obj)
File "/usr/lib/python2.7/pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "/usr/lib/python2.7/pickle.py", line 419, in save_reduce
save(state)
File "/usr/lib/python2.7/pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "/usr/lib/python2.7/pickle.py", line 649, in save_dict
self._batch_setitems(obj.iteritems())
File "/usr/lib/python2.7/pickle.py", line 663, in _batch_setitems
save(v)
File "/usr/lib/python2.7/pickle.py", line 306, in save
rv = reduce(self.proto)
File "/usr/lib/python2.7/copy_reg.py", line 84, in _reduce_ex
dict = getstate()
TypeError: 'AtomGroup' object is not callable
任何建议将不胜感激!
答案 0 :(得分:0)
MDAnalysis.Universe个对象包含一些无法通过标准机制序列化和腌制的对象,例如打开文件描述符。我们需要编写专门的__getstate__()
和__setstate__()
方法,如Pickle protocol所述,但这些方法都不会在当前的0。8。1(2014年4月)版本中实施。
Manel在他的comment on MDAnalysis Issue 173中解释了具体的错误:Pickle搜索__getstate__()
方法。虽然没有实现,但是Universe
管理它自己的属性来动态生成“虚拟属性”,将其解释为原子选择并最终返回一个空的AtomGroup实例。反过来,这被称为因为pickle认为它是__getstate__
的本地实现。但是,AtomGroup不可调用,并且会产生错误。
正如您可能已经注意到,通过询问MDAnalysis user list或提交问题,您获得了更快的响应 - Stackoverflow通常在开发人员列表中较低,以回答此类特定问题。