Commit 3a02bb0a authored by Elisa Rebolini's avatar Elisa Rebolini
Browse files

Merge branch 'release_pythonAPI' into 'master'

Release python api 0.0.3

See merge request !33
parents 3b7285b3 0d88de94
Pipeline #14086 passed with stages
in 8 minutes and 35 seconds
......@@ -9,9 +9,7 @@ option(MINGW_HDF_TRICK "Help building with MinGW" OFF)
option(USE_HDF "Build crysfml with HDF5 library" OFF)
option(GUI "Build crysfml and wcrysfml library" OFF)
option(ARCH32 "32 or 64 bit architecture" ON)
option(CRYSFML08 "Build CrysFML08" OFF)
option(HEAP_ARRAYS "Put arrays in heap instead of stack (only for Windows ifort)" OFF)
option(PROG_EX "Build the Program Examples" ON)
option(PYTHON_API "Build Python API" OFF)
option(QPARALLEL "qparallel option for Ifort on Windows" ON)
option(PYSETUP "Building from setup.py" OFF)
......@@ -42,12 +40,9 @@ message(STATUS "Setting CMAKE_INSTALL_PREFIX to ${CMAKE_INSTALL_PREFIX}")
if (DEFINED CRYSFML_PREFIX)
set(CRYSFML_PREFIX ${CRYSFML_PREFIX})
else()
if(CRYSFML08)
set(CRYSFML_PREFIX LibC08)
else()
set(CRYSFML_PREFIX LibC)
endif()
set(CRYSFML_PREFIX LibC)
endif()
set (CRYSFML_PREFIX ${CMAKE_INSTALL_PREFIX}/${CRYSFML_PREFIX})
message(STATUS "CrysFML installation path set to ${CRYSFML_PREFIX}")
......@@ -84,17 +79,17 @@ message(STATUS "CrysFML installation path set to ${CRYSFML_PREFIX}")
# Include and library paths for HDF5.
# They must be set by the user.
if(DEFINED HDF5_INCLUDE_PATH)
set(HDF5_INCLUDE_PATH ${HDF5_INCLUDE_PATH} CACHE PATH "HDF5 include path")
else()
set(HDF5_INCLUDE_PATH "" CACHE PATH "HDF5 include path")
endif()
# if(DEFINED HDF5_INCLUDE_PATH)
# set(HDF5_INCLUDE_PATH ${HDF5_INCLUDE_PATH} CACHE PATH "HDF5 include path")
# else()
# set(HDF5_INCLUDE_PATH "" CACHE PATH "HDF5 include path")
# endif()
if(DEFINED HDF5_LIBRARY_PATH)
set(HDF5_LIBRARY_PATH ${HDF5_LIBRARY_PATH} CACHE PATH "HDF5 library path")
else()
set(HDF5_LIBRARY_PATH "" CACHE PATH "HDF5 library path")
endif()
# if(DEFINED HDF5_LIBRARY_PATH)
# set(HDF5_LIBRARY_PATH ${HDF5_LIBRARY_PATH} CACHE PATH "HDF5 library path")
# else()
# set(HDF5_LIBRARY_PATH "" CACHE PATH "HDF5 library path")
# endif()
#################################
# Project section
......@@ -126,17 +121,12 @@ endif()
# Includes some modules and build the project.
include(add_prefix)
include(add_suffix)
if (NOT CRYSFML08)
include(set_compiler_flags)
set_compiler_flags()
# The subdirectories of the project.
add_subdirectory(Src)
else()
include(set_compiler_flags_08)
set_compiler_flags_08()
# The subdirectories of the project.
add_subdirectory(Src08)
endif()
include(set_compiler_flags)
set_compiler_flags()
# The subdirectories of the project.
add_subdirectory(Src)
# Build the program example executables and use them as functional tests
if (PROG_EX)
......
......@@ -12,7 +12,7 @@ print("========\nCreate job_info from string")
dat = [
'Title SrTiO3',
'Npatt 1',
'Patt_1 NEUT_2THE 1.54056 1.54056 1.00 0.0 135.0',
'Patt_1 XRAY_2THE 1.54056 1.54056 1.00 0.0 135.0',
'UVWXY 0.025 -0.00020 0.01200 0.00150 0.00465',
'STEP 0.05 ',
'Backgd 50.000']
......@@ -22,6 +22,10 @@ job_info.print_description()
job_info.range_2theta = (0.0, 12.0)
job_info.pattern_type = "NEUT_2THE"
job_info.lambda_ratio = 0.5
job_info.print_description()
#help(CFML_api.JobInfo)
......@@ -127,7 +127,17 @@ class JobInfo(CFML_api.FortranBindedClass):
key=0
return CFML_api.crysfml_api.IO_Formats_get_patt_typ(self.get_fortran_address(), key+1)["patt_typ"]
pattern_type = property(get_pattern_types)
def set_pattern_types(self, patt, indx=None):
"""
String with the pattern type of indx in [0, num_patterns-1]
"""
if indx:
key=indx
else:
key=0
return CFML_api.crysfml_api.IO_Formats_set_patt_typ(self.get_fortran_address(), patt, key+1)
pattern_type = property(get_pattern_types, set_pattern_types)
def get_phase_names(self, indx=None):
"""
......@@ -278,7 +288,14 @@ class JobInfo(CFML_api.FortranBindedClass):
key=0
return CFML_api.crysfml_api.IO_Formats_get_ratio(self.get_fortran_address(),key+1)["ratio"]
lambda_ratio = property(get_lambda_ratio)
def set_lambda_ratio(self, ratio, indx=None):
if indx:
key=indx
else:
key=0
CFML_api.crysfml_api.IO_Formats_set_ratio(self.get_fortran_address(), ratio, key+1)
lambda_ratio = property(get_lambda_ratio, set_lambda_ratio)
@property
def d_to_tof_1(self):
......
......@@ -1270,6 +1270,62 @@ contains
!---------------------
!Setters
!---------------------
function IO_Formats_set_patt_typ(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(Job_info_Type_p) :: job_p
type(object) :: val_obj, indx_obj
character(len=:), allocatable :: val
integer :: indx
r = C_NULL_PTR ! in case of an exception return C_NULL_PTR
! use unsafe_cast_from_c_ptr to cast from c_ptr to tuple
call unsafe_cast_from_c_ptr(args, args_ptr)
! Check if the arguments are OK
ierror = args%len(num_args)
! we should also check ierror, but this example does not do complete error checking for simplicity
if (num_args /= 3) then
call raise_exception(TypeError, "set_pattern_types expects exactly 3 arguments")
!self, new_value
call args%destroy
return
endif
! Doing boring stuff
call get_job_info_type_from_arg(args, job_p)
ierror = args%getitem(val_obj, 1) !get the value
ierror = cast_nonstrict(val, val_obj)
ierror = args%getitem(indx_obj, 2) !get the indx
ierror = cast_nonstrict(indx, indx_obj)
select case (val)
case ("XRAY_2THE", "XRAY_SXTAL", "XRAY_ENER","NEUT_2THE", "NEUT_SXTAL", "NEUT_TOF" )
job_p%p%patt_typ(indx) = val
case default
write(*,*) val, " is not a valid pattern type"
end select
ierror = dict_create(retval)
r = retval%get_c_ptr()
call args%destroy
call val_obj%destroy
call indx_obj%destroy
end function IO_Formats_set_patt_typ
function IO_Formats_set_range_2theta(self_ptr, args_ptr) result(r) bind(c)
......@@ -1405,6 +1461,55 @@ contains
call maxb_obj%destroy
end function IO_Formats_set_lambda
function IO_Formats_set_ratio(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(Job_info_Type_p) :: job_p
type(object) :: val_obj, indx_obj
real(kind=cp) :: val
integer :: indx
r = C_NULL_PTR ! in case of an exception return C_NULL_PTR
! use unsafe_cast_from_c_ptr to cast from c_ptr to tuple
call unsafe_cast_from_c_ptr(args, args_ptr)
! Check if the arguments are OK
ierror = args%len(num_args)
! we should also check ierror, but this example does not do complete error checking for simplicity
if (num_args /= 3) then
call raise_exception(TypeError, "set_lambda_ratio expects exactly 3 arguments")
!self, new_value, indx
call args%destroy
return
endif
! Doing boring stuff
call get_job_info_type_from_arg(args, job_p)
ierror = args%getitem(val_obj, 1) !get the value
ierror = cast_nonstrict(val, val_obj)
ierror = args%getitem(indx_obj, 2) !get the phase number
ierror = cast_nonstrict(indx, indx_obj)
job_p%p%ratio(indx) = val
ierror = dict_create(retval)
r = retval%get_c_ptr()
call args%destroy
call val_obj%destroy
call indx_obj%destroy
end function IO_Formats_set_ratio
function IO_Formats_set_U(self_ptr, args_ptr) result(r) bind(c)
......
......@@ -136,16 +136,21 @@ contains
call get_reflection_list_from_arg(args, reflection_list_p, 2)
call get_job_info_type_from_arg(args, job_p, 3)
write(*,*) job_p%p%patt_typ(1)
select case (job_p%p%patt_typ(1))
case ("XRAY_2THE", "XRAY_SXTAL", "XRAY_ENER")
mode = "NUC"
call Structure_Factors(atom_list_p%p, spg_p%p, reflection_list_p%p, mode)
case("NEUT_2THE", "NEUT_SXTAL", "NEUT_TOF" )
mode = "XRA"
!write(*,*) "X-Ray calculation"
lambda = job_p%p%lambda(1)%mina
call Structure_Factors(atom_list_p%p, spg_p%p, reflection_list_p%p, mode, lambda)
call Structure_Factors(atom_list_p%p, spg_p%p, reflection_list_p%p, mode, lambda)
case("NEUT_2THE", "NEUT_SXTAL", "NEUT_TOF" )
mode = "NUC"
!write(*,*) "Neutron calculation"
call Structure_Factors(atom_list_p%p, spg_p%p, reflection_list_p%p, mode)
case default
write(*,*) 'Default calculation'
call Structure_Factors(atom_list_p%p, spg_p%p, reflection_list_p%p)
......
......@@ -69,6 +69,7 @@ module API_init
IO_Formats_get_num_patterns, &
IO_Formats_get_num_cmd, &
IO_Formats_get_patt_typ, &
IO_Formats_set_patt_typ, &
IO_Formats_get_phas_nam, &
IO_Formats_get_cmd, &
IO_Formats_get_range_stl, &
......@@ -80,6 +81,7 @@ module API_init
IO_Formats_get_lambda, &
IO_formats_set_lambda, &
IO_Formats_get_ratio, &
IO_Formats_set_ratio, &
IO_Formats_get_dtt1, &
IO_Formats_get_dtt2, &
IO_Formats_get_U, &
......@@ -271,7 +273,7 @@ CONTAINS
!--------------------------
!Total number of method in the binding
!--------------------------
call method_table%init(208)
call method_table%init(210)
......@@ -708,7 +710,7 @@ CONTAINS
!--------------------------
! IO formats (35)
! IO formats (37)
!--------------------------
call method_table%add_method("IO_Formats_readn_set_xtal_structure", & ! method name
"read an input file and construct the crystal structure in terms of Cell, SpG and A", & !doc-string
......@@ -749,6 +751,11 @@ CONTAINS
"pat_typ getter", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(IO_Formats_get_patt_typ)) ! address of Fortran function to add
call method_table%add_method("IO_Formats_set_patt_typ", & ! method name
"pat_typ setter", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(IO_Formats_set_patt_typ)) ! address of Fortran function to add
call method_table%add_method("IO_Formats_get_phas_nam", & ! method name
"phas_nam getter", & !doc-string
......@@ -804,6 +811,11 @@ CONTAINS
"ratio getter", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(IO_Formats_get_ratio)) ! address of Fortran function to add
call method_table%add_method("IO_Formats_set_ratio", & ! method name
"ratio setter", & !doc-string
METH_VARARGS, & ! this method takes arguments but no keyword arguments
c_funloc(IO_Formats_set_ratio)) ! address of Fortran function to add
call method_table%add_method("IO_Formats_get_dtt1", & ! method name
"dtt1 getter", & !doc-string
......
CMake is a system used to control the software compilation process using simple platform
and compiler independent configuration files. CMake generates native makefiles and
workspaces that can be used in the compiler environment of your choice.
Here are the instructions to run cmake in order to build the CrysFML library.
***
1) download and install a recent version of cmake (>= 2.8.0 required)
***
2) check that the cmake binary directory is in the PATH altogether
with the different compilers that will be used for the build.
***
3) set the environment variable CRYSFML to the directory where the README is
located.
***
4) create a directory wherever you want that will contain the files
generated during the build (e.g. ${CRYSFML}/build).
If you intend to do the build as superuser, this directory should
give recursively the writing rights for every user.
Now you are ready for the cmake run that will configure your build.
***
5) change directory to the build directory created in step 4.
***
6) the CMake usage is:
cmake -G generator -Dvariable=value path_to_your_source_directory
generator:
CMake requires to know for which build tool it shall generate
files (GNU make, Visual Studio, Xcode, etc). If not specified
on the command line, it tries to guess it based on you
environment. Once identified the build tool, CMake uses the
corresponding Generator for creating files for your build tool.
You can explicitly specify the generator with the command line
option -G "Name of the generator".
For knowing the available generators on your platform, execute
cmake --help
This will list the generator's names at the end of the help text.
Take care the generator's names are case-sensitive.
For standard console Makefiles the generator should be:
- "NMake Makefiles" on Windows
- "Unix Makefiles" on Linux
variable:
Variables customize how the build will be generated.
Useful CMake variables (case sensitive):
* USE_HDF: ON|OFF.
Default OFF
If ON, CrysFML will be able to read NeXuS input data files.
* GUI: ON|OFF.
Default OFF
If OFF, only CrysFML will be built.
If ON, both CrysFML and WCrysFML libraries will be built
* CMAKE_Fortran_COMPILER: ifort|g95|gfortran.
Default ifort.
Sets the compiler to use for the build.
* CMAKE_BUILD_TYPE: Release|Debug|RelWithDebInfo|MinSizeRel.
Default Release.
Sets the build type for make based generators.
* CMAKE_INSTALL_PREFIX
Default /usr/lib/libcrysfml (Unix) C:\Program Files\libcrysfml (Windows).
Path where the library will be installed if "make install" is invoked or the
"INSTALL" target is built.
* CRYSFML_PREFIX
Default crysfml.
Sets the name of the subdirectory within CMAKE_INSTALL_PREFIX where
crysfml will be installed.
* WCRYSFML_PREFIX
Default wcrysfml.
Sets the name of the subdirectory within CMAKE_INSTALL_PREFIX where
wcrysfml will be installed.
***
7) the final step is now to build and install the library. The command to invoke will
depend on the generator used for the build.
Examples:
- Unix: make install
- Window: nmake install
CMake is a system used to control the software compilation process using simple platform
and compiler independent configuration files. CMake generates native makefiles and
workspaces that can be used in the compiler environment of your choice.
Here are the instructions to run cmake in order to build the CrysFML library.
1. download and install a recent version of cmake (>= 3.0.0 required)
2. check that the cmake binary directory is in the PATH altogether
with the different compilers that will be used for the build.
3. set the environment variable CRYSFML to the directory where the README.md is
located.
4. create a directory wherever you want that will contain the files
generated during the build (e.g. ${CRYSFML}/build).
If you intend to do the build as superuser, this directory should
give recursively the writing rights for every user.
Now you are ready for the cmake run that will configure your build.
5. change directory to the build directory created in step 4.
6. the CMake usage is:
cmake -G generator -Dvariable=value path_to_your_source_directory
generator:
CMake requires to know for which build tool it shall generate
files (GNU make, Visual Studio, Xcode, etc). If not specified
on the command line, it tries to guess it based on you
environment. Once identified the build tool, CMake uses the
corresponding Generator for creating files for your build tool.
You can explicitly specify the generator with the command line
option -G "Name of the generator".
For knowing the available generators on your platform, execute
cmake --help
This will list the generator's names at the end of the help text.
Take care the generator's names are case-sensitive.
For standard console Makefiles the generator should be:
- "NMake Makefiles" on Windows
- "Unix Makefiles" on Linux
variable:
Variables customize how the build will be generated.
Useful CMake variables (case sensitive):
* USE_HDF: ON|OFF. (Deprecated)
Default OFF
If ON, CrysFML will be able to read NeXuS input data files.
* GUI: ON|OFF.
Default OFF
If OFF, only CrysFML will be built.
If ON, both CrysFML and WCrysFML libraries will be built
* ARCH32: ON|OFF
Default ON
If ON 32-bits architecture is built
* HEAP_ARRAYS: ON|OFF
Default OFF
Put arrays in heap instead of stack (only for Windows ifort)
* PYTHON_API: ON|OFF
Default OFF
If ON, build the Python API
* CMAKE_Fortran_COMPILER: ifort|g95|gfortran.
Default ifort.
Sets the compiler to use for the build.
* CMAKE_BUILD_TYPE: Release|Debug|RelWithDebInfo|MinSizeRel.
Default Release.
Sets the build type for make based generators.
* CMAKE_INSTALL_PREFIX
Default /usr/lib/libcrysfml (Unix) C:\Program Files\libcrysfml (Windows).
Path where the library will be installed if "make install" is invoked or the
"INSTALL" target is built.
* CRYSFML_PREFIX
Default crysfml.
Sets the name of the subdirectory within CMAKE_INSTALL_PREFIX where
crysfml will be installed.
* WCRYSFML_PREFIX
Default wcrysfml.
Sets the name of the subdirectory within CMAKE_INSTALL_PREFIX where
wcrysfml will be installed.
7. the final step is now to build and install the library. The command to invoke will
depend on the generator used for the build.
Examples:
- Unix: make install
- Window: nmake install
import os
import pathlib
import pkgutil
......@@ -326,13 +325,13 @@ class BuildCommand(distutils.command.build.build):
setup(name="CFML",
version="0.0.1",
author="Simon Ward",
author_email="simon.ward@ess.eu",
version="0.0.3",
author="Juan Rodriguez-Carvajal, Elisa Rebolini, Simon Ward",
author_email="rebolini@ill.fr",
description="The Crystallographic Fortran Modules Library (CrysFML) is a set of modules containing "
"procedures of interest in Crystallographic applications.",
ext_modules=[CMakeExtension(name=PACKAGE_NAME)],
long_description=open("./README", 'r').read(),
long_description=open("./README.md", 'r').read(),
long_description_content_type="text/markdown",
keywords="crystallography, physics, neutron, diffraction",
classifiers=["Intended Audience :: Developers",
......@@ -352,4 +351,4 @@ setup(name="CFML",
'bdist_wheel': Bdist_wheel
},
setup_requires=['wheel']
)
\ No newline at end of file
)
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