Why coding is a valuable addition to the chemistry toolkit
When I started my undergraduate chemistry education, a course in computer programming was not a degree requirement, so most students did not complete one. Instead, my peers and I relied on software applications for coursework that demanded quantitative analysis. And while we could have strayed from software tools and written code to do our calculations, we were not familiar with computer programming; it was not among the skills that comprised our chemistry toolkit. Late nights completing data analysis with my lab partners involved troubleshooting errors in spreadsheets, not debugging code. But if we had gained experience with programming like our peers studying physics or engineering, we could have more effectively handled laboratory data and performed quantitative analysis.
In graduate school, some students wrote code for their research – it became essential for my PhD in theoretical chemistry. Still, it was limited to those in heavily quantitative specialities, mainly physical and analytical chemistry. My peers’ experiences as undergraduates were like mine. None had completed any training in programming, and those now writing code for their research were self-taught.
My PhD advisor helped me start coding by recommending a programming language and providing informal assignments. Through this approach, I learned to code with a goal in mind, and found resources to tackle the problems as needed instead of aimlessly studying a language. After some practice, I gained confidence in my ability to write code that produced sensible results (at least after debugging) and switched to a different language for my research.
I realised that all graduate students could benefit from using code, not just those of a few specialities. As a minimum, everyone needs to extract data from files and perform analysis. Completing these tasks was certainly possible without code. Still, many were cumbersome (especially when repeated over 5–6 years) and could have been automated.
Chemistry, like all sciences, is becoming increasingly digital. Electronic laboratory notebooks and chemical property databases are examples of digital tools for chemistry. Digitisation enables progress by making information more accessible and encouraging more transparent data handling practices. And while many digital tools do not require coding, there is more to gain from digitisation if chemists learn how to write code. For example, information from digital chemical property databases is extracted more efficiently with code that captures the results for user-chosen criteria than when searched manually. Similarly, accessing laboratory data is more straightforward with digital records and code than with hand-written notebooks.
As digital tools in chemistry become more widespread, coding can help to maximise their benefits. And while many universities are adapting their courses so that computer programming is part of the chemistry curriculum, those who have already completed their degrees should also consider expanding their chemistry toolkits by learning to code. This is not as hard as it sounds, as chemists already possess the logical-reasoning and problem-solving skills needed to become effective coders.
Standard software can be inadequate for tackling unique research problems. The same is true for standard laboratory equipment. In the latter case, chemists are clever in preparing atypical solutions to laboratory challenges. Writing code similarly allows chemists to design custom solutions beyond the capabilities of software tools. So, if chemists are ready to build custom equipment, why shy away from writing code?
If you want to try coding, first pick a simple task and write out its procedure. Then, choose a programming language and download all that it requires to execute code. Consult learning resources to help you write code for each step in the procedure (see box); and then run the code and ensure it produces accurate results.
As learning to code is initially challenging, choosing a frequently repeated task ensures that the time spent writing the code is worthwhile. Sorting through a dataset to extract and plot a smaller portion is an example of a suitable task, especially if performed routinely. The steps involved may include reading data stored in files, searching to identify data that match a criterion, and generating a plot. In addition, writing code in a widely used language facilitates sharing with others and increases the chances of finding a friendly colleague to lend a hand. After following the above steps, you will hopefully be able to complete a task that would typically take several minutes (or longer) in a fraction of that time.
Expanding the chemistry toolkit to include coding skills can allow chemists to handle data and use digital resources more effectively. Chemists can learn the basics and write code for their routine work without formal training – I hope you will give it a try.
Interactive coding tutorials in a range of programming languages. Work your way through a tutorial or check out their language-specific cheat sheets.
MIT OpenCourseWare (ocw.mit.edu/courses/intro-programming)
University-level introductory programming courses with video lectures, lecture notes, and assignments.
Stack Overflow (stackoverflow.com)
A question-and-answer website for programming. Ask your own question or check out questions/answers on similar topics.
Language-specific documentation pages
These generally provide detailed information about language-specific topics with examples.