kim-api  2.1.2+v2.1.2.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--2019, Regents of the University of Minnesota.
23 // All rights reserved.
24 //
25 // Contributors:
26 // Ryan S. Elliott
27 //
28 
29 extern "C" {
30 #include "KIM_Collection.h"
31 #include "KIM_CollectionItemType.h"
32 #include "KIM_Collections.h"
33 }
34 #include <iomanip>
35 #include <iostream>
36 #include <string>
37 
38 void dirsForCollection(KIM_Collection const collection,
39  KIM_Collections * const col)
40 {
41  int extent = 0;
42 
43  {
45  col, collection, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
46  std::cout << KIM_Collection_ToString(collection) << ":"
49  << " :\n";
50  for (int i = 0; i < extent; ++i)
51  {
52  char const * dir;
54  std::cout << "\t" << dir << std::endl;
55  }
56 
57  extent = 0;
59  col, collection, KIM_COLLECTION_ITEM_TYPE_portableModel, &extent);
60  std::cout << KIM_Collection_ToString(collection) << ":"
63  << " :\n";
64  for (int i = 0; i < extent; ++i)
65  {
66  char const * dir;
68  std::cout << "\t" << dir << std::endl;
69  }
70 
71  extent = 0;
73  col, collection, KIM_COLLECTION_ITEM_TYPE_simulatorModel, &extent);
74  std::cout << KIM_Collection_ToString(collection) << ":"
77  << " :\n";
78  for (int i = 0; i < extent; ++i)
79  {
80  char const * dir;
82  std::cout << "\t" << dir << std::endl;
83  }
84  }
85 }
86 
88 {
89  int extent;
91  col, kc, KIM_COLLECTION_ITEM_TYPE_modelDriver, &extent);
92  std::cout << KIM_Collection_ToString(kc) << ":"
95  << " :\n";
96  for (int i = 0; i < extent; ++i)
97  {
98  char const * name;
100  std::cout << "\t" << name << std::endl;
101  }
103  col, kc, KIM_COLLECTION_ITEM_TYPE_portableModel, &extent);
104  std::cout << KIM_Collection_ToString(kc) << ":"
107  << " :\n";
108  for (int i = 0; i < extent; ++i)
109  {
110  char const * name;
112  std::cout << "\t" << name << std::endl;
113  }
115  col, kc, KIM_COLLECTION_ITEM_TYPE_simulatorModel, &extent);
116  std::cout << KIM_Collection_ToString(kc) << ":"
119  << " :\n";
120  for (int i = 0; i < extent; ++i)
121  {
122  char const * name;
124  std::cout << "\t" << name << std::endl;
125  }
126 }
127 
128 
129 int main()
130 {
131  KIM_Collections * col;
132 
133  int error = KIM_Collections_Create(&col);
134 
135  if (error)
136  {
137  std::cerr << "Unable to create collections object." << std::endl;
138  return 1;
139  }
140 
141  {
142  char const * project;
143  char const * semVer;
144  KIM_Collections_GetProjectNameAndSemVer(col, &project, &semVer);
145 
146  std::cout << "Project : " << project << std::endl;
147  std::cout << "semVer : " << semVer << std::endl;
148  std::cout << std::endl;
149  }
150 
151  {
152  char const * name;
155  std::cout << KIM_CollectionItemType_ToString(
157  << " env name : " << name << std::endl;
158  std::cout << std::endl;
159  }
160  {
161  char const * name;
164  std::cout << KIM_CollectionItemType_ToString(
166  << " env name : " << name << std::endl;
167  std::cout << std::endl;
168  }
169  {
170  char const * name;
173  std::cout << KIM_CollectionItemType_ToString(
175  << " env name : " << name << std::endl;
176  std::cout << std::endl;
177  }
178 
179 
180  {
181  char const * name;
182  char const * value;
184  std::cout << "config file env name : " << name << std::endl
185  << "config file env value: " << value << std::endl;
186  std::cout << std::endl;
187  }
188 
189 
190  {
191  char const * fileName;
193  std::cout << "config file name : " << fileName << std::endl;
194  std::cout << std::endl;
195  }
196 
197 
198  {
203  std::cout << std::endl;
204  }
205 
206 
207  {
212  std::cout << std::endl;
213  }
214 
215 
216  {
217  int extent;
220  std::cout << KIM_CollectionItemType_ToString(
222  << " :\n";
223  for (int i = 0; i < extent; ++i)
224  {
225  char const * name;
226  KIM_Collections_GetItemNameByType(col, i, &name);
227  std::cout << "\t" << name << std::endl;
228  }
231  std::cout << KIM_CollectionItemType_ToString(
233  << " :\n";
234  for (int i = 0; i < extent; ++i)
235  {
236  char const * name;
237  KIM_Collections_GetItemNameByType(col, i, &name);
238  std::cout << "\t" << name << std::endl;
239  }
242  std::cout << KIM_CollectionItemType_ToString(
244  << " :\n";
245  for (int i = 0; i < extent; ++i)
246  {
247  char const * name;
248  KIM_Collections_GetItemNameByType(col, i, &name);
249  std::cout << "\t" << name << std::endl;
250  }
251  }
252 
253  {
254  char const * fileName;
255  KIM_Collection collection;
257  col,
259  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
260  &fileName,
261  &collection);
262  if (!error)
263  std::cout
264  << "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"
265  << " has library name '" << fileName << "' and is part of the '"
266  << KIM_Collection_ToString(collection) << "' collection."
267  << std::endl;
268  else
269  std::cout << "Error from GetItemLibraryFileNameAndCollection."
270  << std::endl;
271  }
272 
273  {
274  int extent;
276  col,
278  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu",
279  &extent);
280  if (error)
281  std::cout << "Error from CacheListOfItemMetadataFiles." << std::endl;
282  else
283  {
284  char const * fileName;
285  unsigned int fileLength;
286  unsigned char const * fileRawData;
287  int availableAsString;
288  char const * fileString;
289  for (int i = 0; i < extent; ++i)
290  {
292  i,
293  &fileName,
294  &fileLength,
295  &fileRawData,
296  &availableAsString,
297  &fileString);
298  std::cout << "Metadata File " << i << ", " << fileName
299  << ", is of length " << fileLength << std::endl
300  << fileString << std::endl;
301  }
302  }
303  }
304 
306  return 0;
307 }
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.