2 @brief Support for the JAX Python library.
4 IMP currently has rudimentary support for running on a graphics
5 processing unit (GPU) or similar systems such as
6 Tensor Processing Units (TPUs). This support uses the
7 [JAX](https://docs.jax.dev/) Python library.
10 import jax.numpy
as jnp
14 """The space in which restraints are evaluated. See FreeSpace for the
15 default unbounded space, or PeriodicSpace for a space that implements
16 periodic boundary conditions."""
19 """If given an array of particle-particle vectors, return an array
20 of distances. If given a single particle-particle vector, return
25 """Shift r by dr and return new r"""
29 """Modify r[indexes] in place by adding dr"""
33 class FreeSpace(Space):
34 """An unbounded space with no periodic boundary conditions."""
38 return jnp.linalg.norm(dr, axis=-1)
46 return r.at[indexes].add(dr)
50 """A space with periodic boundary conditions.
52 @param side A 3D vector of the periodic boundary box dimensions.
55 def __init__(self, side):
56 self.side = jnp.asarray(side)
59 p_dr = jnp.mod(dr + self.side * 0.5, self.side) - 0.5 * self.side
60 return jnp.linalg.norm(p_dr, axis=-1)
62 def shift(self, r, dr):
63 return jnp.mod(r + dr, self.side)
66 newr = jnp.mod(r[indexes] + dr, self.side)
67 return r.at[indexes].set(newr)
def shift_indexes
Modify r[indexes] in place by adding dr.
A space with periodic boundary conditions.
The space in which restraints are evaluated.
def shift
Shift r by dr and return new r.
def distance
If given an array of particle-particle vectors, return an array of distances.