Skip to content

Commit

Permalink
Update 3.usage.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VINFeng authored and WangXinyan940 committed Nov 8, 2023
1 parent 25ef0dd commit cc0a726
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions docs/user_guide/3.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ In this example, `lig.pdb` is the PDB file containing atomic coordinates, and `l

If you run this script in `examples/classical`, you will get the following output.
```
<function HarmonicBondJaxGenerator.createForce.<locals>.potential_fn at 0x112504af0>
<function HarmonicAngleJaxGenerator.createForce.<locals>.potential_fn at 0x1124cd820>
<function PeriodicTorsionJaxGenerator.createForce.<locals>.potential_fn at 0x18509b790>
<function NonbondJaxGenerator.createForce.<locals>.potential_fn at 0x18509baf0>
<function HarmonicBondGenerator.createPotential.<locals>.potential_fn at 0x7fe6c3bd2280>
<function HarmonicAngleGenerator.createPotential.<locals>.potential_fn at 0x7fe6c3bd2670>
<function PeriodicTorsionGenerator.createPotential.<locals>.potential_fn at 0x7fe6c3c4a8b0>
<function NonbondedGenerator.createPotential.<locals>.potential_fn at 0x7fe6c3bd8670>
```
The force field parameters are stored as a Python dict in the Hamiltonian.
```python
Expand All @@ -50,11 +50,11 @@ Each generated function will read coordinates, box, pairs and force field parame
```python
positions = jnp.array(pdb.getPositions(asNumpy=True).value_in_unit(unit.nanometer))
box = jnp.array([
[ 1.0, 0.0, 0.0],
[ 0.0, 1.0, 0.0],
[ 0.0, 0.0, 1.0]
[10.0, 0.0, 0.0],
[ 0.0, 10.0, 0.0],
[ 0.0, 0.0, 10.0]
])
nbList = NeighborList(box, rc=4)
nbList = NeighborList(box, rcut=4, cov_map=potentials.meta["cov_map"])
nbList.allocate(positions)
pairs = nbList.pairs
```
Expand All @@ -66,7 +66,7 @@ nbfunc = potentials.dmff_potentials['NonbondedForce']
nbene = nbfunc(positions, box, pairs, params)
print(nbene)
```
If everything works fine, you will get `-425.41412` as a result. In addition, you can also use `getPotentialFunc()` and `getParameters()` to obtain the whole potential energy function and force field parameter set, instead of seperated functions for different energy terms.
If everything works fine, you will get `-425.40470` as a result. In addition, you can also use `getPotentialFunc()` and `getParameters()` to obtain the whole potential energy function and force field parameter set, instead of seperated functions for different energy terms.
```python
efunc = potentials.getPotentialFunc()
params = ff.getParameters()
Expand All @@ -75,7 +75,7 @@ totene = efunc(positions, box, pairs, params)

## 3.2 Compute forces
Different from conventional programming frameworks, explicit definition of atomic force calculation functions are no longer needed. Instead, the forces can be evaluated in an automatic manner with `jax.grad`.
```
```python
pos_grad_func = jax.grad(efunc, argnums=0)
force = -pos_grad_func(positions, box, pairs, params)
```
Expand All @@ -85,22 +85,33 @@ Similarly, the derivative of energy with regard to force field parameters can al
```python
param_grad_func = jax.grad(nbfunc, argnums=-1)
pgrad = param_grad_func(positions, box, pairs, params)
print(pgrad["NonbondedForce"]["charge"])
print(pgrad["NonbondedForce"]["sigma"])
```

```python
[ 652.7753 55.108738 729.36115 -171.4929 502.70837
-44.917206 129.63994 -142.31796 -149.62088 453.21503
46.372574 140.15303 575.488 461.46902 294.4358
335.25153 27.828705 671.3637 390.8903 519.6835
220.51129 238.7695 229.97302 210.58838 231.8734
196.40994 237.08563 35.663574 457.76416 77.4798
256.54382 402.2121 611.9573 440.8465 -52.09662
421.86688 592.46265 237.98883 110.286194 150.65375
218.61087 240.20477 -211.85376 150.7331 310.89404
208.65228 -139.23026 -168.8883 114.3645 3.7261353
399.6282 298.28455 422.06445 526.18463 521.27563
575.85767 606.74744 394.40845 549.84033 556.4724
485.1427 512.1267 558.55896 560.4667 562.812
333.74194 ]
```
[ 1.12090099e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
7.57040892e+02 1.45521139e+03 0.00000000e+00 0.00000000e+00
6.78143151e+01 5.87935802e+01 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 4.97000516e+02
0.00000000e+00 0.00000000e+00 1.69941295e+01 0.00000000e+00
4.15689683e+02 1.07864961e+02 -1.05927404e+01 -3.34661347e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 1.95772900e+01
9.87994968e+01 0.00000000e+00 0.00000000e+00 0.00000000e+00
5.21105110e+01 0.00000000e+00 0.00000000e+00 0.00000000e+00
3.11528443e+01 5.66372398e+01 6.27484044e+02 0.00000000e+00
1.87121279e+02 0.00000000e+00 0.00000000e+00 1.16098707e+02
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 6.27866628e+01 5.10221034e+01
0.00000000e+00 0.00000000e+00 3.60011535e+01 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00 0.00000000e+00 0.00000000e+00 0.00000000e+00
0.00000000e+00]
```

0 comments on commit cc0a726

Please sign in to comment.