Git Product home page Git Product logo

bgflow's Introduction

bgflow

Language grade: Python

Bgflow is a pytorch framework for Boltzmann Generators (BG) and other sampling methods.

Boltzmann Generators use neural networks to learn a coordinate transformation of the complex configurational equilibrium distribution to a distribution that can be easily sampled. Accurate computation of free-energy differences and discovery of new configurations are demonstrated, providing a statistical mechanics tool that can avoid rare events during sampling without prior knowledge of reaction coordinates. -- Noe et al. (2019)

This framework provides:


This library is alpha software under active development. Certain elements of its API are going to change in the future and some current implementations may not be tested.

If you are interested in contributing to the library, please feel free to open a pull request or report an issue.

When using bgflow in your research, please cite our preprint (coming soon).


Implementation of a BG with a single Real NVP coupling block as the invertible transformation. The two-dimensional target potential is given by a double well potential in one dimension and a harmonic potential in the other. The prior distribution is a two-dimensional standard normal distribution. Note that the training procedure is not included in this example.

import torch
import matplotlib.pyplot as plt
import bgflow as bg

# define prior and target
dim = 2
prior = bg.NormalDistribution(dim)
target = bg.DoubleWellEnergy(dim)

# here we aggregate all layers of the flow
layers = []
layers.append(bg.SplitFlow(dim // 2))
layers.append(bg.CouplingFlow(
        # we use a affine transformation to transform 
        # the RHS conditioned on the LHS
        bg.AffineTransformer(
            # use simple dense nets for the affine shift/scale
            shift_transformation=bg.DenseNet(
                [dim // 2, 4, dim // 2], 
                activation=torch.nn.ReLU()
            ), 
            scale_transformation=bg.DenseNet(
                [dim // 2, 4, dim // 2], 
                activation=torch.nn.Tanh()
            )
        )
))
layers.append(bg.InverseFlow(bg.SplitFlow(dim // 2)))
    
# now define the flow as a sequence of all operations stored in layers
flow = bg.SequentialFlow(layers)

# The BG is defined by a prior, target and a flow
generator = bg.BoltzmannGenerator(prior, flow, target)

# sample from the BG
samples = generator.sample(1000)
plt.hist2d(
    samples[:, 0].detach().numpy(), 
    samples[:, 1].detach().numpy(), bins=100
)


  • Clone this repository from github
  • Navigate to the cloned repository
  • Run the installation scrip
python setup.py install
  • Install all required dependencies
  • Validate your installation by running all tests in the repository with the command
pytest
  • Depending on the optional installations some tests might be skipped.

  • Mandatory
  • Optional
    • matplotlib
    • pytest (for testing)
    • nflows (for Neural Spline Flows)
    • torchdiffeq (for neural ODEs)
    • ANODE (for neural ODEs)
    • OpenMM (for molecular mechanics energies)
    • ase (for quantum and molecular mechanics energies through the atomic simulation environment)
    • xtb-python (for semi-empirical GFN quantum energies)
    • netCDF4 (for the ReplayBufferReporter)
    • jax (for smooth flows / implicit backprop)
    • jax2torch (for smooth flows / implicit backprop)
    • allegro (for Graph Neural Networks)
    • nequip (for Graph Neural Networks)
    • bgmol (for some example notebooks)

MIT License

bgflow's People

Contributors

olllom avatar jonkhler avatar leonklein avatar franknoe avatar invemichele avatar dibakma avatar lgtm-com[bot] avatar meyerml avatar

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.