From 840744ec97cab8f5637dce8bc888032ec6354338 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marek=20Ne=C4=8Dada?= Date: Fri, 3 Jul 2020 18:50:44 +0300 Subject: [PATCH] Provide access to more information in ScatteringSystem --- qpms/qpms_c.pyx | 45 ++++++++++++++++++++++++++++++++++++++++++++- qpms/qpms_cdefs.pxd | 1 + 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/qpms/qpms_c.pyx b/qpms/qpms_c.pyx index ab76c97..7ea3b9c 100644 --- a/qpms/qpms_c.pyx +++ b/qpms/qpms_c.pyx @@ -535,6 +535,11 @@ cdef class ScatteringSystem: r.append(self.s[0].p[pi]) return r + property particle_count: + """Number of particles in the system (or unit cell)""" + def __get__(self): + self.check_s() + return self.s[0].p_count property fecv_size: """Length of the full excitation coefficient vector""" def __get__(self): @@ -561,6 +566,44 @@ cdef class ScatteringSystem: def __get__(self): return self.s[0].lattice_dimension + property lattice_basis: + """Direct lattice basis vectors for periodic system in 3D cartesian coordinates""" + def __get__(self): + cdef int d = self.lattice_dimension + if d == 0: + return None + else: + return np.array([[self.s[0].per.lattice_basis[i].x, + self.s[0].per.lattice_basis[i].y, + self.s[0].per.lattice_basis[i].z, + ] for i in range(d)]) + + property reciprocal_basis: + """Reciprocal lattice basis vectors for periodic system in 3D cartesian coordinates""" + def __get__(self): + cdef int d = self.lattice_dimension + if d == 0: + return None + else: + return np.array([[self.s[0].per.reciprocal_basis[i].x, + self.s[0].per.reciprocal_basis[i].y, + self.s[0].per.reciprocal_basis[i].z, + ] for i in range(d)]) + + def bspec_pi(self, qpms_ss_pi_t pi): + """Gives the BaseSpec of a particle defined by an index in the internal particles' order, in the form of an array that can be fed to BaseSpec constructor""" + self.check_s() + cdef qpms_ss_pi_t pcount = self.s[0].p_count + if pi >= pcount or pi < 0: raise IndexError("Invalid particle index") + cdef const qpms_vswf_set_spec_t *bspec = qpms_ss_bspec_pi(self.s, pi) + return np.array([ bspec[0].ilist[i] for i in range(bspec[0].n)]) + property bspecs: + """Gives the BaseSpecs of all particles in the internal particles' order, in the form of arrays that can be fed to BaseSpec constructor""" + def __get__(self): + self.check_s() + cdef qpms_ss_pi_t pi, pcount = self.s[0].p_count + return [self.bspec_pi(pi) for pi in range(pcount)] + property unitcell_volume: def __get__(self): self.check_s() @@ -792,7 +835,7 @@ cdef class ScatteringSystem: cdef np.ndarray[int32_t, ndim=1] ar = np.empty((self.s[0].p_count,), dtype=np.int32) cdef int32_t[::1] ar_view = ar for pi in range(self.s[0].p_count): - ar_view[pi] = self.s[0].tm[self.s[0].p[pi].tmatrix_id].spec[0].n + ar_view[pi] = qpms_ss_bspec_pi(self.s, pi)[0].n return ar diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index 4a3c174..8d43538 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -602,6 +602,7 @@ cdef extern from "scatsystem.h": qpms_tmatrix_operation_t op struct qpms_scatsys_periodic_info_t: cart3_t lattice_basis[3] + cart3_t reciprocal_basis[3] double unitcell_volume double eta #etc. -- 2.11.4.GIT