Elastic Class
- class Elastic(graph, dim=2, params={'dashpot': 10.0, 'drag': 0.005, 'rfac': 0.05, 'stiffness': 1.0})
Bases:
objectClass to simulate an elastic network with trainable bonds and rest lengths.
- Parameters:
graph (str or networkx.graph) – If string, filename of saved graph specifying the nodes and edge connections of the elastic network. If networkx.graph object, the graph to use.
dim (int) – The dimensionality of the system. Valid options are 2 and 3.
params (dict, optional) –
Specifies system parameters. Required keywords are :
’rfac’: factor of shortest edge length that should correspond to node radius (used for plotting)
’drag’: coefficient of isotropic drag
’dashpot’: coefficient of dashpot damping at each edge
’stiffness’: initial stiffness assigned to each edge spring
- Variables:
graph (networkx.graph) – Graph specifying the nodes and edges in the network. A stiffness, rest length, and “trainable” parameter are associated with each edge. A trainable edge will be updated during training.
dim (int) – The dimensionality of the system. Valid options are 2 and 3.
n (int) – Number of nodes in the network.
ne (int) – Number of edges in the network.
pts (ndarray) – position coordinates for each node in the system.
vel (ndarray) – velocities for each node in the system.
degree (ndarray) – The degree (number of neighbors) of each node.
Z (float) – The average coordination number, defined as 2*ne/nc, where nc is the number of nodes in the biggest connected component of the system.
dZ (float) – The excess coordination, defined as Z - Ziso, where Ziso is the average coordination required for isostaticity.
traj (ndarray) – The simulated trajectory of the network produced after a call to the solve() routine.
vtraj (ndarray) – The simulated set of velocities produced after a call to the solve() routine.
t_eval (ndarray) – The corresponding time at each simulated frame.
- compute_modes()
Compute the normal modes of the elastic network at equilibrium.
- Returns:
evals (ndarray) – Eigenvalues.
evecs (ndarray) – Unit eigenvectors stored in each column.
- energy(t, q, *args)
Compute the energy of the spring network.
- Parameters:
t (float) – The current time.
q (ndarray) – The degrees of freedom.
args (tuple) –
Collection of simulation arguments :
T: Period for oscillatory force. If T = 0, nodes with an applied force are held stationary.
fix: Boolean indicating which degrees of freedom are held fixed.
network: Network edge properties obtained from _edge_lists().
applied_args: Simulation arguments, which can vary by problem.
train: The type of training to perform.
method: Used only if train is nonzero. Specifies the type of learning rule to use. Default is ‘learning’.
eta: Nudge factor by which to increment applied strain towards the target. Default is 1, which corresponds to pinning directly at the target.
alpha: Learning rate of each learning degree of freedom (stiffnesses or rest lengths). Default is 1e-3.
vmin: The smallest allowed value for each learning degree of freedom.
vsmooth: The value of each learning degree of freedom at which to begin smooth ramp down to vmin.
symmetric: Whether to train symmetrically with an additional free and clamped state.
pbar: Whether to display a progress bar. Default is True.
- Returns:
Total energy of the network.
- Return type:
- mean_square_displacement(nodes=None)
Compute the mean square displacement of the nodes over time.
This routine first removes rigid rotations and translations relative to the first frame, then finds the mean square displacement for each particle over time, and then averages over all particles.
- plot_network(ax)
Plot the network.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to plot.
- reset_equilibrium()
Set the current network state to its equilibrium state.
- reset_init()
Reset the network to its initial, relaxed state.
- reset_view()
Reset the 3D view orientation.
- rigid_correction()
Find the nearest Procrustes transformation (translation + rotation) to the first frame.
- Returns:
The particles’ trajectories corrected for rigid translation and rotation.
- Return type:
ndarray
- rotate_view(R)
Redefine the perspective for 3D visualization.
- Parameters:
R (float or ndarray) – If float, rotation angle about z-axis in radians. If ndarray, a 3D rotation matrix.
- save(filename)
Save the network to a file.
- Parameters:
filename (str) – The name of the text file to write.
- set_axes(ax)
Set up axis limits based on extent of network.
- Parameters:
ax (matplotlib.axes.Axes) – The axes to set up.
- set_frame(fr)
Select a specific simulation frame as the network state.
- Parameters:
fr (int) – The frame number.
- solve(duration, frames, T, applied_args, train=0, method='learning', eta=1.0, alpha=0.001, vmin=0.001, vsmooth=None, fix=0, symmetric=False, pbar=True, integrator='LSODA', rtol=1e-06, atol=1e-08)
Numerically integrate the elastic network in time.
This routine optionally trains edge stiffnesses or rest lengths using directed aging or coupled learning. Upon completion, an output trajectory of frames+1 snapshots is stored in the attribute ‘traj’, and corresponding times in ‘t_eval’.
- Parameters:
duration (float) – The final integration time.
frames (int or ndarray) – If integer, the number of evenly-spaced output frames to produce (excluding initial frame). If array, the time points at which to output snapshots.
T (float) – Period for oscillatory force. If T = 0, nodes with an applied force are held stationary.
applied_args (tuple) – Simulation arguments, which can vary by problem.
train (int, optional) – The type of training to perform. If train = 0 (default), no training is done. If train = 1, train lengths using method ‘aging’ or ‘learning’. If train = 2, train stiffnesses using method ‘aging’ or ‘learning’. If train = 3, train both.
method (str, optional, 'aging' or 'learning') – Used only if train is nonzero. Specifies the type of training approach to use. Default is ‘learning’.
eta (float, optional) – Nudge factor by which to increment applied strain towards the target. Default is 1, which corresponds to pinning directly at the target.
alpha (float or ndarray, optional) – Learning rate of each learning degree of freedom (stiffnesses or rest lengths). Default is 1e-3. If reported as an ndarray of 2 entries, provides the alpha for rest lengths, then stiffnesses.
vmin (float or ndarray, optional) – The smallest allowed value for each learning degree of freedom. Default is 1e-3. If reported as an ndarray of 2 entries, provides the vmin for rest lengths, then stiffnesses.
vsmooth (float or ndarray, optional) – The value of the learning degree of freedom at which to begin smooth ramping to vmin. If reported as an ndarray of 2 entries, provides the vsmooth for rest lengths, then stiffnesses.
fix (ndarray, optional) – An (n,3) array indicating which degrees of freedom should remain fixed and not integrated. If default (0), all degrees of freedom are integrated.
symmetric (bool, optional) – Whether to introduce a symmetric state for training with a different set of boundary conditions. Default is False.
pbar (bool, optional) – Whether to display a progress bar. Default is True.
integrator (str, optional) – Type of integrator to use, as available for scipy.integrate.solve_ivp. Default is ‘LSODA’.
rtol (float, optional) – The relative and absolute error tolerance for the integrator, respectively. Default values are 1e-6 and 1e-8.
atol (float, optional) – The relative and absolute error tolerance for the integrator, respectively. Default values are 1e-6 and 1e-8.
- Returns:
The scipy.integrate.solve_ivp return object, only for diagnostic purposes; the solution is internally parsed.
- Return type: