Author Topic: Loading the dump file error in python script  (Read 774 times)

jatink

  • Newbie
  • *
  • Posts: 24
Loading the dump file error in python script
« on: September 25, 2018, 11:48:13 PM »
Dear OVITO Users,

I'm new to python scripting in OVITO. And I'm banging my head just to solve a simple begining step problem. How to load the file? Can anybody please help me to solve it. It looks like the solution is very simple but I'm constantly missing it while reading this webpage "https://ovito.org/manual/python/introduction/overview.html#loading-data-and-applying-modifiers" Anyhelp to locate the answer will be much appreciated.

This is my sample script:

from ovito.io import *
node = import_file("dump.mix")

from ovito.modifiers import *
node.modifiers.append(SelectExpressionModifier(expression="PotentialEnergy<-3.9"))
node.modifiers.append(DeleteSelectedParticlesModifier())

export_file(node, "outputdata.dump", "lammps_dump", columns = ["Position.X", "Position.Y", "Position.Z", "Structure Type"])


And this is script output:

The Python script has exited with an error.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
  File "/Applications/Ovito.app/Contents/MacOS/../Resources/python/ovito/io/import_file.py", line 121, in import_file
    importer = FileImporter.autodetect_format(ovito.dataset, first_location)
RuntimeError: File does not exist:
dump.mix
« Last Edit: September 26, 2018, 12:16:46 AM by jatin1990 »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #1 on: September 26, 2018, 11:17:52 AM »
Dear jatin1990,

the error message is telling you that there is no file called "dump.mix" in the folder where you're executing ovitos. Are you sure that's the correct name and location etc.?

-Constanze

jatink

  • Newbie
  • *
  • Posts: 24
Re: Loading the dump file error in python script
« Reply #2 on: September 26, 2018, 07:20:52 PM »
Hi Constanze,

Thanks for your reply. But I think it's working if give the full path to the dump file in "node = import_file("dump.mix")" i.e.  if I changed this command with full path then following is the new script and it's output. Please help me to understand it's working now as I'm not sure since I'm still getting error/warning in the output window which I'm not sure about it's source.


-----------------------------------------------------------------------------------
Script:

from ovito.io import *
node = import_file("/Users/kashyap/Google_Drive/NJIT/prof_singh/dump.mix")

from ovito.modifiers import *
node.modifiers.append(SelectExpressionModifier(expression="Position.X<3.9"))
node.modifiers.append(DeleteSelectedParticlesModifier())

export_file(node, "/Users/kashyap/Google_Drive/NJIT/prof_singh/outputdata.dump", "lammps_dump",
columns = ["Position.X", "Position.Y", "Position.Z"])


Output:


Invalid Python script. It does not define the function named modify().


-----------------------------------------------------------------------------------

Despite the Invalid Python script error message I do gets the output file with requested data after running the code in OVITO interface.

Additionally, is there a documentation explaining how to compile the ovitos in university cluster or to access the dump files from cluster while running ovito python script in local machine?

Thank you.
« Last Edit: September 26, 2018, 07:37:13 PM by jatink »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #3 on: September 28, 2018, 09:44:39 AM »
Hi,

