Package Pmv :: Module mvCommand :: Class MVCommand
[hide private]
[frames] | no frames]

Class MVCommand

source code

ViewerFramework.VFCommand.Command --+
Known Subclasses:
repairCommands.AddOXT, repairCommands.AddOXTGUICommand, repairCommands.CheckForCloseContacts, repairCommands.CheckForCloseContactsGUICommand, repairCommands.CheckForMissingAtoms, repairCommands.CheckForMissingAtomsGUICommand, repairCommands.EditHistHydrogens, repairCommands.EditHistHydrogensGUICommand, repairCommands.ModifyCTerminus, repairCommands.ModifyNTerminus, repairCommands.ModifyTermini, repairCommands.RepairMissingAtoms, repairCommands.RepairMissingAtomsGUICommand, interactiveCommands.MVBindCmdToKey, interactiveCommands.MVIcomGUI, interactiveCommands.MVSetInteractiveCmd, bondsCommands.AddBondsCommand, bondsCommands.AddBondsGUICommand, bondsCommands.BuildBondsByDistance, bondsCommands.RemoveBondsCommand, bondsCommands.RemoveBondsGUICommand, editCommands.AddHydrogensCommand, editCommands.AddHydrogensGUICommand, editCommands.AddKollmanChargesCommand, editCommands.AddKollmanChargesGUICommand, editCommands.AssignAtomsRadiiCommand, editCommands.AverageChargeErrorCommand, editCommands.CheckChargesGUICommand, editCommands.CheckResidueChargesCommand, editCommands.ComputeGasteigerCommand, editCommands.ComputeGasteigerGUICommand, editCommands.EditAtomChargeGUICommand, editCommands.EditAtomTypeCommand, editCommands.EditAtomTypeGUICommand, editCommands.FixHydrogenAtomNamesCommand, editCommands.FixHydrogenAtomNamesGUICommand, editCommands.MergeFieldsCommand, editCommands.MergeLonePairsCommand, editCommands.MergeLonePairsGUICommand, editCommands.MergeNPHsCommand, editCommands.MergeNPHsGUICommand, editCommands.MergeSetsCommand, editCommands.SetChargeCommand, editCommands.SplitNodesCommand, editCommands.SplitNodesGUICommand, editCommands.TypeAtomsCommand, editCommands.TypeBondsCommand, genparserCommands.DefinePdbSpecifications, fileCommands.MoleculeLoader, fileCommands.PDBWriter, fileCommands.STLWriter, fileCommands.SaveMMCIF, fileCommands.VRML2Writer, fileCommands.readFromWebCommand, vectfieldCommands.loadVUFile, vectfieldCommands.loadVect, controlPanelCommands.ControlPanel, trajectoryCommands.OpenTrajectoryCommand, trajectoryCommands.PlayTrajectoryCommand, MVCenterOnNodes, MVPrintNodeNames, MVSetIcomLevel, MVSetSelectionLevel, hbondCommands.AddHBondCommand, hbondCommands.AddHBondCommandGUICommand, hbondCommands.AddHBondHydrogens, hbondCommands.AddHBondHydrogensGUICommand, hbondCommands.BuildHydrogenBonds, hbondCommands.BuildHydrogenBondsGUICommand, hbondCommands.DisplayHBonds, hbondCommands.ExtrudeHydrogenBonds, hbondCommands.GetHydrogenBondAcceptors, hbondCommands.GetHydrogenBondDonors, hbondCommands.GetHydrogenBondEnergies, hbondCommands.LimitHydrogenBonds, hbondCommands.ReadIntermolHBonds, hbondCommands.RemoveHBondCommand, hbondCommands.RemoveHBondCommandGUICommand, hbondCommands.ShowHBDonorsAcceptors, hbondCommands.ShowHydrogenBonds, hbondCommands.WriteAssemblyHBonds, hbondCommands.WriteIntermolHBonds, deleteCommands.DeleteAllMolecules, deleteCommands.DeleteAtomSet, deleteCommands.DeleteMolecule, colorPaletteCommands.EditColorPaletteByAtomType, povrayCommands.Povray, extrusionCommands.ComputeSheet2DCommand, extrusionCommands.DisplayPath3DCommand, extrusionCommands.Nucleic_Acids_properties, selectionCommands.MVSelectCommand, selectionCommands.MVClearSelection, selectionCommands.MVCreateSetIfNeeded, selectionCommands.MVSelectFromStringCommand, selectionCommands.MVInvertSelection, selectionCommands.MVSaveSetCommand, selectionCommands.MVSelectSetCommand, selectionCommands.MVSelectSphericalRegion, measureCommands.MeasureAtomCommand, colorCommands.ColorCommand, APBSCommands.APBSDisplayOrthoSlice, APBSCommands.APBSDisplay_Isocontours, APBSCommands.APBSLoad_Profile, APBSCommands.APBSMap_Potential_to_MSMS, APBSCommands.APBSPreferences, APBSCommands.APBSRun, APBSCommands.APBSSave_Profile, APBSCommands.APBSSetup, APBSCommands.APBSVolumeRender, APBSCommands.APBSWrite_APBS_Parameter_File, superImposeCommands.PmvAlignmentEditor, superImposeCommands.SuperImposeAtomsCommand, superImposeCommands.SuperImposeAtomsGUICommand, superImposeCommands.SuperimposeCoordsCommand, gridCommands.AutoGridIsoSurface, gridCommands.AutoGridReader, gridCommands.DXReader, gridCommands.DeleteAutoGrid, gridCommands.GetOrthoSlice, gridCommands.GridReader, gridCommands.SetIsovalue, updateCommands.Update, aboutCommands.About, SLCommands.RestoreBsptCommand, SLCommands.SLCommand, SLCommands.SaveBsptCommand, amberCommands.ConstrainAtomsAmber94, amberCommands.FixAmberHAtomNamesCommand, amberCommands.FixAmberHAtomNamesGUICommand, amberCommands.FixAmberResNamesAndOrderAtomsCommand, amberCommands.FreezeAtomsAmber94, amberCommands.MinimizeAmber94, amberCommands.MolecularDynamicsAmber94, amberCommands.PlayMolecularDynamicsTrjAmber94, amberCommands.SetMDOptsAmber94, amberCommands.SetMinimOptsAmber94, amberCommands.SetupAmber94, labelCommands.LabelByProperties, dashboardCommands.AddDashboardCmd, dashboardCommands.Dashboard, dashboardCommands.DashboardSuspendRedraw, dashboardCommands.DockDashboard, dashboardCommands.FloatDashboard, dashboardCommands.ShowDashboard, visionCommands.ExportSets, visionCommands.VisionCommand, writeMsmsAsCommands.WriteColoredM, writeMsmsAsCommands.WriteSTL, traceCommands.ComputeExtrudeTraceCommand, traceCommands.ComputeTraceCommand, traceCommands.CustomTraceCommand, displayCommands.DisplayCommand, traceCommands.ExtrudeTraceCommand, videoCommands.VideoCommand, displayCommands.BindGeomToMolecularFragmentBase, displayCommands.DisplayInteractionsCommand, displayCommands.ShowMolecules, sdCommands.ReadMolIndexedPolygons, sdCommands.ReadTransformations, msmsCommands.AssignBuriedAreas, msmsCommands.ComputeMSMS, msmsCommands.IdentifyBuriedVertices, msmsCommands.MsmsNPR, msmsCommands.ReadMSMS, msmsCommands.SaveMSMS, superimposeCommandsNew.FreezeAtomsCommand, superimposeCommandsNew.SuperimposeAtomsCommand, superimposeCommandsNew.SuperimposeCommand, superimposeCommandsNew.TransformAtomsCommand, secondaryStructureCommands.ComputeSecondaryStructureCommand, secondaryStructureCommands.ExtrudeSecondaryStructureCommand, secondaryStructureCommands.RibbonCommand, splineCommands.ComputeExtrudeSplineCommand, splineCommands.ComputeSplineCommand, splineCommands.ComputeSplineGUICommand, splineCommands.CustomSplineCommand, splineCommands.ExtrudeSplineCommand

