### Configure Global ContextCache Platform Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Set the OpenMM platform for the global ContextCache before starting a simulation. This example configures it to use the 'Reference' platform and sets the time to live for cache entries. ```python reference_platform = openmm.Platform.getPlatformByName('Reference') cache.global_context_cache.platform = reference_platform cache.global_context_cache.time_to_live = 10 # number of read/write operations ``` -------------------------------- ### Install OpenMMTools Development Build Source: https://github.com/choderalab/openmmtools/blob/main/docs/installation.md Installs the bleeding-edge development build of OpenMMTools. Use with caution as these builds may be unstable. ```bash $ conda config --add channels omnia --add channels conda-forge $ conda install openmmtools-dev ``` -------------------------------- ### Install Miniconda on Linux Source: https://github.com/choderalab/openmmtools/blob/main/docs/installation.md Installs the Python 3 version of Miniconda on Linux systems. Ensure you have wget installed and are using a bash-compatible shell. ```bash $ wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh $ bash ./Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda3 $ export PATH="$HOME/miniconda3/bin:$PATH" ``` -------------------------------- ### Context Caching with MCMCMoves Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Illustrates using different ContextCache instances with MCMCMove objects. This example shows applying moves using a local CPU cache, a dummy cache that deactivates caching, and the global cache on the fastest available platform. ```python from openmmtools import mcmc from openmmtools import states from openmmtools.cache import ContextCache, DummyContextCache import openmm as mm import openmm.unit as unit # Assume system, integrator, context, and sampler_state are initialized # Example setup: # system = mm.System() # integrator = mm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 0.002*unit.picoseconds) # platform = mm.Platform.getPlatformByName('Reference') # context = mm.Context(system, integrator, platform) # sampler_state = states.SamplerState(context.getState(getPositions=True, getVelocities=True).getPositions(), # context.getState(getPositions=True, getVelocities=True).getVelocities()) # Define moves with different context caches # local_cpu_cache = ContextCache(platform='Reference') # mc_translation_move = mcmc.RigidBodyMCMove(molecule_indices, context_cache=local_cpu_cache) # mc_rotation_move = mcmc.RigidBodyMCMove(molecule_indices, context_cache=DummyContextCache()) # langevin_move = mcmc.LangevinIntegratorMove(integrator, nsteps=1000) # Combine moves in a sequence # move = mcmc.SequenceMove(mc_translation_move, mc_rotation_move, langevin_move) # move.apply(sampler_state, context) ``` -------------------------------- ### Install Miniconda on macOS Source: https://github.com/choderalab/openmmtools/blob/main/docs/installation.md Installs the Python 3 version of Miniconda on macOS systems. Note that the provided script is for Linux, but the intent is to use the macOS binary. ```bash $ wget https://repo.continuum.io/miniconda/Miniconda2-latest-MacOSX-x86_64.sh $ bash ./Miniconda3-latest-Linux-x86_64.sh -b -p $HOME/miniconda3 $ export PATH="$HOME/miniconda3/bin:$PATH" ``` -------------------------------- ### Combine Monte Carlo and Dynamics with SequenceMove Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Demonstrates combining different MCMCMove objects sequentially using SequenceMove. This example chains a rigid body Monte Carlo move with Langevin dynamics, including velocity randomization. ```python from openmmtools import mcmc from openmmtools import states import openmm as mm import openmm.unit as unit # Assume system, integrator, context, and sampler_state are initialized # Example setup: # system = mm.System() # integrator = mm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 0.002*unit.picoseconds) # platform = mm.Platform.getPlatformByName('Reference') # context = mm.Context(system, integrator, platform) # sampler_state = states.SamplerState(context.getState(getPositions=True, getVelocities=True).getPositions(), # context.getState(getPositions=True, getVelocities=True).getVelocities()) # Define individual moves # mc_rigid_move = mcmc.RigidBodyMCMove(molecule_indices, translation_acceptance_threshold=0.5, rotation_acceptance_threshold=0.5) # langevin_move = mcmc.LangevinIntegratorMove(integrator, nsteps=1000) # Combine moves in a sequence # move = mcmc.SequenceMove(mc_rigid_move, langevin_move) # move.apply(sampler_state, context) ``` -------------------------------- ### Define NVT Thermodynamic State Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Create a ThermodynamicState object to define ensemble parameters like temperature and pressure. This example sets up an NVT ensemble at 298 K for a water box. ```python from openmmtools.states import ThermodynamicState # Assuming 'system' is an OpenMM System object with box vectors temp_state = ThermodynamicState(system=system, temperature=298*unit.kelvin) ``` -------------------------------- ### Install OpenMMTools Release Build Source: https://github.com/choderalab/openmmtools/blob/main/docs/installation.md Installs the latest stable release of OpenMMTools using conda. This is recommended for most users. It automatically handles dependencies like OpenMM, numpy, and scipy. ```bash $ conda config --add channels omnia --add channels conda-forge $ conda install openmmtools ``` -------------------------------- ### ComposableState Controlling Global Parameter Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md Example of creating a composable state that controls a global parameter in a custom OpenMM force. This is useful for alchemically modifying potentials, such as softening torsions. ```python energy_function = "lambda_torsions * k*(1+cos(periodicity*theta-phase))" custom_force = openmm.CustomTorsionForce(energy_function) custom_force.addGlobalParameter('lambda_torsions', 1.0) # Other force configurations. system.addForce(custom_force) ``` -------------------------------- ### Update OpenMMTools Installation Source: https://github.com/choderalab/openmmtools/blob/main/docs/installation.md Updates an existing conda installation of OpenMMTools to the latest release version. ```bash $ conda update openmmtools ``` -------------------------------- ### Get Context from ContextCache Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Obtain an OpenMM Context and its associated Integrator using ContextCache.get_context(). The cache manages a pool of contexts to minimize GPU resource usage and creation overhead. ```python context, integrator = context_cache.get_context(system, integrator, thermodynamic_state) ``` -------------------------------- ### Define NPT Thermodynamic State Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Convert a ThermodynamicState to an NPT ensemble by setting the pressure attribute. The volume will fluctuate during simulation. This example sets the pressure to 1 atm. ```python from openmmtools.states import ThermodynamicState import openmm.unit as unit # Assuming 'system' is an OpenMM System object npt_state = ThermodynamicState(system=system, temperature=298*unit.kelvin, pressure=1.0*unit.atmosphere) ``` -------------------------------- ### Initialize Thermodynamic and Sampler States Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Create the initial thermodynamic and microscopic states for a simulation system, such as the AlanineDipeptideVacuum. ```python test = testsystems.AlanineDipeptideVacuum() thermodynamic_state = ThermodynamicState(system=test.system, temperature=298*unit.kelvin) sampler_state = SamplerState(positions=test.positions) ``` -------------------------------- ### Initialize MCMC Sampler with a Single Move Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Create an MCMC move (e.g., GHMCMove or LangevinDynamicsMove) and initialize the MCMCSampler with the thermodynamic state, sampler state, and the chosen move. ```python ghmc_move = GHMCMove(timestep=1.0*unit.femtosecond, n_steps=50) langevin_move = LangevinDynamicsMove(n_steps=10) sampler = MCMCSampler(thermodynamic_state, sampler_state, move=ghmc_move) ``` -------------------------------- ### Create TIP3P Water Box Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Creates a TIP3P water cubic box of 2nm side using PME for simulation. ```python from openmmtools import testsystems # Create a TIP3P water cubic box of 2nm side using PME system, positions, topology = testsystems.create_system(model='tip3p', box_edge=2.0*unit.nanometer, nonbonded_method=PME) ``` -------------------------------- ### Create Local ContextCache Instances Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Instantiate local ContextCache objects with specific capacities and time-to-live values, and assign them to moves. This allows for fine-grained control over context management. ```python local_cache1 = cache.ContextCache(capacity=5, time_to_live=50) local_cache2 = cache.ContextCache(platform=reference_platform, capacity=1) sequence_move = SequenceMove([HMCMove(), LangevinDynamicsMove()], context_cache=local_cache1) ghmc_move = GHMCMove(context_cache=local_cache2) ``` -------------------------------- ### Minimize and Run MCMC Simulation Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Perform energy minimization on the system and then run the MCMC sampler for a specified number of iterations. ```python sampler.minimize() sampler.run(n_iterations=2) ``` -------------------------------- ### Import necessary modules for MCMC Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Import ThermodynamicState and SamplerState from openmmtools.states, along with utility modules for testsystems and caching. ```python from simtk import unit from openmmtools import testsystems, cache from openmmtools.states import ThermodynamicState, SamplerState ``` -------------------------------- ### Prepare Alchemical System with AbsoluteAlchemicalFactory Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Use AbsoluteAlchemicalFactory to create an OpenMM System for alchemical manipulation, such as decoupling a molecule. This prepares the system in its interacting state. ```python factory = AbsoluteAlchemicalFactory() # Prepare an alchemical system for p-xylene in T4-lysozyme's binding pocket alchemical_system = factory.create_alchemical_system(system, molecule, binding_site_atoms) ``` -------------------------------- ### Tagging a new release Source: https://github.com/choderalab/openmmtools/wiki/Home Use this command to create a local git tag following semantic versioning after merging changes to the master branch. ```bash git tag -a vX.Y. ``` -------------------------------- ### CustomBondForce with Force Group Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md Demonstrates setting a force group for an OpenMM CustomBondForce. This is used in conjunction with the reduced_potential_at_states utility to optimize energy calculations by only recomputing energies for specified force groups. ```python force = openmm.CustomBondForce('(K/2)*(r-r0)^2;') force.setForceGroup(5) ``` -------------------------------- ### Create Thermodynamic State Protocol Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Utility function to efficiently initialize a list of ThermodynamicState or CompoundThermodynamicState objects. This is useful for setting up replica exchange simulations with varying temperatures. ```python from openmmtools import states # Example: Create 5 replicas with temperatures from 300K to 450K # n_replicas = 5 # temperatures = [300 + i * 10 for i in range(n_replicas)] * unit.kelvin # protocol = states.create_thermodynamic_state_protocol(temperatures) ``` -------------------------------- ### Apply MCMCMove to SamplerState Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Applies an MCMCMove to update the SamplerState, including configurational degrees of freedom like positions and velocities. This demonstrates basic system propagation. ```python from openmmtools import mcmc from openmmtools import states # Assume system, integrator, context, and sampler_state are already initialized # For example: # system = mm.System() # integrator = mm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 0.002*unit.picoseconds) # platform = mm.Platform.getPlatformByName('Reference') # context = mm.Context(system, integrator, platform) # context.setPositions(system.getDefaultPeriodicBoxVectors()) # sampler_state = states.SamplerState(context.getState(getPositions=True, getVelocities=True).getPositions(), # context.getState(getPositions=True, getVelocities=True).getVelocities()) # Example of applying a move (e.g., GHMC integration for 1000 steps) # move = mcmc.GHMCIntegratorMove(integrator, nsteps=1000) # move.apply(sampler_state, context) ``` -------------------------------- ### Configure Softcore Nonbonded Interactions Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Customize softcore parameters for electrostatic and steric interactions to control how they are modified during alchemical transformations. Consult API documentation for detailed parameter explanations. ```python # Example of configuring softcore parameters (specific parameters depend on factory configuration) alchemical_system.nonbonded_softcore_electrostatics = True alchemical_system.nonbonded_softcore_sterics = True ``` -------------------------------- ### Create OpenMM Context with ThermodynamicState Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Generate an OpenMM Context object that is guaranteed to be in the specified thermodynamic state. ThermodynamicState performs consistency checks, automatically adding components like AndersenThermostat if needed. ```python from openmmtools.states import ThermodynamicState from openmm import LangevinIntegrator # Assuming 'system' and 'integrator' are defined temp_state = ThermodynamicState(system=system, temperature=298*unit.kelvin) integrator = LangevinIntegrator(298*unit.kelvin, 1.0/unit.picosecond, 0.002*unit.picoseconds) context = temp_state.create_context(integrator) ``` -------------------------------- ### Standardize and Hash System for Compatibility Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md This method standardizes a system and generates a hash based on its XML serialization to ensure compatibility checks. ```python @classmethod def _standardize_and_hash(cls, system): """Standardize the system and return its hash.""" cls._standardize_system(system) system_serialization = openmm.XmlSerializer.serialize(system) return system_serialization.__hash__() ``` -------------------------------- ### Registering Langevin Integrator Step Methods Source: https://github.com/choderalab/openmmtools/blob/main/docs/releasehistory.md Use this method to register new LangevinIntegrator step methods, simplifying the process. Ensure the step string, callback function, and support for force groups are correctly provided. ```python self._register_step_method(step_string, callback_function, supports_force_groups=False) ``` -------------------------------- ### Pushing tags to remote Source: https://github.com/choderalab/openmmtools/wiki/Home Use this command to push the locally created tags to the remote repository. ```bash git push --tags ``` -------------------------------- ### Implement MCMCMove Apply Method Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md The `apply` method is the core of an `MCMCMove`. It must update `thermodynamic_state` and `sampler_state` correctly. Consider including a `context_cache` argument in the constructor for platform specification. ```python class MCMCMove(SubhookedABCMeta): def apply(self, thermodynamic_state, sampler_state): pass ``` -------------------------------- ### Create CompoundThermodynamicState Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Combine multiple composable states, such as ThermodynamicState and AlchemicalState, into a single CompoundThermodynamicState. This allows for manipulation of various thermodynamic and alchemical parameters simultaneously. ```python compound_state = states.CompoundThermodynamicState(thermodynamic_state, composable_states=[alchemical_state]) ``` -------------------------------- ### Combine Moves using WeightedMove Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Create a weighted set of moves using WeightedMove, allowing the sampler to randomly select one of the provided moves with a specified probability at each iteration. ```python weighted_move = WeightedMove([(ghmc_move, 0.5), (langevin_move, 0.5)]) sampler = MCMCSampler(thermodynamic_state, sampler_state, move=weighted_move) ``` -------------------------------- ### Force Context Creation on Specific Platform Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Specify the OpenMM platform (e.g., 'CUDA', 'OpenCL') on which contexts should be created by the cache. ```python context_cache.platform = openmm.Platform.getPlatformByName('CUDA') ``` -------------------------------- ### Apply Thermodynamic State to Context Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Use ThermodynamicState.apply_to_context() to modify simulation parameters like temperature and pressure within an existing OpenMM Context. This method abstracts away implementation details. ```python thermodynamic_state.apply_to_context(context) ``` -------------------------------- ### IComposableInterface Methods Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md Defines the interface for composable states, outlining methods for applying states to OpenMM systems and contexts, checking for consistency, and standardizing systems. The _find_force_groups_to_update method is optional and used for optimization. ```python class IComposableState: def apply_to_system(self, system): """Modify an OpenMM System to be in this thermodynamic state.""" def check_system_consistency(self, system): """Raise AlchemicalStateError if system has different parameters.""" def apply_to_context(self, context): """Modify an OpenMM Context to be in this thermodynamic state.""" def _standardize_system(cls, system): """Modify the System to be in the standard thermodynamic state.""" def _on_setattr(self, standard_system, attribute_name, old_attribute_value): """Callback that checks if standard system needs to be updated after a state attribute is set.""" def _find_force_groups_to_update(self, context, current_context_state, memo) """Find the force groups whose energy must be recomputed after apply_to_context.""" # Optional. This is used only for optimizations. ``` -------------------------------- ### Configure ContextCache Capacity and TTL Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Set the maximum number of contexts the cache can hold and a time-to-live (TTL) for contexts. The TTL is measured in the number of accesses. ```python context_cache.capacity = 1 context_cache.time_to_live = 1000 ``` -------------------------------- ### Find Forces in OpenMM System Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Provides a convenient way to search for particular force objects within an OpenMM System. ```python from openmmtools import forces from openmm import System # Assuming 'system' is an OpenMM System object # Example: Find all HarmonicBondForce objects harmonic_bonds = forces.find_forces(system, 'HarmonicBondForce') # Example: Find all NonbondedForce objects nonbonded_forces = forces.find_forces(system, 'NonbondedForce') ``` -------------------------------- ### Creating an Alchemical Water Box Source: https://github.com/choderalab/openmmtools/blob/main/docs/releasehistory.md The AlchemicalWaterBox class is a new addition to openmmtools.testsystems. It initializes a system where the first water molecule is alchemically modified. ```python AlchemicalWaterBox ``` -------------------------------- ### Combine Moves using SequenceMove Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Create a sequence of moves by combining multiple MCMC moves into a SequenceMove object, which executes them in a defined order. ```python sequence_move = SequenceMove([ghmc_move, langevin_move]) sampler = MCMCSampler(thermodynamic_state, sampler_state, move=sequence_move) ``` -------------------------------- ### Geodesic-BAOAB Langevin Integrator Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Implements the geodesic-BAOAB Langevin integrator with solute-solvent splitting, collecting statistics on dissipated heat and shadow work. ```python from openmmtools import integrators from openmm import unit # Geodesic-BAOAB Langevin integrator with solute-solvent splitting integrator = integrators.GeodesicBAOABIntegrator(temperature=300*unit.kelvin, collision_rate=1.0/unit.picosecond, splitting='solute-solvent', measure_shadow_work=True) ``` -------------------------------- ### Create T4-Lysozyme System with p-xylene Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Creates a T4-Lysozyme system in implicit OBC GBSA solvent bound to a p-xylene molecule. It also selects heavy atoms of p-xylene and surrounding residues. ```python from openmmtools import testsystems from openmm import unit # Create a T4-Lysozyme system in implicit OBC GBSA solvent bound to a p-xylene molecule system, positions, topology = testsystems.create_system(model='T4-lysozyme', solvent='OBC', explicit_water=False) # Select heavy atoms of p-xylene and few residues surrounding the binding site # Note: This requires MDTraj to be installed and is for illustrative purposes. # p_xylene_heavy_atoms = topology.select('resname "PYX" and heavyatom') # surrounding_residues = topology.select('resid 10 to 20 and heavyatom') # atom_indices = p_xylene_heavy_atoms + surrounding_residues ``` -------------------------------- ### Define Custom Integrator and Force with Serialization Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md Inherit from RestorableOpenMMObject to enable proper copying and serialization of custom OpenMM integrator and force classes, preserving Python interface. ```python class LangevinIntegrator(mmtools.utils.RestorableOpenMMObject, openmm.CustomIntegrator): pass class HarmonicRestraintForce(mmtools.utils.RestorableOpenMMObject, openmm.CustomCentroidBondForce): pass ``` -------------------------------- ### Control Alchemical Degrees of Freedom with AlchemicalState Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Manage alchemical degrees of freedom using AlchemicalState to control Hamiltonian parameters during simulation. The convention is lambda=1 for interacting and lambda=0 for non-interacting states. ```python alchemical_state = AlchemicalState(system=alchemical_system) # Turn off electrostatics and halve Lennard-Jones interactions alchemical_state.set_alchemical_parameter("lambda", 0.5) ``` -------------------------------- ### Testing Nonequilibrium Switching with BAR Source: https://github.com/choderalab/openmmtools/blob/main/docs/releasehistory.md This test uses BAR to evaluate the dragging of a harmonic oscillator with various integrator splittings. It ensures the correct implementation of nonequilibrium switching simulations. ```python run_nonequilibrium_switching() test now uses BAR to test dragging a harmonic oscillator and tests a variety of integrator splittings (["O { V R H R V } O", "O V R H R V O", "R V O H O V R", "H R V O V R H"]) ``` -------------------------------- ### Use DummyContextCache to Disable Caching Source: https://github.com/choderalab/openmmtools/blob/main/docs/mcmc.md Utilize DummyContextCache to prevent context caching, ensuring a new OpenMM Context is created for each operation. This can be useful for debugging or specific performance scenarios. ```python dummy_cache = cache.DummyContextCache(platform=reference_platform) ghmc_move = GHMCMove(context_cache=dummy_cache) ``` -------------------------------- ### LangevinIntegrator as MCMCMove with NaN Recovery Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Utilizes LangevinIntegrator as an MCMCMove, featuring automatic recovery from NaN errors by restoring the system state and retrying the propagation. It attempts recovery up to 5 times before raising an error, serializing simulation objects for debugging. ```python from openmmtools import mcmc from openmmtools import states import openmm as mm import openmm.unit as unit # Assume system, integrator, context, and sampler_state are initialized # Example setup: # system = mm.System() # integrator = mm.LangevinIntegrator(300*unit.kelvin, 1/unit.picosecond, 0.002*unit.picoseconds) # platform = mm.Platform.getPlatformByName('Reference') # context = mm.Context(system, integrator, platform) # sampler_state = states.SamplerState(context.getState(getPositions=True, getVelocities=True).getPositions(), # context.getState(getPositions=True, getVelocities=True).getVelocities()) # Instantiate the move with NaN recovery enabled (default behavior) # move = mcmc.LangevinIntegratorMove(integrator, nsteps=1000) # move.apply(sampler_state, context) # When a NaN occurs, the following files are created for debugging: # debug/langevin-system.xml # debug/langevin-integrator.xml # debug/langevin-state.xml ``` -------------------------------- ### Subclass BaseIntegratorMove for Custom Integrators Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md When an integrator modifies the thermodynamic state, subclass `BaseIntegratorMove`. Implement `_get_integrator` to return your custom integrator and optionally `_before_integration` and `_after_integration` for pre/post-simulation logic. Remember to update `thermodynamic_state` in `_after_integration`. ```python class MyMove(BaseIntegratorMove): def __init__(self, timestep, n_steps, **kwargs): super(MyMove, self).__init__(n_steps, **kwargs) self.timestep = timestep def _get_integrator(self, thermodynamic_state): return MyIntegrator(self.timestep, thermodynamic_state.temperature) def _before_integration(self, context, thermodynamic_state): # Optional: Any operation performed after the context # was created but before integration. def _after_integration(self, context, thermodynamic_state): # Update thermodynamic_state from context parameters. # Optional: Read statistics from context.getIntegrator() parameters. ``` -------------------------------- ### Soften Torsions, Angles, and Bonds Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Modify potential terms beyond nonbonded interactions, such as enabling torsion softening for all dihedrals in a molecule. AlchemicalState can control these terms similarly to nonbonded interactions. ```python # Example: Configure torsion softening for p-xylene dihedrals alchemical_system.torsion_softening = True ``` -------------------------------- ### Enslave Hamiltonian Degrees of Freedom to a Custom Function Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Use custom functions to control Hamiltonian degrees of freedom, such as turning off electrostatic and steric interactions sequentially as a variable like 'lambda' changes from 1.0 to 0.0. ```python from math import step_hm, step alchemical_state.set_alchemical_function("lambda", "step_hm(lambda - 0.5) * electrostatics + step(lambda - 0.5) * sterics") ``` -------------------------------- ### ThermostatedIntegrator Base Class Source: https://github.com/choderalab/openmmtools/blob/main/docs/devtutorial.md Use ThermostatedIntegrator as a base class for integrators coupled to a heat bath. It automatically includes RestorableOpenMMObject functionalities and requires getTemperature/setTemperature methods for ThermodynamicState compatibility. ```python from openmmtools.integrators import ThermostatedIntegrator # Inherit from ThermostatedIntegrator for heat bath coupled integrators class MyThermostatedIntegrator(ThermostatedIntegrator): # Implement getTemperature and setTemperature methods pass ``` -------------------------------- ### Replacing Reaction Field Electrostatics Source: https://github.com/choderalab/openmmtools/blob/main/docs/releasehistory.md Use AlchemicalFactory.replace_reaction_field() to modify fully-interacting systems. This method forces reaction-field electrostatics to remove the shift by setting c_rf = 0, recoding it as a CustomNonbondedForce. ```python AlchemicalFactory.replace_reaction_field() ``` -------------------------------- ### Add Harmonic Restraint Force Source: https://github.com/choderalab/openmmtools/blob/main/docs/gettingstarted.md Adds a harmonic potential between the centers of mass of heavy atoms of a p-xylene molecule and the binding site of T4-Lysozyme. ```python from openmmtools import testsystems, forces from openmm import unit # Create a T4-Lysozyme system in implicit OBC GBSA solvent bound to a p-xylene system, positions, topology = testsystems.create_system(model='T4-lysozyme', solvent='OBC', explicit_water=False) # Find atom indices for p-xylene heavy atoms and T4-Lysozyme binding site residues # (Assuming these selections are defined elsewhere or obtained via MDTraj) # p_xylene_heavy_atoms = ... # t4_lysozyme_binding_site = ... # Add a harmonic restraint between the two groups of atoms # forces.add_harmonic_restraint(system, topology, p_xylene_heavy_atoms, t4_lysozyme_binding_site, k=100*unit.kilojoule_per_mole/unit.nanometer**2) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.