Forum Navigation
You need to log in to create posts and topics.

RuntimeError: File does not exist:

Dear OVITO developers,

I am trying to run the script (shown below) in GUI model to do the coordination analysis. However, I got the error:  The Python script has exited with an error.
Traceback (most recent call last):
File "<string>", line 5, in <module>
File "/usr/bin/../lib/ovito/plugins/python/ovito/io/__init__.py", line 97, in import_file
importer = FileImporter.autodetect_format(ovito.dataset, location)
RuntimeError: File does not exist:
dump.load_0

I would like to know which folder I should put my file in so that OVITO can find it.  Thanks in advance.

Best regards,

Kevin

from ovito.io import import_file
from ovito.modifiers import CoordinationNumberModifier

# Load a particle dataset, apply the modifier, and evaluate pipeline.
pipeline = import_file("dump.load_0")
modifier = CoordinationAnalysisModifier(cutoff = 5.0, number_of_bins = 200)
pipeline.modifiers.append(modifier)
data = pipeline.compute()

# Print the computed g(r) function values.
print(data.tables['coordination-rdf'].xy())

 

Dear Kevin,

you can specify the absolute path to your input file in the import file function if you are unsure about where your current working directory is. Also, in case you are not aware of this: In Python, you can get and set the current working directory with os.getcwd() and os.chdir().

I'm wondering though if this error has a different cause. You said "I am trying to run the script (shown below) in GUI model". Do you mean you are trying to run this script as a python script modifier function from within the GUI? The latter is not possible.

Just to clarify: The script you posted above is a stand-alone batch script which is supposed to be executed from the terminal. As a modifier function for the GUI, it would simply look like this, e.g.

from ovito.modifiers import CoordinationAnalysisModifier
from ovito.data import *

def modify(frame, data):
    data.apply(CoordinationAnalysisModifier(cutoff = 5.0, number_of_bins = 200))
    # Print the computed g(r) function values.
    print(data.tables['coordination-rdf'].xy())

More information on the different usage scenarios of the python scripting interface can be found here: https://www.ovito.org/docs/current/python/introduction/running.php

-Constanze

Dear Constanze,

Thanks for your such an detailed explanation. Following your guidance, I have fixed the problem! Thanks very much!

In addition,  I encountered an error (AttributeError: DataCollection does not have an attribute named 'tables'.) when I used the script (shown below) in OVITO 2.9.0.  Although the problem can be solved by using a more recent version of  OVITO 3.0.1, I would like to know how I can solve this problem in OVITO 2.9.0. Thanks in advance.

Yours sincerely,

Kevin

Script for 2.9.0

from ovito.io import import_file
from ovito.modifiers import CoordinationNumberModifier

# Load a particle dataset, apply the modifier, and evaluate pipeline.
pipeline = import_file("dump.test")
modifier = CoordinationNumberModifier (cutoff = 5.0, number_of_bins = 200)
pipeline.modifiers.append(modifier)
data = pipeline.compute()

# Print the computed g(r) function values.
print(data.tables['coordination-rdf'].xy())

Script for 3.0.1

from ovito.io import import_file
from ovito.modifiers import CoordinationAnalysisModifier
import ovito
print("Hello, this is OVITO %i.%i.%i" % ovito.version)
# Load a particle dataset, apply the modifier, and evaluate pipeline.
pipeline = import_file("dump.test")
modifier = CoordinationAnalysisModifier(cutoff = 5.0, number_of_bins = 200)
pipeline.modifiers.append(modifier)
data = pipeline.compute()

# Print the computed g(r) function values.
print(data.tables['coordination-rdf'].xy())

 

Kevin,

again, all version changes are listed here: https://www.ovito.org/docs/current/python/introduction/version_changes.php
Please understand that we cannot use our limited resources and time to give you free support for OVITO 2.9.

I can only strongly recommend you to update your OVITO version and also becoming a licensee of OVITO Pro if you find the software and our support useful for your work.

All the best,

Constanze

Got it. Thank you!