Giter Club home page Giter Club logo

t_opt's Introduction

Pytorch Tensor Optimizer

This is a parallelized version of the lbfgs optimization algorithm for molecular conformations. A whole set of conformations can be optimized in parallel significantly reducing the time required for conformational searches.

This code was developed based on the lbfgs optimization algorithm as implemented in pytorch lbfgs.py. The intended use is for conformational searches using Nerual Net Potentials. An example interface to the ANI potential and a dummy implementation of a potential in pytorch is included.

This code is released under the MIT license.

Installation

To use this with the ANI Neural net Potential (NNP):

  • install ASE ANI and ensure that it runs correctly including the python interface (nerurochem package)

  • install the cdd_chem package

  • download(git clone) this source code

  • install it into your python environment: cd into thee root direcotry of this package

    pip install .
  • setup the environment as necessary. Note: ASE_ANI requires CUDA.

    export ASE_ANI_DIR=<your ASE_ANI_DIR>
    export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ASE_ANI_DIR/lib
    export PYTHONPATH=${PYTHONPATH}:$ASE_ANI_DIR/lib
  • run on a test case:

     sdfANIOptimizer.py -in data/C2H6.sdf -out C2H6.ani.sdf -conf $ANICONF -computeForce

    Note: a further explaination of the command line options is provided by executing sdfANIOptimizer.py with the -h option.

    To allow sdfANIOptimizer.py to optimize conformers in parallel on the GPU the input file needs to be grouped by atom count. (For ASE_ANI the input compounds also need to be grouped so that the sequence of atom type is identical). Every time a conformation with a different number of atom is encountered the optimization must wait for the previous batch to complete.

Use with other pytorch based NNP's

This requires the implementation of three wrapper classes:

  1. a pytorch module that extends from CoordinateModelInterface
  2. a NNPComputerFactoryInterface class
  3. a tiny command line wrapper like sdfANIMOptimizer

1. Pytorch module

This encapsulates an actual NNP implementation. The forward() method takes an argument of type SameSizeCoordsBatch that provides access to the information on the conformations to minimize:

  • n_confs: the number of conformations
  • n_atom_per_conf: the number of atoms per conformation (all conformations have the same number of atoms)
  • coords: the coordinates
  • atom_types: the atomic numbers of the atoms. note: the conformations may vary in the type of atoms.

A very simplified NNP that pulls all atoms to the coordinates (-0.703,-0.703, -0.703) is given below:

class DummyNet(CoordinateModelInterface):
    """
        A dummy pytoch module that computes a potential that pulls all atoms
        towards having coordinate = -0.703 
    """
    def __init__(self):
        super().__init__()
        
    def forward(self, same_size_coords_batch:SameSizeCoordsBatch):
        c = same_size_coords_batch.coords
        c = c*5
        e = c.pow(2) + c.exp()
        e = e.reshape(c.shape[0],-1).sum(-1)
        # min (y=(5x)^2 + e^(5x)) ~ y(-0.703) = 0.8272
        return e, e   # fake stdev with e, will not affect tests   

The g_ani package contains an implementation that uses its NNP implmentation.


2. The NNP Computer Factory

This Interface takes a string parameter and provides a factory for the NeuralNet Potential. The String parameter can be a directory name as used to point to the configuration directory for the ANI_computer, a filename or any other string that will be used to constuct your PyTorch Module.

An Example can be found in ExampleNNPComputerFactory (NNPComputerFactoryInterface).

Another example is in the g_ani package (NNP_computer_factory.py).


3. Wrapper for command line interface

To create a command line program that you can call to minimize conformations with your NNP you have to create a tiny wrapper that constructs the NNP Computer Factory and passes it to the sdf_multi_optimizer.

An Example can be found in SDFANIMOptimizer.

Acknowledgments

I would like to thank Justin S. Smith and Adrian Reutberg for making the ASE_ANI available and for help to set it up.

I would like to thanks Man-Ling Lee, the Genentech Incubator project and the Genentech Computational Chemistry group for allowing me to work on this.

References:

ASE_ANI

Original implementation of the lbfgs optimization algorithm in pytorch

License

###############################################################################
## The MIT License
##
## SPDX short identifier: MIT
##
## Copyright 2020 Genentech Inc. South San Francisco
##
## Permission is hereby granted, free of charge, to any person obtaining a
## copy of this software and associated documentation files (the "Software"),
## to deal in the Software without restriction, including without limitation
## the rights to use, copy, modify, merge, publish, distribute, sublicense,
## and/or sell copies of the Software, and to permit persons to whom the
## Software is furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
## DEALINGS IN THE SOFTWARE.
###############################################################################

t_opt's People

Contributors

bgobbi avatar smdi-gne 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.