8. networks

This module provides functions for handling data for networks of points and bonds. The functions allow the user to create a (periodic or finite) network of bonds from a set of points, for instance. Also includes functions for handling discrete data, creating lattices from xy, NL, KL, BL, etc. Below are some definitions used throughout the module:

8.1. Some Definitions

NL
: array of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
KL
: NP x max(#neighbors) int array
spring connection/constant list, where 1 corresponds to a true connection, 0 signifies that there is not a connection, -1 signifies periodic bond
BM
: array of length #pts x max(#neighbors)
The (i,j)th element is the bond length of the bond connecting the ith particle to its jth neighbor (the particle with index NL[i,j]).
BL
: array of dimension #bonds x 2
Each row is a bond and contains indices of connected points. Negative values denote particles connected through periodic bonds.
bL
: array of length #bonds
The ith element is the length of of the ith bond in BL
LL
: tuple of 2 floats
Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries. These give the dimensions of the network in x and y, for S(k) measurements and other periodic things.
BBox
: #vertices x 2 float array
bounding polygon for the network, usually a rectangle
eigval_out
: 2*N x 1 complex array
eigenvalues of the matrix, sorted by order of imaginary components
eigvect_out
: typically 2*N x 2*N complex array
eigenvectors of the matrix, sorted by order of imaginary components of eigvals Eigvect is stored as NModes x NP*2 array, with x and y components alternating, like: x0, y0, x1, y1, ... xNP, yNP.
polygons
: list of int lists
indices of xy points defining polygons.
NLNNN
: array of length #pts x max(#next-nearest-neighbors)
Next-nearest-neighbor array: The ith row contains indices for the next nearest neighbors for the ith point.
KLNNN
: array of length #pts x max(#next-nearest-neighbors)
Next-nearest-neighbor connectivity/orientation array: The ith row states whether a next nearest neighbors is counterclockwise (1) or clockwise(-1)
PVxydict
: dict
dictionary of periodic bonds (keys) to periodic vectors (values) If key = (i,j) and val = np.array([ 5.0,2.0]), then particle i sees particle j at xy[j]+val –> transforms into: ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i
PVx
: NP x NN float array (optional, for periodic lattices)
ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i
PVy
: NP x NN float array (optional, for periodic lattices)
ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i

8.2. Overview

delaunay_centroid_lattice_from_pts(xy[, ...]) Convert 2D pt set to lattice (xy, NL, KL, BL, BM) via traingulation.

8.3. Classes and Functions

ilpm.networks.distance_periodic(xy, com, LL)[source]

Compute the distance of xy points from com given periodic rectangular BCs with extents LL Parameters ———- xy : NP x 2 float array

Positions to evaluate distance in periodic rectangular domain
com
: 1 x 2 float array
position to compute distances with respect to
LL
: tuple of floats
spatial extent of each periodic dimension (ie x(LL[0]) = x(0), y(LL[1]) = y(0))
Returns:

dist : len(xy) x 1 float array

distance of xy from com given periodic boundaries in 2d

ilpm.networks.center_of_mass(xy, masses)[source]

Compute the center of mass for a 2D finite, non-PBC system.

Parameters:

xy : NP x 2 float array

The positions of the particles/masses/weighted objects

masses : NP x 1 float array

The weight to attribute to each particle.

Returns:

com : 2 x 1 float array

The position in simulation space of the periodic center of mass

ilpm.networks.com_periodic(xy, LL, masses=1.0)[source]

Compute the center of mass for a 2D periodic system. When a cluster straddles the periodic boundary, a naive calculation of the center of mass will be incorrect. A generalized method for calculating the center of mass for periodic systems is to treat each coordinate, x and y, as if it were on a circle instead of a line. The calculation takes every particle’s x coordinate and maps it to an angle, averages the angle, then maps back.

Parameters:

xy : NP x 2 float array

The positions of the particles/masses/weighted objects

LL :

masses : NP x 1 float array or float

The weight to attribute to each particle. If masses is a float, it is ignored (all particles weighted equally)

Returns:

com : 2 x 1 float array

The position in simulation space of the periodic center of mass

ilpm.networks.running_mean(x, N)[source]

Compute running mean of an array x, averaged over a window of N elements. If the array x is 2d, then a running mean is performed on each row of the array.

Parameters:

x : N x (1 or 2) array

The array to take a running average over

N : int

The window size of the running average

Returns:

output : 1d or 2d array

The averaged array (each row is averaged if 2d), preserving datatype of input array x

ilpm.networks.interpol_meshgrid(x, y, z, n, method='nearest')[source]

Interpolate z on irregular or unordered grid data (x,y) by supplying # points along each dimension. Note that this does not guarantee a square mesh, if ranges of x and y differ.

Parameters:

x : unstructured 1D array

data along first dimension

y : unstructured 1D array

data along second dimension

z : 1D array

values evaluated at x,y

n : int

number of spacings in meshgrid of unstructured xy data

method : {‘linear’, ‘nearest’, ‘cubic’}, optional

Method of interpolation. One of nearest

return the value at the data point closest to the point of interpolation. See NearestNDInterpolator for more details.

linear

tesselate the input point set to n-dimensional simplices, and interpolate linearly on each simplex. See LinearNDInterpolator for more details.

cubic (1-D)

return the value determined from a cubic spline.

cubic (2-D)

return the value determined from a piecewise cubic, continuously differentiable (C1), and approximately curvature-minimizing polynomial surface. See CloughTocher2DInterpolator for more details.

Returns:

X : n x 1 float array

meshgrid of first dimension

X : n x 1 float array

meshgrid of second dimension

Zm : n x 1 float array

(interpolated) values of z on XY meshgrid, with nans masked

ilpm.networks.dist_pts(pts, nbrs, dim=-1, square_norm=False)[source]

Compute the distance between all pairs of two sets of points, returning an array of distances, in an optimized way.

Parameters:

pts: N x 2 array (float or int)

points to measure distances from

nbrs: M x 2 array (float or int)

points to measure distances to

dim: int (default -1)

dimension along which to measure distance. Default is -1, which measures the Euclidean distance in 2D

square_norm: bool

Abstain from taking square root, so that if dim==-1, returns the square norm (distance squared).

Returns:

dist : N x M float array

i,jth element is distance between pts[i] and nbrs[j], along dimension specified (default is normed distance)

ilpm.networks.diff_matrix(AA, BB)[source]

Compute the difference between all pairs of two sets of values, returning an array of differences.

Parameters:

pts: N x 1 array (float or int)

points to measure distances from

nbrs: M x 1 array (float or int)

points to measure distances to

Returns:

Mdiff : N x M float array

i,jth element is difference between AA[i] and BB[j]

ilpm.networks.sort_arrays_by_first_array(arr2sort, arrayList2sort)[source]

Sort many arrays in the same way, based on sorting of first array

Parameters:

arr2sort : N x 1 array

Array to sort

arrayList2sort : List of N x 1 arrays

Other arrays to sort, by the indexing of arr2sort

Returns:

arr_s, arrList_s : sorted N x 1 arrays

ilpm.networks.count_NN(KL)[source]

Count how many nearest neighbors each particle has.

Parameters:

KL : NP x max(#neighbors) array

Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.

Returns:

zvals : NP x 1 int array

The ith element gives the number of neighbors for the ith particle

ilpm.networks.NL2NLdict(NL, KL)[source]

Convert NL into a dictionary which gives neighbors (values) of the particle index (key).

Parameters:

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

KL : NP x max(#neighbors) array

Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.

Returns:

NLdict : dict

NLdict[i] returns an array listing neighbors of the ith particle, where i is an integer.

ilpm.networks.Tri2BL(TRI)[source]

Convert triangulation array (#tris x 3) to bond list (#bonds x 2) for 2D lattice of triangulated points.

Parameters:

TRI : array of dimension #tris x 3

Each row contains indices of the 3 points lying at the vertices of the tri.

Returns:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

ilpm.networks.BL2TRI(BL, xy)[source]

Convert bond list (#bonds x 2) to Triangulation array (#tris x 3) (using dictionaries for speedup and scaling)

Parameters:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

Returns:

TRI : array of dimension #tris x 3

Each row contains indices of the 3 points lying at the vertices of the tri.

ilpm.networks.where_points_in_triangle(pts, v1, v2, v3)[source]

Determine whether point pt is inside triangle with vertices v1,v2,v3, in 2D.

ilpm.networks.cross_pts_triangle(p1, p2, p3)[source]

Return the cross product for arrays of triangles or triads of points

ilpm.networks.memberIDs(a, b)[source]

Return array (c) of indices where elements of a are members of b. If ith a elem is member of b, ith elem of c is index of b where a[i] = b[index]. If ith a elem is not a member of b, ith element of c is ‘None’. The speed is O(len(a)+len(b)), so it’s fast.

ilpm.networks.ismember(a, b)[source]

Return logical array (c) testing where elements of a are members of b. The speed is Order(len(a)+len(b)), so it’s fast.

ilpm.networks.unique_rows(a)[source]

Clean up an array such that all its rows are unique. Reference: http://stackoverflow.com/questions/7989722/finding-unique-points-in-numpy-array

Parameters:

a : N x M array of variable dtype

array from which to return only the unique rows

ilpm.networks.unique_rows_threshold(a, thres)[source]

Clean up an array such that all its rows are at least ‘thres’ different in value. Reference: http://stackoverflow.com/questions/8560440/removing-duplicate-columns-and-rows-from-a-numpy-2d-array

Parameters:

a : N x M array of variable dtype

array from which to return only the unique rows

thres : float

threshold for deleting a row that has slightly different values from another row

Returns:

a : N x M array of variable dtype

unique rows of input array

ilpm.networks.args_unique_rows_threshold(a, thres)[source]

Clean up an array such that all its rows are at least ‘thres’ different in value. Reference: http://stackoverflow.com/questions/8560440/removing-duplicate-columns-and-rows-from-a-numpy-2d-array

Parameters:

a : N x M array of variable dtype

array from which to return only the unique rows

thres : float

threshold for deleting a row that has slightly different values from another row

Returns:

a : N x M array of variable dtype

unique rows of input array

order : N x 1 int array

indices used to sort a in order

ui : N x 1 boolean array

True where row of a[order] is unique.

ilpm.networks.rows_matching(BL, indices)[source]

Find rows with elements matching elements of the supplied array named ‘indices’. Right now just set up for N x 2 int arrays. –> GENERALIZE Returns row indices of BL whose row elements are ALL contained in array named ‘indices’.

ilpm.networks.minimum_distance_between_pts(R)[source]
Parameters:

R : NP x ndim array

the points over which to find the min distance between points

Returns:

min_dist : float

the minimum distance between points

ilpm.networks.find_nearest(array, value)[source]

return the value in array that is nearest to the supplied value

ilpm.networks.NL2BL(NL, KL)[source]

Convert neighbor list and KL (NPxNN) to bond list (#bonds x 2) for lattice of bonded points.

Parameters:

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

KL : NP x max(#neighbors) array

Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.

Returns:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points. Values are negative for periodic BCs.

ilpm.networks.KL2kL(NL, KL, BL)[source]

Convert neighbor list to bond list (#bonds x 2) for lattice of bonded points.

Parameters:

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

KL : array of dimension #pts x (max number of neighbors)

Spring constant list, where nonzero corresponds to a true connection while 0 signifies that there is not a connection.

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

Returns:

kL : array of length #bonds

The ith element is the spring constant of the ith bond in BL, taken from KL

ilpm.networks.BL2KL(BL, NL)[source]

Convert the bond list (#bonds x 2) to connectivity list using NL for its structure.

Parameters:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

Returns:

KL : array of dimension #pts x (max number of neighbors)

Spring constant list, where 1 corresponds to a true connection while 0 signifies that there is not a connection.

ilpm.networks.BL2NLandKL(BL, NP='auto', NN='min')[source]

Convert bond list (#bonds x 2) to neighbor list (NL) and connectivity list (KL) for lattice of bonded points. Returns KL as ones where there is a bond and zero where there is not. (Even if you just want NL from BL, you have to compute KL anyway.) Note that this makes no attempt to preserve any previous version of NL, which in the philosophy of these simulations should remain constant during a simulation. If NL is known, use BL2KL instead, which creates KL according to the existing NL.

Parameters:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

NP : int

number of points (defines the length of NL and KL)

NN : int

maximum number of neighbors (defines the width of NL and KL)

Returns:

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

KL : array of dimension #pts x (max number of neighbors)

Spring constant list, where 1 corresponds to a true connection while 0 signifies that there is not a connection.

ilpm.networks.NL2BM(xy, NL, KL, PVx=None, PVy=None)[source]

Convert bond list (#bonds x 2) to bond matrix (#pts x #nn) for lattice of bonded points.

Parameters:

xy : array of dimension nxd

2D lattice of points (positions x,y(,z) )

NL : int array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

KL : array of dimension #pts x (max number of neighbors)

spring connection/constant list, where one corresponds to a true connection while 0 signifies that there is not a connection.

PVx : NP x NN float array (optional, for periodic lattices)

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

PVy : NP x NN float array (optional, for periodic lattices)

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i

Returns:

BM : array of length #pts x max(#neighbors)

The (i,j)th element is the bond length of the bond connecting the ith particle to its jth neighbor (the particle with index NL[i,j]).

ilpm.networks.BL2BM(xy, NL, BL)[source]

Convert bond list (#bonds x 2) to bond matrix (#pts x #nn) for lattice of bonded points.

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

Returns:

BM : array of length #pts x max(#neighbors)

The (i,j)th element is the bond length of the bond connecting the ith particle to its jth neighbor (the particle with index NL[i,j]).

ilpm.networks.BM2bL(NL, BM, BL)[source]

Convert bond list (#bonds x 2) to bond length list (#bonds x 1) for lattice of bonded points. Assumes that BM has correctly accounted for periodic BCs, if applicable.

Parameters:

NL : array of dimension #pts x max(#neighbors)

The ith row contains indices for the neighbors for the ith point.

BM : array of length #pts x max(#neighbors)

The (i,j)th element is the bond length of the bond connecting the ith particle to its jth neighbor (the particle with index NL[i,j]).

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

Returns:

bL : array of length #bonds

The ith element is the length of of the ith bond in BL.

ilpm.networks.BM2BSM(xy, NL, KL, BM0)[source]

Calc strain in each bond, reported in NP x NN array called BSM (‘bond strain matrix’)

ilpm.networks.bond_length_list(xy, BL, NL=None, KL=None, PVx=None, PVy=None)[source]

Convert bond list (#bonds x 2) to bond length list (#bonds x 1) for lattice of bonded points. (BL2bL)

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points.

Returns:

bL : array of dimension #bonds x 1

Bond lengths, in order of BL (lowercase ‘b’ denotes 1D array)

ilpm.networks.bond_strain_list(xy, BL, bo)[source]

Convert neighbor list to bond list (#bonds x 2) for lattice of bonded points. (makes bs)

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points.

bo : array of dimension #bonds x 1

Rest lengths of bonds, in order of BL, lowercase to denote 1D array.

Returns:

bs : array of dimension #bonds x 1

The strain of each bond, in order of BL

ilpm.networks.xyandTRI2centroid(xy, TRI)[source]

Convert xy and TRI to centroid xy array

ilpm.networks.TRI2centroidNLandKL(TRI)[source]

Convert triangular rep of lattice (such as triangulation) to neighbor array and connectivity array of the triangle centroids.

Parameters:

TRI : Ntris x 3 int array

Triangulation of a point set. Each row gives indices of vertices of single triangle.

Returns:

NL : NP x NN int array

Neighbor list

KL : NP x NN int array (optional, for speed)

Connectivity list, with -1 entries for periodic bonds

ilpm.networks.TRI2centroidNLandKLandBL(TRI)[source]

Convert triangular rep of lattice (such as triangulation) to neighbor array, connectivity array, and bond list of the triangle centroids.

Parameters:

TRI : Ntris x 3 int array

Triangulation of a point set. Each row gives indices of vertices of single triangle.

Returns:

NL : NP x NN int array

Neighbor list

KL : NP x NN int array (optional, for speed)

Connectivity list, with -1 entries for periodic bonds

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

ilpm.networks.TRI2centroidBL(TRI)[source]

Convert triangular rep of lattice (such as triangulation) to bond list of the triangle centroids

Parameters:

TRI : Ntris x 3 int array

Triangulation of a point set. Each row gives indices of vertices of single triangle.

Returns:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

ilpm.networks.TRI2NLandKL(TRI, remove_negatives=False)[source]

Convert triangulation index array (Ntris x 3) to Neighbor List (Nbonds x 2) array and Connectivity array.

Parameters:

TRI : Ntris x 3 int array

Triangulation of a point set. Each row gives indices of vertices of single triangle.

remove_negatives : bool

If any of the indices are -1 in TRI, remove those bonds; this is for triangular reps of the lattice that have non-triangular elements (ex dangling bonds)

Returns:

NL : NP x NN int array

Neighbor list

KL : NP x NN int array (optional, for speed)

Connectivity list, with -1 entries for periodic bonds

ilpm.networks.TRI2BL(TRI, remove_negatives=False)[source]

Convert triangulation index array (Ntris x 3) to Bond List (Nbonds x 2) array.

Parameters:

TRI : Ntris x 3 int array

Triangulation of a point set. Each row gives indices of vertices of single triangle.

remove_negatives : bool

If any of the indices are -1 in TRI, remove those bonds; this is for triangular reps of the lattice that have non-triangular elements (ex dangling bonds)

Returns:

BL : Nbonds x 2 int array

Bond list

ilpm.networks.PVxydict2PVxPVy(PVxydict, NL, check=False)[source]

Convert dictionary of periodic bonds (keys) to periodic vectors (values) denoting periodic ‘virtual’ displacement for bond (i,j) of particle j as viewed by i.

Parameters:

PVxydict : dict

dictionary of periodic bonds (keys) to periodic vectors (values)

NL : NP x NN int array

Neighbor list

check : bool

view intermediate results

Returns:

PVx : NP x NN float array

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

PVy : NP x NN float array

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i

ilpm.networks.flexible_PVxydict2PVxPVy(PVxydict, NL, check=False)[source]

Flexibly (defined later) convert dictionary of periodic bonds (keys) to periodic vectors (values) denoting periodic ‘virtual’ displacement for bond (i,j) of particle j as viewed by i. The flexibility is in that if there is no matching neighbor for a periodic bond, it is destroyed: ie if col = np.argwhere(NL[key[0]] == key[1])[0][0] returns IndexError, delete key from PVxydict and don’t add anything for that bond to PVx and PVy

Parameters:

PVxydict : dict

dictionary of periodic bonds (keys) to periodic vectors (values)

NL : NP x NN int array

Neighbor list

check : bool

view intermediate results

Returns:

PVx : NP x NN float array

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

PVy : NP x NN float array

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i

ilpm.networks.PVxy2PVxydict(PVx, PVy, NL, KL=None, eps=1e-07)[source]
Parameters:

PVx : NP x NN float array

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

PVy : NP x NN float array

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i

NL : NP x NN int array

Neighbor list

KL : NP x NN int array (optional, for speed, could be None)

Connectivity list, with -1 entries for periodic bonds

eps : float

Threshold norm value for periodic boundary vector to be recognized as such

Returns:

PVxydict : dict

dictionary of periodic bonds (keys) to periodic vectors (values)

ilpm.networks.BL2PVxydict(BL, xy, PV)[source]

Extract dictionary of periodic boundary condition vectors from bond list, particle positions

Parameters:

BL : #bonds x 2 int array

Bond list array, with negative-valued rows denoting periodic bonds

xy : NP x 2 float array

positions of the particles in 2D

NL : NP x #NN int array

Neighbor list – the i,jth element is the index (of xy) of the jth neighbor of the ith particle

polygon : Nsides x 2 float array

the bounding box of the sample (can be any polygonal shape with pairs of parellel sides)

PV : Nsides x 2 float array

The ith row of PV is the vector taking the ith side of the polygon (connecting polygon[i] to polygon[i+1 % len(polygon)]

Returns:

PVxydict : dict

dictionary of periodic bonds (keys) to periodic vectors (values) –> transforms into: ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

ilpm.networks.extract_boundary(xy, NL, KL, BL, check=False)[source]

Extract the boundary of a 2D network (xy,NL,KL). If periodic, discards this information.

Parameters:

xy : NP x 2 float array

point set in 2D

BL : #bonds x 2 int array

Bond list

NL : NP x NN int array

Neighbor list. The ith row contains the indices of xy that are the bonded pts to the ith pt. Nonexistent bonds are replaced by zero.

KL : NP x NN int array

Connectivity list. The jth column of the ith row ==1 if pt i is bonded to pt NL[i,j]. The jth column of the ith row ==0 if pt i is not bonded to point NL[i,j].

check: bool

Whether to show intermediate results

Returns:

boundary : #points on boundary x 1 int array

indices of points living on boundary of the network

ilpm.networks.pts_in_polygon(xy, polygon)[source]

Returns points in array xy that are located inside supplied polygon array.

ilpm.networks.inds_in_polygon(xy, polygon)[source]

Returns points in array xy that are located inside supplied polygon array.

ilpm.networks.extract_phase(eigvector, point_arr=[])[source]

Extract phase information from an eigenvector.

Parameters:

eigvector : 2 x NP complex array

First row is X component, second is Y.

point_arr : M x 1 int array or empty for all points

array of indices for which to order the output, in desired order. If empty, gets phase info for all elements/points.

Returns:

phase : NP x 1 float array

The phase of the array

ilpm.networks.delaunay_cut_unnatural_boundary(xy, NL, KL, BL, TRI, thres, check=False)[source]

Keep cutting skinny triangles on the boundary until no more skinny ones. Cuts boundary tris of a triangulation until all have reasonable height/base values.

Parameters:

xy : NP x 2 float array

The point set

NL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Neighbor list. The ith row has neighbors of the ith particle, padded with zeros

KL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Connectivity list. The ith row has ones where ith particle is connected to NL[i,j]

BL : Nbonds x 2 int array

Bond list for the lattice (can include bonds that aren’t triangulated)

TRI : Ntris x 3 int array

The triangulation of the lattice/mesh

thres : float

threshold value for base/height, below which to cut the boundary tri

check: bool

Display intermediate results

Returns:

NL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Neighbor list. The ith row has neighbors of the ith particle, padded with zeros

KL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Connectivity list. The ith row has ones where ith particle is connected to NL[i,j]

BL : Nbonds x 2 int array

Bond list for the lattice (can include bonds that aren’t triangulated)

TRI : (Ntris - Ncut) x 3 int array

The new, trimmed triangulation

ilpm.networks.delaunay_cut_unnatural_boundary_singlepass(xy, BL, TRI, boundary, thres=4.0, check=False)[source]

Algorithm: For each row of TRI containing at least one boundary pt, if contains 2 boundary pts, cut the base (edge) if base/height > threshold. If the tri has all three vertices on the boundary, keep it. Two boundary triangles may share an edge (bond), and removing both will leave a dangling point. To avoid this, check for edges shared between simplices. This allows bonds which are not part of the triangulation. Haven’t inspected for periodicity issues.

Parameters:

xy : NP x 2 float array

The point set

BL : Nbonds x 2 int array

Bond list for the lattice (can include bonds that aren’t triangulated)

TRI : Ntris x 3 int array

The triangulation of the lattice/mesh

boundary : # points on boundary x 1 int array

The indices of the points that live on the boundary

thres : float

threshold value for base/height, below which to cut the boundary tri

check: bool

Display intermediate results

Returns:

TRItrim : (Ntris - Ncut) x 3 int array

The new, trimmed triangulation

Ncut : int

The number of rows of TRI that have been cut (# boundary tris cut)

ilpm.networks.boundary_triangles(TRI, boundary)[source]

Identify triangles of triangulation that live on the boundary (ie share one edge with no other simplices)

ilpm.networks.extract_polygons_lattice(xy, BL, NL=[], KL=[], PVx=[], PVy=[], PVxydict={}, viewmethod=False, check=False)[source]

Extract polygons from a lattice of points. Note that dangling bonds are removed, but no points are removed. This allows correct indexing for PVxydict keys, if supplied.

Parameters:

xy : NP x 2 float array

points living on vertices of dual to triangulation

BL : Nbonds x 2 int array

Each row is a bond and contains indices of connected points

NL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Neighbor list. The ith row has neighbors of the ith particle, padded with zeros

KL : NP x NN int array (optional, speeds up calc if it is known there are no dangling bonds)

Connectivity list. The ith row has ones where ith particle is connected to NL[i,j]

PVx : NP x NN float array (optional, for periodic lattices and speed)

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.

PVy : NP x NN float array (optional, for periodic lattices and speed)

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.

PVxydict : dict (optional, for periodic lattices)

dictionary of periodic bonds (keys) to periodic vectors (values)

viewmethod: bool

View the results of many intermediate steps

check: bool

Check the initial and final result

Returns:

polygons : list of lists of ints

list of lists of indices of each polygon

ilpm.networks.pairwise(iterable)[source]

Convert list into tuples with adjacent items tupled, like: s -> (s0,s1), (s1,s2), (s2, s3), ...

Parameters:

iterable : list or other iterable

the list to tuple

Returns:

out : list of tuples

adjacent items tupled

ilpm.networks.periodic_polygon_indices2xy(poly, xy, BLdbl, PVxydict)[source]

Convert a possibly-periodic polygon object that lists indices of vertices/points into an array of vertex coordinates. This is nontrivial only because of the existence of periodic boundary conditions. This function returns the polygon as it would appear to the zero-index particle (the first particle indexed in the variable ‘poly’.

Parameters:

poly : list of ints

The indices of xy, indexing the polygon in question. The first index may or may not be repeated as the last — it seems to work either way

xy : #pts x 2 float array

the coordinates of the vertices of all polygons in the network

BLdbl : #bonds x 2 signed int array

Bond list reapeated twice, with the second time being a copy of the first, but flipped (the convention of doubling BL is a matter of speedup). ie BLdbl = np.vstack((BL, np.fliplr(BL)))

PVxydict : dict

dictionary of periodic bonds (keys) to periodic vectors (values) If key = (i,j) and val = np.array([ 5.0,2.0]), then particle i sees particle j at xy[j]+val –> transforms into: ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i

Returns:

xypoly : list of coordinates (each a list of 2 floats)

The polygon as it appears to the first particle/vertex in the input list poly

periodicpoly : bool

Whether the polygon traverses a periodic boundary

ilpm.networks.polygons2PPC(xy, polygons, BL=None, PVxydict=None, check=False)[source]

Create list of polygon patches from polygons indexing xy. If the network is periodic, BL, PVx, PVy are required.

Parameters:

xy : NP x 2 float array

coordinates of particles

polygons: list of lists of ints

list of polygons, each of which are a closed list of indices of xy

check: bool

whether to plot the polygon patch collection

Returns:

PPC: list of patches

list for a PatchCollection object

ilpm.networks.is_cyclic_permutation(A, B)[source]

Check if list A is a cyclic permutation of list B.

Parameters:

A : list

B : list

Returns:

bool

Whether A is a cylic permutation of B

ilpm.networks.is_cyclic_permutation_numpy(A, B)[source]

Check if 1d numpy array A is a cyclic permutation of 1d numpy array B. HAVENT TESTED THIS BUT SHOULD WORK?

Parameters:

A : 1d numpy array

B : 1d numpy array

Returns:

bool

Whether A is a cylic permutation of B

ilpm.networks.contains_sublist(lst, sublst)[source]

Check if a list contains a sublist (same order)

Parameters:

lst, sublst : lists

The list and sublist to test

Returns:

bool

Whether sublst is a sublist of lst.

ilpm.networks.azimuthalAverage(image, center=None)[source]

Calculate the azimuthally averaged radial profile, by Jessica R. Lu.

Parameters:

image : N x M numpy array

The 2D image

center : 1 x 2 numpy float (or int) array

The [x,y] pixel coordinates used as the center. The default is

None, which then uses the center of the image (including fracitonal pixels).

Returns:

radial_prof : 1 x N numpy float array

The values of the image, ordered by radial distance

ilpm.networks.remove_pts(keep, xy, BL, NN='min', check=False)[source]

Remove particles not indexed by keep from xy, BL, then rebuild NL, and KL. Zeros out inds where they appear in NL and KL and reorders rows to put zeros last.

Parameters:

keep : NP_0 x 1 int array or bool array

indices (of xy, of particles) to keep

xy : NP_0 x 2 float array

points living on vertices of dual to triangulation

BL : Nbonds_0 x 2 int array or empty list

Each row is a bond and contains indices of connected points

NN : int or string ‘min’

Number of nearest neighbors in each row of KL, NL

Returns:

xy : NP x 2 float array

points living on vertices of dual to triangulation

NL : NP x NN int array

Neighbor list

KL : NP x NN int array

Connectivity list

BL : Nbonds x 2 int array

Each row is a bond and contains indices of connected points

ilpm.networks.compute_bulk_z(xy, NL, KL, BL)[source]

Compute the average coordination number of the bulk particles in a lattice/network.

Parameters:

xy : NP x dim array

positions of particles

NL : NL x NN array

neighbor list

KL : NL x NN array

connectivity list

Returns:

z : float

average coordination number of the bulk particles in the network

ilpm.networks.cut_bonds_z_random(xy, NL, KL, BL, target_z, min_coord=2, bulk_determination='Triangulation', check=False)[source]

Cut bonds in network so that average bulk coordination is z +/- 1 bond/system size. Note that ‘boundary’ is not a unique array if there are dangling bonds.

Parameters:

xy : NP x dim array

positions of particles

NL : NL x NN array

neighbor list

KL : NL x NN array

connectivity list

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

target_z : float

target average bulk coordination, to be approximately enforced by cutting bonds

bulk_determination : string (‘Triangulation’ ‘Cutter’ ‘Endpts’)

How to determine which bonds are in the bulk and which are on the boundary

Returns:

NLout : NL x NN int array

neighbor list

KLout : NL x NN int array

connectivity list

BLout : #bonds x 2 int array

Each row is a bond and contains indices of connected points

ilpm.networks.cut_bonds_z_highest(xy, NL, KL, BL, target_z, check=False)[source]

Cut bonds in network so that average bulk coordination is z +/- 1 bond/system size, using iterative procedure based on connectivity. Note that ‘boundary’ is not a unique array if there are dangling bonds. The boundary is not treated at all, since it is very hard to treat it correctly. Therefore, one MUST crop out the desired region after lattice creation.

Parameters:

xy : NP x dim array

positions of particles

NL : NL x NN array

neighbor list

KL : NL x NN array

connectivity list

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

target_z : float

target average bulk coordination, to be approximately enforced by cutting bonds

Returns:

NL : NL x NN int array

neighbor list

KL : NL x NN int array

connectivity list

BL : #bonds x 2 int array

Each row is a bond and contains indices of connected points

ilpm.networks.setdiff2d(A, B)[source]

Return row elements in A not in B. Used to be called remove_bonds_BL –> Remove bonds from bond list.

Parameters:

A : N1 x M array

Array to take rows of not in B (could be BL, for ex)

B : N2 x M

Array whose rows to compare to those of A

Returns:

BLout : (usually N1-N2) x M array

Rows in A that are not in B. If there are repeats in B, then length will differ from N1-N2.

ilpm.networks.intersect2d(A, B)[source]

Return row elements in A not in B. Used to be called remove_bonds_BL –> Remove bonds from bond list.

Parameters:

A : N1 x M array

Array to take rows of not in B (could be BL, for ex)

B : N2 x M

Array whose rows to compare to those of A

Returns:

BLout : (usually N1-N2) x M array

Rows in A that are not in B. If there are repeats in B, then length will differ from N1-N2.

ilpm.networks.cut_bonds_strain(xy, NL, KL, BM0, bstrain)[source]
Cut bonds from KL (set elems of KL to zero) based on the bond strains.
This is not finished since for now seems ok to convert to BL –> cut –> NL,KL
Parameters:

xy : NP x dim array

positions of particles

NL : NL x NN array

neighbor list

KL : NL x NN array

connectivity list

BM0 : NL x NN array

bond rest lengths

ilpm.networks.cut_bonds(BL, xy, thres)[source]

Cuts bonds with LENGTHS greater than cutoff value.

Parameters:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

xy : array of dimension nx2

2D lattice of points (positions x,y)

thres : float

cutoff length between points

Returns:

BLtrim : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points, contains no bonds longer than thres

ilpm.networks.cut_bonds_strain_BL(BL, xy, bL0, bstrain)[source]

Cuts bonds with STRAIN greater than cutoff value based on BL, and return trimmed BL.

Parameters:

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

xy : array of dimension nx2

2D lattice of points (positions x,y)

bstrain : float

breaking strain – bonds strained above this amount are cut

Returns:

BLtrim : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points, contains no bonds longer than thres

bL0trim : array of dimension #bonds x 1

unstrained bond length list: Each element is the length of the reference (unstrained) bond, in same order as rows of BL

ilpm.networks.tensor_polar2cartesian2D(Mrr, Mrt, Mtr, Mtt, x, y)[source]

converts a Polar tensor into a Cartesian one

Parameters:

Mrr, Mtt, Mrt, Mtr : N x 1 arrays

radial, azimuthal, and shear components of the tensor M

x : N x 1 array

the x positions of the points on which M is defined

y : N x 1 array

the y positions of the points on which M is defined

Returns:

Mxx,Mxy,Myx,Myy : N x 1 arrays

the cartesian components

ilpm.networks.tensor_cartesian2polar2D(Mxx, Myx, Mxy, Myy, x, y)[source]

converts a Cartesian tensor into a Polar one

Parameters:

Mxx,Mxy,Myx,Myy : N x 1 arrays

cartesian components of the tensor M

x : N x 1 array

the x positions of the points on which M is defined

y : N x 1 array

the y positions of the points on which M is defined

Returns:

Mrr, Mrt, Mtr, Mtt : N x 1 arrays

radial, shear, and azimuthal components of the tensor M

ilpm.networks.tensor_polar2cartesian_tractions(Mrr, Mtt, beta)[source]

Given a stress tensor with locally diagonal values Mrr, Mtt, pick out tractions along x and y directions, where x axis is oriented an angle beta from the radial.

Parameters:

Mrr,Mtt : N x 1 arrays

polar components of the tensor M

beta : float

angle of x axis wrt radial axis (phi =0)

Returns:

px : N x 1 float array

the traction in the x direction

py : N x 1 float array

the traction in the y direction

ilpm.networks.rotate_tensor_cartesian(Mxx, Mxy, Myy, beta)[source]

Rotate a symmetric tensor by an angle beta in the xy plane.

see http://www.creatis.insa-lyon.fr/~dsarrut/bib/Archive/others/phys/www.jwave.vt.edu/crcd/batra/lectures/esmmse5984/node38.html or elasticity.tex for more notes

Parameters:

Mxx,Mxy,Myy : N x 1 arrays

cartesian components of the tensor M in xy coord sys

beta : float

angle of x’ wrt x (counterclockwise rotation)

Returns:

Mxxprime, Mxyprime, Mxyprime : N x 1 float arrays

The stress in the rotated xy’ coordinates

ilpm.networks.rotate_vectors_2D(XY, theta)[source]

Given a list of vectors, rotate them actively counterclockwise in the xy plane by theta.

Parameters:

XY : NP x 2 array

Each row is a 2D x,y vector to rotate counterclockwise

theta : float

Rotation angle

Returns:

XYrot : NP x 2 array

Each row is the rotated row vector of XY

ilpm.networks.rotation_matrix_3D(axis, theta)[source]

Return the rotation matrix associated with counterclockwise rotation about the given axis by theta radians.

ilpm.networks.bonds_are_in_region(NL, KL, reg1, reg2)[source]

Discern if a bond is connecting particles in the same region (reg1), or else: connecting reg1 to reg2 or reg2 to reg2. Returns KL-like and kL-like objects with 1 for reg1-reg1 connections and 0 for else.

Parameters:

NL : NP x NN array

Each row corresponds to a lattice site. The entries give indices of the neighboring sites

KL : NP x NN array

Connectivity array. 1 for true connection, 0 for no connection, -1 for periodic connection

reg1 : (fraction)*NP x 1 array

Indices of the portion of the lattice in question

reg2 : (1-fraction)*NP x 1 array

Indices of the rest of the lattice

Returns:

KL_reg1 : NP x NN array

Region 1 connectivity array. Same as input KL, but with reg1-reg2 and reg2-reg2 connections zeroed out.

ilpm.networks.tune_springs_connecting_regions(NL, OmK, reg1, reg2, factor)[source]

Adjust (by a factor) the values of a connection matrix (like OmK or KL) that link sites on opposing regions of a lattice. This only works for two regions, but >2 regions can be built through iteration of this function. Note: reg1 MUST contain the zeroth particle.

Parameters:

NL : NP x NN array

Each row corresponds to a lattice site. The entries give indices of the neighboring sites

reg1 : (fraction)*NP x 1 array

Indices of the portion of the lattice containing the zeroth site

reg2 : (1-fraction)*NP x 1 array

Indices of the other portion of the lattice

factor : float

Factor by which to adjust/tune the values of the connection matrix

ilpm.networks.row_is_in_array(row, array)[source]

Check if row ([x,y]) is an element of an array ([[x1,y1],[x2,y2],...])

ilpm.networks.perp(a)[source]

Get vector perpendicular to input vector a

ilpm.networks.intersection_lines(a1, a2, b1, b2)[source]

Find line intersection using two points on each line see Computer Graphics by F.S. Hill

Parameters:

a1 : 1 x 2 float array

endpoint 1 for the first lineseg

a2 : 1 x 2 float array

endpoint 2 for the first lineseg

b1 : 1 x 2 float array

endpoint 1 for the second lineseg

b2 : 1 x 2 float array

endpoint 2 for the second lineseg

Returns:

intersect : 1 x 2 float array

The intersection of the two lines defined by pts (a1,a2) and (b1,b2)

ilpm.networks.intersection_linesegs(a1, a2, b1, b2, thres=1e-06)[source]

Find line segment intersection using endpts of each lineseg. see Computer Graphics by F.S. Hill

Parameters:

a1 : 1 x 2 float array

endpoint 1 for the first lineseg

a2 : 1 x 2 float array

endpoint 2 for the first lineseg

b1 : 1 x 2 float array

endpoint 1 for the second lineseg

b2 : 1 x 2 float array

endpoint 2 for the second lineseg

thres : float

minimum distance for admitting intersection

Returns:

intersect : 1 x 2 float array

The intersection of the two linesegments (a1,a2) and (b1,b2)

ilpm.networks.find_intersections(A, B)[source]

Get the intersections between line segments A and line segments B, without a nested for loop over linesegs. http://stackoverflow.com/questions/3252194/numpy-and-line-intersections

Returns:x, y : coords of intersections
ilpm.networks.point_is_on_linesegment_2D_singlept(p, a, b, thres=1e-05)[source]

Check if point is on line segment (or vertical line is on plane in 3D, since 3rd dim ignored).

Parameters:

p : array or list of length >=2

The point in 2D

a : array or list of length >=2

One end of the line segment

b : array or list of length >=2

The other end of the line segment

thres : float

How close must the point be to the line segment to be considered to be on it

Returns:

Boolean : whether the pt is on the line segment

ilpm.networks.point_is_on_linesegment_2D(p, a, b, thres=1e-05)[source]

Check if point is on line segment (or vertical line is on plane in 3D, since 3rd dim ignored).

Parameters:

p : array of dimension #points x >=2

The points in 2D (or 3D with 3rd dim ignored)

a : array or list of dimension 1 x >=2

One end of the line segment

b : array or list of dimension 1 x >=2

The other end of the line segment

thres : float

How close must the point be to the line segment to be considered to be on it

Returns:

Boolean array : whether the pts are on the line segment

ilpm.networks.closest_pt_along_line(pt, endpt1, endpt2)[source]

Get point along a line defined by two points (endpts), closest to a point not on the line

Parameters:

pt : array of length 2

point near which to find nearest point

endpt1, endpt2 : arrays of length 2

x,y positions of points on line as array([[x0,y0],[x1,y1]])

Returns:

proj : array of length 2

the point nearest to pt along line

ilpm.networks.closest_pts_along_line(pts, endpt1, endpt2)[source]

For each coordinate in pts, get point along a line defined by two points (endpts) which is closest to that coordinate. Returns p as numpy array of points along the line. Right now just works in 2D.

Parameters:

pts : NP x 2 float array

point near which to find nearest point

endpt1, endpt2 : 2 x 1 float arrays

x,y positions of points on line as array([[x0,y0],[x1,y1]])

Returns:

proj : array of length 2

the points along line that are nearest to each coordinate in pts

ilpm.networks.closest_pt_on_lineseg(pt, endpts)[source]

Get point on line segment closest to a point not on the line; could be an endpt if lineseg is distant from pt.

Parameters:

pt : array of length 2

point near which to find near point

endpts : array of dimension 2x2

x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])

Returns:

proj : array of length 2

the point nearest to pt on lineseg

ilpm.networks.closest_pts_on_lineseg(pts, endpt1, endpt2)[source]

Get points on line segment closest to an array of points not on the line; the closest point can be an endpt, for example if the lineseg is distant from pt. Works in any dimension now, if closest_pts_along_line works in any dimension.

Parameters:

pts : N x dim float array

points near which to find near point

endpt1 : dim x 1 float array

position of first endpt of line segment as array([x0, x1, ... xdim])

endpt2 : dim x 1 float array

position of second endpt of line segment as array([x0, x1, ... xdim])

Returns:

p : N x dim float array

the point nearest to pt on lineseg

d : float

distance from pt to p

ilpm.networks.closest_pts_on_lineseg_2D(pts, endpt1, endpt2)[source]

Get points on line segment closest to an array of points not on the line; the closest point can be an endpt, for example if the lineseg is distant from pt.

Parameters:

pts : array N x 2

points near which to find near point

endpt1 : 2x2 float array

x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])

endpt2 : 2x2 float array

x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])

Returns:

p : array of length 2

the point nearest to pt on lineseg

d : float

distance from pt to p

ilpm.networks.line_pts_are_on_lineseg(p, a, b)[source]

Check if an array of n-dimensional points (p) which lie along a line is between two other points (a,b) on that line (ie, is on a line segment)

Parameters:

p : array of dim N x 2

points for which to evaluate if they are on segment

a,b : dim x 1 float arrays or lists

positions of line segment endpts

Returns:

True or False: whether pt is between endpts

ilpm.networks.line_pts_are_on_lineseg_2D(p, a, b)[source]

Check if an array of points (p) which lie along a line is between two other points (a,b) on that line (ie, is on a line segment)

Parameters:

p : array of dim N x 2

points for which to evaluate if they are on segment

a,b : arrays or lists of length 2

x,y positions of line segment endpts

Returns:

True or False: whether pt is between endpts

ilpm.networks.pts_are_near_lineseg(x, endpt1, endpt2, W)[source]

Determine if pts in array x are within W of line segment

Parameters:

x : NP x 2 float array

the points to consider proximity to a lineseg

endpt1 : 2x2 float array

the first endpoint of the linesegment

endpt2 : 2x2 float array

the second endpoint of the linesegment

W : float

threshold distance from lineseg to consider a point ‘close’

Returns:

NP x 1 boolean array

Whether the points are closer than W from the linesegment

ilpm.networks.is_number(s)[source]

Check if a string can be represented as a number; works for floats

ilpm.networks.string_to_array(string, delimiter='/', dtype='auto')[source]

Convert string to numpy array See also string_sequence_to_numpy_array()

ilpm.networks.string_sequence_to_numpy_array(vals, dtype=<type 'str'>)[source]

Convert a string of numbers like (#/#/#) or (#:#:#) or (#:#) or (#) to a numpy array.

Parameters:

vals : string

List of values, can take formats: ‘check_string_for_empty’, #/#/#, #:#:#, #:#, or #

dtype:

Returns:

out : numpy array

Values input as string, returned as array

ilpm.networks.float2pstr(floatv, ndigits=2)[source]

Format a float as a string, replacing decimal points with p

ilpm.networks.prepstr(string)[source]

Format a string for using as part of a directory string

ilpm.networks.delaunay_lattice_from_pts(xy, trimbound=True, target_z=-1, max_bond_length=-1, thres=4.0, zmethod='random', minimum_bonds=-1, check=False)[source]

Convert 2D pt set to lattice (xy, NL, KL, BL, BM) via traingulation. The order of operations is very important: A) Trim boundary triangles (needs to be a triangulation to work). B) Cut long bonds. C) Tune average coordination. The nontrivial part of this program kills edges which are unnatural according to the following definition: 1. The outside edge is the hypotenuse of the triangle 2. Call the hypotenuse the “base” and determine the “height” of the triangle. Then if base/height > x (where x is some criteria value, say 4), delete that edge/triangle (depending on data structure/object definitions).

Parameters:

xy : #pts to be triangulated x 2 array

xy points from which to construct lattice

trimbound : bool (optional)

Whether to trim the boundary triangles based on aspect ratio

target_z: float

Average coordinate to which the function will tune the network, if specified to be > 0.

max_bond_length : float

cut bonds longer than this value, if specified to be > 0

thres : float

cut boundary triangles with height/base longer than this

zmethod : string (‘random’ ‘highest’)

Whether to cut randomly or cut bonds from nodes with highest z, if target_z > 0

minimum_bonds: int or None (default=-1)

If minimum_bonds>0, removes all points with fewer than minimum_bonds bonds

check: bool

View intermediate results

Returns:

xy : NP x 2 float array

triangulated points

NL : NP x NN int array

Neighbor list

KL : NP x NN int array

Connectivity list

BL : Nbonds x 2 int array

Bond list

BM : NP x NN float array

unstretched (reference) bond length matrix

ilpm.networks.voronoi_lattice_from_pts(points, polygon=None, NN=3, kill_outliers=True, check=False)[source]

Convert 2D pt set to dual lattice (xy, NL, KL, BL) via Voronoi construction

Parameters:

points : #triangulated pts x 2 array

xy points from a Delaunay triangulation

polygon

Returns:

xy : NP x 2 float array

points living on vertices of dual to triangulation

NL : NP x NN int array

Neighbor list

KL : NP x NN int array

Connectivity list

BL : Nbonds x 2 int array

Bond list

ilpm.networks.voronoi_rect_periodic_from_pts(xy, LL, BBox='auto', dist=7.0, check=False)[source]

Convert 2D pt set to dual lattice (xy, NL, KL, BL) via Voronoi construction

Parameters:

points : #triangulated pts x 2 array

xy points from a Delaunay triangulation

polygon

Returns:

xy : NP x 2 float array

points living on vertices of dual to triangulation

NL : NP x NN int array

Neighbor list

KL : NP x NN int array

Connectivity list

BL : Nbonds x 2 int array

Bond list

ilpm.networks.delaunay_centroid_lattice_from_pts(xy, polygon=None, trimbound=True, thres=2.0, shear=-1, check=False)[source]

Convert 2D pt set to lattice (xy, NL, KL, BL, BM) via traingulation. Performs: A) Triangulate the point set. B) If trimbound==True, trim boundary triangles (needs to be a triangulation to work) C) Find centroids D) Connect centroids in z=3 lattice Part of this program kills edges which are unnatural according to the following definition: 1. The outside edge is the hypotenuse of the triangle 2. Call the hypotenuse the “base” and determine the “height” of the triangle. Then if base/height > x (where x is some criteria value, say 4), delete that edge/triangle (depending on data structure/object definitions).

Parameters:

xy : #pts to be triangulated x 2 array

xy points from which to construct lattice

polygon : numpy float array [[x0,y0],...,[xN,yN]], or string ‘auto’

polygon to cut out from centroid lattice. If ‘auto’, cuts out a box with a buffer distance of 5%

trimbound : bool

Whether to trim off high-aspect-ratio triangles from edges of the triangulation before performing centroid operation

thres : float (default = 2.0)

cut boundary triangles with height/base longer than this value

shear : float (ignored if negative)

shear inverse slope (run/rise) to apply to xy in order to prevent degeneracy in triangulation (breaks symmetry)

check : bool

Whether to plot results as they are computed

Returns:

xycent : NP x 2 float array

Centroids of triangulation of xy

NL : NP x NN int array

Neighbor list (of centroids of triangulation of xy)

KL : NP x NN int array

Connectivity list (of centroids of triangulation of xy)

BL : Nbonds x 2 int array

Bond list (of centroids of triangulation of xy)

BM : NP x NN float array

unstretched (reference) bond length matrix (of centroids of triangulation of xy)

ilpm.networks.delaunay_centroid_rect_periodic_network_from_pts(xy, LL, BBox='auto', check=False)[source]

Convert 2D pt set to lattice (xy, NL, KL, BL, BM, PVxydict) via traingulation, handling periodic BCs. Performs: A) Triangulate an enlarged version of the point set. B) Find centroids C) Connect centroids in z=3 lattice D) Crops to original bounding box and connects periodic BCs Note: Normally BBox is centered such that original BBox is [-LL[0]*0.5, -LL[1]*0.5], [LL[0]*0.5, -LL[1]*0.5], etc.

Parameters:

xy : NP x 2 float array

xy points from which to find centroids, so xy are in the triangular representation

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

BBox : #vertices x 2 numpy float array

bounding box for the network. Here, this MUST be rectangular, and the side lengths should be taken to be LL[0], LL[1] for it to be sensible.

check : bool

Whether to view intermediate results

ilpm.networks.delaunay_rect_periodic_network_from_pts(xy, LL, BBox='auto', check=False, target_z=-1, max_bond_length=-1, zmethod='random', minimum_bonds=-1, dist=7.0)[source]

Buffers the true point set with a mirrored point set across each boundary, for a rectangular boundary.

Parameters:

xy : NP x 2 float array

Particle positions

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

BBox : 4 x 2 float array or ‘auto’

The bounding box to use as the periodic boundary box

check : bool

Whether to display intermediate results

target_z: float

Average coordinate to which the function will tune the network, if specified to be > 0.

max_bond_length : float

cut bonds longer than this value

zmethod : string (‘random’ ‘highest’)

Whether to cut randomly or cut bonds from nodes with highest z

minimum_bonds: int

If >0, remove pts with fewer bonds

dist : float

minimum depth of the buffer on each side

Returns:

xytrim : (~NP) x 2 float array

triangulated point set with periodic BCs on right, left, above, and below

ilpm.networks.buffer_points_for_rectangular_periodicBC(xy, LL, dist=7.0)[source]

Buffers the true point set with a mirrored point set across each boundary, for a rectangular boundary.

Parameters:

xy : NP x 2 float array

Particle positions

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

dist : float

minimum depth of the buffer on each side

Returns:

xyout : (>= NP) x 2 float array

Buffered point set with edges of sample tiled on the right, left, above and below

ilpm.networks.buffered_pts_to_periodic_network(xy, BL, LL, BBox='auto', check=False)[source]

Crops to original bounding box and connects periodic BCs of rectangular sample Note: Default BBox is centered such that original BBox is [-LL[0]*0.5, -LL[1]*0.5], [LL[0]*0.5, -LL[1]*0.5], etc.

Parameters:

xy : NP x 2 float array

xy points with buffer points, so xy are in the triangular representation

LL : tuple of 2 floatsf

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

BBox : #vertices x 2 numpy float array

bounding box for the network. Here, this MUST be rectangular, and the side lengths should be taken to be LL[0], LL[1] for it to be sensible.

check : bool

Whether to view intermediate results

ilpm.networks.delaunay_periodic_network_from_pts(xy, PV, BBox='auto', check=False, target_z=-1, max_bond_length=-1, zmethod='random', minimum_bonds=-1, ensure_periodic=False)[source]

Buffers the true point set with a mirrored point set across each boundary, for a rectangular boundary.

Parameters:

xy : NP x 2 float array

Particle positions

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

BBox : 4 x 2 float array or ‘auto’

The bounding box to use as the periodic boundary box

check : bool

Whether to display intermediate results

target_z: float

Average coordinate to which the function will tune the network, if specified to be > 0.

max_bond_length : float

cut bonds longer than this value

zmethod : string (‘random’ ‘highest’)

Whether to cut randomly or cut bonds from nodes with highest z

minimum_bonds: int

If >0, remove pts with fewer bonds

dist : float

minimum depth of the buffer on each side

Returns:

xytrim : (~NP) x 2 float array

triangulated point set with periodic BCs on right, left, above, and below

ilpm.networks.ensure_periodic_connectivity(xy, NL, KL, BL)[source]

For each paticle, look at bonds, and look at the bonds of the same particles elsewhere in a lattice according to the periodic vectors PV. If there are bonds that have been triangulated differently than they in different parts of a periodic network, which can happen due to roundoff error, fix these bonds

ilpm.networks.delaunay_centroid_periodic_network_from_pts(xy, PV, BBox='auto', flex_pvxy=False, shear=-1.0, check=False)[source]

Convert 2D pt set to lattice (xy, NL, KL, BL, BM, PVxydict) via traingulation, handling periodic BCs. Performs: A) Triangulate an enlarged version of the point set. B) Find centroids C) Connect centroids in z=3 lattice D) Crops to original bounding box and connects periodic BCs Note: Normally BBox is centered such that original BBox is [-LL[0]*0.5, -LL[1]*0.5], [LL[0]*0.5, -LL[1]*0.5], etc.

