# Load the configuration
configuration = nlread("equilibrated_nylon_6.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())
simulation = SoftMatterDynamicsSimulation(
    configuration, method, atomic_constraints=atomic_constraints
)
simulation.setLogging(1000)
simulation.setTrajectory(1000, "nylon_6_trajectory.hdf5")

# Measure the stress and strain during the simulation
measurement = SoftMatterDynamicsMeasurements(volume=True, call_interval=10)

# 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]
)
