| 1 |
/* */ |
| 2 |
/* KIM-API: An API for interatomic models */ |
| 3 |
/* Copyright (c) 2013--2022, Regents of the University of Minnesota. */ |
| 4 |
/* All rights reserved. */ |
| 5 |
/* */ |
| 6 |
/* Contributors: */ |
| 7 |
/* Ryan S. Elliott */ |
| 8 |
/* Ellad B. Tadmor */ |
| 9 |
/* Daniel Karls */ |
| 10 |
/* */ |
| 11 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 12 |
/* */ |
| 13 |
/* This library is free software; you can redistribute it and/or */ |
| 14 |
/* modify it under the terms of the GNU Lesser General Public */ |
| 15 |
/* License as published by the Free Software Foundation; either */ |
| 16 |
/* version 2.1 of the License, or (at your option) any later version. */ |
| 17 |
/* */ |
| 18 |
/* This library is distributed in the hope that it will be useful, */ |
| 19 |
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */ |
| 20 |
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */ |
| 21 |
/* Lesser General Public License for more details. */ |
| 22 |
/* */ |
| 23 |
/* You should have received a copy of the GNU Lesser General Public License */ |
| 24 |
/* along with this library; if not, write to the Free Software Foundation, */ |
| 25 |
/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 26 |
/* */ |
| 27 |
|
| 28 |
/* */ |
| 29 |
/* Release: This file is part of the kim-api.git repository. */ |
| 30 |
/* */ |
| 31 |
|
| 32 |
/** |
| 33 |
\page implementation Implementation |
| 34 |
|
| 35 |
Previous Section: \ref theory. |
| 36 |
|
| 37 |
\anchor kim_api_pmi |
| 38 |
## The KIM API Portable Model Interface (KIM API/PMI) |
| 39 |
|
| 40 |
In code, Portable Models (PMs) and Model Drivers (MDs) consist of up to eight |
| 41 |
routines which perform specific tasks. |
| 42 |
|
| 43 |
-# The <em>ModelCreate</em> (or \em ModelDriverCreate ) routine (required), |
| 44 |
which performs initialization tasks for the KIM::Model object. |
| 45 |
|
| 46 |
-# The <em>ModelComputeArgumentsCreate</em> routine (required), which performs |
| 47 |
initialization tasks for a KIM::ComputeArguments object. |
| 48 |
|
| 49 |
-# The \em ModelCompute routine (required), which uses the configuration |
| 50 |
information stored in a KIM::ComputeArguments object to perform the PM's |
| 51 |
core computational tasks. |
| 52 |
|
| 53 |
-# The <em>ModelExtension</em> routine (optional), which provides a mechanism |
| 54 |
for creating and using non-standard extensions to the %KIM API. |
| 55 |
|
| 56 |
-# The <em>ModelRefresh</em> routine (required if parameter pointers are set, |
| 57 |
otherwise should not be provided), which performs updates after a simulator |
| 58 |
makes changes to the PM's parameters (if this is supported). |
| 59 |
|
| 60 |
-# The <em>ModelWriteParameterizedModel</em> (optional) routine, which can be |
| 61 |
used to write the parameter files and CMake file necessary to create a new |
| 62 |
parameterized PM from the current set of in-memory parameters. |
| 63 |
|
| 64 |
-# The \em ModelComputeArgumentsDestroy routine (required), which performs |
| 65 |
finalization tasks for a KIM::ComputeArguments object. |
| 66 |
|
| 67 |
-# The <em>ModelDestroy</em> routine (required), which performs finalization |
| 68 |
tasks for the KIM::Model object. |
| 69 |
|
| 70 |
The %KIM API/PMI provides a separate interface to be used by the PM or MD. For |
| 71 |
each of the routines itemized above, the following table lists (i) the |
| 72 |
associated KIM::ModelRoutineName extensible enumeration constant, (ii) links to |
| 73 |
the associated %KIM API/PMI interface(s) available within the routine, (iii) |
| 74 |
links to the routine's prototype (in C++, C, and Fortran), and (iv) whether the |
| 75 |
%KIM API/PMI requires a PM or MD to provide the routine, or if it is optional. |
| 76 |
|
| 77 |
<table><caption align=top></caption> |
| 78 |
<tr> |
| 79 |
<th> |
| 80 |
Model Routine Name constant |
| 81 |
</th><th> |
| 82 |
%KIM API/PMI Interface |
| 83 |
</th><th> |
| 84 |
Routine prototype (C++; C; Fortran) |
| 85 |
</th><th> |
| 86 |
%KIM API/PMI Required / Optional |
| 87 |
</th> |
| 88 |
</tr> |
| 89 |
<tr> |
| 90 |
<td> |
| 91 |
KIM::MODEL_ROUTINE_NAME::Create |
| 92 |
</td><td> |
| 93 |
KIM::ModelCreate or |
| 94 |
<br> |
| 95 |
KIM::ModelDriverCreate |
| 96 |
</td><td> |
| 97 |
KIM::ModelCreateFunction, |
| 98 |
<br> |
| 99 |
KIM::ModelDriverCreateFunction; |
| 100 |
<br> |
| 101 |
\ref KIM_ModelCreateFunction, |
| 102 |
<br> |
| 103 |
\ref KIM_ModelDriverCreateFunction; |
| 104 |
<br> |
| 105 |
kim_model_module::kim_model_create |
| 106 |
</td><td> |
| 107 |
required |
| 108 |
</td> |
| 109 |
</tr> |
| 110 |
<tr> |
| 111 |
<td> |
| 112 |
KIM::MODEL_ROUTINE_NAME::ComputeArgumentsCreate |
| 113 |
</td><td> |
| 114 |
KIM::ModelComputeArgumentsCreate |
| 115 |
</td><td> |
| 116 |
KIM::ModelComputeArgumentsCreateFunction; |
| 117 |
<br> |
| 118 |
\ref KIM_ModelComputeArgumentsCreateFunction; |
| 119 |
<br> |
| 120 |
kim_model_module::kim_model_compute_arguments_create |
| 121 |
</td><td> |
| 122 |
required |
| 123 |
</td> |
| 124 |
</tr> |
| 125 |
<tr> |
| 126 |
<td> |
| 127 |
KIM::MODEL_ROUTINE_NAME::Compute |
| 128 |
</td><td> |
| 129 |
KIM::ModelCompute and |
| 130 |
<br> |
| 131 |
KIM::ModelComputeArguments |
| 132 |
</td><td> |
| 133 |
KIM::ModelComputeFunction; |
| 134 |
<br> |
| 135 |
\ref KIM_ModelComputeFunction; |
| 136 |
<br> |
| 137 |
kim_model_module::kim_model_compute |
| 138 |
</td><td> |
| 139 |
required |
| 140 |
</td> |
| 141 |
</tr> |
| 142 |
<tr> |
| 143 |
<td> |
| 144 |
KIM::MODEL_ROUTINE_NAME::Extension |
| 145 |
</td><td> |
| 146 |
KIM::ModelExtension |
| 147 |
</td><td> |
| 148 |
KIM::ModelExtensionFunction; |
| 149 |
<br> |
| 150 |
\ref KIM_ModelExtensionFunction; |
| 151 |
<br> |
| 152 |
kim_model_module::kim_model_extension |
| 153 |
</td><td> |
| 154 |
optional |
| 155 |
</td> |
| 156 |
</tr> |
| 157 |
<tr> |
| 158 |
<td> |
| 159 |
KIM::MODEL_ROUTINE_NAME::Refresh |
| 160 |
</td><td> |
| 161 |
KIM::ModelRefresh |
| 162 |
</td><td> |
| 163 |
KIM::ModelRefreshFunction; |
| 164 |
<br> |
| 165 |
\ref KIM_ModelRefreshFunction; |
| 166 |
<br> |
| 167 |
kim_model_module::kim_model_clear_then_refresh |
| 168 |
</td><td> |
| 169 |
required if one or more parameter pointers set, |
| 170 |
otherwise should not be provided |
| 171 |
</td> |
| 172 |
</tr> |
| 173 |
<tr> |
| 174 |
<td> |
| 175 |
KIM::MODEL_ROUTINE_NAME::WriteParameterizedModel |
| 176 |
</td><td> |
| 177 |
KIM::ModelWriteParameterizedModel |
| 178 |
</td><td> |
| 179 |
KIM::ModelWriteParameterizedModelFunction; |
| 180 |
<br> |
| 181 |
\ref KIM_ModelWriteParameterizedModelFunction; |
| 182 |
<br> |
| 183 |
kim_model_module::kim_model_write_parameterized_model |
| 184 |
</td><td> |
| 185 |
optional |
| 186 |
</td> |
| 187 |
</tr> |
| 188 |
<tr> |
| 189 |
<td> |
| 190 |
KIM::MODEL_ROUTINE_NAME::ComputeArgumentsDestroy |
| 191 |
</td><td> |
| 192 |
KIM::ModelComputeArgumentsDestroy |
| 193 |
</td><td> |
| 194 |
KIM::ModelComputeArgumentsDestroyFunction; |
| 195 |
<br> |
| 196 |
\ref KIM_ModelComputeArgumentsDestroyFunction; |
| 197 |
<br> |
| 198 |
kim_model_module::kim_model_compute_arguments_destroy |
| 199 |
</td><td> |
| 200 |
required |
| 201 |
</td> |
| 202 |
</tr> |
| 203 |
<tr> |
| 204 |
<td> |
| 205 |
KIM::MODEL_ROUTINE_NAME::Destroy |
| 206 |
</td><td> |
| 207 |
KIM::ModelDestroy |
| 208 |
</td><td> |
| 209 |
KIM::ModelDestroyFunction; |
| 210 |
<br> |
| 211 |
\ref KIM_ModelDestroyFunction; |
| 212 |
<br> |
| 213 |
kim_model_module::kim_model_destroy |
| 214 |
</td><td> |
| 215 |
required |
| 216 |
</td> |
| 217 |
</tr> |
| 218 |
</table> |
| 219 |
|
| 220 |
The above table also indicates which routines must be provided by a PM. For |
| 221 |
optional routines, each PM must indicate that the routine is required or |
| 222 |
optional for use by the simulator, as described below. |
| 223 |
|
| 224 |
\note **Language restrictions implied by the %KIM API/PMI:** |
| 225 |
<br> |
| 226 |
The %KIM API/PMI implements a cross-language object-oriented-like framework. |
| 227 |
All persistent data (analogous to member variables) needed by a PM or MD object |
| 228 |
must be stored using the \ref cache_buffer_pointers "Caching Capabilities" of |
| 229 |
the %KIM API. For the framework to operate correctly, without surprising |
| 230 |
behavior, PM and MD implementations must obey certain restrictions as described |
| 231 |
below. |
| 232 |
|
| 233 |
\note |
| 234 |
- C++ |
| 235 |
|
| 236 |
The use of static and/or global variables within PM and MD code must be |
| 237 |
avoided. |
| 238 |
|
| 239 |
- C |
| 240 |
|
| 241 |
The use of static and/or global variables within PM and MD code must be |
| 242 |
avoided. |
| 243 |
|
| 244 |
- Fortran |
| 245 |
|
| 246 |
The use of COMMON blocks must be avoided. The use of the SAVE attribute must |
| 247 |
be avoided. Thus, variables should not be initialized when they are declared |
| 248 |
(as this implies the SAVE attribute). Further, the use of module variables, |
| 249 |
except for those defined with the PARAMETER attribute, must be avoided. (The |
| 250 |
Fortran 2008 standard requires that all module variables, implicitly, have |
| 251 |
the SAVE attribute; that is, they are stored in static memory.) Similarly, |
| 252 |
all Fortran subroutines and functions should have the RECURSIVE attribute |
| 253 |
(this is the default starting only with the Fortran 2015 standard). This is |
| 254 |
because without the RECURSIVE attribute compilers are allowed to use static |
| 255 |
memory for a subroutine's/function's local variables (effectively giving them |
| 256 |
the SAVE attribute). |
| 257 |
|
| 258 |
These restrictions are even more important if thread-safety is required. The |
| 259 |
use of RECURSIVE subroutines/functions and avoidance of using the SAVE |
| 260 |
attribute help to assure that memory access conflicts are averted. |
| 261 |
|
| 262 |
|
| 263 |
The %KIM API/PMI provides two interfaces to be used by the Simulator, |
| 264 |
KIM::Model and KIM::ComputeArguments, for interacting with a PM. The |
| 265 |
interaction between the simulator and a PM involves the following steps: |
| 266 |
|
| 267 |
- A simulator creates a <em>Portable Model object</em>, by calling |
| 268 |
KIM::Model::Create, that will be used to exchange pointers to data and |
| 269 |
functions related to the PM between the simulator and PM. Creating this |
| 270 |
object includes the specification of how the simulator will number particles |
| 271 |
(zero-based or one-based), determination of the physical base units that the |
| 272 |
PM will use, and execution of the PM's <em>ModelCreate</em> routine. |
| 273 |
|
| 274 |
When calling KIM::Model::Create to create a <em>PM object</em>, the simulator |
| 275 |
provides a set of "requested" base units that it would prefer to use. |
| 276 |
<em>The %KIM API/PMI gives the PM final authority to decide on the base units |
| 277 |
it will use.</em> Best practice for PMs is to respect the request of the |
| 278 |
simulator and to use the requested base units by converting its parameters |
| 279 |
appropriately. The \c requestedUnitsAccepted output argument of the |
| 280 |
KIM::Model::Create routine is a convenience that allows the simulator a |
| 281 |
short-cut to determine if its request for base units was accepted. (The |
| 282 |
alternative is for the simulator to call to KIM::Model::GetUnits and compare |
| 283 |
the results to the requested units.) |
| 284 |
|
| 285 |
If a base unit is not relevant to the simulator (e.g., a unit of time is not |
| 286 |
necessary for static equilibrium computations), then the simulator should |
| 287 |
specify that the corresponding requested base unit(s) is/are "unused". |
| 288 |
Similarly, if a base unit is irrelevant to the PM (e.g., many models only |
| 289 |
require units of length and energy; Thus, units of charge, temperature, and |
| 290 |
time are irrelevant), then the PM should specify that the corresponding base |
| 291 |
unit(s) is/are "unused" (regardless of the simulator's requested values) when |
| 292 |
calling KIM::ModelCreate::SetUnits within its <em>ModelCreate</em> routine. |
| 293 |
Additionally, the PM should select its preferred (non-"unused") base unit |
| 294 |
value when the simulator provides a request of "unused" for a relevant base |
| 295 |
unit. |
| 296 |
|
| 297 |
The %KIM API/PMI supports "Toy Models", which are a deliberately simplistic |
| 298 |
model with many details removed so that it can be used to explain a mechanism |
| 299 |
concisely. Toy models do not model a real material, but are rather |
| 300 |
associated with a class of materials (e.g., glasses). Toy PMs should use the |
| 301 |
"user" species values (KIM::SPECIES_NAME::user01 through |
| 302 |
KIM::SPECIES_NAME::user20). Some toy models are formulated to be |
| 303 |
nondimensional. Rather than introducing a new type of nondimensional units |
| 304 |
to the %KIM API/PMI with accompanying requirements for simulators to support |
| 305 |
this, toy PMs should define their length base unit as KIM::LENGTH_UNIT::A and |
| 306 |
their energy base unit as KIM::ENERGY_UNIT::eV. From the perspective of the |
| 307 |
toy PM these can be considered proxy units (similar to Lennard-Jones units). |
| 308 |
(See also [Toy Model support within |
| 309 |
openkim.org](https://openkim.org/about-toy-models).) |
| 310 |
|
| 311 |
- Once a PM object is obtained, the simulator should use |
| 312 |
KIM::Model::IsRoutinePresent to determine which routines the PM has provided |
| 313 |
and if they are required or optional. From this information the simulator |
| 314 |
should determine if it can proceed to work with the PM, or if the PM requires |
| 315 |
the use of routines that are not supported by the simulator it should exit. |
| 316 |
|
| 317 |
- Next, the simulator creates a <em>KIM::ComputeArguments object</em>, by |
| 318 |
calling KIM::Model::ComputeArgumentsCreate, that will be used to exchange |
| 319 |
pointers to data and functions related to the atomic configuration and values |
| 320 |
being computed for it. Creating this object includes execution of the PM's |
| 321 |
<em>ModelComputeArgumentsCreate</em> routine. |
| 322 |
|
| 323 |
- Then, to perform a computation, the simulator provides a compute-arguments |
| 324 |
object to the KIM::Model::Compute routine (which, in part, executes the PM's |
| 325 |
<em>ModelCompute</em> function). |
| 326 |
|
| 327 |
- There are input compute-arguments that include the various components that |
| 328 |
make up a configuration (number of particles, particle position vectors, |
| 329 |
etc.). |
| 330 |
|
| 331 |
- There are output compute-arguments that include the quantities (like partial |
| 332 |
energy and partial forces), defined in Section \ref theory, associated with |
| 333 |
the configuration. |
| 334 |
|
| 335 |
- There are also compute-callback functions (such as a function to get a |
| 336 |
particle's neighbor list) that the simulator provides for use by the PM. |
| 337 |
|
| 338 |
- When a simulator is finished working with a PM, it needs to clean up by |
| 339 |
calling KIM::Model::ComputeArgumentsDestroy (which, in part, executes the |
| 340 |
PM's <em>ModelComputeArgumentsDestroy</em> routine) to delete each of the |
| 341 |
compute-arguments objects that were created, and finally calling |
| 342 |
KIM::Model::Destroy (which, in part, executes the PM's <em>ModelDestroy</em> |
| 343 |
routine) to delete the KIM::Model object. |
| 344 |
|
| 345 |
The %KIM API/PMI provides a list of all compute-arguments and compute-callbacks |
| 346 |
defined as part of the official API. Each argument and callback has a "Support |
| 347 |
Status" that can be one of four values: <em>requiredByAPI</em>, |
| 348 |
<em>notSupported</em>, <em>required</em>, or <em>optional</em>. A PM specifies |
| 349 |
a support status value, as part of its <em>ModelComputeArgumentsCreate</em> |
| 350 |
routine, for every compute-argument and compute-callback defined by the %KIM |
| 351 |
API/PMI. Some arguments and callbacks are required by the %KIM API and can |
| 352 |
only have a support status of <em>requiredByAPI</em>. All other arguments and |
| 353 |
callbacks are not required by the %KIM API/PMI, and therefore the PM may set |
| 354 |
their support status to any one of the three remaining options: |
| 355 |
<em>required</em>, <em>optional</em>, or <em>notSupported</em>. Just before |
| 356 |
the PM's <em>ModelComputeArgumentsCreate</em> routine is executed, the %KIM |
| 357 |
API/PMI initializes the support status of all arguments and callbacks to either |
| 358 |
<em>requiredByAPI</em> or <em>notSupported</em>, as indicated in the below |
| 359 |
tables. It is the responsibility of the simulator to use the |
| 360 |
KIM::ComputeArguments object interface to determine the support status of each |
| 361 |
compute-argument and compute-callback and to use this information to determine |
| 362 |
if the PM is capable of performing the desired computation. |
| 363 |
|
| 364 |
Below, lists of each input compute-argument, output compute-argument, and |
| 365 |
compute-callback are provided. To be explicit, zero-based particle |
| 366 |
numbering is used where necessary. |
| 367 |
|
| 368 |
Input compute-argument table: |
| 369 |
| Compute Argument Name | Unit | Data Type | Extent | Memory Layout | Valid Support Statuses (bold -- default) | |
| 370 |
| --------------------- | ------ | --------- | --------------------- | ------------------------------------------------------------------ | ---------------------------------------- | |
| 371 |
| numberOfParticles | N/A | integer | 1 | | <b>requiredByAPI</b> | |
| 372 |
| particleSpeciesCodes | N/A | integer | numberOfParticles | \f$sc^{(0)}, sc^{(1)}, \dots\f$ | <b>requiredByAPI</b> | |
| 373 |
| particleContributing | N/A | integer | numberOfParticles | \f$c^{(0)}, c^{(1)}, \dots\f$ | <b>requiredByAPI</b> | |
| 374 |
| coordinates | length | double | numberOfParticles * 3 | \f$r^{(0)}_1, r^{(0)}_2, r^{(0)}_3, r^{(1)}_1, r^{(1)}_2, \dots\f$ | <b>requiredByAPI</b> | |
| 375 |
|
| 376 |
- numberOfParticles is the number of particles (contributing and |
| 377 |
non-contributing) in the configuration. |
| 378 |
|
| 379 |
- particleSpeciesCodes contains integer codes (as defined by the PM) specifying |
| 380 |
the species of each particle. For example, if the PM defines the mapping Cu |
| 381 |
\f$\leftrightarrow 1\f$, Al \f$\leftrightarrow 2\f$, and Ni \f$\leftrightarrow |
| 382 |
3\f$, then \f$sc^{(0)} = 3, sc^{(1)} = 1, sc^{(2)} = 2, \dots\f$ means that |
| 383 |
particle 0 is a nickel atom, particle 1 is a copper atom, particle 2 is an |
| 384 |
aluminum atom. |
| 385 |
|
| 386 |
- particleContributing contains the contributing/non-contributing status |
| 387 |
of each particle. Particle \f$i\f$ is contributing if \f$c^{(i)} = 1\f$ and |
| 388 |
non-contributing if \f$c^{(i)} = 0\f$. |
| 389 |
|
| 390 |
- coordinates contains the Cartesian components of the particles' position |
| 391 |
vectors, \f$\mathbf{r}^{(i)} = r^{(i)}_1 \mathbf{e}_1 + r^{(i)}_2 |
| 392 |
\mathbf{e}_2 + r^{(i)}_3 \mathbf{e}_3\f$. |
| 393 |
|
| 394 |
Output compute-argument table: |
| 395 |
| Compute Argument Name | Unit | Data Type | Extent | Memory Layout | Valid Support Statuses (bold -- default) | |
| 396 |
| ---------------------------------------------------- | -------------------------- | --------- | --------------------- | ----------------------------------------------------------------------- | ---------------------------------------- | |
| 397 |
| \ref partial_energy "partialEnergy" | energy | double | 1 | | required, optional, <b>notSupported</b> | |
| 398 |
| \ref partial_forces "partialForces" | force | double | numberOfParticles * 3 | \f$f^{\mathcal{C}(0)}_1, f^{\mathcal{C}(0)}_2, f^{\mathcal{C}(0)}_3, f^{\mathcal{C}(1)}_1, f^{\mathcal{C}(1)}_2\dots\f$ | required, optional, <b>notSupported</b> | |
| 399 |
| \ref partial_particle_energy "partialParticleEnergy" | energy | double | numberOfParticles | \f$E^{\mathcal{C}}_0, E^{\mathcal{C}}_1, E^{\mathcal{C}}_2, \dots\f$ | required, optional, <b>notSupported</b> | |
| 400 |
| \ref partial_virial "partialVirial" | energy | double | 6 | \f$V^{\mathcal{C}}_{11}, V^{\mathcal{C}}_{22}, V^{\mathcal{C}}_{33}, V^{\mathcal{C}}_{23}, V^{\mathcal{C}}_{31}, V^{\mathcal{C}}_{12}\f$ | required, optional, <b>notSupported</b> | |
| 401 |
| \ref partial_particle_virial "partialParticleVirial" | energy | double | numberOfParticles * 6 | \f$\mathbf{V}^{\mathcal{C}(0)}, \mathbf{V}^{\mathcal{C}(1)}, \mathbf{V}^{\mathcal{C}(2)}, \dots\f$ | required, optional, <b>notSupported</b> | |
| 402 |
|
| 403 |
- partialEnergy is the configuration's partial energy \f$E^{\mathcal{C}}\f$. |
| 404 |
|
| 405 |
- partialForces contains the partial force vector for each particle, |
| 406 |
\f$\mathbf{f}^{\mathcal{C}(i)} = f^{\mathcal{C}(i)}_1 \mathbf{e}_1 + |
| 407 |
f^{\mathcal{C}(i)}_2 \mathbf{e}_2 + f^{\mathcal{C}(i)}_3 \mathbf{e}_3\f$. |
| 408 |
|
| 409 |
- partialParticleEnergy contains the partial particle energy for each particle, |
| 410 |
\f$E^{\mathcal{C}}_i\f$. |
| 411 |
|
| 412 |
- partialVirial is the configuration's partial virial tensor, |
| 413 |
\f$\mathbf{V}^{\mathcal{C}}\f$. |
| 414 |
|
| 415 |
- partialParticleVirial contains the partial particle virial tensor for each |
| 416 |
particle, \f$\mathbf{V}^{\mathcal{C}(i)}\f$. |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
Compute-callback table: |
| 421 |
| Compute Callback Name | Valid Support Statuses (bold -- default) | |
| 422 |
| --------------------- | ---------------------------------------- | |
| 423 |
| GetNeighborList | <b>requiredByAPI</b> | |
| 424 |
| ProcessDEDrTerm | required, optional, <b>notSupported</b> | |
| 425 |
| ProcessD2EDr2Term | required, optional, <b>notSupported</b> | |
| 426 |
|
| 427 |
- GetNeighborList is a callback function that allows a PM to obtain the list of |
| 428 |
neighbors of a particle. The PM may request any number (\f$\ge1\f$) of |
| 429 |
neighbor lists with different (or equal) cutoff distances. The |
| 430 |
GetNeighborList callback function must support the return of the appropriate |
| 431 |
list of neighbors. The returned list of neighbors consists of a |
| 432 |
contiguous-in-memory list of integers corresponding to an unordered full list |
| 433 |
of a particle's neighbors (not including itself). Each such neighbor list |
| 434 |
must contain at least all particles within the corresponding cutoff distance |
| 435 |
of the specified particle. (However, the returned list may contain particles |
| 436 |
beyond the cutoff distance.) Neighbor lists provided by the simulator must |
| 437 |
be consistent with the configuration coordinates and the PM's cutoff values. |
| 438 |
In particular, the PM must, in principle, be able to independently construct |
| 439 |
its own equivalent neighbor list using just the particle coordinates. |
| 440 |
Further, the GetNeighborList callback routine must check to ensure that the |
| 441 |
neighbor list data (provided, via the simulator, by the compute-arguments |
| 442 |
object) is consistent with the PM's cutoff values. |
| 443 |
|
| 444 |
<b>CAUTION - SIMULATOR DEVELOPERS:</b> In general, it is important that |
| 445 |
neighbor lists provided by a simulator are "efficient" in the sense that the |
| 446 |
list contains only a small number of particles that are located outside the |
| 447 |
cutoff distance. If the lists are not efficient, then the PM computational |
| 448 |
time may be <em>severely</em> impacted. This is especially true for PMs that |
| 449 |
request multiple neighbor lists with a wide range of cutoff distances. |
| 450 |
|
| 451 |
<b>Neighbor List Hint \anchor neighbor_list_hint :</b> The above describes |
| 452 |
the default behavior and all PMs must work correctly when provided with |
| 453 |
neighbor lists of this type. However, based on the <em>neighbor list |
| 454 |
hint</em> provided by the PM a simulator may provide the PM with a modified |
| 455 |
neighbor list that is more efficient. If the PM sets its |
| 456 |
"modelWillNotRequestNeighborsOfNoncontributingParticles" value to 1 (true), |
| 457 |
it is guaranteeing that it will not request the neighbors of non-contributing |
| 458 |
particles. In this case, the simulator does not need to generate a neighbor |
| 459 |
list for such particles. The PM has no way of knowing if the simulator is |
| 460 |
taking advantage of its hint, so it must work correctly for all types of |
| 461 |
neighbor lists consistent with its provided hint. |
| 462 |
|
| 463 |
- ProcessDEDrTerm is a callback function that allows for access to the |
| 464 |
derivatives of the configuration's partial energy, \f$E^{\mathcal{C}}\f$, |
| 465 |
with respect to all pair-distances, \f$r^{(i,j)}, i,j \in C_{p}\f$. That is, |
| 466 |
it allows the PM to communicate the values of \f$\frac{\partial |
| 467 |
E^{\mathcal{C}}}{\partial r^{(i,j)}}\f$ to the simulator. Recall that |
| 468 |
\f$r^{(i,j)}\f$ and \f$r^{(j,i)}\f$ are just two different notations for the |
| 469 |
same quantity. Thus, there are only \f$\frac{\text{numberOfParticles} \cdot |
| 470 |
(\text{numberOfParticles} + 1)}{2}\f$ quantities (as opposed to |
| 471 |
\f$(\text{numberOfParticles})^2\f$) referred to by the notation |
| 472 |
\f$\frac{\partial E^{\mathcal{C}}}{\partial r^{(i,j)}}\f$. |
| 473 |
|
| 474 |
These quantities can be used to compute many quantities of interest |
| 475 |
associated with the configuration. For example, it is possible to |
| 476 |
independently compute the partial virial from this information using the |
| 477 |
formula |
| 478 |
|
| 479 |
\f[ |
| 480 |
\mathbf{V}^{\mathcal{C}} |
| 481 |
= \sum_{i \in C_p} \sum_{j \in \mathcal{N}^{(i)}_{r_{\text{infl}}}} \;\; |
| 482 |
\sum_{k \not= j; \; k \in \bar{\mathcal{N}}^{(i)}_{r_{\text{infl}}}} |
| 483 |
\left(\frac{1}{2 r^{(j,k)}} \frac{\partial \tilde{E}_i}{\partial r^{(j,k)}} |
| 484 |
\right) \mathbf{r}^{(j,k)} \otimes \mathbf{r}^{(j,k)}. |
| 485 |
\f] |
| 486 |
|
| 487 |
- ProcessD2EDr2Term is a callback function that allows for access to the second |
| 488 |
derivatives of the configuration's partial energy, \f$E^{\mathcal{C}}\f$, |
| 489 |
with respect to all pair-distances, \f$r^{(i,j)}, i,j \in C_{p}\f$. That is, |
| 490 |
it allows the PM to communicate the values of \f$\frac{\partial^2 |
| 491 |
E^{\mathcal{C}}}{\partial r^{(i,j)} \partial r^{(m,n)}}\f$ to the simulator. |
| 492 |
|
| 493 |
See the documentation of the KIM::Model and KIM::ComputeArguments interfaces |
| 494 |
for more details of the %KIM API/PMI from the simulator's perspective. |
| 495 |
|
| 496 |
See the documentation of the KIM::ModelCompute, KIM::ModelComputeArguments, |
| 497 |
KIM::ModelComputeArgumentsCreate, KIM::ModelComputeArgumentsDestroy, |
| 498 |
KIM::ModelCreate, KIM::ModelDestroy, KIM::ModelDriverCreate, |
| 499 |
KIM::ModelExtension, KIM::ModelRefresh, and KIM::ModelWriteParameterizedModel |
| 500 |
interfaces for more details of the %KIM API/PMI from the PM's perspective. |
| 501 |
|
| 502 |
\anchor kim_api_smi |
| 503 |
## The KIM API Simulator Model Interface (KIM API/SMI) |
| 504 |
|
| 505 |
In code, Simulator Models (SMs) are simply a set of <em>parameter files</em> |
| 506 |
and a <em>specification file</em> which contains simulator input commands and |
| 507 |
metadata (supported species, units, etc.) needed to run the model in its native |
| 508 |
simulator. |
| 509 |
|
| 510 |
The %KIM API/SMI consists of the KIM::SimulatorModel interface which provides |
| 511 |
programatic access to the SM's parameter files and the contents of its |
| 512 |
specification file. Conceptually, an SM specification file contains a series |
| 513 |
of key-value pairs. Some key-value pairs are defined and required by the %KIM |
| 514 |
API/SMI. All other key-value pairs are called "Simulator Fields". For |
| 515 |
flexibility and generality, the content and meaning of the simulator fields is |
| 516 |
not defined by the %KIM API/SMI. Instead, each simulator is free to create and |
| 517 |
define its own set of specifications. The value part of a simulator field |
| 518 |
key-value pair is one or more strings called "Simulator Field Lines". These |
| 519 |
strings may contain template tags (of the form "@<template-tag-key>@") which |
| 520 |
the KIM::SimulatorModel object will replace by performing template substitution |
| 521 |
using the "Template Map". The %KIM API/SMI defines a small set of template |
| 522 |
mappings which facilitate providing copies of the SM's parameter files to the |
| 523 |
simulator. Additionally, simulators may define their own template mappings and |
| 524 |
add these to the %KIM API/SMI's set to be used for template substitution. |
| 525 |
|
| 526 |
Although the %KIM API/SMI is designed for maximum flexibility, an example of |
| 527 |
one way it can be used by a simulator to support SMs is helpful. In |
| 528 |
particular, for the [LAMMPS](https://lammps.sandia.gov) simulator, performing a |
| 529 |
simulation with a specific model typically involves three separate parts: (1) |
| 530 |
specifying the physical units in which the model's parameters are given and |
| 531 |
therefore the units in which the simulation will be performed; (2) specifying |
| 532 |
other default properties needed by the model which must be set before the |
| 533 |
LAMMPS simulation box is defined, such as the LAMMPS atom style; and (3) |
| 534 |
specifying the `pair_style` or other style commands that define the model's |
| 535 |
interactions and read in the model's parameter files. Here is an example |
| 536 |
LAMMPS input file for the ReaxFF potential, similar to the CHO example included |
| 537 |
in the LAMMPS distribution. |
| 538 |
|
| 539 |
\code{.unparsed} |
| 540 |
# REAX potential for CHO system |
| 541 |
|
| 542 |
units real |
| 543 |
|
| 544 |
atom_style charge |
| 545 |
neigh_modify every 10 delay 0 check no |
| 546 |
|
| 547 |
neighbor 2 bin |
| 548 |
|
| 549 |
read_data data.CHO |
| 550 |
|
| 551 |
pair_style reax/c lmp_control |
| 552 |
pair_coeff * * ffield.reax.cho H C O |
| 553 |
fix reaxqeq all qeq/reax 1 0.0 10.0 1e-6 param.qeq |
| 554 |
|
| 555 |
fix 1 all nve |
| 556 |
fix 2 all temp/berendsen 500.0 500.0 100.0 |
| 557 |
|
| 558 |
timestep 0.25 |
| 559 |
|
| 560 |
run 100 |
| 561 |
\endcode |
| 562 |
|
| 563 |
In this case, the `units` line corresponds to (1) above. The `atom_style` and |
| 564 |
`neigh_modify` lines correspond to (2) above. And, the `pair_style`, |
| 565 |
`pair_coeff`, and `fix reaxqeq` lines correspond to (3) above. The strings |
| 566 |
"lmp_control", "ffield.reax.cho", and "param.qeq" are parameter file names |
| 567 |
(which are expected to be in the current working directory, since the names do |
| 568 |
not start with a '/'). Also of note is the string of parameters "H C O" on the |
| 569 |
`pair_coeff` line, which specifies a mapping between the species names "H", |
| 570 |
"C", and "O" used by the ReaxFF model and the LAMMPS atom type numbers 1, 2, |
| 571 |
and 3, respectively. The number of atom types and their species mapping are |
| 572 |
part of the simulation, not part of the model. In this case these values are |
| 573 |
specified within the "data.CHO" input file listed on the `read_data` line. |
| 574 |
Since the number of atom types and the species map can change from simulation |
| 575 |
to simulation, any LAMMPS %KIM SM implementation will need a way of specifying |
| 576 |
the atom type mapping on the `pair_coeff` line. |
| 577 |
|
| 578 |
The LAMMPS SM implementation accommodates all of these needs by defining three |
| 579 |
Simulator Fields, corresponding to the three parts of a LAMMPS model |
| 580 |
specification discussed above. (1) A "units" field, with a single line |
| 581 |
containing the LAMMPS unit system string required by the model. (2) A |
| 582 |
"model-init" field, with zero or more lines containing, in this case, the |
| 583 |
`atom_style` and `neigh_modify` commands. And (3) a "model-defn" field, with |
| 584 |
zero or more lines containing, in this case, the `pair_style`, `pair_coeff`, |
| 585 |
and `fix reaxqeq` commands. In the latter field lines, the correct parameter |
| 586 |
file names are obtained through the %KIM API/SMI's template substitution |
| 587 |
mechanism, using the standard template keys for the SM's parameter files. The |
| 588 |
correct atom type mapping is obtained through a special, LAMMPS defined, |
| 589 |
template map with key "atom-type-sym-list". The result of all of these |
| 590 |
considerations and definitions is the following SM specification file (see the |
| 591 |
\ref kim_api_sm_schema_version_1 "KIM API/SMI Specification File Schema" for |
| 592 |
details of the file format) for the LAMMPS ReaxFF model. |
| 593 |
|
| 594 |
\code{.edn} |
| 595 |
{ |
| 596 |
"kim-api-sm-schema-version" 1 |
| 597 |
"model-name" "Sim_LAMMPS_ReaxFF_ChenowethVanDuinGoddard_2008_CHO__SM_584143153761_000" |
| 598 |
"simulator-name" "LAMMPS" |
| 599 |
"simulator-version" "28 Feb 2019" |
| 600 |
"supported-species" "C H O" |
| 601 |
"units" "real" |
| 602 |
"model-init" [ "atom_style charge" |
| 603 |
"neigh_modify one 4000" |
| 604 |
] |
| 605 |
"model-defn" [ "pair_style reax/c @<parameter-file-2>@ safezone 2.0 mincap 100" |
| 606 |
"pair_coeff * * @<parameter-file-1>@ @<atom-type-sym-list>@" |
| 607 |
"fix reaxqeq all qeq/reax 1 0.0 10.0 1.0e-6 @<parameter-file-3>@" |
| 608 |
] |
| 609 |
} |
| 610 |
\endcode |
| 611 |
|
| 612 |
The ordering of the SM's parameter files is specified in the SM's \c |
| 613 |
CMakeLists.txt configuration file. With this SM defined and installed in one |
| 614 |
of the %KIM API collections, the following is equivalent to the above LAMMPS |
| 615 |
input script. |
| 616 |
|
| 617 |
\code{.unparsed} |
| 618 |
# REAX potential for CHO system |
| 619 |
|
| 620 |
kim_init Sim_LAMMPS_ReaxFF_ChenowethVanDuinGoddard_2008_CHO__SM_584143153761_000 real |
| 621 |
|
| 622 |
neighbor 2 bin |
| 623 |
|
| 624 |
read_data data.CHO |
| 625 |
|
| 626 |
kim_interactions C H O |
| 627 |
|
| 628 |
fix 1 all nve |
| 629 |
fix 2 all temp/berendsen 500.0 500.0 100.0 |
| 630 |
|
| 631 |
timestep 0.25 |
| 632 |
|
| 633 |
run 100 |
| 634 |
\endcode |
| 635 |
|
| 636 |
See the documentation of the KIM::SimulatorModel interface for more details of |
| 637 |
the %KIM API/SMI. |
| 638 |
|
| 639 |
|
| 640 |
Next Section: \ref version2_differences. |
| 641 |
|
| 642 |
*/ |
| 643 |
|
| 644 |
LocalWords: yyyy Ellad Tadmor Karls kim api ref ModelCreate ModelCompute |
| 645 |
LocalWords: ModelDriverCreate ModelRefresh ModelDestroy requiredByAPI sc Cu |
| 646 |
LocalWords: notSupported numberOfParticles particleSpeciesCodes Ni mathbf EDr |
| 647 |
LocalWords: particleContributing leftrightarrow partialEnergy partialForces |
| 648 |
LocalWords: mathcal partialParticleEnergy partialVirial partialParticleVirial |
| 649 |
LocalWords: virial GetNeighborList ProcessDEDrTerm ProcessD ac infl otimes em |
| 650 |
LocalWords: ModelComputeArgumentsCreate ModelComputeArgumentsDestroy ge cdot |
| 651 |
LocalWords: Modelcompureargumentsdestroy ModelExtension CMake PMI PMs MDs tr |
| 652 |
LocalWords: modelWillNotRequestNeighborsOfNoncontributingParticles td br PM's |
| 653 |
LocalWords: ModelWriteParameterizedModel requestedUnitsAccepted SMI SMs SM's |
| 654 |
LocalWords: metadata programatic SM SMI's nondimensional Lennard openkim org |
| 655 |
LocalWords: pmi smi PMI ModelCreateFunction ModelDriverCreateFunction LAMMPS |
| 656 |
LocalWords: ModelComputeArgumentsCreateFunction ModelComputeFunction ReaxFF |
| 657 |
LocalWords: ModelExtensionFunction ModelRefreshFunction ModelDestroyFunction |
| 658 |
LocalWords: ModelWriteParameterizedModelFunction CHO REAX reax lmp coeff qeq |
| 659 |
LocalWords: ModelComputeArgumentsDestroyFunction reaxqeq param nve berendsen |
| 660 |
LocalWords: timestep endcode init defn sym sm edn Sim ChenowethVanDuinGoddard |
| 661 |
LocalWords: safezone mincap CMakeLists txt |