SimulationBarostatFrequencyProfile¶
Included in QATK.Dynamics
- class SimulationBarostatFrequencyProfile(initial_value, initial_gradient=None, update_frequency=None, total_steps=None)¶
Class for setting the pressure coupling frequency in NPT molecular dynamics. Setting the coupling frequency to 0 turns off pressure coupling, changing the simulation to NVT. The coupling frequency, when applied, is always rounded to the nearest integer value.
Note that values added to this profile must be a PhysicalQuantity of type Unitless rather than an integer or float.
- Parameters:
initial_value (float) – The initial value of the coupling frequency at step 0.
initial_gradient (float | None) – The initial gradient of the coupling frequency. if None is given the gradient is assumed to be zero. The gradient is in terms of change of the coupling frequency over the fraction of the simulation.
update_frequency (int | None) – The step frequency with which the barostat frequency 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 (float) – The value of the quantity at the given fraction.
gradient (float | 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:
float
Usage Examples¶
Perform a dynamics simulation of nylon-6. Switch the ensemble from NVT to NPT halfway through the simulation by setting the barostat frequency from 0 to 25.
# Set the barostat frequency profile to turn on NPT halfway through the simulation.
frequency_profile = SimulationBarostatFrequencyProfile(
initial_value=0,
initial_gradient=0
)
frequency_profile.addQuantityValue(0.5, 25, gradient=0)
# Run the simulation
simulation.simulate(
100000, hook_functions=[measurement], profiles=[frequency_profile]
)
equilibrated_nylon_6.hdf5
barostat_frequency_profile_example.py
Notes¶
The SimulationBarostatFrequencyProfile adds a profile that controls the sampling frequency of the Monte
Carlo barostat. One use of this kind of profile is to switch the barostat from a normal sampling frequency to zero.
Setting the barostat sampling frequency to zero turns off the barostat, returning the system to NVT. This works as
the Monte Carlo barostat is implemented separately from the thermostat, and does not modify the thermostat equations
of motion. The profile is implemented so that the barostat frequency can be constantly updated during the simulation.
Profiles work by taking both the value, and optionally the gradient of the barostat frequency at different points.
These can then be used to construct a piecewise linear function of the sampling frequency during the simulation. As the barostat
frequency is a whole number, values are rounded when applied to the barostat.
When specifying barostat frequencies 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 barostat frequency and optionally barostat frequency 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 barostat frequency at that point
and optionally a gradient in the barostat frequency from that point. If the value from the last segment does not
match the new barostat frequency the barostat frequency 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 barostat frequency. 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.