restraintmaker.interface_Pymol package

Subpackages

Submodules

restraintmaker.interface_Pymol.RestraintMaker_Logic module

Contains the class Logic_Handler, which defines the program flow, decides which user activities are allowed and manages Importers, Selections, Restraints, Filters, Optimzers and Exporters.

class restraintmaker.interface_Pymol.RestraintMaker_Logic.Logic_Handler(all_atoms: List[restraintmaker.utils.Utilities.Atom])[source]

Bases: object

__init__(all_atoms: List[restraintmaker.utils.Utilities.Atom])[source]

Handles the program flow. By defining it inside a class we get proper encapsulation and prevent problems with multiple imports

When a GUI Program Launches it should create one instance of a Logic_Handler and use it to control the program flow. It should pass GUI-events to it (by calling the react_to_event method.). The GUI Module should NOT need to directly access any other modules. (Except utilities). Warning: To keep things clean there is not backwards communicatopn from the Logic_Handler to the GUI module. It is the GUI Modules responsibility to check on the current state of the program, after creating events. Warning: I really do NOT want the GUI-Program to inherit form the Logic_Handler. It will inherit from a GUI Element (e.g. interface_Pymol.Wizard). Python suppports multiple inheritance, but I don’t.

RECOMMENDATIONS TO WRITE A NEW GUI MODULE: The GUI Module should have the following functions/Elements

  1. Buttons/Lists… for the different actions that can be performed (Import, RestraintType, Selection …). These should call the function set_importer_type, set_restraint_type …

    The GUI Program should use the action_states dict, to check which actions are currently available.

  2. 2 Toggle buttons / radio buttons… to switch between select / delete mode and atom / restraint mode

  1. Events: The GUI Module is responsible for translating whatever events it understands into events relevant to the selections. It can do this by calling the function react_to_event(event_type, kw_args) Recommended translations: SELECT: When the user clicks a certain Atom

    MOVE: Mouse movement / keyboard arrows … SIZE: Mouse wheel / keyboard arrows CONFIRM: Double Click, Enter …

    The GUI module should check the state of the program (event_state dict and selected_atoms, selected-restraints) every time after calling react_to_event. I recommend wrapping the react_to_event function into a function of the GUI module to do that automatically.

  2. Some Selections (SphericalSelection & subclasses) are more intuitive if the GUI program draws a sphere at the corresponding position. => If you want that you have to introduce special for the GUI module to check the current selection

Parameters

all_atoms (t.List[u.Atom]) – List of all atoms in the Molecules, which should be connected

_check_selection_status()[source]

_check_selection_status needs to be called at the end of every react_to_*_event function, after updating the selection.

It checks if the selection has finished and adds the selected atoms to the list, if necessary.

Return type

NoReturn

_set_exporter_type(new_exporter_type: type)[source]

changes the current type of Exporter and creates and applies an Exporter of that type. @Warnings Should only be called via set_action_type which handles type checking.

Parameters

new_exporter_type (t.Type[Exporter]) – type of the new Filter

Return type

NoReturn

_set_filter_type(new_filter_type: type)[source]

changes the current type of Filter and creates and applies a Filter of that type.

@Warnings should only be called via set_action_type which handles type checking

Parameters

new_filter_type (t.Type[Filter]) – type of the new Filter

Return type

NoReturn

_set_importer_type(new_importer_type: Type[restraintmaker.io.Importer._Importer])[source]

_set_importer_type changes the current Importer type, and creates and apllies a new Importer of that type.

Warning

Should only be called via set_action_type which handles type checking

Parameters

new_importer_type (type[Importer]) – An available type of Importer

Returns

None

Return type

None

:raises TypeError if new_importer_type is not in available_importer_types

_set_optimizer_type(new_optimizer_type: type)[source]

changes the current type of Optimizer and creates and applies a Optimizer of that type. @Warnings Should only be called via set_action_type which handles type checking.

Parameters

new_optimizer_type (t.Type[Filter]) – type of the new Filter

Return type

NoReturn

_set_restraint_type(new_restraint_type: Type[restraintmaker.utils.Restraints._Restraint])[source]

_set_restraint_type changes the current type of Restraint.

Warning

Should only be called via set_action_type which handles type checking

Parameters

new_restraint_type (type[Restraint._Restraint}) – A type of restraint

Returns

None

Return type

None

Raises

TypeError if new_restraint_type is not in available_restraint_types

_set_selection_type(new_selection_type: type)[source]

chagnes the current type of Selection and starts a new selection of that type.

@warnings: Should only be called via set_action_type which handles type checking

Parameters

new_selection_type (t.Type[Selection]) – type of the new Selection

Return type

NoReturn

react_to_event(event_type: restraintmaker.interface_Pymol.pymol_utilities.program_states.EventType, **kw_args: Any)[source]

react_to_event should be called by the GUI-module to report an event

react_to_event will then call the relevant update function of the active selection and refresh all atom lists etc.

@Waring react_to_event will change the state of the program (i.e. selected_atoms, selected_restraints, mode and actions states) It is strongly recommended to wrap react_to_event into a function of the GUI-module, which will check these and redraw the scene and de?activate buttons, if necessary/.

Parameters
  • event_type (program_states.EventType) – What kind of event was triggered?

  • kw_args (dict) – Arguments the relevant update function will need

Return type

NoReturn

Raises
  • BadArgumentException – if args to not match the the corresponding logic_handler.react_to_*_event_function

  • NotImplementedError – if a new event_type is used, which the function does not know about.

set_action_states()[source]

checks the current state of the program and decides, which actions are allowed at the moment

many TODOs

Return type

NoReturn

