pytorch implementation of dftd2 & dftd3

Overview

torch-dftd

pytorch implementation of dftd2 [1] & dftd3 [2, 3]

Install

# Install from pypi
pip install torch-dftd

# Install from source (for developers)
git clone https://github.com/pfnet-research/torch-dftd
pip install -e .

Quick start

from ase.build import molecule
from torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator

atoms = molecule("CH3CH2OCH3")
# device="cuda:0" for fast GPU computation.
calc = TorchDFTD3Calculator(atoms=atoms, device="cpu", damping="bj")

energy = atoms.get_potential_energy()
forces = atoms.get_forces()

print(f"energy {energy} eV")
print(f"forces {forces}")

Dependency

The library is tested under following environment.

  • python: 3.6
  • CUDA: 10.2
torch==1.5.1
ase==3.21.1
# Below is only for 3-body term
cupy-cuda102==8.6.0
pytorch-pfn-extras==0.3.2

Development tips

Formatting & Linting

pysen is used to format the python code of this repository.
You can simply run below to get your code formatted :)

# Format the code
$ pysen run format
# Check the code format
$ pysen run lint

CUDA Kernel function implementation with cupy

cupy supports users to implement CUDA kernels within python code, and it can be easily linked with pytorch tensor calculations.
Element wise kernel is implemented and used in some pytorch functions to accelerate speed with GPU.

See document for details about user defined kernel.

Citation

Please always cite original paper of DFT-D2 [1] or DFT-D3 [2, 3], if you used this software for your publication.

DFT-D2:
[1] S. Grimme, J. Comput. Chem, 27 (2006), 1787-1799. DOI: 10.1002/jcc.20495

DFT-D3:
[2] S. Grimme, J. Antony, S. Ehrlich and H. Krieg, J. Chem. Phys, 132 (2010), 154104. DOI: 10.1063/1.3382344

If BJ-damping is used in DFT-D3:
[3] S. Grimme, S. Ehrlich and L. Goerigk, J. Comput. Chem, 32 (2011), 1456-1465. DOI: 10.1002/jcc.21759

