Download Python Code

Links to Python code appear in various locations on this website. One way to  use the code is to scroll down the page that displays it, and click View Raw in the lower-right corner. Thereafter, copy & paste the code into your Python editor. The page you are now viewing offers a more efficient way to download more code at once. Below you will find several zip-files, each with a collection of files that are posted on this website. I gently recommend that you use the free community version of PyCharm to edit & run this Python code. It is especially my use of MatPlotLib’s waitforbuttonpress() function that increases the appeal of PyCharm compared to other environments. See the Video Tutorial on Python, also linked on the Basics page, to get started with Python and PyCharm.

Dropbox Tip

Some of the links above connect to a Dropbox storage. That means you will see a list of all the files in the zip package when you click the link. Near the top of that page there is a Download link (small arrow pointing down to horizontal line). In the dialog box that then appears, there is NO NEED to sign in to Dropbox.  Instead, just click on “Or continue with download only” at the bottom of the dialog box, to quickly download all the files in the zip-file to your computer.

PyCharm Tip

As you will see in the Video Tutorial on Python posted on the Basics page, I recommend the free community version of PyCharm as editor (IDE) for Python. Because I often display plots with the command plt.waitforbuttonpress(), please go to Settings > Tools > Python plots in PyCharm and TURN OFF “Show plots in tool window.” That makes the plots appear nicely in separate windows, giving you the opportunity to Click somewhere in the plot to continue…

G0

The file G0.zip (updated May 17, 2026) contains Python code for simple linear static analysis. It is essentially an excerpt from G2. This batch of code is used in CIVL 436 Matrix Structural Analysis and Dynamics.

G1

The file G1.zip (updated May 17, 2026) contains Python code for linear dynamic analysis. It is essentially an excerpt from G2. This batch of code is used in CIVL 436 Matrix Structural Analysis and Dynamics and CIVL 507 Dynamics of Structures.

G2

The file G2.zip (updated May 20, 2026) contains the core G2 files. Examples and ground motion files for use with G2 are available in the links below

G2 Examples

The file G2Examples.zip (updated May 20, 2026) contains several examples of using G2, some useful in teaching, others for research.

Ground Motions

The file GroundMotions.zip (updated May 20, 2026) contains a variety of files employed to apply recorded or synthetic ground motion to structural models, for use with both G1 and G2. Note: I keep the ground motion files in a separate folder, which is why you will see file references like “../GroundMotions/filename” throughout G1 and G2. If you do the same, i.e., if you don’t remove the “../GroundMotions/” prefix when you load ground motions, then remember in PyCharm to right-click on the GroundMotions folder and select Mark Directory as… > Sources Root to make the ground motion files visible from other folders. 

Structural

The file Structural.zip (updated May 20, 2026) contains a collection of Python code for cross-section analysis, linear static structural analysis, plastic capacity analysis, and dynamics.

Optimization

The file Optimization.zip  (updated May 20, 2026) contains a collection of Python code with optimization algorithms. This batch of code is relevant for CIVL 518 Reliability and Structural Safety.

Reliability

The file Reliability.zip (updated May 20, 2026) contains a collection of Python code for reliability analysis. This batch of code is particularly relevant for CIVL 518 Reliability and Structural Safety. Note: In order to run FOSM and FORM reliability analysis you need to have the Optimization files (see above) available in the same folder. 

Probability & Statistics

The file ProbStats.zip (updated May 20, 2026) contains a collection of Python files for some special-purpose probabilistic calculations, we well as Bayesian statistical inference for random variables and linear regression models. This batch of code is particularly relevant for CIVL 518 Reliability and Structural Safety.