Parameters:

xy : NP x 2 float array

xy points from which to find centroids, so xy are in the triangular representation

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

BBox : #vertices x 2 numpy float array

bounding box for the network. Here, this MUST be rectangular, and the side lengths should be taken to be LL[0], LL[1] for it to be sensible.

check : bool

Whether to view intermediate results

ilpm.networks.buffer_points_for_periodicBC(xy, PV, check=False)[source]

Buffers the true point set with a mirrored point set across each boundary, for a parallelogram (or evenutally a more argitrary boundary).

Parameters:

xy : NP x 2 float array

Particle positions

PV : 2 x 2 float array

Periodic vectors: the first has x and y components, the second has only positive y component.

dist : float

minimum depth of the buffer on each side

Returns:

xyout : (>= NP) x 2 float array

Buffered point set with edges of sample tiled on the right, left, above and below

ilpm.networks.buffered_pts_to_periodic_network_parallelogram(xy, BL, PV, BBox='auto', flex_pvxy=False, check=False)[source]

Crops to original bounding box and connects periodic BCs of sample in a parallelogram Note: Default BBox is such that original BBox is [-PV[0, 0]*0.5, -(PV[1, 1] + PV[0, 1])*0.5], [PV[0, 0]*0.5, (-PV[1, 1] + PV[0, 1])*0.5], etc. Presently this only allows parallelograms with vertical sides.

