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)

NLG evaluation via Statistical Measures of Similarity: BaryScore, DepthScore, InfoLM

NLG evaluation via Statistical Measures of Similarity: BaryScore, DepthScore, InfoLM Automatic Evaluation Metric described in the papers BaryScore (EM

Pierre Colombo 28 Dec 28, 2022
Unsupervised Pre-training for Person Re-identification (LUPerson)

LUPerson Unsupervised Pre-training for Person Re-identification (LUPerson). The repository is for our CVPR2021 paper Unsupervised Pre-training for Per

143 Dec 24, 2022
Make your own game in a font!

Project structure. Included is a suite of tools to create font games. Tutorial: For a quick tutorial about how to make your own game go here For devel

Michael Mulet 125 Dec 04, 2022
[ECE NTUA] 👁 Computer Vision - Lab Projects & Theoretical Problem Sets (2020-2021)

Computer Vision - NTUA (2020-2021) This repository hosts the lab projects and theoretical problem sets of the Computer Vision course held by ECE NTUA

Dimitris Dimos 6 Jul 21, 2022
Tensorflow port of a full NetVLAD network

netvlad_tf The main intention of this repo is deployment of a full NetVLAD network, which was originally implemented in Matlab, in Python. We provide

Robotics and Perception Group 225 Nov 08, 2022
Paddle-Skeleton-Based-Action-Recognition - DecoupleGCN-DropGraph, ASGCN, AGCN, STGCN

Paddle-Skeleton-Action-Recognition DecoupleGCN-DropGraph, ASGCN, AGCN, STGCN. Yo

Chenxu Peng 3 Nov 02, 2022
Official PyTorch(Geometric) implementation of DPGNN(DPGCN) in "Distance-wise Prototypical Graph Neural Network for Node Imbalance Classification"

DPGNN This repository is an official PyTorch(Geometric) implementation of DPGNN(DPGCN) in "Distance-wise Prototypical Graph Neural Network for Node Im

Yu Wang (Jack) 18 Oct 12, 2022
Anderson Acceleration for Deep Learning

Anderson Accelerated Deep Learning (AADL) AADL is a Python package that implements the Anderson acceleration to speed-up the training of deep learning

Oak Ridge National Laboratory 7 Nov 24, 2022
Semantically Contrastive Learning for Low-light Image Enhancement

Semantically Contrastive Learning for Low-light Image Enhancement Here, we propose an effective semantically contrastive learning paradigm for Low-lig

48 Dec 16, 2022
基于Flask开发后端、VUE开发前端框架,在WEB端部署YOLOv5目标检测模型

基于Flask开发后端、VUE开发前端框架,在WEB端部署YOLOv5目标检测模型

37 Jan 01, 2023
3D ResNet Video Classification accelerated by TensorRT

Activity Recognition TensorRT Perform video classification using 3D ResNets trained on Kinetics-400 dataset and accelerated with TensorRT P.S Click on

Akash James 39 Nov 21, 2022
Automatic Video Captioning Evaluation Metric --- EMScore

Automatic Video Captioning Evaluation Metric --- EMScore Overview For an illustration, EMScore can be computed as: Installation modify the encode_text

Yaya Shi 17 Nov 28, 2022
Code for HLA-Face: Joint High-Low Adaptation for Low Light Face Detection (CVPR21)

HLA-Face: Joint High-Low Adaptation for Low Light Face Detection The official PyTorch implementation for HLA-Face: Joint High-Low Adaptation for Low L

Wenjing Wang 77 Dec 08, 2022
Implementing a simplified copy of Shazam application from scratch using MinHashing and LSH.

Building Shazam from scratch In this repository we tried to implement a simplified copy of the Shazam application able to tell you the name of a song

Arturo Ghinassi 0 Nov 17, 2022
This repository contains the files for running the Patchify GUI.

Repository Name Train-Test-Validation-Dataset-Generation App Name Patchify Description This app is designed for crop images and creating smal

Salar Ghaffarian 9 Feb 15, 2022
190 Jan 03, 2023
HandTailor: Towards High-Precision Monocular 3D Hand Recovery

HandTailor This repository is the implementation code and model of the paper "HandTailor: Towards High-Precision Monocular 3D Hand Recovery" (arXiv) G

Lv Jun 113 Jan 06, 2023
PASSL包含 SimCLR,MoCo,BYOL,CLIP等基于对比学习的图像自监督算法以及 Vision-Transformer,Swin-Transformer,BEiT,CVT,T2T,MLP_Mixer等视觉Transformer算法

PASSL Introduction PASSL is a Paddle based vision library for state-of-the-art Self-Supervised Learning research with PaddlePaddle. PASSL aims to acce

186 Dec 29, 2022
Code release for "Masked-attention Mask Transformer for Universal Image Segmentation"

Mask2Former: Masked-attention Mask Transformer for Universal Image Segmentation Bowen Cheng, Ishan Misra, Alexander G. Schwing, Alexander Kirillov, Ro

Meta Research 1.2k Jan 02, 2023
GLaRA: Graph-based Labeling Rule Augmentation for Weakly Supervised Named Entity Recognition

GLaRA: Graph-based Labeling Rule Augmentation for Weakly Supervised Named Entity Recognition

Xinyan Zhao 29 Dec 26, 2022