mittinatten / freesasa

C-library for calculating Solvent Accessible Surface Areas
http://freesasa.github.io/
MIT License
110 stars 36 forks source link

Python3 again. #23

Closed npolizzi closed 7 years ago

npolizzi commented 7 years ago

Hi, I can't seem to get freesasa to work with python3.6 on my mac. I am using OS Sierra 10.12.4 and have installed Python3.6 with anaconda. I tried the suggested fix, but to no avail. I am also a little confused by the suggestion. You changed the code in freesasa.pyx by adding a comment (# cython: c_string_type=str, c_string_encoding=utf8)? You also changed the print statement in the test.py to conform to python3, but this does not fix the underlying issue. When I try to load a structure I get the following typeerror:


fs_struct = freesasa.Structure('3x35.pdb')

TypeError Traceback (most recent call last) in () ----> 1 fs_struct = freesasa.Structure('3x35.pdb')

freesasa.pyx in freesasa.Structure.init (freesasa.c:4088)()

TypeError: expected bytes, str found


I can load it with fs_struct = freesasa.Structure('3x35.pdb'.encode('utf-8'), but this does not seem to fix the following error down the line:


fs_struct = freesasa.Structure('3x35.pdb'.encode('utf-8'))

fs_result = freesasa.Result(fs_struct)

selections = freesasa.selectArea('ifg_residue, chain A and resi 93'.enco ...: de('utf-8'),fs_struct,fs_result)

TypeError Traceback (most recent call last) in () ----> 1 selections = freesasa.selectArea('ifg_residue, chain A and resi 93'.encode('utf-8'),fs_struct,fs_result)

freesasa.pyx in freesasa.selectArea (freesasa.c:9008)()

TypeError: expected bytes, int found


Any help is much appreciated. Would really like to use your package :)

Btw, without the .encode() in the selection command, I get the str TypeError as in the structure command:


selections = freesasa.selectArea('ifg_residue, chain A and resi 93',fs_s ...: truct,fs_result)

TypeError Traceback (most recent call last) in () ----> 1 selections = freesasa.selectArea('ifg_residue, chain A and resi 93',fs_struct,fs_result)

freesasa.pyx in freesasa.selectArea (freesasa.c:9008)()

TypeError: expected bytes, str found

mittinatten commented 7 years ago

Hmm, I'm not sure what happened here. The tests passed on my computer but now they don't, must have mixed up versions.

For me it works if I change to c_string_encoding=ascii in the .pyx file. Does that work for you too?

npolizzi commented 7 years ago

Hi, Thanks for the help. No, it didn't work for me. I added the following lines (in bold) to the freesasa.pyx file:


c_string_type=str c_string_encoding=ascii

from libc.stdio cimport FILE, fopen, fclose from libc.stdlib cimport free, realloc, malloc


I reconfigured and reinstalled with make, but I get the same error. It also does not work with utf-8 encoding.

mittinatten commented 7 years ago

These Cython directives are not regular variables, they need to be added as a comment exactly as in 60735b2.

npolizzi commented 7 years ago

Ah, I see. I had it as a comment before with the utf-8 encoding and it didn't work, so I assumed I needed to uncomment. Now with the comment exactly as you mention with ascii, I no longer get the str byte encoding error. So that problem is solved. However, I still get the following error during selections:


fs_struct = freesasa.Structure('3x35.pdb')

fs_result = freesasa.Result(fs_struct)

selection = freesasa.selectArea(('ifg_atoms, chain A and name C+O and resi 93','ifg_resi, chain A and resi 93'), fs_struct, fs_result) Assertion failed: (result), function select_area_impl, file selection.c, line 533. Abort trap: 6


Any thoughts on that one?

Thanks again!

mittinatten commented 7 years ago

It probably fails because you haven't performed a calculation. Here's the documentation for how to run a simple calculation: https://freesasa.github.io/doxygen/Python.html

The error was caught in the C code, but should ideally have been caught already by the Python wrapper with an explanatory message. Will try to fix this after my vacation!

npolizzi commented 7 years ago

Yep, you're right. I had a typo in the command. I should have used freesasa.calc, not freesasa.Result. Thank you! Everything works now.