|
| 1 | +Running FlashMD in LAMMPS |
| 2 | +========================= |
| 3 | + |
| 4 | +Installation |
| 5 | +------------ |
| 6 | + |
| 7 | +Running in LAMMPS is supported starting from FlashMD 0.2.5. Make sure you have an |
| 8 | +updated version: |
| 9 | + |
| 10 | +```bash |
| 11 | + pip install flashmd --upgrade |
| 12 | +``` |
| 13 | + |
| 14 | +Next, you will need to install a version of LAMMPS with FlashMD enabled. Here, we focus |
| 15 | +on installing it quickly using conda with GPU acceleration via Kokkos. For other |
| 16 | +installation configurations (compiling from source, CPU-only, etc.), as well as more |
| 17 | +details, you can refer to this |
| 18 | +[page](https://docs.metatensor.org/metatomic/latest/engines/lammps.html#how-to-install-the-code). |
| 19 | + |
| 20 | +**Step 1** Find your GPU's architecture, either via the command |
| 21 | +``nvidia-smi --query-gpu=compute_cap --format=csv,noheader`` or by looking it up |
| 22 | +from this [page](https://developer.nvidia.com/cuda/gpus). Remove the . (dot) from the |
| 23 | +number you get and match it to the number from the following list: |
| 24 | +``VOLTA70, AMPERE80, AMPERE86, ADA89, HOPPER90``. For example, if you got 8.9, go for |
| 25 | +"ADA89". |
| 26 | + |
| 27 | +**Step 2** Run ``conda install -c metatensor -c conda-forge "lammps-metatomic=*=cuda*ADA89*nompi*"``, |
| 28 | +where you should replace ``ADA89`` with the string you found above. If you do not have |
| 29 | +conda yet, we recommend the [Miniforge](https://github.com/conda-forge/miniforge) conda provider. |
| 30 | +On HPC systems, it is safer to execute this command on a GPU-enabled compute (or debug) |
| 31 | +node, as sometimes nvidia drivers are not present on login nodes and this can prevent |
| 32 | +conda from installing the correct GPU libraries. |
| 33 | + |
| 34 | +You are now ready to run FlashMD in LAMMPS! |
| 35 | + |
| 36 | +**Note:** FlashMD in LAMMPS does not support running on multiple GPUs yet, and we are |
| 37 | +actively working on this feature. However, FlashMD supports between 120k and 300k atoms |
| 38 | +even on a single GPU on modern HPC clusters. |
| 39 | + |
| 40 | +**Note:** FlashMD in LAMMPS does not support running with exact energy conservation. You |
| 41 | +can use the i-PI and ASE interfaces if you need this functionality. |
| 42 | + |
| 43 | +Usage |
| 44 | +----- |
| 45 | + |
| 46 | +LAMMPS will need the FlashMD model and, in some cases, the energy model (MLIP) it was |
| 47 | +trained on. Here is how you can get them in the current directory from Python: |
| 48 | + |
| 49 | +```py |
| 50 | + from flashmd import get_pretrained |
| 51 | + |
| 52 | + time_step = 16 # in fs, also available: 1, 2, 4, 8, 32, 64, 128 |
| 53 | + energy_model, flashmd_model = get_pretrained("pet-omatpes", time_step) |
| 54 | + energy_model.save("mlip.pt") |
| 55 | + flashmd_model.save(f"flashmd-{time_step}.pt") |
| 56 | +``` |
| 57 | + |
| 58 | +**Note:** Stick to no more than 30x the time step that you would use in normal MD for your system! |
| 59 | + |
| 60 | +Here below you will see how to run different types of molecular dynamics. In all cases, |
| 61 | +you should launch LAMMPS as ``lmp -in in.flashmd -k on g 1 -pk kokkos newton on neigh half -sf kk`` |
| 62 | +(assuming your input file is named ``in.flashmd``), or ``lmp -in in.flashmd`` if you |
| 63 | +want to run without Kokkos acceleration. The following sections will present some input |
| 64 | +files that you can take inspiration from. Trivially, we advise you to consult the [LAMMPS |
| 65 | +documentation](https://docs.lammps.org) for further explanation of all the parameters. |
| 66 | + |
| 67 | +# NVT (Langevin thermostat) |
| 68 | + |
| 69 | +Langevin dynamics is conceptually one of the easiest methods to target the NVT ensemble |
| 70 | +in molecular dynamics. Here is an input file to use a Langevin thermostat with FlashMD: |
| 71 | + |
| 72 | +``` |
| 73 | +# Create a block of Al -- replace it with your system |
| 74 | +units metal |
| 75 | +atom_style atomic |
| 76 | +boundary p p p |
| 77 | +lattice fcc 4.05 |
| 78 | +region box block 0 5 0 5 0 5 |
| 79 | +create_box 1 box |
| 80 | +create_atoms 1 box |
| 81 | +
|
| 82 | +# Setting the energy model is useful if you want to have a look at the energy, but it |
| 83 | +# will slow down your simulation. Uncomment it if you need it. |
| 84 | +# pair_style metatomic mlip.pt device cuda non_conservative on |
| 85 | +# pair_coeff * * 13 |
| 86 | +
|
| 87 | +mass 1 26.9815386 |
| 88 | +
|
| 89 | +timestep 0.016 # 16 fs here, must match the time step of the FlashMD model! |
| 90 | +
|
| 91 | +velocity all create 700.0 12345 mom yes rot yes dist gaussian |
| 92 | +
|
| 93 | +fix 0 all metatomic flashmd-16.pt types 13 device cuda |
| 94 | +fix 1 all langevin 700.0 700.0 0.1 12345 |
| 95 | +
|
| 96 | +thermo 10 |
| 97 | +
|
| 98 | +run 1000 # runs 16 ps |
| 99 | +``` |
| 100 | + |
| 101 | +Here, the "13" appearing in ``pair_coeff`` and ``fix metatomic`` is the atomic number of |
| 102 | +Al. If you have a system with multiple LAMMPS types, you will need to replace "13" by the |
| 103 | +atomic numbers corresponding to the LAMMPS atom types, in order (e.g., often "8 1" for |
| 104 | +water simulations). |
| 105 | + |
| 106 | +The same goes for the mass. For example, for water, |
| 107 | +``` |
| 108 | +mass 1 15.9994 |
| 109 | +mass 2 1.008 |
| 110 | +``` |
| 111 | +FlashMD is not transferable across different masses. Therefore, if your atomic masses do |
| 112 | +not correspond to those used to train FlashMD (which are the standard atomic weights, |
| 113 | +i.e., abundance-weighted isotopic averages), an error will be raised. The same will |
| 114 | +happen if your time step does not match that of the FlashMD model. |
| 115 | + |
| 116 | +# NVT (CSVR thermostat) |
| 117 | + |
| 118 | +Although coupling a system with a Langevin thermostat samples the NVT ensemble |
| 119 | +correctly, it can alter the dynamical properties of the simulation. In contrast, the |
| 120 | +CSVR thermostat results in NVT sampling while leaving the dynamical properties largely |
| 121 | +unaffected. |
| 122 | + |
| 123 | +``` |
| 124 | +# Create a block of Al -- replace it with your system |
| 125 | +units metal |
| 126 | +atom_style atomic |
| 127 | +boundary p p p |
| 128 | +lattice fcc 4.05 |
| 129 | +region box block 0 5 0 5 0 5 |
| 130 | +create_box 1 box |
| 131 | +create_atoms 1 box |
| 132 | +
|
| 133 | +# Setting the energy model is useful if you want to have a look at the energy, but it |
| 134 | +# will slow down your simulation. Uncomment it if you need it. |
| 135 | +# pair_style metatomic mlip.pt device cuda non_conservative on |
| 136 | +# pair_coeff * * 13 |
| 137 | +
|
| 138 | +mass 1 26.9815386 |
| 139 | +
|
| 140 | +timestep 0.016 # 16 fs here, must match the time step of the FlashMD model! |
| 141 | +
|
| 142 | +velocity all create 700.0 12345 mom yes rot yes dist gaussian |
| 143 | +
|
| 144 | +fix 0 all metatomic flashmd-16.pt types 13 device cuda |
| 145 | +fix 1 all temp/csvr 700.0 700.0 0.1 12345 |
| 146 | +
|
| 147 | +thermo 10 |
| 148 | +
|
| 149 | +run 1000 # runs 16 ps |
| 150 | +``` |
| 151 | + |
| 152 | +Beware! When using the CSVR thermostat, although FlashMD will still very often be |
| 153 | +qualitatively correct, the dynamical properties of the simulation might be |
| 154 | +quantitatively off, especially when using large time steps. When using this thermostat, |
| 155 | +you should confirm any findings with normal MD: uncomment the ``pair_style`` and |
| 156 | +``pair_coeff`` lines, remove ``non_conservative on``, replace the ``fix metatomic`` line |
| 157 | +with ``fix 0 all nve`` and you will be ready to run traditional MD with the r2SCAN model |
| 158 | +that FlashMD was trained on. |
| 159 | + |
| 160 | +# NPT |
| 161 | + |
| 162 | +To run NPT, just add a pressure-control fix to the simulation. For example: |
| 163 | + |
| 164 | +``` |
| 165 | +# Create a block of Al -- replace it with your system |
| 166 | +units metal |
| 167 | +atom_style atomic |
| 168 | +boundary p p p |
| 169 | +lattice fcc 4.05 |
| 170 | +region box block 0 5 0 5 0 5 |
| 171 | +create_box 1 box |
| 172 | +create_atoms 1 box |
| 173 | +
|
| 174 | +# Setting the energy model is useful if you want to have a look at the energy, but it |
| 175 | +# will slow down your simulation. Uncomment it if you need it. |
| 176 | +pair_style metatomic mlip.pt device cuda |
| 177 | +pair_coeff * * 13 |
| 178 | +
|
| 179 | +mass 1 26.9815386 |
| 180 | +
|
| 181 | +timestep 0.016 # 16 fs here, must match the time step of the FlashMD model! |
| 182 | +
|
| 183 | +velocity all create 700.0 12345 mom yes rot yes dist gaussian |
| 184 | +
|
| 185 | +fix 0 all metatomic flashmd-16.pt types 13 device cuda |
| 186 | +fix 1 all langevin 700.0 700.0 0.1 12345 # or CSVR |
| 187 | +fix 2 all press/langevin iso 1.0 1.0 1.0 temp 700.0 700.0 67890 |
| 188 | +
|
| 189 | +thermo 10 |
| 190 | +
|
| 191 | +run 1000 # runs 16 ps |
| 192 | +``` |
| 193 | + |
| 194 | +Note that this time we uncommented the lines defining the energy model: |
| 195 | +``` |
| 196 | +pair_style metatomic mlip.pt device cuda |
| 197 | +pair_coeff * * 13 |
| 198 | +``` |
| 199 | +(and we removed ``non_conservative on``). This is because the energy model is used to |
| 200 | +provide stresses for pressure control. This will slow your simulation down quite a |
| 201 | +bit, but we are actively working to make NPT dynamics with FlashMD more efficient! |
| 202 | + |
| 203 | +# Metadynamics using PLUMED |
| 204 | + |
| 205 | +To run metadynamics with PLUMED, you can just add a PLUMED fix to the simulation. |
| 206 | +For example: |
| 207 | + |
| 208 | +``` |
| 209 | +fix 0 all metatomic flashmd-16.pt types 13 device cuda |
| 210 | +fix 1 all langevin 700.0 700.0 0.1 12345 |
| 211 | +fix 2 all plumed plumedfile plumed.dat outfile plumed.log |
| 212 | +``` |
0 commit comments