1 Introduction

Metal corrosion is a major industrial problem, responsible for a significant waste of material and a reduction in the performance and durability of the metallic materials that make up infrastructure [1]. This occurrence can be avoided by altering the metal itself or the surrounding conditions or isolating the metal from the corrosive environment [2]. The choice of mild steel is based on the knowledge acquired by researchers over the last few decades and on studies aimed at meeting the new objectives of the processing industries and the environment. Mild steel is one of the most widely used materials in industry, thanks to its high strength and reliability [3]. Unfortunately, mild steel is susceptible to corrosion during long-term use due to its exposure to harsh and complex environments. In particular, the pickling process. The acid solution can also corrode the mild steel substrate as it removes the oxide layer [4]. In the existing literature, using inhibitors to impede metal dissolution remains an essential approach [5, 6]. Corrosion inhibitors are widely used to reduce corrosive attacks on metallic materials [7]. The known dangerous effects and stringent environmental regulations of most synthetic organic inhibitors have attracted the attention of researchers to the need to develop more effective inhibitors [8]. These organic compounds of plant origin are suitable corrosion inhibitors due to the natural composition of their molecules (heteroatoms N, O, S) or polar groups such as -NH2, -OH, -COOH, -CN-, and -SH and the absence of heavy metals [9]. Plant-derived natural products are typically cost-effective and are available through simple extraction processes that are easily accessible, renewable, environmentally friendly, and widely used to minimize the cost of corrosion control [10]. Extracts from leaves, roots, bark, seeds, and fruits are combinations of organic compounds that generally possess polar functionalities, including nitrogen, sulfur, or oxygen atoms [11, 12]. Among them are alkaloids containing one or more nitrogen atoms. For example, tryptamine [13] and caffeine [14] are used as corrosion inhibitors. Therefore, developing new green corrosion inhibitors derived from plant extracts has become one of the guiding directions for corrosion researchers [4].

In addition, by exploring technological applications for food residues, it is possible to decrease the quantity of discarded waste and enhance the economic feasibility of suitable waste management alternatives [15].

The aim of this study was to investigate the inhibitory effect of aqueous and ethanolic extracts of Pelargonium graveolens as corrosion inhibitors for mild steel in 1M hydrochloric acid, using HPLC and SEM/EDX techniques. This study was completed by a complementary theoretical approach using DFT.

2 Materials and Methods

2.1 Plant Material

The aerial part of the plant used (P. graveolens) was harvested in May 2020, in the ksar Tizgaghine 20 km from Tinjdad in the Er-Rachidia region (31° 55′ 55″ north, 4° 25′ 28″ west). The plant was dried in a dry, ventilated place for one month, then ground with an electric grinder and stored in the shade in closed premises. 30 g of plant powder was placed in a cartridge, then put in a siphon attached to a flask containing 250 mL of extraction solvent, the extraction solvents used to be ethanol and water. A refrigerator was placed on top. The solvent was evaporated using a rotary evaporator after a 6-h extraction period.

2.2 Chromatographie Liquide à Haute Performance (HPLC)

The HPLC system was used to separate the bioactive compounds of P. graveolens ethanolic and aqueous sheet extracts. Chromatographic separation was performed on a C18 column (5 mm, 250 4.6mm i.d.) at room temperature. The elution was conducted with a flow rate of 0.5mL min−1 following the gradient shown in Table 1. Methanol (A) and ultra-pure water (B) were used as solvents. The UV detector wavelength is 254 nm.

Table 1 The HPLC mobile phase gradient

2.3 Material Preparation

The steel used in this work is mild steel composed of Fe (99.30), C (0.21), Mn (0.05), Si (0.38), S (0.05), P (0.09), and Al (0.01). Mild steel samples were polished on moistened abrasive papers (Si–C. silicon carbide) of progressively finer grain size: grades 400, 600, 1000, and 1500, rinsed with distilled water to remove ass impurities, and degreased with acetone to get rid of fatty matter. Subsequently, the extracted material was washed with distilled water and then dried using an electric dryer. The corrosive test solution employed in the study was prepared by diluting a stock solution of analytical reagent grade hydrochloric acid (HCl 37%) with distilled water, resulting in a 1M HCl concentration. The concentration of inhibitors investigated ranged from 0.25 to 1.0 g L−1.

