Git Product home page Git Product logo

Comments (2)

cpgoodri avatar cpgoodri commented on April 28, 2024

Have you tried just using a customer shift function?

from jax-md.

sschoenholz avatar sschoenholz commented on April 28, 2024

Hey @Noahyt,

Sorry about the delay in response, we were busy getting ready for ICML. As @cpgoodri, it should be possible to do this without really modifying jax md. The basic premise is that we should use a new shift function that only moves a subset of the particles. By passing an explicit mask to the particles, it should be possible to adjust the frozen particles dynamically. One caveat is that this won't work with simulation environments that need to use the number of degrees of freedom as a parameter (for example, NVT simulations); if this use-case is important for you please let me know and I'll see what I can do!

In any case, here is schematically how I would write such a shift function,

displacement, shift = space.periodic(box_size)
def masked_shift(R, dR, is_mobile=None):
  if is_mobile is None:
    return shift(R, dR)
  return np.where(is_mobile[:, None], shift(R, dR), R)

Then this masked_shift function can be passed to minimizers. The is_mobile array can be passed as a keyword argument to the minimizer and it should just work.

fire_init, fire_apply = minimize.fire_descent(energy_fn, masked_shift)
fire_apply = jit(fire_apply)
fire_state = fire_init(R)

# Freeze all but the first 10 particles.
is_mobile = np.arange(N) > 10 
for i in range(steps):
  fire_state = fire_apply(fire_state, is_mobile=is_mobile)

Here is an example colab notebook that puts all of this together. Please let me know if this isn't what you had in mind or if you get stuck!

from jax-md.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.