Skip to content

Commit 5a84423

Browse files
author
corochann
committed
first commit
0 parents  commit 5a84423

39 files changed

+3464
-0
lines changed

.flexci/build_and_push.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash -uex
2+
3+
IMAGE_BASE="${1:-}"
4+
IMAGE_PUSH=1
5+
if [ "${IMAGE_BASE}" = "" ]; then
6+
IMAGE_BASE="torch-dftd3"
7+
IMAGE_PUSH=0
8+
fi
9+
10+
TEST_PIP_PACKAGES="
11+
flake8 pytest pytest-cov pytest-xdist pytest-benchmark
12+
"
13+
14+
SRC_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/.."; pwd)"
15+
16+
docker_build_and_push() {
17+
18+
IMAGE_TAG="${1}"; shift
19+
IMAGE_NAME="${IMAGE_BASE}:${IMAGE_TAG}"
20+
21+
pushd "$(dirname ${0})"
22+
docker build -f ${SRC_ROOT}/docker/Dockerfile -t "${IMAGE_NAME}" "$@" .
23+
popd
24+
25+
if [ "${IMAGE_PUSH}" = "0" ]; then
26+
echo "Skipping docker push."
27+
else
28+
docker push "${IMAGE_NAME}"
29+
fi
30+
}
31+
32+
WAIT_PIDS=""
33+
34+
# PyTorch 1.5 + Python 3.6
35+
docker_build_and_push torch15 \
36+
--build-arg base_image="nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04" \
37+
--build-arg python_version="3.6.12" \
38+
--build-arg pip_packages="torch==1.5.* torchvision==0.6.* ${TEST_PIP_PACKAGES}" &
39+
WAIT_PIDS="$! ${WAIT_PIDS}"
40+
41+
# Wait until the build complete.
42+
for P in ${WAIT_PIDS}; do
43+
wait ${P}
44+
done

.flexci/config.pbtxt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
configs {
2+
# Project name.
3+
key: "torch-dftd.pytest"
4+
value {
5+
requirement {
6+
cpu: 4
7+
memory: 16
8+
disk: 10
9+
gpu: 1
10+
}
11+
command:
12+
"bash -x .flexci/pytest_script.sh"
13+
}
14+
}

.flexci/pytest_script.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
set -eu
3+
4+
#IMAGE=pytorch/pytorch:1.5.1-cuda10.1-cudnn7-devel
5+
IMAGE=asia.gcr.io/pfn-public-ci/torch-dftd3-ci:torch15
6+
7+
8+
main() {
9+
SRC_ROOT="$(cd "$(dirname "${BASH_SOURCE}")/../.."; pwd)"
10+
11+
prepare_docker &
12+
wait
13+
14+
# Build and push docker images for unit tests.
15+
# bash -x -c "${SRC_ROOT}/.flexci/build_and_push.sh" \
16+
# "${IMAGE}"
17+
18+
# 1st pytest: when xdist is enabled with `-n $(nproc)`, benchmark is not executed.
19+
# 2nd pytest: only execute pytest-benchmark.
20+
docker run --runtime=nvidia --rm --volume="$(pwd)":/workspace -w /workspace \
21+
${IMAGE} \
22+
bash -x -c "pip install flake8 pytest pytest-cov pytest-xdist pytest-benchmark && \
23+
pip install cupy-cuda102 pytorch-pfn-extras && \
24+
pip install -e . && \
25+
pysen run lint && \
26+
pytest --cov=torch_dftd -n $(nproc) -m 'not slow' tests &&
27+
pytest --benchmark-only tests"
28+
}
29+
30+
31+
# prepare_docker makes docker use tmpfs to speed up.
32+
# CAVEAT: Do not use docker during this is running.
33+
prepare_docker() {
34+
service docker stop
35+
mount -t tmpfs -o size=100% tmpfs /var/lib/docker
36+
service docker start
37+
gcloud auth configure-docker
38+
}
39+
40+
41+
main "$@"

