Eötvös Quantum Utilities  v4.9.146
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','WorkingDir' };
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
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  atom_idx = 1;
191  else
192  % determine the new length of the cell array
193  atom_idx = length( param_structure.Atom ) + 1;
194  end
195 
196  % determine the new length of the cell array
197 % atom_idx = length( param_structure.Atom ) + 1;
198 
199  % fill in input data
200  childNodes = theNode.getChildNodes;
201  numChildNodes = childNodes.getLength;
202 
203  for count = 1:numChildNodes
204  theChild = childNodes.item(count-1);
205 
206  if strcmpi(char(theChild.getNodeName), 'PL' )
207  % the principal layer
208  attributes = parseAttributes( theChild );
209  param_structure.Atom(atom_idx).PL = str2double(attributes.value);
210  elseif strcmpi(char(theChild.getNodeName), 'Id' )
211  % the identification umber
212  attributes = parseAttributes( theChild );
213  param_structure.Atom(atom_idx).Id = str2double(attributes.value);
214  end
215 
216  end
217 
218  end
219 
220  %% createShape
221  %> @brief This function creates structure shape for the scattering region
222  %> @param theNode A node of an XML DOM.
223  %> @return Returns with the modificated parameter structure
224  function param_structure = createShape( theNode, param_structure )
225  if theNode.hasChildNodes
226  childNodes = theNode.getChildNodes;
227  numChildNodes = childNodes.getLength;
228  else
229  return
230  end
231 
232  shape = structures('shape');
233 
234  for count = 1:numChildNodes
235  theChild = childNodes.item(count-1);
236 
237  if strcmpi(char(theChild.getNodeName), 'width' )
238  attributes = parseAttributes( theChild );
239  shape.width = str2double( attributes.value );
240  elseif strcmpi(char(theChild.getNodeName), 'height' )
241  attributes = parseAttributes( theChild );
242  shape.height = str2double( attributes.value );
243  end
244  end
245 
246  param_structure.shape = shape;
247  end
248 
249 
251  %> @brief This function sets parameters of the Leads
252  %> @param theNode A node of an XML DOM.
253  %> @return Returns with a cell array of lead parameters
254  function setLeadParameters( theNode )
255  if theNode.hasChildNodes
256  childNodes = theNode.getChildNodes;
257  numChildNodes = childNodes.getLength;
258  else
259  return
260  end
261 
262  % do a for loop to cover all the leads
263  for count = 1:numChildNodes
264  theChild = childNodes.item(count-1);
265 
266  if strcmpi(char(theChild.getNodeName), 'lead' )
267  param.Leads = createLeadNode( theChild, param.Leads );
268  elseif strcmpi(char(theChild.getNodeName), 'NofLeads' )
269  attributes = parseAttributes(theChild);
270  setOptValue( attributes, char(theChild.getNodeName) )
271  end
272 
273 
274  end
275 
276  end
277 
278  %% createLeadNode
279  %> @brief This function fills up data from one particular lead node
280  %> @param theNode A node of an XML DOM.
281  %> @param Leads A cell array of lead parameters.
282  %> @return Returns with the updated cell array of lead parameters.
283  function Leads = createLeadNode( theNode, Leads )
284  lead_attributes = parseAttributes( theNode );
285  num = str2double(lead_attributes.num);
286 
287  try
288  params = Leads{num};
289  catch err
290  params = structures('lead_param');
291  end
292 
293  if theNode.hasChildNodes
294  childNodes = theNode.getChildNodes;
295  numChildNodes = childNodes.getLength;
296  else
297  return
298  end
299 
300 
301 
302  for count = 1:numChildNodes
303  theChild = childNodes.item(count-1);
304 % params = setParamValue( params, theChild );
305  if strcmpi(char(theChild.getNodeName), 'Atom' )
306  params = createAtom( theChild, params );
307  else
308  params = setParamValue( params, theChild );
309  end
310  end
311 
312 
313  Leads{num} = params;
314 
315  end
316 
317 
318  %% setOptValue
319  %> @brief This sets a value for a field in the Opt structure
320  %> @param attributes A sata structure extracted from the XML DOM node.
321  %> @param attribname String of the attribute name to be set
322  function setOptValue( attributes, attribname )
323 
324  if ( isfield( attributes, 'value') )
325  if ~isnan( str2double( attributes.('value') ) )
326  Opt.( attribname ) = str2double( attributes.('value') );
327  else
328  Opt.( attribname ) = attributes.('value');
329  end
330  else
331  display(['bad attribute: ', attribname ])
332  end
333 
334  end
335 
336  %% setParamValue
337  %> @brief This function sets a value for a field in the #param_structure
338  %> @param param_structure Data structure containing the physical parameters
339  %> @param node An instance of XML DOM node.
340  %> @return Returns with the updated structure of parameters
341  function param_structure = setParamValue( param_structure, node )
342 
343  attributes = parseAttributes( node );
344 
345  if isfield( attributes, 'value' )
346  % make a difference between character and numeric type values (if the type of the input parameter was mistaken or missing)
347  value = str2double(attributes.value);
348  if isnan( value )
349  param_structure.(char(node.getNodeName)) = attributes.value;
350  else
351  param_structure.(char(node.getNodeName)) = value;
352  end
353 
354  elseif isfield( attributes, 'abs' ) && isfield( attributes, 'phase' )
355  param_structure.(char(node.getNodeName)) = str2double(attributes.abs)*exp(1i*str2double(attributes.phase));
356  end
357 
358  end
359 
360 
361 
362  %% parseAttributes
363  %> @brief This function parses the attributes of the XML node
364  %> @param theNode An instance of XML DOM node.
365  %> @return Returns with the structure of the extracted parameters
366  function attributes = parseAttributes(theNode)
367  % Create attributes structure.
368 
369  attributes = [];
370  if theNode.hasAttributes
371  theAttributes = theNode.getAttributes;
372  numAttributes = theAttributes.getLength;
373  attributes = struct();
374  else
375  return
376  end
377 
378  for count = 1:numAttributes
379  attrib = theAttributes.item(count-1);
380  attributes.( char(attrib.getName) ) = char(attrib.getValue);
381  end
382 
383 
384  end
385 
386 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.
function()
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.