2.4 The Gravimetric Study

The gravimetric measurements were conducted using a glass cell equipped with a thermostat-cooled condenser to maintain the electrolyte at the desired temperature. The volume of the electrolyte was set at 100 ml. The samples used in the experiment were rectangular and had specific dimensions (length = 1.95 cm, width = 1.65 cm, thickness = 0.65 cm). Before each measurement, the samples were accurately weighed and submerged in beakers containing 100 ml of acid solutions, both with and without the inhibitor (extract), at various temperatures for 6 h. The inhibitory efficacy was calculated using the following expression (1).

$$ \eta \% = \left[ {\frac{{C_{R}^{0} - C_{R} }}{{C_{R}^{0} }}} \right] \times 100 $$
(1)

\({\text{C}}_{{\text{R}}}^{0} : \) corrosion rate before immersion in the inhibited solution, \({\text{C}}_{{\text{R}}} :{ }\) corrosion rate after immersion in the inhibited solution.

2.5 Electrochemical Study

The electrochemical measurements were performed utilizing a biological potentiostat, which was controlled by the EC-lab software. For all tests performed, a three-electrode cell was used. The auxiliary electrode is a platinum electrode. The reference electrode used is an Ag/AgCl electrode, and the working electrode consists of a 0.98 cm2 steel plate which is placed directly in the cell, leaving a free surface. The mass loss tests were carried out in a 50-ml beaker. Impedance measurements are made at 25°C in the presence and absence of the inhibitor. After immersion, stability is reached after 30 min in the open circuit. The intensity-potential curves are obtained in potentiodynamic mode with a sweep speed of 1 mv min−1. The potential applied to the sample varies continuously from – 800 to – 200 mV ECS−1. The inhibition efficiency (ɳpp%) was calculated from the corrosion current density values using the following Eq. (2)

$$ \eta_{{{\text{pp}}}} \% \; = \;\frac{{i_{{{\text{corr}}}}^{0} - i_{{{\text{corr}}}} }}{{i_{{{\text{corr}}}}^{0} }} \times 100 $$
(2)

\(i_{{{\text{corr}}}}^{0}\) represents the corrosion current density in the absence of any inhibitor or blank solution, \(i_{{{\text{corr}}}}^{0}\) represents the corrosion current density in the presence of the inhibitor.

The electrochemical impedance spectroscopy (EIS) method was employed within a frequency range of 10 kHz to 100 mHz, with 10 data points per decade. Nyquist curves were generated and subsequently analyzed using a suitable equivalent circuit. The equivalent circuit model was selected to accurately represent the electrical response of the system under investigation [16]. The inhibition efficiency (IE) can be calculated using the following formula Eq. (3)

$$ \eta_{{{\text{imp}}}} \% \; = \;\frac{{R^{\prime}_{{\text{P}}} \; - \; R_{{\text{P}}} }}{{R_{{\text{P}}} }}\; \times \; 100 $$
(3)

Rp′ represents the polarization resistance of the mild steel electrode in the presence of an inhibitor, while Rp represents the polarization resistance of the mild steel electrode in the absence of any inhibitor.

2.6 Scanning Electron Microscope (SEM)

The surface morphology of the carbon steel samples was examined before and after immersion in the studied solutions, both with and without the inhibitor. This examination was conducted by the JSM-IT 500 HR scanning electron microscope (SEM) connected to an X-ray analysis system (EDX). The SEM operated at an electronic acceleration of 8 kV, allowing for high-resolution imaging of the sample surfaces. Additionally, the EDX analysis provided information on the elemental composition of the sample surfaces, aiding in the characterization of any changes resulting from the immersion in the solutions with and without the inhibitor.

3 Results and Discussion

3.1 Identification of Phenolic Compounds by HPLC–UV

