Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aaronfinke opened this issue Jun 12, 2023 · 5 comments
Open

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

aaronfinke opened this issue Jun 12, 2023 · 5 comments

Comments

@aaronfinke
Copy link

aaronfinke commented Jun 12, 2023

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Author

aaronfinke commented Nov 17, 2023

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
Copy link
Member

bkpoon commented Nov 17, 2023

@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
Copy link
Contributor

Fixed: 44a6dc3
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants