penganyang commited on
Commit
c302366
·
verified ·
1 Parent(s): b7cecbd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +106 -3
README.md CHANGED
@@ -1,3 +1,106 @@
1
- ---
2
- license: cc-by-4.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: cc-by-4.0
3
+ ---
4
+
5
+ # Description
6
+
7
+ DPA-2.4-7M is trained using a multitask strategy on the [OpenLAM datasets](https://www.aissquare.com/datasets/detail?pageType=datasets&name=OpenLAM-TrainingSet-v1&id=308). The benchmark results can be found at the [LAMBench website.](https://www.aissquare.com/openlam?tab=Benchmark)
8
+
9
+ Please ensure the usage of the correct code version (**v3.1.0a0**) corresponding to this model.
10
+
11
+ # How to use
12
+
13
+ ## Installation
14
+
15
+ To use the pretrained model, you need to first install the corresponding version of DeePMD-kit. You can try easy installation:
16
+
17
+ ```bash
18
+ pip install torch torchvision torchaudio
19
+ pip install git+https://github.com/deepmodeling/deepmd-kit@v3.1.0a0
20
+ ```
21
+
22
+ For other installation options, please visit the [Releases page](https://github.com/deepmodeling/deepmd-kit/releases/tag/v3.1.0a0) page to download the off-line package for **deepmd-kit v3.1.0a0**, and refer to the [official documentation](https://docs.deepmodeling.com/projects/deepmd/en/v3.0.0rc0/install/easy-install.html) for off-line installation instructions.
23
+
24
+ ## Use the pretrained model
25
+
26
+ The pretrained model can be used directly for prediction tasks, such as serving as an ASE calculator.
27
+
28
+ This model is pretrained in a multi-task manner, featuring a unified backbone (referred to as the unified descriptor) and several fitting nets for different datasets. For detailed information, refer to the [DPA-2 paper](https://arxiv.org/abs/2312.15492).
29
+
30
+ The first step involves selecting a specific fitting net from the model to make predictions. To list the available fitting nets (`model-branch`) in this pretrained model, use the following command:
31
+
32
+ ```bash
33
+ dp --pt show dpa-2.4.pt model-branch
34
+ ```
35
+
36
+ This will generate an output similar to the following:
37
+
38
+ ```plaintext
39
+ Available model branches are ['Domains_Alloy', 'Domains_Anode', 'Domains_Cluster',
40
+ 'Domains_Drug', 'Domains_FerroEle', 'Domains_SSE_PBE', 'Domains_SemiCond', 'H2O_H2O_PD',
41
+ 'Metals_AlMgCu', 'Metals_Cu', 'Metals_Sn', 'Metals_Ti', 'Metals_V', 'Metals_W', 'Others_C12H26',
42
+ 'Others_HfO2', 'Domains_SSE_PBESol', 'Domains_Transition1x', 'H2O_H2O_DPLR',
43
+ 'H2O_H2O_PBE0TS_MD', 'H2O_H2O_PBE0TS', 'H2O_H2O_SCAN0', 'Metals_AgAu_PBED3', 'Others_In2Se3',
44
+ 'MP_traj_v024_alldata_mixu', 'Alloy_tongqi', 'SSE_ABACUS', 'Hybrid_Perovskite',
45
+ 'solvated_protein_fragments', 'Electrolyte', 'ODAC23', 'Alex2D', 'Omat24', 'SPICE2', 'OC20M',
46
+ 'OC22', 'Organic_Reactions', 'RANDOM'], where 'RANDOM' means using a randomly initialized
47
+ fitting net.
48
+ ```
49
+
50
+ Select a fitting net that closely matches your system. Ensure that the elements in your system are included in the corresponding fitting net if you are conducting direct predictions or simulations. For more information on the pretrained datasets, refer to [below](https://www.aissquare.com/models/detail?pageType=models&name=DPA-2.3.1-v3.0.0rc0&id=287#data-used-for-pretraining). **Note**: model branches including "Metals_Cu","Others_C12H26","H2O_H2O_DPLR","H2O_H2O_PBE0TS_MD","H2O_H2O_PBE0TS", and "H2O_H2O_SCAN0" are deprecated (training datasets were removed during the training process).
51
+
52
+ Assuming you choose `H2O_H2O-PD`, you can first freeze the model branch from the multi-task pretrained model:
53
+
54
+ ```bash
55
+ dp --pt freeze -c dpa-2.4-7M.pt -o frozen_model.pth --head H2O_H2O-PD
56
+ ```
57
+
58
+ Then you can use the following Python code for prediction or optimization:
59
+
60
+ ```python
61
+ ## Compute potential energy
62
+ from ase import Atoms
63
+ from deepmd.calculator import DP as DPCalculator
64
+ dp = DPCalculator("frozen_model.pth")
65
+ water = Atoms('H2O', positions=[(0.7601, 1.9270, 1), (1.9575, 1, 1), (1., 1., 1.)], cell=[100, 100, 100])
66
+ water.calc = dp
67
+ print(water.get_potential_energy())
68
+ print(water.get_forces())
69
+
70
+ ## Run BFGS structure optimization
71
+ from ase.optimize import BFGS
72
+ dyn = BFGS(water)
73
+ dyn.run(fmax=1e-6)
74
+ print(water.get_positions())
75
+ ```
76
+
77
+
78
+ ## Zero-Shot Inference
79
+
80
+ Given that energy labels calculated via DFT can vary by an arbitrary constant, LAMs are consistently used to predict the energy difference between the label and a dummy model that estimates potential energy solely based on the chemical formula.
81
+ Specifically, the dummy model is defined as
82
+
83
+ E = Σₑ nₑ · b̂ₑ;
84
+
85
+ where **E** is the predicted energy, **nₑ** is the number of atoms of element **e**, and **b̂ₑ** is the per-atom energy of element **e** obtained via least-squares fitting:
86
+
87
+ b̂ = argmin Σᵢ ( yᵢ − Σₑ nᵢ,ₑ bₑ )²,
88
+
89
+ with **nᵢ,ₑ** denoting the number of atoms of element **e** in sample **i**, and **yᵢ** the corresponding DFT energy label.
90
+ When applying the pretrained model to a new downstream system, it is advisable to adjust the energy bias term to better align with the DFT energy labels of the downstream system. This adjustment can enhance prediction accuracy without necessitating further training of the neural network parameters.
91
+
92
+ To be specific, given a new downstream system, we use `dp --pt change-bias` to do zero-shot procedure, which will inherit the neural network parameters of the pretrained multitask model, but updating the energy bias to better align with the downstream system.
93
+
94
+ ```bash
95
+ dp --pt change-bias dpa-2.4-7M.pt -s <your_system> --model-branch Omat24
96
+ ```
97
+
98
+ ## Fine-tuning
99
+
100
+ To fine-tune a pretrained model, you need to ensure that the model configuration (model/descriptor and model/fitting_net) matches exactly with the pretrained model. The input_finetune.json file provided on this page contains the same model configuration as the pretrained model.
101
+
102
+ To prepare for fine-tuning, replace the model/type_map and training/training(validation)_data sections in input_finetune.json with your specific dataset information, just the same as from scratch. Additionally, adjust the learning rate for fine-tuning, typically a small learning rate such as 1e-4 for learning_rate/start_lr is recommended. One can inherit a pretrained fitting net by using the `--model-branch` argument.
103
+
104
+ ```bash
105
+ dp --pt train input_finetune.json --finetune dpa-2.4-7M.pt --model-branch Omat24
106
+ ```