deepmd-kit: deep learning for molecular dynamics

41
DeePMD-kit: deep learning for molecular dynamics Linfeng Zhang, Han Wang, Yuzhi Zhang, Fengbo Yuan, Duan Kang, Zilong Wang, and many others Hands-on Workshop 2018 August 6, 2018 Linfeng Zhang (PU/PKU) DeePMD-kit 1 / 41

Upload: others

Post on 03-Dec-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

DeePMD-kit: deep learning for molecular dynamics

Linfeng Zhang, Han Wang, Yuzhi Zhang, Fengbo Yuan,

Duan Kang, Zilong Wang, and many others

Hands-on Workshop 2018

August 6, 2018

Linfeng Zhang (PU/PKU) DeePMD-kit 1 / 41

Outline

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 2 / 41

Introduction

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 3 / 41

Introduction

Deep learning meets molecular modeling

Curse of Dimensionality: representation, regularity, efficiency.

Deep neural networks (DNN): (mysterious) capability of learning complex and highlynonlinear functional dependence.

fw(x) = tanh(b1 +W1 tanh(b2 +W2 tanh(b3 +W3 tanh(... tanh(bD +WDx)))))

Linfeng Zhang (PU/PKU) DeePMD-kit 4 / 41

Introduction

Multi-scale Molecular Modeling

A micro-scopic system, a macro-scopic system, and the linking quantity.

A few examples:

ab initio molecular dynamics (MD):quantum mechanics (QM) to MD, potential energy surface (PES);

Coarse-grained (CG) MD:atoms to CG “particles”, free energy surface (FES)/CG potential;

enhanced sampling/phase transition:atoms to fewer collective variables (CVs), FES.

Linfeng Zhang (PU/PKU) DeePMD-kit 5 / 41

Introduction

Multi-scale Molecular Modeling

Traditional dilemma: accuracy vs cost. Taking MD as an example.

E = E(x1,x2, ...,xi, ...,xN),

mid2xi

dt2= Fi = −∇xi

E.

Two ways to calculate E and F :

QM: accurate but very expensive. The Car-Parrinello MD with KS-DFT:

E = ⟨Ψ0|HKSe |Ψ0⟩, µϕi = HKS

e ϕi +∑j

Λijϕj.

Empirical potentials: fast but limited. The Lennard-Jones potential:

Vij = 4ϵ[(σ

rij)12 − (

σ

rij)6], E =

1

2

∑i=j

Vij.

Linfeng Zhang (PU/PKU) DeePMD-kit 6 / 41

Introduction

Deep learning meets molecular modeling

In this tutorial:

Basics of TensorFlow and deep learning;

Basics of Deep Potential and DeePMD-kit;

DeePMD-kit: Training and MD;

Workflow for a new study.

Linfeng Zhang (PU/PKU) DeePMD-kit 7 / 41

Basics of TensorFlow and deep learning

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 8 / 41

Basics of TensorFlow and deep learning

Basics of TensorFlow and deep learning

Linfeng Zhang (PU/PKU) DeePMD-kit 9 / 41

Basics of TensorFlow and deep learning

Basics of TensorFlow and deep learning

Basic problem: Regression and backpropogation, e.g.:

minω

l(f (x), fω(x)), l(f (x), fω(x)) =∑i

(f (xi)− fω(xi))2

ω 7→ ω −∇ωl(f (x), fω(x))

(figure from YouTube: computational graph and back propagation)Linfeng Zhang (PU/PKU) DeePMD-kit 10 / 41

Basics of TensorFlow and deep learning

Basics of TensorFlow and deep learning

Important concepts: Tensor, OP, Placeholder, Optimizer, and Session.Please see example 1 for linear regression and example 2 for a simple neural network.

See instructions in the corresponding example folder.More resources: https://www.tensorflow.org/tutorials/.

Linfeng Zhang (PU/PKU) DeePMD-kit 11 / 41

Basics of TensorFlow and deep learning

Example 2: fitting the sin curve

import necessary libraries, prepare testing data, and define input and output:

Linfeng Zhang (PU/PKU) DeePMD-kit 12 / 41

Basics of TensorFlow and deep learning

Example 2: fitting the sin curve

Define model and training scheme:

Linfeng Zhang (PU/PKU) DeePMD-kit 13 / 41

Basics of TensorFlow and deep learning

