kim-api  2.3.0+v2.3.0.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
collections-example-fortran.f90
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 module error
27  use, intrinsic :: iso_c_binding
28  implicit none
29 
30  public
31 
32 contains
33  recursive subroutine my_error(message)
34  implicit none
35  character(len=*, kind=c_char), intent(in) :: message
36 
37  print *, "* Error : ", trim(message)
38  stop 1
39  end subroutine my_error
40 end module error
41 
42 module utilities
43  implicit none
44 
45  public
46 
47 contains
48  subroutine dirs_for_collection(collection, col)
49  use, intrinsic :: iso_c_binding
53  implicit none
54  type(kim_collection_type), intent(in) :: collection
55  type(kim_collections_handle_type), intent(inout) :: col
56 
57  integer(c_int) ierr
58  integer(c_int) i
59  integer(c_int) extent
60  character(len=2048, kind=c_char) coll_str
61  character(len=2048, kind=c_char) item_type_str
62  character(len=2048, kind=c_char) dir_str
63 
64  call kim_cache_list_of_directory_names( &
65  col, collection, kim_collection_item_type_model_driver, extent, ierr)
66  call kim_to_string(collection, coll_str)
67  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
68  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
69 
70  do i = 1, extent
71  call kim_get_directory_name(col, i, dir_str, ierr)
72  print '(A,A)', achar(9), trim(dir_str)
73  end do
74 
75  call kim_cache_list_of_directory_names( &
76  col, collection, kim_collection_item_type_portable_model, extent, ierr)
77  call kim_to_string(collection, coll_str)
78  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
79  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
80 
81  do i = 1, extent
82  call kim_get_directory_name(col, i, dir_str, ierr)
83  print '(A,A)', achar(9), trim(dir_str)
84  end do
85 
86  call kim_cache_list_of_directory_names( &
87  col, collection, kim_collection_item_type_simulator_model, extent, ierr)
88  call kim_to_string(collection, coll_str)
89  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
90  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
91 
92  do i = 1, extent
93  call kim_get_directory_name(col, i, dir_str, ierr)
94  print '(A,A)', achar(9), trim(dir_str)
95  end do
96  end subroutine dirs_for_collection
97 
98  subroutine names_for_collection(kc, col)
99  use, intrinsic :: iso_c_binding
103  implicit none
104  type(kim_collection_type), intent(in) :: kc
105  type(kim_collections_handle_type), intent(inout) :: col
106 
107  integer(c_int) ierr
108  integer(c_int) i
109  integer(c_int) extent
110  character(len=2048, kind=c_char) coll_str
111  character(len=2048, kind=c_char) item_type_str
112  character(len=2048, kind=c_char) name_str
113 
114  call kim_cache_list_of_item_names_by_collection_and_type( &
115  col, kc, kim_collection_item_type_model_driver, extent, ierr)
116  call kim_to_string(kc, coll_str)
117  call kim_to_string(kim_collection_item_type_model_driver, item_type_str)
118  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
119 
120  do i = 1, extent
121  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
122  print '(A,A)', achar(9), trim(name_str)
123  end do
124 
125  call kim_cache_list_of_item_names_by_collection_and_type( &
126  col, kc, kim_collection_item_type_portable_model, extent, ierr)
127  call kim_to_string(kc, coll_str)
128  call kim_to_string(kim_collection_item_type_portable_model, item_type_str)
129  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
130 
131  do i = 1, extent
132  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
133  print '(A,A)', achar(9), trim(name_str)
134  end do
135 
136  call kim_cache_list_of_item_names_by_collection_and_type( &
137  col, kc, kim_collection_item_type_simulator_model, extent, ierr)
138  call kim_to_string(kc, coll_str)
139  call kim_to_string(kim_collection_item_type_simulator_model, item_type_str)
140  print '(A,":",A," :")', trim(coll_str), trim(item_type_str)
141 
142  do i = 1, extent
143  call kim_get_item_name_by_collection_and_type(col, i, name_str, ierr)
144  print '(A,A)', achar(9), trim(name_str)
145  end do
146  end subroutine names_for_collection
147 end module utilities
148 
149 !-------------------------------------------------------------------------------
150 !
151 ! Main program
152 !
153 !-------------------------------------------------------------------------------
155  use, intrinsic :: iso_c_binding
156  use error
157  use utilities
161  implicit none
162 
163  integer(c_int) :: ierr
164  integer(c_int) :: extent
165  integer(c_int) :: i
166  type(kim_collections_handle_type) :: col
167  type(kim_collection_type) col_t
168  type(kim_collection_item_type_type) it
169  character(len=2048, kind=c_char) project_name
170  character(len=2048, kind=c_char) sem_ver
171  character(len=2048, kind=c_char) name
172  character(len=2048, kind=c_char) value
173  character(len=2048, kind=c_char) file_name
174  integer(c_long) file_length
175  integer(c_int) available_as_string
176  integer(c_signed_char) file_raw_data(10000)
177  character(len=10000, kind=c_char) file_string
178  character(len=2048, kind=c_char) item_type_str
179 
180  call kim_collections_create(col, ierr)
181 
182  if (ierr /= 0) then
183  call my_error("Unable to create collections object.")
184  end if
185 
186  call kim_get_project_name_and_sem_ver(col, project_name, sem_ver)
187  print *, "Project : ", trim(project_name)
188  print *, "semVer : ", trim(sem_ver)
189  print *, ""
190 
192  call kim_get_environment_variable_name(col, it, name, ierr)
193  call kim_to_string(it, item_type_str)
194  print '(A," env name : ",A)', trim(item_type_str), trim(name)
195  print *, ""
196 
198  call kim_get_environment_variable_name(col, it, name, ierr)
199  call kim_to_string(it, item_type_str)
200  print '(A," env name : ",A)', trim(item_type_str), trim(name)
201  print *, ""
202 
204  call kim_get_environment_variable_name(col, it, name, ierr)
205  call kim_to_string(it, item_type_str)
206  print '(A," env name : ",A)', trim(item_type_str), trim(name)
207  print *, ""
208 
209  call kim_get_configuration_file_environment_variable(col, name, value)
210  print '("config file env name : ",A)', trim(name)
211  print '("config file env value : ",A)', trim(value)
212  print *, ""
213 
214  call kim_get_configuration_file_name(col, file_name)
215  print '("config file name : ",A)', trim(file_name)
216  print *, ""
217 
222  print *, ""
223 
228  print *, ""
229 
231  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
232  call kim_to_string(it, item_type_str)
233  print '(A," :")', trim(item_type_str)
234  do i = 1, extent
235  call kim_get_item_name_by_type(col, i, name, ierr)
236  print '(A,A)', achar(9), trim(name)
237  end do
238 
240  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
241  call kim_to_string(it, item_type_str)
242  print '(A," :")', trim(item_type_str)
243  do i = 1, extent
244  call kim_get_item_name_by_type(col, i, name, ierr)
245  print '(A,A)', achar(9), trim(name)
246  end do
247 
249  call kim_cache_list_of_item_names_by_type(col, it, extent, ierr)
250  call kim_to_string(it, item_type_str)
251  print '(A," :")', trim(item_type_str)
252  do i = 1, extent
253  call kim_get_item_name_by_type(col, i, name, ierr)
254  print '(A,A)', achar(9), trim(name)
255  end do
256 
257  call kim_get_item_library_file_name_and_collection( &
258  col, it, trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), name, &
259  col_t, ierr)
260  if (ierr /= 0) then
261  print '(A)', "Error from GetItemLibraryFileNameAndCollection"
262  else
263  call kim_to_string(col_t, value)
264  print '(A,A,A,A,A,A)', &
265  "Simulator Model Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu ", &
266  "has library name '", trim(name), "' and is part of the '", &
267  trim(value), "' collection."
268  end if
269 
270  call kim_cache_list_of_item_metadata_files( &
271  col, it, trim("Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu"), extent, ierr)
272  if (ierr /= 0) then
273  print '(A)', "Error from CacheListOfItemMetadataFiles"
274  else
275  do i = 1, extent
276  call kim_get_item_metadata_file_length(col, i, file_length, &
277  available_as_string, ierr)
278  call kim_get_item_metadata_file_values(col, i, file_name, &
279  file_raw_data, file_string, ierr)
280  print '(A,I2,A,A,A,I6)', "Metadata File ", i, ", ", trim(file_name), &
281  ", is of length", file_length
282  print '(A)', trim(file_string)
283  end do
284  end if
285 
286  call kim_collections_destroy(col)
287 
288 end program collections_example_fortran
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_model_driver
type(kim_collection_type), save, public, protected kim_collection_user
subroutine dirs_for_collection(collection, col)
An Extensible Enumeration for the CollectionItemType's supported by the KIM API.
recursive subroutine, public kim_collections_create(collections_handle, ierr)
Create a new KIM API Collections object.
Provides the interface to the KIM API Collections and is meant to be used by simulators.
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_portable_model
recursive subroutine my_error(message)
type(kim_collection_type), save, public, protected kim_collection_environment_variable
subroutine names_for_collection(kc, col)
type(kim_collection_item_type_type), save, public, protected kim_collection_item_type_simulator_model
type(kim_collection_type), save, public, protected kim_collection_system
program collections_example_fortran
type(kim_collection_type), save, public, protected kim_collection_current_working_directory
An Extensible Enumeration for the Collection's supported by the KIM API.
recursive subroutine, public kim_collections_destroy(collections_handle)
Destroy a previously Collections::Create'd object.