24小时热门版块排行榜    

Znn3bq.jpeg
汕头大学海洋科学接受调剂
查看: 5215  |  回复: 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的回帖

伊有涯

新虫 (小有名气)

【答案】应助回帖

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

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的回帖

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的回帖
最具人气热帖推荐 [查看全部] 作者 回/看 最后发表
[考研] 08工学 309分求调剂 +7 Yin DY 2026-04-08 7/350 2026-04-13 22:50 by pies112
[考研] 复试调剂 +17 积极向上; 2026-04-10 19/950 2026-04-13 19:53 by 闲人终南山
[考研] 生物学调剂 +11 小冉要努力 2026-04-10 13/650 2026-04-13 11:46 by 电化学及催化
[考研] +10 李多米lee. 2026-04-12 11/550 2026-04-12 22:58 by yuyin1233
[考研] 0860004 求调剂 309分 +9 Yin DY 2026-04-08 9/450 2026-04-11 22:55 by dongdian1
[考研] 070300化学279求调剂 +19 哈哈哈^_^ 2026-04-08 20/1000 2026-04-11 20:43 by stoner78
[考研] 电子信息279求调剂,有书读就行 +8 wwwooden 2026-04-08 11/550 2026-04-11 20:22 by cq2548
[考研] 农学0904 312求调剂 +3 Say Never 2026-04-11 3/150 2026-04-11 17:22 by daydayup2005
[考研] 农学0904 312求调剂 +6 Say Never 2026-04-10 6/300 2026-04-11 10:33 by wwj2530616
[考研] 283求调剂,工科! +12 苏打水7777 2026-04-08 12/600 2026-04-11 10:28 by 逆水乘风
[考研] 346,工科求调剂 +3 moser233 2026-04-09 3/150 2026-04-11 10:04 by zhq0425
[考研] 0854调剂 +4 长弓傲 2026-04-09 4/200 2026-04-11 09:18 by 猪会飞
[考研] 本科211 工科085400 280分求调剂 可跨专业 +11 LZH(等待调剂中 2026-04-10 11/550 2026-04-11 08:39 by zhq0425
[考研] 263能源动力专硕求调剂 +4 加大号饭盒袋 2026-04-10 4/200 2026-04-10 20:52 by gong120082
[考研] 314求调剂 +18 xhhdjdjsjks 2026-04-09 19/950 2026-04-10 18:53 by HPUCZ
[考研] 求调剂 材料与工程 324分 专硕 +19 翩翩一书生 2026-04-10 21/1050 2026-04-10 11:41 by wp06
[考研] 337求调剂 +4 Gky09300550, 2026-04-09 4/200 2026-04-09 17:18 by 帕尔马拉特
[论文投稿] 求助文献原文 10+3 18500821399 2026-04-08 3/150 2026-04-09 16:56 by 北京莱茵润色
[考研] 招收有机化学、化工,药学,食品灯专业学生 +3 yrfhjgdj 2026-04-08 3/150 2026-04-09 10:15 by QYQX_123
[考研] 生物学328分求调剂 +9 闪电kkl 2026-04-08 10/500 2026-04-08 21:42 by liuhuiying09
信息提示
请填处理意见