Xmipp  v3.23.11-Nereus
Classes | Functions | Variables
python_symmetry.h File Reference
#include "Python.h"
Include dependency graph for python_symmetry.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  SymListObject
 

Functions

PyObject * SymList_new (PyTypeObject *type, PyObject *args, PyObject *kwargs)
 
void SymList_dealloc (SymListObject *self)
 
PyObject * SymList_readSymmetryFile (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * SymList_computeDistance (PyObject *obj, PyObject *args, PyObject *kwargs)
 
PyObject * SymList_getSymmetryMatrices (PyObject *obj, PyObject *args, PyObject *kwargs)
 

Variables

PyObject * PyXmippError
 
PyMethodDef SymList_methods []
 
PyTypeObject SymListType
 

Function Documentation

◆ SymList_computeDistance()

PyObject* SymList_computeDistance ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 140 of file python_symmetry.cpp.

141 {
142 
143  PyObject *pyMd = nullptr;
144  auto *pyProjdirMode = Py_False;
145  auto *pyCheckMirrors = Py_False;
146  auto *pyObjectRotation = Py_False;
147 
148  if (PyArg_ParseTuple(args, "O|OOO", &pyMd,
149  &pyProjdirMode,
150  &pyCheckMirrors,
151  &pyObjectRotation))
152  {
153  if (!MetaData_Check(pyMd))
154  PyErr_SetString(PyExc_TypeError,
155  "Expected MetaData as first argument");
156  try
157  {
158  bool projdir_mode = false;
159  bool check_mirrors = false;
160  bool object_rotation = false;
161  if (PyBool_Check(pyProjdirMode))
162  projdir_mode = (pyProjdirMode == Py_True);
163  if (PyBool_Check(pyCheckMirrors))
164  check_mirrors = (pyCheckMirrors == Py_True);
165  if (PyBool_Check(pyObjectRotation))
166  object_rotation = (pyObjectRotation == Py_True);
167  auto *self = (SymListObject*) obj;
168  self->symlist->computeDistance(MetaData_Value(pyMd),projdir_mode,
169  check_mirrors,
170  object_rotation);
171  Py_RETURN_NONE;
172  }
173  catch (XmippError &xe)
174  {
175  PyErr_SetString(PyXmippError, xe.what());
176  }
177  }
178  return nullptr;
179 }
#define MetaData_Check(v)
#define MetaData_Value(v)
PyObject * PyXmippError
Definition: xmippmodule.cpp:47
void(* obj)()

◆ SymList_dealloc()

void SymList_dealloc ( SymListObject self)

Definition at line 49 of file python_symmetry.cpp.

50 {
51  delete self->symlist;
52  Py_TYPE(self)->tp_free(self);
53 }
#define Py_TYPE(op)
Definition: frm_wrap.cpp:761

◆ SymList_getSymmetryMatrices()

PyObject* SymList_getSymmetryMatrices ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 87 of file python_symmetry.cpp.

88 {
89  Matrix2D<double> L(4, 4);
90  Matrix2D<double> R(4, 4);
91  PyObject * symMatrices;
92  PyObject * symMatrix;
93  PyObject * row;
94  char * str = nullptr;
95 
96  if (PyArg_ParseTuple(args, "s", &str))
97  {
98  try
99  {
100  auto *self = (SymListObject*) obj;
101 
102  //create symmetry object
103  self->symlist->readSymmetryFile(str);
104  symMatrices = PyList_New(self->symlist->symsNo()+1);
105  symMatrix = PyList_New(3);
106 
107  //add identity matrix to results
108  row = Py_BuildValue("[fff]", 1., 0., 0.);
109  PyList_SetItem(symMatrix,0,row);
110  row = Py_BuildValue("[fff]", 0., 1., 0.);
111  PyList_SetItem(symMatrix,1,row);
112  row = Py_BuildValue("[fff]", 0., 0., 1.);
113  PyList_SetItem(symMatrix,2,row);
114  PyList_SetItem(symMatrices,0,symMatrix);
115 
116  //copy each symmetry matrix to a python list
117  for (int i=0; i < self->symlist->true_symNo; ++i)
118  {
119  symMatrix = PyList_New(3);
120  self->symlist->getMatrices(i, L, R);
121  for (int j=0; j < 3; ++j)
122  {
123  row = Py_BuildValue("[fff]", R(j,0), R(j,1), R(j,2));
124  PyList_SetItem(symMatrix,j,row);
125  }
126  PyList_SetItem(symMatrices,i+1,symMatrix);
127  }
128  return symMatrices;
129  }
130  catch (XmippError &xe)
131  {
132  PyErr_SetString(PyXmippError, xe.what());
133  }
134  }
135  return nullptr;
136 }
#define i
#define j
PyObject * PyXmippError
Definition: xmippmodule.cpp:47
void(* obj)()

◆ SymList_new()

PyObject* SymList_new ( PyTypeObject *  type,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 37 of file python_symmetry.cpp.

38 {
39  auto *self = (SymListObject*)type->tp_alloc(type, 0);
40  if (self != nullptr)
41  {
42  self->symlist = new SymList();
43  //self->symlist->readSymmetryFile("i3");
44  }
45  return (PyObject *)self;
46 }
viol type

◆ SymList_readSymmetryFile()

PyObject* SymList_readSymmetryFile ( PyObject *  obj,
PyObject *  args,
PyObject *  kwargs 
)

Definition at line 57 of file python_symmetry.cpp.

58 {
59  char * str = nullptr;
60 
61  if (PyArg_ParseTuple(args, "s", &str))
62  {
63  try
64  {
65  auto *self = (SymListObject*) obj;
66  self->symlist->readSymmetryFile(str);
67  Py_RETURN_NONE;
68  }
69  catch (XmippError &xe)
70  {
71  PyErr_SetString(PyXmippError, xe.what());
72  }
73  }
74  return nullptr;
75 }
PyObject * PyXmippError
Definition: xmippmodule.cpp:47
void(* obj)()

Variable Documentation

◆ PyXmippError

PyObject* PyXmippError

Definition at line 47 of file xmippmodule.cpp.

◆ SymList_methods

PyMethodDef SymList_methods[]

Definition at line 277 of file python_symmetry.cpp.

◆ SymListType

PyTypeObject SymListType

Definition at line 295 of file python_symmetry.cpp.