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¶
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLNP 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
- BMarray 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]).
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points. Negative values denote particles connected through periodic bonds.
- bLarray of length #bonds
The ith element is the length of of the ith bond in BL
- LLtuple 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_out2*N x 1 complex array
eigenvalues of the matrix, sorted by order of imaginary components
- eigvect_outtypically 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.
- polygonslist of int lists
indices of xy points defining polygons.
- NLNNNarray 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.
- KLNNNarray 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)
- PVxydictdict
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
- PVxNP 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
- PVyNP 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¶
|
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
- com1 x 2 float array
position to compute distances with respect to
- LLtuple of floats
spatial extent of each periodic dimension (ie x(LL[0]) = x(0), y(LL[1]) = y(0))
- Returns
- distlen(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
- xyNP x 2 float array
The positions of the particles/masses/weighted objects
- massesNP x 1 float array
The weight to attribute to each particle.
- Returns
- com2 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
- xyNP x 2 float array
The positions of the particles/masses/weighted objects
- LL :
- massesNP 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
- com2 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
- xN x (1 or 2) array
The array to take a running average over
- Nint
The window size of the running average
- Returns
- output1d 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
- xunstructured 1D array
data along first dimension
- yunstructured 1D array
data along second dimension
- z1D array
values evaluated at x,y
- nint
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
- Xn x 1 float array
meshgrid of first dimension
- Xn x 1 float array
meshgrid of second dimension
- Zmn 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
- distN 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
- MdiffN 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
- arr2sortN x 1 array
Array to sort
- arrayList2sortList of N x 1 arrays
Other arrays to sort, by the indexing of arr2sort
- Returns
- arr_s, arrList_ssorted N x 1 arrays
-
ilpm.networks.
count_NN
(KL)[source]¶ Count how many nearest neighbors each particle has.
- Parameters
- KLNP x max(#neighbors) array
Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.
- Returns
- zvalsNP 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
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLNP x max(#neighbors) array
Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.
- Returns
- NLdictdict
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
- TRIarray of dimension #tris x 3
Each row contains indices of the 3 points lying at the vertices of the tri.
- Returns
- BLarray 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
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- Returns
- TRIarray 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
- aN 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
- aN x M array of variable dtype
array from which to return only the unique rows
- thresfloat
threshold for deleting a row that has slightly different values from another row
- Returns
- aN 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
- aN x M array of variable dtype
array from which to return only the unique rows
- thresfloat
threshold for deleting a row that has slightly different values from another row
- Returns
- aN x M array of variable dtype
unique rows of input array
- orderN x 1 int array
indices used to sort a in order
- uiN 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
- RNP x ndim array
the points over which to find the min distance between points
- Returns
- min_distfloat
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
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLNP x max(#neighbors) array
Connectivity matrix. All nonzero elements (whether =1 or simply !=0) are interpreted as connections.
- Returns
- BLarray 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
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLarray 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.
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- Returns
- kLarray 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
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- Returns
- KLarray 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
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- NPint
number of points (defines the length of NL and KL)
- NNint
maximum number of neighbors (defines the width of NL and KL)
- Returns
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLarray 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
- xyarray of dimension nxd
2D lattice of points (positions x,y(,z) )
- NLint array of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- KLarray 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.
- PVxNP 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
- PVyNP 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
- BMarray 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
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- Returns
- BMarray 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
- NLarray of dimension #pts x max(#neighbors)
The ith row contains indices for the neighbors for the ith point.
- BMarray 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]).
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- Returns
- bLarray 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
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points.
- Returns
- bLarray 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
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points.
- boarray of dimension #bonds x 1
Rest lengths of bonds, in order of BL, lowercase to denote 1D array.
- Returns
- bsarray of dimension #bonds x 1
The strain of each bond, in order of BL
-
ilpm.networks.
TRI2centroidNLandKL
(TRI)[source]¶ Convert triangular rep of lattice (such as triangulation) to neighbor array and connectivity array of the triangle centroids.
- Parameters
- TRINtris x 3 int array
Triangulation of a point set. Each row gives indices of vertices of single triangle.
- Returns
- NLNP x NN int array
Neighbor list
- KLNP 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
- TRINtris x 3 int array
Triangulation of a point set. Each row gives indices of vertices of single triangle.
- Returns
- NLNP x NN int array
Neighbor list
- KLNP x NN int array (optional, for speed)
Connectivity list, with -1 entries for periodic bonds
- BLarray 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
- TRINtris x 3 int array
Triangulation of a point set. Each row gives indices of vertices of single triangle.
- Returns
- BLarray 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
- TRINtris x 3 int array
Triangulation of a point set. Each row gives indices of vertices of single triangle.
- remove_negativesbool
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
- NLNP x NN int array
Neighbor list
- KLNP 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
- TRINtris x 3 int array
Triangulation of a point set. Each row gives indices of vertices of single triangle.
- remove_negativesbool
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
- BLNbonds 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
- PVxydictdict
dictionary of periodic bonds (keys) to periodic vectors (values)
- NLNP x NN int array
Neighbor list
- checkbool
view intermediate results
- Returns
- PVxNP 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
- PVyNP 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
- PVxydictdict
dictionary of periodic bonds (keys) to periodic vectors (values)
- NLNP x NN int array
Neighbor list
- checkbool
view intermediate results
- Returns
- PVxNP 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
- PVyNP 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
- PVxNP 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
- PVyNP 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
- NLNP x NN int array
Neighbor list
- KLNP x NN int array (optional, for speed, could be None)
Connectivity list, with -1 entries for periodic bonds
- epsfloat
Threshold norm value for periodic boundary vector to be recognized as such
- Returns
- PVxydictdict
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
- xyNP x 2 float array
positions of the particles in 2D
- NLNP x #NN int array
Neighbor list – the i,jth element is the index (of xy) of the jth neighbor of the ith particle
- polygonNsides x 2 float array
the bounding box of the sample (can be any polygonal shape with pairs of parellel sides)
- PVNsides 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
- PVxydictdict
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
- xyNP x 2 float array
point set in 2D
- BL#bonds x 2 int array
Bond list
- NLNP 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.
- KLNP 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
- eigvector2 x NP complex array
First row is X component, second is Y.
- point_arrM 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
- phaseNP 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
- xyNP x 2 float array
The point set
- NLNP 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
- KLNP 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]
- BLNbonds x 2 int array
Bond list for the lattice (can include bonds that aren’t triangulated)
- TRINtris x 3 int array
The triangulation of the lattice/mesh
- thresfloat
threshold value for base/height, below which to cut the boundary tri
- check: bool
Display intermediate results
- Returns
- NLNP 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
- KLNP 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]
- BLNbonds 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
- xyNP x 2 float array
The point set
- BLNbonds x 2 int array
Bond list for the lattice (can include bonds that aren’t triangulated)
- TRINtris 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
- thresfloat
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
- Ncutint
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
- xyNP x 2 float array
points living on vertices of dual to triangulation
- BLNbonds x 2 int array
Each row is a bond and contains indices of connected points
- NLNP 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
- KLNP 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]
- PVxNP 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.
- PVyNP 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.
- PVxydictdict (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
- polygonslist 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
- iterablelist or other iterable
the list to tuple
- Returns
- outlist 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
- polylist 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)))
- PVxydictdict
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
- xypolylist of coordinates (each a list of 2 floats)
The polygon as it appears to the first particle/vertex in the input list poly
- periodicpolybool
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
- xyNP 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
- Alist
- Blist
- 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
- A1d numpy array
- B1d 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, sublstlists
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
- imageN x M numpy array
The 2D image
- center1 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_prof1 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
- keepNP_0 x 1 int array or bool array
indices (of xy, of particles) to keep
- xyNP_0 x 2 float array
points living on vertices of dual to triangulation
- BLNbonds_0 x 2 int array or empty list
Each row is a bond and contains indices of connected points
- NNint or string ‘min’
Number of nearest neighbors in each row of KL, NL
- Returns
- xyNP x 2 float array
points living on vertices of dual to triangulation
- NLNP x NN int array
Neighbor list
- KLNP x NN int array
Connectivity list
- BLNbonds 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
- xyNP x dim array
positions of particles
- NLNL x NN array
neighbor list
- KLNL x NN array
connectivity list
- Returns
- zfloat
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
- xyNP x dim array
positions of particles
- NLNL x NN array
neighbor list
- KLNL x NN array
connectivity list
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- target_zfloat
target average bulk coordination, to be approximately enforced by cutting bonds
- bulk_determinationstring (‘Triangulation’ ‘Cutter’ ‘Endpts’)
How to determine which bonds are in the bulk and which are on the boundary
- Returns
- NLoutNL x NN int array
neighbor list
- KLoutNL 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
- xyNP x dim array
positions of particles
- NLNL x NN array
neighbor list
- KLNL x NN array
connectivity list
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- target_zfloat
target average bulk coordination, to be approximately enforced by cutting bonds
- Returns
- NLNL x NN int array
neighbor list
- KLNL 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
- AN1 x M array
Array to take rows of not in B (could be BL, for ex)
- BN2 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
- AN1 x M array
Array to take rows of not in B (could be BL, for ex)
- BN2 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
- xyNP x dim array
positions of particles
- NLNL x NN array
neighbor list
- KLNL x NN array
connectivity list
- BM0NL x NN array
bond rest lengths
-
ilpm.networks.
cut_bonds
(BL, xy, thres)[source]¶ Cuts bonds with LENGTHS greater than cutoff value.
- Parameters
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- thresfloat
cutoff length between points
- Returns
- BLtrimarray 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
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- bstrainfloat
breaking strain – bonds strained above this amount are cut
- Returns
- BLtrimarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points, contains no bonds longer than thres
- bL0trimarray 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, MtrN x 1 arrays
radial, azimuthal, and shear components of the tensor M
- xN x 1 array
the x positions of the points on which M is defined
- yN x 1 array
the y positions of the points on which M is defined
- Returns
- Mxx,Mxy,Myx,MyyN 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,MyyN x 1 arrays
cartesian components of the tensor M
- xN x 1 array
the x positions of the points on which M is defined
- yN x 1 array
the y positions of the points on which M is defined
- Returns
- Mrr, Mrt, Mtr, MttN 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,MttN x 1 arrays
polar components of the tensor M
- betafloat
angle of x axis wrt radial axis (phi =0)
- Returns
- pxN x 1 float array
the traction in the x direction
- pyN 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,MyyN x 1 arrays
cartesian components of the tensor M in xy coord sys
- betafloat
angle of x’ wrt x (counterclockwise rotation)
- Returns
- Mxxprime, Mxyprime, MxyprimeN 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
- XYNP x 2 array
Each row is a 2D x,y vector to rotate counterclockwise
- thetafloat
Rotation angle
- Returns
- XYrotNP 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
- NLNP x NN array
Each row corresponds to a lattice site. The entries give indices of the neighboring sites
- KLNP 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_reg1NP 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
- NLNP 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
- factorfloat
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.
intersection_lines
(a1, a2, b1, b2)[source]¶ Find line intersection using two points on each line see Computer Graphics by F.S. Hill
- Parameters
- a11 x 2 float array
endpoint 1 for the first lineseg
- a21 x 2 float array
endpoint 2 for the first lineseg
- b11 x 2 float array
endpoint 1 for the second lineseg
- b21 x 2 float array
endpoint 2 for the second lineseg
- Returns
- intersect1 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
- a11 x 2 float array
endpoint 1 for the first lineseg
- a21 x 2 float array
endpoint 2 for the first lineseg
- b11 x 2 float array
endpoint 1 for the second lineseg
- b21 x 2 float array
endpoint 2 for the second lineseg
- thresfloat
minimum distance for admitting intersection
- Returns
- intersect1 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, ycoords 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
- parray or list of length >=2
The point in 2D
- aarray or list of length >=2
One end of the line segment
- barray or list of length >=2
The other end of the line segment
- thresfloat
How close must the point be to the line segment to be considered to be on it
- Returns
- Booleanwhether 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
- parray of dimension #points x >=2
The points in 2D (or 3D with 3rd dim ignored)
- aarray or list of dimension 1 x >=2
One end of the line segment
- barray or list of dimension 1 x >=2
The other end of the line segment
- thresfloat
How close must the point be to the line segment to be considered to be on it
- Returns
- Boolean arraywhether 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
- ptarray of length 2
point near which to find nearest point
- endpt1, endpt2arrays of length 2
x,y positions of points on line as array([[x0,y0],[x1,y1]])
- Returns
- projarray 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
- ptsNP x 2 float array
point near which to find nearest point
- endpt1, endpt22 x 1 float arrays
x,y positions of points on line as array([[x0,y0],[x1,y1]])
- Returns
- projarray 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
- ptarray of length 2
point near which to find near point
- endptsarray of dimension 2x2
x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])
- Returns
- projarray 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
- ptsN x dim float array
points near which to find near point
- endpt1dim x 1 float array
position of first endpt of line segment as array([x0, x1, … xdim])
- endpt2dim x 1 float array
position of second endpt of line segment as array([x0, x1, … xdim])
- Returns
- pN x dim float array
the point nearest to pt on lineseg
- dfloat
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
- ptsarray N x 2
points near which to find near point
- endpt12x2 float array
x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])
- endpt22x2 float array
x,y positions of endpts of line segment as array([[x0,y0],[x1,y1]])
- Returns
- parray of length 2
the point nearest to pt on lineseg
- dfloat
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
- parray of dim N x 2
points for which to evaluate if they are on segment
- a,bdim 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
- parray of dim N x 2
points for which to evaluate if they are on segment
- a,barrays 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
- xNP x 2 float array
the points to consider proximity to a lineseg
- endpt12x2 float array
the first endpoint of the linesegment
- endpt22x2 float array
the second endpoint of the linesegment
- Wfloat
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=<class 'str'>)[source]¶ Convert a string of numbers like (#/#/#) or (#:#:#) or (#:#) or (#) to a numpy array.
- Parameters
- valsstring
List of values, can take formats: ‘check_string_for_empty’, #/#/#, #:#:#, #:#, or #
- dtype:
- Returns
- outnumpy 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.
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
- trimboundbool (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_lengthfloat
cut bonds longer than this value, if specified to be > 0
- thresfloat
cut boundary triangles with height/base longer than this
- zmethodstring (‘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
- xyNP x 2 float array
triangulated points
- NLNP x NN int array
Neighbor list
- KLNP x NN int array
Connectivity list
- BLNbonds x 2 int array
Bond list
- BMNP 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
- xyNP x 2 float array
points living on vertices of dual to triangulation
- NLNP x NN int array
Neighbor list
- KLNP x NN int array
Connectivity list
- BLNbonds 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
- xyNP x 2 float array
points living on vertices of dual to triangulation
- NLNP x NN int array
Neighbor list
- KLNP x NN int array
Connectivity list
- BLNbonds 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
- polygonnumpy 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%
- trimboundbool
Whether to trim off high-aspect-ratio triangles from edges of the triangulation before performing centroid operation
- thresfloat (default = 2.0)
cut boundary triangles with height/base longer than this value
- shearfloat (ignored if negative)
shear inverse slope (run/rise) to apply to xy in order to prevent degeneracy in triangulation (breaks symmetry)
- checkbool
Whether to plot results as they are computed
- Returns
- xycentNP x 2 float array
Centroids of triangulation of xy
- NLNP x NN int array
Neighbor list (of centroids of triangulation of xy)
- KLNP x NN int array
Connectivity list (of centroids of triangulation of xy)
- BLNbonds x 2 int array
Bond list (of centroids of triangulation of xy)
- BMNP 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
- xyNP x 2 float array
xy points from which to find centroids, so xy are in the triangular representation
- LLtuple 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.
- checkbool
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
- xyNP x 2 float array
Particle positions
- LLtuple of 2 floats
Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.
- BBox4 x 2 float array or ‘auto’
The bounding box to use as the periodic boundary box
- checkbool
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_lengthfloat
cut bonds longer than this value
- zmethodstring (‘random’ ‘highest’)
Whether to cut randomly or cut bonds from nodes with highest z
- minimum_bonds: int
If >0, remove pts with fewer bonds
- distfloat
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
- xyNP x 2 float array
Particle positions
- LLtuple of 2 floats
Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.
- distfloat
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
- xyNP x 2 float array
xy points with buffer points, so xy are in the triangular representation
- LLtuple 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.
- checkbool
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
- xyNP x 2 float array
Particle positions
- LLtuple of 2 floats
Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.
- BBox4 x 2 float array or ‘auto’
The bounding box to use as the periodic boundary box
- checkbool
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_lengthfloat
cut bonds longer than this value
- zmethodstring (‘random’ ‘highest’)
Whether to cut randomly or cut bonds from nodes with highest z
- minimum_bonds: int
If >0, remove pts with fewer bonds
- distfloat
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
- xyNP x 2 float array
xy points from which to find centroids, so xy are in the triangular representation
- LLtuple 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.
- checkbool
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
- xyNP x 2 float array
Particle positions
- PV2 x 2 float array
Periodic vectors: the first has x and y components, the second has only positive y component.
- distfloat
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
- xyNP 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
- PV2 x 2 float array
Periodic vectors: the first has x and y components, the second has only positive y component.
- BBox4 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!
- checkbool
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
- xyNP x 2 float array
Particle positions
- LLtuple of 2 floats
Horizontal and vertical extent of the bounding box (a rectangle) through which there are periodic boundaries.
- distfloat
maximum depth of the buffer on each side
- Returns
- xyout :
- PBCmapdict 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
- TRIarray 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
- NLNP x NN int array
Neighbor list
- KLNP x NN int array
Connectivity list
- BLNbonds x 2 int array
Bond list
- BMNP 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
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- bsarray of dimension #bonds x 1
Strain in each bond
- climvfloat or tuple
Color limit for coloring bonds by bs
- Returns
- line_segmentsmatplotlib.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={}, nljnnn=None, kljnnn=None, klknnn=None, ax=None, fig=None, axcb='auto', cbar_ax=None, cbar_orientation='vertical', 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, cax_label='Strain', zorder=0, rasterized=False)[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
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points
- bsarray of dimension #bonds x 1 or None
Strain in each bond
- fnamestring
Full path including name of the file (.png, etc), if None, will not save figure
- titlestring
The title of the frame
- NLNP x NN int array (optional, for speed)
Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions
- KLNP x NN int array (optional, for speed)
Specify to speed up computation, if colorz or colorpoly or if periodic boundary conditions
- BLNNN :
- NLNNN :
- KLNNN :
- PVxNP 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.
- PVyNP 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.
- PVxydictdict (optional, for periodic lattices)
dictionary of periodic bonds (keys) to periodic vectors (values)
- nljnnn#pts x max(#NNN) int array or None
nearest neighbor array matching NLNNN and KLNNN. nljnnn[i, j] gives the neighbor of i such that NLNNN[i, j] is the next nearest neighbor of i through the particle nljnnn[i, j]
- kljnnn#pts x max(#NNN) int array or None
bond array describing periodicity of bonds matching NLNNN and KLNNN. kljnnn[i, j] describes the bond type (bulk -> +1, periodic –> -1) of bond connecting i to nljnnn[i, j]
- klknnn#pts x max(#NNN) int array or None
bond array describing periodicity of bonds matching NLNNN and KLNNN. klknnn[i, j] describes the bond type (bulk -> +1, periodic –> -1) of bond connecting nljnnn[i, j] to NLNNN[i, j]
- 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
- cbar_axaxis instance
Axis to use for colorbar. If colorbar instance is not already defined, use axcb instead.
- cbar_orientationstr (‘horizontal’ or ‘vertical’)
Orientation of the colorbar
- xlimv: float or tuple of floats
- ylimv: float or tuple of floats
- climvfloat 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)
- figsizetuple
w,h tuple in inches
- colorpolybool
Whether to color in polygons formed by bonds according to the number of sides
- bondcolorcolor specification (hexadecimal or RGB)
- colormapif bondcolor is None, uses bs array to color bonds
- bgcolorhex format string, rgb color spec, or None
If not None, sets the bgcolor. Often used is ‘#d9d9d9’
- axis_offbool
Turn off the axis border and canvas
- axis_equalbool
- text_topleftstr or None
- 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
- negative_NNN_arrowsbool
make positive and negative NNN hoppings different color
- showbool
whether to show the plot after creating it
- arrow_alphafloat
opacity of the arrow
- fontsizeint (default=8)
fontsize for all labels
- cax_labelint (default=’Strain’)
Label for the colorbar
- zorderint
z placement on axis (higher means bringing network to the front, lower is to the back
- 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, check=False)[source]¶ Plots and displays a 2D image of the lattice with colored bonds.
- Parameters
- xyarray of dimension nx2
2D lattice of points (positions x,y)
- BLarray of dimension #bonds x 2
Each row is a bond and contains indices of connected points. Negative values denote periodic BCs
- bsarray of dimension #bonds x 1 (like np.shape(BL[:, 0])
Strain in each bond
- fnamestring
Full path including name of the file (.png, etc)
- titlestring
The title of the frame
- climvfloat or tuple
Color limit for coloring bonds by bs
- colorzbool
Whether to color the particles by their coordination number
- closebool
Whether or not to leave the plot hanging to force it to be closed
- colorpolybool
Whether to color polygons by the number of edges
- BLNNNNP x NNNN int array
Bond list for next nearest neighbor couplings.
- Returns
- axmatplotlib axis instance or None
If close==True, returns None. Otherwise returns the axis with the network plotted on it.