Re: [Rdkit-discuss] python/c++ interface again...

2012-06-02 Thread Paul Emsley
On 02/06/12 04:44, Greg Landrum wrote:

 On Fri, Jun 1, 2012 at 1:41 PM, Paul Emsleypaul.ems...@bioch.ox.ac.uk  
 wrote:
 I'd like to return a PyObject *.  I have a RDKit::RWMol, say - or a
 pointer to a new one if need be...
 If you are using a boost.python interface, and your function is
 exposed using boost::python::def, then the right thing happens
 more-or-less automatically if you have a function that returns an
 RDKit::RWMol * ... [snip]


Thanks.   I will mail to devel list later.

Paul.


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


[Rdkit-discuss] python/c++ interface again...

2012-06-01 Thread Paul Emsley

Hi,

I've been trying to read boost python docs and I am lost...

I'd like to return a PyObject *.  I have a RDKit::RWMol, say - or a 
pointer to a new one if need be...

// return a regularized molecule (copy of input with coordinates replaced)
PyObject *
coot::regularize(PyObject *mol_in_py) {

RDKit::ROMol mol = 
boost::python::extractRDKit::ROMol(mol_in_py); // thanks Uwe H
.. do stuff ..
// construct return value
RDKit::RWMol *regularized_mol = new RDKit::RWMol(mol);  // needs 
boostifying?
update_coords(regularized_mol);  // replace with refined positions

return somehow_wrap(regularized_mol);

}

What is somehow_wrap()?  What should I have read to find this out for 
myself?

Cheers,

Paul.


--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] python/c++ interface again...

2012-06-01 Thread Eddie Cao
Hi,

I am not quite fluent with Boost.Python myself, but you could try this:

return RDKit::RWMOL_SPTR(regularized_mol);

or

return RDKit::ROMOL_SPTR(regularized_mol);

Eddie


On Jun 1, 2012, at 4:41 AM, Paul Emsley wrote:

 
 Hi,
 
 I've been trying to read boost python docs and I am lost...
 
 I'd like to return a PyObject *.  I have a RDKit::RWMol, say - or a 
 pointer to a new one if need be...
 
 // return a regularized molecule (copy of input with coordinates replaced)
 PyObject *
 coot::regularize(PyObject *mol_in_py) {
 
RDKit::ROMol mol = 
 boost::python::extractRDKit::ROMol(mol_in_py); // thanks Uwe H
.. do stuff ..
// construct return value
RDKit::RWMol *regularized_mol = new RDKit::RWMol(mol);  // needs 
 boostifying?
update_coords(regularized_mol);  // replace with refined positions
 
return somehow_wrap(regularized_mol);
 
 }
 
 What is somehow_wrap()?  What should I have read to find this out for 
 myself?
 
 Cheers,
 
 Paul.
 
 
 --
 Live Security Virtual Conference
 Exclusive live event will cover all the ways today's security and 
 threat landscape has changed and how IT managers can respond. Discussions 
 will include endpoint security, mobile security and the latest in malware 
 threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
 ___
 Rdkit-discuss mailing list
 Rdkit-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss


Re: [Rdkit-discuss] python/c++ interface again...

2012-06-01 Thread Greg Landrum
Hi Paul,

On Fri, Jun 1, 2012 at 1:41 PM, Paul Emsley paul.ems...@bioch.ox.ac.uk wrote:

 I've been trying to read boost python docs and I am lost...

 I'd like to return a PyObject *.  I have a RDKit::RWMol, say - or a
 pointer to a new one if need be...

If you are using a boost.python interface, and your function is
exposed using boost::python::def, then the right thing happens
more-or-less automatically if you have a function that returns an
RDKit::RWMol *. I say more-or-less because you will probably also have
to tell the library what to do about ownership of the pointer; you'll
get a very informative compiler error here if you leave that out and
it's required.

Even if you're not using boost.python for the entire interface, it may
be worth trying to use it for the functions where you want to return
RDKit objects. I have no idea if this is possible, but it's worth a
try.

You'd do a function something like this:

RDKit::ROMol *
coot::regularize(RDKit::ROMol mol) {
   .. do stuff ..
   // construct return value
   RDKit::RWMol *regularized_mol = new RDKit::RWMol(mol);
   update_coords(regularized_mol);  // replace with refined positions
   return static_castROMol *(regularized_mol);
}

Notice how that has no reference to python objects in it; it's also
conceivably useful from your C++ code.
To expose to python, you have in the code for your wrapper module:
boost::python::def(regularize,coot::regularize,(python::arg(mol)),
  docs,
  boost::python::return_value_policyboost::python::manage_new_object());

This (obviously) isn't tested in any way, shape, or form. It probably
also won't work unless the whole thing is inside a module that's set
up using the BOOST_PYTHON_MODULE macro, but it's worth a try.

Having said all of that: this is starting to move in a very highly
specialized direction that's maybe not interesting to most of the
readers of rdkit-discuss (though it's fascinating to me :-). I'd
suggest moving this discussion to rdkit-devel. Paul: if the above
doesn't work, please post something to rdkit-devel along with a short
description of how you're creating your python modules (are you using
SWIG? wrapping them by hand? already using Boost.Python?) and I'll try
to help more. A pointer to actual code would also help.

-greg

 // return a regularized molecule (copy of input with coordinates replaced)
 PyObject *
 coot::regularize(PyObject *mol_in_py) {

    RDKit::ROMol mol =
 boost::python::extractRDKit::ROMol(mol_in_py); // thanks Uwe H
    .. do stuff ..
    // construct return value
    RDKit::RWMol *regularized_mol = new RDKit::RWMol(mol);  // needs
 boostifying?
    update_coords(regularized_mol);  // replace with refined positions

    return somehow_wrap(regularized_mol);

 }

 What is somehow_wrap()?  What should I have read to find this out for
 myself?

 Cheers,

 Paul.


 --
 Live Security Virtual Conference
 Exclusive live event will cover all the ways today's security and
 threat landscape has changed and how IT managers can respond. Discussions
 will include endpoint security, mobile security and the latest in malware
 threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
 ___
 Rdkit-discuss mailing list
 Rdkit-discuss@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/rdkit-discuss

--
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
___
Rdkit-discuss mailing list
Rdkit-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/rdkit-discuss