49#include <libxml/encoding.h>
50#include <libxml/xmlwriter.h>
51#include <libxml/xmlreader.h>
52#include <libxml/parser.h>
55extern xmlNodePtr
findnode (xmlNodePtr startnode,
char * nname);
69 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"chemistry");
71 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST (
const xmlChar *)
"atoms",
"%d", this_proj -> natomes);
73 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"species");
76 val = g_strdup_printf(
"%d", this_proj -> nspec);
77 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"number", BAD_CAST
val);
81 for ( i=0 ; i<this_proj -> nspec ; i++ )
83 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"label");
85 val = g_strdup_printf(
"%d", i);
86 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"id", BAD_CAST
val);
90 val = g_strdup_printf(
"%d", this_proj ->
chemistry -> nsps[i]);
91 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"num", BAD_CAST
val);
95 rc = xmlTextWriterWriteFormatString (writer,
"%s",
exact_name(this_proj ->
chemistry -> label[i]));
97 rc = xmlTextWriterEndElement(writer);
100 rc = xmlTextWriterEndElement(writer);
101 if (rc < 0)
return 1;
102 rc = xmlTextWriterEndElement(writer);
103 if (rc < 0)
return 1;
119 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"coordinates");
120 if (rc < 0)
return 1;
123 for ( i=0 ; i<this_proj -> natomes ; i++ )
125 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"atom");
126 if (rc < 0)
return 1;
127 val = g_strdup_printf(
"%d", i+1);
128 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"id", BAD_CAST
val);
130 if (rc < 0)
return 1;
132 val = g_strdup_printf(
"%d", this_proj ->
atoms[0][i].sp);
133 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"sp", BAD_CAST
val);
135 if (rc < 0)
return 1;
137 val = g_strdup_printf(
"%f", this_proj ->
atoms[0][i].
x);
138 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"x", BAD_CAST
val);
140 if (rc < 0)
return 1;
141 val = g_strdup_printf(
"%f", this_proj ->
atoms[0][i].
y);
142 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"y", BAD_CAST
val);
144 if (rc < 0)
return 1;
145 val = g_strdup_printf(
"%f", this_proj ->
atoms[0][i].
z);
146 rc = xmlTextWriterWriteAttribute(writer, BAD_CAST (
const xmlChar *)
"z", BAD_CAST
val);
148 if (rc < 0)
return 1;
149 rc = xmlTextWriterEndElement(writer);
150 if (rc < 0)
return 1;
152 rc = xmlTextWriterEndElement(writer);
153 if (rc < 0)
return 1;
168 xmlTextWriterPtr writer;
170 writer = xmlNewTextWriterFilename(this_proj -> coordfile, 0);
171 if (writer == NULL)
return 1;
172 rc = xmlTextWriterSetIndent(writer, 1);
173 if (rc < 0)
return 1;
178 rc = xmlTextWriterStartDocument(writer, NULL,
MY_ENCODING, NULL);
179 if (rc < 0)
return 1;
181 rc = xmlTextWriterWriteComment(writer, (
const xmlChar *)_(
" Simple chemical library XML file "));
182 if (rc < 0)
return 1;
183 rc = xmlTextWriterStartElement(writer, BAD_CAST
"scl-xml");
184 if (rc < 0)
return 1;
188 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST (
const xmlChar *)
"class",
"%s",
"Misc");
189 if (rc < 0)
return 1;
192 rc = xmlTextWriterStartElement(writer, BAD_CAST (
const xmlChar *)
"names");
193 if (rc < 0)
return 1;
196 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST (
const xmlChar *)
"library-name",
"%s",
"Name in atomes library");
197 if (rc < 0)
return 1;
200 rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST (
const xmlChar *)
"iupac-name",
"%s",
"IUPAC name");
201 if (rc < 0)
return 1;
212 rc = xmlTextWriterEndElement(writer);
213 if (rc < 0)
return 1;
224 rc = xmlTextWriterEndElement(writer);
225 if (rc < 0)
return 1;
227 rc = xmlTextWriterEndDocument(writer);
228 if (rc < 0)
return 1;
230 xmlFreeTextWriter(writer);
265 xmlTextReaderPtr reader;
266 const xmlChar sml[8]=
"scl-xml";
267 xmlNodePtr racine, chem_node;
268 xmlNodePtr at_node, sp_node, coord_node;
269 xmlNodePtr spec_node, lab_node, lot_node;
285 if (doc == NULL)
return 0;
286 racine = xmlDocGetRootElement(doc);
287 if (g_strcmp0 ((
char *)(racine -> name), (
char *)sml) != 0)
292 chem_node =
findnode(racine -> children,
"chemistry");
294 at_node =
findnode (chem_node -> children,
"atoms");
296 content = xmlNodeGetContent(at_node);
301 sp_node =
findnode (chem_node -> children,
"species");
303 spec_node = sp_node -> properties -> children;
305 content = xmlNodeGetContent(spec_node);
309 lab_node = sp_node -> children;
316 lab_node =
findnode (lab_node,
"label");
318 content = xmlNodeGetContent(lab_node);
319 val = g_strdup_printf (
"%s", content);
324 xspec = lab_node -> properties;
328 lot_node = xspec -> children;
330 if (g_strcmp0 (
"num",(
char *)xspec -> name) == 0)
332 content = xmlNodeGetContent(lot_node);
336 xspec = xspec -> next;
338 lab_node = lab_node -> next;
345 at_node =
findnode (racine -> children,
"coordinates");
347 coord_node = at_node -> children;
351 coord_node =
findnode (coord_node,
"atom");
353 xspec = coord_node -> properties;
357 lot_node = xspec -> children;
359 content = xmlNodeGetContent(lot_node);
360 if (g_strcmp0 (
"x",(
char *)xspec -> name) == 0)
364 else if (g_strcmp0 (
"y",(
char *)xspec -> name) == 0)
368 else if (g_strcmp0 (
"z",(
char *)xspec -> name) == 0)
372 else if (g_strcmp0 (
"sp",(
char *)xspec -> name) == 0)
378 xspec = xspec -> next;
380 coord_node = coord_node -> next;
383 xmlFreeTextReader(reader);
Binding to the Fortran90 subroutines.
Callback declarations for main window.
void allocatoms(project *this_proj)
allocate project data
integer(kind=c_int) function chemistry()
double * allocdouble(int val)
allocate a double * pointer
int * allocint(int val)
allocate an int * pointer
double string_to_double(gpointer string)
convert string to double
Global variable declarations Global convenience function declarations Global data structure defin...
gchar * exact_name(gchar *name)
short cut to print string without spaces
Messaging function declarations.
Function declarations for reading atomes project file Function declarations for saving atomes proje...
int open_sml_file_out_of_library()
read 'Simple chemical library XML' file outside of atomes library
xmlNodePtr findnode(xmlNodePtr startnode, char *nname)
find XML node
int save_sml_coordinates(xmlTextWriterPtr writer, project *this_proj)
write content of SML file
double get_z_from_periodic_table(gchar *lab)
get Z from atom label
int save_sml_chemistry(xmlTextWriterPtr writer, project *this_proj)
write content of SML file
int clean_xml_data(xmlDoc *doc, xmlTextReaderPtr reader)
free XML data
int sml_writer(project *this_proj)
write content of SML file
int write_sml(project *this_proj)
write SML file
Functions declaration to read atomic coordinates.