Base class for command objects for a molecule viewer.
Base class for command objects for a molecule viewer
This command class derives from the ViewerFramework.VFCommand.Command class.
Classes derived from that class can be added to a MoleculeViewer using the
addCommand method.
To write a command the programmer has to create a class MyCmd derived from the
MVCommand class and should overwrite the following methods when relevant.

Information on how to write an inputForm is also available at

    __init__(self, func=None)
        The constructor has to be overwritten to set the self.flag attribute
        self.objArgOnly is turned on when the doit only has one required
        argument which is the current selection.
        This will automatically make this command a Picking command
        self.negateKw is turned on when the doit method takes a boolean
        flag negate which makes this command undoable.

        see Pmv.colorCommands.color command class for an example

    __call__(self, *args, **kw):
        Entrypoint to the command from the command line. It overloads
        calling the object (command) as a function, which enables calling
        an instance of a command as a method of a viewer once it it has
        been loaded.
        Typically, this method checks the arguments supplied and calls the
        doitWrapper method with the arguments supplied.
        This method needs to have the same signature than the doit.
        A documentation string supplying the following information will be
        displayed in a tooltip when calling the command from the python
        idle shell.
        This documentation string should provide the synopsis of the
        command and a description of the arguments.

        See, for good example
        of documentation string.
    guiCallback(self, event=None, *args, **kw):
        This method is bound by default as the callback of the GUI item
        associated with the command.
        It is the entrypoint of the command through the GUI.
        It typically creates an inputform allowing the user to specify any
        argument required for the command.
        The command method showForm is typically called with the name of
        the form to be created and a bunch of optional argument described
        Once all the parameters are known, the doitWrapper method is
        called to carry out the command.

        The old behavior was to call self.vf.getUserInput. The showForm method
        is a command method and replace the getUserInput method of the
        ViewerFramework. Although some commands still implement the
        getUserInput mechanism.
    buildFormDescr(self, formName):
        This method typically creates the inputform descriptor used by the
        guiCallback method to get user input for the command.
        The formName is a string which will be used as a key in the
        cmdForms dictionary to store the form information.
        This method is called by self.showForm
        This method returns an instance of an InputFormDescr which is the
        object describing a inputform in ViewerFramework.
        More information can be found in mglutil/gui/InputForm/Tk/

        For an example see: module
         Almost all the PMV command implement an inputform.
    doit(self, *args, **kw):
        This method does the actual work. It should not implement any
        functionality that should be available outside the application
        for scripting purposes. This method should call such functions or
    setUpUndo(self, *args, **kw):
        Typically this method should be implemented if the command is
        undoable. It should have the same signature than the doit and the
        __call__ method.

        See displayCommands and colorCommands for a good example 
