Author Topic: How to stay in console mode when using Python interpreter ovitos ?  (Read 1494 times)

Xtof

  • Jr. Member
  • **
  • Posts: 66
Hi all,

I just found out we can use OVITO as a Python interpreter and automatise many tasks. Really powerful.

I am following the manual and playing with some examples. For instance I created the modifier WignerSeitzModifier() and loaded some dump files from LAMMPS. Works very well to calculate interstitials and vacancies.

After executing ovitos (ovitos script.py), we get back to the command line. However, I would like to keep the hand in the console to check some values interactively. Is that possible ?

Also, I use to work with the Anaconda distribution and its editor Spyder to work with Python. Is it possible to load ovito inside as a module and execute it interactively from Spyder in order to stay in the console ?

Many thanks in advance and best regards,
Christophe

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: How to stay in console mode when using Python interpreter ovitos ?
« Reply #1 on: February 21, 2017, 05:28:36 PM »
Hi,

As stated here in the documentation, the current version OVITO requires that scripts are executed by the ovitos interpreter. You cannot use your standard interpreter to import the ovito Python module. The main reason for this restriction is that the Python module requires a fully initialised program environment as a context. Historically, OVITO has been a graphical program and the Python programming interface was added later as an extension plugin that allows controlling the program functions programatically. A second reason is that the precompiled Python extension modules coming with the binary version of OVITO may not be compatible with all Python interpreters, because they were built specifically for the embedded ovitos interpreter.

However, this status is likely going to change. I am working on making the ovito Python package loadable from external Python interpreters without having to start ovito or ovitos first. In a first version I will make OVITO's analysis and file I/O functions available to scripts. Later, visualization and rendering functions will follow.

In the meantime you might be able to integrate the ovitos interpreter, which behaves almost like the standard CPython interpreter, into Spyder if that IDE allows you to configure the Python interpreter to use. Let me know if you have any further questions.

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: How to stay in console mode when using Python interpreter ovitos ?
« Reply #2 on: February 21, 2017, 05:33:58 PM »
Regarding your question how to stay in console mode after executing a script file:

There is no such option in the ovitos interpreter, but you can try to append the following lines at the end of your script:

Code: [Select]
import IPython
IPython.start_ipython(['--nosep','--no-confirm-exit','--no-banner','-i'])

Xtof

  • Jr. Member
  • **
  • Posts: 66
Re: How to stay in console mode when using Python interpreter ovitos ?
« Reply #3 on: February 22, 2017, 09:40:27 AM »
The solution you suggest works, I stay into console mode. However, it looses memory of all variables that were defined in the script.

Christophe

Alexander Stukowski

  • Administrator
  • Hero Member
  • *****
  • Posts: 555
Re: How to stay in console mode when using Python interpreter ovitos ?
« Reply #4 on: February 22, 2017, 10:41:36 AM »
Yeah, true. I overlooked this.

I checked the IPython documentation now. Here is the way it's correctly done:

Code: [Select]
import IPython
IPython.terminal.embed.embed()

Xtof

  • Jr. Member
  • **
  • Posts: 66
Re: How to stay in console mode when using Python interpreter ovitos ?
« Reply #5 on: February 22, 2017, 10:50:22 AM »
It works ! Great ! Thanks a lot.

Christophe