Skip to content

MooersLab/cctbxsnips-VSC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 

Repository files navigation

cctbxsnips for Visual Studio Code (VS Code or VSC)

Version License: MIT

CCTBX

CCTBX is the Computational Crystallography Toolbox. Its development is based at Lawrence-Berkeley National Laboratory. It provides code for computations with diffraction data and atomic coordinates of proteins and small molecules. It has C++ and Python ports. It is available in Anaconda in the conda-forge channel known as cctbx-base for python3.8 through 3.12 for Windows, macOS, and Linux.

Blaine's cctbx install protocol

I assume that Anaconda has already been installed. We will create a conda env specifically for CCTBX. CCTBX has numerous dependencies. It is best kept in an isolated env. We also create the corresponding Jupyter Notebook kernel while we are at it.

Execute one line at a time: Wait for the execution to finish before executing the next line.

conda create --name cctbx39 python=3.9
conda activate cctbx39
conda install -c conda-forge cctbx-base -y
conda install ipykernel -y
python -m ipykernel install --user --name cctbx39 --display-name "cctbx python3.9"

The second to last command triggers the installation of Jupyter in the cctbx39 env. The last command creates and installs the Jupyter kernel in ~/Library/Jupyter/kernels/cctbx39 on the Mac. Select cctbx python3.9 from the list of kernels when opening a new notebook in Jupyter.

Replace the 3.9 or 39 above with whatever version of Python you want to use (between 3.8 and 3.11).

The problems that this repo addresses

  1. ** Facilitation of code reuse **. Code snippets can save time by reusing existing code. The presence of tab stops in code snippets can help ensure that all parameters that need customization to a new problem are considered. Thus, tab stops can reduce subsequent debugging.

  2. Use VSC to edit Jupyter and Colab code and markdown cells The existing snippet formats for Jupyter and Colab notebooks do not support tab triggers and tab stops, which are standard features of code snippet systems in most text editors. We can overcome these limitations by sending the active code cell to VSC via the GhostText extension for the browser.

Installation

VSC has built-in support for snippets. The snippets are stored in a single JSON file by programming language.

  1. Install the snippets for VSC.

From the above folder vscpymolsnips, download and move the file source.python.json on the macOS to ~/Library/Application\ Support/Code/User/snippets/python.json ; on Windows to $HOME/APPDATA\Roaming\Code\User\snippets\python.json; on Linux to $HOME/.config/Code/User/snippets/python.json. If you have an existing python.json, you want to concatenate the files.

  1. Optional If you want to use these snippets from VSC to edit live cells in Jupyter or Colab notebooks, install GhostText browser extension in your browser and the GhostText extension for VSC. Open the command palette (Option-X on macOS) in VSC and enter "Enable GhostText".

Example of VSCode editing a live code cell in a Jupyter notebook

Note After opening a connection from a code cell in a Jupyter Notebook (light-theme) to VSCode (dark-theme), a markdown document will appear in VSCode. You must manually change the scope to Python by opening the command palette (enter Option-X on macOS) and entering Change Language Mode. This will open a menu with a list of programming languages. Select python. Now you will be able to access the cctbx snippets inside VSCode.

However, each new cell activated with GhostText opens a new temporary document in VScode. The scope has to be changed again. This grows old fast. The default file extension of this temporary document is *.tmp. The tmp file extension can be remapped to Python as follows in the settings.json file:

"files.associations": {
    "*.tmp": "python"
},

The image below shows a popup menu with the selected snippet and a preview of its code in VSC. This provides a chance to check that the snippet has the desired code. Hit tab to insert the code.

The image below shows two code blocks run in the Jupyter Notebook. Note that the output of a run code block is returned to the Jupyter notebook; however, it does not appear in the temporary document in VSC because it is outside of the active text area of the Jupyter notebook. In addition, the name of the mtz file is being changed. While this is happening, Jupyter automatically returns a popup menu of candidate files.

Related repositories

Update History

Version Changes Date
Version 0.1 Fixed typos in README.md 2024 April 10

Sources of funding

  • NIH: R01 CA242845
  • NIH: R01 AI088011
  • NIH: P30 CA225520 (PI: R. Mannel)
  • NIH P20GM103640 and P30GM145423 (PI: A. West)