Home > Twilight Electron Density Validation Script > Installation
Following links from my tutorial web site to Amazon.com allows you to find best new and used prices and helps to support the educational parts of this web site. See also my recommendations.
Twilight Installation 

Visualizing Ligand Molecules in Twilight Electron Density - README!

Christian X.  Weichenbergera*,  Edwin  Pozharskib* and  Bernhard  Ruppc

aCenter for Biomedicine, European Academy of Bozen/Bolzano (EURAC), Viale Druso 1, Bozen/Bolzano, I-39100, Italy,  bUniversity of Maryland, Baltimore, MD, USA, and  ck.k. Hofkristallamt, 991 Audrey Place, Vista, CA, 92084, USA

Correspondence email:  Christian.Weichenberger@eurac.edu; epozh001@umaryland.edu

Installation instructions for Twilight (DATE: 2018-Feb-17)

This document provides a guide for installing the side-packages needed to run Twilight, a program for visualizing ligands, which are in disagreement with electron density.

For full functionality, the Crystallographic Object-Oriented Toolkit (coot) needs to be installed on your system. Please visit the coot web page http://www.biop.ox.ac.uk/coot for further instructions on installing coot.

The package is shipped as a BZIP-compressed tarball. Each supported platform offers a great variety of utilities for extraction. We assume you are familiar with your preferred extraction program, and nowadays on most operating systems a double click on the package will extract its contents.

The software depends on Python 2.X, and it was tested with Python 2.7. We therefore recommend installing Python 2.7 on your system, unless it is already present. See the following supported operating systems for a detailed description on installation and launching. Please be sure your PYTHONPATH environment variable points to the correct installation, this especially applies to CCP4 users, since the suite is shipped with its own python interpreter and alters the environment variables.

For all Operating Systems, please unpack the Twilight archive into a suitable working directory of your choice. Then follow the remaining instructions.


We have tested Twilight on Debian 6, aka 'Squeeze'. PyGTK is available for most Linux distributions, and on many of them, along with Python, it is already installed by default. Please see your distribution dependent package manager for instructions on how to find/install packages on your system.

At the time of writing, Debian 6 (Squeeze) was shipped with Python 2.6 by default. The Twilight application will nevertheless run on these systems and emit some warnings as some negligible functionalities will not be supported. To install PyGTK on this Linux distribution you need to enter the following command (requires root privileges):

sudo aptitude install python2.6 python-gtk2

See steps 4 and 5 from the Windows installation instructions for testing and launching the Twilight application.

Mac OS X

On Mac OS X, PyGTK used to be a little bit more complicated to install, as no installer packages was available for this platform at the time of Twilight development. Thanks to a hint from Avinash P., this can now be easily done by downloading the latest version of a PyGTK installer package for Mac OS X at sourceforge:


If this does not work for you, please follow the instructions we have previously suggested:


In case fink (http://www.finkproject.org/) is installed on your system, you need to install the corresponding 'pygtk2-gtk-pyXY' package, where 'XY' is the matching version number for your Python interpreter. For example, if you are running Python 2.7 (as can be found out by typing 'python --version' in the command line), you need to install 'pygtk2-gtk-py27' with the command 'fink install pygtk2-gtk-py27'. See steps 4 and 5 from the Windows installation instructions for testing and launching the Twilight application.

If you are using MacPorts (http://www.macports.org/), the following series of commands should install PyGTK for Python 2.7. As we are not using MacPorts, we could not test this approach.

sudo port install python27
sudo port select --set python python27
sudo port install py27-pygtk

An installation tip from George Phillips: Also the $PYTHONPATH env variable has to point to the right installation of python.Sometimes the ccp4 configuration sets the path elsewhere, and I did not have the optional command lines tools installed for XCODE, which is a prequisite for macports.

Instead of setting up from scratch fink or macports, a Linux virtual machine running Debian may be a time saving option, see the Linux section of the README. We have successfully tested Twilight on several operating system with VirtualBox, https://www.virtualbox.org.

See steps 4 and 5 from the Windows installation instructions for testing and launching the Twilight application.


Please have a look at the PyGTK web site, http://www.pygtk.org/downloads.html. A Python interpreter has to be installed prior to installation of the PyGTK package. The steps for installing PyGTK on Windows are summarized below:

1. Find out if there is already some Python interpreter on your machine. Open a DOS-shell (Start->All Programs->Accessories->Command Prompt) and type 'python --version'. If there is a message like 'Python 2.X.Y', remember that you have installed a Python interpreter with version number 2.X and skip the next step. If the command has not been recognized follow the next step.

2. Install Python. We recommend to install the 32-bit version of Python 2.7, which can be retrieved from http://python.org/download/. Remember your Python version: 2.7

3. Install PyGTK. Go to the home page of PyGTK and download the all-in-one installer. You will also find a README file in the download directory for detailed explanations. Importantly, you need to download the matching version for your Python interpreter you have taken down in either step 1 or step 2. For example, if you have installed Python 2.7 on your system, the PyGTK package 'pygtk-all-in-one-2.24.2.win32-py2.7.msi' will install PyGTK 2.24.2 for your 32-bit Windows.

4. Test your installation. Open a Command Prompt (see step 1) and change the working directory to the installation directory of Twilight. Type in the command 'python pygtktest.py', and if everything has been installed properly, a short message will appear in a PyGTK window. You are now ready to run the real application.

5. Run Twilight. If you are not yet in the installation directory of Twilight, change to it now. Type 'python twilight.py', and after a short loading time an empty Twilight window will appear. Use the 'File' menu to load the ligand table file called 'ligands-2012-01-15.tsv' (as discussed in the accompanying publication [PMID 23385767]) or the file 'ligands-2018-01-11.tsv' (shipped
with Twilight v1.12 and higher). Additional options can be supplied to the Twilight program, please type 'python twilight.py --help' for a comprehensive list of available options. Especially, if you are interested in exploring ligands in very good agreement with electron density, invoke Twilight with the command line option '--show-hq-rscc'. Sorting and grouping the table by RSCC value alone (default is by combined score S) is achieved by the command line option '--sort-rscc'.


Techniques, tools and best practices for ligand electron-density analysis and results from their application to deposited crystal structures. E. Pozharski, C. X. Weichenberger and B. Rupp, Acta Crystallogr D69, 150-167 (2013)

Visualizing Ligand Molecules in Twilight Electron Density. C. X. Weichenberger, E. Pozharski and B. Rupp, Acta Crystallogr. F69(2), 195-200 (2013)



Change Log

Program distribution comes in a bz2 zipped tar package:

New Twilight (2018 and on) can be downloaded here. The old 2012 version is still available here.

My texbook

A useful resource if you want to learn more about protein crystallography, ligand structures, and structure validation

For now

You can still use the web tutorial for free!

Telephone: 925-209-7429 • The entire site 2005-2017 by Bernhard Rupp. All rights reserved.