.gitignore

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
pip-wheel-metadata/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
target/
76+
77+
# Jupyter Notebook
78+
.ipynb_checkpoints
79+
80+
# IPython
81+
profile_default/
82+
ipython_config.py
83+
84+
# pyenv
85+
.python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
95+
__pypackages__/
96+
97+
# Celery stuff
98+
celerybeat-schedule
99+
celerybeat.pid
100+
101+
# SageMath parsed files
102+
*.sage.py
103+
104+
# Environments
105+
.env
106+
.venv
107+
env/
108+
venv/
109+
ENV/
110+
env.bak/
111+
venv.bak/
112+
113+
# Spyder project settings
114+
.spyderproject
115+
.spyproject
116+
117+
# Rope project settings
118+
.ropeproject
119+
120+
# mkdocs documentation
121+
/site
122+
123+
# mypy
124+
.mypy_cache/
125+
.dmypy.json
126+
dmypy.json
127+
128+
# Pyre type checker
129+
.pyre/
130+
131+
# PyCharm
132+
.idea/
133+
tests/ase_dftd3.out
134+
tests/ase_dftd3.xyz

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Preferred Networks, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# torch-dftd
2+
pytorch implementation of dftd2 [1] & dftd3 [2, 3]
3+
4+
## Install
5+
6+
```bash
7+
git clone https://github.com/pfnet-research/torch-dftd
8+
pip install -e .
9+
```
10+
11+
## Quick start
12+
13+
```python
14+
from ase.build import molecule
15+
from torch_dftd.torch_dftd3_calculator import TorchDFTD3Calculator
16+
17+
atoms = molecule("CH3CH2OCH3")
18+
# device="cuda:0" for fast GPU computation.
19+
calc = TorchDFTD3Calculator(atoms=atoms, device="cpu", damping="bj")
20+
21+
energy = atoms.get_potential_energy()
22+
forces = atoms.get_forces()
23+
24+
print(f"energy {energy} eV")
25+
print(f"forces {forces}")
26+
```
27+
28+
## Dependency
29+
30+
The library is tested under following environment.
31+
- python: 3.6
32+
- CUDA: 10.2
33+
```bash
34+
torch==1.5.1
35+
ase==3.21.1
36+
# Below is only for 3-body term
37+
cupy-cuda102==8.6.0
38+
pytorch-pfn-extras==0.3.2
39+
```
40+
41+
## Development tips
42+
### Formatting & Linting
43+
[pysen](https://github.com/pfnet/pysen) is used to format the python code of this repository.<br/>
44+
You can simply run below to get your code formatted :)
45+
```bash
46+
# Format the code
47+
$ pysen run format
48+
# Check the code format
49+
$ pysen run lint
50+
```
51+
52+
### CUDA Kernel function implementation with cupy
53+
[cupy](https://github.com/cupy/cupy) supports users to implement CUDA kernels within python code,
54+
and it can be easily linked with pytorch tensor calculations.<br/>
55+
Element wise kernel is implemented and used in some pytorch functions to accelerate speed with GPU.
56+
57+
See [document](https://docs.cupy.dev/en/stable/user_guide/kernel.html) for details about user defined kernel.
58+
59+
## Citation
60+
61+
Please always cite original paper of DFT-D2 [1] or DFT-D3 [2, 3], if you used this software for your publication.
62+
63+
DFT-D2:<br/>
64+
[1] S. Grimme, J. Comput. Chem, 27 (2006), 1787-1799.
65+
DOI: [10.1002/jcc.20495](https://doi.org/10.1002/jcc.20495)
66+
67+
DFT-D3:<br/>
68+
[2] S. Grimme, J. Antony, S. Ehrlich and H. Krieg, J. Chem. Phys, 132 (2010), 154104.
69+
DOI: [10.1063/1.3382344](https://doi.org/10.1063/1.3382344)
70+
71+
If BJ-damping is used in DFT-D3:<br/>
72+
[3] S. Grimme, S. Ehrlich and L. Goerigk, J. Comput. Chem, 32 (2011), 1456-1465.
73+
DOI: [10.1002/jcc.21759](https://doi.org/10.1002/jcc.21759)

docker/Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# FROM nvidia/cuda:10.2-cudnn7-devel-ubuntu18.04
2+
ARG base_image
3+
FROM ${base_image}
4+
5+
# Install pyenv requirements.
6+
# https://github.com/pyenv/pyenv/wiki/Common-build-problems#requirements
7+
RUN export DEBIAN_FRONTEND=noninteractive && \
8+
apt-get -y update && \
9+
apt-get -y install \
10+
build-essential libssl-dev zlib1g-dev libbz2-dev \
11+
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
12+
xz-utils tk-dev libffi-dev liblzma-dev git gfortran && \
13+
rm -rf /var/lib/apt/lists/* /var/cache/apt/archives/*
14+
15+
# Install pyenv.
16+
RUN git clone https://github.com/pyenv/pyenv.git /opt/pyenv
17+
ENV PYENV_ROOT=/opt/pyenv
18+
ENV PATH ${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}
19+
20+
# Install Python.
21+
ARG python_version
22+
RUN pyenv install ${python_version} && \
23+
pyenv global ${python_version}
24+
25+
# Install test dependencies.
26+
ARG pip_packages
27+
RUN pip install -U pip && \
28+
pip install ${pip_packages} && \
29+
pip list
30+
31+
# Install DFTD3
32+
RUN cd /tmp && \
33+
wget https://www.chemie.uni-bonn.de/pctc/mulliken-center/software/dft-d3/dftd3.tgz && \
34+
tar zxvf dftd3.tgz && \
35+
make && \
36+
mv dftd3 /usr/local/bin && \
37+
rm dftd3.tgz

0 commit comments

Comments
 (0)