Of course, one is free to overwrite any of these methods and for instance
rename doit using a more appropriate name. But, when doing so,
the programmer has to overwrite both __call__ and guiCallback to call
the right method to carry out the work.

Besides these methods which are required to be implemented in a command there
are the following optional methods:
     strArg(self, arg):
         Method to turn a command argument into a string. Used by the log
         method to generate a log string for the command.
         This method can be overwritten or extended by classes subclassing
         Command in order to handle properly instances of objects defined
         by the application when not handled properly by the base class.
         This method has been overwritten to be 'Molecule' aware.
         If you need to handle an argument a particular way this method should
         be overwritten.
        This method called when command is loaded. It typically checks for dependencies and
        if all the dependencies are not found the command won't be loaded.
        See msmsCommands for an example
        (previously initCommand)
        onAddCmdToViewer is called once when a command is loaded into a
        Typically, this method :
            takes care of dependencies (i.e. load other commands that
                                        might be required)
            creates/initializes variables.
        see, etc...
        method allowing to modify the GUI associated with a command
    onAddObjectToViewer(self, obj):
        (previously named initGeom)
        When a command is loaded that implements an onAddObjectToViewer
        function,this function id called for every object present in the
        Once the command is loaded, this function will be called for every
        new object added to the application.
        In general, onAddObjectToViewer is used by a command to add a new
        geometry to the geometry container of an object.
        It is also where picking events and building arrays of colors specific
        to each geometry can be registered.

        See secondaryStructureCommands, msmsCommadns etc.. for an example
    onRemoveObjectFromViewer(self, obj):
        In python if all references to an object are not deleted, memory
        space occupied by that object even after its deletion is not freed.
        This function will be called for every object removed (deleted) from
        the application.
        When references to an object are created inside a command which are
        not related to the geomContainer of the object, in order to prevent
        memory leak this command has to implement an onRemoveObjectFromViewer
        to delete those references.
        See secondaryStructureCommands for an example