Example 2: fitting the sin curve

Perform training:

Linfeng Zhang (PU/PKU) DeePMD-kit 14 / 41

Basics of TensorFlow and deep learning

Example 2: fitting the sin curve

Note: be careful about your model and training scheme!!!

Linfeng Zhang (PU/PKU) DeePMD-kit 15 / 41

Basics of Deep Potential and DeePMD-kit

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 16 / 41

Basics of Deep Potential and DeePMD-kit

DeePMD-kit

Towards realization of a general platform for DL-based PES modeling.

(H. Wang, et al. Comp. Phys. Comm., 2018: 0010-4655(https://github.com/deepmodeling/deepmd-kit))

Linfeng Zhang (PU/PKU) DeePMD-kit 17 / 41

Basics of Deep Potential and DeePMD-kit

An end-to-end representation: why?

Development of image recognition: model and data

Linfeng Zhang (PU/PKU) DeePMD-kit 18 / 41

Basics of Deep Potential and DeePMD-kit

Requirements

Requirements of an end-to-end PES model that we consider to be fundamental:

be accurate and efficient;

use no input information other than atomic coordinates and types;

be size-extensive;

preserve natural symmetries: translation, rotation, and permutation;

minimize human intervention;

be smooth.

Deep Potential (Comm. Comp. Phys. 23.3 (2018): 629-639.),

DeePMD (Phys. Rev. Lett. 120 (2018), 143001),

DeepPot-SE (arxiv: 1805.09003).

Linfeng Zhang (PU/PKU) DeePMD-kit 19 / 41

Basics of Deep Potential and DeePMD-kit

Notations

Consider a system of N atoms, r = r1, r2, ..., rN.

the coordinate matrix R ∈ RN×3:

R = rT1 , · · · , rT

i , · · · , rTNT , ri = (xi, yi, zi).

rc: a pre-defined cut-off radius.

For atom i, defined its neighbors Nrc(i) = j|rij < rc, and rji ≡ rj − ri.

Define i’s local environment matrix

Ri = rT1i, · · · , rT

ji, · · · , rTNi,i

T , rji = (xji, yji, zji).

E(R) ≡ E: a map from the coordinate matrix to the potential energy;

Ei(Ri) ≡ Ei: a map from i’s local environment matrix to the corresponding “atomic”energy.

Linfeng Zhang (PU/PKU) DeePMD-kit 20 / 41

Basics of Deep Potential and DeePMD-kit

Deep Potential: construction

Structure: composite neural networks (NNs). E =∑

iEi, see (a) below.

Within each sub-network: fully connected NNs with symmetrized inputs.

Linfeng Zhang (PU/PKU) DeePMD-kit 21 / 41

Basics of Deep Potential and DeePMD-kit

Deep Potential: symmetry considerations

Translation, rotation, and permutation.

Tbf (r) = f (r + b), RUf (r) = f (rU),

Pσf (r) = f (rσ(1), rσ(2), ..., rσ(N))

Linfeng Zhang (PU/PKU) DeePMD-kit 22 / 41

Basics of Deep Potential and DeePMD-kit

Reconsider the symmetries

Translation, rotation, and permutation.

Tbf (r) = f (r + b), RUf (r) = f (rU),

Pσf (r) = f (rσ(1), rσ(2), ..., rσ(N))

Two simple ideas for a general and faithful representation:

Translation and Rotation:

Ωijk = rji · rki, an Ni ×Ni matrix.

Permutation: ∑j∈N (i)

g(rji)rji.

If we have M different g’s, then we map Ni coordinates to M permutationallysymmetrized coordinates.

Linfeng Zhang (PU/PKU) DeePMD-kit 23 / 41

Basics of Deep Potential and DeePMD-kit

DeepPot-SE

The whole sub-network consists of an encoding net Di(Ri) and a fitting net Ei(Di).See (b) below.

(Rotation: Ri(Ri)T , permutation: (Gi1)TRi and (Ri)TGi2.)

Linfeng Zhang (PU/PKU) DeePMD-kit 24 / 41

Basics of Deep Potential and DeePMD-kit

Training

Training process: minimization of the loss function

Ω = pe(E − E)2 + pf∑i

|Fi − Fi|2.

pe and pf are adaptively selected during the training process.

Linfeng Zhang (PU/PKU) DeePMD-kit 25 / 41

Basics of Deep Potential and DeePMD-kit

Case 1: doing various systems with the same principle

Linfeng Zhang (PU/PKU) DeePMD-kit 26 / 41

Basics of Deep Potential and DeePMD-kit

Case 1: doing various systems with the same principle

Linfeng Zhang (PU/PKU) DeePMD-kit 27 / 41

Basics of Deep Potential and DeePMD-kit

Case 2: structural information of DFT water

Radial and angular distribution function of liquid water (PI-AIMD):

Distribution of the Steinhardt order parameter Q6:

Linfeng Zhang (PU/PKU) DeePMD-kit 28 / 41

Basics of Deep Potential and DeePMD-kit

Case 3: Coarse graining

Given CG variables s. Free energy surface (FES) A(s):

A(s) = −1

βln p(s), p(s) =

1

Z

∫e−βU(r)δ(s(r)− s) dr.

Mean forcesF (s) = −∇sA(s).

Deep Potential for coarse graining (DeePCG, arXiv preprint: 1802.08549)

Linfeng Zhang (PU/PKU) DeePMD-kit 29 / 41

Basics of Deep Potential and DeePMD-kit

DeePCG for a solvent-free model

Alanine Dipeptide: free energy of dihedral anglessolvated (left) and solvent-free (right, represented by DeePCG) models

Linfeng Zhang (PU/PKU) DeePMD-kit 30 / 41

Basics of Deep Potential and DeePMD-kit

Scalability

Linfeng Zhang (PU/PKU) DeePMD-kit 31 / 41

Basics of Deep Potential and DeePMD-kit

DeePMD-kit

Towards realization of a general platform for DL-based PES modeling.

(H. Wang, et al. Comp. Phys. Comm., 2018: 0010-4655(https://github.com/deepmodeling/deepmd-kit))

Linfeng Zhang (PU/PKU) DeePMD-kit 32 / 41

Basics of Deep Potential and DeePMD-kit

DeePMD-kit

Features:

model ability maximized, human intervention minimized;

interfacing state-of-the-art deep learning and MD packages:TensorFlow, LAMMPS, i-PI, ...;

parallelization: MPI/GPU support;

Not sensitive to hyper-parameter settings:only network topology, cut-off radius, and learning rate scheme.

Linfeng Zhang (PU/PKU) DeePMD-kit 33 / 41

DeePMD-kit: training and MD

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 34 / 41

DeePMD-kit: training and MD

DeePMD-kit: training and MD

example 3: several training inputs;example 4: training for a water model.example 5: several LAMMPS instances;See instructions in the corresponding example folder.

Linfeng Zhang (PU/PKU) DeePMD-kit 35 / 41

DeePMD-kit: training and MD

DeePMD-kit: training and MD

example 3: several training inputs, refer to Section 3.2 in the manual

Linfeng Zhang (PU/PKU) DeePMD-kit 36 / 41

DeePMD-kit: training and MD

DeePMD-kit: training and MD

example 4: training for a water model

After training, use dp frz − o graph.pb to freeze a model in graph.pb.

Linfeng Zhang (PU/PKU) DeePMD-kit 37 / 41

DeePMD-kit: training and MD

DeePMD-kit: training and MD

example 5: several LAMMPS instances. The only change: potential.mod.

use lmp serial < in.xxxx to run MD.

Linfeng Zhang (PU/PKU) DeePMD-kit 38 / 41

Workflow for a new study

Outline

1 Introduction

2 Basics of TensorFlow and deep learning

3 Basics of Deep Potential and DeePMD-kit

4 DeePMD-kit: training and MD

5 Workflow for a new study

Linfeng Zhang (PU/PKU) DeePMD-kit 39 / 41

Workflow for a new study

Using DeePMD-kit + TensorFlow for training

example 6: workflow, from data conversion to training.

See tutorial for more instructions.

Linfeng Zhang (PU/PKU) DeePMD-kit 40 / 41

Workflow for a new study

Future studies

Installation: if you are lucky, you could use conda to install Deepmd.kit (on Linux withTensorFlow 1.8 installed):

conda install -c deepmd.kit deepmd

Or you may need to install from scratch ...

For any problem, you are welcome to contact Linfeng Zhang ([email protected]),or Deep Potential ([email protected])

Linfeng Zhang (PU/PKU) DeePMD-kit 41 / 41