├── LICENSE ├── README.md └── python.snippets /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Blaine Mooers and the Board of Regenets for the University of Oklahoma Health Sciences 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cctbxsnips for the UltiSnips plugin in Vim and NeoVim 2 | 3 | ![Version](https://img.shields.io/static/v1?label=cctbxsnips-Ultisnips&message=0.1&color=brightcolor) 4 | [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT) 5 | 6 | 7 | ## CCTBX 8 | 9 | [CCTBX](https://github.com/cctbx/cctbx_project) is the Computational Crystallography Toolbox. 10 | Its development is based at Lawrence-Berkeley National Laboratory. 11 | It provides code for computations with diffraction data and atomic coordinates of proteins and small molecules. 12 | It has C++ and Python ports. 13 | It is available in Anaconda in the conda-forge channel as cctbx-base for python3.8 through 3.11 for Windows, macOS, and Linux. 14 | 15 | ### Installation 16 | 17 | I assume that Anaconda has already been installed. We also create the 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. 18 | 19 | ```bash 20 | conda create --name cctbx39 python=3.9 21 | conda activate cctbx39 22 | conda install -c conda-forge cctbx-base -y 23 | conda install ipykernel -y 24 | python -m ipykernel install --user --name cctbx39 --display-name "cctbx python3.9" 25 | ``` 26 | 27 | The second to last command triggers the installation of Jupyter in the cctbx39 env. 28 | The last command creates and installs the Jupyter kernel in `~/Library/Jupyter/kernels/cctbx39` on the Mac. 29 | Select **cctbx python3.9** from the list of kernels when opening a new notebook in Jupyter. 30 | 31 | Replace the *3.9* or *39* above with whatever version of Python you want to use (between 3.8 and 3.11). 32 | 33 | ## UltiSnips 34 | 35 | UltiSnips is a popular snippet manager for Vim. 36 | It should work with [NeoVim](https://github.com/SirVer/ultisnips/issues/1505), but due to changes in NeoVim, UltiSnips is less stable there. 37 | There are other snippets managers for Vim and NeoVim, but UltiSnips is well-established. 38 | 39 | 40 | ## The problems that this repo addresses 41 | 42 | 1. **Facilitation of code reuse**. The use of 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. 43 | 44 | 2. **Use Emacs 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 Emacs via the GhostText extension for the browser and the atomic-chrome package for Emacs. 45 | 46 | ## Installation 47 | 48 | 1. Install the snippets for Vim. 49 | 50 | I assume that the Ultisnips plugin has already been properly installed. 51 | The snippets are stored in a single file called python.snippets. 52 | I store this file in a folder called my-snippets/Ultisnips. 53 | You may have to concatenate python.snippets with an existing python.snippets file. 54 | 55 | ```bash 56 | cd ~/.vim/my-snippets/Ultisnips 57 | git clone https://github.com/MooersLab/cctbxsnips-Ultisnips.git 58 | cd cctbxsnips-Ultisnips/ 59 | mv python.snippets ../. 60 | cd .. 61 | rm -rf cctbxsnips-Ultisnips 62 | ``` 63 | 64 | 2. **Optional** If you want to use these snippets from Vim or NeoVim to edit live cells in Jupyter or Colab notebooks, install [GhostText](https://ghosttext.fregante.com/) in your browser and the [Vim Ghost](https://github.com/raghur/vim-ghost)plugin for Vim. Install the [nvim-ghost](https://github.com/subnut/nvim-ghost.nvim] plugin for NeoVim). 65 | 66 | 67 | ## Related repositories 68 | - [cctbxsnips-Emacs](https://github.com/MooersLab/cctbxsnips-Emacs) CCTBX snippets for the yasnippet snippet system in for Emacs. 69 | - [cctbxsnips-SublimeText3](https://github.com/MooersLab/cctbxsnips-SublimeText3) CCTBX snippets for Sublime Text 3 (ST3). 70 | - [cctbxsnips-VSC](https://github.com/MooersLab/cctbxsnips-VSC) CCTBX snippets for Visual Studio Code (VSC). 71 | - [cctbxsnips-neosnippets](https://github.com/MooersLab/cctbxsnips-neosnippets) CCTBX snippets for Vim or NeoVim via neosnippets plugin. 72 | - [cctbxsnips-Snipmate](https://github.com/MooersLab/cctbxsnips-snipmate) CCTBX snippets for Vim or NeoVim via snipmate plugin. 73 | - [cctbxsnips-Atom](https://github.com/MooersLab/cctbxsnips-Atom) CCTBX snippets for Atom. 74 | - [Jupyterlab cctbx snippets](https://github.com/MooersLab/jupyterlabcctbxsnips) CCTBX snippets for JupyterLab with the jupyterlab-snippets extension or the jupyterlab-snippets-mutlimenus extension. 75 | - [Jupyterlab cctbx plus snippets](https://github.com/MooersLab/jupyterlabcctbxsnipsplus) The variant of the jupyterlabcctbxsnips library with comments to guide editing of the snippets. 76 | - [Colab cctbx snippets](https://github.com/MooersLab/colabcctbxsnips) Colab snippets. 77 | 78 | ## Update History 79 | 80 | |Version | Changes | Date | 81 | |:-----------:|:---------------------------------------------------------------------------:|:---------------:| 82 | | Version 0.2 | Fixed typos in README.md. Added Badges and Update table | 2024 April 12 | 83 | 84 | 85 | ## Sources of funding 86 | 87 | - NIH: R01 CA242845 88 | - NIH: R01 AI088011 89 | - NIH: P30 CA225520 (PI: R. Mannel) 90 | - NIH P20GM103640 and P30GM145423 (PI: A. West) 91 | -------------------------------------------------------------------------------- /python.snippets: -------------------------------------------------------------------------------- 1 | snippet millerMtzImports "Read a mtz file into a miller array." b 2 | from iotbx.reflection_file_reader import any_reflection_file 3 | hkl_file = any_reflection_file("${1:3hz7.mtz}") 4 | miller_arrays = hkl_file.as_miller_arrays(merge_equivalents=False) 5 | $0 6 | endsnippet 7 | 8 | snippet millerArrayLabels "Print column labels in a Miller array." b 9 | [print("Miller Array %s: %s" % (i, miller_array.info().labels)) for i, miller_array in list(enumerate(miller_arrays))[:2]] 10 | $0 11 | endsnippet 12 | 13 | snippet millerArrayWavelengths "Print wavelengths of each miller array." b 14 | [print("Miller Array %s: %s" % (i, miller_array.info().wavelength)) for i, miller_array in list(enumerate(miller_arrays))] 15 | $0 16 | endsnippet 17 | 18 | snippet millerArraySources "Print the source of each miller array." b 19 | print("Miller Array %s: %s" % (i, miller_array.info().source)) for i, miller_array in list(enumerate(miller_arrays))] 20 | $0 21 | endsnippet 22 | 23 | snippet millerArrayLengths "Print length of miller arrays (i.e., the number of datasets in a mtz file)." b 24 | len(miller_arrays) 25 | $0 26 | endsnippet 27 | 28 | snippet millerArraySymmetry "Print the crystal symmetry of each miller array." b 29 | [print("Miller Array %s: %s" % (i, miller_array.info().crystal_symmetry_from_file)) for i, miller_array in list(enumerate(miller_arrays))] 30 | $0 31 | endsnippet 32 | 33 | snippet millerArrayHKLs "Print all of the miller indices for a given Miller array." b 34 | [print(hkl) for hkl in miller_arrays[${1:0}].indices()] 35 | $0 36 | endsnippet 37 | 38 | snippet millerArrayMethods "Print the available methods for the Miller class." b 39 | dir(miller_arrays[${1:0}]) 40 | $0 41 | endsnippet 42 | 43 | snippet millerArraydstar "Return the resolution range in d* in a specified Miller array." b 44 | miller_arrays[${1:0}].min_max_d_star_sq() 45 | $0 46 | endsnippet 47 | 48 | snippet millerArrayDminDmax "Return the resolution range in Angstroms for a Miller array." b 49 | miller_arrays[${1:0}].d_max_min() 50 | $0 51 | endsnippet 52 | 53 | snippet millerArrayIsigma 54 | "Return the I/sig overall for a given Miller array." b 55 | miller_arrays[${1:0}].i_over_sig_i() 56 | $0 57 | endsnippet 58 | 59 | snippet millerArrayCC "Return CC one-half sigma tau for a given Miller array." b 60 | miller_arrays[${1:0}].cc_one_half_sigma_tau() 61 | $0 62 | endsnippet 63 | 64 | snippet millerArrayCConeHalf "Return CC one-half for a given Miller array. " b 65 | miller_arrays[${1:0}].cc_one_half() 66 | $0 67 | endsnippet 68 | 69 | snippet millerArrayBijvoetRatios "Print the Bijvoet ratios in a specified Miller array. May have to average by bin first." b 70 | [print(i) for i in miller_arrays[${1:0}].bijvoet_ratios()] 71 | $0 72 | endsnippet 73 | 74 | snippet millerArrayMeasurability "Return the `measurability` of the anomalous signal in a specified Miller array." b 75 | miller_arrays[${1:0}].measurability() 76 | $0 77 | endsnippet 78 | 79 | snippet millerArrayAnomalousSignal "Return the anomalous signal in a specified Miller array." b 80 | miller_arrays[${1:0}].anomalous_signal() 81 | $0 82 | endsnippet 83 | 84 | snippet millerArrayComprehensiveSummary "Show comprehensive summary for a specified Miller array. " b 85 | miller_arrays[${1:0}].show_comprehensive_summary() 86 | $0 87 | endsnippet 88 | 89 | snippet millerArrayCountBijvoetPairs "Show number of bijvoet pairs for a specified Miller array." b 90 | miller_arrays[${1:0}].n_bijvoet_pairs() 91 | $0 92 | endsnippet 93 | 94 | snippet millerArrayWilsonRatio "Show wilson ratio of miller array for a specified Miller array. " b 95 | miller_arrays[${1:0}].wilson_ratio() 96 | $0 97 | endsnippet 98 | 99 | snippet millerArrayUnpackIpIn "Unpack into I(+) and I(-) for a specified Miller array. " b 100 | Iobs = miller_arrays[${1:0}] 101 | i_plus, i_minus = Iobs.hemispheres_acentrics() 102 | ipd = i_plus.data() 103 | ip=list(ipd) 104 | imd = i_minus.data() 105 | im = list(imd) 106 | len(im) 107 | Iobs.show_summary() 108 | print(Iobs.info()) 109 | print(Iobs.observation_type()) 110 | $0 111 | endsnippet 112 | 113 | snippet millerArrayPrintSelectRows "Print five rows of the Iobs for a specified Miller array. " b 114 | list(Iobs[${1:100:105}]) 115 | $0 116 | endsnippet 117 | 118 | snippet millerArrayExtractIntensities "Extract just the intensities for a give Miller array and print ten rows of them." b 119 | Iobs = miller_arrays[${1:0}] 120 | iobsdata = Iobs.data() 121 | list(iobsdata[${1:100:110}]) 122 | $0 123 | endsnippet 124 | 125 | snippet millerArrayPrintntensities "Print all of the intensities for a given Miller array." b 126 | [print(hkl) for hkl in miller_arrays[1].data()] 127 | $0 128 | endsnippet 129 | 130 | snippet millerArrayconvert2mtz "Convert the miller array into a mtz_dataset and write out as a mtz file." b 131 | # Convert the miller array into a mtz_dataset and write out as a mtz file. 132 | mtz_dataset = Iobs.as_mtz_dataset(column_root_label="${1:I}") 133 | mtz_dataset.mtz_object().write("${2:3hz7intensities}.mtz") 134 | $0 135 | endsnippet 136 | 137 | snippet millerArrayReadMtz "Read in the mtz file and print its column labels as a sanity check." b 138 | mtz_filename2 = "${1:3hz7intensities}.mtz" 139 | mtz_file2 = mtz.object(mtz_filename2) 140 | mtz_file2.column_labels() 141 | $0 142 | endsnippet 143 | 144 | snippet millerArray2Dictionary "Set up the arrays as dictionaries" b 145 | from iotbx import mtz 146 | mtz_obj = mtz.object(file_name="${1:3nd4}.mtz") 147 | # Only works with mtz.object. 148 | # Does not work if mtz is read in with iotbx.file_reader. 149 | miller_arrays_dict = mtz_obj.as_miller_arrays_dict() 150 | $0 151 | endsnippet 152 | 153 | snippet millerArrayDictionaryKeys "Print the miller keys() of a miller dictionary." b 154 | miller_arrays_dict.keys() 155 | $0 156 | endsnippet 157 | 158 | snippet millerArrayDictPrintColumns "Print the column labels of Miller dictionary." b 159 | from iotbx import mtz 160 | mtz_obj = mtz.object(file_name="${1:/Users/blaine/3nd4.mtz}") 161 | # Only works with mtz.object. Does not work if mtz is read in with iotbx.file_reader. 162 | miller_arrays_dict = mtz_obj.as_miller_arrays_dict() 163 | [print(f"Column label: {key[2]}") for key in miller_arrays_dict.keys()] 164 | $0 165 | endsnippet 166 | 167 | snippet millerArrayBuildFromUnitCell "Peter Zwart's code for generating the indices for unit cell of given symmetry and dimensions. " b 168 | from cctbx import miller 169 | import cctbx 170 | from cctbx import crystal 171 | 172 | ms = miller.build_set( 173 | crystal_symmetry=crystal.symmetry( 174 | space_group_symbol="${1:Fd-3m}", 175 | unit_cell=(${2:5.4307,5.4307,5.4307,90.00,90.0,90.00})), 176 | anomalous_flag=${3:True}, 177 | d_min=${4:0.4}) 178 | 179 | [print(hkl) for hkl in ms.indices()] 180 | $0 181 | endsnippet 182 | 183 | snippet millerArrayMapToASU "Map generated reflections to the asu and print." b 184 | from cctbx import miller 185 | import cctbx 186 | from cctbx import crystal 187 | 188 | ms = miller.build_set( 189 | crystal_symmetry=crystal.symmetry( 190 | space_group_symbol="${1:Fd-3m}", 191 | unit_cell=(${2:5.4307,5.4307,5.4307,90.00,90.0,90.00})), 192 | anomalous_flag=${3:True}, 193 | d_min=${4:0.4}) 194 | 195 | msu = ms.map_to_asu() 196 | [print(hkl2) for hkl2 in msu.indices()] 197 | $0 198 | endsnippet 199 | 200 | snippet millerArrayPrintSummary "Read mtz file into a miller array and print summary." b 201 | from iotbx.reflection_file_reader import any_reflection_file 202 | hkl_in = any_reflection_file(file_name="${1:3nd4}.mtz") 203 | miller_arrays = hkl_in.as_miller_arrays() 204 | f_obs = miller_arrays[0] 205 | f_obs.show_summary() 206 | $0 207 | endsnippet 208 | 209 | snippet mtzObjectSummary "Read mtz file into a mtz object and print summary." b 210 | from iotbx import mtz 211 | mtz_obj = mtz.object(file_name="/Users/blaine/${1:3nd4}.mtz") 212 | mtz_obj.show_summary() 213 | $0 214 | endsnippet 215 | 216 | snippet millerArrayFromMtz "Read mtz file into a Miller array." b 217 | from iotbx import mtz 218 | mtz_obj = mtz.object(file_name="${1:3nd4}.mtz") 219 | miller_arrays = mtz_obj.as_miller_arrays() 220 | $0 221 | endsnippet 222 | 223 | snippet millerArrayTruncate "Read mtz file into a Miller array, truncate, and print summary." b 224 | from iotbx import mtz 225 | mtz_obj = mtz.object(file_name="${1:3nd4}.mtz") 226 | miller_arrays = mtz_obj.as_miller_arrays() 227 | miller_array_truncated = miller_arrays[0].resolution_filter(d_min=${2:2}, d_max=${3:5}) 228 | print(miller_array_truncated) 229 | miller_array_truncated.show_summary() 230 | $0 231 | endsnippet 232 | 233 | snippet millerArrayDictColumnLabels "Print column labels of a Miller array dictionary." b 234 | [print(f"Column label: {key[2]}") for key in miller_arrays_dict.keys()] 235 | $0 236 | endsnippet 237 | 238 | snippet condaInstall "The conda commands to install cctbx with the jupyter notebook, pandas, and xarray." b 239 | conda create --name ${1:cctbx37} python=${2:3.7} 240 | conda activate ${1:cctbx37} 241 | conda install -c conda-forge cctbx-base jupyter pandas xarray 242 | $0 243 | endsnippet 244 | 245 | snippet condaRemove "The conda commands to remove cctbx37 env." b 246 | conda remove --name ${1:cctbx37} 247 | endsnippet 248 | 249 | snippet fetchPDB "Fetch pdb file from RCSB in PDB format." b 250 | from iotbx.pdb.fetch import get_pdb 251 | import sys 252 | get_pdb(id="${1:3nd4}",data_type="pdb", mirror="rcsb", format="pdb", log=sys.stdout) 253 | $0 254 | endsnippet 255 | 256 | snippet updateCLT "Update the command line tools for Xcode on Mac OS X. " b 257 | sudo touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress 258 | softwareupdate -l 259 | # Update command line tools via software update. 260 | sudo rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress 261 | endsnippet 262 | 263 | snippet extractCrystalSymmetry "Extract crystal symmetry from mtz file." b 264 | from __future__ import absolute_import, division, print_function 265 | from iotbx import mtz 266 | from cctbx import crystal 267 | 268 | def extract_from(file_name): 269 | mtz_object = mtz.object(file_name=file_name) 270 | assert mtz_object.n_symmetry_matrices() > 0 271 | return mtz_object.crystals()[0].crystal_symmetry() 272 | 273 | extract_from(file_name="${1:3nd4}.mtz") 274 | $0 275 | endsnippet 276 | 277 | snippet plotDstarsLogMeans "Generate the list of dstars and logMeans as lists for plotting by matplotlib." b 278 | '''Generate the list of dstars and logMeans as lists 279 | for plotting by matplotlib.''' 280 | 281 | used = list(binner.range_used()) 282 | selections = [binner.selection(i) for i in used] 283 | 284 | # make means of the intensities by bin 285 | means = [Iobs.select(sel).mean() for sel in selections] 286 | from math import log 287 | lnmeans = [log(y) for y in means] 288 | 289 | # meansBR = [Iobs.bijvoet_ratios().select(sel).mean() for sel in selections] 290 | 291 | # make d_centers 292 | d_star_power = 1.618034 293 | centers = binner.bin_centers(d_star_power) 294 | d_centers = list(centers**(-1 / d_star_power)) 295 | 296 | %matplotlib inline 297 | import matplotlib.pyplot as plt 298 | import matplotlib as mpl 299 | mpl.rcParams["savefig.dpi"] = 600 300 | mpl.rcParams["figure.dpi"] = 600 301 | 302 | fig, ax = plt.subplots(figsize=[3.25, 2.]) 303 | ax.scatter(d_centers,lnmeans,c="k",alpha=0.3,s=5.5) 304 | 305 | ax.set_xlim(${1:8, 1.5}) # decreasing time 306 | ax.set_xlabel(r"$d^*$ in $\AA$",fontsize=12) 307 | ax.set_ylabel("ln(I)",fontsize=12) 308 | plt.xticks(fontsize=12) 309 | plt.yticks(fontsize=12) 310 | ax.grid(False) 311 | plt.savefig("${2:3hz7}iobsvsdstar.pdf",bbox_inches="tight") 312 | plt.show() 313 | $0 314 | endsnippet 315 | 316 | snippet plotDstarsMeasurability "Generate the list of dstars and measurability as lists for plotting by matplotlib." b 317 | from iotbx.reflection_file_reader import any_reflection_file 318 | hkl_file = any_reflection_file("${1:3hz7}.mtz") 319 | miller_arrays = hkl_file.as_miller_arrays(merge_equivalents=False) 320 | 321 | Iobs = miller_arrays[1] 322 | # Set up the bins 323 | n_bins = 50 324 | binner = Iobs.setup_binner(n_bins=n_bins) 325 | # binner.show_summary() 326 | used = list(binner.range_used()) 327 | selections = [binner.selection(i) for i in used] 328 | 329 | # make d_centers for the x-axis 330 | d_star_power = 1.618034 331 | centers = binner.bin_centers(d_star_power) 332 | d_centers = list(centers**(-1 / d_star_power)) 333 | 334 | # make list of the measurabilities by resolution bin 335 | meas = [Iobs.select(sel).measurability() for sel in selections] 336 | 337 | %matplotlib inline 338 | import matplotlib.pyplot as plt 339 | import matplotlib as mpl 340 | mpl.rcParams["savefig.dpi"] = 600 341 | mpl.rcParams["figure.dpi"] = 600 342 | 343 | fig, ax = plt.subplots(figsize=[3.25, 2.]) 344 | ax.scatter(d_centers,lnmeans,c="k",alpha=0.3,s=5.5) 345 | 346 | ax.set_xlim(8, 1.5) # decreasing time 347 | ax.set_xlabel(r"$d^*$ in $\AA$",fontsize=12) 348 | ax.set_ylabel("ln(I)",fontsize=12) 349 | plt.xticks(fontsize=12) 350 | plt.yticks(fontsize=12) 351 | ax.grid(False) 352 | plt.savefig("${1:3hz7}measureability.pdf",bbox_inches="tight") 353 | plt.show() 354 | $0 355 | endsnippet 356 | 357 | snippet computeAllMillerIndices "Compute all possible Miller indices." b 358 | from cctbx import miller 359 | 360 | def generate_reflection_indices(uc, dmin): 361 | maxh, maxk, maxl = uc.max_miller_indices(dmin) 362 | 363 | indices = [] 364 | 365 | for h in range(-maxh, maxh + 1): 366 | for k in range(-maxk, maxk + 1): 367 | for l in range(-maxl, maxl + 1): 368 | if h == 0 and k == 0 and l == 0: 369 | continue 370 | if uc.d((h, k, l)) < dmin: 371 | continue 372 | indices.append((h, k, l)) 373 | return indices 374 | 375 | uc=(${1:5.4307,5.4307,5.4307,90.00,90.0,90.00}) 376 | dmin=${2:1.0} 377 | $0 378 | endsnippet 379 | 380 | snippet computeAllMillerIndicesASU "Compute all possible Miller indices in the ASU." b 381 | from cctbx import miller 382 | import cctbx 383 | from cctbx import crystal 384 | 385 | ms = miller.build_set( 386 | crystal_symmetry=crystal.symmetry( 387 | space_group_symbol="${1:Fd-3m}", 388 | unit_cell=("${2:5.4307,5.4307,5.4307,90.00,90.0,90.00}") ), 389 | anomalous_flag=${3:False}, 390 | d_min=${4:0.4}) 391 | 392 | for hkl in ms.indices(): 393 | print(hkl) 394 | 395 | # map the reflections to the asu and print 396 | 397 | msu = ms.map_to_asu() 398 | [print(hkl2) for hkl2 in msu.indices()] 399 | $0 400 | endsnippet 401 | 402 | snippet computeAllMillerIndicesUnitCell "Build miller indices given unit cell and resolution limit." b 403 | from cctbx import crystal 404 | from cctbx import miller 405 | 406 | ms = miller.build_set( 407 | crystal_symmetry=crystal.symmetry( 408 | space_group_symbol="${1:P4}", 409 | unit_cell=(${2:150.8,150.8,250.4,90.0,90.0,90.0})), 410 | anomalous_flag=${3:False}, 411 | d_min=${4:1.4}) 412 | msu = ms.map_to_asu() 413 | [print(hkl) for hkl in msu.indices()] 414 | print(msu.show_comprehensive_summary()) 415 | $0 416 | endsnippet 417 | 418 | snippet extractReflectionMtzFile "Extract the reflections from a mtz file." b 419 | from iotbx import mtz 420 | mtz_obj = mtz.object(file_name="${1:Users/blaine/manuscripts/RETkinaseLoxo/ret_blu.mtz}") 421 | mtz_obj.show_summary() 422 | $0 423 | endsnippet 424 | 425 | snippet extractReflectionInShell "Extract the reflections in a shell." b 426 | from iotbx import mtz 427 | mtz_obj = mtz.object(file_name="${1:2V89}.mtz") 428 | miller_arrays = mtz_obj.as_miller_arrays() 429 | for miller_array in miller_arrays: 430 | miller_array_truncated = miller_array.resolution_filter(d_min=${2:2}, d_max=${3:5}) 431 | print(miller_array_truncated) 432 | $0 433 | endsnippet 434 | 435 | snippet plotRfactorResolutionBin "Read in a phenix.refine mtz file. It plots the work and free R-factors by resolution bin." b 436 | #!/usr/bin/env python 437 | # coding: utf-8 438 | ''' 439 | This script reads in a phenix.refine mtz file. 440 | It plots the R-factor by resolution bin. 441 | The plots are made with matplotlib using miller arrays. 442 | It also plots the correlation coefficients. 443 | The plots were made with matplotlib. 444 | 445 | This script was adapted from an example script in iotbx: 446 | 447 | Source: https://github.com/cctbx/cctbx_project/blob/master/ 448 | iotbx/examples/recalculate_phenix_refine_r_factors.py 449 | ''' 450 | 451 | 452 | # get_ipython().run_line_magic("matplotlib", "inline") 453 | 454 | from __future__ import absolute_import, division, print_function 455 | from iotbx.reflection_file_utils import get_r_free_flags_scores 456 | from iotbx.file_reader import any_file 457 | import matplotlib 458 | import matplotlib.pyplot as plt 459 | 460 | 461 | 462 | def compute_r_factors(fobs, fmodel, flags): 463 | fmodel, fobs = fmodel.common_sets(other=fobs) 464 | fmodel, flags = fmodel.common_sets(other=flags) 465 | fc_work = fmodel.select(~(flags.data())) 466 | fo_work = fobs.select(~(flags.data())) 467 | fc_test = fmodel.select(flags.data()) 468 | fo_test = fobs.select(flags.data()) 469 | r_work = fo_work.r1_factor(fc_work) 470 | r_free = fo_test.r1_factor(fc_test) 471 | 472 | print("r_work = %.4f" % r_work) 473 | print("r_free = %.4f" % r_free) 474 | print("") 475 | 476 | binner = flags.setup_binner(n_bins=20) 477 | d_star_power = 1.618034 478 | centers = binner.bin_centers(d_star_power) 479 | d_centers = list(centers**(-1 / d_star_power)) 480 | # for i in d_centers: 481 | # print(i) 482 | 483 | fo_work.use_binning_of(flags) 484 | fc_work.use_binner_of(fo_work) 485 | fo_test.use_binning_of(fo_work) 486 | fc_test.use_binning_of(fo_work) 487 | 488 | r_work_list = [] 489 | r_free_list = [] 490 | cc_work_list = [] 491 | cc_free_list = [] 492 | for i_bin in fo_work.binner().range_all(): 493 | sel_work = fo_work.binner().selection(i_bin) 494 | sel_test = fo_test.binner().selection(i_bin) 495 | fo_work_bin = fo_work.select(sel_work) 496 | fc_work_bin = fc_work.select(sel_work) 497 | fo_test_bin = fo_test.select(sel_test) 498 | fc_test_bin = fc_test.select(sel_test) 499 | if fc_test_bin.size() == 0 : continue 500 | 501 | r_work_bin = fo_work_bin.r1_factor(other=fc_work_bin, 502 | assume_index_matching=True) 503 | r_work_list.append(r_work_bin) 504 | 505 | r_free_bin = fo_test_bin.r1_factor(other=fc_test_bin, 506 | assume_index_matching=True) 507 | r_free_list.append(r_free_bin) 508 | 509 | cc_work_bin = fo_work_bin.correlation(fc_work_bin).coefficient() 510 | cc_work_list.append(cc_work_bin) 511 | 512 | cc_free_bin = fo_test_bin.correlation(fc_test_bin).coefficient() 513 | cc_free_list.append(cc_free_bin) 514 | 515 | legend = flags.binner().bin_legend(i_bin, show_counts=False) 516 | print("%s %8d %8d %.4f %.4f %.3f %.3f" % (legend, fo_work_bin.size(), 517 | fo_test_bin.size(), r_work_bin, r_free_bin, cc_work_bin, cc_free_bin)) 518 | 519 | return d_centers, r_work_list, r_free_list, cc_work_list, cc_free_list 520 | 521 | 522 | def plot_r_factors(d_centers, r_work_list, r_free_list): 523 | plt.scatter(d_centers, r_work_list, label=r"$\mathit{R_{work}}$") 524 | plt.scatter(d_centers, r_free_list, label=r"$\mathit{R_{free}}$") 525 | plt.xlabel(r"Resolution ($\mathrm{\AA}$)") 526 | plt.ylabel(r"R-factor (%)") 527 | plt.legend(loc="upper right") 528 | plt.savefig("Rs.pdf") 529 | plt.close() 530 | 531 | 532 | def plot_cc(d_centers, cc_work_list, cc_free_list): 533 | plt.scatter(d_centers, cc_work_list, label=r"$\mathit{CC_{work}}$") 534 | plt.scatter(d_centers, cc_free_list, label=r"$\mathit{CC_{free}}$") 535 | plt.xlabel(r"Resolution ($\mathrm{\AA}$)") 536 | plt.ylabel(r"Correlation Coefficeint Fo vs Fc (%)") 537 | plt.legend(loc="lower right") 538 | plt.savefig("CCs.pdf") 539 | 540 | 541 | def run(input_mtz): 542 | mtz_in = any_file(input_mtz) 543 | ma = mtz_in.file_server.miller_arrays 544 | flags = fmodel = fobs = None 545 | # select the output arrays from phenix.refine. This could easily be modified 546 | # to handle MTZ files from other programs. 547 | for array in ma : 548 | labels = array.info().label_string() 549 | if labels.startswith("R-free-flags"): 550 | flags = array 551 | elif labels.startswith("F-model"): 552 | fmodel = abs(array) 553 | elif labels.startswith("F-obs-filtered"): 554 | fobs = array 555 | if (None in [flags, fobs, fmodel]): 556 | raise RuntimeError("Not a valid phenix.refine output file") 557 | scores = get_r_free_flags_scores([flags], None) 558 | test_flag_value = scores.test_flag_values[0] 559 | flags = flags.customized_copy(data=flags.data()==test_flag_value) 560 | 561 | (d_centers, 562 | r_work_list, 563 | r_free_list, 564 | cc_work_list, 565 | cc_free_list) = compute_r_factors(fobs, fmodel, flags) 566 | plot_r_factors(d_centers, r_work_list, r_free_list) 567 | plot_cc(d_centers, cc_work_list, cc_free_list) 568 | 569 | 570 | if (__name__ == "__main__"): 571 | run(input_mtz="${1:28molrepEdited_5_refine_001}.mtz") 572 | $0 573 | endsnippet 574 | 575 | snippet plotFcalcsrResolutionBin "Example of computing Fcalcs and then plotting them by resolution bin. This script uses miller arrays and binner." b 576 | ''' 577 | This script reads in a phenix.refine mtz file. 578 | It plots the R-factor by resolution bin. 579 | The plots are made with matplotlib using miller arrays. 580 | It also plots the correlation coefficients. 581 | The plots were made with matplotlib. 582 | 583 | This script was adapted from an example script in iotbx: 584 | 585 | Source: https://github.com/cctbx/cctbx_project/blob/master/ 586 | iotbx/examples/recalculate_phenix_refine_r_factors.py 587 | ''' 588 | 589 | 590 | # get_ipython().run_line_magic("matplotlib", "inline") 591 | 592 | from __future__ import absolute_import, division, print_function 593 | from iotbx.reflection_file_utils import get_r_free_flags_scores 594 | from iotbx.file_reader import any_file 595 | import matplotlib 596 | import matplotlib.pyplot as plt 597 | 598 | 599 | 600 | def compute_r_factors(fobs, fmodel, flags): 601 | fmodel, fobs = fmodel.common_sets(other=fobs) 602 | fmodel, flags = fmodel.common_sets(other=flags) 603 | fc_work = fmodel.select(~(flags.data())) 604 | fo_work = fobs.select(~(flags.data())) 605 | fc_test = fmodel.select(flags.data()) 606 | fo_test = fobs.select(flags.data()) 607 | r_work = fo_work.r1_factor(fc_work) 608 | r_free = fo_test.r1_factor(fc_test) 609 | 610 | print("r_work = %.4f" % r_work) 611 | print("r_free = %.4f" % r_free) 612 | print("") 613 | 614 | binner = flags.setup_binner(n_bins=20) 615 | d_star_power = 1.618034 616 | centers = binner.bin_centers(d_star_power) 617 | d_centers = list(centers**(-1 / d_star_power)) 618 | # for i in d_centers: 619 | # print(i) 620 | 621 | fo_work.use_binning_of(flags) 622 | fc_work.use_binner_of(fo_work) 623 | fo_test.use_binning_of(fo_work) 624 | fc_test.use_binning_of(fo_work) 625 | 626 | r_work_list = [] 627 | r_free_list = [] 628 | cc_work_list = [] 629 | cc_free_list = [] 630 | for i_bin in fo_work.binner().range_all(): 631 | sel_work = fo_work.binner().selection(i_bin) 632 | sel_test = fo_test.binner().selection(i_bin) 633 | fo_work_bin = fo_work.select(sel_work) 634 | fc_work_bin = fc_work.select(sel_work) 635 | fo_test_bin = fo_test.select(sel_test) 636 | fc_test_bin = fc_test.select(sel_test) 637 | if fc_test_bin.size() == 0 : continue 638 | 639 | r_work_bin = fo_work_bin.r1_factor(other=fc_work_bin, 640 | assume_index_matching=True) 641 | r_work_list.append(r_work_bin) 642 | 643 | r_free_bin = fo_test_bin.r1_factor(other=fc_test_bin, 644 | assume_index_matching=True) 645 | r_free_list.append(r_free_bin) 646 | 647 | cc_work_bin = fo_work_bin.correlation(fc_work_bin).coefficient() 648 | cc_work_list.append(cc_work_bin) 649 | 650 | cc_free_bin = fo_test_bin.correlation(fc_test_bin).coefficient() 651 | cc_free_list.append(cc_free_bin) 652 | 653 | legend = flags.binner().bin_legend(i_bin, show_counts=False) 654 | print("%s %8d %8d %.4f %.4f %.3f %.3f" % (legend, fo_work_bin.size(), 655 | fo_test_bin.size(), r_work_bin, r_free_bin, cc_work_bin, cc_free_bin)) 656 | 657 | return d_centers, r_work_list, r_free_list, cc_work_list, cc_free_list 658 | 659 | 660 | def plot_r_factors(d_centers, r_work_list, r_free_list): 661 | plt.scatter(d_centers, r_work_list, label=r"$\mathit{R_{work}}$") 662 | plt.scatter(d_centers, r_free_list, label=r"$\mathit{R_{free}}$") 663 | plt.xlabel(r"Resolution ($\mathrm{\AA}$)") 664 | plt.ylabel(r"R-factor (%)") 665 | plt.legend(loc="upper right") 666 | plt.savefig("Rs.pdf") 667 | plt.close() 668 | 669 | 670 | def plot_cc(d_centers, cc_work_list, cc_free_list): 671 | plt.scatter(d_centers, cc_work_list, label=r"$\mathit{CC_{work}}$") 672 | plt.scatter(d_centers, cc_free_list, label=r"$\mathit{CC_{free}}$") 673 | plt.xlabel(r"Resolution ($\mathrm{\AA}$)") 674 | plt.ylabel(r"Correlation Coefficeint Fo vs Fc (%)") 675 | plt.legend(loc="lower right") 676 | plt.savefig("CCs.pdf") 677 | 678 | 679 | def run(input_mtz): 680 | mtz_in = any_file(input_mtz) 681 | ma = mtz_in.file_server.miller_arrays 682 | flags = fmodel = fobs = None 683 | # select the output arrays from phenix.refine. This could easily be modified 684 | # to handle MTZ files from other programs. 685 | for array in ma : 686 | labels = array.info().label_string() 687 | if labels.startswith("R-free-flags"): 688 | flags = array 689 | elif labels.startswith("F-model"): 690 | fmodel = abs(array) 691 | elif labels.startswith("F-obs-filtered"): 692 | fobs = array 693 | if (None in [flags, fobs, fmodel]): 694 | raise RuntimeError("Not a valid phenix.refine output file") 695 | scores = get_r_free_flags_scores([flags], None) 696 | test_flag_value = scores.test_flag_values[0] 697 | flags = flags.customized_copy(data=flags.data()==test_flag_value) 698 | 699 | (d_centers, 700 | r_work_list, 701 | r_free_list, 702 | cc_work_list, 703 | cc_free_list) = compute_r_factors(fobs, fmodel, flags) 704 | plot_r_factors(d_centers, r_work_list, r_free_list) 705 | plot_cc(d_centers, cc_work_list, cc_free_list) 706 | 707 | 708 | if (__name__ == "__main__"): 709 | run(input_mtz="${1:28molrepEdited_5_refine_001}.mtz") 710 | endsnippet 711 | 712 | snippet plotIntensityResolutionBin "Miller arrays to plot of bin mean intensity over dstar" b 713 | from iotbx.file_reader import any_file 714 | import matplotlib.pyplot as plt 715 | 716 | f = any_file("${1:/Users/blaine/manuscripts/RETkinaseLoxo/ret_blu.mtz}") 717 | 718 | print(f.file_type) 719 | f.show_summary() 720 | miller_arrays = f.file_server.miller_arrays 721 | iobs = miller_arrays[3] 722 | flags = miller_arrays[0] 723 | iobs, flags = iobs.common_sets(other=flags) 724 | iobsData = iobs.data() 725 | list(iobsData[100:110]) 726 | iobs.show_comprehensive_summary() 727 | # iobs.binner() 728 | n_bins = ${2:20} 729 | binner = iobs.setup_binner(n_bins=n_bins) 730 | binner.show_summary() 731 | 732 | used = list(binner.range_used()) 733 | selections = [binner.selection(i) for i in used] 734 | means = [iobs.select(sel).mean() for sel in selections] 735 | 736 | from math import log 737 | lnmeans = [log(y) for y in means] 738 | 739 | d_star_power = 1.618034 740 | centers = binner.bin_centers(d_star_power) 741 | d_centers = list(centers**(-1 / d_star_power)) 742 | d_centers 743 | 744 | # plt.ylabel("Natural log of the amplitudes squared") 745 | # plt.xlabel(r"$\textrm{d^*}$ in $\textrm{\AA}$") 746 | # ax.set_xlim(35, 1.5) 747 | # plt.scatter(d_centers,lnmeanss) 748 | 749 | fig, ax = plt.subplots() 750 | ax.scatter(d_centers,lnmeans) 751 | ax.set_xlim(${3:8}, ${4:1.5}) # decreasing 752 | ax.set_xlabel(r"$d^*$ in $\AA$") 753 | ax.set_ylabel("Natural log of the intensities") 754 | ax.grid(False) 755 | plt.savefig("${5:iobsvsdstar}.pdf") 756 | $0 757 | endsnippet 758 | 759 | snippet cns2mtz "Miller arrays to convert CNS reflection file into an mtz file" b 760 | from iotbx import reflection_file_reader 761 | import os 762 | reflection_file = reflection_file_reader.any_reflection_file(file_name=os.path.expandvars("${1:\$CNS_SOLVE/doc/html/tutorial/data/pen/scale.hkl}")) 763 | from cctbx import crystal 764 | crystal_symmetry = crystal.symmetry( unit_cell=(${2:97.37, 46.64, 65.47, 90, 115.4, 90}), space_group_symbol="${3:C2}") 765 | miller_arrays = reflection_file.as_miller_arrays( crystal_symmetry=crystal_symmetry) 766 | mtz_dataset = None 767 | for miller_array in miller_arrays: 768 | if (mtz_dataset is None): 769 | mtz_dataset = miller_array.as_mtz_dataset( 770 | column_root_label=miller_array.info().labels[0]) 771 | else: 772 | mtz_dataset.add_miller_array( 773 | miller_array=miller_array, 774 | column_root_label=miller_array.info().labels[0]) 775 | mtz_object = mtz_dataset.mtz_object() 776 | mtz_object.show_summary() 777 | $0 778 | endsnippet 779 | 780 | snippet FsigmaFbyabsLindex "L-plot" b 781 | import pandas as pd 782 | ''' 783 | Use pandas to read in a hkl file with whitespace separators into a dataframe. 784 | Append to the dataframe a column with F/sigmaF values. 785 | Append to the dataframe a column with the absolute value of the L indices. 786 | Average F/sigmaF by absL index. 787 | Write to absL and F/sigmaF to csv file. 788 | ''' 789 | mtzdata = pd.read_csv("${1:1524start}.hkl", names=["H","K","L",${2:"F","SIGF"}], sep="\s+") 790 | mtzdata["FovSigF"] = mtzdata.apply(lambda row: row["F"] / row["SIGF"], axis=1) 791 | mtzdata["absL"] = mtzdata.apply(lambda row: abs(row["L"]), axis=1) 792 | FovSigFabsL = mtzdata.groupby([mtzdata.absL]).FovSigF.mean() 793 | FovSigFabsL.to_csv("${3:test2}.csv") 794 | $0 795 | endsnippet 796 | 797 | snippet changeMtzColumns "Read in mtz file and write out with fewer columns." b 798 | from iotbx.reflection_file_reader import any_reflection_file 799 | hkl_in = any_reflection_file("${1:/Users/blaine/manuscripts/RETkinaseLoxo/ret_blu.mtz}") 800 | 801 | miller_arrays = hkl_in.as_miller_arrays() 802 | 803 | i_obs = miller_arrays[3] 804 | r_free_flags = miller_arrays[0] 805 | f_obs = i_obs.f_sq_as_f() 806 | 807 | mtz_dataset = i_obs.as_mtz_dataset(column_root_label="I") 808 | mtz_dataset.add_miller_array(f_obs, column_root_label="F") 809 | mtz_dataset.add_miller_array(r_free_flags,column_root_label="${2:FreeR_flag}") 810 | mtz_dataset.mtz_object().write("${3:loxodata.mtz}") 811 | $0 812 | endsnippet 813 | 814 | snippet normalizedStructureFactors "Calculate quasi-normalized structure factor." b 815 | all_e_values = miller_array.quasi_normalize_structure_factors().sort(by_value="data") 816 | $0 817 | endsnippet 818 | 819 | snippet readMtzFile "Read in a mtz file into a Miller array with iotbx.file_reader." b 820 | from iotbx.file_reader import any_file 821 | mtz_in = any_file("${1:data}.mtz", force_type="mtz") 822 | miller_arrays = mtz_in.file_server.miller_arrays 823 | $0 824 | endsnippet 825 | 826 | snippet pattersonContourMap "Read in a mtz file with iotbx.file_reader." b 827 | import numpy 828 | from matplotlib import pyplot 829 | import gemmi 830 | # https://gemmi.readthedocs.io/en/latest/grid.html 831 | ccp4 = gemmi.read_ccp4_map("${1:/Users/blaine/4bqrPatterson.ccp4}") 832 | ccp4.setup() 833 | arr = numpy.array(ccp4.grid, copy=False) 834 | x = numpy.linspace(0, ccp4.grid.unit_cell.a, num=arr.shape[0], endpoint=False) 835 | y = numpy.linspace(0, ccp4.grid.unit_cell.b, num=arr.shape[1], endpoint=False) 836 | X, Y = numpy.meshgrid(x, y, indexing="ij") 837 | pyplot.rcParams["figure.figsize"] = (8.0, 8.0) 838 | pyplot.contour(X, Y, arr[:,:,0],500, zorder=1,linestyles="solid") 839 | pyplot.gca().set_aspect("equal", adjustable="box") 840 | pyplot.show() 841 | 842 | arr2 = numpy.array(ccp4.grid, copy=False) 843 | x = numpy.linspace(0, ccp4.grid.unit_cell.a, num=arr2.shape[0], endpoint=False) 844 | z = numpy.linspace(0, ccp4.grid.unit_cell.c, num=arr2.shape[1], endpoint=False) 845 | X, Z = numpy.meshgrid(x, z, indexing="ij") 846 | pyplot.rcParams["figure.figsize"] = (4.0, 20.5) 847 | pyplot.contour(X, Z, arr[:,:,0],500, zorder=1, linestyles="solid") 848 | pyplot.gca().set_aspect("equal", adjustable="box") 849 | pyplot.savefig("patterson.png", dpi=600) 850 | pyplot.show() 851 | $0 852 | endsnippet 853 | 854 | snippet condaInstall2 "The conda commands to remove old env and create a new one for cctbx. These commands need to be run on the command line." b 855 | conda remove --name cctbx${1:37} 856 | conda create -n ${2:cctbx38} -c conda-forge cctbx-base python=${4:3.8} 857 | conda activate ${2:cctbx38} 858 | conda install -c conda-forge cctbx-base 859 | conda install -c anaconda ipykernel 860 | python -m ipykernel install --user --name ${2:cctbx38} --display-name "${2:cctbx38}" 861 | $0 862 | endsnippet 863 | 864 | snippet eigenvalues "The commands to find the eigenvalues and eigenvectors on a tensor. The code is from a post to cctbxbb on 10 December 2020 by Richard Gildea in a reply to Robert Oeffner about code in cctbx for finding eigenvalues and eigenvectors. Robert was requesting the analog in cctbx to scipy.linalg.eig." b 865 | from scitbx.array_family import flex; 866 | from scitbx.linalg import eigensystem; 867 | m = flex.double(($1:-2, -4, 2, -2, 1, 2, 4, 2, 5})); 868 | m.reshape(flex.grid(3,3)); 869 | es = eigensystem.real_symmetric(m); 870 | list(es.values()); 871 | list(es.vectors()); 872 | $0 873 | endsnippet 874 | 875 | snippet IpIm "Scatter plot of I(+) and (I(-). The presence of an anomalous signal is indicated by deviations from x=y." b 876 | %matplotlib inline 877 | import matplotlib.pyplot as plt 878 | import matplotlib as mpl 879 | import matplotlib.ticker as ticker 880 | from matplotlib.ticker import MultipleLocator #, FormatStrFormatter 881 | from matplotlib.ticker import FuncFormatter 882 | from iotbx.reflection_file_reader import any_reflection_file 883 | 884 | # >>> change the mtz file name 885 | hkl_file = any_reflection_file("${1:3hz7}.mtz") 886 | miller_arrays = hkl_file.as_miller_arrays(merge_equivalents=False) 887 | Iobs = miller_arrays[1] 888 | i_plus, i_minus = Iobs.hemispheres_acentrics() 889 | ipd = i_plus.data() 890 | ip=list(ipd) 891 | imd = i_minus.data() 892 | im = list(imd) 893 | len(im) 894 | 895 | comma_fmt = FuncFormatter(lambda x, p: format(int(x), ",")) 896 | 897 | mpl.rcParams["savefig.dpi"] = 600 898 | mpl.rcParams["figure.dpi"] = 600 899 | 900 | # Set to width of a one column on a two-column page. 901 | # May want to adjust settings for a slide. 902 | fig, ax = plt.subplots(figsize=[3.25, 3.25]) 903 | ax.scatter(ip,im,c="k",alpha=0.3,s=5.5) 904 | ax.set_xlabel(r"I(+)",fontsize=12) 905 | ax.set_ylabel(r"I(-)",fontsize=12) 906 | ax.xaxis.set_major_locator(MultipleLocator(50000.)) 907 | ax.yaxis.set_major_locator(MultipleLocator(50000.)) 908 | ax.get_xaxis().set_major_formatter(comma_fmt) 909 | ax.get_yaxis().set_major_formatter(comma_fmt) 910 | 911 | plt.xticks(fontsize=12) 912 | plt.yticks(fontsize=12) 913 | ax.grid(False) 914 | 915 | # >>> change name of the figure file 916 | plt.savefig("${1:3hz7}IpIm.pdf",bbox_inches="tight") 917 | $0 918 | endsnippet 919 | 920 | snippet fetchFASTA "Fetch fasta file from RCSB." b 921 | from iotbx.pdb.fetch import get_pdb 922 | import sys 923 | get_pdb(id="3nd4",data_type="pdb", mirror="rcsb", format="pdb", log=sys.stdout) 924 | $0 925 | endsnippet 926 | 927 | snippet fetchXrayCif "Fetch X-ray data from RCSB in mmCIF format." b 928 | from iotbx.pdb.fetch import get_pdb 929 | import sys 930 | get_pdb(id="${1:3nd4}",data_type="xray", mirror="rcsb", format="cif", log=sys.stdout) 931 | $0 932 | endsnippet 933 | 934 | snippet fetchAtomicCif "Fetch atomic coordinates from RCSB in mmCIF format." b 935 | from iotbx.pdb.fetch import get_pdb 936 | import sys 937 | get_pdb(id="${1:3nd4}",data_type="xray", mirror="rcsb", format="cif", log=sys.stdout) 938 | $0 939 | endsnippet 940 | 941 | snippet symmetryFromPDB "Print the symmetry from a PDB file." b 942 | import iotbx 943 | iotbx.pdb.crystal_symmetry_from_pdb.extract_from("${1:3nd4}.pdb") 944 | $0 945 | endsnippet 946 | 947 | snippet makeMaps "Read in mtz and pdb file and write map coefficients to a separate mtz file." b 948 | from mmtbx.maps.utils import create_map_from_pdb_and_mtz 949 | '''The phenix.maps commandline tool is the recommended approach.''' 950 | id="${1:3nd4}" 951 | create_map_from_pdb_and_mtz( 952 | pdb_file="%s.pdb" % id, 953 | mtz_file="%s.mtz" % id, 954 | output_file="%s_maps.mtz" % id, 955 | fill=False, 956 | out=None, 957 | llg_map=False, 958 | remove_unknown_scatterering_type=True, 959 | assume_pdb_data=False) 960 | $0 961 | endsnippet 962 | 963 | snippet testCCTBX "Enter this snippet on the command line in an empty directory." b 964 | libtbx.run_tests_parallel module=libtbx module=cctbx nproc=${1:6} 965 | $0 966 | endsnippet 967 | 968 | snippet condaInstall4Ununtu "Enter this snippet on the command line in an empty directory." b 969 | apt install nodejs git 970 | wget https://repo.anaconda.com/archive/${1:Anaconda3-2020.02-Linux-x86_64.sh} 971 | bash ${1:Anaconda3-2020.02-Linux-x86_64.sh} 972 | conda create -n ${2:pc37} python=3.7 schrodinger::pymol-bundle=2.4.1 conda-forge::cctbx-base conda-forge::jupyter 973 | conda activate ${2:pc37} 974 | conda install conda-forge::jupyterlab=2.2.0 975 | # The following may be needed 976 | # jupyter serverextension enable --py jupyterlab --user 977 | pip install jupyterlab-snippets-multimenus 978 | jupyter lab build 979 | # Might be needed 980 | # jupyter lab clean 981 | jupyter --path # select the top option under Data for storing the libraries 982 | cd ~/.local/share/jupyter # change as per output from prior line 983 | mkdir multimenus_snippets 984 | cd multimenus_snippets 985 | git clone https://github.com/MooersLab/juptyerlabpymolcctbx.git cctbx 986 | git clone https://github.com/MooersLab/juptyerlabpymolcctbxplus.git cctbx+ 987 | git clone https://github.com/MooersLab/juptyerlabpymolpysnips.git pymol 988 | git clone https://github.com/MooersLab/juptyerlabpymolpysnipsplus.git pymol+ 989 | jupyter lab # or libtbx.python -m jupyter-lab 990 | $0 991 | endsnippet 992 | 993 | snippet condaListEnvs "List the currently available envs. The bang (!) enables running this command in a Juptyer Notebook. Delete the bang to run the command in the terminal." b 994 | !conda env list 995 | endsnippet 996 | 997 | snippet condaRemoveEnv "Remove a specified env. The bang (!) enables running this command in a Juptyer Notebook. Delete the bang to run the command in the terminal." b 998 | !conda env remove --name cctbx37 999 | endsnippet 1000 | 1001 | snippet condaInstallCCTBXInsidePyMOL "Install cctbx inside PyMOL. This protocol worked on a Mac OS." b 1002 | # At the PyMOL prompt in the PyMOL GUI paste the following: 1003 | conda install conda-forge::cctbx-base conda-forge::jupyter 1004 | conda install conda-forge::jupyterlab=2.2.0 1005 | conda install conda-forge::cctbx-base 1006 | # In a terminal 1007 | /Applications/PyMOL.app/Contents/bin/jupyter serverextension enable --py jupyterlab --user 1008 | /Applications/PyMOL.app/Contents/bin/ipython kernel install --name pymol --user 1009 | /Applications/PyMOL.app/Contents/bin/pip install jupyterlab-snippets-multimenus 1010 | /Applications/PyMOL.app/Contents/bin/jupyter lab build 1011 | /Applications/PyMOL.app/Contents/bin/jupyter lab clean 1012 | /Applications/PyMOL.app/Contents/bin/jupyter --path # select the top option under Data for storing the libraries 1013 | cd ~.local/share/jupyter # change as per output from prior line 1014 | mkdir multimenus_snippets 1015 | cd multimenus_snippets 1016 | git clone https://github.com/MooersLab/juptyerlabpymolcctbx.git cctbx 1017 | git clone https://github.com/MooersLab/juptyerlabpymolcctbxplus.git cctbx+ 1018 | git clone https://github.com/MooersLab/juptyerlabpymolpysnips.git pymol 1019 | git clone https://github.com/MooersLab/juptyerlabpymolpysnipsplus.git pymol+ 1020 | /Applications/PyMOL.app/Contents/bin/ipython kernel install --name pymol37 --user 1021 | $0 1022 | endsnippet 1023 | 1024 | snippet testCCTBXpython38 "Bash script to test new installation of cctbx with Python3.7 in a conda env." b 1025 | #! /bin/sh 1026 | set noglob 1027 | set verbose 1028 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/libtbx/run_tests.py 1029 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/iotbx/run_tests.py 1030 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/boost_adptbx/run_tests.py 1031 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/fable/run_tests.py 1032 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/scitbx/run_tests.py 1033 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/cctbx/run_tests.py 1034 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/cctbx/run_examples.py 1035 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/smtbx/run_tests.py 1036 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/cflib_adaptbx/run_tests.py 1037 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/reduce/run_tests.py 1038 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/mmtbx/run_tests.py 1039 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/cctbx_website/run_tests.py 1040 | libtbx.python $CONDA_PREFIX/lib/python3.8/site-packages/gltbx/run_tests.py 1041 | endsnippet 1042 | 1043 | snippet testCCTBXpython37 "Bash script to test new installation of cctbx with Python3.8 in a conda env." b 1044 | #! /bin/sh 1045 | set noglob 1046 | set verbose 1047 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/libtbx/run_tests.py 1048 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/iotbx/run_tests.py 1049 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/boost_adptbx/run_tests.py 1050 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/fable/run_tests.py 1051 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/scitbx/run_tests.py 1052 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/cctbx/run_tests.py 1053 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/cctbx/run_examples.py 1054 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/smtbx/run_tests.py 1055 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/cflib_adaptbx/run_tests.py 1056 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/reduce/run_tests.py 1057 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/mmtbx/run_tests.py 1058 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/cctbx_website/run_tests.py 1059 | libtbx.python $CONDA_PREFIX/lib/python3.7/site-packages/gltbx/run_tests.py 1060 | endsnippet 1061 | 1062 | snippet gemmiInstall "Command to install gemmi (https://github.com/project-gemmi/gemmi). Documentation is located here (https://gemmi.readthedocs.io/en/latest/install.html)." b 1063 | # Install from PyPi 1064 | pip install gemmi 1065 | # OR install the latest version directly from github. 1066 | pip install git+https://github.com/project-gemmi/gemmi.git 1067 | endsnippet 1068 | 1069 | snippet fixPermissionsOnMacSDK "Fix permission on MacOS SDK. Adjust the version number of the sdk as needed." b 1070 | cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/ 1071 | sudo ln -s MacOSX.sdk MacOSX10.15.sdk 1072 | endsnippet 1073 | 1074 | snippet averageB "Print the average B factor for all atoms." b 1075 | from iotbx import pdb 1076 | pdb_name = '~/${1:Downloads/4RBQ}.pdb' 1077 | pdb_inp = pdb.input(file_name=pdb_name) 1078 | atoms = pdb_inp.atoms() 1079 | bfactors = atoms.extract_b() 1080 | bfactors.format_mean("%6.2f Ang.^2") 1081 | $0 1082 | endsnippet 1083 | 1084 | snippet testCCTBXpython39 "Bash script to test new installation of cctbx with Python3.9 in a conda env." b 1085 | #! /bin/sh 1086 | set noglob 1087 | set verbose 1088 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/libtbx/run_tests.py 1089 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/iotbx/run_tests.py 1090 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/boost_adptbx/run_tests.py 1091 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/fable/run_tests.py 1092 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/scitbx/run_tests.py 1093 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/cctbx/run_tests.py 1094 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/cctbx/run_examples.py 1095 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/smtbx/run_tests.py 1096 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/cflib_adaptbx/run_tests.py 1097 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/reduce/run_tests.py 1098 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/mmtbx/run_tests.py 1099 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/cctbx_website/run_tests.py 1100 | libtbx.python $CONDA_PREFIX/lib/python3.9/site-packages/gltbx/run_tests.py 1101 | endsnippet 1102 | 1103 | snippet testCCTBXpython310 "Bash script to test new installation of cctbx with Python3.10 in a conda env." b 1104 | #! /bin/sh 1105 | set noglob 1106 | set verbose 1107 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/libtbx/run_tests.py 1108 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/iotbx/run_tests.py 1109 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/boost_adptbx/run_tests.py 1110 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/fable/run_tests.py 1111 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/scitbx/run_tests.py 1112 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/cctbx/run_tests.py 1113 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/cctbx/run_examples.py 1114 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/smtbx/run_tests.py 1115 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/cflib_adaptbx/run_tests.py 1116 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/reduce/run_tests.py 1117 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/mmtbx/run_tests.py 1118 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/cctbx_website/run_tests.py 1119 | libtbx.python $CONDA_PREFIX/lib/python3.10/site-packages/gltbx/run_tests.py 1120 | endsnippet 1121 | 1122 | snippet testCCTBXpython311 "Bash script to test new installation of cctbx with Python3.11 in a conda env." b 1123 | #! /bin/sh 1124 | set noglob 1125 | set verbose 1126 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/libtbx/run_tests.py 1127 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/iotbx/run_tests.py 1128 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/boost_adptbx/run_tests.py 1129 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/fable/run_tests.py 1130 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/scitbx/run_tests.py 1131 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/cctbx/run_tests.py 1132 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/cctbx/run_examples.py 1133 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/smtbx/run_tests.py 1134 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/cflib_adaptbx/run_tests.py 1135 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/reduce/run_tests.py 1136 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/mmtbx/run_tests.py 1137 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/cctbx_website/run_tests.py 1138 | libtbx.python $CONDA_PREFIX/lib/python3.11/site-packages/gltbx/run_tests.py 1139 | endsnippet 1140 | 1141 | --------------------------------------------------------------------------------