Comments
  • [WIP] Cell-related gradient modifications

    [WIP] Cell-related gradient modifications

    I found that the current implementation has several performance issues regarding gradient wrt. cell. This PR modifies that. Since the changes are relatively much, I will put some comments.

    Change summary:

    • Use shift for gradient instead of cell.
    • shift is now length scale instead cell unit.
    • Calculate Voigt notation style stress directly

    Also, this PR contains bugfix related to sked cell.

    bug enhancement 
    opened by So-Takamoto 1
  • Raise Error with single atom inputs.

    Raise Error with single atom inputs.

    When the length of atoms is 1, the routine raises error.

    from ase.build import molecule
    from ase.calculators.dftd3 import DFTD3
    from torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator
    
    if __name__ == "__main__":
        atoms = molecule("H")
        # device="cuda:0" for fast GPU computation.
        calc = TorchDFTD3Calculator(atoms=atoms, device="cpu", damping="bj")
    
        energy = atoms.get_potential_energy()
        forces = atoms.get_forces()
    
        print(f"energy {energy} eV")
        print(f"forces {forces}")
    
    
    Traceback (most recent call last):
      File "quick.py", line 12, in <module>
        energy = atoms.get_potential_energy()
      File "/home/ahayashi/envs/dftd/lib/python3.8/site-packages/ase/atoms.py", line 731, in get_potential_energy
        energy = self._calc.get_potential_energy(self)
      File "/home/ahayashi/envs/dftd/lib/python3.8/site-packages/ase/calculators/calculator.py", line 709, in get_potential_energy
        energy = self.get_property('energy', atoms)
      File "/home/ahayashi/torch-dftd/torch_dftd/torch_dftd3_calculator.py", line 141, in get_property
        dftd3_result = Calculator.get_property(self, name, atoms, allow_calculation)
      File "/home/ahayashi/envs/dftd/lib/python3.8/site-packages/ase/calculators/calculator.py", line 737, in get_property
        self.calculate(atoms, [name], system_changes)
      File "/home/ahayashi/torch-dftd/torch_dftd/torch_dftd3_calculator.py", line 119, in calculate
        results = self.dftd_module.calc_energy(**input_dicts, damping=self.damping)[0]
      File "/home/ahayashi/torch-dftd/torch_dftd/nn/base_dftd_module.py", line 75, in calc_energy
        E_disp = self.calc_energy_batch(
      File "/home/ahayashi/torch-dftd/torch_dftd/nn/dftd3_module.py", line 86, in calc_energy_batch
        E_disp = d3_autoev * edisp(
      File "/home/ahayashi/torch-dftd/torch_dftd/functions/dftd3.py", line 189, in edisp
        c6 = _getc6(Zi, Zj, nci, ncj, c6ab=c6ab, k3=k3)  # c6 coefficients
      File "/home/ahayashi/torch-dftd/torch_dftd/functions/dftd3.py", line 97, in _getc6
        k3_rnc = torch.where(cn0 > 0.0, k3 * r, -1.0e20 * torch.ones_like(r)).view(n_edges, -1)
    RuntimeError: cannot reshape tensor of 0 elements into shape [0, -1] because the unspecified dimension size -1 can be any value and is ambiguous
    
    opened by AkihideHayashi 1
  • use shift for gradient calculation instead of cell

    use shift for gradient calculation instead of cell

    I found that the current implementation has several performance issues regarding gradient wrt. cell. This PR modifies it. Since the changes are relatively much, I will put some comments.

    Change summary:

    • Use shift for gradient instead of cell.
    • shift is now length scale instead cell unit.
    • Calculate Voigt notation style stress directly

    Also, this PR contains bugfix related to sked cell.

    bug enhancement 
    opened by So-Takamoto 0
  • Bugfix: batch calculation with abc=True

    Bugfix: batch calculation with abc=True

    I found that test function test_calc_energy_force_stress_device_batch_abc unintentionally ignores abc argument.

    This PR modified related implementation to work it.

    In addition, corner case correspondence when the total number of atom is zero is also added. (n_graphs cannot be calculated from batch_edge when len(batch_edge) == 0.)

    bug 
    opened by So-Takamoto 0
  • Fixed a bug for inputs with 0 adjacencies.

    Fixed a bug for inputs with 0 adjacencies.

    The _gettc6 routine now works correctly even when the number of adjacencies is 0. Instead of calling calc_neighbor_by_pymatgen when the number of atoms is 0 and the periodic boundary condition, it now return edge_index, S for adjacency 0. In my environment, using the result of torch.sum for the size of torch.zeros caused an error, so I changed it to cast the result of sum to int.

    bug 
    opened by AkihideHayashi 0
  •  Bug in test for stress

    Bug in test for stress

    In test_torch_dftd3_calculator.py/_assert_energy_force_stress_equal, there is a code below.

        if np.all(atoms.pbc == np.array([True, True, True])):
            s1 = atoms.get_stress()
            s2 = atoms.get_stress()
            assert np.allclose(s1, s2, atol=1e-5, rtol=1e-5)
    

    This code cannot compare the results of stresses of calc1 and calc2. Both s1 and s2 are the stress of calc2.

    opened by AkihideHayashi 0
Releases(v0.3.0)
  • v0.3.0(Apr 25, 2022)

    This is the release note of v0.3.0.

    Highlights

    • use shift for gradient calculation instead of cell #13 (Thank you @So-Takamoto )
      • It includes 1. speed up of stress calculation for batch atoms, and 2. bug fix for stress calculation when cell is skewed.
    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Sep 4, 2021)

    This is the release note of v0.2.0.

    Highlights

    • Add PFP citation in README.md #2
    • Use pymatgen for pbc neighbor search speed up #3

    Bug fixes

    • Fixed a bug for inputs with 0 adjacencies. #6 (Thank you @AkihideHayashi )
    • Remove RuntimeError on no-cupy environment #8 (Thank you @So-Takamoto )
    • Bugfix: batch calculation with abc=True #9 (Thank you @So-Takamoto )

    Others

    • move pysen to develop dependency #10 (Thank you @So-Takamoto )
    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(May 10, 2021)

Parris, the automated infrastructure setup tool for machine learning algorithms.

README Parris, the automated infrastructure setup tool for machine learning algorithms. What Is This Tool? Parris is a tool for automating the trainin

Joseph Greene 319 Aug 02, 2022
An evaluation toolkit for voice conversion models.

Voice-conversion-evaluation An evaluation toolkit for voice conversion models. Sample test pair Generate the metadata for evaluating models. The direc

30 Aug 29, 2022
Official code for paper "Optimization for Oriented Object Detection via Representation Invariance Loss".

Optimization for Oriented Object Detection via Representation Invariance Loss By Qi Ming, Zhiqiang Zhou, Lingjuan Miao, Xue Yang, and Yunpeng Dong. Th

ming71 56 Nov 28, 2022
Ego4d dataset repository. Download the dataset, visualize, extract features & example usage of the dataset

Ego4D EGO4D is the world's largest egocentric (first person) video ML dataset and benchmark suite, with 3,600 hrs (and counting) of densely narrated v

Meta Research 118 Jan 07, 2023
SuRE Evaluation: A Supplementary Material

SuRE Evaluation: A Supplementary Material This repository contains supplementary material regarding the evaluations presented in the paper Visual Expl

NYU Visualization Lab 0 Dec 14, 2021
BEGAN in PyTorch

BEGAN in PyTorch This project is still in progress. If you are looking for the working code, use BEGAN-tensorflow. Requirements Python 2.7 Pillow tqdm

Taehoon Kim 260 Dec 07, 2022
Official PyTorch Implementation of Rank & Sort Loss [ICCV2021]

Rank & Sort Loss for Object Detection and Instance Segmentation The official implementation of Rank & Sort Loss. Our implementation is based on mmdete

Kemal Oksuz 229 Dec 20, 2022
CT Based COVID 19 Diagnose by Image Processing and Deep Learning

This project proposed the deep learning and image processing method to undertake the diagnosis on 2D CT image and 3D CT volume.

1 Feb 08, 2022
This is an official implementation of our CVPR 2021 paper "Bottom-Up Human Pose Estimation Via Disentangled Keypoint Regression" (https://arxiv.org/abs/2104.02300)

Bottom-Up Human Pose Estimation Via Disentangled Keypoint Regression Introduction In this paper, we are interested in the bottom-up paradigm of estima

HRNet 367 Dec 27, 2022
Deep Reinforcement Learning by using an on-policy adaptation of Maximum a Posteriori Policy Optimization (MPO)

V-MPO Simple code to demonstrate Deep Reinforcement Learning by using an on-policy adaptation of Maximum a Posteriori Policy Optimization (MPO) in Pyt

Nugroho Dewantoro 9 Jun 06, 2022
This repository consists of Blender python scripts and corresponding assets to generate variants of the CANDLE dataset

candle-simulator This repository consists of Blender python scripts and corresponding assets to generate variants of the IITH-CANDLE dataset. The rend

1 Dec 15, 2021
Codebase for Inducing Causal Structure for Interpretable Neural Networks

Interchange Intervention Training (IIT) Codebase for Inducing Causal Structure for Interpretable Neural Networks Release Notes 12/01/2021: Code and Pa

Zen 6 Oct 10, 2022
Portfolio asset allocation strategies: from Markowitz to RNNs

Portfolio asset allocation strategies: from Markowitz to RNNs Research project to explore different approaches for optimal portfolio allocation starti

Luigi Filippo Chiara 1 Feb 05, 2022
a spacial-temporal pattern detection system for home automation

Argos a spacial-temporal pattern detection system for home automation. Based on OpenCV and Tensorflow, can run on raspberry pi and notify HomeAssistan

Angad Singh 133 Jan 05, 2023
Simulated garment dataset for virtual try-on

Simulated garment dataset for virtual try-on This repository contains the dataset used in the following papers: Self-Supervised Collision Handling via

33 Dec 20, 2022
paper: Hyperspectral Remote Sensing Image Classification Using Deep Convolutional Capsule Network

DC-CapsNet This is a tensorflow and keras based implementation of DC-CapsNet for HSI in the Remote Sensing Letters R. Lei et al., "Hyperspectral Remot

LEI 7 Nov 29, 2022
Music Classification: Beyond Supervised Learning, Towards Real-world Applications

Music Classification: Beyond Supervised Learning, Towards Real-world Applications

104 Dec 15, 2022
Plug and play transformer you can find network structure and official complete code by clicking List

Plug-and-play Module Plug and play transformer you can find network structure and official complete code by clicking List The following is to quickly

8 Mar 27, 2022
Based on Stockfish neural network(similar to LcZero)

MarcoEngine Marco Engine - interesnaya neyronnaya shakhmatnaya set', kotoraya ispol'zuyet metod samoobucheniya(dostizheniye khoroshoy igy putem proboy

Marcus Kemaul 4 Mar 12, 2022
Reinforcement Learning Theory Book (rus)

Reinforcement Learning Theory Book (rus)

qbrick 206 Nov 27, 2022