Commit 2fa04ed9 authored by Elisa Rebolini's avatar Elisa Rebolini
Browse files

Atom list type python API

parent 02257fce
......@@ -18,4 +18,7 @@ class AtomList():
def __init__(self, address=None):
self.__address = None
if address is not None:
self.__address = address
\ No newline at end of file
self.__address = address
def print_description(self):
crysfml_api.atom_typedef_write_atom_list(self.__address)
......@@ -13,6 +13,7 @@ project(Python_API Fortran)
set(LIBRARY_NAME crysfml_api)
add_library(${LIBRARY_NAME} SHARED
Extensions/API_init.f90
Extensions/API_Atom_TypeDef.f90
Extensions/API_Crystallographic_Symmetry.f90
Extensions/API_Crystal_Metrics.f90
Extensions/API_IO_Formats.f90
......
module API_Atom_TypeDef
use forpy_mod
use, intrinsic :: iso_c_binding
use, intrinsic :: iso_fortran_env
use CFML_Atom_TypeDef, only: &
Atom_List_type, &
Atoms_Cell_type, &
Allocate_Atom_List, &
Atoms_Cell_To_List, &
Write_Atom_list
implicit none
type Atom_list_type_p
type(Atom_list_type), pointer :: p
end type Atom_list_type_p
type Atoms_cell_type_p
type(Atoms_cell_type), pointer :: p
end type Atoms_cell_type_p
contains
subroutine get_alist_from_arg(args, cell_p)
type(tuple) :: args
type(Atom_list_type_p), intent(out) :: alist_p
type(object) :: arg_obj
type(list) :: arg_list
integer :: alist_p12(12)
integer :: ierror
integer :: ii
type(object) :: t
ierror = args%getitem(arg_obj, 0)
ierror = cast(arg_list, arg_obj)
do ii=1,12
ierror = arg_list%getitem(t, ii-1)
ierror = cast(alist_p12(ii), t)
enddo
alist_p = transfer(alist_p12, alist_p)
end subroutine get_cell_from_arg
! @brief Allocate an atom list for N atoms
! @todo Do we need to bind that function ??
function atom_typedef_set_atomlist(self_ptr, args_ptr) result(r) bind(c)
type(c_ptr), value :: self_ptr
type(c_ptr), value :: args_ptr
type(c_ptr) :: r
type(tuple) :: args
type(dict) :: retval
integer :: num_args
integer :: ierror
integer :: i,ii
type(list) :: index_obj
type(object) :: natom_obj
integer :: natom
type(Atom_list_type_p) :: alist_p
integer :: alist_p12(12)
r = C_NULL_PTR
call unsafe_cast_from_c_ptr(args, args_ptr)
ierror = args%len(num_args)
if (num_args /=1 ) then
call raise_exception(TypeError, "set_atomlist expects exactly 1 argument")
call args%destroy
return
endif
ierror = args%getitem(natom_obj, 0)
ierror = cast_nonstrict(natom, natom_obj)
allocate(alist_p%p)
call Allocate_Atom_List(natom, alist_p%p)
alist_p12 = transfer(alist_p,alist_p12)
ierror = list_create(index_obj)
do ii=1,12
ierror = index_obj%append(alist_p12(ii))
end do
ierror = dict_create(retval)
ierror = retval%setitem("address", index_obj)
r = retval%get_c_ptr()
end function atom_typedef_set_atomlist
! @brif Print the description of the atom list to standard output
! @todo Optional arguments
function atom_typedef_write_atom_list(self_ptr, args_ptr) result(r) bind(c)
type(c_ptr), value :: self_ptr
type(c_ptr), value :: args_ptr
type(c_ptr) :: r
type(tuple) :: args
type(dict) :: retval
integer :: num_args
integer :: ierror
type(Atom_list_type_p) :: alist_p
r = C_NULL_PTR
call unsafe_cast_from_c_ptr(args, args_ptr)
ierror = args%len(num_args)
if (num_args /= 1) then
call raise_exception(TypeError, "write_atom_list expects exactly 1 argument")
call args%destroy
return
endif
call get_alist_from_arg(args, alist_p)
call Write_Atom_List(alist_p%p)
ierror = dict_create(retval)
r = retval%get_c_ptr()
end function atom_typedef_write_atom_list
end module API_Atom_TypeDef
......@@ -118,6 +118,7 @@ contains
end function crystal_metrics_set_crystal_cell
! @brief Print the description of the cell to standard output
function crystal_metrics_write_crystal_cell(self_ptr, args_ptr) result(r) bind(c)
type(c_ptr), value :: self_ptr
......
......@@ -19,19 +19,13 @@ module API_IO_Formats
use, intrinsic :: iso_fortran_env
use CFML_IO_Formats, only: Readn_set_Xtal_structure
use CFML_Atom_TypeDef, only: Atom_List_Type
use API_Atom_TypeDef, only: Atom_List_Type_p
use API_Crystallographic_Symmetry, only: Space_Group_Type_p
use API_Crystal_Metrics, only: Crystal_Cell_Type_p
implicit none
!type definitions This should be in the API_Atom_TypeDef
type Atom_list_type_p
type(Atom_list_type), pointer :: p
end type Atom_list_type_p
contains
!-------------------------------------------------------------------------
......
......@@ -49,6 +49,9 @@ module API_init
crystal_metrics_get_rcellvol, &
crystal_metrics_get_stdvol, &
crystal_metrics_get_CartType
use API_Atom_TypeDef, only: &
atom_typedef_write_atom_list
implicit none
......@@ -76,7 +79,7 @@ CONTAINS
integer :: ierror
ierror = forpy_initialize()
call method_table%init(27)
call method_table%init(28)
!--------------------------
! Crystallographic Symmetry (6)
!--------------------------
......@@ -117,6 +120,14 @@ CONTAINS
"read an input file and construct the crystal structure in terms of Cell, SpG and A", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(IO_formats_readn_set_xtal_structure)) ! address of Fortran function to add
!--------------------------
! Atom Typedef (1)
!--------------------------
call method_table%add_method("atom_typedef_write_atom_list", & ! method name
"Return the atom list description", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(atom_typedef_write_atom_list)) ! address of Fortran function to add
!--------------------------
! Crystal Metrics (20)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment