Coot: Difference between revisions

1,902 bytes added ,  20 October 2008
no edit summary
No edit summary
Line 212: Line 212:


[[bernhards_key_bindings_for_coot.py]]
[[bernhards_key_bindings_for_coot.py]]
==Python to Scheme and return==
===Translating between Python and Scheme===
Python scripting is different to (default) scheme scripting which is mainly described in Paul Emsley's documentation (although it's mentioned somewhere, fairly hidden). You have to change the commands in the following way:
  GUILE scripting: (guile-command argument1 argument2 ...)
  PYTHON scripting: python_command(argument1, argument2, ...)
====Simple rules for Scheme to Python translations====
Here some simple rules how to translate from Scheme to Python. To translate the other way around, i.e. Python to Scheme, just turn the rules around:
# replace all '-' with '_' (except in equation when you need arithmetic '-' minus signs)
# move the brackets around the argument(s)
# separate multiple arguments by commas rather than spaces
# replace 'define' for functions with 'def' and for assignments with an '='
# Make sure to use indentation for the function content [Python is indentation sensitive] and a ':' after the function definition.
====A simple example====
In Scheme we may have the following script:
(define mol2-pdbFile "somePDBfile.pdb" )
(define mol2-model (read-pdb mol2-pdbFile))
(define (read-mol-again)
        (clear-and-update-model-molecule-from-file mol2-model mol2-pdbFile))
(read-mol-again)
Which will translate into Python:
  mol2_pdbFile = "somePDBfile.pdb"
  mol2_model = read_pdb(mol2_pdbFile)
  def read_mol_again():
      clear_and_update_model_molecule_from_file(mol2_model, mol2_pdbFile)
  read_mol_again()
===Running a Scheme/Python command from Python/Scheme===
As of Coot 0.5 (and if you have both scripting languages available) you an use the following commands to run a script or command in the other language:
  (run-python-command "python_command(arg1, arg2, ...)")    [from guile/scheme]
  run_scheme_command("(scheme-command arg1 arg2 ...)")      [from python]


=Enhanced Menu Appearance=
=Enhanced Menu Appearance=
28

edits