Skip to content

Commit 8602007

Browse files
committed
fix bug and change Example
1 parent 7d5ddc2 commit 8602007

24 files changed

+13700
-211
lines changed

README.md

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
___
1+
from sympy.physics.units import forcefrom sympy.physics.units import energy___
22
# ABFML
33

44
## 1. Introduction
@@ -27,6 +27,9 @@ To get started with ABFML, follow these steps to set up the environment and inst
2727
# This installs ABFML from the local directory.
2828
```
2929
### 2.2 Installing ABFML-LAMMPS
30+
In general for force field development users, this step can be skipped for now.
31+
It would be more efficient to apply it to large-scale molecular dynamics
32+
when all aspects of the force field are relevantly calculated/checked by the more convenient ASEs
3033
To integrate ABFML with LAMMPS, follow these steps:
3134
```bash
3235
# 1. Download LAMMPS:
@@ -53,11 +56,18 @@ To integrate ABFML with LAMMPS, follow these steps:
5356
cd src
5457
make yes-abfml
5558
make mpi
59+
60+
# 6. Run lammps:
61+
pair_style abfml model.pt
62+
pair coeff * * 29 30
63+
64+
# Use the element number to represent the element type
5665
```
5766
**Note**: Ensure your GCC compiler is version 9.0 or above, as older versions may not support.
5867

5968
## 3. Build a new model
60-
Build your own model input in the input file and specify the path to the model's py file
69+
Build your own model input in the input file and specify the path to the model's py file,
70+
This is an example of a simple LJ potential, which can be found in example/new-model。
6171
```json
6272
{
6373
"model_setting": {
@@ -72,7 +82,7 @@ Build your own model input in the input file and specify the path to the model's
7282
}
7383
}
7484
```
75-
Then you can use the relevant modules for training, validation and simulation
85+
Then you can use the relevant modules for training, validation and simulation
7686

7787
## 4. Run
7888

@@ -84,15 +94,24 @@ To run an example using ABFML, follow these steps:
8494
# 2. Navigate to the example directory:
8595
cd abfml/example/dp
8696

87-
# 3. Run:
97+
# 3. Quick check for model correctness
98+
abfml check -m model.pt -d float32
99+
100+
# 4. train:
88101
abfml train input.json
89102
# This command starts the training process using the configurations specified in `input.json`.
90103

91-
# 4. Quick check for model correctness
92-
abfml check -m model.pt -d float32
93-
# 5. Run lammps:
94-
pair_style abfml model.pt
95-
pair coeff * * 29 30
96-
97-
# Use the element number to represent the element type
104+
# 5. valid:
105+
abfml valid -m 'model.pt' -f "../data/test.extxyz" -n 10
106+
```
107+
108+
Use the ASE calculator to perform quick calculations on the model created.
109+
```python
110+
from abfml.calculate import ABFML
111+
from ase.build import bulk
112+
calc = ABFML('model.pt')
113+
structure = bulk('Cu', a=3.62)
114+
structure.calc = calc
115+
energy = structure.get_potential_energy()
116+
force = structure.get_forces()
98117
```

abfml/entrypoints/check.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def check_mlff(
1919
input: Optional[str] = None,
2020
dtype: str = "float32",
2121
**kwargs):
22-
logger = Logger("valid.log").logger
22+
logger = Logger("check.log").logger
2323
log_logo(logger=logger)
2424