The results of the HPLC analysis obtained for the aqueous (PGaq) and ethanolic (PGEt) extracts of P. graveolens at a wavelength of 254 nm are shown in Figs. 1 and 2.

Fig. 1
figure 1

HPLC chromatogram of P. graveolens aqueous extract

Fig. 2
figure 2

HPLC chromatogram of P. graveolens ethanolic extract

The analysis of the aqueous and ethanolic extracts of P. graveolens by HPLC–UV revealed the presence of phenolic compounds. The separation conditions used resulted in a more or less separate chromatogram (Figs. 1 and 2). The aqueous extract contains nine compounds: caffeine acid, gallic acid, para-coumaric acid, rutin quercetin, salicylic acid, vanillin vanillic acid, and hydroxybenzoic acid. The ethanoic extract contains eight phenolic compounds: gallic acid, vanillin, para-coumaric acid, caffeic acid, rutin, salicylic acid, vanillic acid, and hydroxybenzoic acid. The quantification of the identified polyphenols showed that the ethanolic extract was richer in phenolic compounds than the aqueous extract. The majority compound in the aqueous extract was gallic acid with a concentration of (17.29μg g−1 crude extract) followed by hydroxybenzoic acid (2.75μg g−1), rutin (4.31μg g−1), para-coumaric acid (3.51μg g−1), and quercetin (1.83μg g−1). While for the ethanolic extract, the results showed that it is rich in rutin (37.07μg g−1) followed by para-coumaric acid (12.07 μg g−1), gallic acid (10.35μg g−1), vanillin (8.86μg g−1), salicylic acid (5.791μg g−1), and hydroxybenzoic acid (2.17μg g−1) (Table 2).

Table 2 Phenolic compounds identified by HPLC–UV in aqueous and ethanolic extracts of P. graveolens

A subsequent study by Omar et al. [17] also mentioned the presence of gallic acid with a concentration of (0.61 mg g−1), caffeic acid (2.09 mg g−1), rutin (81.17 mg g−1), and quercitrin (2.29 mg g−1) in the ethanolic extract of P. graveolens leaves.

3.2 Concentration Effect

To study the inhibitory effect of P. graveolens extracts on mild steel, a gravimetric study with deferential concentration (0.25 g L−1 to 1.0 g L−1) was performed. The results obtained are summarized in Table 3 and Fig. 3.

Table 3 Corrosion rates (CR) and percentage of inhibitory efficiencies (IE%) of aqueous and ethanolic extracts of P. graveolens
Fig. 3
figure 3

Evolution of corrosion rate (CR) and inhibition efficiency (IE) of mild steel corrosion in 1M HCl as a function of the concentration of aqueous and ethanolic extracts of P. graveolens

The obtained results indicate that the corrosion rate decreases as the concentration of the studied inhibitors increases. It implies that the aqueous and ethanolic extracts of P. graveolens effectively delay the corrosion of the steel. While inhibitory efficiency increases with increasing concentration and reaches a maximum value of 97% for aqueous extract and 92% for ethanolic extraction at an optimal concentration of 1.0 g L−1, these results obtained are highly significant compared to another study, for example, P. tremula leaf extract revealed maximum 82.06% inhibition efficiency at 4.0 g L−1 inhibitor concentration [18], and Phyllanthus emblica seed extract revealed maximum 92.43% corrosion inhibition efficiency using 4.0 g L−1 in 15% HCl solution [19].

The observed results can be explained by the adsorption process, wherein the inhibitor chemicals employed are adsorbed onto the surface of the mild steel. This adsorption process forms a protective layer, which acts as a barrier against corrosion, thereby reducing the corrosion rate. The inhibitor molecules effectively prevent or hinder the interaction between the metal surface and the corrosive environment, leading to the delayed corrosion of the steel [20].

3.3 Electrochemical measurements

The evolution of steel potential in 1.0 M HCl in the absence and presence of different concentrations of aqueous and ethanolic extracts of P. graveolens is shown in Fig. 4.

Fig. 4
figure 4

Open-circuit potential monitoring of steel in 1M HCl in the absence and presence of 1.0 g L−1 concentration of PGaq and PGEt extracts at 298°K

