Skip to content

[BUG] fixes pdb file cause FileNotFoundError when using --nofixfile and --pymol #184

@chAwater

Description

@chAwater

To Reproduce

  1. Edit the 1vsn.pdb file, add an empty line in the end. (mimic the fix will be applied to the pdb)
  2. Run the code
docker run --rm \
    -v ${PWD}:/results \
    -w /results \
    -u $(id -u ${USER}):$(id -g ${USER}) \
    pharmai/plip:latest -f 1vsn.pdb -yv --nofixfile
  1. See the error
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/pymol/internal.py", line 293, in file_read
    handle = open(finfo, 'rb')
             ^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: './plipfixed.1vsn_1vfawm8i.pdb'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/src/plip/plipcmd.py", line 355, in <module>
    main()
  File "/src/plip/plipcmd.py", line 351, in main
    run_analysis(expanded_path, arguments.pdbid)  # Start main script
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/plip/plipcmd.py", line 160, in run_analysis
    process_pdb(inputstruct, config.OUTPATH, as_string=read_from_stdin, outputprefix=output_prefix)
  File "/src/plip/plipcmd.py", line 87, in process_pdb
    [visualize_in_pymol(plcomplex) for plcomplex in complexes]
  File "/src/plip/plipcmd.py", line 87, in <listcomp>
    [visualize_in_pymol(plcomplex) for plcomplex in complexes]
     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/src/plip/visualization/visualize.py", line 40, in visualize_in_pymol
    cmd.load(plcomplex.sourcefile)
  File "/usr/lib/python3/dist-packages/pymol/importing.py", line 819, in load
    kw['contents'] = _self.file_read(filename)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/pymol/internal.py", line 297, in file_read
    raise pymol.CmdException('failed to open file "%s"' % finfo)
pymol.CmdException:  Error: failed to open file "./plipfixed.1vsn_1vfawm8i.pdb"

Debug
After applied fixes pdb

  • self.sourcefiles['pdbcomplex'] = pdbpath_fixed
  • but the file was not saved when --nofixfile

if not config.PLUGIN_MODE:
if pdbparser.num_fixed_lines > 0:
logger.info(f'{pdbparser.num_fixed_lines} lines automatically fixed in PDB input file')
# Save modified PDB file
if not as_string:
basename = os.path.basename(pdbpath).split('.')[0]
else:
basename = "from_stdin"
pdbpath_fixed = tmpfile(prefix='plipfixed.' + basename + '_', direc=self.output_path)
create_folder_if_not_exists(self.output_path)
self.sourcefiles['pdbcomplex'] = pdbpath_fixed
self.corrected_pdb = re.sub(r'[^\x00-\x7F]+', ' ', self.corrected_pdb) # Strip non-unicode chars
if not config.NOFIXFILE: # Only write to file if this option is not activated
with open(pdbpath_fixed, 'w') as f:
f.write(self.corrected_pdb)
self.information['pdbfixes'] = True

Expected behavior

  • Maybe remove the fixed file in the end of the program?

Related issues (maybe)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions