[chimera-dev] Creating graphics objects from Python code

Konrad Hinsen research at khinsen.fastmail.net
Wed Jan 12 05:15:12 PST 2011


On 7 Jan 2011, at 19:12, Tom Goddard wrote:

>  You can use the Chimera BILD format without creating a temporary  
> file by creating a string containing the commands, then use StringIO  
> to make a file object from that string and open it.  For example,
>
>    from StringIO import StringIO
>    bild = StringIO(".cylinder %g %g %g %g %g %g %g\n"
>                % (end1[0], end1[1], end1[2], end2[0], end2[1],  
> end2[2], radius))
>    from chimera import openModels
>    model = openModels.open(bild, type="Bild", identifyAs='My  
> annotations', sameAs = mol)
>
> The identifyAs argument assigns the name to the new model that will  
> be shown in the Model Panel dialog.  The sameAs argument says that  
> the new model should be aligned with the specified model (same  
> positioning transform).

This works perfectly well, except for one point: a session containing  
such models cannot be saved to a session file:

Traceback (most recent call last):
   File "/Applications/Chimera.app/Contents/Resources/lib/python2.7/ 
site-packages/Pmw/Pmw_1_3/lib/PmwBase.py", line 1747, in __call__
     return apply(self.func, args)
   File "/Applications/Chimera.app/Contents/Resources/share/chimera/ 
baseDialog.py", line 342, in command
     getattr(s, buttonFuncName(txt))()
   File "/Applications/Chimera.app/Contents/Resources/share/OpenSave/ 
__init__.py", line 237, in Save
     getattr(self, self.keepEquiv())()
   File "/Applications/Chimera.app/Contents/Resources/share/chimera/ 
baseDialog.py", line 560, in OK
     self.Apply()
   File "/Applications/Chimera.app/Contents/Resources/share/OpenSave/ 
__init__.py", line 169, in Apply
     self.command(1, self)
   File "/Applications/Chimera.app/Contents/Resources/share/ 
SimpleSession/gui.py", line 24, in _saveCB
     saveSession(paths[0])
   File "/Applications/Chimera.app/Contents/Resources/share/ 
SimpleSession/save.py", line 151, in saveSession
     source = v.openedAs[0]
AttributeError: '_vrml.VRMLModel' object has no attribute 'openedAs'

Should this be considered a bug or the fair punishment for using  
undocumented features?

Konrad.
--
---------------------------------------------------------------------
Konrad Hinsen
Centre de Biophysique Moléculaire, CNRS Orléans
Synchrotron Soleil - Division Expériences
Saint Aubin - BP 48
91192 Gif sur Yvette Cedex, France
Tel. +33-1 69 35 97 15
E-Mail: research at  khinsen dot fastmail dot net
---------------------------------------------------------------------





More information about the Chimera-dev mailing list