Add library functions for accessing LAMMPS configuration

This commit is contained in:
Richard Berger 2018-06-25 23:56:18 -04:00
parent 35f5a685f6
commit 19f81e0802
5 changed files with 100 additions and 6 deletions

View File

@ -209,6 +209,7 @@ class lammps(object):
self.c_bigint = get_ctypes_int(self.extract_setting("bigint"))
self.c_tagint = get_ctypes_int(self.extract_setting("tagint"))
self.c_imageint = get_ctypes_int(self.extract_setting("imageint"))
self._installed_packages = None
# shut-down LAMMPS instance
@ -562,13 +563,36 @@ class lammps(object):
shrinkexceed)
@property
def uses_exceptions(self):
def has_exceptions(self):
""" Return whether the LAMMPS shared library was compiled with C++ exceptions handling enabled """
try:
if self.lib.lammps_has_error:
return True
except(AttributeError):
return False
return self.lib.lammps_config_has_exceptions() != 0
@property
def has_gzip_support(self):
return self.lib.lammps_config_has_gzip_support() != 0
@property
def has_png_support(self):
return self.lib.lammps_config_has_png_support() != 0
@property
def has_jpeg_support(self):
return self.lib.lammps_config_has_jpeg_support() != 0
@property
def has_ffmpeg_support(self):
return self.lib.lammps_config_has_ffmpeg_support() != 0
@property
def installed_packages(self):
if self._installed_packages is None:
self._installed_packages = []
npackages = self.lib.lammps_config_package_count()
sb = create_string_buffer(100)
for idx in range(npackages):
self.lib.lammps_config_package_name(idx, sb, 100)
self._installed_packages.append(sb.value.decode())
return self._installed_packages
# -------------------------------------------------------------------------
# -------------------------------------------------------------------------

View File

@ -1190,6 +1190,15 @@ bool Info::has_exceptions() {
#endif
}
bool Info::has_package(const char * package_name) {
for(int i = 0; LAMMPS::installed_packages[i] != NULL; ++i) {
if(strcmp(package_name, LAMMPS::installed_packages[i]) == 0) {
return true;
}
}
return false;
}
/* ---------------------------------------------------------------------- */
char **Info::get_variable_names(int &num) {

View File

@ -38,6 +38,7 @@ class Info : protected Pointers {
static bool has_jpeg_support();
static bool has_ffmpeg_support();
static bool has_exceptions();
static bool has_package(const char * package_name);
char **get_variable_names(int &num);

View File

@ -38,6 +38,7 @@
#include "memory.h"
#include "error.h"
#include "force.h"
#include "info.h"
using namespace LAMMPS_NS;
@ -1522,6 +1523,56 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
END_CAPTURE
}
// ----------------------------------------------------------------------
// library API functions for accessing LAMMPS configuration
// ----------------------------------------------------------------------
int lammps_config_has_package(char * package_name) {
return Info::has_package(package_name);
}
int lammps_config_package_count() {
int i = 0;
while(LAMMPS::installed_packages[i] != NULL) {
++i;
}
return i;
}
int lammps_config_package_name(int index, char * buffer, int max_size) {
int i = 0;
while(LAMMPS::installed_packages[i] != NULL && i < index) {
++i;
}
if(LAMMPS::installed_packages[i] != NULL) {
strncpy(buffer, LAMMPS::installed_packages[i], max_size);
return true;
}
return false;
}
int lammps_config_has_gzip_support() {
return Info::has_gzip_support();
}
int lammps_config_has_png_support() {
return Info::has_png_support();
}
int lammps_config_has_jpeg_support() {
return Info::has_jpeg_support();
}
int lammps_config_has_ffmpeg_support() {
return Info::has_ffmpeg_support();
}
int lammps_config_has_exceptions() {
return Info::has_exceptions();
}
// ----------------------------------------------------------------------
// library API functions for error handling
// ----------------------------------------------------------------------

View File

@ -55,6 +55,15 @@ void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *);
void lammps_scatter_atoms(void *, char *, int, int, void *);
void lammps_scatter_atoms_subset(void *, char *, int, int, int, int *, void *);
int lammps_config_has_package(char * package_name);
int lammps_config_package_count();
int lammps_config_package_name(int index, char * buffer, int max_size);
int lammps_config_has_gzip_support();
int lammps_config_has_png_support();
int lammps_config_has_jpeg_support();
int lammps_config_has_ffmpeg_support();
int lammps_config_has_exceptions();
// lammps_create_atoms() takes tagint and imageint as args
// ifdef insures they are compatible with rest of LAMMPS
// caller must match to how LAMMPS library is built