Skip to content

Commit

Permalink
Merge pull request #11 from chrisiacovella/update_neighboring
Browse files Browse the repository at this point in the history
Update neighboring class output, additional input checking, more tests, simple LJ Langevin example system.
  • Loading branch information
chrisiacovella authored Dec 28, 2023
2 parents 2133efc + 20f8c9a commit 58db5df
Show file tree
Hide file tree
Showing 6 changed files with 240 additions and 99 deletions.
2 changes: 0 additions & 2 deletions Examples/LJ_langevin.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@
nbr_list = NeighborListNsqrd(
OrthogonalPeriodicSpace(), cutoff=cutoff, skin=skin, n_max_neighbors=180
)
from chiron.neighbors import PairList


# build the neighbor list from the sampler state
nbr_list.build_from_state(sampler_state)
Expand Down
25 changes: 22 additions & 3 deletions chiron/integrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@


class LangevinIntegrator:
"""
Langevin dynamics integrator for molecular dynamics simulation using the BAOAB splitting scheme [1].
References:
[1] Benedict Leimkuhler, Charles Matthews;
Robust and efficient configurational molecular sampling via Langevin dynamics.
J. Chem. Phys. 7 May 2013; 138 (17): 174102. https://doi.org/10.1063/1.4802990
"""

def __init__(
self,
stepsize=1.0 * unit.femtoseconds,
Expand All @@ -25,21 +36,28 @@ def __init__(
Parameters
----------
stepsize : unit.Quantity, optional
Time step size for the integration.
Time step of integration with units of time. Default is 1.0 * unit.femtoseconds.
collision_rate : unit.Quantity, optional
Collision rate for the Langevin dynamics.
Collision rate for the Langevin dynamics, with units 1/time. Default is 1.0 / unit.picoseconds.
save_frequency : int, optional
Frequency of saving the simulation data. Default is 100.
reporter : SimulationReporter, optional
Reporter object for saving the simulation data. Default is None.
"""

self.kB = unit.BOLTZMANN_CONSTANT_kB * unit.AVOGADRO_CONSTANT_NA
log.info(f"stepsize = {stepsize}")
log.info(f"collision_rate = {collision_rate}")
log.info(f"save_frequency = {save_frequency}")

self.stepsize = stepsize
self.collision_rate = collision_rate
if reporter is not None:
log.info(f"Using reporter {reporter} saving to {reporter.filename}")
self.reporter = reporter
self.save_frequency = save_frequency

self.velocities = None
def set_velocities(self, vel: unit.Quantity) -> None:
"""
Set the initial velocities for the Langevin Integrator.
Expand Down Expand Up @@ -73,6 +91,8 @@ def run(
Number of simulation steps to perform.
key : jax.random.PRNGKey, optional
Random key for generating random numbers.
nbr_list : NeighborListNsqrd, optional
Neighbor list for the system.
progress_bar : bool, optional
Flag indicating whether to display a progress bar during integration.
Expand All @@ -85,7 +105,6 @@ def run(

self.box_vectors = sampler_state.box_vectors
self.progress_bar = progress_bar
self.velocities = None
temperature = thermodynamic_state.temperature
x0 = sampler_state.x0

Expand Down
5 changes: 5 additions & 0 deletions chiron/mcmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@ def apply(
log.debug(f"Initial positions are {initial_positions} nm.")
# Propose perturbed positions. Modifying the reference changes the sampler state.
proposed_positions = self._propose_positions(initial_positions)

log.debug(f"Proposed positions are {proposed_positions} nm.")
# Compute the energy of the proposed positions.
if atom_subset is None:
Expand All @@ -420,6 +421,10 @@ def apply(
sampler_state.x0 = sampler_state.x0.at[jnp.array(atom_subset)].set(
proposed_positions
)
if nbr_list is not None:
if nbr_list.check(sampler_state.x0):
nbr_list.build(sampler_state.x0, sampler_state.box_vectors)

proposed_energy = thermodynamic_state.get_reduced_potential(
sampler_state, nbr_list
) # NOTE: in kT
Expand Down
Loading

0 comments on commit 58db5df

Please sign in to comment.