kim-api  2.3.0+v2.3.0.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
simulator-model-example-c.cpp
Go to the documentation of this file.
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 //
9 // SPDX-License-Identifier: LGPL-2.1-or-later
10 //
11 // This library is free software; you can redistribute it and/or
12 // modify it under the terms of the GNU Lesser General Public
13 // License as published by the Free Software Foundation; either
14 // version 2.1 of the License, or (at your option) any later version.
15 //
16 // This library is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 // Lesser General Public License for more details.
20 //
21 // You should have received a copy of the GNU Lesser General Public License
22 // along with this library; if not, write to the Free Software Foundation,
23 // Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 //
25 
26 
27 extern "C" {
28 #include "KIM_SimulatorHeaders.h"
29 }
30 #include <cstdlib>
31 #include <iomanip>
32 #include <iostream>
33 #include <string>
34 
35 int main()
36 {
37  KIM_SimulatorModel * SM;
39  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", &SM);
40 
41  if (error)
42  {
43  std::cout << "Can't create SM." << std::endl;
44  goto fail;
45  }
46 
47  {
48  char const * pSimulatorName;
49  char const * pSimulatorVersion;
51  SM, &pSimulatorName, &pSimulatorVersion);
52  std::cout << "Simulator name : " << pSimulatorName << std::endl
53  << "Simulator version : " << pSimulatorVersion << std::endl
54  << std::endl;
55  }
56 
57  {
58  int extent;
60  std::cout << "SM supports " << extent << " species:" << std::endl;
61  for (int i = 0; i < extent; ++i)
62  {
63  char const * pSpecies;
64  error = KIM_SimulatorModel_GetSupportedSpecies(SM, i, &pSpecies);
65  if (error)
66  {
67  std::cout << "Unable to get species." << std::endl;
68  goto fail;
69  }
70  else
71  {
72  std::cout << "\t" << std::setw(2) << i << " " << pSpecies << std::endl;
73  }
74  }
75  std::cout << std::endl;
76  }
77 
78  {
80  SM, "atom-type-sym-list", "Pb Pb Au Pb");
81  if (error)
82  {
83  std::cout << "Unable to add template map." << std::endl;
84  goto fail;
85  }
87  int numberFields;
89  std::cout << "SM has " << std::setw(2) << numberFields
90  << " fields :" << std::endl;
91 
92  for (int i = 0; i < numberFields; ++i)
93  {
94  int extent;
95  char const * pFieldName;
97  SM, i, &extent, &pFieldName);
98  std::cout << " Field " << std::setw(2) << i << " is " << pFieldName
99  << " and has " << std::setw(2) << extent
100  << " lines:" << std::endl;
101  for (int j = 0; j < extent; ++j)
102  {
103  char const * pFieldLine;
104  error = KIM_SimulatorModel_GetSimulatorFieldLine(SM, i, j, &pFieldLine);
105  if (error)
106  {
107  std::cout << "Unable to get field line." << std::endl;
108  goto fail;
109  }
110  else
111  {
112  std::cout << "\t" << pFieldLine << std::endl;
113  }
114  }
115  }
116  std::cout << std::endl;
117  }
118 
119  {
120  char const * pDirName;
122  std::cout << "SM param dir name is " << pDirName << std::endl;
123 
124  char const * pSpecName;
126  std::cout << "SM spec file name is " << pSpecName << std::endl << std::endl;
127  error = system((std::string("cat ") + pDirName + "/" + pSpecName).c_str());
128  std::cout << std::endl;
129 
130  int numberParamFiles;
131  KIM_SimulatorModel_GetNumberOfParameterFiles(SM, &numberParamFiles);
132  std::cout << "SM has " << numberParamFiles
133  << " parameter files:" << std::endl;
134  for (int i = 0; i < numberParamFiles; ++i)
135  {
136  char const * pParamFileBasename;
138  SM, i, &pParamFileBasename);
139  if (error)
140  {
141  std::cout << "Unable to get parameter file basename." << std::endl;
142  goto fail;
143  }
144  else
145  {
146  std::cout << "Parameter file " << std::setw(2) << i
147  << " has basename : " << pParamFileBasename << std::endl;
148  error
149  = system((std::string("cat ") + pDirName + "/" + pParamFileBasename)
150  .c_str());
151  std::cout << std::endl;
152  }
153  }
154  }
155 
157  return 0;
158 fail:
160  return 1;
161 }
void KIM_SimulatorModel_CloseTemplateMap(KIM_SimulatorModel const *const simulatorModel)
Close the template map and perform template substitutions.
struct KIM_SimulatorModel KIM_SimulatorModel
Provides the primary interface to a KIM API SimulatorModel object and is meant to be used by simulato...
void KIM_SimulatorModel_GetParameterFileDirectoryName(KIM_SimulatorModel const *const simulatorModel, char const **const directoryName)
Get absolute path name of the temporary directory where parameter files provided by the simulator mod...
int KIM_SimulatorModel_GetSimulatorFieldMetadata(KIM_SimulatorModel const *const simulatorModel, int const fieldIndex, int *const extent, char const **const fieldName)
Get the metadata for the simulator field of interest.
void KIM_SimulatorModel_GetNumberOfSimulatorFields(KIM_SimulatorModel const *const simulatorModel, int *const numberOfSimulatorFields)
Get the number of simulator fields provided by the SimulatorModel.
void KIM_SimulatorModel_GetSimulatorNameAndVersion(KIM_SimulatorModel const *const simulatorModel, char const **const simulatorName, char const **const simulatorVersion)
Get the SimulatorModel&#39;s simulator name and version.
void KIM_SimulatorModel_GetNumberOfSupportedSpecies(KIM_SimulatorModel const *const simulatorModel, int *const numberOfSupportedSpecies)
Get the number of species supported by the SimulatorModel.
int KIM_SimulatorModel_GetParameterFileBasename(KIM_SimulatorModel const *const simulatorModel, int const index, char const **const parameterFileBasename)
Get the basename (file name without path) of a particular parameter file. The file is located in the ...
void KIM_SimulatorModel_Destroy(KIM_SimulatorModel **const simulatorModel)
Destroy a previously SimulatorModel::Create&#39;d object.
void KIM_SimulatorModel_GetNumberOfParameterFiles(KIM_SimulatorModel const *const simulatorModel, int *const numberOfParameterFiles)
Get the number of parameter files provided by the SimulatorModel.
void KIM_SimulatorModel_GetSpecificationFileName(KIM_SimulatorModel const *const simulatorModel, char const **const specificationFileName)
Get the SimulatorModel&#39;s specification file basename (file name without path). The file is located in...
int KIM_SimulatorModel_AddTemplateMap(KIM_SimulatorModel const *const simulatorModel, char const *const key, char const *const value)
Add a new key-value entry to the template map.
int KIM_SimulatorModel_Create(char const *const simulatorModelName, KIM_SimulatorModel **const simulatorModel)
Create a new KIM API SimulatorModel object.
int KIM_SimulatorModel_GetSimulatorFieldLine(KIM_SimulatorModel const *const simulatorModel, int const fieldIndex, int const lineIndex, char const **const lineValue)
Get a line for the simulator field of interest with all template substitutions performed (Requires th...
int KIM_SimulatorModel_GetSupportedSpecies(KIM_SimulatorModel const *const simulatorModel, int const index, char const **const speciesName)
Get a species name supported by the SimulatorModel.
Collection const system
The standard system Collection.