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