Exposing MoleculeData to Python

7 views
Skip to first unread message

julien

unread,
Nov 28, 2012, 9:37:05 AM11/28/12
to sire-de...@googlegroups.com
Hi Chris,

I would like to expose the class MoleculeData to Python so that I can write in a script this line of code

 newmol_coords = AtomCoords( mol.data().info() )

The idea is to get an atomcoords object initialised with the correct number of cut groups present in the molecule mol.

I can then update the coordinates of the atoms using

 newmol_coords.set( cgatomidx, atom_coord)

and eventually edit mol to use newmol_coords as a property("coordinates")


At the moment I cannot simply type mol.data().info() in a python script

--> 328         newmol_coords = AtomCoords( mol.data().info() )
    329         print "Processing molecule %s natoms %s " % ( molnum.value(), molnatoms )
    330         for x in range(0,molnatoms):

TypeError: No to_python (by-value) converter found for C++ type: SireMol::MoleculeData

The fix would be (I think) to expose MoleculeData and MoleculeInfoData to python

In moleculedata.h I have added the following line of code

SIRE_EXPOSE_CLASS(SireMol::MoleculeData)

And recompiled the C++ code and Python wrapper.

However compilation of the wrappers fails with the following error message

CMakeFiles/Mol.dir/MoleculeData.pypp.cpp.o: In function `register_MoleculeData_class()':

MoleculeData.pypp.cpp:(.text+0x73b): undefined reference to `SireMol::MoleculeData::assertHasMetadata(SireBase::PropertyName const&) const'

MoleculeData.pypp.cpp:(.text+0x888): undefined reference to `SireMol::MoleculeData::assertHasMetadata(SireBase::PropertyName const&, SireBase::PropertyName const&) const'

MoleculeData.pypp.cpp:(.text+0x959): undefined reference to `SireMol::MoleculeData::assertHasProperty(SireBase::PropertyName const&) const'


The folder sire/python2/Mol/ contains the python script special_code.py . Is it possible that this script has to be modified to correctly wrap the above three methods? If so...is there a specific fix_XXXX function in that script that I could adapt for this purpose?

Thanks,

Julien



julien

unread,
Nov 28, 2012, 9:59:49 AM11/28/12
to sire-de...@googlegroups.com
An update,

Using

newmol_coords = AtomCoords( mol.property("coordinates") )

seems to work for what I want to do. I'm in no rush, but I would be curious to understand better why generating the python wrappers sometimes fail.

Best wishes,

Christopher Woods

unread,
Nov 28, 2012, 12:54:00 PM11/28/12
to sire-de...@googlegroups.com

  Hi Julien,

Your solution is the "correct" way of initializing the coordinates. I deliberately designed MoleculeData and MoleculeInfoData as private classes that shouldn't be exposed to python. These classes are designed to be held by the copy-on-write pointers in Sire, and there is no equivalent mechanism for this is Python. Unfortunately, py++ is exposing some of the functions that expose these objects, e.g. .info(). I will find a way to block exposure of these functions via something in special_code.py...

  Best wishes,

  Christopher
--
You received this message because you are subscribed to the Google Groups "Sire Developers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/sire-developers/-/6bQzZ6DqHuEJ.
To post to this group, send email to sire-de...@googlegroups.com.
To unsubscribe from this group, send email to sire-develope...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sire-developers?hl=en.
Reply all
Reply to author
Forward
0 new messages