it looks like you copied that code snippet you posted here in a Python script modifier in the gui? This wouldn't work, since it's only meant to contain a single modifier function.
Note that what you wrote is a stand-alone batch script which you need to run from the command line, (see this section in the manual about running scripts http://ovito.org/manual/python/introduction/running.htm .

Code: [Select]
ovitos name_of_your_script.py
-Constanze
« Last Edit: September 28, 2018, 11:24:40 AM by Constanze Kalcher »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #4 on: September 28, 2018, 10:19:25 AM »
Quote
Additionally, is there a documentation explaining how to compile the ovitos in university cluster

There is no documentation for any specific cluster, however, this section in the manual describes how to compile ovito from source if necessary.
http://www.ovito.org/manual_testing/development.html
Quote
...or to access the dump files from cluster while running ovito python script in local machine?
Yes, when running on a local machine, the path to the file in the import_file() function can be a remote sftp:// URL. Have a look at the section about importing files from remote computers.

-Constanze
« Last Edit: September 28, 2018, 10:22:28 AM by Constanze Kalcher »

jatink

  • Newbie
  • *
  • Posts: 24
Re: Loading the dump file error in python script
« Reply #5 on: October 02, 2018, 10:26:32 PM »
Hi,

it looks like you copied that code snippet you posted here in a Python script modifier in the gui? This wouldn't work, since it's only meant to contain a single modifier function.
Note that what you wrote is a stand-alone batch script which you need to run from the command line, (see this section in the manual about running scripts http://ovito.org/manual/python/introduction/running.htm .

Code: [Select]
ovitos name_of_your_script.py
-Constanze

Hello Constanze,

I think I understood what you're saying about basic working machanism of the code. Correct me if I'm wrong: Referring to the 4 methods described here http://ovito.org/manual/python/introduction/running.html  ; the first one can only modify the data and write it(can't load the input data) by reading the python script from "File > Run Python Script" ONLY; second method is complete A to Z solution where it can load the data, modify it and export it by running the script from command terminal of the operating system ONLY; third and fourth methods are just to write once own modifier or write once own rendering image template by running the script from "Python Script Modifier" from OVITO's GUI ONLY.

Additionally, I'm not able to submit ovito job from terminal; it says "-bash: ovitos: command not found". So I guess installing the OVITO with the help of GUI will not install command line capability so one had to build it from source while following the instructions given at "http://www.ovito.org/manual_testing/development.build_macosx.html". But I'm facing errors while executing a part of the instructions given below:

/opt/local/bin/python3.5 configure.py \
   --qmake $HOME/Qt/5.7/clang_64/bin/qmake \
   --confirm-license \
   --no-designer-plugin \
   --no-qml-plugin \
   --assume-shared \
   --sip=/opt/local/bin/sip-3.5 \
   --concatenate \
   --enable QtCore \
   --enable QtGui \
   --enable QtWidgets \
   --enable QtMacExtras



It throws following,

/opt/local/Library/Frameworks/Python.framework/Versions/3.5/Resources/Python.app/Contents/MacOS/Python: can't open file 'configure.py': [Errno 2] No such file or directory


P.S: I'm using OVITO version 3.0.

Thanks a lot for your time.
« Last Edit: October 03, 2018, 02:02:20 AM by jatink »

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #6 on: October 03, 2018, 08:24:54 PM »
Hello jatink,

you don't have to build it from source. The python scripting interface comes with the OVITO package.
From your error message I can see you're using MacOS. If you right click on the OVITO-icon in your applications folder and choose "Show package Content", you can see that "ovitos" is in the subfolder "MacOS".

So from the terminal, you can call it like this:

Code: [Select]
/Applications/Ovito.app/Contents/MacOS/ovitos
or you can make your life easier by adding the following line to your "~/.bash_profile" file:
Code: [Select]
export PATH=/Applications/Ovito.app/Contents/MacOS/:$PATH so you won't have to type the whole path every time.

Edit: If you're not really familiar with the Terminal app, I think this might be helpful:
https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/CommandLInePrimer/CommandLine.html

-Constanze



« Last Edit: October 03, 2018, 08:56:17 PM by Constanze Kalcher »

jatink

  • Newbie
  • *
  • Posts: 24
Re: Loading the dump file error in python script
« Reply #7 on: October 04, 2018, 07:54:27 AM »
Thanks Constanze, for your informative reply. Can you please help me with the following error:

Jatins-MacBook-Air:test kashyap$ /Applications/Ovito.app/Contents/MacOS/ovitos velocity.py
Traceback (most recent call last):
  File "/Users/kashyap/Google_Drive/NJIT/prof_singh/test/ovito.py", line 2, in <module>
    print("Hello, this is OVITO %i.%i.%i" % ovito.version)
AttributeError: module 'ovito' has no attribute 'version'
ERROR: Failed to initialize Python interpreter.


Moreover, can you please confirm about correctness about the first part of my last reply.
Thank you.

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #8 on: October 04, 2018, 02:03:44 PM »
Hello jatink,

as for your previous reply, yes in principle you're right, except for the part about not being able to load input data when invoking "Run python script" from the GUI, but you would need to call add_to_scene() to make it appear in your viewports. More on this in the first highlighted box in this Manual entry about importing files:
http://ovito.org/manual_testing/python/introduction/file_io.html.

I can't really make sense of your error message though. Did you maybe accidentally install several instances of OVITO? Also can you tell me what this file is?
Quote
/Users/kashyap/Google_Drive/NJIT/prof_singh/test/ovito.py

-Constanze

Constanze Kalcher

  • Administrator
  • Full Member
  • *****
  • Posts: 121
Re: Loading the dump file error in python script
« Reply #9 on: October 04, 2018, 05:14:17 PM »
My guess is that "ovito.py" is a script you wrote and it's in the same folder as "velocity.py"? If that's the case, note that this file might be mistaken for the actual ovito module when you call
Code: [Select]
import ovitoand that's what causes the error. (Read more on python modules here).
You should better rename it to something else.

jatink

  • Newbie
  • *
  • Posts: 24
Re: Loading the dump file error in python script
« Reply #10 on: October 04, 2018, 10:55:29 PM »
Hello jatink,

as for your previous reply, yes in principle you're right, except for the part about not being able to load input data when invoking "Run python script" from the GUI, but you would need to call add_to_scene() to make it appear in your viewports. More on this in the first highlighted box in this Manual entry about importing files:
http://ovito.org/manual_testing/python/introduction/file_io.html.
Quote
/Users/kashyap/Google_Drive/NJIT/prof_singh/test/ovito.py

-Constanze

HI Constanze,

I'm sorry to be not clear enough at the first place. When I said "the first one can only modify the data and write it(i.e. can't load the input data) by reading the python script from "File > Run Python Script" ONLY"; I meant this method can not be used to load the data, it can only be use to modify and write the data once the dump file is already loaded into OVITO from GUI functionality. So it's similar to the Python Script modifier. And we can't submit batch job script from File > Run Python Script or can we?  I gets the error about function modify is not define when I submit batch script from File > Run Python Script. Please let me know if I'm wrong.

Thank you.

jatink

  • Newbie
  • *
  • Posts: 24
Re: Loading the dump file error in python script
« Reply #11 on: October 04, 2018, 10:56:37 PM »
My guess is that "ovito.py" is a script you wrote and it's in the same folder as "velocity.py"? If that's the case, note that this file might be mistaken for the actual ovito module when you call
Code: [Select]
import ovitoand that's what causes the error. (Read more on python modules here).
You should better rename it to something else.

You're correct! That solved the error. I'll be careful from next time.
Thanks a lot!
« Last Edit: October 04, 2018, 11:06:07 PM by jatink »