For tests carried out with the steel electrode, with the presence of the ethanolic extract, the potential varies slightly than in the aqueous extract and stabilizes from the first minutes of immersion. It should be noted that in inhibited solutions, the potential of the electrode moves toward anodic values. In general, the potential values for inhibited systems are less negative than those for uninhibited systems. This result can be attributed to the formation of a protective film on the steel surface and suggests inhibition of the anodic dissolution of the steel by the extract [21].

3.4 Potentiodynamic polarization Study

The results of potentiodynamic polarization tests without and with the addition of PGaq and PGEt extracts are shown in Fig. 5.

Fig. 5
figure 5

Potentiodynamic polarization curves for the mild steel surface obtained at 298°K without and with the addition of the inhibitors PGaq and PGEt at different concentrations

Analysis of graphical representations of the variation of log icorr as a function of potential for steel in 1.0 M HCl in the absence and presence of PGaq and PGEt extracts showed an increase in cathodic and anodic current with increasing temperature. The values of the corrosion current density of steel in 1.0 M HCl in the absence and presence of PGaq and PGEt extracts at different temperatures and the corresponding inhibitory efficiencies are shown in Table 4.

Table 4 Corrosion current densities of steel in 1M HCl in the absence and presence of aqueous and ethanolic extracts of P. graveolens and inhibition rates obtained at different temperatures

The analysis of these results showed that the inhibitory efficacy of both PGaq and PGEt increased with increasing concentration and reached 97.6% for PGaq and 95.2% for PGEt at 1.0 g L−1. Furthermore, no change in the cathodic mechanism was observed from the low variation in the cathodic slope values (ßc).

Various researchers have suggested a classification for inhibitors based on their effect on the corrosion potential (Ecorr) of the system when the shift in Ecorr values in the presence of inhibitors exceeds 85 mV compared to the Ecorr value of the blank solution (without inhibitor); these inhibitors are categorized as either anodic or cathodic inhibitors [22, 23]. By adsorbing onto the steel surface, these inhibitors create a protective layer that impedes the corrosion process. This layer acts as a barrier, inhibiting both the anodic corrosion reaction (metal dissolution) and the cathodic reaction (reduction of oxygen or other species). As a result, the inhibitors exhibit a mixed-type inhibition mechanism, providing corrosion protection by hindering both the anodic and cathodic processes at the same time.

3.5 Electrochemical Impedance Spectroscopy

Electrochemical impedance spectroscopy (EIS) is a powerful technique that can provide additional information about elementary steps and processes that are not easily detected using the potentiodynamic bias technique. The diagrams of the electrochemical impedance spectroscopy of the mild steel in the inhibited and uninhibited solution are shown in Fig. 6, and the electrochemical impedance parameters have been extracted after good simulation as SIE plots grouped in Table 5.

Fig. 6
figure 6

Impedance diagrams of steel in the absence and presence of different concentrations of PGaq and PGEt extracts from the aerial part of P. graveolens

Table 5 The impedance parameters of steel were evaluated in the absence and presence of various concentrations of PGaq and PGEt extracts from the aerial parts of P. graveolens

The impedance graphs of steel obtained in the absence and presence of different concentrations of PGaq and PGEt extracts from P. graveolens leaves exhibiting non-ideal semicircular Nyquist plots are due to heterogeneities on the steel surface. These heterogeneities can arise from impurities on the steel surface as well as the adsorption of inhibitors [24]. In addition, the shape of the capacitive loops increases slightly with increasing concentration. Nyquist diagrams have only one semicircle which indicates that the charge transfer controlled the mechanism of corrosion reactions [25].

EIS plots of steel obtained in the absence and presence of different concentrations of PGaq and PGEt extracts from P. graveolens leaves showed non-ideal semicircular Nyquist plots in which the radius of the semicircular plots systematically increased in each case with the addition of the studied extracts, implying that these extracts may establish a protective oxide film on the electrode surface due to spontaneous adsorption of the molecules existing in the extracts studied [26].

