Eötvös Quantum Utilities  v5.0.144
Providing the Horsepowers in the Quantum Realm
XMLinput.m
Go to the documentation of this file.
1 %% Eotvos Quantum Transport Utilities - XMLinput
2 % Copyright (C) 2009-2017 Peter Rakyta, Ph.D.
3 %
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation, either version 3 of the License, or
7 % (at your option) any later version.
8 %
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License for more details.
13 %
14 % You should have received a copy of the GNU General Public License
15 % along with this program. If not, see http://www.gnu.org/licenses/.
16 %
17 %> @addtogroup filters Filters
18 %> @{
19 %> @file XMLinput.m
20 %> @brief This function is an input filter that parses XML file and fills up the parameter structures necessary to initialize EQuUs classes.
21 %> @}
22 %> @brief This function is an input filter that parses XML file and fills up the parameter structures necessary to initialize EQuUs classes.
23 %> @param filename A string containing the filename of the XML file.
24 %> @return [1] An instance of structure #Opt
25 %> @return [2] An instance of structure #param
26 function [Opt, param] = XMLinput( filename )
27 
28 
29 
30 parameter_names = { 'Decimation', 'Decimation_block', 'magnetic_field', 'magnetic_field_trans_invariant', 'Lattice_Type', ...
31  'Simple_Green_Function', 'Linear_Regression_in_B', 'BdG', 'Spin', 'Silent', 'usingDualModes', 'debug', 'workers', 'custom_Hamiltonians' };
32 
34 parseXML( filename )
35 
37 
38 %TODO
39 % check data consistency like LeadNum, orientation VS Lead_orientation
40 
41  %% setDefaults
42  %> @brief This function sets default values to the parameter structures
43  function setDefaults()
44 
45  Opt = structures('Opt');
46  Opt.Decimation = 4;
47  Opt.Decimation_block = 151;
48  Opt.NofLeads = 0;
49  Opt.magnetic_field = 0;
50  Opt.magnetic_field_trans_invariant = true;
51  Opt.Lattice_Type = [];
52  Opt.Simple_Green_Function = 0;
53  Opt.Linear_Regression_in_B = 1;
54  Opt.BdG = 0;
55  Opt.Spin = 0;
56  Opt.Silent = 0;
57  Opt.usingDualModes = 1;
58  Opt.debug = 0;
59  Opt.workers = [];
60  Opt.custom_Hamiltonians = [];
61 
62  param = structures('param');
63 
64  % skeletons for physical parameters of the scattering region and leads
65  param.scatter = struct();
66 
67  param.scatter.shape = structures('shape');
68 
69  param.Leads = cell(0);
70 
71  end
72 
73  %% parseXML
74  %> @brief This opens the XML file and fills up the parameter structures
75  %> @param filename A string containing the filename of the XML file.
76  function parseXML(filename)
77 
78  cCommonFunctions = CommonFunctions();
79  if cCommonFunctions.isOctave()
80  parser = javaObject('org.apache.xerces.parsers.DOMParser');
81  parser.parse(filename);
82  tree = parser.getDocument;
83  else
84  tree = xmlread(filename);
85  end
86 
87  traverseNodes( tree );
88 
89  end
90 
91 
92  %% traverseNodes
93  %> @brief This function parses over the attributes of the tree node
94  %> @param theNode An instance of XML DOM node.
95  function traverseNodes( theNode )
96  % Recurse over node children.
97 
98  if theNode.hasChildNodes
99  childNodes = theNode.getChildNodes;
100  numChildNodes = childNodes.getLength;
101  else
102  return
103  end
104 
105 
106  for count = 1:numChildNodes
107  theChild = childNodes.item(count-1);
108 
109  if strcmpi(char(theChild.getNodeName), 'parameters' )
110  traverseNodes( theChild )
111  elseif strcmpi(char(theChild.getNodeName), 'computing_parameters' )
112  setComputingParameters( theChild )
113  elseif strcmpi(char(theChild.getNodeName), 'Scatter_region' )
114  setScatterParameters( theChild )
115  elseif strcmpi(char(theChild.getNodeName), 'Lead_parameters' )
116  setLeadParameters( theChild )
117  end
118 
119 
120 
121  %children(count) = makeStructFromNode(theChild);
122  end
123  end
124 
126  %> @brief This function sets computing parameters in the structure #Opt
127  %> @param theNode An instance of XML DOM node.
128  function setComputingParameters( theNode )
129  if theNode.hasChildNodes
130  childNodes = theNode.getChildNodes;
131  numChildNodes = childNodes.getLength;
132  else
133  return
134  end
135 
136  for count = 1:numChildNodes
137  theChild = childNodes.item(count-1);
138 
139  if ismember(char(theChild.getNodeName), parameter_names )
140  attributes = parseAttributes(theChild);
141  setOptValue( attributes, char(theChild.getNodeName) )
142  end
143  end
144 
145  end
146 
147 
148  %% setScatterParameter
149  %> @brief This function sets parameters for the scattering region
150  %> @param theNode An instance of XML DOM node.
151  function setScatterParameters( theNode )
152  if theNode.hasChildNodes
153  childNodes = theNode.getChildNodes;
154  numChildNodes = childNodes.getLength;
155  else
156  return
157  end
158 
159  for count = 1:numChildNodes
160  theChild = childNodes.item(count-1);
161 
162  if ismember(char(theChild.getNodeName), parameter_names )
163  attributes = parseAttributes(theChild);
164  setOptValue( attributes, char(theChild.getNodeName) )
165  elseif strcmpi(char(theChild.getNodeName), 'shape' )
166  param.scatter = createShape( theChild, param.scatter );
167  elseif strcmpi(char(theChild.getNodeName), 'Atom' )
168  param.scatter = createAtom( theChild, param.scatter );
169  else
170  param.scatter = setParamValue( param.scatter, theChild );
171  end
172  end
173 
174  end
175 
176  %% createAtom
177  %> @brief This function creates a structure Atom consisting of the atomic data of the sites
178  %> @param theNode A node of an XML DOM.
179  %> @return Returns with the modificated parameter structure
180  function param_structure = createAtom( theNode, param_structure )
181 
182  % determine, whether the node has child nodes or not
183  if ~theNode.hasChildNodes
184  return
185  end
186 
187  % initialize cell array of Atoms if necessary
188  if ~isfield(param_structure, 'Atom') || isempty( param_structure.Atom )
189  param_structure.Atom = structures('Atom');
190  end
191 
192  % determine the new length of the cell array
193  atom_idx = length( param_structure.Atom ) + 1;
194 
195  % fill in input data
196  childNodes = theNode.getChildNodes;
197  numChildNodes = childNodes.getLength;
198 
199  for count = 1:numChildNodes
200  theChild = childNodes.item(count-1);
201 
202  if strcmpi(char(theChild.getNodeName), 'PL' )
203  % the principal layer
204  attributes = parseAttributes( theChild );
205  param_structure.Atom(atom_idx).PL = str2double(attributes.value);
206  elseif strcmpi(char(theChild.getNodeName), 'Id' )
207  % the identification umber
208  attributes = parseAttributes( theChild );
209  param_structure.Atom(atom_idx).Id = str2double(attributes.value);
210  end
211 
212  end
213 
214  end
215 
216  %% createShape
217  %> @brief This function creates structure shape for the scattering region
218  %> @param theNode A node of an XML DOM.
219  %> @return Returns with the modificated parameter structure
220  function param_structure = createShape( theNode, param_structure )
221  if theNode.hasChildNodes
222  childNodes = theNode.getChildNodes;
223  numChildNodes = childNodes.getLength;
224  else
225  return
226  end
227 
228  shape = structures('shape');
229 
230  for count = 1:numChildNodes
231  theChild = childNodes.item(count-1);
232 
233  if strcmpi(char(theChild.getNodeName), 'width' )
234  attributes = parseAttributes( theChild );
235  shape.width = str2double( attributes.value );
236  elseif strcmpi(char(theChild.getNodeName), 'height' )
237  attributes = parseAttributes( theChild );
238  shape.height = str2double( attributes.value );
239  end
240  end
241 
242  param_structure.shape = shape;
243  end
244 
245 
247  %> @brief This function sets parameters of the Leads
248  %> @param theNode A node of an XML DOM.
249  %> @return Returns with a cell array of lead parameters
250  function setLeadParameters( theNode )
251  if theNode.hasChildNodes
252  childNodes = theNode.getChildNodes;
253  numChildNodes = childNodes.getLength;
254  else
255  return
256  end
257 
258  % do a for loop to cover all the leads
259  for count = 1:numChildNodes
260  theChild = childNodes.item(count-1);
261 
262  if strcmpi(char(theChild.getNodeName), 'lead' )
263  param.Leads = createLeadNode( theChild, param.Leads );
264  elseif strcmpi(char(theChild.getNodeName), 'NofLeads' )
265  attributes = parseAttributes(theChild);
266  setOptValue( attributes, char(theChild.getNodeName) )
267  end
268 
269 
270  end
271 
272  end
273 
274  %% createLeadNode
275  %> @brief This function fills up data from one particular lead node
276  %> @param theNode A node of an XML DOM.
277  %> @param Leads A cell array of lead parameters.
278  %> @return Returns with the updated cell array of lead parameters.
279  function Leads = createLeadNode( theNode, Leads )
280  lead_attributes = parseAttributes( theNode );
281  num = str2double(lead_attributes.num);
282 
283  try
284  params = Leads{num};
285  catch err
286  params = structures('lead_param');
287  end
288 
289  if theNode.hasChildNodes
290  childNodes = theNode.getChildNodes;
291  numChildNodes = childNodes.getLength;
292  else
293  return
294  end
295 
296 
297 
298  for count = 1:numChildNodes
299  theChild = childNodes.item(count-1);
300  params = setParamValue( params, theChild );
301  end
302 
303 
304  Leads{num} = params;
305 
306  end
307 
308 
309  %% setOptValue
310  %> @brief This sets a value for a field in the Opt structure
311  %> @param attributes A sata structure extracted from the XML DOM node.
312  %> @param attribname String of the attribute name to be set
313  function setOptValue( attributes, attribname )
314 
315  if ( isfield( attributes, 'value') )
316  if ~isnan( str2double( attributes.('value') ) )
317  Opt.( attribname ) = str2double( attributes.('value') );
318  else
319  Opt.( attribname ) = attributes.('value');
320  end
321  else
322  display(['bad attribute: ', attribname ])
323  end
324 
325  end
326 
327  %% setParamValue
328  %> @brief This function sets a value for a field in the #param_structure
329  %> @param param_structure Data structure containing the physical parameters
330  %> @param node An instance of XML DOM node.
331  %> @return Returns with the updated structure of parameters
332  function param_structure = setParamValue( param_structure, node )
333 
334  attributes = parseAttributes( node );
335 
336  if isfield( attributes, 'value' )
337  % make a difference between character and numeric type values (if the type of the input parameter was mistaken or missing)
338  value = str2double(attributes.value);
339  if isnan( value )
340  param_structure.(char(node.getNodeName)) = attributes.value;
341  else
342  param_structure.(char(node.getNodeName)) = value;
343  end
344 
345  elseif isfield( attributes, 'abs' ) && isfield( attributes, 'phase' )
346  param_structure.(char(node.getNodeName)) = str2double(attributes.abs)*exp(1i*str2double(attributes.phase));
347  end
348 
349  end
350 
351 
352 
353  %% parseAttributes
354  %> @brief This function parses the attributes of the XML node
355  %> @param theNode An instance of XML DOM node.
356  %> @return Returns with the structure of the extracted parameters
357  function attributes = parseAttributes(theNode)
358  % Create attributes structure.
359 
360  attributes = [];
361  if theNode.hasAttributes
362  theAttributes = theNode.getAttributes;
363  numAttributes = theAttributes.getLength;
364  attributes = struct();
365  else
366  return
367  end
368 
369  for count = 1:numAttributes
370  attrib = theAttributes.item(count-1);
371  attributes.( char(attrib.getName) ) = char(attrib.getValue);
372  end
373 
374 
375  end
376 
377 end
function createAtom(theNode, param_structure)
This function creates a structure Atom consisting of the atomic data of the sites.
Structure Atom contains the atomic identifiers of the sites.
Definition: structures.m:148
function parseXML(filename)
This opens the XML file and fills up the parameter structures.
function parseAttributes(theNode)
This function parses the attributes of the XML node.
Structure Opt contains the basic computational parameters used in EQuUs.
Definition: structures.m:60
Structure shape contains data about the geometry of the scattering region.
Definition: structures.m:106
function XMLinput(filename)
This function is an input filter that parses XML file and fills up the parameter structures necessary...
function setComputingParameters(theNode)
This function sets computing parameters in the structure Opt.
function Transport(Energy, B)
Calculates the conductance at a given energy value.
function createShape(theNode, param_structure)
This function creates structure shape for the scattering region.
A class providing function handle to reduce the number of sites in the Hamiltonian via decimation pro...
Definition: Decimation.m:29
A class containing common basic functionalities.
function setDefaults()
This function sets default values to the parameter structures.
function createLeadNode(theNode, Leads)
This function fills up data from one particular lead node.
Structure param contains data structures describing the physical parameters of the scattering center ...
Definition: structures.m:45
Structure sites contains data to identify the individual sites in a matrix.
Definition: structures.m:187
function ValidateStructures(Opt, param)
This function verify the input structures Opt and param and create system specific data structures.
function traverseNodes(theNode)
This function parses over the attributes of the tree node.
function setLeadParameters(theNode)
This function sets parameters of the Leads.
function setParamValue(param_structure, node)
This function sets a value for a field in the #param_structure.
function setOptValue(attributes, attribname)
This sets a value for a field in the Opt structure.
function structures(name)
function setScatterParameters(theNode)
This function sets parameters for the scattering region.