kim-api 2.3.0+AppleClang.AppleClang.GNU
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
Loading...
Searching...
No Matches
collections-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
27#include "KIM_Collection.hpp"
29#include "KIM_Collections.hpp"
30#include <iostream>
31#include <string>
32
33void dirsForCollection(KIM::Collection const collection,
34 KIM::Collections * const col)
35{
36 int extent = 0;
37
38 {
39 using namespace KIM::COLLECTION_ITEM_TYPE;
40 col->CacheListOfDirectoryNames(collection, modelDriver, &extent);
41 std::cout << collection.ToString() << ":" << modelDriver.ToString()
42 << " :\n";
43 for (int i = 0; i < extent; ++i)
44 {
45 std::string const * dir;
46 col->GetDirectoryName(i, &dir);
47 std::cout << "\t" << *dir << std::endl;
48 }
49
50 extent = 0;
51 col->CacheListOfDirectoryNames(collection, portableModel, &extent);
52 std::cout << collection.ToString() << ":" << portableModel.ToString()
53 << " :\n";
54 for (int i = 0; i < extent; ++i)
55 {
56 std::string const * dir;
57 col->GetDirectoryName(i, &dir);
58 std::cout << "\t" << *dir << std::endl;
59 }
60
61 extent = 0;
62 col->CacheListOfDirectoryNames(collection, simulatorModel, &extent);
63 std::cout << collection.ToString() << ":" << simulatorModel.ToString()
64 << " :\n";
65 for (int i = 0; i < extent; ++i)
66 {
67 std::string const * dir;
68 col->GetDirectoryName(i, &dir);
69 std::cout << "\t" << *dir << std::endl;
70 }
71 }
72}
73
75{
76 using namespace KIM::COLLECTION_ITEM_TYPE;
77 int extent;
78 col->CacheListOfItemNamesByCollectionAndType(kc, modelDriver, &extent);
79 std::cout << kc.ToString() << ":" << modelDriver.ToString() << " :\n";
80 for (int i = 0; i < extent; ++i)
81 {
82 std::string const * name;
83 col->GetItemNameByCollectionAndType(i, &name);
84 std::cout << "\t" << *name << std::endl;
85 }
86 col->CacheListOfItemNamesByCollectionAndType(kc, portableModel, &extent);
87 std::cout << kc.ToString() << ":" << portableModel.ToString() << " :\n";
88 for (int i = 0; i < extent; ++i)
89 {
90 std::string const * name;
91 col->GetItemNameByCollectionAndType(i, &name);
92 std::cout << "\t" << *name << std::endl;
93 }
94 col->CacheListOfItemNamesByCollectionAndType(kc, simulatorModel, &extent);
95 std::cout << kc.ToString() << ":" << simulatorModel.ToString() << " :\n";
96 for (int i = 0; i < extent; ++i)
97 {
98 std::string const * name;
99 col->GetItemNameByCollectionAndType(i, &name);
100 std::cout << "\t" << *name << std::endl;
101 }
102}
103
104
105int main()
106{
107 KIM::Collections * col;
108
110
111 if (error)
112 {
113 std::cerr << "Unable to create collections object." << std::endl;
114 return 1;
115 }
116
117 {
118 std::string const * project;
119 std::string const * semVer;
120 col->GetProjectNameAndSemVer(&project, &semVer);
121
122 std::cout << "Project : " << *project << std::endl;
123 std::cout << "semVer : " << *semVer << std::endl;
124 std::cout << std::endl;
125 }
126
127 {
128 std::string const * name;
130 &name);
132 << " env name : " << *name << std::endl;
133 std::cout << std::endl;
134 }
135 {
136 std::string const * name;
138 &name);
140 << " env name : " << *name << std::endl;
141 std::cout << std::endl;
142 }
143 {
144 std::string const * name;
146 &name);
148 << " env name : " << *name << std::endl;
149 std::cout << std::endl;
150 }
151
152
153 {
154 std::string const * name;
155 std::string const * value;
156 col->GetConfigurationFileEnvironmentVariable(&name, &value);
157 std::cout << "config file env name : " << *name << std::endl
158 << "config file env value: " << *value << std::endl;
159 std::cout << std::endl;
160 }
161
162
163 {
164 std::string const * fileName;
165 col->GetConfigurationFileName(&fileName);
166 std::cout << "config file name : " << *fileName << std::endl;
167 std::cout << std::endl;
168 }
169
170
171 {
172 using namespace KIM::COLLECTION;
174 dirsForCollection(user, col);
175 dirsForCollection(environmentVariable, col);
176 dirsForCollection(currentWorkingDirectory, col);
177 std::cout << std::endl;
178 }
179
180
181 {
182 using namespace KIM::COLLECTION;
184 namesForCollection(user, col);
185 namesForCollection(environmentVariable, col);
186 namesForCollection(currentWorkingDirectory, col);
187 std::cout << std::endl;
188 }
189
190
191 {
192 using namespace KIM::COLLECTION_ITEM_TYPE;
193 int extent;
194 col->CacheListOfItemNamesByType(modelDriver, &extent);
195 std::cout << modelDriver.ToString() << " :\n";
196 for (int i = 0; i < extent; ++i)
197 {
198 std::string const * name;
199 col->GetItemNameByType(i, &name);
200 std::cout << "\t" << *name << std::endl;
201 }
202 col->CacheListOfItemNamesByType(portableModel, &extent);
203 std::cout << portableModel.ToString() << " :\n";
204 for (int i = 0; i < extent; ++i)
205 {
206 std::string const * name;
207 col->GetItemNameByType(i, &name);
208 std::cout << "\t" << *name << std::endl;
209 }
210 col->CacheListOfItemNamesByType(simulatorModel, &extent);
211 std::cout << simulatorModel.ToString() << " :\n";
212 for (int i = 0; i < extent; ++i)
213 {
214 std::string const * name;
215 col->GetItemNameByType(i, &name);
216 std::cout << "\t" << *name << std::endl;
217 }
218 }
219
220 {
221 std::string const * fileName;
222 KIM::Collection collection;
225 "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
226 &fileName,
227 &collection);
228 if (!error)
229 std::cout
230 << "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"
231 << " has library name '" << *fileName << "' and is part of the '"
232 << collection.ToString() << "' collection." << std::endl;
233 else
234 std::cout << "Error from GetItemLibraryFileNameAndCollection."
235 << std::endl;
236 }
237
238 {
239 int extent;
242 "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
243 &extent);
244 if (error)
245 std::cout << "Error from CacheListOfItemMetadataFiles." << std::endl;
246 else
247 {
248 std::string const * fileName;
249 unsigned int fileLength;
250 unsigned char const * fileRawData;
251 int availableAsString;
252 std::string const * fileString;
253 for (int i = 0; i < extent; ++i)
254 {
255 col->GetItemMetadataFile(i,
256 &fileName,
257 &fileLength,
258 &fileRawData,
259 &availableAsString,
260 &fileString);
261 std::cout << "Metadata File " << i << ", " << *fileName
262 << ", is of length " << fileLength << std::endl
263 << *fileString << std::endl;
264 }
265 }
266 }
267
269 return 0;
270}
An Extensible Enumeration for the Collection's supported by the KIM API.
std::string const & ToString() const
Converts the object to a string.
std::string const & ToString() const
Converts the object to a string.
Provides the interface to the KIM API Collections and is meant to be used by simulators.
int GetItemNameByType(int const index, std::string const **const itemName) const
Get the name of an item from the cached list.
void GetProjectNameAndSemVer(std::string const **const projectName, std::string const **const semVer) const
Get the KIM API project name and full Semantic Version string.
int GetEnvironmentVariableName(CollectionItemType const itemType, std::string const **const name) const
Get the names of environment variables that store configuration settings for the KIM::COLLECTION::env...
void GetConfigurationFileEnvironmentVariable(std::string const **const name, std::string const **const value) const
Get the name and value of the environment variable that stores the name of the KIM API user configura...
int GetItemLibraryFileNameAndCollection(CollectionItemType const itemType, std::string const &itemName, std::string const **const fileName, Collection *const collection) const
Get the item's library file name and its KIM::Collection.
int CacheListOfItemNamesByType(CollectionItemType const itemType, int *const extent)
Cache a list of all item names of a specific type in the KIM API collections.
int GetItemMetadataFile(int const index, std::string const **const fileName, unsigned int *const fileLength, unsigned char const **const fileRawData, int *const availableAsString, std::string const **const fileString) const
Get the name and content of one of an item's metadata files.
int CacheListOfItemNamesByCollectionAndType(Collection const collection, CollectionItemType const itemType, int *const extent)
Cache a list of all item names of a specific type in a specific collection.
int GetDirectoryName(int const index, std::string const **const directoryName) const
Get the name of a directory from the cached list.
static int Create(Collections **const collections)
Create a new KIM API Collections object.
void GetConfigurationFileName(std::string const **const fileName) const
Get the absolute file and path name of the KIM API user configuration file.
int GetItemNameByCollectionAndType(int const index, std::string const **const itemName) const
Get the name of an item from the cached list.
int CacheListOfDirectoryNames(Collection const collection, CollectionItemType const itemType, int *const extent)
Cache a list of directory names where a specific KIM API collection stores library files for a specif...
int CacheListOfItemMetadataFiles(CollectionItemType const itemType, std::string const &itemName, int *const extent)
Cache a list of an item's metadata files.
static void Destroy(Collections **const collections)
Destroy a previously Collections::Create'd object.
void dirsForCollection(KIM::Collection const collection, KIM::Collections *const col)
int main()
void namesForCollection(KIM::Collection kc, KIM::Collections *const col)
Contains the enumeration constants and the discovery routines for the CollectionItemType Extensible E...
CollectionItemType const simulatorModel
The standard simulatorModel CollectionItemType.
CollectionItemType const portableModel
The standard portableModel CollectionItemType.
CollectionItemType const modelDriver
The standard modelDriver CollectionItemType.
Contains the enumeration constants and the discovery routines for the Collection Extensible Enumerati...
Collection const system
The standard system Collection.