kim-api  2.2.1+v2.2.1.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
collections-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--2020, 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_Collection.h"
32 #include "KIM_CollectionItemType.h"
33 #include "KIM_Collections.h"
34 }
35 #include <iostream>
36 
37 void dirsForCollection(KIM_Collection const collection,
38  KIM_Collections * const col)
39 {
40  int extent = 0;
41 
42  {
44  col, collection, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
45  std::cout << KIM_Collection_ToString(collection) << ":"
48  << " :\n";
49  for (int i = 0; i < extent; ++i)
50  {
51  char const * dir;
53  std::cout << "\t" << dir << std::endl;
54  }
55 
56  extent = 0;
58  col, collection, KIM_COLLECTION_ITEM_TYPE_portableModel, &extent);
59  std::cout << KIM_Collection_ToString(collection) << ":"
62  << " :\n";
63  for (int i = 0; i < extent; ++i)
64  {
65  char const * dir;
67  std::cout << "\t" << dir << std::endl;
68  }
69 
70  extent = 0;
72  col, collection, KIM_COLLECTION_ITEM_TYPE_simulatorModel, &extent);
73  std::cout << KIM_Collection_ToString(collection) << ":"
76  << " :\n";
77  for (int i = 0; i < extent; ++i)
78  {
79  char const * dir;
81  std::cout << "\t" << dir << std::endl;
82  }
83  }
84 }
85 
87 {
88  int extent;
90  col, kc, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
91  std::cout << KIM_Collection_ToString(kc) << ":"
94  << " :\n";
95  for (int i = 0; i < extent; ++i)
96  {
97  char const * name;
99  std::cout << "\t" << name << std::endl;
100  }
102  col, kc, KIM_COLLECTION_ITEM_TYPE_portableModel, &extent);
103  std::cout << KIM_Collection_ToString(kc) << ":"
106  << " :\n";
107  for (int i = 0; i < extent; ++i)
108  {
109  char const * name;
111  std::cout << "\t" << name << std::endl;
112  }
114  col, kc, KIM_COLLECTION_ITEM_TYPE_simulatorModel, &extent);
115  std::cout << KIM_Collection_ToString(kc) << ":"
118  << " :\n";
119  for (int i = 0; i < extent; ++i)
120  {
121  char const * name;
123  std::cout << "\t" << name << std::endl;
124  }
125 }
126 
127 
128 int main()
129 {
130  KIM_Collections * col;
131 
132  int error = KIM_Collections_Create(&col);
133 
134  if (error)
135  {
136  std::cerr << "Unable to create collections object." << std::endl;
137  return 1;
138  }
139 
140  {
141  char const * project;
142  char const * semVer;
143  KIM_Collections_GetProjectNameAndSemVer(col, &project, &semVer);
144 
145  std::cout << "Project : " << project << std::endl;
146  std::cout << "semVer : " << semVer << std::endl;
147  std::cout << std::endl;
148  }
149 
150  {
151  char const * name;
154  std::cout << KIM_CollectionItemType_ToString(
156  << " env name : " << name << std::endl;
157  std::cout << std::endl;
158  }
159  {
160  char const * name;
163  std::cout << KIM_CollectionItemType_ToString(
165  << " env name : " << name << std::endl;
166  std::cout << std::endl;
167  }
168  {
169  char const * name;
172  std::cout << KIM_CollectionItemType_ToString(
174  << " env name : " << name << std::endl;
175  std::cout << std::endl;
176  }
177 
178 
179  {
180  char const * name;
181  char const * value;
183  std::cout << "config file env name : " << name << std::endl
184  << "config file env value: " << value << std::endl;
185  std::cout << std::endl;
186  }
187 
188 
189  {
190  char const * fileName;
192  std::cout << "config file name : " << fileName << std::endl;
193  std::cout << std::endl;
194  }
195 
196 
197  {
202  std::cout << std::endl;
203  }
204 
205 
206  {
211  std::cout << std::endl;
212  }
213 
214 
215  {
216  int extent;
219  std::cout << KIM_CollectionItemType_ToString(
221  << " :\n";
222  for (int i = 0; i < extent; ++i)
223  {
224  char const * name;
225  KIM_Collections_GetItemNameByType(col, i, &name);
226  std::cout << "\t" << name << std::endl;
227  }
230  std::cout << KIM_CollectionItemType_ToString(
232  << " :\n";
233  for (int i = 0; i < extent; ++i)
234  {
235  char const * name;
236  KIM_Collections_GetItemNameByType(col, i, &name);
237  std::cout << "\t" << name << std::endl;
238  }
241  std::cout << KIM_CollectionItemType_ToString(
243  << " :\n";
244  for (int i = 0; i < extent; ++i)
245  {
246  char const * name;
247  KIM_Collections_GetItemNameByType(col, i, &name);
248  std::cout << "\t" << name << std::endl;
249  }
250  }
251 
252  {
253  char const * fileName;
254  KIM_Collection collection;
256  col,
258  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
259  &fileName,
260  &collection);
261  if (!error)
262  std::cout
263  << "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"
264  << " has library name '" << fileName << "' and is part of the '"
265  << KIM_Collection_ToString(collection) << "' collection."
266  << std::endl;
267  else
268  std::cout << "Error from GetItemLibraryFileNameAndCollection."
269  << std::endl;
270  }
271 
272  {
273  int extent;
275  col,
277  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
278  &extent);
279  if (error)
280  std::cout << "Error from CacheListOfItemMetadataFiles." << std::endl;
281  else
282  {
283  char const * fileName;
284  unsigned int fileLength;
285  unsigned char const * fileRawData;
286  int availableAsString;
287  char const * fileString;
288  for (int i = 0; i < extent; ++i)
289  {
291  i,
292  &fileName,
293  &fileLength,
294  &fileRawData,
295  &availableAsString,
296  &fileString);
297  std::cout << "Metadata File " << i << ", " << fileName
298  << ", is of length " << fileLength << std::endl
299  << fileString << std::endl;
300  }
301  }
302  }
303 
305  return 0;
306 }
KIM_Collection const KIM_COLLECTION_environmentVariable
The standard environmentVariable Collection.
void dirsForCollection(KIM_Collection const collection, KIM_Collections *const col)
int main()
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...
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&#39;s metadata files.
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...
KIM_CollectionItemType const KIM_COLLECTION_ITEM_TYPE_simulatorModel
The standard simulatorModel CollectionItemType.
KIM_Collection const KIM_COLLECTION_system
The standard system 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.
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.
An Extensible Enumeration for the Collection&#39;s supported by the KIM API.
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&#39;s metadata files.
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&#39;s library file name and its KIM::Collection.
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.
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_Collection const KIM_COLLECTION_user
The standard user Collection.
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_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.
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_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 KIM_Collections_Destroy(KIM_Collections **const collections)
Destroy a previously Collections::Create&#39;d object.
KIM_CollectionItemType const KIM_COLLECTION_ITEM_TYPE_modelDriver
The standard modelDriver CollectionItemType.
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...
void namesForCollection(KIM_Collection kc, KIM_Collections *const col)
struct KIM_Collections KIM_Collections
Provides the interface to the KIM API Collections and is meant to be used by simulators.
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.