[ase-users] Error with tkinter & matplotlib

Ask Hjorth Larsen asklarsen at gmail.com
Mon Sep 3 18:13:55 CEST 2018


Hi,

Den tor. 23. aug. 2018 kl. 08.37 skrev Clayton Spencer via ase-users
<ase-users at listserv.fysik.dtu.dk>:
>
>
> I'm new to ASE (and also to Python and CentOS 7). Please forgive my ignorance.
>
> I successfully ran the ethaneNEB.py file.  I wanted to view the energy profile along the converged NEB approximation to the MEP.  I modified the ethaneNEB.py file according to the "Diffusion of Au on Al(100) surface (NEB)" (https://wiki.fysik.dtu.dk/ase/tutorials/neb/diffusion.html).
>
> Running that file (shown below) with:
> $ python ethaneNEB.py > ethaneNEB.out 2>&1 &
>
> produced the follow errors in the .out file:
>
> Traceback (most recent call last):
>   File "ethaneNEB.py", line 5, in <module>
>     import matplotlib.pyplot as plt
>   File "/home/cfspence/.local/lib/python2.7/site-packages/matplotlib/pyplot.py", line 115, in <module>
>     _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
>   File "/home/cfspence/.local/lib/python2.7/site-packages/matplotlib/backends/__init__.py", line 62, in pylab_setup
>     [backend_name], 0)
>   File "/home/cfspence/.local/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 4, in <module>
>     from . import tkagg  # Paint image to Tk photo blitter extension.
>   File "/home/cfspence/.local/lib/python2.7/site-packages/matplotlib/backends/tkagg.py", line 5, in <module>
>     from six.moves import tkinter as Tk
>   File "/home/cfspence/.local/lib/python2.7/site-packages/six.py", line 203, in load_module
>     mod = mod._resolve()
>   File "/home/cfspence/.local/lib/python2.7/site-packages/six.py", line 115, in _resolve
>     return _import_module(self.mod)
>   File "/home/cfspence/.local/lib/python2.7/site-packages/six.py", line 82, in _import_module
>     __import__(name)
> ImportError: No module named Tkinter
>
> I get a similar "No module named Tkinter" when running ase gui from the command line.  For reference I'm running on CentOS 7 which uses Python 2.7.5.
>
> Please advise on how to fix the matplotlib and tkinter issues.  Thanks, in advance, for your help!

If you simply try importing Tkinter, does that fail?

python -c "import Tkinter"

If you reorder the imports so you import matplotlib right in the
beginning, does this change anything?

Best regards
Ask

>
> --Clayton
>
> The modified ethaneNEB.py file is shown below:
> +++++++++++++++++++++++++++++++++++++++++++++++++++
>
> from ase.build import molecule
> from ase.neb import NEB
> from ase.calculators.emt import EMT
> from ase.optimize.fire import FIRE as QuasiNewton
> import matplotlib.pyplot as plt
> from ase.neb import NEBTools
> from ase.io import read
>
> # Optimise molecule
> initial = molecule('C2H6')
> initial.set_calculator(EMT())
> relax = QuasiNewton(initial)
> relax.run(fmax=0.05)
>
> # Create final state
> final = initial.copy()
> final.positions[2:5] = initial.positions[[3, 4, 2]]
>
> # Generate blank images
> images = [initial]
>
> for i in range(9):
>     images.append(initial.copy())
>
> for image in images:
>     image.set_calculator(EMT())
>
> images.append(final)
>
> # Run IDPP interpolation
> neb = NEB(images)
> neb.interpolate()
>
> # Run NEB calculation
> qn = QuasiNewton(neb, trajectory='ethane_linear.traj',
>                  logfile='ethane_linear.log')
> qn.run(fmax=0.05)
>
> #Read in the images
> images = read('ethane_linear.traj at -11')
>
> nebtools = NEBTools(images)
>
> #Get the calculated barrier and the energy change from inital to final configuration
> Ef, dE = nebtools.get_barrier()
> print(Ef, dE)
>
> #Get the barrier without any interpolation between highest images.
> Ef, dE = nebtools.get_barrier(fit=FALSE)
> print(Ef, dE)
>
> #Create a figure like that coming from ASE-GUI.
> fig = nebtools.plot_band()
> fig.savefig('ethane-rotationBarrier.png')
>
> _______________________________________________
> ase-users mailing list
> ase-users at listserv.fysik.dtu.dk
> https://listserv.fysik.dtu.dk/mailman/listinfo/ase-users



More information about the ase-users mailing list