1.能不能用ovito处理AIMD的XDATCAR文件?
2.如果可以为什么我用官网提供的Python脚本只能得出第一个离子步的数据?
3.有没有大佬可以帮忙改进一下Python脚本?
# Import OVITO modules.
from ovito.io import *
from ovito.modifiers import *
from ovito.pipeline import *
# Import NumPy module.
import numpy
# Load a simulation snapshot of a Cu-Zr metallic glass.
pipeline = import_file("D:/ovito/400/XDATCAR",multiple_frames = True)
# Set atomic radii (required for polydisperse Voronoi tessellation).
atom_types = pipeline.source.data.particles['Particle Type'].types
atom_types[0].radius = 1.28 # atomic radius (atom type 1 in input file)
atom_types[1].radius = 1.55 # atomic radius (atom type 2 in input file)
# Set up the Voronoi analysis modifier.
voro = VoronoiAnalysisModifier(
compute_indices = True,
use_radii = True,
edge_threshold = 0.1
)
pipeline.modifiers.append(voro)
# Let OVITO compute the results.
data = pipeline.compute()
# Access computed Voronoi indices.
# This is an (N) x (M) array, where M is the maximum face order.
voro_indices = data.particles['Voronoi Index']
# 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)))
result:
(0, 0, 0, 2, 8, 4, 0, 0) 11 (5.5 %)
(0, 0, 0, 3, 6, 4, 0, 0) 7 (3.5 %)
(0, 0, 0, 0, 12, 0, 0, 0) 6 (3.0 %)
(0, 0, 0, 1, 10, 3, 0, 0) 5 (2.5 %)
(0, 0, 0, 2, 8, 1, 0, 0) 5 (2.5 %)
(0, 0, 0, 4, 6, 4, 0, 0) 5 (2.5 %)
(0, 0, 0, 2, 8, 5, 0, 0) 5 (2.5 %)
(0, 0, 0, 1, 10, 2, 0, 0) 5 (2.5 %)
(0, 0, 0, 2, 8, 0, 0, 0) 4 (2.0 %)
(0, 0, 0, 4, 4, 6, 0, 0) 3 (1.5 %) |