How to stringfy a swig matrix object like matrix3*3 in openbabel??

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

How to stringfy a swig matrix object like matrix3*3 in openbabel??

Ning Shen
Hi, I am using swig wrapper of [openbabel][1](written in C++, and supply a python wrapper through swig)

Below i just use it to read a molecule structure file and get the unitcell property of it.
import pybel
for molecule in pybel.readfile('pdb','./test.pdb'):
    unitcell = molecule.unitcell
    print unitcell
   |..>    
   |..>    
<openbabel.OBUnitCell; proxy of <Swig Object of type 'OpenBabel::OBUnitCell *' at 0x17b390c0> >

The unitcell has function CellMatrix(),

unitcell.GetCellMatrix()
   <22> <openbabel.matrix3x3; proxy of <Swig Object of type 'OpenBabel::matrix3x3 *' at 0x17b3ecf0> >

the OpenBabel::matrix3x3 is something like :

1 2 3
4 5 6
7 8 9
 i am wondering how to print out the contents of the matrix3*3 . I have tried __str__ and __repr__ with it.

Any general way to stringfy the contents of a matrix wrapped by swing in python ?

thanks

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
Reply | Threaded
Open this post in threaded view
|

Re: How to stringfy a swig matrix object like matrix3*3 in openbabel??

Tim Vandermeersch
On Tue, Mar 30, 2010 at 11:10 PM, Ning Shen <[hidden email]> wrote:

> Hi, I am using swig wrapper of [openbabel][1](written in C++, and supply a
> python wrapper through swig)
>
> Below i just use it to read a molecule structure file and get the unitcell
> property of it.
> import pybel
> for molecule in pybel.readfile('pdb','./test.pdb'):
>     unitcell = molecule.unitcell
>     print unitcell
>    |..>
>    |..>
> <openbabel.OBUnitCell; proxy of <Swig Object of type 'OpenBabel::OBUnitCell
> *' at 0x17b390c0> >
>
> The unitcell has function CellMatrix(),
>
> unitcell.GetCellMatrix()
>    <22> <openbabel.matrix3x3; proxy of <Swig Object of type
> 'OpenBabel::matrix3x3 *' at 0x17b3ecf0> >
>
> the OpenBabel::matrix3x3 is something like :
>
> 1 2 3
> 4 5 6
> 7 8 9
>  i am wondering how to print out the contents of the matrix3*3 . I have
> tried __str__ and __repr__ with it.
>
> Any general way to stringfy the contents of a matrix wrapped by swing in
> python ?

>>> import openbabel
>>> m = openbabel.matrix3x3()
>>> for i in range(3):
...   for j in range(3):
...     m.Set(i, j, 3*i+j)
...
>>> for i in range(3):
...   print m.Get(i, 0), m.Get(i, 1), m.Get(i, 2)
...
0.0 1.0 2.0
3.0 4.0 5.0
6.0 7.0 8.0


> thanks
>
> ------------------------------------------------------------------------------
> Download Intel&#174; Parallel Studio Eval
> Try the new software tools for yourself. Speed compiling, find bugs
> proactively, and fine-tune applications for parallel performance.
> See why Intel Parallel Studio got high marks during beta.
> http://p.sf.net/sfu/intel-sw-dev
> _______________________________________________
> OpenBabel-discuss mailing list
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/openbabel-discuss
>
>

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
OpenBabel-discuss mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/openbabel-discuss