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

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

Dear OVITO developers,

When I was trying to run a python script (as attached) to do the bcc-defects analysis, an error occurred:  Invalid Python script. It does not define the function modify().  Could you please tell me how I can fix this problem? Thanks in advance!

 

Best regards,

Kevin

Uploaded files:

Hi,

the error message suggests that you were trying to use this script as a python script modifier in the GUI.

Note that this is a stand-alone python batch script which has to be executed from the terminal. Doing a quick google search, I have found that the author of the script has published some examples showing how this script is to be used. That should answer your question:
https://github.com/jomoeller/bda/tree/master/example

Quote from Constanze Kalcher on December 18, 2020, 5:53 pm

Hi,

the error message suggests that you were trying to use this script as a python script modifier in the GUI.

Note that this is a stand-alone python batch script which has to be executed from the terminal. Doing a quick google search, I have found that the author of the script has published some examples showing how this script is to be used. That should answer your question:
https://github.com/jomoeller/bda/tree/master/example

Dear Constanze,

Thanks for your help. I have followed the instructions given on the website. However, after I executed the command from the terminal: ovitos /path/to/bda/ovitos_bcc-defect-analysis.py -c example.chkpt -b 0 0 0 -p Men-II , I got the error:  Traceback (most recent call last):
File "ovitos_bcc-defect-analysis.py", line 818, in <module>
main()
File "ovitos_bcc-defect-analysis.py", line 515, in main
ovito_bin = ovito.__file__.split('lib',1)[0] + 'bin/ovito'
NameError: name 'ovito' is not defined

I used the "ovitos" instead of "/path/to/ovito/bin/ovitos" as shown in the example to avoid the error /path/to/ovito/bin/ovitos: No such file or directory.

Could you please tell me how I can run this python script successfully from the terminal?  Thanks in advanve!

Best regards,

Kevin

Dear Kevin,

did you properly substitute "/path/to/ovito/bin/ovitos" with the abolute path to your own OVITO Pro installation?
In case you have any further questions, don't hesitate to contact the author of the script directly on github.

Best,

Constanze

Dear Constanze,

Thanks for your reply. The path is right.  I will contact the author for help.

Best regards,

Kevin

That's a good idea, Kevin. When you start the ovitos interpreter from the terminal in the interactive mode and just enter the line that causes you problems, what do you see?

print(ovito.__file__)

Usually, the explanation for the NameError you posted above is that you didn't import the respective python module.

Dear Constanze,

Thanks for your advice and sorry for my late response. The author replied me recently. He said he used an old version of Ovito 2.6.1 at that time. But I cannot find that version.

You said that the error is caused by the fact that I did not import the respective python module. Could you please tell me how I can do that in the terminal or do I need to add some commands into the python script?

In addition, what should I do with this command (print(ovito.__file__)) you mentioned above?  Thanks in advance.

Best regards,

Kevin

 

Quote from Constanze Kalcher on December 22, 2020, 3:05 pm

That's a good idea, Kevin. When you start the ovitos interpreter from the terminal in the interactive mode and just enter the line that causes you problems, what do you see?

print(ovito.__file__)
print(ovito.__file__)
print(ovito.__file__)

Usually, the explanation for the NameError you posted above is that you didn't import the respective python module.

Dear Constanze,

I have fixed this problem by adding this command (import ovito) at the beginning of that python script. However, a new problem occurs. i.e., Traceback (most recent call last):
File "./ovitos_bcc-defect-analysis.py", line 796, in <module>
main()
File "./ovitos_bcc-defect-analysis.py", line 558, in main
cna=CommonNeighborAnalysisModifier(adaptive_mode = True)
AttributeError: Object type CommonNeighborAnalysisModifier does not have an attribute named 'adaptive_mode'.

Could you please tell me how I can fix this problem? Thanks in advance.

Best regards,

Kevin

Hi Kevin,

are you using the scripting interface ovitos, or did you install the module ovito in your own python interpreter? In the latter case you'll of course first need to import the ovito module to be able to use it.

The new error you're reporting stems from the fact that the script needs to be ported to OVITO 3 syntax, see https://ovito.org/docs/current/python/introduction/version_changes.php

We will try to look into the issue in the coming days and will let you know, maybe we can help if you haven't already succeeded by then.

Best,

Constanze

Dear Constanze,

I really appreciate your help! The problem has been solved by run the python script in the terminal using OVITO 3.0.1. But, a new error came, as shown below: File "ovitos_bcc-defect-analysis.py", line 537, in main
box = asarray(node.source.cell.matrix)
AttributeError: 'ovito.plugins.PyScript.FileSource' object has no attribute 'cell'.

I have gone through the website you gave me and I found these sentences: The SimulationCell class now behaves like a Numpy matrix array of shape (3,4), providing direct access to the cell vectors and the cell origin. The old array and marray accessor attributes have been deprecated.

I think this may have something to do with my problem. As a Python and OVITO beginner, I  am not able to figure out what I should do. Could you please tell me what I should do?  Thanks in advance!

Best regards,

Kevin