[Chimera-users] Resize a molecule

Thomas Goddard goddard at cgl.ucsf.edu
Wed Apr 27 12:02:25 PDT 2005

Here is some code to scale a molecule size by a given factor.  That is
all atoms have their coordinates multiplied by a factor.


------- Start of forwarded message -------

Date: Wed, 27 Apr 2005 11:05:55 -0700 (PDT)
From: Thomas Goddard <goddard at cgl.ucsf.edu>

Hi Jinghua,

  By "virus cage pdb file" I guess you mean you placed atoms at
icosahedral positions, and want to show them connected up to show some
icosahedral pattern.

  I think the easiest approach is to open your old session, run a
command to change the diameter of the cage, then save a new session.
Below is some Python code that provides a "scalemol" Chimera command.
Make a directory chimera/share/scalemol in your Chimera distribution
and put the code below in file chimera/share/scalemol/ChimeraExtension.py.
Then start Chimera, open the cage PDB model, use menu entry
Favorites/Command line, and type a command:

	scalemol 0 1.5

to make model number 0 bigger by a factor of 1.5.  If you have more than
one model open you can see the model numbers using Favorites / Model Panel,
the model number is shown in the left hand column.


- ----
scalemol/ChimeraExtension.py code follows:

# -----------------------------------------------------------------------------
def scale_molecule(cmdname, args):

    from Midas.midas_text import error

    fields = args.split()
        model_num = int(fields[0])
        factor = float(fields[1])
        error('Syntax error: scalemol <model-number> <factor>')

    import chimera
    mlist = chimera.openModels.list(id = model_num)
    if len(mlist) == 0:
        error('scalemol: No model number %d' % model_num)

    for model in mlist:
        for a in model.atoms:
            x, y, z = a.coord().xyz.data()
            c = chimera.Coord()
            c.x, c.y, c.z = (factor*x, factor*y, factor*z)
# -----------------------------------------------------------------------------
import Midas.midas_text
Midas.midas_text.addCommand('scalemol', scale_molecule)

------- End of forwarded message -------

More information about the Chimera-users mailing list