The radius of each semicircular shape showed an upward trend compared with white, which can be attributed to the total coverage of the surface occupied by these extracts on the steel, which can be attributed to a link with multiple and active molecules of the surface occupied by the extracts tested on the steel [27].

Analysis of steel impedance parameters in the absence and presence of different concentrations of PGaq and PGEt extracts from P. graveolens revealed several essential findings. The polarization resistance (PR) increased with the inhibitor concentration, indicating that inhibiting agents reduced the steel corrosion rate. The element phase constant (Q) and double-layer capacitance (Cdl) showed slight decreases, suggesting that the adsorption of the inhibitors onto the steel surface was occurring.

This observation was further supported by the calculated inhibition efficiencies, which reached 96.6% in the presence of PGaq and 94.1% in the presence of PGEt at the optimum concentration of 1.0 g L−1. It is inferred that the inhibitor molecules used adsorbed have replaced H2O and other corrosive species initially adsorbed to the electrode surface [26].

The correlation between the inhibition efficiencies obtained from the electrochemical impedance spectroscopy (EIS) technique and the potentiodynamic polarization technique indicates that both methods yield consistent results. Furthermore, the results obtained from the electrochemical methods closely match those obtained from weight loss measurements, with only slight differences attributed to the exposure time. The weight loss tests require a longer immersion time to reach complete saturation of the inhibiting molecules on the steel surface (6 h), and the electrochemical tests provide a more rapid evaluation of inhibition performance.

In conclusion, these findings confirm that both PGaq and PGEt extracts from P. graveolens leaves act as effective inhibitors against mild steel corrosion in the 1M HCl solution.

3.6 Adsorption Isotherm

To find the appropriate adsorption isotherm for the PGaq and PGEt inhibitors, various isotherms were tested, such as those of Langmuir, Temkin, and Freundlich. The results obtained from electrochemical impedance spectroscopy are shown in Fig. 7, and the linear equations for these isotherms are summarized in Table 6.

Fig. 7
figure 7

Adsorption isotherm models tested for the two inhibitors PGaq and PGEt at 298 K

Table 6 Linear equations for adsorption isotherms

From the isotherm models studied, PGaq and PGEt follow the Langmuir isotherm since they have the best regression coefficient and a slope close to unity. (1.008 for PGaq and 0.835 for PGEt).

The calculated free energy values (\(\Delta G_{{{\text{ads}}}}^{^\circ }\)) for the aqueous and ethanolic extracts of P. graveolens were − 18.636 kJ mol−1 and − 13.593 kJ mol−1, respectively. Negative ∆G°ads values indicate the spontaneity of the adsorption process and the stability of the adsorbed layer on the metal surface. Based on the calculated values, the adsorption of the P. graveolens extracts on the steel surface is primarily attributed to forming a physical bond. The \(\Delta G_{{{\text{ads}}}}^{^\circ }\) values falling between − 20 and − 40 kJ mol−1 suggest that the adsorption process involves a combination of electrostatic interactions and weak chemical interactions. The stability of the adsorbed layer indicates that the extracts can effectively form a protective film on the steel surface, reducing the corrosion rate [28, 29]. These ∆G°ads values provide quantitative information about the adsorption process and support the conclusion that the adsorption of the P. graveolens extracts on the steel surface is predominantly due to physical interactions (Table 7).

Table 7 Adsorption parameters obtained from adsorption isotherm models

3.7 Temperature Effect

The effect of temperature on the inhibition efficacy of P. graveolens extracts at a concentration of 1.0 g L−1 was investigated over a temperature range from 298 to 333 K. Mass loss measurements were determined after a 2-h immersion period.

The results obtained for inhibition efficiency and corrosion rate are presented in Table 8.

Table 8 Corrosion parameters obtained from the mass loss of mild steel in 1.0 g L−1 of aqueous (PGaq) and ethanolic (PGEt) extracts of P. graveolens at different temperatures

The obtained results indicate that the corrosion rate is accelerated with increasing temperature in the presence of the inhibitor compared to blank. And the inhibitory efficacy is decreased from 97% (298°K) to 90% (333°K) for aqueous extract and from 92 to 78% for ethanolic extraction of P. graveolens.

