Programming in Awk Language. LiStaLiA: Little Statistics Library in Awk. Part II

This article describes a new function of the LiStaLiA library. As I mentioned in Part I of this series of articles, I didn’t extensively test the library, so I am releasing it as an alpha version. Please let me know if you find any errors or if you improve the function, and feel free to send me your modified code!

CALCULATING STATISTICS PROPERTIES OF DATA SETS

The new functions perform a statistical analysis of the data set read by the function ReadData(). The source code of this new library functions is reported in the Appendix. The following list report all the descriptor calculated buy the functions.

Continue reading

Unix C-Shell Programming Notes: Part II

This is the second part of this series of notes on the advanced use of the Unix shell. The first part can be accessed by following the link. In this second part, I will show some advanced examples I wrote for my research activity.

1. CHANGE FILE NAMES SCRIPT

I wrote this script to change the default names of the files generated during a molecular dynamics simulation by the program mdrun in the early version of the GROMACS package for MD simulation. GROMACS is a widely used software package for simulating the behavior of molecules and molecular systems. Although it is now possible to define the root name of the files upon running the simulation program, this script can still be helpful. The script is written in the C Shell (csh) .

 #! /bin/csh -ef
#
# Change the names of the default  output Files
# generated by the program GROMACS mdrun program
#
# (c) Danilo Roccatano
#######
#
#Define the radix of the files name
#
setenv RADIX  'EH_min'

if (-e md.log) then
   if (  -e $RADIX'.log')  then 
     echo Warning $RADIX'.log' exist
   else
     mv md.log            $RADIX'.log'
   endif
else
   echo The md.log file does not exist!
endif

if (-e ener.ene) then
  if (  -e 'e'$RADIX'.ene') then 
   echo Warning 'e'$RADIX'.ene' exist
  else
    mv ener.ene       'e'$RADIX'.ene'
  endif
else
  echo The energy file does not exist
endif

if (-e ctraj.xtc ) then
  if ( -e 'r'$RADIX'.xtc') then 
    echo Warning 'r'$RADIX'.xtc' exist
  else
    mv ctraj.xtc      'r'$RADIX'.xtc'
  endif
else
  echo The compressed trajectory file does not exist
endif

if (-e confout.gro) then
  if ( -e 'x'$RADIX'.gro') then 
    echo Warning 'x'$RADIX'.gro' exist
  else
    mv confout.gro    'x'$RADIX'.gro'
  endif
else
  echo The final configuration file does not exit.
  echo Probably your simulation crashed before the end 
endif
 
exit
Continue reading

The shell of a snail and its 3D Digitization with the Structure-from-Motion algorithm

To grass, or leaf, or fruit, or wall,
The snail sticks close, nor fears to fall,
As if he grew there, house and all
                                                 Together.
Within that house secure he hides,
When danger imminent betides
Of storm, or other harm besides
                                                Of weather.
Give but his horns the slightest touch,
His self-collecting power is such,
He shrinks into his house, with much
                                                Displeasure.
Where’er he dwells, he dwells alone,
Except himself has chattels none,
Well satisfied to be his own
                                             Whole treasure.
Thus, hermit-like, his life he leads,
Nor partner of his banquet needs,
And if he meets one, only feeds
                                                The faster.
Who seeks him must be worse than blind,
(He and his house are so combin’d)
If, finding it, he fails to find
                                                Its master.

The Snail by William Cowper (1731-1800)

Introduzione

The beautiful poetry of Cowper expresses the pleasant charm that this small inhabitant of our gardens instills. I have always been fascinated by this gastropod, to the point that it was one of my favorite invertebrates for my amateur naturalistic observations. Furthermore, I still recall with pleasure and nostalgia the collection of those called ‘ciammaruchelle‘ in the Ciociaro dialect, which are small snails. These were gathered by the handful in the wheat fields after the harvest. It was one of the various culinary traditions that involved my entire family every year and were carried out with constant devotion. The collection was organized with careful timing, locations, and weather conditions to increase the likelihood of success. Usually, we would return home with a rich and tasty haul, but not without difficulties, as the little snails would climb onto the thistle plants (Cynara cardunculus L., 1753) where they would hide among the thorns to protect themselves from predators. Unfortunately for them, the predator Homo Sapiens Sapiens Frusinenses, equipped with keen eyesight and great tenacity, did not easily give up its prey!

The collected species was a variety of the snail Eobania vermiculata, commonly known as “rigatella,” which is very common in Mediterranean regions. The snails were gathered in woven baskets and, once back home, they were enclosed in circular cages with fine mesh walls for several days to purge their intestines. They were then cooked for a few hours in a tomato base spiced with mint (Clinopodium nepeta), following an ancient recipe. The dish was consumed with fresh or, even better, baked bread to make it crispy. It was a vibrant celebration of scents, flavors, and colors, with the sound of slurping as they tried to empty the succulent contents of their shells. A delicate feast of aromas and flavors: the scent of tomato infused with snail meat and mint, combined with the red color of the snails’ shells adorned with white-brown stripes.

