openmm / pdbfixer

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

Index out of bounds error when calling fixer function #232

Closed Tonylac77 closed 2 years ago

Tonylac77 commented 2 years ago

Hi,

I have been trying to integrate PDBFixer in a KNIME workflow with success so far. However, I am now encountering this error when defined the PDBFixer function:

IndexError: list index out of range
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/tmp/ipykernel_31011/68583871.py in <module>
     10 print(file_name)
     11 
---> 12 fixer = PDBFixer(filename=file_name+".pdb")
     13 chains = list(fixer.topology.chains())
     14 

~/anaconda3/envs/deepchem37/lib/python3.7/site-packages/pdbfixer/pdbfixer.py in __init__(self, filename, pdbfile, pdbxfile, url, pdbid)
    245                 self._initializeFromPDBx(file)
    246             else:
--> 247                 self._initializeFromPDB(file)
    248             file.close()
    249         elif pdbfile:

~/anaconda3/envs/deepchem37/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

~/anaconda3/envs/deepchem37/lib/python3.7/site-packages/openmm/app/pdbfile.py in __init__(self, file, extraParticleIdentifier)
    161             self._positions.append(coords*nanometers)
    162         ## The atom positions read from the PDB file.  If the file contains multiple frames, these are the positions in the first frame.
--> 163         self.positions = self._positions[0]
    164         self.topology.setPeriodicBoxVectors(pdb.get_periodic_box_vectors())
    165         self.topology.createStandardBonds()

IndexError: list index out of range

This is my code:

file_name = '/home/ddop/deepchem/2o1x-fixed'

print(file_name)

fixer = PDBFixer(filename=file_name+".pdb")
chains = list(fixer.topology.chains())

df2 = pd.DataFrame(chains, columns='chain')

output_table_1 = df2

error occurs at "fixer="

I've tried this using PDBFixer 1.7 and 1.8 and openmm version 7.5.1 and 7.6, with no luck. Currently in Python 3.7.

I use essentially the exact same code in previous KNIME nodes without any issues so I am confused as to why this error occurs now with this file. I have tried this in a non-KNIME python environment and get the same error. I have also tried changing the file naming with no luck.

Any help greatly appreciated!

peastman commented 2 years ago

Can you attach the PDB file? I'll take a look and see what is causing the error.

Tonylac77 commented 2 years ago

I've just noticed that the file being used by the code above is 0kBytes, which likely is the issue. This file was generated using the other PDBFixer functions. Please find the original input file(2o1x), output file(2o1x_fixed) and the code I used to generate the 2o1x_fixed file. Hope everything is clear and thanks in advance for the help.

import pandas as pd
import deepchem as dc
from deepchem.utils import download_url, load_from_disk
from simtk.openmm.app import PDBFile
from pdbfixer import PDBFixer
from deepchem.utils.docking_utils import prepare_inputs

df = input_table_1.copy().reset_index()

print(df)

file_name = df.loc[0].at['pdb_location_var']

print(file_name)

fixed_pdb_location = '%s_fixed.pdb' % (file_name)

fixer = PDBFixer(filename=file_name+".pdb")

PDBFile.writeFile(
    fixer.topology, 
    fixer.positions,
    fixer.addMissingHydrogens(7.0),
    open(fixed_pdb_location,
    'w'))

df['pdb_location_var'] = fixed_pdb_location 

output_table_1 = df

2o1x.zip 2o1x_fixed.zip

Tonylac77 commented 2 years ago

I seem to have fixed the issue.

If I change the code to this:

fixer = PDBFixer(filename=file_name+".pdb")
fixer.addMissingHydrogens(7.0)

PDBFile.writeFile(
    fixer.topology, 
    fixer.positions,
    open(fixed_pdb_location,
    'w'))

instead of what I wrote above, the file seems to be written correctly (2.6 MB).

Will close the issues.