Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - eason1021

Pages: [1]
1
Support Forum / The mutable problem in Function
« on: January 30, 2019, 11:46:01 AM »
Hello everyone, when I write a script to calculate the property. Sometimes I need to set the pbc.
In the latest version, I set the pbc condition like this:
Code: [Select]
cell_ref = node_ref.compute().cell_
with cell_ref:
    cell_ref.pbc=(True,True,False)
This method is a success, however, when I use the same method in def, it has an error message.
Code: [Select]
def compute_myproperty(frame, input, output):
    data = input
    data.cell_.pbc = (True, True, False)
the message said that I need to add '_' notation.
But I have been added it... how to solve this problem?

2
Hello everyone,
I tried to use this NearestNeighborFinder to find neighboring atoms and form unit cells.
I set periodic boundary conditions, the program also has the correct atomic identifier.
But when I tried to calculate the distance between adjacent atoms and adjacent atoms, I found that the coordinates of the atoms would still use the original coordinates, and would not be updated to the coordinates of the periodic boundary. Is there any way to obtain the coordinates of the periodic boundary?
Code: [Select]
cell = node.compute().cell_
with cell:
    cell.pbc=(True,True,False)

data = node.compute()

#Found REF nearest 6 atoms around the center atom
N= 6
finder = NearestNeighborFinder(N, data)
ptypes = data.particles['Particle Type']
positions = data.particles['Position']

# Loop over all input particles:
for index in range(data.particles.count):

    neighbors = [ (neigh.index, neigh.delta) for neigh in finder.find(index) ]




3
Support Forum / How to coloring particles by its properties
« on: July 27, 2018, 02:57:42 PM »
Hello everyone.
I use the python script to define the particle's new properties.
Now I want to coloring the atom with its properties.
For example:atom 1 is type A,then coloring the blue,atom 2 is type B,then coloring the orange...and I can choose the color by myself.
Has any modifiers can do this function? I read the vis modifiers,but I don't see the similar function to coloring by atom.

4
Support Forum / Order of neighbors from NearestNeighborFinder
« on: July 09, 2018, 07:02:26 PM »
And I still want to ask a question.
Now I stored 6 nearest neighbors around the central atom.
The neigh index in NearestNeighborFinder is sorted list of nearest neighbors.
But I want to sort these 6 atoms is array by +x +y +z -x -y -z direction to central atom.
Has any function to re-array the neigh index list?

5
When I update my ovito to the latest version.
My older script can't work
It will said:AttributeError: type object 'BondsView' has no attribute 'Enumerator'

Below is my code:

Code: [Select]
from ovito.io import *
from ovito.modifiers import *
from ovito.data import Bonds

# Import standard Python and NumPy modules.
import sys
import numpy

# Load the simulation dataset to be analyzed.
node = import_file("input.dump")

#create a output file
file = open('output_file.txt' , 'w')

# Create bonds.
node.modifiers.append(CreateBondsModifier(cutoff = 3.5))

# Compute CNA indices on the basis of the created bonds.
node.modifiers.append(
        CommonNeighborAnalysisModifier(mode = CommonNeighborAnalysisModifier.Mode.BondBased))
                     
# Let OVITO's data pipeline do the heavy work.
node.compute()

# A two-dimensional array containing the three CNA indices
# computed for each bond in the system.
cna_indices = node.output.bond_properties['CNA Indices'].array

# This helper function takes a two-dimensional array and computes the frequency
# histogram of the data rows using some NumPy magic.
# It returns two arrays (of same length):
#    1. The list of unique data rows from the input array
#    2. The number of occurences of each unique row
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)
    return (a[indices], counts)

# Used below for enumerating the bonds of each particle:
bond_enumerator = Bonds.Enumerator(node.output.bonds)

