I experienced a problem using the 'import module' instead of the 'from module import ...' syntax. This clearly shows that my understanding of loading modules is not sufficient. As far as I find elsewhere, this difference is mainly a style issue, but this does not explains the following situation.
I installed ase using
sudo apt install python3-ase
I tried the following:
import ase
ase.io.read
which outputs
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'ase' has no attribute 'io'
However, when trying
from ase.io import read
read
or - also possible -
from ase.io import read
import ase
ase.io.read
I get the output
<function read at 0x7f33dc721730>
The latter is the desired result as I want to use the ase.io.read function to read a .cif file.
More about the origin of the problem is shown in the following python session:
import sys
import ase
sys.modules['ase']
module 'ase' from '/home/vanbeverj/Programs/anaconda3/envs/abienv/lib/python3.6/site-packages/ase/init.py'
dir(ase)
['Atom', 'Atoms', 'LooseVersion', 'all', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'version', 'ase', 'atom', 'atoms', 'calculators', 'cell', 'constraints', 'data', 'dft', 'formula', 'geometry', 'np', 'parallel', 'symbols', 'sys', 'transport', 'units', 'utils']
from ase.io import read
dir(ase)
['Atom', 'Atoms', 'LooseVersion', 'all', 'builtins', 'cached', 'doc', 'file', 'loader', 'name', 'package', 'path', 'spec', 'version', 'ase', 'atom', 'atoms', 'calculators', 'cell', 'constraints', 'data', 'dft', 'formula', 'geometry', 'io', 'np', 'parallel', 'symbols', 'sys', 'transport', 'units', 'utils']
The 'dir(ase)' commands have clearly different outputs. What happens with e.g. the io submodule? Can someone explains me what is going on under the hood?