kim-api  2.2.1+v2.2.1.GNU.GNU.
An Application Programming Interface (API) for the Knowledgebase of Interatomic Models (KIM).
simulator-model-example-fortran.f90
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) 2013--2020, Regents of the University of Minnesota.
23 ! All rights reserved.
24 !
25 ! Contributors:
26 ! Ryan S. Elliott
27 !
28 
29 module error
30  use, intrinsic :: iso_c_binding
31  implicit none
32 
33  public
34 
35 contains
36  recursive subroutine my_error(message)
37  implicit none
38  character(len=*, kind=c_char), intent(in) :: message
39 
40  print *, "* Error : ", trim(message)
41  stop 1
42  end subroutine my_error
43 
44  recursive subroutine my_warning(message)
45  implicit none
46  character(len=*, kind=c_char), intent(in) :: message
47 
48  print *, "* Warning : ", trim(message)
49  end subroutine my_warning
50 end module error
51 
52 !-------------------------------------------------------------------------------
53 !
54 ! Main program
55 !
56 !-------------------------------------------------------------------------------
58  use, intrinsic :: iso_c_binding
59  use error
61  implicit none
62  interface
63  integer(c_int) function c_system(cmd) bind(c, name="system")
64  use, intrinsic :: iso_c_binding
65  character(c_char), intent(in) :: cmd(*)
66  end function c_system
67  end interface
68 
69  integer(c_int) :: ierr
70  integer(c_int) :: extent
71  integer(c_int) :: no_fields
72  integer(c_int) :: i
73  integer(c_int) :: j
74  type(kim_simulator_model_handle_type) :: sm
75 
76  character(len=2048, kind=c_char) s_name
77  character(len=2048, kind=c_char) s_ver
78  character(len=2048, kind=c_char) species
79  character(len=2048, kind=c_char) field_name
80  character(len=2048, kind=c_char) line
81  character(len=2048, kind=c_char) dir_name
82  character(len=2048, kind=c_char) spec_name
83  character(len=2048, kind=c_char) param_basename
84 
85  call kim_simulator_model_create( &
86  "Sim_LAMMPS_LJcut_AkersonElliott_Alchemy_PbAu", sm, ierr)
87 
88  if (ierr /= 0) then
89  call my_error("Can't create SM.")
90  end if
91 
92  call kim_get_simulator_name_and_version(sm, s_name, s_ver)
93  print *, "Simulator name : ", trim(s_name)
94  print *, "Simulator version : ", trim(s_ver)
95  print *, ""
96 
97  call kim_get_number_of_supported_species(sm, extent)
98  print *, "SM supports", extent, " species:"
99  do i = 1, extent
100  call kim_get_supported_species(sm, i, species, ierr)
101  if (ierr /= 0) then
102  call my_error("Unable to get species.")
103  else
104  print '(A,I2," ",A)', achar(9), i, trim(species)
105  end if
106  end do
107  print *, ""
108 
109  call kim_add_template_map(sm, "atom-type-sym-list", "Pb Pb Au Pb", ierr)
110  if (ierr /= 0) then
111  call my_error("Unable to add template map.")
112  end if
113  call kim_close_template_map(sm)
114  call kim_get_number_of_simulator_fields(sm, no_fields)
115  print '("SM has ",I2," fields :")', no_fields
116  do i = 1, no_fields
117  call kim_get_simulator_field_metadata(sm, i, extent, field_name, ierr)
118  print '(" Field",I2," is ",A," and has ",I2," lines:")', &
119  i, trim(field_name), extent
120 
121  do j = 1, extent
122  call kim_get_simulator_field_line(sm, i, j, line, ierr)
123  if (ierr /= 0) then
124  call my_error("Unable to get field line.")
125  else
126  print '(A,A)', achar(9), trim(line)
127  end if
128  end do
129  end do
130  print *, ""
131 
132  call kim_get_parameter_file_directory_name(sm, dir_name)
133  print '("SM param dir name is ",A)', trim(dir_name)
134 
135  call kim_get_specification_file_name(sm, spec_name)
136  print '("SM spec file name is ",A)', trim(spec_name)
137  ierr = c_system("cat "//trim(dir_name)//"/"//trim(spec_name)//c_null_char)
138 
139  call kim_get_number_of_parameter_files(sm, extent)
140  print '("SM has ",I1," parameter files:")', extent
141  do i = 1, extent
142  call kim_get_parameter_file_basename(sm, i, param_basename, ierr)
143  if (ierr /= 0) then
144  call my_error("Unable to get parameter file basename.")
145  else
146  print '("Parameter file ",I2," has basename ",A)', i, trim(param_basename)
147  ierr = c_system( &
148  "cat "//trim(dir_name)//"/"//trim(param_basename)//c_null_char)
149  print *, ""
150  end if
151  end do
152 
153  call kim_simulator_model_destroy(sm)
154 
155 end program collections_example_fortran
recursive subroutine my_warning(message)
recursive subroutine my_error(message)
program collections_example_fortran