This observation is consistent with the idea that higher temperatures can enhance the kinetics of corrosion reactions, which can weaken the protective effect of inhibitors. At higher temperatures, the molecules from the inhibitor extracts might become less adsorbed on the metal surface, reducing their ability to form a protective barrier against corrosive agents.

Additionally, higher temperatures can alter the solubility and stability of the inhibitor compounds, affecting their availability for adsorption on the metal [30].

Figure 8 shows Arrhenius diagrams for mild steel corrosion rate as a function of inverse absolute temperature. These variations are straight lines for different concentrations without and with inhibitors. From Arrhenius equations (Eq. 4. Equation 5), we can calculate the activation parameters for different concentrations of each extract (Table 9).

$$ i_{{{\text{corr}}}} \; = \;Ae^{{\left( { - \frac{Ea}{{RT}}} \right)}} $$
(4)
$$ i_{{{\text{corr}}}} \; = \; \frac{RT}{{Nh}}e^{{\left( {\frac{{{{\Delta S}}^{*} }}{R}} \right)}} e^{{\left( { - \frac{{{\Delta H}^{*} }}{RT}} \right)}} $$
(5)

A: the Arrhenius constant, Ea: apparent activation energy, R: the gas constant, T: absolute temperature, h: Plank's constant, N: Avogadro's number.

Fig. 8
figure 8

Arrhenius lines for mild steel in 1M HCl in the absence and presence of PGaq and PGEt extracts

Table 9 Mild steel activation parameters in 1M HCl with and without 1 g L−1 of PGEt and PGaq extracts

The results shown in Table 9 indicate that the Ea values obtained in the inhibited solutions are higher compared to those obtained in the uninhibited solution. This suggests that the inhibitors used form electrostatic bonds with the mild steel surface, indicating physical adsorption [31]. These electrostatic bonds contribute to corrosion inhibition by forming a protective layer on the steel surface.

Furthermore, the enthalpy of activation (ΔH*) values for the P. graveolens extracts are higher than those observed in the absence of an inhibitor. These positive ΔH* values indicate that the dissolution reaction in the presence of the extracts is endothermic, meaning that it requires an input of energy to occur. This suggests that the presence of the inhibiting agents changes the thermodynamics of the corrosion process and makes the process more unfavorable.

Additionally, the highly negative values of ΔS* in the presence of the aqueous and ethanolic extracts indicate that the activated complex formed on the mild steel surface becomes more ordered and compared to the presence of a 1 M HCl solution alone[32]. This indicates that the presence of the extracts promotes a more organized arrangement of molecules at the steel surface during the corrosion process.

These findings suggest that the P. graveolens extracts effectively inhibit the corrosion of mild steel by forming electrostatic bonds with the steel surface, increasing the activation energy, and altering the thermodynamics and molecular arrangement during the corrosion process. This provides evidence for the inhibitory mechanism of the extracts and their potential as corrosion inhibitors for mild steel in acidic environments.

3.8 Scanning Electron Microscope (SEM).

Figure 9 shows SEM images of the steel surface recorded before and after exposure to 1M HCl medium without and with the addition of 1.0 g L−1 aqueous extract and ethanolic extract of P. graveolens.

Fig. 9
figure 9

SEM micrographs of mild steel surface before 6 h immersion in 1M HCl (a); after 6 h immersion in 1M HCl (b); after 6 h immersion in 1M HCl + 1 g L−1 ethanolic extract (c); after 6 h immersion in 1M HCl + 1.0 g L−1 aqueous extract of P. graveolens at 25°C (d)

The SEM results confirm the protective effect of the ethanolic and aqueous P. graveolens extract inhibitors on the mild steel surface. The inhibitors act as a barrier, preventing or slowing down the corrosive attack of the HCl solution on the metal surface. This visual evidence aligns with the quantitative corrosion inhibition data obtained from other techniques and further supports the potential of the P. graveolens extract inhibitors as effective corrosion inhibitors for mild steel in acidic environments. (Fig. 9).