# Loop over atoms.
bonds_array = node.output.bonds.array
# Loop over particles and print their CNA indices.
for particle_index in range(node.output.number_of_particles):
   
    # Print particle index (1-based).
    sys.stdout.write("%i " % (particle_index+1))
    # Create local list with CNA indices of the bonds of the current particle.
    bond_index_list = list(bond_enumerator.bonds_of_particle(particle_index))
    local_cna_indices = cna_indices[bond_index_list]

    # Count how often each type of CNA triplet occurred.
    unique_triplets, triplet_counts = row_histogram(local_cna_indices)
   
    # Print list of triplets with their respective counts.
    for triplet, count in zip(unique_triplets, triplet_counts):
        sys.stdout.write("%s:%i " % (triplet, count))
        file.write("\n%i %s:%i " % (particle_index+1, triplet, count))

# Loop over half-bonds of current atom.
    for bond_index in bond_enumerator.bonds_of_particle(particle_index):
        atomA = bonds_array[bond_index][0]
        atomB = bonds_array[bond_index][1]
        assert(atomA == particle_index)
        print("\nAtom %i has a bond to atom %i" % (atomA, atomB))
        file.write("\nAtom %i has a bond to atom %i" % (atomA, atomB))

    # End of particle line
sys.stdout.write("\n")
file.close()

6
Support Forum / How to export custom variables by python scripts?
« on: January 23, 2018, 05:26:42 AM »
I want to export the atomA & atomB as a imd(or txt)

the code is below


# Import OVITO modules.
from ovito.io import *
from ovito.modifiers import *
from ovito.data import *
from ovito.data import Bonds
from ovito.modifiers import PythonScriptModifier

# Import standard Python and NumPy modules.
import sys
import numpy

# Load the simulation dataset to be analyzed.
node = import_file('/Users/eason851021/Documents/1635/dump.tensile_200.dump')
# Create bonds.
node.modifiers.append(CreateBondsModifier(cutoff = 3.5))

# Compute CNA indices on the basis of the created bonds.
node.modifiers.append(
        CommonNeighborAnalysisModifier(mode = CommonNeighborAnalysisModifier.Mode.BondBased))
                     
# Let OVITO's data pipeline do the heavy work.
node.compute()

# A two-dimensional array containing the three CNA indices
# computed for each bond in the system.
cna_indices = node.output.bond_properties['CNA Indices'].array

# This helper function takes a two-dimensional array and computes the frequency
# histogram of the data rows using some NumPy magic.
# It returns two arrays (of same length):
#    1. The list of unique data rows from the input array
#    2. The number of occurences of each unique row
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)
    return (a[indices], counts)

# Used below for enumerating the bonds of each particle:
bond_enumerator = Bonds.Enumerator(node.output.bonds)

# Loop over atoms.
bonds_array = node.output.bonds.array
# Loop over particles and print their CNA indices.
for particle_index in range(node.output.number_of_particles):
   
    # Print particle index (1-based).
    sys.stdout.write("%i " % (particle_index+1))
   
    # Create local list with CNA indices of the bonds of the current particle.
    bond_index_list = list(bond_enumerator.bonds_of_particle(particle_index))
    local_cna_indices = cna_indices[bond_index_list]

    # Count how often each type of CNA triplet occurred.
    unique_triplets, triplet_counts = row_histogram(local_cna_indices)
   
    # Print list of triplets with their respective counts.
    for triplet, count in zip(unique_triplets, triplet_counts):
        sys.stdout.write("%s:%i " % (triplet, count))
   # Loop over half-bonds of current atom.
    for bond_index in bond_enumerator.bonds_of_particle(particle_index):
        atomA = bonds_array[bond_index][0]
        atomB = bonds_array[bond_index][1]
        assert(atomA == particle_index)
        print("\nAtom %i has a bond to atom %i" % (atomA, atomB))
   
    export_file(node, "/Users/eason851021/Documents/1635/output.imd",
   format = "imd",
   columns = ["Particle Identifier", "Particle Type", "%i"%(atomA), "%i" % (atomB)])
   
   # End of particle line
    sys.stdout.write("\n")



But it display an error ´╝ÜRuntimeError: The set of output data columns is invalid (column 3). The property '0' does not exist.

Pages: [1]