Continue reading

Exploring Photoelasticity of Plastic Materials with the MLT

In the recent Instructable project Introducing the Mini LED Table: Compact, Affordable, and Enhanced With Computer Vision, we presented an inexpensive, compact, and easy-to-build Mini LED Table (MLT) that is a simple and cost-effective project for a STEM activity and a tool for educational purposes. Among other applications, The device can open doors for students and educators to explore the fascinating world of material science and engineering by providing an affordable and compact solution.

In a new project on the Instructables website, I have extended the capability of the MLT by adding a device that uses polarizer filters in front of the Picamera, which will provide the capability to visualize the internal stress distribution within transparent materials. These stress patterns due to the birefringence of some materials are paramount for engineering analysis. They are significant in determining various substances’ mechanical behavior and structural integrity. 

To address this possible application, we will explain how to add a polarizer to the MLT, which is already equipped with computer vision capabilities. In short, the accessory consists in adding a removable polarizer filter onto the Mini LED Table and incorporating another polarizer near the Picamera mounted on a rotatable 3D support enabling the visualization and analysis of colorful stress patterns that arise in transparent plastic and other materials exhibiting photoelastic effects.

By harnessing the capabilities of MLT, polarized light, and computer vision integration, we want to provide educators and students with a powerful tool for visualizing and understanding the intricate stress patterns present in transparent plastics and other photoelastic materials.

Before delving into the details of the project, let us provide a brief overview of photoelasticity and its significance in engineering. Photoelasticity is a powerful technique used to analyze the stress distribution in materials. It is based on the principle that the refractive index of a photoelastic material changes with applied stress. By passing polarized light through a stressed material and analyzing the resulting fringe patterns, engineers can gain valuable insights into the stress distribution and behavior of the material under various loading conditions.

Photoelasticity finds extensive applications in engineering. It aids in designing and analyzing components subjected to complex stress states, such as structural components, machine parts, and even optical devices. By visualizing stress concentrations, engineers can optimize designs, identify potential failure points, and enhance various systems’ overall reliability and performance. Additionally, photoelasticity plays a crucial role in material testing, prototype validation, and quality control processes, enabling engineers to ensure the integrity and safety of critical components.

Study of the Absorption of Covid19 Spike RBD on Silica Nanosurface

Silica is an essential component of many everyday materials. We use silica in containers, appliances, and electronic devices such as smartphones, computers, and tablet screens. These surfaces come into frequent contact with our skin, providing ample opportunities for pathogens, viruses, and microbes to accumulate. Therefore, it is crucial to study the adsorption mechanisms of these microorganisms on silica surfaces.

In collaboration with experimental groups at the University of Lincoln, the University of Greenwich, and Diamond Light Source, we investigate the adsorption mechanisms of isolated RBD regions of the COVID-19 spikes on silica nanoparticles. Our study proposes a simple geometrical model for packing protein particles on spherical silica nanoparticles, which aligns well with the available experimental data. This model revealed a surface occupancy of 32% relative to the maximum theoretical RBD packing, indicating significant adsorption.

My computational contribution to this study involved using molecular dynamics (MD) simulations to explore the binding modes and orientations of the protein adsorbed on a model silica surface. The model consisted of a flat patch of silica surface, which serves as a good approximation of the nanoparticle surface used in the experimental part of this study, given their size. Our findings showed that up to 25% of the RBD’s secondary structures underwent conformational changes as a result of adsorption onto silica nanoparticles.

These insights enhance our understanding of the principles governing protein-surface interactions and can contribute to strategies for controlling the spread of SARS-CoV-2 through contaminated objects.


MD simulations of RBD-silica interaction. (A) Representation of the RBD adsorbed on silica in a representative configuration at the end point of simulation 1. The rectangle highlights the area of contact detailed in panel B. (B) Detailed representation of three residues in close contact with silica: arginine 346 (R346), lysine 356 (K356) and glutamic acid 340 (E340) from left to right. The distances
between hydrogen and oxygen atoms at the interface are indicated and are compatible with the hydrogen bonds length.

REFERENCE

Soloviev, M., Siligardi, G., Roccatano, D. and Ferrari, E., 2022. Modelling the adsorption of proteins to nanoparticles at the solid-liquid interface. Journal of Colloid and Interface Science, 605, pp.286-295.

FORTRAN Programming: A Basic Introduction (PART I)

