Next: MoleculeRep
Up: High-level Python Interface
Previous: High-level Python Interface
Contents
Index
The Molecule class is a proxy for molecules loaded into VMD. Most
operations raise ValueError if the proxy no longer refers to a valid
molecule (i.e. if the molecule has been deleted).
Molecule instances provide the following methods:
- __init__(id=None):
Creating a new Molecule instance with no arguments will create a new
empty molecule in VMD. Passing a valid molecule id will make the
Molecule instance mirror the state of the corresponding molecule in VMD.
- __int__():
Casting a Molecule to an int returns the molecule ID.
- rename(self, newname): Changes the name of the molecule.
- name():
Returns the name of the molecule.
- delete():
Deletes the molecule corresponding to this Molecule instance. The object can
no longer be used.
- load(filename, filetype=None, first=0, last=-1, step=1, waitfor=-1, volsets=[0]):
Load molecule data from the given file. The filetype will be guessed from
the filename extension; this can be overrideen by setting the filetype
option. first, last, and step control which coordinates
frames to load, if any. volsets indicates which volumetric data sets
to load from the file. Raises IOError if the file cannot be loaded.
- save(filename, filetype=None, first=0, last=-1, step=1, waitfor=-1, sel=None):
Save timesteps to the given file. The filetype will be guessed from
the filename extension; this can be overridden by setting the filetype
option. first, last, and step control which timesteps to save. Returns
the number of frames written before the command completes. Pass an
AtomSel instance as sel to write only a selection of atoms to the file.
Note that this differs from the AtomSel.write() method in that
Molecule.save() writes a range of timesteps, while AtomSel.write()
writes only the coordinates corresponding to the selection's currently
selected frame.
- files():
- types():
Returns a list of filenames and file types, respectively, for the files that
have been loaded into this molecule.
- numAtoms(): Returns the number of atoms in the molecule.
- numFrames(): Returns the number of coordinate frames in the
molecule.
- setFrame(frame):
Set the coordinate frame to the given value. Must be in the range
[0, numFrames())
- curFrame(): Returns the current coordinate frame for the molecule.
- delFrame(first=0, last=-1, step=1):
Deletes the given range of frames.
- dupFrame(frame = None):
Duplicate the given frame, apending it to the end. if frame is
None then the current frame is used.
- numReps():
Returns the number of molecular representations (reps) in the given molecule.
- reps():
Returns a list of MoleculeRep objects, one for each rep in the molecule.
- addRep(rep):
Add the given MoleculeRep instance to the Molecule. Modifications to the
rep will affect all Molecules to which the rep has been added. Raises
ValueError if the rep has already been added to this molecule.
- delRep(rep):
Removes the given MoleculeRep from the Molecule. The rep is not affected
and can be added to other molecules, but changes to it will no longer affect
this Molecule.
- clearReps(): Removes all reps from this molecule.
- autoUpdate(rep, onoff = None):
If onoff is not None, sets the auto-update status for this rep
and molecule (note that a rep's auto-update status may be different for
different molecules). Returns the reps auto-update status.
- ssRecalc(): Recalculate the secondary structure for this molecule.
Examples:
>>> from VMD import *
>>> from Molecule import *
>>> bR=Molecule()
>>> bR.load('../proteins/brH.pdb')
<snip>
<Molecule.Molecule instance at 0x406d878c>
>>> bR.name()
'molecule'
>>> bR.rename('bR')
<Molecule.Molecule instance at 0x406d878c>
>>> bR.name()
'bR'
>>> bR.numAtoms()
3762
>>> bR.dupFrame()
<Molecule.Molecule instance at 0x406d878c>
>>> bR.numFrames()
2
Next: MoleculeRep
Up: High-level Python Interface
Previous: High-level Python Interface
Contents
Index
vmd@ks.uiuc.edu