The following methods are helper methods.
    log(self, *args, **kw):
         Method to log a command. args provides a list of positional
         arguments and kw is a dictionary of named arguments. This method
         loops over both args and kw and builds a string representation of
         their values. When a class is passed as one the arguments, an
         additional command is logged to load that class.
         This method also sets the command's lastCmdLog member.

    showForm(self, *args, **kw):
        If the inputForm object associated with the given formName already
        exists than it just deiconify the forms unless the force argument is
        set to true.
        Otherwise, showForm calls buildFormDescr with the given
        formName, then it creates an instance of InputForm with the given
        parameters and stores this object in the cmdForms dictionary, where
        the key is the formName and the value the InputForm object.
        (see the showForm documentation string for the description of the
        showForm will return the dictionary containing the values of the
        widgets if modal or blocking other it will return the form object.
If a command generates geometries to be displayed in the camera, it is
expected to create the geometry objects and add them to the appropriate

A Python module implementing commands should implement the following at the
end of the file so the commands are loadable in the application using
the browseCommands command.

commandList -- which is a list of dictionaries containing the following:
               'name': command name (string) used as an alias to invoke
                       the command from the commandline.
               'cmd' : Command Class
               'gui' : Typically is a commandGUI object but can be None
                       if no GUI is associated with the Command

An initModule method
def initModule(viewer):
    for dict in commandList:
        viewer.addCommand(dict['cmd'], dict['name'], dict['gui'])

This method will be used by the browseCommands command to load the
given module into the application but also to determine which
modules implement commands.

Instance Methods [hide private]
  __init__(self, func=None)
  guiCallback(self, event=None, log=None, redraw=None)
Default callback function called by the gui
  _strArg(self, arg)
Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets
  strArg(self, arg)
Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets

Inherited from ViewerFramework.VFCommand.Command: __call__, __repr__, addCallbackAfter, addCallbackBefore, addUndoCall, afterDoit, beforeDoit, buildFormDescr, buildLogArgList, checkDependencies, cleanup, customizeGUI, doit, doitWrapper, getArguments, getHelp, getLastUsedValues, getLogArgs, getValNamedArgs, log, logString, onAddCmdToViewer, onAddNewCmd, onCmdRun, setLastUsedValues, setupUndoAfter, setupUndoBefore, showForm, tkCb, updateGeom, warningMsg

Class Variables [hide private]

Inherited from ViewerFramework.VFCommand.Command: negateKw, objArgOnly

Method Details [hide private]

__init__(self, func=None)

source code 
Overrides: ViewerFramework.VFCommand.Command.__init__

guiCallback(self, event=None, log=None, redraw=None)

source code 
Default callback function called by the gui
Overrides: ViewerFramework.VFCommand.Command.guiCallback
(inherited documentation)

_strArg(self, arg)

source code 
Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets
Overrides: ViewerFramework.VFCommand.Command._strArg

strArg(self, arg)

Method to turn a command argument into a string for logging purposes Add support for TreeNodes and TreeNodeSets
Overrides: ViewerFramework.VFCommand.Command.strArg