source: sasview/realSpaceModeling/pointsmodelpy/pointsmodelpymodule/misc.cc @ fbae881

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since fbae881 was 112f54c, checked in by Mathieu Doucet <doucetm@…>, 15 years ago

real_space_modeling: added method to return P(r) as two lists

  • Property mode set to 100644
File size: 24.3 KB
Line 
1// -*- C++ -*-
2#include <Python.h>
3
4#include <vector>
5#include <cstring>
6#include <stdexcept>
7#include "Point3D.h"
8#include "misc.h"
9#include "lores_model.h"
10#include "pdb_model.h"
11#include "complex_model.h"
12#include "geo_shape.h"
13#include "iq.h"
14
15// copyright
16
17char pypointsmodelpy_copyright__doc__[] = "";
18char pypointsmodelpy_copyright__name__[] = "copyright";
19
20static char pypointsmodelpy_copyright_note[] = 
21    "pointsmodelpy python module: Copyright (c) 2007 University of Tennessee";
22
23
24PyObject * pypointsmodelpy_copyright(PyObject *, PyObject *)
25{
26    return Py_BuildValue("s", pypointsmodelpy_copyright_note);
27}
28   
29// new_loresmodel
30//wrapper for LORESModel constructor LORESModel(double density)
31
32char pypointsmodelpy_new_loresmodel__doc__[] = "Low-resolution shapes:real space geometric complex models";
33char pypointsmodelpy_new_loresmodel__name__[] = "new_loresmodel";
34
35PyObject * pypointsmodelpy_new_loresmodel(PyObject *, PyObject *args)
36{
37  double density = 0;
38
39  int ok = PyArg_ParseTuple(args, "d",&density);
40  if(!ok) return NULL;
41
42  LORESModel *newlores = new LORESModel(density);
43  return PyCObject_FromVoidPtr(newlores, PyDelLores);
44}
45   
46void PyDelLores(void *ptr){
47  LORESModel * oldlores = static_cast<LORESModel *>(ptr);
48  delete oldlores;
49  return;
50}
51
52//LORESModel methods add(GeoShape &, double sld)
53char pypointsmodelpy_lores_add__name__[] = "lores_add";
54char pypointsmodelpy_lores_add__doc__[] = "loresmodel method:add(Geoshape &,sld)";
55
56PyObject * pypointsmodelpy_lores_add(PyObject *, PyObject *args){
57  double sld = 1;
58  PyObject *pyloresmodel = 0, *pyshape = 0;
59  int ok = PyArg_ParseTuple(args, "OOd", &pyloresmodel, &pyshape, &sld);
60  if(!ok) return NULL;
61
62  void *temp = PyCObject_AsVoidPtr(pyloresmodel);
63  void *temp2 = PyCObject_AsVoidPtr(pyshape);
64
65  LORESModel * thislores = static_cast<LORESModel *>(temp);
66  GeoShape * thisshape = static_cast<GeoShape *>(temp2);
67
68  thislores->Add(*thisshape, sld);
69
70  return Py_BuildValue("i", 0);
71}
72
73//LORESModel methods GetPoints(vector<Point3D> &)
74char pypointsmodelpy_get_lorespoints__name__[] = "get_lorespoints";
75char pypointsmodelpy_get_lorespoints__doc__[] = "get the points from the lores model";
76
77PyObject * pypointsmodelpy_get_lorespoints(PyObject *, PyObject *args){
78  PyObject *pyloresmodel = 0, *pypoint3dvec = 0;
79  int ok = PyArg_ParseTuple(args, "OO", &pyloresmodel, &pypoint3dvec);
80  if(!ok) return NULL;
81
82  void *temp = PyCObject_AsVoidPtr(pyloresmodel);
83  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
84
85  LORESModel * thislores = static_cast<LORESModel *>(temp);
86  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
87
88  int npts = thislores->GetPoints(*thisvec);
89  //temporary
90  thislores->WritePoints2File(*thisvec);
91  return Py_BuildValue("i", npts);
92}
93
94// new_pdbmodel
95//wrapper for PDBModel constructor PDBModel()
96
97char pypointsmodelpy_new_pdbmodel__doc__[] = "PDB model: contain atomic coordinate from PDB file & Scattering length density";
98char pypointsmodelpy_new_pdbmodel__name__[] = "new_pdbmodel";
99
100PyObject * pypointsmodelpy_new_pdbmodel(PyObject *, PyObject *args)
101{
102  PDBModel *newpdb = new PDBModel();
103  return PyCObject_FromVoidPtr(newpdb, PyDelPDB);
104}
105   
106void PyDelPDB(void *ptr){
107  PDBModel * oldpdb = static_cast<PDBModel *>(ptr);
108  delete oldpdb;
109  return;
110}
111
112//PDBModel methods AddPDB(char * pdbfile)
113char pypointsmodelpy_pdbmodel_add__name__[] = "pdbmodel_add";
114char pypointsmodelpy_pdbmodel_add__doc__[] = "Add a structure from PDB";
115
116PyObject * pypointsmodelpy_pdbmodel_add(PyObject *, PyObject *args){
117  PyObject *pypdbmodel = 0;
118  char * pdbfile;
119
120  int ok = PyArg_ParseTuple(args, "Os", &pypdbmodel, &pdbfile);
121  if(!ok) return NULL;
122
123  void *temp = PyCObject_AsVoidPtr(pypdbmodel);
124
125  PDBModel * thispdb = static_cast<PDBModel *>(temp);
126
127  thispdb->AddPDB(pdbfile);
128
129  return Py_BuildValue("i", 0);
130}
131
132//PDBModel methods GetPoints(Point3DVector &)
133char pypointsmodelpy_get_pdbpoints__name__[] = "get_pdbpoints";
134char pypointsmodelpy_get_pdbpoints__doc__[] = "Get atomic points from pdb with SLD";
135
136PyObject * pypointsmodelpy_get_pdbpoints(PyObject *, PyObject *args){
137  PyObject *pypdbmodel = 0, *pypoint3dvec = 0;
138  int ok = PyArg_ParseTuple(args, "OO", &pypdbmodel, &pypoint3dvec);
139  if(!ok) return NULL;
140
141  void *temp = PyCObject_AsVoidPtr(pypdbmodel);
142  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
143
144  PDBModel * thispdb = static_cast<PDBModel *>(temp);
145  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
146
147  int npts = thispdb->GetPoints(*thisvec);
148
149  return Py_BuildValue("i", npts);
150}
151
152// new_complexmodel
153//wrapper for ComplexModel constructor ComplexModel()
154
155char pypointsmodelpy_new_complexmodel__doc__[] = "COMPLEX model: contain LORES and PDB models";
156char pypointsmodelpy_new_complexmodel__name__[] = "new_complexmodel";
157
158PyObject * pypointsmodelpy_new_complexmodel(PyObject *, PyObject *args)
159{
160  ComplexModel *newcomplex = new ComplexModel();
161  return PyCObject_FromVoidPtr(newcomplex, PyDelComplex);
162}
163   
164void PyDelComplex(void *ptr){
165  ComplexModel * oldcomplex = static_cast<ComplexModel *>(ptr);
166  delete oldcomplex;
167  return;
168}
169
170//ComplexModel methods Add(PointsModel *)
171char pypointsmodelpy_complexmodel_add__name__[] = "complexmodel_add";
172char pypointsmodelpy_complexmodel_add__doc__[] = "Add LORES model or PDB Model,type has to be specified (either PDB or LORES)";
173
174PyObject * pypointsmodelpy_complexmodel_add(PyObject *, PyObject *args){
175  PyObject *pycomplexmodel = 0, *pymodel = 0;
176  char * modeltype;
177
178  int ok = PyArg_ParseTuple(args, "OOs", &pycomplexmodel,&pymodel, &modeltype);
179  if(!ok) return NULL;
180
181  void *temp2 = PyCObject_AsVoidPtr(pycomplexmodel);
182  ComplexModel *thiscomplex = static_cast<ComplexModel *>(temp2);
183
184  void *temp = PyCObject_AsVoidPtr(pymodel);
185  if (strcmp(modeltype,"LORES") == 0){
186    LORESModel * thislores = static_cast<LORESModel *>(temp);
187    thiscomplex->Add(thislores);
188  }
189  else if (strcmp(modeltype,"PDB") == 0){
190    PDBModel * thispdb = static_cast<PDBModel *>(temp);
191    thiscomplex->Add(thispdb);
192  }
193  else{
194    throw runtime_error("The model type is either PDB or LORES");
195  }
196
197  return Py_BuildValue("i", 0);
198}
199
200//ComplexModel methods GetPoints(Point3DVector &)
201char pypointsmodelpy_get_complexpoints__name__[] = "get_complexpoints";
202char pypointsmodelpy_get_complexpoints__doc__[] = "Get points from complex model (container for LORES & PDB model)";
203
204PyObject * pypointsmodelpy_get_complexpoints(PyObject *, PyObject *args){
205  PyObject *pycomplexmodel = 0, *pypoint3dvec = 0;
206  int ok = PyArg_ParseTuple(args, "OO", &pycomplexmodel, &pypoint3dvec);
207  if(!ok) return NULL;
208
209  void *temp = PyCObject_AsVoidPtr(pycomplexmodel);
210  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
211
212  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
213  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
214
215  int npts = thiscomplex->GetPoints(*thisvec);
216
217  return Py_BuildValue("i", npts);
218}
219
220//create a new vector that holds of class Point3D objects
221char pypointsmodelpy_new_point3dvec__doc__[] = "";
222char pypointsmodelpy_new_point3dvec__name__[] = "new_point3dvec";
223
224PyObject * pypointsmodelpy_new_point3dvec(PyObject *, PyObject *args)
225{
226  PyObject *pyvec = 0;
227
228  vector<Point3D> *newvec = new vector<Point3D>();
229
230  return PyCObject_FromVoidPtr(newvec, PyDelPoint3DVec);
231}
232
233void PyDelPoint3DVec(void *ptr)
234{
235  vector<Point3D> * oldvec = static_cast<vector<Point3D> *>(ptr);
236  delete oldvec;
237  return;
238
239}
240
241//LORESModel method distribution(point3dvec)
242char pypointsmodelpy_get_lores_pr__name__[] = "get_lores_pr";
243char pypointsmodelpy_get_lores_pr__doc__[] = "calculate distance distribution function";
244
245PyObject * pypointsmodelpy_get_lores_pr(PyObject *, PyObject *args)
246{
247  PyObject *pymodel = 0, *pypoint3dvec = 0;
248  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pypoint3dvec);
249  if(!ok) return NULL;
250
251  void *temp = PyCObject_AsVoidPtr(pymodel);
252  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
253  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
254
255  LORESModel * thislores = static_cast<LORESModel *>(temp);
256  double rmax = thislores->DistDistribution(*thisvec);
257 
258  return Py_BuildValue("d", rmax);
259}
260
261//LORESModel method distribution_xy(point3dvec)
262char pypointsmodelpy_distdistribution_xy__name__[] = "distdistribution_xy";
263char pypointsmodelpy_distdistribution_xy__doc__[] = "calculate distance distribution function on XY plane";
264
265PyObject * pypointsmodelpy_distdistribution_xy(PyObject *, PyObject *args)
266{
267  PyObject *pymodel = 0, *pypoint3dvec = 0;
268  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pypoint3dvec);
269  if(!ok) return NULL;
270
271  void *temp = PyCObject_AsVoidPtr(pymodel);
272  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
273
274  LORESModel * thislores = static_cast<LORESModel *>(temp);
275
276  Py_BEGIN_ALLOW_THREADS
277  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
278  thislores->DistDistributionXY(*thisvec);
279  Py_END_ALLOW_THREADS
280 
281  return Py_BuildValue("i", 0);
282}
283
284//PDBModel method distribution_xy(point3dvec)
285char pypointsmodelpy_get_pdb_pr_xy__name__[] = "get_pdb_pr_xy";
286char pypointsmodelpy_get_pdb_pr_xy__doc__[] = "calculate distance distribution function on XY plane";
287
288PyObject * pypointsmodelpy_get_pdb_pr_xy(PyObject *, PyObject *args)
289{
290  PyObject *pymodel = 0, *pypoint3dvec = 0;
291  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pypoint3dvec);
292  if(!ok) return NULL;
293
294  void *temp = PyCObject_AsVoidPtr(pymodel);
295  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
296  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
297
298  PDBModel * thispdb = static_cast<PDBModel *>(temp);
299  thispdb->DistDistributionXY(*thisvec);
300
301  return Py_BuildValue("i", 0);
302}
303
304//PDBModel method distribution(point3dvec)
305char pypointsmodelpy_get_pdb_pr__name__[] = "get_pdb_pr";
306char pypointsmodelpy_get_pdb_pr__doc__[] = "calculate distance distribution function";
307
308PyObject * pypointsmodelpy_get_pdb_pr(PyObject *, PyObject *args)
309{
310  PyObject *pymodel = 0, *pypoint3dvec = 0;
311  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pypoint3dvec);
312  if(!ok) return NULL;
313
314  void *temp = PyCObject_AsVoidPtr(pymodel);
315  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
316  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
317
318  Py_BEGIN_ALLOW_THREADS
319  PDBModel * thispdb = static_cast<PDBModel *>(temp);
320  thispdb->DistDistribution(*thisvec);
321  Py_END_ALLOW_THREADS
322 
323  return Py_BuildValue("i", 0);
324}
325
326//ComplexModel method distribution(point3dvec)
327char pypointsmodelpy_get_complex_pr__name__[] = "get_complex_pr";
328char pypointsmodelpy_get_complex_pr__doc__[] = "calculate distance distribution function";
329
330PyObject * pypointsmodelpy_get_complex_pr(PyObject *, PyObject *args)
331{
332  PyObject *pymodel = 0, *pypoint3dvec = 0;
333  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pypoint3dvec);
334  if(!ok) return NULL;
335
336  void *temp = PyCObject_AsVoidPtr(pymodel);
337  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
338  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
339
340  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
341  Py_BEGIN_ALLOW_THREADS
342  thiscomplex->DistDistribution(*thisvec);
343  Py_END_ALLOW_THREADS
344  return Py_BuildValue("i", 0);
345}
346
347//LORESModel method CalculateIQ(iq)
348char pypointsmodelpy_get_lores_iq__name__[] = "get_lores_iq";
349char pypointsmodelpy_get_lores_iq__doc__[] = "calculate scattering intensity";
350
351PyObject * pypointsmodelpy_get_lores_iq(PyObject *, PyObject *args)
352{
353  PyObject *pylores = 0, *pyiq = 0;
354  int ok = PyArg_ParseTuple(args, "OO", &pylores, &pyiq);
355  if(!ok) return NULL;
356
357  void *temp = PyCObject_AsVoidPtr(pylores);
358  void *temp2 = PyCObject_AsVoidPtr(pyiq);
359
360  LORESModel * thislores = static_cast<LORESModel *>(temp);
361  IQ * thisiq = static_cast<IQ *>(temp2);
362
363  Py_BEGIN_ALLOW_THREADS
364  thislores->CalculateIQ(thisiq);
365  Py_END_ALLOW_THREADS
366 
367  return Py_BuildValue("i",0);
368}
369
370//LORESModel method CalculateIQ(q)
371char pypointsmodelpy_get_lores_i__name__[] = "get_lores_i";
372char pypointsmodelpy_get_lores_i__doc__[] = "calculate averaged scattering intensity from a single q";
373
374PyObject * pypointsmodelpy_get_lores_i(PyObject *, PyObject *args)
375{
376  PyObject *pylores = 0;
377  double q = 0;
378  int ok = PyArg_ParseTuple(args, "Od", &pylores, &q);
379  if(!ok) return NULL;
380
381  void *temp = PyCObject_AsVoidPtr(pylores);
382
383  LORESModel * thislores = static_cast<LORESModel *>(temp);
384 
385  double I = 0.0;
386  Py_BEGIN_ALLOW_THREADS
387  I = thislores->CalculateIQ(q);
388  Py_END_ALLOW_THREADS
389 
390  return Py_BuildValue("d",I);
391}
392
393// method calculateIQ_2D(iq)
394char pypointsmodelpy_calculateIQ_2D__name__[] = "calculateIQ_2D";
395char pypointsmodelpy_calculateIQ_2D__doc__[] = "calculate scattering intensity";
396
397PyObject * pypointsmodelpy_calculateIQ_2D(PyObject *, PyObject *args)
398{
399  PyObject *pylores = 0, *pyiq = 0;
400  double theta = 0;
401  int ok = PyArg_ParseTuple(args, "OOd", &pylores, &pyiq,&theta);
402  if(!ok) return NULL;
403
404  void *temp = PyCObject_AsVoidPtr(pylores);
405  void *temp2 = PyCObject_AsVoidPtr(pyiq);
406
407  LORESModel * thislores = static_cast<LORESModel *>(temp);
408  IQ * thisiq = static_cast<IQ *>(temp2);
409 
410  Py_BEGIN_ALLOW_THREADS
411  thislores->CalculateIQ_2D(thisiq,theta);
412  Py_END_ALLOW_THREADS
413 
414  return Py_BuildValue("i",0);
415}
416
417// method calculateI_Qxy(Qx,Qy)
418char pypointsmodelpy_calculateI_Qxy__name__[] = "calculateI_Qxy";
419char pypointsmodelpy_calculateI_Qxy__doc__[] = "calculate scattering intensity on a 2D pixel";
420
421PyObject * pypointsmodelpy_calculateI_Qxy(PyObject *, PyObject *args)
422{
423  PyObject *pylores = 0;
424  double qx = 0, qy = 0;
425  double I = 0;
426
427  int ok = PyArg_ParseTuple(args, "Odd", &pylores, &qx,&qy);
428  if(!ok) return NULL;
429
430  void *temp = PyCObject_AsVoidPtr(pylores);
431  LORESModel * thislores = static_cast<LORESModel *>(temp);
432 
433  Py_BEGIN_ALLOW_THREADS
434  I = thislores->CalculateIQ_2D(qx,qy);
435  Py_END_ALLOW_THREADS
436 
437  return Py_BuildValue("d",I);
438}
439
440// method calculateI_Qxy(poitns, Qx,Qy)
441char pypointsmodelpy_calculateI_Qvxy__name__[] = "calculateI_Qvxy";
442char pypointsmodelpy_calculateI_Qvxy__doc__[] = "calculate scattering intensity on a 2D pixel";
443
444PyObject * pypointsmodelpy_calculateI_Qvxy(PyObject *, PyObject *args)
445{
446  PyObject *pylores = 0, *pypoint3dvec = 0;
447  double qx = 0, qy = 0;
448  double I = 0;
449
450  int ok = PyArg_ParseTuple(args, "OOdd", &pylores, &pypoint3dvec, &qx,&qy);
451  if(!ok) return NULL;
452
453  void *temp = PyCObject_AsVoidPtr(pylores);
454  LORESModel * thislores = static_cast<LORESModel *>(temp);
455  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
456  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
457 
458  Py_BEGIN_ALLOW_THREADS
459  I = thislores->CalculateIQ_2D(*thisvec, qx,qy);
460  Py_END_ALLOW_THREADS
461 
462  return Py_BuildValue("d",I);
463}
464
465// PDBModel method calculateIQ(iq)
466char pypointsmodelpy_get_pdb_iq__name__[] = "get_pdb_iq";
467char pypointsmodelpy_get_pdb_iq__doc__[] = "calculate scattering intensity for PDB model";
468
469PyObject * pypointsmodelpy_get_pdb_iq(PyObject *, PyObject *args)
470{
471  PyObject *pymodel = 0, *pyiq = 0;
472  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pyiq);
473  if(!ok) return NULL;
474
475  void *temp = PyCObject_AsVoidPtr(pymodel);
476  void *temp2 = PyCObject_AsVoidPtr(pyiq);
477
478  PDBModel * thispdb = static_cast<PDBModel *>(temp);
479  IQ * thisiq = static_cast<IQ *>(temp2);
480
481  Py_BEGIN_ALLOW_THREADS
482  thispdb->CalculateIQ(thisiq);
483  Py_END_ALLOW_THREADS
484 
485  return Py_BuildValue("i",0);
486}
487
488// PDBModel method calculateIQ_2D(qx,qy)
489char pypointsmodelpy_get_pdb_Iqxy__name__[] = "get_pdb_Iqxy";
490char pypointsmodelpy_get_pdb_Iqxy__doc__[] = "calculate scattering intensity by a given (qx,qy) for PDB model";
491
492PyObject * pypointsmodelpy_get_pdb_Iqxy(PyObject *, PyObject *args)
493{
494  PyObject *pypdb = 0;
495  double qx = 0, qy = 0;
496  double I = 0;
497
498  int ok = PyArg_ParseTuple(args, "Odd", &pypdb, &qx,&qy);
499  if(!ok) return NULL;
500
501  void *temp = PyCObject_AsVoidPtr(pypdb);
502  PDBModel * thispdb = static_cast<PDBModel *>(temp);
503
504  Py_BEGIN_ALLOW_THREADS
505  I = thispdb->CalculateIQ_2D(qx,qy);
506  Py_END_ALLOW_THREADS
507 
508  return Py_BuildValue("d",I);
509}
510
511// PDBModel method calculateIQ_2Dv(points,qx,qy)
512char pypointsmodelpy_get_pdb_Iqvxy__name__[] = "get_pdb_Iqvxy";
513char pypointsmodelpy_get_pdb_Iqvxy__doc__[] = "calculate scattering intensity by a given (qx,qy) for PDB model";
514
515PyObject * pypointsmodelpy_get_pdb_Iqvxy(PyObject *, PyObject *args)
516{
517  PyObject *pypdb = 0, *pypoint3dvec = 0;
518  double qx = 0, qy = 0;
519  double I = 0;
520
521  int ok = PyArg_ParseTuple(args, "OOdd", &pypdb, &pypoint3dvec, &qx,&qy);
522  if(!ok) return NULL;
523
524  void *temp = PyCObject_AsVoidPtr(pypdb);
525  PDBModel * thispdb = static_cast<PDBModel *>(temp);
526  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
527  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
528
529  Py_BEGIN_ALLOW_THREADS
530  I = thispdb->CalculateIQ_2D(*thisvec,qx,qy);
531  Py_END_ALLOW_THREADS
532 
533  return Py_BuildValue("d",I);
534}
535
536// ComplexModel method calculateIQ(iq)
537char pypointsmodelpy_get_complex_iq__name__[] = "get_complex_iq";
538char pypointsmodelpy_get_complex_iq__doc__[] = "calculate scattering intensity for COMPLEX model";
539
540PyObject * pypointsmodelpy_get_complex_iq(PyObject *, PyObject *args)
541{
542  PyObject *pymodel = 0, *pyiq = 0;
543  int ok = PyArg_ParseTuple(args, "OO", &pymodel, &pyiq);
544  if(!ok) return NULL;
545
546  void *temp = PyCObject_AsVoidPtr(pymodel);
547  void *temp2 = PyCObject_AsVoidPtr(pyiq);
548
549  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
550  IQ * thisiq = static_cast<IQ *>(temp2);
551
552  Py_BEGIN_ALLOW_THREADS
553  thiscomplex->CalculateIQ(thisiq);
554  Py_END_ALLOW_THREADS
555 
556  return Py_BuildValue("i",0);
557}
558
559//LORESModel method CalculateIQ_2D(points,qx,qy)
560char pypointsmodelpy_get_complex_Iqxy__name__[] = "get_complex_iq_2D";
561char pypointsmodelpy_get_complex_Iqxy__doc__[] = "calculate averaged scattering intensity from a single q";
562
563PyObject * pypointsmodelpy_get_complex_Iqxy(PyObject *, PyObject *args)
564{
565  PyObject *pylores = 0, *pypoint3dvec = 0;
566  double qx = 0, qy = 0;
567  int ok = PyArg_ParseTuple(args, "OOdd", &pylores, &pypoint3dvec, &qx, &qy);
568  if(!ok) return NULL;
569
570  void *temp = PyCObject_AsVoidPtr(pylores);
571  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
572  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
573  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
574
575  double I = 0.0;
576  Py_BEGIN_ALLOW_THREADS
577  I = thiscomplex->CalculateIQ_2D(*thisvec,qx,qy);
578  Py_END_ALLOW_THREADS
579 
580  return Py_BuildValue("d",I);
581}
582
583//LORESModel method CalculateIQ_2D_Error(points,qx,qy)
584char pypointsmodelpy_get_complex_Iqxy_err__name__[] = "get_complex_iq_2D_err";
585char pypointsmodelpy_get_complex_Iqxy_err__doc__[] = "calculate averaged scattering intensity from a single q";
586
587PyObject * pypointsmodelpy_get_complex_Iqxy_err(PyObject *, PyObject *args)
588{
589  PyObject *pylores = 0, *pypoint3dvec = 0;
590  double qx = 0, qy = 0;
591  int ok = PyArg_ParseTuple(args, "OOdd", &pylores, &pypoint3dvec, &qx, &qy);
592  if(!ok) return NULL;
593
594  void *temp = PyCObject_AsVoidPtr(pylores);
595  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
596  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
597  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
598
599  double I = 0.0;
600  Py_BEGIN_ALLOW_THREADS
601  I = thiscomplex->CalculateIQ_2D_Error(*thisvec,qx,qy);
602  Py_END_ALLOW_THREADS
603 
604  return Py_BuildValue("d",I);
605}
606
607//LORESModel method CalculateIQ(q)
608char pypointsmodelpy_get_complex_i__name__[] = "get_complex_i";
609char pypointsmodelpy_get_complex_i__doc__[] = "calculate averaged scattering intensity from a single q";
610
611PyObject * pypointsmodelpy_get_complex_i(PyObject *, PyObject *args)
612{
613  PyObject *pylores = 0;
614  double q = 0;
615  int ok = PyArg_ParseTuple(args, "Od", &pylores, &q);
616  if(!ok) return NULL;
617
618  void *temp = PyCObject_AsVoidPtr(pylores);
619
620  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
621 
622  double I = 0.0;
623  Py_BEGIN_ALLOW_THREADS
624  I = thiscomplex->CalculateIQ(q);
625  Py_END_ALLOW_THREADS
626 
627  return Py_BuildValue("d",I);
628}
629
630char pypointsmodelpy_get_complex_i_error__name__[] = "get_complex_i_error";
631char pypointsmodelpy_get_complex_i_error__doc__[] = "calculate error on averaged scattering intensity from a single q";
632
633PyObject * pypointsmodelpy_get_complex_i_error(PyObject *, PyObject *args)
634{
635  PyObject *pylores = 0;
636  double q = 0;
637  int ok = PyArg_ParseTuple(args, "Od", &pylores, &q);
638  if(!ok) return NULL;
639
640  void *temp = PyCObject_AsVoidPtr(pylores);
641
642  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
643
644  double I = 0.0;
645  Py_BEGIN_ALLOW_THREADS
646  I = thiscomplex->CalculateIQError(q);
647  Py_END_ALLOW_THREADS
648 
649  return Py_BuildValue("d",I);
650}
651
652
653
654
655//method outputPR(string filename)
656char pypointsmodelpy_outputPR__name__[] = "outputPR";
657char pypointsmodelpy_outputPR__doc__[] = "print out P(R) to a file";
658
659PyObject * pypointsmodelpy_outputPR(PyObject *, PyObject *args)
660{
661  PyObject *pymodel = 0;
662  char *outfile;
663  int ok = PyArg_ParseTuple(args, "Os", &pymodel, &outfile);
664  if(!ok) return NULL;
665
666  void *temp = PyCObject_AsVoidPtr(pymodel);
667
668  LORESModel * thislores = static_cast<LORESModel *>(temp);
669
670  thislores->OutputPR(outfile);
671
672  return Py_BuildValue("i", 0);
673}
674
675
676//method get_pr()
677char pypointsmodelpy_getPR__name__[] = "get_pr";
678char pypointsmodelpy_getPR__doc__[] = "Return P(r) as a list of points";
679
680PyObject * pypointsmodelpy_getPR(PyObject *, PyObject *args)
681{
682  PyObject *pymodel = 0;
683  char *outfile;
684  int ok = PyArg_ParseTuple(args, "O", &pymodel);
685  if(!ok) return NULL;
686
687  void *temp = PyCObject_AsVoidPtr(pymodel);
688
689  LORESModel * thislores = static_cast<LORESModel *>(temp);
690
691  // Get the P(r) array
692  Array2D<double> pr_ = thislores->GetPr();
693
694  // Create two lists to store the r and P(r) values
695  PyObject* r_list  = PyList_New(0);
696  PyObject* pr_list = PyList_New(0);
697
698  double sum = 0.0;
699  double r_stepsize = 1.0;
700  if (pr_.dim1()>2) r_stepsize = pr_[1][0] - pr_[0][0];
701
702  for (int i = 0;  i < pr_.dim1(); ++i){
703          sum += pr_[i][1]*r_stepsize;
704  }
705
706  for (int i = 0;  i < pr_.dim1(); ++i){
707          if (pr_[i][1]==0) continue;
708          int r_append  = PyList_Append(r_list, Py_BuildValue("d", pr_[i][0]));
709          int pr_append = PyList_Append(pr_list, Py_BuildValue("d", pr_[i][1]/sum));
710          if (r_append+pr_append<0) return NULL;
711  }
712
713  return Py_BuildValue("OO", r_list, pr_list);
714}
715
716
717
718//method outputPR_xy(string filename)
719char pypointsmodelpy_outputPR_xy__name__[] = "outputPR_xy";
720char pypointsmodelpy_outputPR_xy__doc__[] = "print out P(R) to a file";
721
722PyObject * pypointsmodelpy_outputPR_xy(PyObject *, PyObject *args)
723{
724  PyObject *pyloresmodel = 0;
725  char *outfile;
726  int ok = PyArg_ParseTuple(args, "Os", &pyloresmodel, &outfile);
727  if(!ok) return NULL;
728
729  void *temp = PyCObject_AsVoidPtr(pyloresmodel);
730
731  LORESModel * thislores = static_cast<LORESModel *>(temp);
732
733  thislores->OutputPR_XY(outfile);
734
735  return Py_BuildValue("i", 0);
736}
737
738//PDBModel method outputPR(string filename)
739char pypointsmodelpy_save_pdb_pr__name__[] = "save_pdb_pr";
740char pypointsmodelpy_save_pdb_pr__doc__[] = "print out P(R) to a file";
741
742PyObject * pypointsmodelpy_save_pdb_pr(PyObject *, PyObject *args)
743{
744  PyObject *pymodel = 0;
745  char *outfile;
746  int ok = PyArg_ParseTuple(args, "Os", &pymodel, &outfile);
747  if(!ok) return NULL;
748
749  void *temp = PyCObject_AsVoidPtr(pymodel);
750
751  PDBModel * thispdb = static_cast<PDBModel *>(temp);
752
753  thispdb->OutputPR(outfile);
754
755  return Py_BuildValue("i", 0);
756}
757
758//ComplexModel method outputPR(string filename)
759char pypointsmodelpy_save_complex_pr__name__[] = "save_complex_pr";
760char pypointsmodelpy_save_complex_pr__doc__[] = "print out P(R) to a file";
761
762PyObject * pypointsmodelpy_save_complex_pr(PyObject *, PyObject *args)
763{
764  PyObject *pymodel = 0;
765  char *outfile;
766  int ok = PyArg_ParseTuple(args, "Os", &pymodel, &outfile);
767  if(!ok) return NULL;
768
769  void *temp = PyCObject_AsVoidPtr(pymodel);
770
771  ComplexModel * thiscomplex = static_cast<ComplexModel *>(temp);
772
773  thiscomplex->OutputPR(outfile);
774
775  return Py_BuildValue("i", 0);
776}
777
778
779//method outputPDB(string filename)
780char pypointsmodelpy_outputPDB__name__[] = "outputPDB";
781char pypointsmodelpy_outputPDB__doc__[] = "save the monte-carlo distributed points of the geomodel into a PDB format file.\
782                                           a .pdb extension will be automatically added";
783
784PyObject * pypointsmodelpy_outputPDB(PyObject *, PyObject *args)
785{
786  PyObject *pyloresmodel = 0, *pypoint3dvec=0;
787  char *outfile;
788  int ok = PyArg_ParseTuple(args, "OOs", &pyloresmodel, &pypoint3dvec,&outfile);
789  if(!ok) return NULL;
790
791  void *temp = PyCObject_AsVoidPtr(pyloresmodel);
792
793  LORESModel * thislores = static_cast<LORESModel *>(temp);
794
795  void *temp2 = PyCObject_AsVoidPtr(pypoint3dvec);
796  vector<Point3D> * thisvec = static_cast<vector<Point3D> *>(temp2);
797
798  thislores->OutputPDB(*thisvec,outfile);
799
800  return Py_BuildValue("i", 0);
801}
802
803// version
804// $Id$
805
806// End of file
Note: See TracBrowser for help on using the repository browser.