Rdkit: MaeMolSupplier NameError - python-3.x

I would like to able to extract details about a molecule in ".mae" format. I imported the rdkit.Chem.rdmolfiles functions and it seems to work for MolFromSmiles, but not for MaeMolSupplier as suggested in the 2019 documentation. Instead I get a NameError. Any aid/help in calling this function would be greatly appreciated.
Works OK with MolFromSmiles
import rdkit
from rdkit.Chem.rdmolfiles import *
mol = MolFromSmiles('C1NCN1')
print(mol)
(my-rdkit-env) [Me]$ python3 testrdkit.py
<rdkit.Chem.rdchem.Mol object at 0x7f237f917030>
Now to show the error
import rdkit
from rdkit.Chem.rdmolfiles import *
suppl = MaeMolSupplier(file('five.mae'))
print(suppl)
my-rdkit-env) [Me]$ python3 testrdkit.py
Traceback (most recent call last):
File "testrdkit.py", line 8, in <module>
suppl = MaeMolSupplier(file('five.mae'))
NameError: name 'MaeMolSupplier' is not defined

import * doesn't work here either.
Just import rdmolfiles.
from rdkit.Chem import rdmolfiles
suppl = rdmolfiles.MaeMolSupplier('five.mae')
print(suppl)
<rdkit.Chem.rdmolfiles.MaeMolSupplier object at 0x000002792CEFC5B0>

Related

Cyclic import in Python3

I have the following directory structure:
my-game/
__init__.py
logic/
__init__.py
game.py
player.py
game.py and player.py have import dependency on each other (cyclic imports).
game.py has the following definition.
from logic.player import RandomPlayer, InteractivePlayer
T = 8
class Game:
def __init__(self, p1, p2)
...
# some other things
if __name__ == '__main__':
p1 = RandomPlayer()
p2 = InteractivePlayer()
g = Game(p1, p2)
...
player.py is as follows:
from logic.game import T
class Player:
def __init__(self):
...
class RandomPlayer(Player):
def __init__(self):
...
class InteractivePlayer(Player):
def __init__(self):
...
I am trying to run the game from logic/ directory but I get the following error.
$ python3 game.py
Traceback (most recent call last):
File "game.py", line 2, in <module>
from logic.player import RandomPlayer, InteractivePlayer
ModuleNotFoundError: No module named 'logic'
I then tried running game.py from the directory higher up (my-game/).
$ python3 logic/game.py
Traceback (most recent call last):
File "logic/game.py", line 2, in <module>
from logic.player import RandomPlayer, InteractivePlayer
ModuleNotFoundError: No module named 'logic'
What am I doing wrong? How can I make these cyclic imports work?
I have also tried using this import in player.py
from .game import T
and using
from .player import RandomPlayer, InteractivePlayer
in game.py.
In this case, I get a different error. For example, when running from my-game/,
$ python3 logic/game.py
Traceback (most recent call last):
File "logic/game.py", line 2, in <module>
from .player import RandomPlayer, InteractivePlayer
ModuleNotFoundError: No module named '__main__.player'; '__main__' is not a package
I get a similar error when running from logic/ directory.
I looked at this post but didn't understand where I was going wrong.
You are made a circulair import in your code try to remove it from your import
Vist this link you can find some other info about circular import :Remove python circular import

why when I use " from module import * " and I want want to see functions of the module by help (module) it is not working?

why should I use just import module to see the functions in it?
By help (module )
but it is not woking with from module import *
is there any way to see the functions of it by from module import *
When you do from module import * - only the exported symbols from module are added to your module. The name module itself is not imported. Since help merely looks at documentation of imported symbols, that's why your help(module) is not working.
>>> from os import *
>>> help(os)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'os' is not defined
>>>
What you can do is this:
>>> import os
>>> help(os)
>>>
>>> from os import path
>>>

How to call the class choosercolor from module tkinter in python function askcolor?

I want to call the askcolor function to call the color palette:
from tkinter import *
colorchooser.askcolor()
But I get error:
Traceback (most recent call last):
File "<pyshell#1>", line 1, in <module>
colorchooser.askcolor()
NameError: name 'colorchooser' is not defined
You are using from tkinter import * that imports from tkinter all methods and variables (actually all public objects not starting with _), but not its submodules. (you can read more here)
So when you try to call colorchooser.askcolor() you have not imported it yet because it's a submodule!
You can change your import and it will resolve to issue!
Try this:
from tkinter import colorchooser
colorchooser.askcolor()
Hope this helps you!

AttributeError: module 'typing' has no attribute 're' in pandas Python 3.7

I can't import pd from pandas because i have this error. I search on google but I didn't find the fix for this..
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37\lib\site-packages\pandas\__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "C:\Python37\lib\site-packages\pandas\compat\__init__.py", line 431, in <module>
re_type = typing.re.Pattern
AttributeError: module 'typing' has no attribute 're'
I think this is changing underneath us as Python's typing module matures, but in our case, the issue was that we did from Typing import re, and then later did something like:
def funct(some_re: re.Pattern):
The fix was dumb. Simply change your import to be from typing import Pattern and then do:
def funct(some_re: Pattern):
Bleh. Warts.

surprise.dataset is not a package

When I try to execute this code
import surprise.dataset
file = 'ml-100k/u.data'
col = 'user item rating timestamp'
reader = surprise.dataset.Reader(line_format = col, sep = '\t')
data = surprise.dataset.Dataset.load_from_file(file, reader = reader)
data.split(n_folds = 5)
I get this error:
Traceback (most recent call last):
File "/home/user/PycharmProjects/prueba2/surprise.py", line 1, in <module>
import surprise.dataset
File "/home/user/PycharmProjects/prueba2/surprise.py", line 1, in <module>
import surprise.dataset
ModuleNotFoundError: No module named 'surprise.dataset'; 'surprise' is not a package
But surprise is installed. How can I use it?
If you want to import a submodule, instead of doing:
import surprise.dataset
do:
from surprise import dataset
then in the rest of the code, reference it as dataset instead of surprise.dataset (i.e. replace surprise.dataset.Reader with dataset.Reader). If you don’t want to update the rest of your code, you can also just import the whole surprise module instead with:
import surprise

Resources