24小时热门版块排行榜    

Znn3bq.jpeg
汕头大学海洋科学接受调剂
查看: 5223  |  回复: 12

gtssongchi

木虫 (小有名气)

[求助] ovito中打开python脚本错误 已有3人参与

大家好,用ovito计算voronoi多面体时,按照手册采用的python脚本计算。手册上脚本如下
# Import OVITO modules.
from ovito.io import *
from ovito.modifiers import *

# Import NumPy module.
import numpy

# Load a simulation snapshot of a Cu-Zr metallic glass.
node = import_file("../data/CuZr_metallic_glass.dump.gz"

# Set atomic radii (required for polydisperse Voronoi tessellation).
atypes = node.source.particle_properties.particle_type.type_list
atypes[0].radius = 1.35        # Cu atomic radius (atom type 1 in input file)
atypes[1].radius = 1.55        # Zr atomic radius (atom type 2 in input file)

# Set up the Voronoi analysis modifier.
voro = VoronoiAnalysisModifier(
    compute_indices = True,
    use_radii = True,
    edge_count = 6, # Length after which Voronoi index vectors are truncated
    edge_threshold = 0.1
)
node.modifiers.append(voro)
                     
# Let OVITO compute the results.
node.compute()

# Make sure we did not lose information due to truncated Voronoi index vectors.
if voro.max_face_order > voro.edge_count:
    print("Warning: Maximum face order in Voronoi tessellation is {0}, "
          "but computed Voronoi indices are truncated after {1} entries. "
          "You should consider increasing the 'edge_count' parameter to {0}."
          .format(voro.max_face_order, voro.edge_count))
    # Note that it would be possible to automatically increase the 'edge_count'
    # parameter to 'max_face_order' here and recompute the Voronoi tessellation:
    #   voro.edge_count = voro.max_face_order
    #   node.compute()

# Access computed Voronoi indices as NumPy array.
# This is an (N)x(edge_count) array.
voro_indices = node.output.particle_properties['Voronoi Index'].array

# This helper function takes a two-dimensional array and computes a frequency
# histogram of the data rows using some NumPy magic.
# It returns two arrays (of equal length):
#    1. The list of unique data rows from the input array
#    2. The number of occurences of each unique row
# Both arrays are sorted in descending order such that the most frequent rows
# are listed first.
def row_histogram(a):
    ca = numpy.ascontiguousarray(a).view([('', a.dtype)] * a.shape[1])
    unique, indices, inverse = numpy.unique(ca, return_index=True, return_inverse=True)
    counts = numpy.bincount(inverse)
    sort_indices = numpy.argsort(counts)[::-1]
    return (a[indices[sort_indices]], counts[sort_indices])

# Compute frequency histogram.
unique_indices, counts = row_histogram(voro_indices)

# Print the ten most frequent histogram entries.
for i in range(10):
    print("%s\t%i\t(%.1f %%)" % (tuple(unique_indices),
                                 counts,
                                 100.0*float(counts)/len(voro_indices)))

我只是将其中的文件路径改变了。在运行时却提示如下错误:
Traceback (most recent call last):
  File "/home/csong/ovito.py", line 2, in <module>
    from ovito.io import *
ImportError: No module named 'ovito.io'; 'ovito' is not a package
ERROR: Failed to initialize Python interpreter.

请问这是什么原因呢?
回复此楼

» 猜你喜欢

已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
回帖支持 ( 显示支持度最高的前 50 名 )

969354217

新虫 (初入文坛)

引用回帖:
5楼: Originally posted by cuso4852cuoh at 2019-04-17 19:57:33
请问楼主怎么弄的,我也在搞这个,一直出错
Traceback (most recent call last):
  File &quot;F:\py\vo.py&quot;, line 62, in &lt;module&gt;
    print(&quot;%s\t%i\t(%.1f %%)&quo ...

你找到解决方法了吗?
6楼2019-05-10 10:13:19
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
普通回帖

abinitio

版主 (著名写手)

【答案】应助回帖

感谢参与,应助指数 +1
ovito 是那个版本?我感觉3.0.0 -dev的pythonscript好象有问题
2楼2017-11-15 15:58:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

gtssongchi

木虫 (小有名气)

引用回帖:
2楼: Originally posted by abinitio at 2017-11-15 15:58:03
ovito 是那个版本?我感觉3.0.0 -dev的pythonscript好象有问题

老师您好,ovito是2.9.0的版本
3楼2017-11-15 19:16:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

伊有涯

新虫 (小有名气)

【答案】应助回帖

ovito怎么用python进行计算啊?怎么弄的啊?
喜欢天空,百看不厌。当然不看也可以。
4楼2018-07-05 19:37:49
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cuso4852cuoh

新虫 (小有名气)

【答案】应助回帖

请问楼主怎么弄的,我也在搞这个,一直出错
Traceback (most recent call last):
  File "F:\py\vo.py", line 62, in <module>
    print("%s\t%i\t(%.1f %%)" % (tuple(unique_indices),
IndexError: index 1 is out of bounds for axis 0 with size 1
,我弄到ovito里,一直报这个错
5楼2019-04-17 19:57:33
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

刘子不晕车

禁虫 (初入文坛)

本帖内容被屏蔽

7楼2019-12-30 00:23:50
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

pl947

禁虫 (小有名气)

本帖内容被屏蔽

8楼2019-12-31 11:15:26
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

pl996

禁虫 (小有名气)

本帖内容被屏蔽

9楼2020-01-02 14:17:08
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

pl927

禁虫 (小有名气)

本帖内容被屏蔽

10楼2020-01-03 15:54:03
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 gtssongchi 的主题更新
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 085404 22408 309分求调剂 +8 lzmk 2026-04-14 9/450 2026-04-15 13:23 by 黑科技矿业
[考研] 求调剂推荐 +5 小聂爱学习 2026-04-14 5/250 2026-04-15 09:01 by blunt110
[考研] 071000生物学调剂求助 +18 zzzzwww 2026-04-09 21/1050 2026-04-14 15:39 by zs92450
[考研] 279求调剂 +12 张番茄不炒蛋 2026-04-11 12/600 2026-04-14 15:38 by zs92450
[考研] 考研英一数一338分 +9 长江大学东校区 2026-04-13 10/500 2026-04-14 00:41 by 王珺璞
[考研] 一志愿华工085600 331分 +7 天下ww 2026-04-09 7/350 2026-04-13 09:01 by lhj2009
[考研] 电气专硕320求调剂 +6 小麻子111 2026-04-10 6/300 2026-04-12 10:54 by lemon6009
[考研] 299求调剂 +8 ZVVZ13 2026-04-08 8/400 2026-04-12 00:40 by 蓝云思雨
[考研] 药学专硕调剂 +8 ? 一路生?花? 2026-04-10 10/500 2026-04-11 21:21 by zhouxiaoyu
[考研] 296求调剂 +14 汪!?! 2026-04-08 15/750 2026-04-11 20:28 by dongdian1
[考研] 085501机械专硕 302分 不挑专业求调剂 +7 汪某. 2026-04-09 7/350 2026-04-11 14:37 by luhong1990
[考研] 342电子信息专硕求调剂 +9 你让我怎么荔枝 2026-04-10 10/500 2026-04-11 08:33 by zhq0425
[考研] 材料与化工调剂 +12 否极泰来2026 2026-04-10 13/650 2026-04-11 00:28 by wangjihu
[考研] 计算机类求调剂,22408-274分 +7 上岸de小虫 2026-04-09 8/400 2026-04-10 19:56 by fxue1114
[考研] 22408 366分,本科211,一志愿西工大 +4 Rubt 2026-04-09 4/200 2026-04-10 19:51 by chemisry
[考研] 一志愿华东师范生物学326分,求调剂 +8 刘墨墨 2026-04-09 8/400 2026-04-10 12:00 by pengliang8036
[考研] 314求调剂 +14 weltZeng 2026-04-09 14/700 2026-04-09 23:14 by wolf97
[考研] 复试调剂,一志愿郑州大学材料与化工289分 +31 硕星赴 2026-04-08 31/1550 2026-04-09 16:54 by Delta2012
[考研] 0860004 求调剂 309分 +6 Yin DY 2026-04-09 6/300 2026-04-09 10:19 by 啊李999
[考研] 334求调剂 +16 Riot2025 2026-04-08 17/850 2026-04-09 09:28 by wdyheheeh
信息提示
请填处理意见