The results obtained from the analysis of the atomic composition of the mild steel samples provide valuable insights into the corrosion process, and the protective effect of P. graveolens extracts is presented in Table 10 .

Table 10 Mass percentage of elements obtained from EDX spectra

In the absence of any inhibitor, the atomic percentage of iron decreased significantly from 98.18% to 85.28% after immersion in 1M HCl. This reduction in iron content indicates the dissolution of iron atoms from the steel surface due to the corrosive attack of the acid. Additionally, the appearance of a new oxygen (O) peak confirms the presence of iron oxides, which are characteristic corrosion products.

However, in the presence of P. graveolens extracts, the decrease in the atomic percentage of iron is less pronounced. The ethanolic extract decreased by 92.22%, while the aqueous extract decreased by 93.16%. These results suggest that the samples can protect the steel surface and inhibit the dissolution of iron atoms to the same extent.

Moreover, In the presence of the extracts, an increase in the atomic percentage of carbon and silicon is also observed. This increase can be attributed to the adsorption of components present in the samples onto the steel surface. These adsorbed components form a protective layer that hinders the corrosive attack, thereby reducing the dissolution of iron atoms.

Overall, the analysis of the atomic composition supports the hypothesis that the P. graveolens extract forms a protective layer on the mild steel surface, reducing the corrosion rate and altering the corrosion products. The presence of carbon and silicon atoms, along with the reduced dissolution of iron, indicates the formation of a protective barrier that contributes to the inhibition of corrosion(Fig. 10) [33].

Fig. 10
figure 10

EDX spectra of mild steel before 6 h immersion in 1 M HCl (a); after 6 h immersion in 1 M HCl (b); after 6 h immersion in 1 M HCl + 1 g L−1 ethanolic extract (c); after 6 h immersion in 1 M HCl + 1 g L−1 aqueous extract of P. graveolens at 25 °C (d)

3.9 Studies on DFT Calculation

In this study, the structures of nine molecules from the extract were optimized, confirming their presence as true minima on the potential energy surface by the absence of negative frequencies in the frequency calculations. The DFT/B3LYP method and Gaussian 09 and Gauss View 6 software packages [34] were employed to calculate various properties of these compounds, including molecular geometry, HOMO and LUMO energies, and molecular electrostatic potentials. All calculations utilized a 6-31G (d. p) basis set.

3.10 Examination of Frontier Molecular Orbitals:

The HOMO and LUMO energies of all compounds were determined using the B3LYP/6-31G (d.p) level of theory. Fig. 11 illustrates the HOMO and LUMO orbitals of the compounds under investigation. These orbitals play a critical role in chemical reactions, with the HOMO denoting electron-donating capability and the LUMO representing electron-accepting ability. A narrow energy gap between the HOMO and LUMO facilitates efficient electronic charge transfer from donor to acceptor groups, resulting in high molecular polarizability. Conversely. a wide energy gap between the HOMO and LUMO indicates lower reactivity. The calculated parameters are summarized in Table 11.

Fig. 11
figure 11

The HOMO and LUMO for nine compounds at B3LYP/6-31G (d. p)

Table 11 Quantum chemical descriptors of all molecule structures using DFT at B3LYP/6-31G (d. p) level of theory

According to Koopmans' theorem [35], closed-shell molecules allow for the calculation of the Ionization Potential (I) and Electron Affinity (A) by utilizing the energies of the highest occupied molecular orbital (EHOMO) and the lowest unoccupied molecular orbital (ELUMO), respectively.

By using the following equations [36, 37], the values of the ionization potential (I) and electron affinity (A) can be employed to compute the absolute electronegativity (χ), absolute hardness (ƞ), and softness (σ, the reciprocal of hardness).

$$ \chi = \left( {I + A} \right)/2 $$
$$ \eta = ({\text{I}} - {\text{A}})/{2} $$

The expression for the fraction of transferred electrons, denoted as (ΔN), can be described by the following equation (Eq. 6):

