SimulationPressureProfile

Included in QATK.Dynamics

class SimulationPressureProfile(initial_value, initial_gradient=None, update_frequency=None, total_steps=None)

Class for creating a profile of pressure values for use during a dynamics simulation.

Parameters:
  • initial_value (PhysicalQuantity of type pressure) – The initial value of the pressure at step 0.

  • initial_gradient (PhysicalQuantity of type pressure | None) – The initial gradient of the pressure. if None is given the gradient is assumed to be zero. The gradient is in terms of change of the pressure over the fraction of the simulation.

  • update_frequency (int | None) – The step frequency with which the pressure is updated during the simulation.

  • total_steps (int | None) – The total number of steps in the simulation. This allows the conversion from fraction of simulation to step number. If None is given it must be set later before use.

addQuantityValue(fraction, value, gradient=None)

Add a new value of the quantity at the given fraction of the simulation.

Parameters:
  • fraction (float) – The fraction of the simulation at which the quantity value is defined. Must be between 0 and 1.

  • value (PhysicalQuantity) – The value of the quantity at the given fraction.

  • gradient (PhysicalQuantity | None) – The gradient of the quantity at the given fraction. If None is given the gradient is assumed to be zero. The gradient is in terms of change of the quantity over the fraction of the simulation.

setTotalSteps(total_steps)

Set the total number of steps in the simulation.

Parameters:

total_steps (int) – The total number of steps in the simulation.

setUpdateFrequency(frequency)

Set the frequency, in number of steps, the quantity from the profile is used to update the simulation.

Parameters:

frequency (int) – The number of steps between quantity updates.

setValueFunction(function)

Set a custom function for calculating the value of the quantity at a given step in the simulation. The function takes in the fraction of the simulation performed, which ranges from 0 to 1, and returns the value corresponding to that fraction.

An example use of this might be to set a function might be to sinusoidally vary a parameter during the simulations.

Parameters:

function (function | None) – A function that takes in a float between 0 and 1, and returns a PhysicalQuantity. None restores the default linear interpolation function.

totalSteps()
Returns:

The total number of steps in the simulation, if set.

Return type:

int | None

uniqueString()

Return a unique string representing the state of the object.

updateFrequency()
Returns:

The step frequency with which the quantity is updated during the simulation.

Return type:

int

value(step)

Get the value of the quantity at the given step in the simulation.

Parameters:

step (int) – The step in the simulation for which the quantity value is requested.

Returns:

The value of the quantity at the given step.

Return type:

PhysicalQuantity

Usage Examples

Change the pressure in a simulation of poly(methyl acrylate) from 0 MPa to 100 MPa. Pressure is raised first by 20 MPa over 10 ps, and then the system is allowed to equilibrate over the next 10 ps.

# Set the pressure profile
pressure_profile = SimulationPressureProfile(
    initial_value=0*MPa,
    initial_gradient=200*MPa
)
pressure_profile.addQuantityValue(0.1, 20*MPa, gradient=0*MPa)
pressure_profile.addQuantityValue(0.2, 20*MPa, gradient=200*MPa)
pressure_profile.addQuantityValue(0.3, 40*MPa, gradient=0*MPa)
pressure_profile.addQuantityValue(0.4, 40*MPa, gradient=200*MPa)
pressure_profile.addQuantityValue(0.5, 60*MPa, gradient=0*MPa)
pressure_profile.addQuantityValue(0.6, 60*MPa, gradient=200*MPa)
pressure_profile.addQuantityValue(0.7, 80*MPa, gradient=0*MPa)
pressure_profile.addQuantityValue(0.8, 80*MPa, gradient=200*MPa)
pressure_profile.addQuantityValue(0.9, 100*MPa, gradient=0*MPa)

# Run the simulation
simulation.simulate(100000, hook_functions=[measurement], profiles=[pressure_profile])

equilibrated_pma.hdf5 pressure_profile_example.py

Notes

The SimulationPressureProfile adds a pressure profile to a soft matter dynamics simulation. The profile is implemented so that the pressure can be constantly updated during the simulation. Profiles work by taking both the value, and optionally the gradient of the pressure at different points. These can then be used to construct a piecewise linear function of the pressure during the simulation. This can be used to implement a number of simulation protocols, such as compression or equilibration protocols.

When specifying pressures and gradients, everything is specified with reference to the fraction of the simulation completed. In this the profile is both independent of the number of steps in the simulation and also the time step. Gradients are likewise given as the instantaneous rate of change over the whole simulation.

Profiles are created by giving an initial pressure and optionally pressure gradient. Gradients are optional, and when not specified are assumed to be zero. Additional points on the profile are added with the addQuantityValue method. This takes the fraction of the simulation progress, the pressure at that point and optionally a gradient in the pressure from that point. If the value from the last segment does not match the new pressure the pressure profile is discontinuous.

It is also possible to define a profile using a user-defined function. In this way profiles such as sinusoidal or other shapes can be easily implemented. The function is given with the setValueFunction method. This function should take as an argument the fraction of the simulation and return a pressure. Custom functions are not saved as part of the profile when it is written with nlsave, and thus must be re-set if a profile is used from a file.