Skip to content

Getting started

BTheDragonMaster edited this page Jan 11, 2022 · 8 revisions

In order to make PIKAChU as easy to use as possible, we prepared a number of functions in pikachu.general. You can read through these at your own leisure in the GitHub repository, or follow the tutorials below.

Reading SMILES strings

The easiest way to read in SMILES strings is through the read_smiles function in pikachu.general:

from pikachu.general import read_smiles

smiles = 'c1ccccc1'
structure = read_smiles(smiles)

This yields an instance of class Structure, which can be used for visualisation, substructure searches, and performing chemical reactions.

Visualisation

Drawing SMILES strings

Alternatively, if you simply want to visualise your SMILES and do not need to process its structure beforehand, it is possible to directly draw a structure from SMILES. This will make a matplotlib window pop-up, displaying a drawing of your structure.

from pikachu.general import draw_smiles

smiles = 'c1ccccc1'
draw_smiles(smiles)

There are also functions that let you directly save the output image to a .svg or .png:

from pikachu.general import svg_from_smiles, png_from_smiles

smiles = 'c1ccccc1'
svg_from_smiles(smiles, 'benzene.svg')
png_from_smiles(smiles, 'benzene.png')

These functions save the .svg or .png image to the working directory.

Visualising substructures

If you want to visualise substructures in superstructures using SMILES strings, there are three options:

  1. Colour only the first occurrence of a substructure in a superstructure
  2. Colour all occurrences of a substructure in a superstructure
  3. Colour all occurrences of multiple substructures in a superstructure, with the possibility to colour different substructures in different colours.

Each of these functionalities can be executed with a single function call to highlight_subsmiles_single, highlight_subsmiles_all, and highlight_subsmiles_multiple respectively.

When no colours are given, colours are chosen from a default palette, but they can also be user-defined. Many colour names are supported ('brown', 'pink', 'orange', etc.), as well as hex codes (#ffffff).

There is the option to show the molecule in a pop-up window (visualisation='show', default), or save it as an svg (visualisation='svg') or png (visualisation='png'). In the latter two cases, an output file (out_file) should also be provided.

from pikachu.general import highlight_substructure

ornithine = "O=C[C@@H](N)CCCN"
alanine = "O=C[C@@H](N)C"

daptomycin = "CCCCCCCCCC(=O)N[C@@H](CC1=CNC2=CC=CC=C21)C(=O)N[C@H](CC(=O)N)C(=O)N[C@@H](CC(=O)O)C(=O)N[C@H]3[C@H](OC(=O)[C@@H](NC(=O)[C@@H](NC(=O)[C@H](NC(=O)CNC(=O)[C@@H](NC(=O)[C@H](NC(=O)[C@@H](NC(=O)[C@@H](NC(=O)CNC3=O)CCCN)CC(=O)O)C)CC(=O)O)CO)[C@H](C)CC(=O)O)CC(=O)C4=CC=CC=C4N)C"

# Highlighting a single occurrence of a single substructure

highlight_substructure(alanine, daptomycin, search_mode='single')

# Highlighting all occurrences of a single substructure

highlight_substructure(ornithine, daptomycin, search_mode='all', visualisation='svg', out_file='ornithine_in_daptomycin.svg')

# Highlighting all occurrences of multiple substructures

highlight_substructure([alanine, ornithine], daptomycin, search_mode='multiple', colour=['blue', 'dark blue'], visualisation='png', out_file='daptomycin_substructures.png')

Clone this wiki locally