Acta Polytechnica doi:10.14311/AP.2018.58.0026 Acta Polytechnica 58(1):26–36, 2018 © Czech Technical University in Prague, 2018 available online at http://ojs.cvut.cz/ojs/index.php/ap THERMOCHEMICAL CALCULATIONS USING SERVICE- ORIENTED ARCHITECTURE IN THE WEB SERVICE FORM Pavel Horovčák, Ján Terpák∗ Institute of Control and Informatization of Production Processes, Technical University of Košice, Boženy Němcovej 3, 042 00 Košice, Slovak Republic ∗ corresponding author: jan.terpak@tuke.sk Abstract. The subject of this article is the service-oriented architecture utilization in the design and implementation of a web service that is intended to perform selected thermochemical calculations for chemical reactions. Computing functions allow the chemical reaction calculations, such as molar heat capacity, enthalpy, entropy and Gibbs free energy. In the next part, there is a description of each function, the method of service calling in the client application and the structure specification of outputs and error states of the service. In addition to computing functions, the web service also has a group of three information functions that characterize the purpose of the web service and its parameters, provide in tabular form a list of all web service functions and a list of all error states of the web service. The final section describes the presentation web service application with a demonstration of the specific calculations, the possibilities of using the service, and a further solution treatment. Keywords: thermochemical calculation; chemical reaction; service-oriented architecture; web service. 1. Introduction The basic tasks of chemical and process engineering mainly include an analysis of existing processes, de- sign of new processes, construction of technological equipment, optimizing the use of material and energy flows, monitoring, indirect measurement of process quantities and process control itself [1–5]. Thermo- chemical calculations of chemical reactions provide a basis for the quantification of processes in the chemi- cal industry, processing of raw materials, energy and so on. This is particularly the calculation of the molar heat capacity, heat of reaction, entropy, determining the direction of a chemical reaction based on the cal- culation of Gibbs free energy, determination of the equilibrium constant, etc. [6, 7]. For the implementation of thermochemical calcu- lations, there is currently a large number of software tools created using different information technologies. These technologies and program tools based on them begin at simple spreadsheets and desktop applications, continue with network applications using HTML and various server scripts and end at a service-oriented architecture [8] (SOA) through the web services [9] or enterprise services bus (ESB) [10], which is option- ally also applied in the form of a cloud computing [11] (CC). The concept of cloud computing is currently one of the most popular marketing witticisms in the IT industry [11]. The term Cloud with all its derivatives has been adopted as a metaphor for the Internet-based services. In work [12] several definitions and charac- teristics of the SOA have been given. The starting point is the basic definition, according to which the current SOA is an architecture that supports service orientation when using a web service [13]. Other defi- nitions [14, 15], specifications and characteristics [16] Figure 1. Web services and cloud computing [8] in more detail indicate the requirements, character- istics, forms, targets, platforms, interaction and ap- plications of the SOA. The relationship between the WS, SOA, and CC can be shown in the form of the Venn diagram [8] (Fig. 1). In this diagram, the WS is concluding (encapsulating) the CC because the CC uses the WS for the purposes of connection. However, the WS are and can be used also outside CC. Such WS use can be a part of the SOA, or may not, because the SOA does not need to use only the WS for the connection purposes. A view of the complexity of solved problems and the participation of numerous teams whose members often operate at different workplaces can be formu- lated by following requirements for functionality of software tools: unified management of the thermo- chemical data and calculations, the network user ac- cess to unified data and calculations, independence on hardware and software platforms on the user’s end and the modularity of calculations in terms of their use and dissemination. 26 http://dx.doi.org/10.14311/AP.2018.58.0026 http://ojs.cvut.cz/ojs/index.php/ap vol. 58 no. 1/2018 Thermochemical calculations using SOA in the web service form The article is a contribution in the field of thermo- chemical calculations using web services and provides the possibility of its use in different areas. 2. Overview of the current state The basis of thermochemical calculations of a chemical reaction are mainly the thermochemical data of the pure substances present in a chemical reaction. The source of thermochemical data are primarily book pub- lications such as [17, 18], wherein the thermochemical data are shown in the form of table values, depending on the temperature. In the case of automated calculation, the form of functions is more appropriate than table values. From publications, various forms of the functions are known [18, 19] and due to the number of substances and form of the functional dependence, it appears to be the best source known as NASA polynomials [19]. Other sources of thermochemical data are various electronic sources [20] which represent applications from a simple desktop to a network [21] application. The outcome of these applications is usually a table, which can be saved to a text file. Analysis of the current situation also shows the num- ber of software tools they support and implement ther- mochemical calculations. The best known software resources include especially FactSage [22], GWB [23], HSC Chemistry [24], MELTS [25], MTDATA [26], METSIM [27] and so on. We can also include web por- tals, such as CTserver [28], WebQC [29], or TEST [30], in the list of the program tools. Most software tools are commercial and some are also available for free, but with a considerably reduced substances database. One of the few providers of the WS in the field of thermodynamic calculations is CTserver Web Ser- vices [28], which provides a total of four different services through the WSDL (Web Services Descrip- tion Language) files. Services allow to obtain ther- modynamic properties of minerals and their reactions using an internally consistent database of Berman [31], to calculate the thermodynamic properties of other phases and solutions in the phase library of CTserver, perform calculations of the solubility model based on Papale [32] and carry out calculations of the FeTi- oxygen system by Ghiorso and Evans [33]. To make the data relating to the generation of free energies of reactions and minerals available, it was decided, at Geoscience Australia [34], to also create a web ser- vice that is not further specified (in the form of the WSDL). In the work [35], the authors write about the group of chemically oriented (chemoinformatics) web services (also without the WSDL) formed at In- diana University. The subject of the WS database infrastructure issues for thermochemical data [19, 36] and its application for the distributed computation of chemical equilibrium is being investigated at San Diego University in works [37, 38]. The data access over the web for different calculations (chemistry, bi- ology, etc.) in a documented WS is the subject of work [39]. CDK (Chemistry Development Kit) [40] can be called a clear forerunner of web access solutions through the WS to chemical data, which addresses the client side using Java applets and in addition to the web access also allows mutual communication of the server part with the R system. The WS for cal- culations of molecular similarities using the CDK are specified in paper [41] (with broken links to the WS specification). The use of SOA through WS, for example, calcu- lating the reactive effectiveness of atom-diatom sys- tems [42], is very rare. Web services herein are used for the allocation of computing capacity. Quantum reactive scattering studies of atom-diatom systems have nowadays become routine computing applica- tions when you need to either confirm the associated potential surface energy or to accurately estimate the effectiveness of the reactive system [43]. In terms of functionality, there are software re- sources offering options from simple outputs to more complex tools realizing thermochemical calculations. The single outputs include, in particular, molar mass calculations of the various substances, view of the chemical formula, balance of chemical reaction pro- viding primary thermochemical data, and the like. More complex instruments are provided according to the system parameters (open, closed, chemical re- action, etc.), generation of state quantities (tempera- ture, enthalpy, entropy, and the like), calculation of thermochemical properties of substances at the given temperature and pressure. They enable the acquisi- tion of number and chemical formulas of components in the current phase or mixture, and so on. In terms of technologies used, the individual soft- ware tools are developed using HTML, PHP, Java, SOA in WS form, and the like. Existing resources can also be divided from the point of view of an applica- tion implementation, i.e., whether it is a desktop or network application. Within the analysis of the existing software re- sources, the form of communication with the user also needs to be evaluated. In the case of simple closed systems, it is mainly of visual form consisting of values and graphs. Open systems offer the possibilities from data fields to various file formats. The XML structure can be considered as most appropriate output format mainly in terms of the creation of modular software tools and their linkage to source data. Based on analysis of existing software resources and in view of the requirements for program tools provid- ing thermochemical data and calculations, the most suitable form seems to be the use of a service-oriented architecture through WS. Web services, among other web resources to provide data and services such as calculations, stand out mainly due to their compatibil- ity, allowing users to use and combine different WSs, with the benefit that it does not matter in which pro- gramming resources they were created and not even on what software platform the service is implemented. 27 Pavel Horovčák, Ján Terpák Acta Polytechnica 3. Thermochemical calculations Selected thermochemical calculations of chemical reac- tion realised in the form of a web service and described in this article are based on the following general chem- ical reaction in the form 0 = m∑ j=1 νjNj, (1) where νj is the stoichiometric coefficient of substance Nj and m is the number of substances in the reaction. The value of νj is positive in the case of a product and is negative in case of a reactant. The molar heat capacity of the general chemical reaction is given by ∆C◦p(T) = R 7∑ i=1 ∆aiTi−3, (2) where R is the universal gas constant (8.314 J K−1 mol−1), ∆ai is the coefficient for a given chem- ical reaction based on the coefficients of the NASA polynomial for pure substances [12, 19] and T is the temperature (K). The reference state of the substances is generally taken to be the thermodynamically stable state at a temperature T0=298.15 K. Coefficient ∆ai is calculated as follows ∆ai = m∑ j=1 νjai,j, (3) where ai,j is i-th coefficient of the NASA polynomial for j-th substance of the chemical reaction (1). Calculation of the reaction enthalpy for a given chemical reaction is based on the integral of the molar heat capacity ∆rH◦(T) = ∆rH◦(T0) + ∫ T T0 ∆C◦p(T)dT, (4) where ∆rH◦(T0) is reaction the enthalpy for a given chemical reaction at a temperature T0 and is calcu- lated according to the formula ∆rH◦(T0) = m∑ j=1 νjH ◦ j (T0), (5) where H◦j (T0) is the enthalpy of the pure substance j-th at a temperature T0. The calculation of the entropy change for a given chemical reaction is based on the integral of the pro- portion of changes in molar heat capacity and tem- perature ∆rS◦(T) = ∆rS◦(T0) + ∫ T T0 ∆C◦p(T) T dT, (6) where ∆rS◦(T0) is the entropy change for a given chemical reaction at a temperature T0 and is calcu- lated according to the formula ∆rS◦(T0) = m∑ j=1 νjS ◦ j (T0), (7) where S◦j (T0) is the entropy of the pure substance j-th at a temperature T0. Gibbs free energy is calculated on the basis of changes in the enthalpy (4) and entropy (6) using the equation ∆rG◦(T) = ∆rH◦(T) −T∆rS◦(T). (8) Based on the equation ∆rG◦(T) = −RT ln K (9) the value of the logarithm of the equilibrium constant is equal to ln K = − ∆rG◦(T) RT . (10) Based on the equation (4) for calculating the enthalpy and van’t Hoff reaction isobar(∂ ln K ∂T ) p = ∆rH◦(T) RT 2 , (11) and after integration, we obtain the relation for the equilibrium constant logarithm ln K(T) = ln K(T0) − ∆rH◦(0) R ( 1 T − 1 T0 ) + ∆a1 2 ( 1 T 2 − 1 T 20 ) + ∆a2 ( 1 T0 − 1 + ln T T0 T ) + ∆a3 ln T T0 + 7∑ i=4 ∆ai (Ti−3 −Ti−30 ) (i− 2)(i− 3) , (12) where ∆rH◦(0) = ∆rH◦(T0) −R ( − ∆a1 T0 + 7∑ i=3 ∆aiTi−20 i− 2 ) . (13) The equilibrium constant for the general form of a chemical reaction (1) can be expressed using activi- ties [7]. If we set the activities of condensed compo- nents of the chemical reaction equal to one and the gaseous components are expressed by means of partial pressures, the equilibrium constant takes the form K = m∏ j=1 ( p◦j p◦ )νj (14) where p◦ is the normal pressure (101 325 Pa), p◦j are partial pressures. Based on the known value of the equilibrium con- stants and the specified total pressure, we can calcu- late the equilibrium partial pressure, or equilibrium composition, of the gas component. From the point of view of the number of gas components on the side of products, or reactants, and of the number of moles, different specific cases can occur. In the following, we consider only the cases where in the chemical reaction we have: 28 vol. 58 no. 1/2018 Thermochemical calculations using SOA in the web service form νi νj c3 c2 c1 c0 n n 0 0 1 + n √ K − n √ Kpc n 2n 0 1 n √ Kp◦ − n √ Kp◦pc n 2n 1 0 n √ K(p◦)2 − n √ K(p◦)2pc 2n 3n 1 − n √ K 2 n √ Kp◦pc − n √ Kp◦(pc)2 Table 1. The equation coefficients (17) for the number of moles of reactant (νi) and product (νj). • one gaseous product, • one gaseous reactant, • one gaseous product and one gaseous reactant. In the first case, where one gaseous product Nj with the number of moles of νj occurs in the chemical reaction, we can express the equilibrium constant as follows K = ( p◦j p◦ )νj , resp. p◦j = p ◦ νj √ K (15) In the second case, where one gaseous reactant Ni with the number of moles of νi occurs in the chemical reaction, it is essentially the first case that the chemi- cal reaction takes place in the opposite direction. The equilibrium constant has the form K = ( p◦i p◦ )νi , resp. p◦i = p◦ νi √ K (16) In the third case, where one gaseous product Nj with the number of moles of νj and one gaseous reactant Ni with the number of moles of νi occurs in the chemical reaction and the sum of the partial pressures is equal to the total pressure (pc = p◦i +p ◦ j ), then it is necessary to solve the following equation c3(p◦j ) 3 + c2(p◦j ) 2 + c1p◦j + c0 = 0, (17) where coefficients ci are given in the Tab. 1. The result of the equation (17) is the partial pres- sure of the gaseous product p◦j, or mole fraction xj = p◦j/pc, or mole percent. The calculations repre- sent a generalization of the calculations for gaseous components while generally only solutions for specific cases are found in the literature [6]. Finding direction of a chemical reaction or Gibbs free energy for known initial partial pressures is based on the following equation ∆rG◦(T) = ∆rG◦(T0) + RT ln ( (p◦)−∆ν m∏ j=1 (p◦j ) νj ) , (18) where the calculation of ∆rG◦(T ) is according to (9), and the equilibrium constant is determined by van’t Hoff reaction isobar (12). The value of ∆ν represents the change in the total quantity of moles of substances. 4. Web service design The purpose of the web service named as Ther- moChemDC (Thermo Chemical Data Calculations) is to do selected thermochemical calculations of a chemical reaction. The WS provides two groups of calculations. The first group includes the calcula- tion of the change of the molar heat capacity (2), the calculation of the heat of reaction (4), the cal- culation of the entropy change (6), the calculation of Gibbs free energy (8) and the calculation of the logarithm of the equilibrium constant (10). The cal- culations can be made for a specified temperature or a temperature interval. The second group in- cludes the calculation of the logarithm of the equi- librium constant (11), the calculation of the equilib- rium composition (14) and the calculation of Gibbs free energy (18) using the van’t Hoff reaction iso- bar (11). Above-mentioned calculations can be per- formed for a given temperature, pressure or partial pressure or their intervals. Other WS functions in- clude the balance control of chemical reaction and the decomposition of both sides of a chemical re- action on its individual components. In addition to computing functions, the WS also has a group of three information functions that are designed as multi-lingual. These functions characterize the pur- pose of WS ThermoChemDC and its parameters, pro- vide in tabular form a list of all functions of the WS and also list of all error states of WS Ther- moChemDC. In its activities, the WS uses additional web ser- vices that have been proposed and implemented in our department. WS ThermPropDC [12] provides ther- mochemical properties of chemical substances (1154 substances and their 1817 phases) for the purposes of individual calculations. WS ChemForm [44] is used to convert standard notation of the chemical formula stored in the ASCII form to the HTML format. Web service ErrorService is designed for the selection of error status meaning for a specified WS using its nu- meric identifier for the specified error’s code, and in the chosen language. WS ThermoChemDC directly uses the WS ThermPropDC based on the use of NASA resources (NASA Polynomials) [12, 19, 36] in all calculations, which include also other published dependences [6, 17, 45, 46] and are supplemented with the CAS [47] 29 Pavel Horovčák, Ján Terpák Acta Polytechnica # Meaning of function Function parameters 1 Enthalpy Reaction, Language, Temperature [K] 2 Enthalpy for the temperature interval Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 3 Gibbs energy Reaction, Language, Temperature [K] 4 Gibbs energy for the temperature interval Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 5 Entropy Reaction, Language, Temperature [K] 6 Entropy for the temperature interval Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 7 Logarithm of the equilibrium constant Reaction, Language, Temperature [K] 8 Logarithm of the equilibrium constant for the temperature interval Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 9 Molar heat capacity Reaction, Language, Temperature [K] 10 Molar heat capacity for the temperature interval Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 11 Control of chemical reactions balance Reaction, Language 12 Decomposition of chemical reaction Reaction, Language 13 Logarithm of the equilibrium constant (van’t Hoff) Reaction, Language, Temperature [K] 14 Logarithm of the equilibrium constant for the temperature interval (van’t Hoff) Reaction, Language, Temperature1 [K], Temperature2 [K], Step [K] 15 Equilibrium composition Reaction, Language, Temperature [K], Pressure [Pa] 16 Equilibrium composition for the pressures interval Reaction, Language, Temperature [K], Pressure1 [Pa], Pressure2 [Pa], Step [Pa] 17 Gibbs energy (van’t Hoff) Reaction, Language, Temperature [K], Pressure [Pa], Partial Pressure [Pa] 18 Gibbs energy for the pressures interval (van’t Hoff) Reaction, Language, Temperature [K], Pressure [Pa], Partial Pressure1 [Pa], Partial Pressure2 [Pa], Step [Pa] Table 2. List of web service ThermoChemDC functions parameter and with one or more names of substances in two languages. In some cases, the value of 000000 is used for the CAS identifier, which indicates the fact that it failed to detect CAS value for a given substance at any website. The CAS identifier is optionally stored in the database infrastructure of the WS as a link to the appropriate website [48– 54]. Similarly, you can choose to save the formula of the substance in a standard ASCII form or in a HTML format (the form of the upper/lower index), which ensures the WS ChemForm [44]. General ad- ministration of the database infrastructure of the WS ThermPropDC provides a standalone application ad- min_tp. This application allows a gradual creation of all tables in the operation and preparation ser- vice’s database, populating tables with NASA, CAS data and the names from the relevant files, transfer complete records to the operation database, option- ally manually completing the CAS identifier and the names of substances and/or perform a backup of the database into a file. WS ThermoChemDC is implemented in a PHP de- velopment environment (required PHP version 5 and above) and as a database system, it uses MySQL in version 5 also. The current version of the WS with a class named ThermoChemDC includes a total of 52 methods, while five of them are service interfaces and are also specified in the file ThermoChemDC.wsdl. Other methods are internal and intended for differ- ent calculations or control, creating XML structures, auxiliary, declaratory, folding tasks, a communication with the database system or are complementary. 5. The methods and functions of web service The WS ThermoChemDC provides users with a total of five methods through the WSDL file. The first two 30 vol. 58 no. 1/2018 Thermochemical calculations using SOA in the web service form # Meaning of error 1 One of the reactants is not in the database 2 One of the products is not in the database 3 The specified temperature is outside the permitted interval (left side — reactants) 4 Syntax error in the reaction writing 5 Incorrect reaction — reactants and products do not contain the same chemical elements 6 Calling a non-existent function of the web service — method getThermoChemCalc 7 Incorrect parameters (1 or more) of web service calling — method getThermoChemCalc 8 Used web service is off-line 9 Connection error to database (db server): Access denied for user 10 Error when selecting error meaning from db table [ws_errors] 11 Incorrect reaction balance — reactants and products do not contain the same number of chemical elements 12 The reaction does not contain any gaseous compound 13 The numbers of gaseous components of the reaction greater than 1 are not yet solved 14 Calling a non-existent function of the web service — method getParcPresCalc 15 Incorrect parameters (1 or more) of web service calling — method getParcPresCalc 16 The first parameter of the cubic parabola respectively Kp1 is equal to zero 17 Error when selecting function meaning from db table [ws_functions] 18 Error when selecting function parameters from db table [ws_funcparams] 19 The specified temperature is outside the permitted interval (right side — products) Table 3. List of web service ThermoChemDC error states methods are computational — getThermoChemCalc and getParcPresCalc, the other three methods are informational — getHelp, getWsFunc, and getError. Each calculation method can operate in several modes and thus perform the various functions. Calculation methods have from three to six parameters. The first three parameters are required, the first parameter specifies the specific function of WS, the second param- eter contains a chemical reaction and the third param- eter defines the language of outputs or error messages of the WS. Other parameters are related to the desired function of the calculation method according to Tab. 2. The method getThermoChemCalc is used to solve the functions 1–12, the method getParcPresCalc to solve the functions 13–18. The method getHelp provides the user of the WS with a brief description of the service — purpose, WSDL file, list of methods, their purpose and param- eters, description of their outputs and correspond- ing XML structures, and other WS used within the service itself. The method getWsFunc provides a list of all WS functions together with parameters of these functions in a tabular form — Tab. 2. The first column is the function code; the second col- umn is a more detailed description of the relevant service function, and a list of its parameters. The return value of getError method is a list of all error states of ThermoChemDC WS, which is also imple- mented in a tabular form — Tab. 3. The first col- umn is the error code; in the second column, there is a more detailed description of the service’s error state. All three informational methods have one parameter $lang that defines the selected language of the output of above methods. 6. Web service call WS ThermoChemDC is available to clients through a WSDL file, which is located at http://omega.tuke. sk/wsdl/ThermoChemDC.wsdl. This file specifies all the attributes required for the WS call. The WS can be used either in a separate client application or in another WS. Calling the WS consists of a sequence of two steps. The first step is a instantiated object that represents the client part of the WS. To create an instance, a WSDL service file is used. The sec- ond step is the appropriate method call, which is the WS function with the corresponding parameters. The object instance created in the previous step is used for the calling. The WS calling is supported by all current development environments (whether in the client application or in other WS). These are primarily web development environments (e.g., PHP, Java, ASP, Ajax), but they also include desktop development en- vironments (e.g., MATLAB). The above-mentioned sequence of the WS call steps is then dependent on the chosen development environment for the imple- mentation of the WS call. For an illustration of calling the WS we describe the procedures in a development environment PHP. Step one, create an object instance, has the form: $wsdl = "http://omega.tuke.sk/wsdl/"; $urlwsdl = $wsdl."ThermoChemDC.wsdl"; $c = new SoapClient($urlwsdl); where $urlwsdl indicates the location of the WSDL file of the WS (its URL) and $c is an instance of an object to interact with the WS. The second step is to call the desired method and/or the WS function through the instance $c and, after entering specific 31 http://omega.tuke.sk/wsdl/ThermoChemDC.wsdl http://omega.tuke.sk/wsdl/ThermoChemDC.wsdl Pavel Horovčák, Ján Terpák Acta Polytechnica Figure 2. Sample output of a single client of Ther- moChemDC WS parameters, for example, to calculate the enthalpy ($r=1), may take the form: $r = 1; $t = ’400’; $l=’0’; $e = ’CaCO3(cr)=CaO(cr)+CO2’; $xml = $c->getThermoChemCalc($r,$e,$l,$t); print $xml; Because the WS returns as the output value the XML structure ($xml), the easiest way of its presentation is the direct visual display of this structure. Variables $r, $e, $l, $t are calling parameters of the selected WS function, where $r is the selection of the function (WS mode), $e contains a chemical equation, $l is the language and $t is the temperature. The appearance of the presentation results on the screen justifies using a CSS file, in which to each spe- cific element of the output XML structure of the web service, a corresponding way of view is pre- scribed (such as appropriate colourfulness of indi- vidual items). Those items of the XML structure that should not, for any reason, be displayed can be identified as ’display: none’. The simplicity of creating a client application illustrates a sample of an enthalpy calculation (mode 1) for the reaction ’CaCO3(cr)=CaO(cr)+CO2’ for a given temperature (400 K). The script has the form: