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-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
27extern "C" {
28#include "KIM_Collection.h"
30#include "KIM_Collections.h"
31}
32#include <iostream>
33
34void dirsForCollection(KIM_Collection const collection,
35 KIM_Collections * const col)
36{
37 int extent = 0;
38
39 {
41 col, collection, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
42 std::cout << KIM_Collection_ToString(collection) << ":"
45 << " :\n";
46 for (int i = 0; i < extent; ++i)
47 {
48 char const * dir;
50 std::cout << "\t" << dir << std::endl;
51 }
52
53 extent = 0;
55 col, collection, KIM_COLLECTION_ITEM_TYPE_portableModel, &extent);
56 std::cout << KIM_Collection_ToString(collection) << ":"
59 << " :\n";
60 for (int i = 0; i < extent; ++i)
61 {
62 char const * dir;
64 std::cout << "\t" << dir << std::endl;
65 }
66
67 extent = 0;
69 col, collection, KIM_COLLECTION_ITEM_TYPE_simulatorModel, &extent);
70 std::cout << KIM_Collection_ToString(collection) << ":"
73 << " :\n";
74 for (int i = 0; i < extent; ++i)
75 {
76 char const * dir;
78 std::cout << "\t" << dir << std::endl;
79 }
80 }
81}
82
84{
85 int extent;
87 col, kc, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
88 std::cout << KIM_Collection_ToString(kc) << ":"
91 << " :\n";
92 for (int i = 0; i < extent; ++i)
93 {
94 char const * name;
96 std::cout << "\t" << name << std::endl;
97 }
100 std::cout << KIM_Collection_ToString(kc) << ":"
103 << " :\n";
104 for (int i = 0; i < extent; ++i)
105 {
106 char const * name;
108 std::cout << "\t" << name << std::endl;
109 }
112 std::cout << KIM_Collection_ToString(kc) << ":"
115 << " :\n";
116 for (int i = 0; i < extent; ++i)
117 {
118 char const * name;
120 std::cout << "\t" << name << std::endl;
121 }
122}
123
124
125int main()
126{
127 KIM_Collections * col;
128
129 int error = KIM_Collections_Create(&col);
130
131 if (error)
132 {
133 std::cerr << "Unable to create collections object." << std::endl;
134 return 1;
135 }
136
137 {
138 char const * project;
139 char const * semVer;
140 KIM_Collections_GetProjectNameAndSemVer(col, &project, &semVer);
141
142 std::cout << "Project : " << project << std::endl;
143 std::cout << "semVer : " << semVer << std::endl;
144 std::cout << std::endl;
145 }
146
147 {
148 char const * name;
153 << " env name : " << name << std::endl;
154 std::cout << std::endl;
155 }
156 {
157 char const * name;
162 << " env name : " << name << std::endl;
163 std::cout << std::endl;
164 }
165 {
166 char const * name;
171 << " env name : " << name << std::endl;
172 std::cout << std::endl;
173 }
174
175
176 {
177 char const * name;
178 char const * value;
180 std::cout << "config file env name : " << name << std::endl
181 << "config file env value: " << value << std::endl;
182 std::cout << std::endl;
183 }
184
185
186 {
187 char const * fileName;
189 std::cout << "config file name : " << fileName << std::endl;
190 std::cout << std::endl;
191 }
192
193
194 {
199 std::cout << std::endl;
200 }
201
202
203 {
208 std::cout << std::endl;
209 }
210
211
212 {
213 int extent;
218 << " :\n";
219 for (int i = 0; i < extent; ++i)
220 {
221 char const * name;
223 std::cout << "\t" << name << std::endl;
224 }
229 << " :\n";
230 for (int i = 0; i < extent; ++i)
231 {
232 char const * name;
234 std::cout << "\t" << name << std::endl;
235 }
240 << " :\n";
241 for (int i = 0; i < extent; ++i)
242 {
243 char const * name;
245 std::cout << "\t" << name << std::endl;
246 }
247 }
248
249 {
250 char const * fileName;
251 KIM_Collection collection;
253 col,
255 "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
256 &fileName,
257 &collection);
258 if (!error)
259 std::cout
260 << "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"
261 << " has library name '" << fileName << "' and is part of the '"
262 << KIM_Collection_ToString(collection) << "' collection."
263 << std::endl;
264 else
265 std::cout << "Error from GetItemLibraryFileNameAndCollection."
266 << std::endl;
267 }
268
269 {
270 int extent;
272 col,
274 "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
275 &extent);
276 if (error)
277 std::cout << "Error from CacheListOfItemMetadataFiles." << std::endl;
278 else
279 {
280 char const * fileName;
281 unsigned int fileLength;
282 unsigned char const * fileRawData;
283 int availableAsString;
284 char const * fileString;
285 for (int i = 0; i < extent; ++i)
286 {
288 i,
289 &fileName,
290 &fileLength,
291 &fileRawData,
292 &availableAsString,
293 &fileString);
294 std::cout << "Metadata File " << i << ", " << fileName
295 << ", is of length " << fileLength << std::endl
296 << fileString << std::endl;
297 }
298 }
299 }
300
302 return 0;
303}
KIM_Collection const KIM_COLLECTION_environmentVariable
The standard environmentVariable Collection.
KIM_Collection const KIM_COLLECTION_user
The standard user Collection.
KIM_Collection const KIM_COLLECTION_currentWorkingDirectory
The standard currentWorkingDirectory Collection.
char const * KIM_Collection_ToString(KIM_Collection const collection)
Converts the object to a string.
KIM_Collection const KIM_COLLECTION_system
The standard system Collection.
KIM_CollectionItemType const KIM_COLLECTION_ITEM_TYPE_simulatorModel
The standard simulatorModel CollectionItemType.
KIM_CollectionItemType const KIM_COLLECTION_ITEM_TYPE_portableModel
The standard portableModel CollectionItemType.
char const * KIM_CollectionItemType_ToString(KIM_CollectionItemType const collectionItemType)
Converts the object to a string.
KIM_CollectionItemType const KIM_COLLECTION_ITEM_TYPE_modelDriver
The standard modelDriver CollectionItemType.
int KIM_Collections_CacheListOfItemNamesByType(KIM_Collections *const collections, KIM_CollectionItemType const itemType, int *const extent)
Cache a list of all item names of a specific type in the KIM API collections.
int KIM_Collections_GetItemLibraryFileNameAndCollection(KIM_Collections *const collections, KIM_CollectionItemType const itemType, char const *const itemName, char const **const fileName, KIM_Collection *const collection)
Get the item's library file name and its KIM::Collection.
int KIM_Collections_GetEnvironmentVariableName(KIM_Collections *const collections, KIM_CollectionItemType const itemType, char const **const name)
Get the names of environment variables that store configuration settings for the KIM::COLLECTION::env...
void KIM_Collections_GetConfigurationFileName(KIM_Collections *const collections, char const **const fileName)
Get the absolute file and path name of the KIM API user configuration file.
void KIM_Collections_Destroy(KIM_Collections **const collections)
Destroy a previously Collections::Create'd object.
int KIM_Collections_GetDirectoryName(KIM_Collections *const collections, int const index, char const **const directoryName)
Get the name of a directory from the cached list.
int KIM_Collections_CacheListOfDirectoryNames(KIM_Collections *const collections, KIM_Collection const collection, KIM_CollectionItemType const itemType, int *const extent)
Cache a list of directory names where a specific KIM API collection stores library files for a specif...
void KIM_Collections_GetProjectNameAndSemVer(KIM_Collections *const collections, char const **const projectName, char const **const semVer)
Get the KIM API project name and full Semantic Version string.
int KIM_Collections_GetItemMetadataFile(KIM_Collections *const collections, int const index, char const **const fileName, unsigned int *const fileLength, unsigned char const **const fileRawData, int *const availableAsString, char const **const fileString)
Get the name and content of one of an item's metadata files.
int KIM_Collections_Create(KIM_Collections **const collections)
Create a new KIM API Collections object.
int KIM_Collections_GetItemNameByCollectionAndType(KIM_Collections *const collections, int const index, char const **const itemName)
Get the name of an item from the cached list.
void KIM_Collections_GetConfigurationFileEnvironmentVariable(KIM_Collections *const collections, char const **const name, char const **const value)
Get the name and value of the environment variable that stores the name of the KIM API user configura...
struct KIM_Collections KIM_Collections
Provides the interface to the KIM API Collections and is meant to be used by simulators.
int KIM_Collections_GetItemNameByType(KIM_Collections *const collections, int const index, char const **const itemName)
Get the name of an item from the cached list.
int KIM_Collections_CacheListOfItemMetadataFiles(KIM_Collections *const collections, KIM_CollectionItemType const itemType, char const *const itemName, int *const extent)
Cache a list of an item's metadata files.
int KIM_Collections_CacheListOfItemNamesByCollectionAndType(KIM_Collections *const collections, KIM_Collection const collection, KIM_CollectionItemType const itemType, int *const extent)
Cache a list of all item names of a specific type in a specific collection.
void dirsForCollection(KIM_Collection const collection, KIM_Collections *const col)
void namesForCollection(KIM_Collection kc, KIM_Collections *const col)
int main()
An Extensible Enumeration for the Collection's supported by the KIM API.