In college, before video games, we would amuse our- selves by posing programming exercises. One of the favorites was to write the shortest self-reproducing pro- gram. Since this is an exercise divorced from reality, the usual vehicle was FORTRAN. Actually, FORTRAN was the language of choice for the same reason that three-legged races are popular.

Ken Thompson, Communications of the ACM. 27 (8), 761–763, 1984.

In December of last year, I celebrated the 30th anniversary of my Laurea in Chemistry dissertation. The starting of my thesis dissertation also signed my acquaintance to one of the grannies of the scientific programming languages, FORTRAN. Since then, I have used and (continue to) this language for my research activity by writing several thousands of lines of code. Therefore, I want to share some of my modest programming achievements using this language.

I will concisely introduce this captivating programming language in a series of articles. This is a primer on a programming language with much more to offer, especially in the new versions starting from the FORTRAN 90. Readers interested in deepening their knowledge in FORTRAN can find online many excellent tutorials and discussion groups, as well as plenty of excellent textbooks that have been written.

The FORTRAN language 

Fortran (FORmula TRANslation) language was introduced in 1957 and remains the language of choice for most scientific programming. The language was constantly restyled and updated (e.g. Fortran IV, Fortran 77). Recent improvements, recently introduced with the Fortran 90 and 95/2003, include several extensions in more modern languages (e.g. in the C language). Some of the most important features of Fortran 90/95 include recursive subroutines, dynamic storage allocation and pointers, user-defined data structures, modules, and the ability to manipulate entire arrays. Fortran 90 is compatible with Fortran 77 but not the other way around. However, the new Fortran language has evolved in a modern computer language by incorporating constructs from other languages.  

Continue reading

A Practical Introduction to the C Language for Computational Chemistry. Part 4

Controlling complexity is the essence of computer programming.

Brian W. Kernighan. in Software Tools (with PJ Plauger), 1976.

THE FUNCTIONS

