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)

🔥🔥High-Performance Face Recognition Library on PaddlePaddle & PyTorch🔥🔥

face.evoLVe: High-Performance Face Recognition Library based on PaddlePaddle & PyTorch Evolve to be more comprehensive, effective and efficient for fa

Zhao Jian 3.1k Jan 02, 2023
Code used to generate the results appearing in "Train longer, generalize better: closing the generalization gap in large batch training of neural networks"

Train longer, generalize better - Big batch training This is a code repository used to generate the results appearing in "Train longer, generalize bet

Elad Hoffer 145 Sep 16, 2022
A small fun project using python OpenCV, mediapipe, and pydirectinput

Here I tried a small fun project using python OpenCV, mediapipe, and pydirectinput. Here we can control moves car game when yellow color come to right box (press key 'd') left box (press key 'a') lef

Sameh Elisha 3 Nov 17, 2022
Object detection evaluation metrics using Python.

Object detection evaluation metrics using Python.

Louis Facun 2 Sep 06, 2022
Code for the paper "Location-aware Single Image Reflection Removal"

Location-aware Single Image Reflection Removal The shown images are provided by the datasets from IBCLN, ERRNet, SIR2 and the Internet images. The cod

72 Dec 08, 2022
A Novel Plug-in Module for Fine-grained Visual Classification

Pytorch implementation for A Novel Plug-in Module for Fine-Grained Visual Classification. fine-grained visual classification task.

ChouPoYung 109 Dec 20, 2022
A full-fledged version of Pix2Seq

Stable-Pix2Seq A full-fledged version of Pix2Seq What it is. This is a full-fledged version of Pix2Seq. Compared with unofficial-pix2seq, stable-pix2s

peng gao 205 Dec 27, 2022
Code for "NeuralRecon: Real-Time Coherent 3D Reconstruction from Monocular Video", CVPR 2021 oral

NeuralRecon: Real-Time Coherent 3D Reconstruction from Monocular Video Project Page | Paper NeuralRecon: Real-Time Coherent 3D Reconstruction from Mon

ZJU3DV 1.4k Dec 30, 2022
Hashformers is a framework for hashtag segmentation with transformers.

Hashtag segmentation is the task of automatically inserting the missing spaces between the words in a hashtag. Hashformers applies Transformer models

Ruan Chaves 41 Nov 09, 2022
BasicRL: easy and fundamental codes for deep reinforcement learning。It is an improvement on rainbow-is-all-you-need and OpenAI Spinning Up.

BasicRL: easy and fundamental codes for deep reinforcement learning BasicRL is an improvement on rainbow-is-all-you-need and OpenAI Spinning Up. It is

RayYoh 12 Apr 28, 2022
Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive Learning".

ERICA Source code and dataset for ACL2021 paper: "ERICA: Improving Entity and Relation Understanding for Pre-trained Language Models via Contrastive L

THUNLP 75 Nov 02, 2022
COVINS -- A Framework for Collaborative Visual-Inertial SLAM and Multi-Agent 3D Mapping

COVINS -- A Framework for Collaborative Visual-Inertial SLAM and Multi-Agent 3D Mapping Version 1.0 COVINS is an accurate, scalable, and versatile vis

ETHZ V4RL 183 Dec 27, 2022
sktime companion package for deep learning based on TensorFlow

NOTE: sktime-dl is currently being updated to work correctly with sktime 0.6, and wwill be fully relaunched over the summer. The plan is Refactor and

sktime 573 Jan 05, 2023
Code, final versions, and information on the Sparkfun Graphical Datasheets

Graphical Datasheets Code, final versions, and information on the SparkFun Graphical Datasheets. Generated Cells After Running Script Example Complete

SparkFun Electronics 102 Jan 05, 2023
🛰️ List of earth observation companies and job sites

Earth Observation Companies & Jobs source Portals & Jobs Geospatial Geospatial jobs newsletter: ~biweekly newsletter with geospatial jobs by Ali Ahmad

Dahn 64 Dec 27, 2022
[NeurIPS 2021] "Drawing Robust Scratch Tickets: Subnetworks with Inborn Robustness Are Found within Randomly Initialized Networks" by Yonggan Fu, Qixuan Yu, Yang Zhang, Shang Wu, Xu Ouyang, David Cox, Yingyan Lin

Drawing Robust Scratch Tickets: Subnetworks with Inborn Robustness Are Found within Randomly Initialized Networks Yonggan Fu, Qixuan Yu, Yang Zhang, S

12 Dec 11, 2022
Offcial repository for the IEEE ICRA 2021 paper Auto-Tuned Sim-to-Real Transfer.

Offcial repository for the IEEE ICRA 2021 paper Auto-Tuned Sim-to-Real Transfer.

47 Jun 30, 2022
Implements Gradient Centralization and allows it to use as a Python package in TensorFlow

Gradient Centralization TensorFlow This Python package implements Gradient Centralization in TensorFlow, a simple and effective optimization technique

Rishit Dagli 101 Nov 01, 2022
Speech-Emotion-Analyzer - The neural network model is capable of detecting five different male/female emotions from audio speeches. (Deep Learning, NLP, Python)

Speech Emotion Analyzer The idea behind creating this project was to build a machine learning model that could detect emotions from the speech we have

Mitesh Puthran 965 Dec 24, 2022
In this project, two programs can help you take full agvantage of time on the model training with a remote server

In this project, two programs can help you take full agvantage of time on the model training with a remote server, which can push notification to your phone about the information during model trainin

GrayLee 8 Dec 27, 2022