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 this video, also linked on the Basics page, to get started with Python and PyCharm.

Structural

The file Struct.zip (updated February 13, 2025) contains a collection of Python code for cross-section analysis, linear static structural analysis, plastic capacity analysis, and dynamics.

Reliability & Optimization

The file RelOpt.zip  (updated December 29, 2025) contains a collection of Python code for reliability and optimization analysis. The reason why the files from those two categories are in one batch is that FOSM and FORM reliability analysis employ optimization algorithms. This batch of code is particularly relevant for CIVL 518 Reliability and Structural Safety.

G2 & Ground Motions

The file G2.zip (updated January 2, 2026) contains the core G2 files, plus some examples and recorded/synthetic ground motion files that are not posted elsewhere on this website. This batch of code is used in CIVL 509 Nonlinear Structural Analysis.

OpenSees

The file OpenSees.zip (updated July 15, 2024) contains a few input files for running OpenSees via its OpenSeesPy interface. See the OpenSees and OpenSeesPy websites, as well as the neat Portwood Digital blog for additional information & examples.

Download 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, t
here 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 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…