2525
if input is not None:
@@ -83,6 +83,26 @@ def check_mlff(
8383
logger.info(f"+----------------------------------------------------------------------------------------------+")
8484

8585
logger.info(f"+-------------------------------------- periodicity check -------------------------------------+")
86+
cluster = bulk('Cu', 'fcc', a=3.62, cubic=True)
87+
cluster.calc = calculator
88+
energy = [cluster.get_potential_energy()]
89+
force = [cluster.get_forces()]
90+
cluster = cluster * (3, 3, 3)
91+
cluster.calc = calculator
92+
energy.append(cluster.get_potential_energy())
93+
force.append(cluster.get_forces())
94+
dE = energy[1] - energy[0] * 27
95+
dF = np.abs(force[1][:4] - force[0]).sum().item()
96+
logger.info(f" bulk-> energy: {energy[0]:>.6f}, force: {force[0].sum().item():>.6f}")
97+
logger.info(f" 3*3*3 bulk-> energy: {energy[1]:>.6f}, force: {force[1].sum().item():>.6f}")
98+
logger.info(f" difference-> E[1]-E[0]*27: {dE:>.6f}, dF: {dF:>.6f}")
99+
logger.info(f"Information: The energy of the expanded cell of a periodic structure is proportional to the number")
100+
logger.info(f" of times it is expanded and the force on the corresponding atoms is unchanged.")
101+
logger.warning(f"If the difference is less than 1e-5 it may be an accuracy problem,")
102+
logger.warning(f"otherwise the energy and force relationship should be checked.")
103+
logger.info(f"+----------------------------------------------------------------------------------------------+")
104+
105+
logger.info(f"+------------------------------------- energy-force check -------------------------------------+")
86106
cluster = Atoms(element_symbol + '3', position)
87107
cluster.calc = calculator
88108
energy = [cluster.get_potential_energy()]
@@ -100,22 +120,3 @@ def check_mlff(
100120
logger.warning(f"otherwise the energy and force relationship should be checked.")
101121
logger.info(f"+----------------------------------------------------------------------------------------------+")
102122

103-
logger.info(f"+------------------------------------- energy-force check -------------------------------------+")
104-
cluster = bulk('Cu', 'fcc', a=3.62, cubic=True)
105-
cluster.calc = calculator
106-
energy = [cluster.get_potential_energy()]
107-
force = [cluster.get_forces()]
108-
cluster = cluster * (3,3,3)
109-
cluster.calc = calculator
110-
energy.append(cluster.get_potential_energy())
111-
force.append(cluster.get_forces())
112-
dE = energy[1] - energy[0] * 27
113-
dF = np.abs(force[1][:4] - force[0]).sum().item()
114-
logger.info(f" bulk-> energy: {energy[0]:>.6f}, force: {force[0].sum().item():>.6f}")
115-
logger.info(f" 3*3*3 bulk-> energy: {energy[1]:>.6f}, force: {force[1].sum().item():>.6f}")
116-
logger.info(f" difference-> E[1]-E[0]*27: {dE:>.6f}, dF: {dF:>.6f}")
117-
logger.info(f"Information: The energy of the expanded cell of a periodic structure is proportional to the number")
118-
logger.info(f" of times it is expanded and the force on the corresponding atoms is unchanged.")
119-
logger.warning(f"If the difference is less than 1e-5 it may be an accuracy problem,")
120-
logger.warning(f"otherwise the energy and force relationship should be checked.")
121-
logger.info(f"+----------------------------------------------------------------------------------------------+")

abfml/model/normal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def normal(self, normal_loader, param_class: Param):
102102
torch.zeros(ntype, requires_grad=False)]
103103
from abfml.model.field_model_bp import BPMlp
104104
for i, image_batch in enumerate(normal_loader):
105-
neighbor_list = image_batch['neighbor_list']
105+
Nij= image_batch['Nij']
106106
Zij = image_batch['Zij']
107107
Rij = image_batch["Rij"]
108108
Zi = image_batch["Zi"]
@@ -112,7 +112,7 @@ def normal(self, normal_loader, param_class: Param):
112112
bp_features_information=param_class.BPDescriptor.bp_features_information,
113113
bp_features_param=param_class.BPDescriptor.bp_features_param,
114114
element_map=element_type,
115-
neighbor_list=neighbor_list,
115+
Nij=Nij,
116116
Zij=Zij,
117117
Rij=Rij)
118118

0 Bytes
Binary file not shown.

example/bp-model/bp_input.json renamed to example/bp-model/input.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@
4242
},
4343
"data_setting": {
4444
"file_format": "extxyz",
45-
"train_file": ["test1.extxyz"],
46-
"valid_file": ["test1.extxyz"]
45+
"train_file": ["../data/test.extxyz"],
46+
"valid_file": ["../data/test.extxyz"]
4747
},
4848
"train_setting": {
4949
"epoch": 1,

example/bp-model/loss.curve

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Epoch T_RMSE_Loss V_RMSE_Loss T_RMSE_E_tot V_RMSE_E_tot T_RMSE_Force V_RMSE_Force Total_Time(s)
2-
1 3.25684e+00 4.03030e+00 1.28853e+00 1.22914e+00 1.96831e+00 1.53909e+00 0.08
2+
1 2.37143e-01 1.71323e-01 9.88585e-02 2.08156e-02 1.38284e-01 7.51426e-02 56.81

0 commit comments

Comments
 (0)