# Load the configuration
configuration = nlread("equilibrated_ps.hdf5")[0]

# Create and set the calculator
builder = OPLSPotentialBuilder()
calculator = SoftMatterCalculator(
    builder, use_lennard_jones_pme=True, assign_atom_types=True
)
configuration.setCalculator(calculator)

# Set the simulation
atomic_constraints = [FixCenterOfMass()]
method = NPTAndersenMonteCarlo(
    initial_velocity=ConfigurationVelocities(),
    pressure_coupling=[True, True, False]
)
simulation = SoftMatterDynamicsSimulation(
    configuration, method, atomic_constraints=atomic_constraints
)
simulation.setLogging(1000)
simulation.setTrajectory(1000, "ps_trajectory.hdf5")

# Measure the stress and strain during the simulation
measurement = SoftMatterDynamicsMeasurements(
    strain=["xx", "yy", "zz"], stress=["zz"], call_interval=100
)

# Set the cell length profile to implement a strain of 0.02
initial_length = configuration.primitiveVectors().norm(axis=1)[2]
length_profile = SimulationCellLengthProfile(
    "zz",
    initial_value=initial_length,
    initial_gradient=0.02*initial_length
)

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