patrickfuller / imolecule

An embeddable webGL molecule viewer and file format converter.
http://patrickfuller.github.io/imolecule/
MIT License
86 stars 18 forks source link

'pybel' has no attribute 'ob' #33

Closed ghost closed 6 years ago

ghost commented 6 years ago

While attempting to draw() a smile, I get this error message:

`AttributeError Traceback (most recent call last)

in () ----> 1 import imolecule as i 2 i.draw("CC1(C(N2C(S1)C(C2=O)NC(=O)CC3=CC=CC=C3)C(=O)O)C") ~/anaconda2/envs/python35/lib/python3.5/site-packages/imolecule/__init__.py in () ----> 1 from imolecule.notebook import draw, generate, to_json # noqa 2 3 __title__ = 'imolecule' 4 __version__ = '0.1.13' 5 __author__ = 'Patrick Fuller' ~/anaconda2/envs/python35/lib/python3.5/site-packages/imolecule/notebook.py in () 6 7 from . import json_formatter as json ----> 8 from . import format_converter 9 10 file_path = os.path.normpath(os.path.dirname(__file__)) ~/anaconda2/envs/python35/lib/python3.5/site-packages/imolecule/format_converter.py in () 10 try: 11 import pybel ---> 12 ob = pybel.ob 13 table = ob.OBElementTable() 14 has_ob = True AttributeError: module 'pybel' has no attribute 'ob'` I can't seem to find a reference to pybel.ob... Is this a mistake?
patrickfuller commented 6 years ago

It's likely that openbabel was not properly installed. How'd you install the program?

ghost commented 6 years ago

Hi Patrick, I used:

import sys
!{sys.executable} -m pip install pybel

in jupyter.

patrickfuller commented 6 years ago

That's the issue. The pip pybel package doesn't install the openbabel library, so most of pybel won't work.

Your two options are to install from source or, if you use conda, try conda install -c openbabel openbabel (works 80% of the time).

ghost commented 6 years ago

Hi Patrick, thanks for your help, I was able to get it working using the conda install method.

diallobakary4 commented 5 years ago

I am trying to use another package which also require openbabel and pybel. Reinstalling using conda install -c openbabel openbabel did not help. I am getting the same error message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-b8e3e949172b> in <module>
      2 
      3 my_mol = PDBComplex()
----> 4 my_mol.load_pdb("C:\\Users\username\Documents\HD\MEP\IspC_DXR\PfDXR_3D\\5jaz.pdb") # Load the PDB file into PLIP class
      5 print(my_mol) # Shows name of structure and ligand binding sites
      6 my_bsid = 'E20:A:2001' # Unique binding site identifier (HetID:Chain:Position)

~\Anaconda3\envs\base-copy\lib\site-packages\plip\modules\preparation.py in load_pdb(self, pdbpath, as_string)
   1316         if not as_string:
   1317             self.sourcefiles['filename'] = os.path.basename(self.sourcefiles['pdbcomplex'])
-> 1318         self.protcomplex, self.filetype = read_pdb(self.corrected_pdb, as_string=True)
   1319 
   1320         # Update the model in the Mapper class instance

~\Anaconda3\envs\base-copy\lib\site-packages\plip\modules\supplemental.py in read_pdb(pdbfname, as_string)
    383 def read_pdb(pdbfname, as_string=False):
    384     """Reads a given PDB file and returns a Pybel Molecule."""
--> 385     pybel.ob.obErrorLog.StopLogging()  # Suppress all OpenBabel warnings
    386     if os.name != 'nt':  # Resource module not available for Windows
    387         maxsize = resource.getrlimit(resource.RLIMIT_STACK)[-1]

@patrickfuller, other suggestion to this problem?

patrickfuller commented 5 years ago

@diallobakary4 you should ask over at openbabel/openbabel.

diallobakary4 commented 5 years ago

Ok. Thank you.

Le ven. 11 janv. 2019 à 20:26, Patrick Fuller notifications@github.com a écrit :

@diallobakary4 https://github.com/diallobakary4 you should ask over at openbabel/openbabel https://github.com/openbabel/openbabel.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/patrickfuller/imolecule/issues/33#issuecomment-453611581, or mute the thread https://github.com/notifications/unsubscribe-auth/AM6CFaXmF9O9gqTzrZA6MHejh1oJ6_7Jks5vCNdogaJpZM4T2zfg .

--

Bakary N’tji DIALLO

PhD Student (Bioinformatics) http://linkedin.com/in/bakarydiallo, Research Unit in Bioinformatics (RUBi) https://rubi.ru.ac.za/

Mail: diallobakary4@gmail.com | Skype: diallobakary4

Tel: ​+27798233845 | +223 74 56 57 22 | +223 97 39 77 14

thoth291 commented 3 years ago

I've got into the same situation and simply added one more except after this line: https://github.com/patrickfuller/imolecule/blob/8e143f21928cec54d346ccd259ef4b9289da1700/imolecule/format_converter.py#L18 Since I'm using openbabel > 3 - this check is really not configured well and it fails not at import error - but at attribute error - so one more except is needed to handle this case.

...
except ImportError:
    has_ob = False
except:
    has_ob = False
patrickfuller commented 3 years ago

@thoth291 I just took a pass at making the code support only open babel 3. Try pip install -U imolecule and let me know if it works for you.

I'll also update the code base to asyncio / python 3 / ES6 when I get the time. Hope this helps!

thoth291 commented 3 years ago

Thank you, @patrickfuller , it works (in terms of importing properly). I also noticed that it doesn't work in Jupyter Lab - I made a reference about it here: #32

patrickfuller commented 3 years ago

@thoth291 that's unfortunately a harder problem and would take some work to do right. I'd recommend using a better maintained chemical drawer like 3DMol.js if it suits your needs.

Sorry I can't help more!

thoth291 commented 3 years ago

@patrickfuller , yep, that's what I ended up to be using so far. Sort of a mixture of rdkit and py3dmol... Thank you for your help!