[Chimera-users] Scripting to write / save multiple models into single pdf file

Sumitro Harjanto u0601918 at nus.edu.sg
Sun Mar 14 23:12:59 PDT 2010

Hi Eric,


I managed to figure out something by pirating some python codes I found
from chimera mailing list through googling. I want to use the code to
save my reply log, which is going to be about 3.4 million lines (by the
way, is there a maximum buffer for the number of lines reply log can
take? I feared overrunning the buffer and losing my some part of the


Below is the code; I commented away the part I do not use from the
original code.


I tried the code by opening it using the chimera gui, and it worked just
fine, producing the log file I want. But when I tried opening the same
code using command line the log file was produced, but empty.

I tried :


E:\Chimera\bin>chimera --nogui save_replylog.py   <- -  doesnot show
anything, no popup command window, nothing.

E:\Chimera\bin>chimera --nogui --debug save_replylog.py <- - shows a new
pop up window


Both commands created my log file, but were both empty files.


I would want to run the script later in nogui mode, but I need to
retrieve the log for rmsd values, therefore I need to overcome this
problem. Any advise..?









from chimera import runCommand

from chimera.tkgui import saveReplyLog


#def rms2ref(ref, pose, no):

#    runCommand('open %s; open %s' % (ref, pose))

#    i = 1

#    while i <= no:

#       # only hetatms are included --> ~@/element=h

#       runCommand('sel #1.%i & ~@/element=h' % i)

#       runCommand('rmsd #0 sel')

#       i += 1


#rms2ref('lig_cryst.pdb', 'poses.sdf', 10)


runCommand('open noprefs

runCommand('open noprefs E:\\A.Model_receptor\\PDB_MODELS\\1DUZ.pdb')

runCommand('open noprefs

runCommand('rmsd #0:@ca #1:2-182.A at ca')

runCommand('match #0:@ca,n,c,o #1:2-182.A at ca,n,c,o')

runCommand('match #2:1-3.C,7-9.C at ca #1:1-3.C,7-9.C at ca ')

runCommand('match #2:1-3.C,7-9.C at ca,n,c,o #1:1-3.C,7-9.C at ca,n,c,o ')

runCommand('combine #0|#2:1-9.C name
A-0101_ITLVYKVYY_2CIK.C.(1DUZ.C).A-0101_1W72_A modelId 5')

runCommand('write format pdb 5

runCommand('close all')


# generate output from replyLog.txt




#rmsds = []

#for i in open('mylog2.txt').readlines():

#    if i.startswith('RMSD between'):

#       rmsds.append(i.split()[-2])


#print rmsds




From: Eric Pettersen [mailto:pett at cgl.ucsf.edu] 
Sent: 12 March 2010 6:24 AM
To: Sumitro Harjanto
Cc: chimera-users at cgl.ucsf.edu
Subject: Re: [Chimera-users] Scripting to write / save multiple models
into single pdf file


Hi Sumitro,

            Don't include "open" on the Unix command line.  You only
need that when typing into Chimera's own command line.




On Mar 10, 2010, at 10:28 AM, Sumitro Harjanto wrote:

That was a bull's eye, indeed, after turning off the autostart for Model
panel, the simple command of ">chimera --nogui" does not make anymore


So I advanced a little and try to run a .cmd file using the command

>chimera --nogui open


But again I got the same error message:

Chimera failed abnormally; the exit code was: 1

Use -debug command line option for the full error message.



Below is what I see after adding "--debug" to the command:


Cannot execute 'gzip': no automatic decompression of .Z files

Traceback (most recent call last):

  File "E:\Chimera\share\chimeraInit.py", line 425, in init

   Chimera.openModels.open<a, prefixableType=1>

  File "E:\Chimera\share\chimera\__init__.py", line 1405, in open

    Raise ValueError, "Unknown model type"

ValueError: Unknown model type

Error while processing open:

ValueError: Unknown model type


  File "E:\Chimera\share\chimera\__init__.py", line 1405, in open

    Raise ValueError, "Unknown model type"


See reply log for Phyton traceback.


Opening 2HN7.pdb...

1 model opened

Opened ... ... ... (and actually continues to complete my script)


Later on I tried to open a pdb instead (>chimera --nogui open
e:\A.Model_receptor\PDB_MODELS\3B3I.pdb) and the same thing happened,
even the debug window shows the same message about unknown model type.


Any way to go around this..? I don't know if it helps, but below is my
"preferences" file


{'Model Panel': {'freqButs': {'2D Diagram': False,

                              'activate': False,

                              'activate all': True,

                              'activate only': True,

                              'add hydrogens...': False,

                              'add/edit note...': True,

                              'attributes...': True,

                              'blast protein...': True,

                              'clipping...': True,

                              'close': True,

                              'color by SS...': False,

                              'compute SS': True,

                              'copy/combine...': True,

                              'deactivate': False,

                              'focus': True,

                              'hide': False,

                              'match...': True,

                              'minimize...': False,

                              'rainbow...': True,

                              'rename...': True,

                              'render/sel by attr...': True,

                              'select': True,

                              'select chain(s)...': True,

                              'sequence...': True,

                              'show': False,

                              'show all atoms': True,

                              'show only': True,

                              'surface main': True,

                              'tile...': True,

                              'toggle active': True,

                              'trace backbones': True,

                              'trace chains': True,

                              'transform as...': True,

                              'write PDB': True},

                 'lastUse': 1268231127.7550001},

 'Nucleotides': {'slab styles': {}},

 'Ribbon Styles': {'atoms': {}, 'scaling': {}, 'xsections': {}},

 'Tools': {'autoStart': {},

           'confirmOnStart': {},

           'dirList': [],

           'inFavorites': {'Command Line': 2,

                           'Model Panel': 0,

                           'Reply Log': 4,

                           'Sequence': 3,

                           'Side View': 1},

           'onToolbar': {}},

 'command line gui': {'remembered commands': ['select #0:2-182.A at C',

                                              'write selected format pdb
0 E:\\A.Model_receptor\\PDB_MODELS\\1W72_c.pdb']},

 'initial size': {'Window size': (525, 513)},

 'miller browser': {'dirHistory':


                    'fileHistory': {'':




                                    'main chimera import dialog':










                    'lastFilter': {'main chimera import dialog': 'all
(guess type)'}},

 'update check': {'last time': (2010, 3, 3, 12, 50, 48, 371000, None)},

 'version tracking': {'last version': '1.4_b29093'},

 'write PDB dialog': {'multiSavePDB': 'single'}}








From: Eric Pettersen [mailto:pett at cgl.ucsf.edu] 
Sent: 10 March 2010 3:17 AM
To: Sumitro Harjanto
Cc: chimera-users at cgl.ucsf.edu
Subject: Re: [Chimera-users] Scripting to write / save multiple models
into single pdf file


Hmm, it seems that you have the Model Panel set to autostart in your
preferences.  Now, Chimera probably should ignore autostarting tools
when it is in nogui mode, but currently it doesn't.  So what you will
have to do for now (until we fix this) is to start Chimera normally,
turn off the autostart of the Model Panel (and any other graphical tools
probably), save the new preferences, and then run your script.


If you look in the "Preferences" preference category, it will show the
location of the preferences file.  You could squirrel away your original
preferences file somewhere, make the version with no autostarting, copy
that somewhere, and then put your original version back.  You would then
be able to use the no-autostarting preferences by specifying it's
location with the --preferences startup option.




                        Eric Pettersen

                        UCSF Computer Graphics Lab



On Mar 8, 2010, at 7:32 PM, Sumitro Harjanto wrote:


Hi Eric,


Thanks for the suggestion. I don't really script, I usually use a c++
code / excel to generate the command (.cmd) files. Should be okay for
the automation for now, if I run into any problem then I will post it up
here again. =]


Mean while I try running the command "chimera.exe -nogui" in
PATH/chimera/bin but got the following error message. I followed the
instruction and copy over the debug message (below). any advise? I'm on
a win7 X86 platform btw.







Chimera failed abnormally; the exit code was: 1

Use -debug command line option for the full error message.



Cannot execute 'gzip': no automatic decompression of .Z files

Traceback (most recent call last):

  File "E:\Chimera\share\__main__.py", line 65, in <module>

    value = chimeraInit.init(sys.argv)

  File "E:\Chimera\share\chimeraInit.py", line 401, in init


  File "E:\Chimera\share\chimera\extension\base.py", line 1056, in


  File "E:\Chimera\share\chimera\extension\base.py", line 959, in



  File "E:\Chimera\share\ModelPanel\ChimeraExtension.py", line 23, in


  File "E:\Chimera\share\chimera\dialogs.py", line 77, in display

    dialog = find(name, create=1)

  File "E:\Chimera\share\chimera\dialogs.py", line 62, in find

    return d()

  File "E:\Chimera\share\chimera\baseDialog.py", line 523, in __init__

    BaseDialog.__init__(self, master, *args, **kw)

  File "E:\Chimera\share\chimera\baseDialog.py", line 244, in __init__


  File "E:\Chimera\share\ModelPanel\base.py", line 217, in fillInUI


  File "E:\Chimera\share\ModelPanel\base.py", line 436, in _addColumns


  File "E:\Chimera\share\ModelPanel\base.py", line 454, in _buildTable

    % len(filter(lambda s: s == 1, self.shownColumns)))

  File "E:\Chimera\bin\Lib\lib-tk\Tix.py", line 1306, in __init__

    cnf, kw)

  File "E:\Chimera\bin\Lib\lib-tk\Tix.py", line 307, in __init__

    self.tk.call(widgetName, self._w, *extra)

_tkinter.TclError: invalid command name "tixScrolledHList"

Return code: 1

Press return or enter to to exit




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://plato.cgl.ucsf.edu/pipermail/chimera-users/attachments/20100315/7cf9614d/attachment.html>

More information about the Chimera-users mailing list