kim-api 2.3.0+AppleClang.AppleClang.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
Loading...
Searching...
No Matches
simulator-model-example.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
28#include <cstdlib>
29#include <iomanip>
30#include <iostream>
31#include <string>
32
33int main()
34{
37 "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", &SM);
38
39 if (error)
40 {
41 std::cout << "Can't create SM." << std::endl;
42 return 1;
43 }
44
45 {
46 std::string const * pSimulatorName;
47 std::string const * pSimulatorVersion;
48 SM->GetSimulatorNameAndVersion(&pSimulatorName, &pSimulatorVersion);
49 std::cout << "Simulator name : " << *pSimulatorName << std::endl
50 << "Simulator version : " << *pSimulatorVersion << std::endl
51 << std::endl;
52 }
53
54 {
55 int extent;
56 SM->GetNumberOfSupportedSpecies(&extent);
57 std::cout << "SM supports " << extent << " species:" << std::endl;
58 for (int i = 0; i < extent; ++i)
59 {
60 std::string const * pSpecies;
61 error = SM->GetSupportedSpecies(i, &pSpecies);
62 if (error)
63 {
64 std::cout << "Unable to get species." << std::endl;
65 goto fail;
66 }
67 else
68 {
69 std::cout << "\t" << std::setw(2) << i << " " << *pSpecies << std::endl;
70 }
71 }
72 std::cout << std::endl;
73 }
74
75 {
76 error = SM->AddTemplateMap("atom-type-sym-list", "Pb Pb Au Pb");
77 if (error)
78 {
79 std::cout << "Unable to add template map." << std::endl;
80 goto fail;
81 }
82 SM->CloseTemplateMap();
83 int numberFields;
84 SM->GetNumberOfSimulatorFields(&numberFields);
85 std::cout << "SM has " << std::setw(2) << numberFields
86 << " fields :" << std::endl;
87
88 for (int i = 0; i < numberFields; ++i)
89 {
90 int extent;
91 std::string const * pFieldName;
92 error = SM->GetSimulatorFieldMetadata(i, &extent, &pFieldName);
93 std::cout << " Field " << std::setw(2) << i << " is " << *pFieldName
94 << " and has " << std::setw(2) << extent
95 << " lines:" << std::endl;
96 for (int j = 0; j < extent; ++j)
97 {
98 std::string const * pFieldLine;
99 error = SM->GetSimulatorFieldLine(i, j, &pFieldLine);
100 if (error)
101 {
102 std::cout << "Unable to get field line." << std::endl;
103 goto fail;
104 }
105 else
106 {
107 std::cout << "\t" << *pFieldLine << std::endl;
108 }
109 }
110 }
111 std::cout << std::endl;
112 }
113
114 {
115 std::string const * pDirName;
116 SM->GetParameterFileDirectoryName(&pDirName);
117 std::cout << "SM param dir name is " << *pDirName << std::endl;
118
119 std::string const * pSpecName;
120 SM->GetSpecificationFileName(&pSpecName);
121 std::cout << "SM spec file name is " << *pSpecName << std::endl
122 << std::endl;
123 error
124 = system((std::string("cat ") + *pDirName + "/" + *pSpecName).c_str());
125 std::cout << std::endl;
126
127 int numberParamFiles;
128 SM->GetNumberOfParameterFiles(&numberParamFiles);
129 std::cout << "SM has " << numberParamFiles
130 << " parameter files:" << std::endl;
131 for (int i = 0; i < numberParamFiles; ++i)
132 {
133 std::string const * pParamFileBasename;
134 error = SM->GetParameterFileBasename(i, &pParamFileBasename);
135 if (error)
136 {
137 std::cout << "Unable to get parameter file basename." << std::endl;
138 goto fail;
139 }
140 else
141 {
142 std::cout << "Parameter file " << std::setw(2) << i
143 << " has basename : " << *pParamFileBasename << std::endl;
144 error = system(
145 (std::string("cat ") + *pDirName + "/" + *pParamFileBasename)
146 .c_str());
147 std::cout << std::endl;
148 }
149 }
150 }
151
153 return 0; // false
154fail:
156 return 1; // true
157}
Provides the primary interface to a KIM API SimulatorModel object and is meant to be used by simulato...
void GetNumberOfSimulatorFields(int *const numberOfSimulatorFields) const
Get the number of simulator fields provided by the SimulatorModel.
static void Destroy(SimulatorModel **const simulatorModel)
Destroy a previously SimulatorModel::Create'd object.
int GetSimulatorFieldLine(int const fieldIndex, int const lineIndex, std::string const **const lineValue) const
Get a line for the simulator field of interest with all template substitutions performed (Requires th...
void GetSpecificationFileName(std::string const **const specificationFileName) const
Get the SimulatorModel's specification file basename (file name without path). The file is located in...
int GetParameterFileBasename(int const index, std::string const **const parameterFileBasename) const
Get the basename (file name without path) of a particular parameter file. The file is located in the ...
void GetNumberOfParameterFiles(int *const numberOfParameterFiles) const
Get the number of parameter files provided by the SimulatorModel.
int GetSimulatorFieldMetadata(int const fieldIndex, int *const extent, std::string const **const fieldName) const
Get the metadata for the simulator field of interest.
int GetSupportedSpecies(int const index, std::string const **const speciesName) const
Get a species name supported by the SimulatorModel.
void GetSimulatorNameAndVersion(std::string const **const simulatorName, std::string const **const simulatorVersion) const
Get the SimulatorModel's simulator name and version.
void GetParameterFileDirectoryName(std::string const **const directoryName) const
Get absolute path name of the temporary directory where parameter files provided by the simulator mod...
void CloseTemplateMap()
Close the template map and perform template substitutions.
void GetNumberOfSupportedSpecies(int *const numberOfSupportedSpecies) const
Get the number of species supported by the SimulatorModel.
int AddTemplateMap(std::string const &key, std::string const &value)
Add a new key-value entry to the template map.
static int Create(std::string const &simulatorModelName, SimulatorModel **const simulatorModel)
Create a new KIM API SimulatorModel object.