A C program is a collection of functions. A C function is equivalent to the subroutine in FORTRAN or BASIC and procedures in PASCAL, PERL, or PYTHON programming languages. A portion of the program cannot be executed independently but only as part of another program. The function contains a specific algorithm or a stand-alone procedure. You have already used several library functions in your previous programs. Output commands for printing or reading files (such as printf(), openf()), mathematical functions (sqrt(), cos() are a library or intrinsic functions as well. Other library functions, we can classify as follows

  • Input/output functions. Input/output on the computer devices (e.g. output to the terminal, printer, hard disk, input from keyboard). It is usually used with #include <stdio.h>;
  • String manipulation functions. This library contains common operations on strings (e.g., concatenation, length, search, and extraction of substrings). It is usually used with #include <string.h>;
  • Mathematical functions. Mathematical calculations (e.g. trigonometrics functions, exponentiation, square root extraction). It is usually used with #include <math.h>;
  • Graphical functions. Function for graphics operations (open a graphical window and canvas) and drawing graphical primitives (e.g. points, line, curves).
  • Operative system control functions. Operation requiriing allocation of the computer resources or devices (e.g. date and time, allocation of memory). It is usually used with, for example, #include <time.h>;
  • Data conversion functions. Operation for data conversion (e.g. change characters type, ascii to integer). It is usually used with #include <ctype.h>;

To use these function, you need to use the precompiler instruction #include at the beginning of the program. The compiler use by deafult the standard library #include <stdlib.h>;

You can write your functions, and it is called user-defined functions. The use of function allows the program to structure and makes its organization and reading easier. C language is structured around the use of functions. The main() function is a function that contains calls to other functions, both intrinsic and user-defined functions.

Continue reading

NATALE 2022: Il Trigesimo Anniversario della mia Tesi di Laurea

Mais à l’instant même où la gorgée mêlée des miettes du gâteau toucha mon palais, je tressaillis, attentif à ce qui se passait d’extraordinaire en moi. Un plaisir délicieux m’avait envahi, isolé, sans la notion de sa cause.

PROUST Marcel, Du côté de chez Swann.

Ci sono ricordi del passato che rievocano nostalgicamente piacevoli momenti nella nostra vita. Questi preziosi tesori sono, a volte, sepolti nella nostra mente o, come nel mio caso, in quella di dimenticati cristalli di ferrite. Come per dolcetti di Proust, il ritrovamento di queste vestigie ci fa rivivere le emozioni di un passato lontano. I ricordi di cui parlo sono quelle della mia tesi di Laurea in Chimica che dopo essere stata scritta e discussa fu poi dimenticata nella memoria artificiale di obsoleti supporti magnetici degli albori della rivoluzione digitale.

Discussi la mia tesi di laurea il 23 dicembre dell’anno 1992, era l’ultima sessione di laurea di quell’anno. A quell’epoca, non esisteva ancora la laurea triennale che fu introdotta in conformità con il processo di Bologna dall’anno scolastico 2001/2002. Il corso di laurea in chimica era quinquennale e si entrava in tesi nell’ultimo anno. La tesi sperimentale comportava un lavoro originale che doveva essere discusso di fronte a una commissione di laurea composta dai professori del dipartimento, i relatori e i controrelatori (coloro che dovevano leggere la tesi e valutare il lavoro di ricerca e la sua presentazione). Pertanto, la tesi di Laurea (come del resto l’equivalente tesi magistrale) era un’esperienza molto importante nel condizionare la scelta dello studente nell’avviarsi o meno in una carriera accademica. Nel mio caso, la tesi segnò la scelta di intraprendere la carriera dello scienziato e educatore.  Scelta che, come gli academici goliardici delle prime università europee, mi ha portato a peregrinare lontano dalla mia alma mater nelle lontane Università del nord Europa. Di fatti, questa prefazione è stata abbozzata a Brema in Germania e completata a Lincoln nel Regno Unito, a pochi chilometri dalla città che diede i natali a Isacco Newton.

Continue reading

La Modellazione 3D della Forma delle Uova degli Uccelli per il Design di Oggetti Funzionali

La Pasqua di quest’anno è stata un’altra occasione per pubblicare il mio tradizionale articolo sulla matematica della forma delle uova degli uccelli. Quest’anno con l’aiuto dei miei figli, abbiamo creato il seguente Instructable educazionale:

https://www.instructables.com/Modelling-and-Designing-of-Bird-Eggs-for-3D-Printi/

Il progetto mira a mostrare come utilizzare un semplice modello matematico per generare la forma 3D di uova di uccelli reali aggiustandone i diversi parametri. I modelli di uova generati possono essere salvati come modello tridimensionale nel formato STL e poi stampati utilizzando una stampante ad estrusione di filamento plastico. L’uovo stampato può essere dipinto o modificato utilizzando un programma di modellistica 3D (per esempio MeshLab, sviluppato in Italy dal Visual Computing Lab of CNR-ISTI) per aggiungere funzionalità per gadget o giocattoli nella forma di uovo. Viene spiegato in dettaglio un esempio di come creare un uovo illuminato internamente con un LED multicolore.

Più recentemente, per divertimento, ho pubblicato sempre su sito Instrutables un altro esempio usando lo stesso approccio:

https://www.instructables.com/The-Eggyrint/

Inoltre, l’argomento della modellazione della forma delle uova è stato trattato in articoli precedenti e il lettore interessato può integrare le informazioni nel progetto Instructable con quelle fornite nei seguenti articoli:

https://wordpress.com/post/daniloroccatano.blog/3792

https://wordpress.com/post/daniloroccatano.blog/5171

https://wordpress.com/post/daniloroccatano.blog/6760

Nell’Instructable dviene fornito un programma in C++ che dà la possibilità di generare le forma 3D delle uova e salvarle in STL. Può essere utilizzato per la ricerca, l’insegnamento e il divertimento.

Spero che il nostro progetto vi piaccia e commenti e suggerimenti costruttivi sono sempre i benvenuti!

Exploring the Lotus Effect using Candle Soot

I recently published an new Instructable that is the results of some home experiments that I did some time ago (see also my previous article).

https://www.instructables.com/EXPLORING-THE-LOTUS-EFFECT-USING-CANDLE-SOOT/

It shows how to prepare these simple surfaces and make some interesting observations with them. Like the previous two Instructables, my family help me a lot in preparing it in the very short time of one day. So a big thank you to my wife, Francesco, and, in particular, to Leonardo.

Hydrophobic and super-hydrophobic surfaces are ubiquitous in the natural world. You do not need to search much to find good examples: just walk out in your garden after a light rain and look at the plenty of weed leaves pearly decorated by water droplets. If you have an ornamental pond, you may have even the chance to see floating better examples of plants having a super-hydrophobic surface. Notably, wettability in Nature is present in a different form that subtle differences in the function and effect on the water droplets. Plant leaves need to keep their surfaces clean for light-harvesting efficiency. A water repellent leaves let water drops roll over its surface and mechanically remove dust particles. This effect was first noted on leaves of the Lotus plant, and for that reason, it is also called the Lotus effect.

Several novel technological materials exploit the properties of super-hydrophobic. For example, in your kitchen, Teflon pans are used to avoid sticking food residuals and therefore easily cleaned. Your car windows are teated to let the water easily roll over the surface. 

Candle soot is an artificial material that is easy to produce and can be used to demonstrate some of the properties of the (super)-hydrophobic surface existing in nature.