$$ \Delta N\; = \;\frac{{\chi \left( {{\text{Fe}}} \right) - \chi \left( {{\text{inh}}} \right)}}{{2\left( {\eta \left( {{\text{Fe}}} \right) + \eta \left( {{\text{inh}}} \right)} \right)}} $$
(6)

In the equation, χ(Fe)represents the electronegativity of the metal [χ(Fe) = 7], while χinh refers to the electronegativity of the inhibitor. Additionally, η(Fe) and χinh correspond to the hardness values of the metal [η(Fe) = 0] and the inhibitor respectively [21].

All the values of ΔN are positive, which indicates that all the molecules are considered electron donors to the unoccupied d orbitals of Fe. We also note that the positive value of ΔN is associated with the ability of molecules to donate an electron to the metal surface.

The energy difference ΔE reflects the electronic stability and reactivity of molecules. And lower values indicate more favorable adsorption of the molecules from the extract.

Quercetin demonstrates effective inhibition activity due to its lower energy difference (4.177 eV) than the other substances, which results in favorable adsorption. The significant adsorption capacity of quercetin is supported by its high softness value (σ = 0.479).

In terms of dipole moment (µ) and electronegativity (χ), it is widely recognized that higher values of these parameters likely lead to increased adsorption of the chemical compound on the metal surface. This increases the contact area between the molecule and the metal, improving the inhibitor's ability to inhibit corrosion.

Analyzing the electronic densities of the highest occupied molecular orbital (HOMO) and lowest unoccupied molecular orbital (LUMO) in nine molecules demonstrates that the HOMO's electronic density is uniformly distributed across the entire molecule, although rutin is an exceptional case.

The electron density is more concentrated on the aromatic ring. This distribution provides a general indication of the preferred areas for electrophilic or nucleophilic attack.

3.11 Molecular Electrostatic Potential (MEP) Analysis

The determination of the molecular electrostatic potentials (MEP) for the compounds was carried out through DFT calculations, utilizing the optimized geometries obtained at the B3LYP/6-31G (d.p) level of theory. The objective was to identify the specific areas within the compounds that exhibit higher vulnerability to electrophilic and nucleophilic attacks. As depicted in (Fig. 12), the blue areas indicate a partial positive charge, which renders them more susceptible to nucleophilic attacks. Conversely, the red and yellow regions possess a negative charge, which makes them more susceptible to electrophilic attacks. The potential values gradually decrease from blue to red. Notably, the regions of negative potential primarily reside on oxygen atoms, indicating a high repulsion, while the remaining areas exhibit a positive potential, signifying a high attraction.

Fig. 12
figure 12

MEPs pictures of all molecules at B3LYP/6-31G (d.p) level of theory in the gas phase

4 Conclusion

This research focuses on investigating the corrosion inhibition properties of the aqueous and ethanolic extracts obtained from the P. graveolens plant on mild steel in hydrochloric acid (HCl) media. The study employs a comprehensive approach utilizing various experimental techniques and theoretical calculations.

The inhibitory effects of the extracts were evaluated using several methods, including gravimetric analysis, stationary, and transient electrochemical techniques such as electrochemical impedance spectroscopy (EIS), and examination of the morphological changes of mild steel using scanning electron microscopy coupled with energy-dispersive X-ray spectroscopy (EDX). Additionally, density functional theory (DFT) calculations at the B3LYP/6-31G (d, p) level were employed to complement the experimental findings.

The obtained results demonstrate the effective inhibition of the dissolution rate of mild steel by both the aqueous and ethanolic extracts of P. graveolens. The inhibitory efficacy of the extracts reached a maximum value of 97% for the aqueous extract and 92% for the ethanolic extraction at a concentration of 1 g L−1. These findings indicate that the extracts have significant potential as corrosion inhibitors for mild steel in HCl media.

By employing a combination of experimental and theoretical approaches, this work provides valuable insights into the inhibitory properties of P. graveolens extracts and expands the knowledge of corrosion inhibition. The results contribute to developing eco-friendly and efficient corrosion inhibitors to protect mild steel in acidic environments.