Skip to content
Snippets Groups Projects
Commit 19f81e08 authored by Richard Berger's avatar Richard Berger
Browse files

Add library functions for accessing LAMMPS configuration

parent 35f5a685
No related branches found
No related tags found
No related merge requests found
...@@ -209,6 +209,7 @@ class lammps(object): ...@@ -209,6 +209,7 @@ class lammps(object):
self.c_bigint = get_ctypes_int(self.extract_setting("bigint")) self.c_bigint = get_ctypes_int(self.extract_setting("bigint"))
self.c_tagint = get_ctypes_int(self.extract_setting("tagint")) self.c_tagint = get_ctypes_int(self.extract_setting("tagint"))
self.c_imageint = get_ctypes_int(self.extract_setting("imageint")) self.c_imageint = get_ctypes_int(self.extract_setting("imageint"))
self._installed_packages = None
# shut-down LAMMPS instance # shut-down LAMMPS instance
...@@ -562,13 +563,36 @@ class lammps(object): ...@@ -562,13 +563,36 @@ class lammps(object):
shrinkexceed) shrinkexceed)
@property @property
def uses_exceptions(self): def has_exceptions(self):
""" Return whether the LAMMPS shared library was compiled with C++ exceptions handling enabled """ """ Return whether the LAMMPS shared library was compiled with C++ exceptions handling enabled """
try: return self.lib.lammps_config_has_exceptions() != 0
if self.lib.lammps_has_error:
return True @property
except(AttributeError): def has_gzip_support(self):
return False 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
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
# ------------------------------------------------------------------------- # -------------------------------------------------------------------------
......
...@@ -1190,6 +1190,15 @@ bool Info::has_exceptions() { ...@@ -1190,6 +1190,15 @@ bool Info::has_exceptions() {
#endif #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) { char **Info::get_variable_names(int &num) {
......
...@@ -38,6 +38,7 @@ class Info : protected Pointers { ...@@ -38,6 +38,7 @@ class Info : protected Pointers {
static bool has_jpeg_support(); static bool has_jpeg_support();
static bool has_ffmpeg_support(); static bool has_ffmpeg_support();
static bool has_exceptions(); static bool has_exceptions();
static bool has_package(const char * package_name);
char **get_variable_names(int &num); char **get_variable_names(int &num);
......
...@@ -38,6 +38,7 @@ ...@@ -38,6 +38,7 @@
#include "memory.h" #include "memory.h"
#include "error.h" #include "error.h"
#include "force.h" #include "force.h"
#include "info.h"
using namespace LAMMPS_NS; using namespace LAMMPS_NS;
...@@ -1522,6 +1523,56 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type, ...@@ -1522,6 +1523,56 @@ void lammps_create_atoms(void *ptr, int n, tagint *id, int *type,
END_CAPTURE 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 // library API functions for error handling
// ---------------------------------------------------------------------- // ----------------------------------------------------------------------
......
...@@ -55,6 +55,15 @@ void lammps_gather_atoms_subset(void *, char *, int, int, int, int *, void *); ...@@ -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(void *, char *, int, int, void *);
void lammps_scatter_atoms_subset(void *, char *, int, int, 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 // lammps_create_atoms() takes tagint and imageint as args
// ifdef insures they are compatible with rest of LAMMPS // ifdef insures they are compatible with rest of LAMMPS
// caller must match to how LAMMPS library is built // caller must match to how LAMMPS library is built
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment