-
Notifications
You must be signed in to change notification settings - Fork 25
Using Atomistica's neighbor list from Python
Lars Pastewka edited this page Oct 2, 2015
·
6 revisions
Note: There is an equivalent standalone implementation of this neighbor list available in matscipy that is easier to use than Atomistica's.
The following example shows how to use the neighbor list in Python.
import atomistica.native as native
# Load you atoms object
a = ...
# You need an ATOMISTICA particles object to do this
p = native.from_atoms(a)
# Instantiate an ATOMISTICA neighbor list object, *avgn* is the
# average number of neighbors per atom.
nl = native.Neighbors(avgn)
# Ask the neighbor list to compute neighbors at least up to
# cutoff *cutoff*. Neighbor list may contain farther atoms.
nl.request_interaction_range(cutoff)
# Construct neighbor list and return neighbors. Returned are a
# list of integers *i_list* and *j_list* that denote the neighbor
# pair. List *r_list* contains the distance.
# The atomic position come from calc.particles, which is an ATOMISTICA
# *Particles* object. The positions are assigned when the calculator
# is bound to the Atoms object using a.set_calculator(calc) above,
# or upon calls to get_potential_energy(). I admit that this is
# somewhat intransparent.
i_list, j_list, r_list = nl.get_neighbors(p)
# Example 1: Loop over all pairs
for i, j, r in zip(i_list, j_list, r_list):
print i, j, r
# Do something else
# Example 2: Compute pair distribution function up to *cutoff* with
# number of bins *nbins*
hist, bin_edges = np.histogram(r_list, bins=nbins, range=[0.0, cutoff])