Commit 6b1d2e45 authored by Thomas Kluyver's avatar Thomas Kluyver
Browse files

First attempt at binding UnitCell struct

parent df353ddf
......@@ -115,3 +115,40 @@ cdef class Detector:
def panel_names(self):
return [self._img.detgeom.panels[i].name.decode('utf-8') for i in range(self.n_panels)]
cdef class UnitCell:
cdef crystfel.UnitCell* _ptr
cdef bint ptr_owner
def __cinit__(self):
self.ptr_owner = False
def __dealloc__(self):
# De-allocate if not null and flag is set
if self._ptr is not NULL and self.ptr_owner is True:
self._ptr = NULL
cdef UnitCell from_ptr(crystfel.UnitCell* ptr, bint owner=False):
# Call to __new__ bypasses __init__ constructor
cdef UnitCell cell = UnitCell.__new__(UnitCell)
cell._ptr = ptr
cell.ptr_owner = True
return cell
def from_parameters(cls, double a, double b, double c,
double alpha, double beta, double gamma):
cdef crystfel.UnitCell* ptr = crystfel.cell_new_from_parameters(
a, b, c, alpha, beta, gamma,
return UnitCell.from_ptr(ptr, owner=True)
def lengths(self):
double a, b, c, alpha, beta, gamma
crystfel.cell_get_parameters(self._ptr, &a, &b, &c, &alpha, &beta, &gamma)
return np.array([a, b, c])
......@@ -120,3 +120,31 @@ cdef extern from "crystfel/peaks.h":
int min_pix_count, int max_pix_count, int local_bg_radius, int min_res,
int max_res, int use_saturated
cdef extern from "crystfel/cell.h":
cdef struct rvec:
double u, v, w
ctypedef enum LatticeType:
ctypedef struct UnitCell:
pass # Opaque struct, used through functions
UnitCell* cell_new()
UnitCell* cell_new_from_cell(const UnitCell* orig)
UnitCell* cell_new_from_parameters(double a, double b, double c,
double alpha, double beta, double gamma)
void cell_free(UnitCell* cell)
cell_set_parameters(UnitCell* cell, double a, double b, double c,
double alpha, double beta, double gamma)
int cell_get_parameters(UnitCell* cell, double* a, double* b, double* c,
double* alpha, double* beta, double* gamma)
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