/|PV[0] + PV[1]

/ |

/ |

| PV[0]
/
/

|/ (0,0)

Parameters:

xy : NP x 2 float array

xy points with buffer points, so xy are in the triangular representation

BL : #bonds x 2 int array

Bond list for the network: a row with [i, j] means i and j are connected. If negative, across periodic boundary

PV : 2 x 2 float array

Periodic vectors: the first has x and y components, the second has only positive y component.

BBox : 4 x 2 numpy float array

bounding box for the network. Here, this must be a parallelogram. The first point must be the lower left point!

check : bool

Whether to view intermediate results

ilpm.networks.highlight_bonds(xy, BL, ax=None, color='r', lw=1, show=True)[source]

Plot bonds specified in BL on specified axis.

Parameters:

xy

BL

ax

color

show

Returns:

ax

ilpm.networks.find_cut_bonds(BL, keep)[source]

Identify which bonds are cut by the supplied mask ‘keep’.

Parameters:

BL

keep

Returns:

BLcut : #cut bonds x 2 int array

The cut bonds

cutIND : #bonds x 1 int array

indices of BL of cut bonds

ilpm.networks.PBCmap_for_rectangular_buffer(xy, LL, dist=7.0)[source]

Buffers the true point set with a mirrored point set across each boundary, for a rectangular boundary, and creates a dict mapping each mirror (outer) particle to its true (inner) particle. NOTE: This code is UNTESTED!

Parameters:

xy : NP x 2 float array

Particle positions

LL : tuple of 2 floats

Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.

dist : float

maximum depth of the buffer on each side

Returns:

xyout :

PBCmap : dict with int keys and tuple of (int, numpy 1x2 float array) as values

Periodic boundary condition map, takes (key) index of xyout to (value) its reference/true point For example, say that particle 2 looks to particle 1 as if beyond a boundary, translated by (LL[0],0). Since this function buffers the true point set with a mirrored point set across each boundary, then PBCmap maps the index of the mirror point to its true particle position inside the bounding box of the sample, tupled with the true particle’s periodic vector (the vector mapping the true point to the mirror pt).

ilpm.networks.centroid_lattice_from_TRI(xy, TRI, check=False)[source]

Convert triangular representation (such as a triangulation) of lattice to xy, NL, KL of centroid lattice.

Parameters:

xy : #pts x 2 float array

xy points from which to find centroids, so xy are in the triangular representation

TRI : array of dimension #tris x 3

Each row contains indices of the 3 points lying at the vertices of the tri.

Returns:

xy : #pts x 2 float array

centroids for lattice

NL : NP x NN int array

Neighbor list

KL : NP x NN int array

Connectivity list

BL : Nbonds x 2 int array

Bond list

BM : NP x NN float array

unstretched (reference) bond length matrix

ilpm.networks.collect_lines(xy, BL, bs, climv)[source]

Creates collection of line segments, colored according to an array of values.

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

bs : array of dimension #bonds x 1

Strain in each bond

climv : float or tuple

Color limit for coloring bonds by bs

Returns:

line_segments : matplotlib.collections.LineCollection

Collection of line segments

ilpm.networks.draw_lattice(ax, lat, bondcolor='k', colormap='BlueBlackRed', lw=1, climv=0.1)[source]

Add a network to an axis instance (draw the bonds of the network)

Parameters:

ax

xy

BL

bondcolor

colormap

lw

climv

ilpm.networks.movie_plot_2D(xy, BL, bs=None, fname='none', title='', NL=[], KL=[], BLNNN=[], NLNNN=[], KLNNN=[], PVx=[], PVy=[], PVxydict={}, ax=None, fig=None, axcb='auto', xlimv='auto', ylimv='auto', climv=0.1, colorz=True, ptcolor=None, figsize='auto', colorpoly=False, bondcolor=None, colormap='seismic', bgcolor=None, axis_off=False, axis_equal=True, text_topleft=None, lw=-1.0, ptsize=10, negative_NNN_arrows=False, show=False, arrow_alpha=1.0, fontsize=8)[source]

Plots (and saves if fname is not ‘none’) a 2D image of the lattice with colored bonds and particles colored by coordination (both optional).

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points

bs : array of dimension #bonds x 1

Strain in each bond

fname : string

Full path including name of the file (.png, etc), if None, will not save figure

title : string

The title of the frame

NL : NP x NN int array (optional, for speed)

Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions

KL : NP x NN int array (optional, for speed)

Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions

PVx : NP x NN float array (optional, for periodic lattices and speed)

ijth element of PVx is the x-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.

PVy : NP x NN float array (optional, for periodic lattices and speed)

ijth element of PVy is the y-component of the vector taking NL[i,j] to its image as seen by particle i If PVx and PVy are specified, PVxydict need not be specified.

PVxydict : dict (optional, for periodic lattices)

dictionary of periodic bonds (keys) to periodic vectors (values)

ax: matplotlib figure axis instance

Axis on which to draw the network

fig: matplotlib figure instance

Figure on which to draw the network

axcb: matplotlib colorbar instance

Colorbar to use for strains in bonds

xlimv: float or tuple of floats

ylimv: float or tuple of floats

climv : float or tuple

Color limit for coloring bonds by bs

colorz: bool

whether to color the particles by their coordination number

ptcolor: string color spec or tuple color spec or None

color specification for coloring the points, if colorz is False. Default is None (no coloring of points)

figsize : tuple

w,h tuple in inches

colorpoly : bool

Whether to color in polygons formed by bonds according to the number of sides

bondcolor : color specification (hexadecimal or RGB)

colormap : if bondcolor is None, uses bs array to color bonds

bgcolor : hex format string, rgb color spec, or None

If not None, sets the bgcolor. Often used is ‘#d9d9d9’

axis_off

axis_equal

text_topleft

lw: float

line width for plotting bonds. If lw == -1, then uses automatic line width to adjust for bond density..

ptsize: float

size of points passed to absolute_sizer

Returns:

[ax,axcb] : stuff to clear after plotting

ilpm.networks.display_lattice_2D(xy, BL, NL=[], KL=[], BLNNN=[], NLNNN=[], KLNNN=[], PVxydict={}, PVx=[], PVy=[], bs='none', title='', xlimv=None, ylimv=None, climv=0.1, colorz=True, ptcolor=None, ptsize=10, close=True, colorpoly=False, viewmethod=False, labelinds=False, colormap='seismic', bgcolor='#d9d9d9', axis_off=False, fig=None, ax=None, linewidth=0.0, edgecolors=None)[source]

Plots and displays a 2D image of the lattice with colored bonds.

Parameters:

xy : array of dimension nx2

2D lattice of points (positions x,y)

BL : array of dimension #bonds x 2

Each row is a bond and contains indices of connected points. Negative values denote periodic BCs

bs : array of dimension #bonds x 1

Strain in each bond

fname : string

Full path including name of the file (.png, etc)

title : string

The title of the frame

climv : float or tuple

Color limit for coloring bonds by bs

colorz : bool

Whether to color the particles by their coordination number

close : bool

Whether or not to leave the plot hanging to force it to be closed

colorpoly : bool

Whether to color polygons by the number of edges

BLNNN : NP x NNNN int array

Bond list for next nearest neighbor couplings.

Returns:

ax : matplotlib axis instance or None

If close==True, returns None. Otherwise returns the axis with the network plotted on it.