Skip to content

Commit

Permalink
add zero force gotcha
Browse files Browse the repository at this point in the history
  • Loading branch information
jkitchin committed Sep 5, 2023
1 parent 634e62b commit 2fe77bb
Showing 1 changed file with 165 additions and 3 deletions.
168 changes: 165 additions & 3 deletions ocp-tutorial/gotchas.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -568,11 +568,173 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 12,
"id": "fab9bb13",
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/cgcnn_200k.pt\n",
"CGCNN 200k 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/cgcnn_2M.pt\n",
"CGCNN 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"CGCNN 20M argument of type 'NoneType' is not iterable\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/cgcnn_all.pt\n",
"CGCNN All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/dimenet_200k.pt\n",
"DimeNet 200k 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/dimenet_2M.pt\n",
"DimeNet 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/schnet_200k.pt\n",
"SchNet 200k 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/schnet_2M.pt\n",
"SchNet 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/schnet_20M.pt\n",
"SchNet 20M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2020_11/s2ef/schnet_all_large.pt\n",
"SchNet All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_02/s2ef/dimenetpp_200k.pt\n",
"DimeNet++ 200k 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_02/s2ef/dimenetpp_2M.pt\n",
"DimeNet++ 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_02/s2ef/dimenetpp_20M.pt\n",
"DimeNet++ 20M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_02/s2ef/dimenetpp_all.pt\n",
"DimeNet++ All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_12/s2ef/spinconv_force_centric_2M.pt\n",
"SpinConv 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_08/s2ef/spinconv_force_centric_all.pt\n",
"SpinConv All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_12/s2ef/gemnet_t_direct_h512_2M.pt\n",
"GemNet-dT 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2021_08/s2ef/gemnet_t_direct_h512_all.pt\n",
"GemNet-dT All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"PaiNN All argument of type 'NoneType' is not iterable\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2022_07/s2ef/gemnet_oc_base_s2ef_2M.pt\n",
"GemNet-OC 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2022_07/s2ef/gemnet_oc_base_s2ef_all.pt\n",
"GemNet-OC All 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/gemnet_oc_base_s2ef_all_md.pt\n",
"GemNet-OC All+MD 'utf-8' codec can't decode byte 0x80 in position 128: invalid start byte\n",
"GemNet-OC-Large All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/scn_t1_b1_s2ef_2M.pt\n",
"SCN 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"SCN-t4-b2 2M argument of type 'NoneType' is not iterable\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/scn_all_md_s2ef.pt\n",
"SCN All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"eSCN-L4-M2-Lay12 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/escn_l6_m2_lay12_2M_s2ef.pt\n",
"eSCN-L6-M2-Lay12 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/escn_l6_m2_lay12_all_md_s2ef.pt\n",
"eSCN-L6-M2-Lay12 All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"eSCN-L6-M3-Lay20 All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_06/oc20/s2ef/eq2_83M_2M.pt\n",
"EquiformerV2 (83M) 2M 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_06/oc20/s2ef/eq2_31M_ec4_allmd.pt\n",
"EquiformerV2 (31M) All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_06/oc20/s2ef/eq2_153M_ec4_allmd.pt\n",
"EquiformerV2 (153M) All+MD 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2022_09/oc22/s2ef/gndt_oc22_all_s2ef.pt\n",
"GemNet-dT OC22 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"GemNet-OC OC22 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"GemNet-OC OC20+OC22 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_05/oc22/s2ef/gnoc_oc22_oc20_all_s2ef.pt\n",
"GemNet-OC trained with `enforce_max_neighbors_strictly=False` #467 OC20+OC22 'utf-8' codec can't decode byte 0x80 in position 128: invalid start byte\n",
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2022_09/oc22/s2ef/gnoc_finetune_all_s2ef.pt\n",
"GemNet-OC OC20->OC22 'utf-8' codec can't decode byte 0x80 in position 64: invalid start byte\n"
]
}
],
"source": [
"%run ocp-tutorial.ipynb\n",
"\n",
"import os\n",
"from ocpmodels.common.relaxation.ase_utils import OCPCalculator\n",
"\n",
"for ckp in checkpoints:\n",
" try:\n",
" checkpoint = get_checkpoint(ckp)\n",
" calc = OCPCalculator(checkpoint, cpu=True)\n",
" except Exception as exc:\n",
" print(ckp, exc)\n",
" finally:\n",
" os.unlink(checkpoint)"
]
},
{
"cell_type": "markdown",
"id": "dcec19f0",
"metadata": {},
"source": [
"# The forces don't sum to zero\n",
"\n",
"In DFT, the forces on all the atoms should sum to zero; otherwise, there is a net translational or rotational force present. This is not enforced in OCP models. Instead, individual forces are predicted, with no constraint that they sum to zero. If the force predictions are very accurate, then they sum close to zero. You can further improve this if you subtract the mean force from each atom."
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "30e35f91",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Downloading https://dl.fbaipublicfiles.com/opencatalystproject/models/2023_03/s2ef/escn_l6_m3_lay20_all_md_s2ef.pt\n"
]
},
{
"data": {
"text/plain": [
"array([-0.00371197, -0.01800631, 0.01127684], dtype=float32)"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"%run ocp-tutorial.ipynb\n",
"checkpoint = get_checkpoint('eSCN-L6-M3-Lay20 All+MD')\n",
"\n",
"from ocpmodels.common.relaxation.ase_utils import OCPCalculator\n",
"calc = OCPCalculator(checkpoint=os.path.expanduser(checkpoint), cpu=True)\n",
"\n",
"from ase.build import fcc111, add_adsorbate\n",
"from ase.optimize import BFGS\n",
"slab = fcc111('Pt', size=(2, 2, 5), vacuum=10.0)\n",
"add_adsorbate(slab, 'O', height=1.2, position='fcc')\n",
"slab.set_calculator(calc)\n",
"\n",
"f = slab.get_forces()\n",
"f.sum(axis=0)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "3b99f9ac",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.2270175e-07, 7.5437129e-08, -1.1920929e-07], dtype=float32)"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# This makes them sum closer to zero by removing net translational force\n",
"(f - f.mean(axis=0)).sum(axis=0)"
]
}
],
"metadata": {
Expand Down

0 comments on commit 2fe77bb

Please sign in to comment.