set_action_type(x_type)[source]

set_action should be called by the GUI module when the user selects an Importer, Restraint, Selection, Filter, Optimizer or Exporter

It will then call the relevant _set_X_type function.

@Warnings set_action_type will change the state of the program (i.e. selected_atoms, selected_restraints, mode and actions states) It is strongly recommended to wrap react_to_event into a function of the GUI-module, which will check these and redraw the scene and de?activate buttons, if necessary/.

Parameters

x_type (type) – A type of Importer, Selection, Restraint, Filter, Optimizer or Exporter

Return type

NoReturn

Raises

TypeError – if the specified type is not recognized

set_mode(select_delete: bool, atom_restraint: bool)[source]

set_mode should be called by the GUI module when the user toggles the buttons to change the program mode

warning: set_action_type will change the state of the program (i.e. selected_atoms, selected_restraints, mode and actions states) It is strongly recommended to wrap react_to_event into a function of the GUI-module, which will check these and redraw the scene and de?activate buttons, if necessary/.

Parameters
  • select_delete (bool) – Select mode (True) or Delete mode (False)?

  • atom_restraint (bool) – Atoms mode (True) or Delete mode (False)?

Return type

NoReturn

restraintmaker.interface_Pymol.RestraintMaker_Pymol module

This module plugs in the restraintmaker logic into PyMOL. It basically contains the GUI-realisation and the linkeage to the logic.

class restraintmaker.interface_Pymol.RestraintMaker_Pymol.Restraints_Wizard(_self=<module 'pymol.cmd' from '/home/bschroed/miniconda3/envs/restraintmakerDev/lib/python3.9/site-packages/pymol/cmd.py'>)[source]

Bases: pymol.wizard.Wizard

This class helps generating dis res. Sources: label(Wizard)

__init__(_self=<module 'pymol.cmd' from '/home/bschroed/miniconda3/envs/restraintmakerDev/lib/python3.9/site-packages/pymol/cmd.py'>)[source]

Initialize PyMol to the wizard!

Parameters

_self

_action_button_pressed(x_name: str)[source]

button_pressed should be called when any of the action buttons is pressed.

It will call the releveant logic_handler.set_*_type method, redraw the molecule and enable/disabnle buttons if necessary. I think it is easier to pack all buttons into one function, and go through a switch table, than to define seperate functions for importer, Selection etc, plus a function called in all cases

Parameters

x_name (str) – The __name__ attribute of a type Importer, Restraint, Selection, Filter, Optimizer or Exporter

Raises

TypeError if x_type is not a type of Importer, Restraint, Selection, Filter, Optimizer or Exporter

:return - :rtype: None :warning: The x_type attribute MUST be of type string, not type, because of technical issues: To be able to pass this function to the interface_Pymol pyhton interpreter all its arguments need to be of type string So the interface_Pymol module will work with __name__ instead of __class__ attributes

_toggle_button_pressed(button)[source]

_mode_button pressed is called when one of the 2 buttons defining the user mode is pressed.

Parameters

button (str) – Which button was pressed

Returns

Return type

check_objects_exists(obj: str) bool[source]

check_if_onject_exists checks if a interface_Pymol object of a certain name existst. :warning: Pymol does not count Selections as objects.

Parameters

sele (str) – Name of a interface_Pymol selection

Returns

Selection contains at least one object: True. Selection does not exist or is empty: False

Return type

bool

create_pymol_objects_for_restraints()[source]
do_dirty()[source]

TODO: Find a better way to detect movement of pseudoatom: Do_position? / Save last positon and only call do move if it actually moved TODO STRUC: Move this out to a provider function. The GUI handling program should not deal with special cases for certain selction types.

do_key(k, x, y, mod)[source]
Parameters
  • k (int) – pressed key

  • x (float) – coordinate x

  • y (float) – coordinate y

  • mod – shift pressed

do_pick(bondFlag)[source]
do_select(sele)[source]

..function: do_generate_restraints

do_special(k, x, y, mod)[source]

control special actions of the keyboard

Parameters
  • k (int) – pressed key

  • x (int) – coordinate x

  • y (float) – coordinate y

  • mod (int) – pressed shift?

Return type

None

file_nr = 1
get_event_mask()[source]
get_panel()[source]
get_prompt()[source]

called automatically upon refresh wizard

provide_services_to_spherical_selection()[source]
redraw()[source]

redraw paints all selected atoms, and the atoms in the active selection in different colours. Sets all other atoms back to standard colours

Different colours for 1) Atoms in the curently active selections (not yet confirmed)
  1. Selected Atoms

  2. Atoms in restraints

  3. Atoms in restraints we are looking at at the moment (in tst mode))

Returns

Return type

set_wizard_style()[source]
trigger_event(event_type: restraintmaker.interface_Pymol.pymol_utilities.program_states.EventType, **kw_args: Any)[source]

trigger_event will call the logic_handler’s appropriate react_to_*_event function, depending on event_type and cause the wizard and the view to apply the changes caused by the event.

TypeError will be thrown if trigger_event is called without explicitly stating the keywords of the target update function

Parameters
  • event_type (program_states.EventType) – what event has been caused? Acceptable values: ‘select’, ‘move’, ‘size’, ‘confirm’

  • kw_args (t.Any) – Arguments the relevant update functon will need. KEYWORDS OF THE CORRESPONDING _Selection._update_* function MUST BE GIVEN. (** => dict)

Return type

NoReturn

Raises
  • ValueError – if event_type can not be resolved to a logic.handler.react_to_*_event function

  • u.BadArgumentException – if args to not match the the corresponding logic_handler.react_to_*_event_function

update_menu()[source]

Module contents