Biophysics lab notes
The notebooks in this repository are meant as notes on topics relevant to my PhD either:
- Directly such as the crystallography, FT, eigenvalues of rotation and data reduction topics
- Or indirectly as topics mentioned/assumed in litature which I have read in an attempt to answer research questions
They can be rendered online using nbviewer by clicking the links provided below or alternatively they can be downloaded from the repository homepage and run/edited locally with ipython using the notebook option.
- Series and transforms stuff
- Linear Algebra/ Numerical analysis
- Determinant calculation and matrix inversion with symbolic algebra
- Gauss-Jordan elimination, Gaussian elimination, LU decomposition, Gauss-Seidel, Jacobi method
- Eigenvectors and eigenvalues
- Vector projections and Gram Schmidt orthogonalisation
- QR decomposition, Householder reductions, Givens transformations
- Mathematical optimisation
- Dimensionality reduction and machine learning
- Basic I/O functionality
- Crystallography
- Structure factor calculation by direct summation
- Structure factor calculation in CCTBX explained
- Density sampling
- The reciprocal lattice and metric tensor
- Point group, space group and reciprocal space symmertry
- DRAFT: Intuition of structure factors as projections of 1D electron density
- DRAFT: Investigating 'signature reflections' using a 1D toy system
- How to import CCTBX in iPython
- How to install Soleil's FoxTrot
- Physics
- Other random mathsy notes
- Biochemistry
Python standard library examples
After having rewritten a program several times after finding more elegant ways to do the same thing, I decided it would be a worthwhile investment to properly explore the full standard library. I have therefore written these scripts as short how-to examples/recipes/demos/reference notes for myself on modules in the standard library. All code is my own.
- C/C++ python extensions (python-dev should be installed)
- distutils: my wrapper to build library files via a templated script which executes distutil setup functionality
- distutils (basic): basic c/c++ python extension library building functionality
- api_example.c: simple importable (wrapped) c functions, dynamic memory allocolation, reference counting
- GUI programming with Tkinter
- Tkinter 1: 3 very basic GUIs, Labels, fonts, images; Frames; Buttons; binding event handlers to widgets and messages, use PIL for images
- Tkinter 2: Menus, toolbars, statusbars, dialog, and data input
- Tkinter 3: File opening/saving dialog, hack to suppress an error message on mac
- Tkinter 4: Bitmap buttons, custom LargeTextButton widget class
- Tkinter 5: Top level/ pop-up windows, nested event loops
- Tkinter 6: Gridded widgets (calculator app)
- Tkinter 7: Checkbutton widgets (text2int app)
- Tkinter 8: Radiobutton widgets, with shared variables (text2int app)
- Tkinter 9: Canvas widgets
- Tkinter 10: Drag and drop canvas
- Tkinter 11: Text widget, (web reader app)
- Tkinter 12: LabelFrame, Scrollbar, Listbox widget & self updating/auto recall
- Tkinter 13: Scrollbar and setting window size
- ttk 1: Progressbar widgets and auto recall
- ttk 2: Treeview (file system reader app)
- ttk 3: Notebook, hack to get scrollbar to work in tabs (ScrollCanvasPage class) Note: Use Apple's default python (built with Clang) when running the Tkinter GUI, since the Tkinter module in the anaconda intsall make the GUIs look like they do on Linux!
- Multi-threading and queues
- thread: run two+ thrads in unison
- threading1: download files, carry out calculations in background, the Thread class, logging
- threading2: communicate between slave/main threads with a Queue, and detect KeyboardInterrupt
- threading3: same as above but dynamically allocate jobs
- Servers and sockets and CGI programming
- socket1: listens and talks to socket2, try/finally construct usage
- socket2: talks and listens to socket1
- cgi1: user input form and reply uses example.html
- cgi2: more complex user input/reply (HKL2resolution app) uses example2.html and example2.reply.html
- HTTPServer: set up HTTPServer on localhost to run CGI scripts from All cgi scripts should be placed in a cgi-bin directory and made executable. HTTPSever and HTML templates are one directory up from cgi-bin. After running server open the HTML files in firefox at <ipaddress>:<port>/example.html
- Regex, string manipulation
- re: lots and lots of regular expression examples
- unicodedata: read/print the unicode symbols to the terminal
- string: old/new formatting sub-languages, template strings
-
textwrap: useful only for dedent
- Curses (coloured printing to terminal) and pprint
- Readng HTML and downloading etc
- HTMLParser1: basic use of HTMLParser class to read website data (e.g. download and pull out the IUCR index neatly)
- HTMLParser2: more handles, connects to a CGI script on the localhost
- xml: Parses example.xml using SAX or DOM handlers
- urlib: very basic (download a PDB file) see also Tkinter11 for more complicated use
- Useful functions and classes
- collections: including defaultdict, Counter, namedtuple, OrderedDict (download stock trading info), some custom subclasses
- itertools1: clever functions such as takewhile, groupby and compress
- itertools2: combinations etc.
- functools1: partial functions
- functools2: decorators
- functools3: total ordering
- operator: maths operators as functions
- copy: including deepcopy for list of lists.
- Data and persistence
- Math/sorting
- cmath: complex math
- random: psudeo-random numbers and distributions
- fractions: floats as fractions using limit_denominator, GCD calculation
- decimal: decimal floating point numbers rather than binary floating point
- set: built-in set methods
- bisect: sort algorithm if appending and resorting
- heapq: sort algorithm
- System and OS tools
- sys: interpretter parameters
- os1: environmental variables, functions similar to shutil, nice, change creation time parameters etc.
- os2: watch a process (given by process ID) and report on status
- os3: walk down a file tree (2 implementations)
- os4: OS specific path manipultaion, size of file
- subprocess: spawn subprocesses from shell capturing stdout and stderr
- shutil: access functions like mv, rm, cp etc.
- glob: use wildcards when searching file directory (e.g. *.py file sizes)
- psutils: monitor system usage (3rd party)
- CLI mode
- Coding tools
- inspect: inspect different levels of the stack (e.g. before functions are called) or inspect object properties (e.g. function arguments) not as elegant as traceback2
- traceback1: parse a function call without regex, not as elegant as given in traceback2 or inspect
- traceback2: parse function call with regex
- doctest: Test examples (e.g. factorial) in doc strings
- rlcompleter: use with readline to get IPython like tab completion
- readline: same as above with vim-like raw input
- imp: import modules by filename, warning suppression using with context manager
- profile: time code (bisect vs. built-in sort)
- Logging and warnings
- Time and date
- Other: run command files, HOWTOs
- vim commands: custom syntax, copy from clipboard, hardcopy printing, etc.
- bash commands: file/os level management in bash
- .vimrc: clever indenting, statusbar formatting, printer setup
- .pythonrc: my mac PYTHONSTARTUP file using colour printing display hook with rebound REPL
- Sphinx compatible docstrings (external)