cctbx / cctbx_project

Computational Crystallography Toolbox
https://cci.lbl.gov/docs/cctbx
Other
218 stars 116 forks source link

iotbx.pdb.input C++ signature issue #887

Open aaronfinke opened 1 year ago

aaronfinke commented 1 year ago

When I try the following (version 2023.05):

from iotbx.pdb.fetch import fetch
from libtbx.utils import Sorry, null_out
data = fetch(id="7QRZ",log=null_out(),format="pdb", local_cache=None)
pdb_in = iotbx.pdb.hierarchy.input(pdb_string=data.read())

I get the following error:

---------------------------------------------------------------------------
ArgumentError                             Traceback (most recent call last)
Cell In[13], line 4
      2 from libtbx.utils import Sorry, null_out
      3 data = fetch(id="7QRZ",log=null_out(),format="pdb", local_cache=None)
----> 4 pdb_in = iotbx.pdb.hierarchy.input(pdb_string=data.read())
      5 aa_resnames = iotbx.pdb.amino_acid_codes.one_letter_given_three_letter
      6 hierarchy = pdb_in.construct_hierarchy()

File ~/data_staff/conda/envs/edna2/lib/python3.8/site-packages/iotbx/pdb/hierarchy.py:2997, in input.__init__(self, file_name, pdb_string, source_info, sort_atoms)
   2994 else:
   2995   if (source_info is Auto): source_info = "string"
   2996   pdb_inp = iotbx.pdb.input(
-> 2997     source_info=source_info, lines=flex.split_lines(pdb_string))
   2998 super(input, self).__init__(input=pdb_inp, sort_atoms=sort_atoms)

ArgumentError: Python argument types in
    scitbx_array_family_flex_ext.split_lines(bytes)
did not match C++ signature:
    split_lines(boost::python::str multi_line_string, bool keep_ends=False, bool count_lines_first=True)
​
rjgildea commented 1 year ago

data = fetch(id="7QRZ",log=null_out(),format="pdb", local_cache=None) returns a byte string, and iotbx.pdb.hierarchy.input expects a standard Python string, so you simply need to change the following line to: pdb_in = iotbx.pdb.hierarchy.input(pdb_string=data.read().decode()).

olegsobolev commented 1 year ago

In addition to Richard's suggestion, you should use iotbx.pdb.input directly, since I'm going to remove iotbx.pdb.hierarchy.input some time soon.

aaronfinke commented 10 months ago

Now I am getting the following error:

`In [14]: pdbStructure = iotbx.pdb.fetch.load_pdb_structure('1rqw', format="pdb")

ModuleNotFoundError Traceback (most recent call last) Cell In[14], line 1 ----> 1 pdbStructure = iotbx.pdb.fetch.load_pdb_structure('1rqw', format="pdb")

File /gpfs/offline1/staff/biomax/aarfin/mambaforge/envs/edna2/lib/python3.10/site-packages/iotbx/pdb/fetch.py:217, in load_pdb_structure(id, format, allow_unknowns, local_cache) 212 """ 213 Simple utility method to load the PDB hierarchy and xray structure objects 214 directly (without intermediate files). 215 """ 216 data = fetch(id=id, format=format, log=null_out(), local_cache=local_cache) --> 217 import iotbx.pdb.input 218 pdb_in = iotbx.pdb.input(pdb_string=data.read()) 219 hierarchy = pdb_in.construct_hierarchy()

ModuleNotFoundError: No module named 'iotbx.pdb.input'`

bkpoon commented 10 months ago

@olegsobolev Should that import be just import iotbx.pdb? I also get the import error when I try import iotbx.pdb.input. But this works

import iotbx.pdb
iotbx.pdb.input
<function input at 0x12652a430>
olegsobolev commented 10 months ago

Fixed: https://github.com/cctbx/cctbx_project/commit/44a6dc3d94fb967dabef1d28c2957e823c136994 Note, that this function returns both hierarchy and xray_structure objects, so I would recommend to use it like I did in the test. If you need pdb_input, refer to the implementation.