Libraries#
Creating our own functions can be useful and fun, but others may have already written them and made them available through libraries. There are many different Python libraries available. So, for most of the time, we will use functions that others have written.
Importing Libraries#
We need to import
libraries before we can use them. Importing a library means loading it into the memory so it is there when we need to work with it.
We use convenient naming to access them. The library name is followed by as
, the name following is used as the local name. E.g. we write pd.command
instead of pandas.command
every time we need to use it.
import os
import numpy as np
import pandas as pd
Using Modules#
Libraries usually contain lots of modules that themselves contain several functions.
For example, the commonly used matplotlib library (which is used for creating static, animated, and interactive visualizations), has a pyplot
module (which is a state-based interface to matplotlib). We can choose to only import this module.
Another example is the optimize
module with the curve_fit
function (which is used for non-linear least-squares fitting) from the SciPy library (which is used for scientific and technical computing). To only import this function, we can use the from
construct.
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
Examples and Documentation#
OS to interact with the operating system.
NumPy is the linear algebra library for scientific computing.
Matplotlib is a commonly used plotting library.
Pandas to import data from, for example, an Excel file and to create a DataFrame. Its ease of use makes it ideal to work with large data sets.
Differential equations and curve-fitting are solved in Python with the SciPy package.
SciKit-Learn for machine learning.
nglview for interactive molecular graphics.
OpenMM for molecular dynamic simulations.
MDAnalysis to analyze trajectories from molecular dynamics simulations.
Kinetics to model multi-enzyme reactions with uncertainty
…