[vtkusers] vtkMolecule and vtkAtom

Marcus D. Hanwell marcus.hanwell at kitware.com
Fri Sep 4 11:24:48 EDT 2015

On Thu, Sep 3, 2015 at 12:39 PM, David Gobbi <david.gobbi at gmail.com> wrote:
> On Thu, Sep 3, 2015 at 9:36 AM, Marcus D. Hanwell
> <marcus.hanwell at kitware.com> wrote:
>> On Thu, Sep 3, 2015 at 11:22 AM, Favre  Jean <jfavre at cscs.ch> wrote:
>> >
>> > I have a C++ code building a molecule, Appending atoms, etc. No problem
>> > there.
>> >
>> > Using Python, I cannot do the same. Why aren't the AppendAtom() methods
>> > not
>> > available to a vtkMolecule object? How should one build a molecule with
>> > vtkpython?
>> I don't think they are wrapped due to limitations in the Python
>> wrapping, and the pattern we wanted to use for scalable storage of
>> molecular data. I think we could get them wrapped, or add some simpler
>> API for the Python/wrapped languages.
>> I don't think this is something we tested, or looked at very deeply.
>> Much of the code was developed in quite a short period as part of a
>> Google Summer of Code project, it would be nice to extend it to better
>> support Python.
> Marcus, don't be so pessimistic about the Python wrappers.  Jean, just tell
> cmake to wrap vtkAtom, and the AppendAtom method should work just fine.
> Change the following lines in Common/DataModel/CMakeLists.txt:
>   set_source_files_properties(
>     ...
>     vtkAtom.h
>     )
> The problem is that WRAP_EXCLUDE includes all of the classes that Java
> and Tcl cannot wrap, and as a result, many classes are excluded from the
> Python wrapping even though Python is perfectly capable of using them.
> I should do a sweep through the cmake files to make the wrapping more
> inclusive.
This worked great, I was able to run the folllowing locally in vtkpython:

import vtk
mol = vtk.vtkMolecule()
h1 = mol.AppendAtom(1, 0.0, 0.0, -0.5)
h2 = mol.AppendAtom(1, 0.0, 0.0, 0.5)
b = mol.AppendBond(1, h1, h2)

Proof that it retained the information:

>>> print mol.GetNumberOfAtoms()
>>> print mol.GetNumberOfBonds()

I pushed https://gitlab.kitware.com/mhanwell/vtk/commits/molecules-in-python
for anyone that wants to test it out. I will try to add a test before
making a merge request.



More information about the vtkusers mailing list