Introduction
|
You can assign the values of several variables at once.
Multiple values can be stored togeother in a list, which is ordered, or a dictionary, which is not ordered.
|
File Parsing
|
Indentation is very important in for loops and if statements. Don’t forget the : and to indent the items in the loop.
You should use the os.path module to work with file paths.
One of the most flexible ways to read in the lines of a file is the readlines() function.
An if statement can be used to find a particular string within a file.
The split() function can be used to seperate the elements of a string.
You will often need to recast data into a different data type when it was read in as a string.
|
Processing Multiple Files and Writing Files
|
Use the glob function in the python library glob to find all the files you want to analyze.
You can have multiple for loops nested inside each other.
Python can only print strings to files.
Don’t forget to close files so python will actually write them.
|
Working with Tabular Data
|
If you are reading in a file that is mostly numerical data, there are better ways to read in the data than using readlines() .
The notation to refer to a particular element of an array is array_name[row,column] .
Typically, you should not write a function to perform a standard math operation. The function probably already exists in numpy .
|
Plotting and Data Visualization
|
The matplotlib library is the most commonly used plotting library.
You can import libraries with shorthand names.
You can save a figure with the savefig command.
Matplotlib is highly customizable. You can change the style of your plot, and there are many kinds of plots.
|
Writing Functions
|
Functions make your code easier to read, more reuseable, more portable, and easier to test.
If a function returns True or False, you can use it in an if statement as a condition.
|
The Atomic Simulation Environment: Python for Chemistry
|
The ASE can be used to read, write and manipulate most common chemical formats.
Calculators in ASE interface with a variety of compuational chemistry programs.
Because the ASE is in python, we can use it to do a chemical calculation and use other python modules (e.g. numpy, matplotlib) to use the results of calculations.
|