2014-03-26 55 views
1

我試圖用泡菜來轉儲MDAnalysis.universe對象,但我得到了錯誤mmessage像如何使用pickle從MDAnalysis模塊轉儲Universe對象?

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

MDAnalysis.Universe對象包含一些對象,這些對象不能被標準機制(如打開的文件描述符)序列化和挑選。需要編寫專門的__getstate__()__setstate__()方法,如Pickle protocol中所述,但是從目前的0.8.1(2014年4月)版本開始並沒有實施這些方法。

具體錯誤由Manel在他的comment on MDAnalysis Issue 173中解釋:Pickle搜索__getstate__()方法。雖然沒有實現,但Universe管理自己的屬性以實時生成「虛擬屬性」,將其解釋爲原子選擇並最終返回一個空的AtomGroup實例。這又被稱爲是因爲pickle認爲它是__getstate__的本地實現。但是,AtomGroup不可調用,並導致錯誤。

正如您可能注意到的,您通過詢問​​或提交問題得到了更快的響應 - Stackoverflow在回答這些特定問題的開發人員列表中通常較低。