Page width Text size

OlexSys News & Events

Be informed with important and relevant news about our software and services

Add your own Python scripts to Olex2

Author: OlexSys Ltd/11 September 2013/Categories: Documentation

Olex2 can be scripted using Python. Here are a few pointers which will help you to get started. Firstly, we recommend using a Python IDE when working with scripts. We are developing our Python code using Wing IDE. The place to put your python scripts is in the Olex2 subdirectory /etc/scripts. To register a script with Olex2, you need to add the name of your file to the list in the  file called ''. We will not update this file when Olex2 updates, so your links will be safe. The only entry in this file is 'import example' - and if you look at the file called, you will see the minimum imports required to work with Olex2: import olex import olx from olexFunctions import OlexFunctions OV = OlexFunctions() ''' To run this example script, type spy.example("Hello") in Olex2 ''' def example(text="No Text Provided"): print "Example Function is now printing your text: %s" %text OV.registerFunction(example) All Python scripts are called by prefexing the command with the string 'spy.' So, When you type 'spy.example' in Olex2, the text above will be printed. If you type 'spy.example(Hello!)' it will print 'Hello!'. Go on, try it! And that's it. You have now full access to ALL functions in Olex2 -- and also everything in the cctbx. Of course, you need to figure out the relevant imports for everything to work. Above, we imported olx. This gives you access to everything Olex2 knows about a structure. For example, to find everything to do with the asymmetric unit, you need to explore
  • - Fractionalise arguments [1 or 3]
  • - GetAtomAfix arguments [1]
  • - GetAtomCount arguments [none]
  • - GetAtomCrd arguments [1]
  • - GetAtomlabel arguments [2]
  • - GetAtomName arguments [1]
  • - GetAtomOccu arguments [1]
  • - GetAtomType arguments [1]
  • - GetAtomU arguments [1]
  • - GetAtomUiso arguments [1]
  • - GetCell arguments [none or 1]
  • - GetCellSymm arguments [none or 1]
  • - GetCellVolume arguments [none]
  • - GetFormula arguments [none]
  • - GetPeak arguments [1]
  • - GetVolume arguments [none]
  • - GetWeight arguments [none or 1]
  • - GetZ arguments [none]
  • - GetZprime arguments [none]
  • - IsAtomDeleted arguments [1]
  • - IsPeak arguments [1]
  • - NewAtom arguments [4]
  • - NPDCount arguments [none]
  • - Orthogonalise arguments [1 or 3]
  • - SetAtomCrd arguments [4]
  • - SetAtomlabel arguments [2]
  • - SetAtomOccu arguments [2]
  • - SetAtomU arguments [2 or 7]
  • - SetZ arguments [1]
  • - SetZprime arguments [1]
In order to explore the cctbx, you need to import OlexCctbxAdapter. from cctbx_olex_adapter import OlexCctbxAdapter oca = OlexCctbxAdapter() In your IDE, you can now explore the contents of oca.

Number of views (2931)/Comments (0)

Comments are only visible to subscribers.

Theme picker

Did You Know?

The latest version of ShelXL is fully supported by Olex2. 

Please use the latest versions of ShelXL. If you haven't updated to ShelXL-20XX yet, then please get your copy now by searching for SHELX on the web!

What's New

Olex2 Workshop at the IUCr in Prague 2020

Olex2 Workshop at the IUCr in Prague 2020

This workshop has now been postponed to the IUCr in 2021 There will be an official Olex2 Workshop at the start of this year's IUCr on Saturday, 22nd August in Prague. Registration now...
10 February 2020/Author: OlexSys Ltd/Number of views (1922)/Comments (0)/

Theme picker

How to Find OlexSys

OlexSys Ltd
Chemistry Department

Durham University, DH1 3LE , UK

+44 (0) 191 334 2004