openmm / pdbfixer

PDBFixer fixes problems in PDB files
Other
453 stars 114 forks source link

PDB file lines read in as Models, throws "AttributeError: 'Model' object has no attribute 'decode'" #237

Open ddcas9 opened 2 years ago

ddcas9 commented 2 years ago

In pdbfixer 1.6, 1.7 and 1.8 and openmm 7.5.1 (and 7.6 running pdbfixer 1.8), The following line:

fixer = PDBFixer(url=f'https://files.rcsb.org/download/{pdbid}.pdb')

fails with the trace (using pdbfixer 1.7 and openmm 7.5.1):

7 frames

/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2115             magic_arg_s = self.var_expand(line, stack_depth)
   2116             with self.builtin_trap:
-> 2117                 result = fn(magic_arg_s, cell)
   2118             return result
   2119 

<decorator-gen-53> in time(self, line, cell, local_ns)

/usr/local/lib/python3.7/dist-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/usr/local/lib/python3.7/dist-packages/IPython/core/magics/execution.py in time(self, line, cell, local_ns)
   1191         else:
   1192             st = clock2()
-> 1193             exec(code, glob, local_ns)
   1194             end = clock2()
   1195             out = None

<timed exec> in <module>()

/usr/local/lib/python3.7/site-packages/pdbfixer/pdbfixer.py in __init__(self, filename, pdbfile, pdbxfile, url, pdbid)
    263                 self._initializeFromPDBx(contents)
    264             else:
--> 265                 self._initializeFromPDB(StringIO(contents))
    266 
    267         # Check the structure has some atoms in it.

/usr/local/lib/python3.7/site-packages/pdbfixer/pdbfixer.py in _initializeFromPDB(self, file)
    283 
    284         structure = PdbStructure(file)
--> 285         pdb = app.PDBFile(structure)
    286         self.topology = pdb.topology
    287         self.positions = pdb.positions

/usr/local/lib/python3.7/site-packages/openmm/app/pdbfile.py in __init__(self, file, extraParticleIdentifier)

/usr/local/lib/python3.7/site-packages/openmm/app/internal/pdbstructure.py in __init__(self, input_stream, load_all_models, extraParticleIdentifier)

/usr/local/lib/python3.7/site-packages/openmm/app/internal/pdbstructure.py in _load(self, input_stream)

AttributeError: 'Model' object has no attribute 'decode'

The relevant line in _load(self, input_stream) is discussed in #81, though I don't understand where _load is called here. On line 285, a PdbStructure is passed to PDBFile, but the PdbStructure constructor isn't then called with this PdbStructure instance as an argument. Does the error actually happen on 284?

Thank you!

peastman commented 2 years ago

I just tried the line you quoted and it worked correctly. What PDB file are you trying to load? Possibly the problem is specific to that PDB ID.

nish-d commented 2 years ago

fixer = PDBFixer(pdbid = '3uo4') Facing the same error. With all PDB ids.

AttributeError                            Traceback (most recent call last)
<timed exec> in <module>

~/miniconda3/lib/python3.9/site-packages/pdbfixer/pdbfixer.py in __init__(self, filename, pdbfile, pdbxfile, url, pdbid)
    263                 self._initializeFromPDBx(contents)
    264             else:
--> 265                 self._initializeFromPDB(StringIO(contents))
    266 
    267         # Check the structure has some atoms in it.

~/miniconda3/lib/python3.9/site-packages/pdbfixer/pdbfixer.py in _initializeFromPDB(self, file)
    283 
    284         structure = PdbStructure(file)
--> 285         pdb = app.PDBFile(structure)
    286         self.topology = pdb.topology
    287         self.positions = pdb.positions

~/miniconda3/lib/python3.9/site-packages/openmm/app/pdbfile.py in __init__(self, file, extraParticleIdentifier)

~/miniconda3/lib/python3.9/site-packages/openmm/app/internal/pdbstructure.py in __init__(self, input_stream, load_all_models, extraParticleIdentifier)

~/miniconda3/lib/python3.9/site-packages/openmm/app/internal/pdbstructure.py in _load(self, input_stream)

AttributeError: 'Model' object has no attribute 'decode'
jchodera commented 2 years ago

That's odd. I was able to get this to run on osx with openmm 7.7.0, pdbfixer 1.8.1, and python 3.9.9 on the first try:

>>> from pdbfixer import PDBFixer
>>> fixer = PDBFixer(pdbid = '3uo4')

Could you do a complete conda environment dump (conda env export)?

nish-d commented 2 years ago

Attaching the output for conda env export. conda_env.txt

peastman commented 2 years ago

You have very old versions of both PDBFixer and OpenMM. You can update them with

conda update -c conda-forge openmm pdbfixer