{"id":22731063,"url":"https://github.com/genentech/t_opt","last_synced_at":"2025-09-04T04:21:34.918Z","repository":{"id":185772699,"uuid":"577963172","full_name":"Genentech/t_opt","owner":"Genentech","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-30T23:01:53.000Z","size":58,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"develop","last_synced_at":"2025-03-30T01:31:45.534Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Genentech.png","metadata":{"files":{"readme":"README.md","changelog":"HISTORY.md","contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2022-12-13T23:41:44.000Z","updated_at":"2023-06-22T17:02:05.000Z","dependencies_parsed_at":null,"dependency_job_id":"1554846a-8bc0-4ee6-9fa5-48e9d23830e0","html_url":"https://github.com/Genentech/t_opt","commit_stats":null,"previous_names":["genentech/t_opt"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Genentech/t_opt","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genentech%2Ft_opt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genentech%2Ft_opt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genentech%2Ft_opt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genentech%2Ft_opt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Genentech","download_url":"https://codeload.github.com/Genentech/t_opt/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Genentech%2Ft_opt/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273549816,"owners_count":25125374,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-04T02:00:08.968Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-10T19:19:18.687Z","updated_at":"2025-09-04T04:21:34.867Z","avatar_url":"https://github.com/Genentech.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Pytorch Tensor Optimizer\n\nThis 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.\n\nThis code was developed based on the lbfgs optimization algorithm as implemented in pytorch [lbfgs.py](https://pytorch.org/docs/stable/_modules/torch/optim/lbfgs.html).\nThe intended use is for conformational searches using Nerual Net Potentials. \nAn example interface to the [ANI](https://github.com/isayev/ASE_ANI) potential and \na dummy implementation of a potential in pytorch is included.\n\nThis code is released under the [MIT license](License.txt).\n\n\n## Installation\n\nTo use this with the ANI Neural net Potential (NNP):\n   - install [ASE ANI](https://github.com/isayev/ASE_ANI) and ensure that it runs \n     correctly including the python interface (nerurochem package)\n     \n   - install the [cdd_chem](../cdd_chem) package \n\n   - download(git clone) this source code\n\n   - install it into your python environment:\n     cd into thee root direcotry of this package\n     ```bash\n     pip install .\n     ```\n\n   - setup the environment as necessary. Note: ASE_ANI requires CUDA.\n     ```bash\n     export ASE_ANI_DIR=\u003cyour ASE_ANI_DIR\u003e\n     export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ASE_ANI_DIR/lib\n     export PYTHONPATH=${PYTHONPATH}:$ASE_ANI_DIR/lib\n     ```\n\n   - run on a test case:\n     ```bash\n      sdfANIOptimizer.py -in data/C2H6.sdf -out C2H6.ani.sdf -conf $ANICONF -computeForce\n     ```\n     Note: a further explaination of the command line options is provided by executing sdfANIOptimizer.py with the -h option.\n\n     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.\n\n\n## Use with other pytorch based NNP's\n\nThis requires the implementation of three wrapper classes:\n\n1. a pytorch [module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) that extends from [CoordinateModelInterface](t_opt/coordinates_batch.py)\n2. a [NNPComputerFactoryInterface](t_opt/NNP_computer_factory.py) class\n3. a tiny command line wrapper like [sdfANIMOptimizer](sdfANIMOptimizer.py)\n\n\n----------------\n##### 1. Pytorch module\nThis encapsulates an actual NNP implementation. The `forward()` method takes an argument of type  [SameSizeCoordsBatch](t_opt/coordinates_batch.py) that provides access to the information on the conformations to minimize:\n- n_confs: the number of conformations\n- n_atom_per_conf: the number of atoms per conformation (all conformations have the same number of atoms)\n- coords: the coordinates\n- atom_types: the atomic numbers of the atoms. note: the conformations may vary in the type of atoms.\n\nA very simplified NNP that pulls all atoms to the coordinates (-0.703,-0.703, -0.703) is given below:\n\n\n```\nclass DummyNet(CoordinateModelInterface):\n    \"\"\"\n        A dummy pytoch module that computes a potential that pulls all atoms\n        towards having coordinate = -0.703 \n    \"\"\"\n    def __init__(self):\n        super().__init__()\n        \n    def forward(self, same_size_coords_batch:SameSizeCoordsBatch):\n        c = same_size_coords_batch.coords\n        c = c*5\n        e = c.pow(2) + c.exp()\n        e = e.reshape(c.shape[0],-1).sum(-1)\n        # min (y=(5x)^2 + e^(5x)) ~ y(-0.703) = 0.8272\n        return e, e   # fake stdev with e, will not affect tests   \n```\n\nThe g_ani package contains an [implementation](https://github.com/Genentech/g_ani/blob/b2a1d638e38e8fe07e2b23a9abd5aebaa85bf5d0/ml_qm/pt/nn/ani_net.py#L277) that uses its NNP implmentation.\n\n------------------------\n##### 2. The NNP Computer Factory\n\nThis 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](t_opt.ANI_computer.py), a filename \nor any other string that will be used to constuct your PyTorch Module.\n\nAn Example can be found in ExampleNNPComputerFactory ([NNPComputerFactoryInterface](t_opt/NNP_computer_factory.py)).\n\nAnother example is in the g_ani package ([NNP_computer_factory.py](https://github.com/Genentech/g_ani/blob/b2a1d638e38e8fe07e2b23a9abd5aebaa85bf5d0/ml_qm/optimize/NNP_computer_factory.py#L22)).\n\n\n------------------------\n##### 3. Wrapper for command line interface\nTo create a command line program that you can call to minimize conformations with\nyour NNP you have to create a tiny wrapper that constructs the NNP Computer Factory and passes it to the [sdf_multi_optimizer](t_opt/sdf_multi_optimizer.py).\n\nAn Example can be found in [SDFANIMOptimizer](t_opt/SDFANIMOptimizer.py).\n\n\n## Acknowledgments\n\nI would like to thank Justin S. Smith and Adrian Reutberg for making the ASE_ANI available and for help to set it up.\n\nI would like to thanks Man-Ling Lee, the Genentech Incubator project and the Genentech Computational Chemistry group for allowing me to work on this.\n\n## References:\n\n[ASE_ANI](https://github.com/isayev/ASE_ANI)\n\n[Original implementation of the lbfgs optimization algorithm in pytorch](https://pytorch.org/docs/stable/_modules/torch/optim/lbfgs.html)\n\n\n## License\n```\n###############################################################################\n## The MIT License\n##\n## SPDX short identifier: MIT\n##\n## Copyright 2020 Genentech Inc. South San Francisco\n##\n## Permission is hereby granted, free of charge, to any person obtaining a\n## copy of this software and associated documentation files (the \"Software\"),\n## to deal in the Software without restriction, including without limitation\n## the rights to use, copy, modify, merge, publish, distribute, sublicense,\n## and/or sell copies of the Software, and to permit persons to whom the\n## Software is furnished to do so, subject to the following conditions:\n##\n## The above copyright notice and this permission notice shall be included\n## in all copies or substantial portions of the Software.\n##\n## THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n## DEALINGS IN THE SOFTWARE.\n###############################################################################\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenentech%2Ft_opt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgenentech%2Ft_opt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgenentech%2Ft_opt/lists"}