kim-api  2.1.4-git+v2.1.3-git-1-g7847914a.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 // CDDL HEADER START
3 //
4 // The contents of this file are subject to the terms of the Common Development
5 // and Distribution License Version 1.0 (the "License").
6 //
7 // You can obtain a copy of the license at
8 // http://www.opensource.org/licenses/CDDL-1.0. See the License for the
9 // specific language governing permissions and limitations under the License.
10 //
11 // When distributing Covered Code, include this CDDL HEADER in each file and
12 // include the License file in a prominent location with the name LICENSE.CDDL.
13 // If applicable, add the following below this CDDL HEADER, with the fields
14 // enclosed by brackets "[]" replaced with your own identifying information:
15 //
16 // Portions Copyright (c) [yyyy] [name of copyright owner]. All rights reserved.
17 //
18 // CDDL HEADER END
19 //
20 
21 //
22 // Copyright (c) 2016--2019, Regents of the University of Minnesota.
23 // All rights reserved.
24 //
25 // Contributors:
26 // Ryan S. Elliott
27 //
28 
29 
30 extern "C" {
31 #include "KIM_SimulatorHeaders.h"
32 }
33 #include <cstdlib>
34 #include <iomanip>
35 #include <iostream>
36 #include <string>
37 
38 int main()
39 {
40  KIM_SimulatorModel * SM;
42  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", &SM);
43 
44  if (error)
45  {
46  std::cout << "Can't create SM." << std::endl;
47  goto fail;
48  }
49 
50  {
51  char const * pSimulatorName;
52  char const * pSimulatorVersion;
54  SM, &pSimulatorName, &pSimulatorVersion);
55  std::cout << "Simulator name : " << pSimulatorName << std::endl
56  << "Simulator version : " << pSimulatorVersion << std::endl
57  << std::endl;
58  }
59 
60  {
61  int extent;
63  std::cout << "SM supports " << extent << " species:" << std::endl;
64  for (int i = 0; i < extent; ++i)
65  {
66  char const * pSpecies;
67  error = KIM_SimulatorModel_GetSupportedSpecies(SM, i, &pSpecies);
68  if (error)
69  {
70  std::cout << "Unable to get species." << std::endl;
71  goto fail;
72  }
73  else
74  {
75  std::cout << "\t" << std::setw(2) << i << " " << pSpecies << std::endl;
76  }
77  }
78  std::cout << std::endl;
79  }
80 
81  {
83  SM, "atom-type-sym-list", "Pb Pb Au Pb");
84  if (error)
85  {
86  std::cout << "Unable to add template map." << std::endl;
87  goto fail;
88  }
90  int numberFields;
92  std::cout << "SM has " << std::setw(2) << numberFields
93  << " fields :" << std::endl;
94 
95  for (int i = 0; i < numberFields; ++i)
96  {
97  int extent;
98  char const * pFieldName;
100  SM, i, &extent, &pFieldName);
101  std::cout << " Field " << std::setw(2) << i << " is " << pFieldName
102  << " and has " << std::setw(2) << extent
103  << " lines:" << std::endl;
104  for (int j = 0; j < extent; ++j)
105  {
106  char const * pFieldLine;
107  error = KIM_SimulatorModel_GetSimulatorFieldLine(SM, i, j, &pFieldLine);
108  if (error)
109  {
110  std::cout << "Unable to get field line." << std::endl;
111  goto fail;
112  }
113  else
114  {
115  std::cout << "\t" << pFieldLine << std::endl;
116  }
117  }
118  }
119  std::cout << std::endl;
120  }
121 
122  {
123  char const * pDirName;
125  std::cout << "SM param dir name is " << pDirName << std::endl;
126 
127  char const * pSpecName;
129  std::cout << "SM spec file name is " << pSpecName << std::endl << std::endl;
130  error = system((std::string("cat ") + pDirName + "/" + pSpecName).c_str());
131  std::cout << std::endl;
132 
133  int numberParamFiles;
134  KIM_SimulatorModel_GetNumberOfParameterFiles(SM, &numberParamFiles);
135  std::cout << "SM has " << numberParamFiles
136  << " parameter files:" << std::endl;
137  for (int i = 0; i < numberParamFiles; ++i)
138  {
139  char const * pParamFileName;
140  error = KIM_SimulatorModel_GetParameterFileName(SM, i, &pParamFileName);
141  if (error)
142  {
143  std::cout << "Unable to get parameter file name." << std::endl;
144  goto fail;
145  }
146  else
147  {
148  std::cout << "Parameter file " << std::setw(2) << i
149  << " has name : " << pParamFileName << std::endl;
150  error = system(
151  (std::string("cat ") + pDirName + "/" + pParamFileName).c_str());
152  std::cout << std::endl;
153  }
154  }
155  }
156 
158  return 0;
159 fail:
161  return 1;
162 }
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.
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.
int KIM_SimulatorModel_GetParameterFileName(KIM_SimulatorModel const *const simulatorModel, int const index, char const **const parameterFileName)
Get the basename (file name without path) of a particular parameter file. The file is located in the ...
Collection const system
The standard system Collection.