1 # Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
3 # Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 # CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the License.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with this library; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 # See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
22 import xml.dom.minidom
23 from ATOMGEN_Data import *
25 __doc_name__ = "Atomic"
26 __doc_tag__ = "document"
27 __mol_tag__ = "molecule"
29 __name_attr__ = "name"
34 def readXmlFile( fileName ):
36 Reads the atomic data from the XML file
39 doc = xml.dom.minidom.parse( fileName )
40 if str( doc.doctype.name ) != __doc_name__:
41 return # wrong file format
42 docnode = doc.getElementsByTagName( __doc_tag__ )
44 return # wrong file format
45 mols = docnode[0].getElementsByTagName( __mol_tag__ )
47 c_name = str( mol.getAttribute( __name_attr__ ) )
48 ac = Molecule( c_name )
49 atoms = mol.getElementsByTagName( __atom_tag__ )
51 a_name = str( atom.getAttribute( __name_attr__ ) )
52 x = float( atom.getAttribute( __x_attr__ ) )
53 y = float( atom.getAttribute( __y_attr__ ) )
54 z = float( atom.getAttribute( __z_attr__ ) )
55 ac.addAtom( Atom( a_name, x, y, z ) )
59 def writeXmlFile( filename, data ):
61 Writes the atomic data to the XML file
64 raise Exception( "Bad data" )
65 doc = xml.dom.minidom.Document()
66 doc.appendChild(xml.dom.minidom.DocumentType( __doc_name__ ) )
67 docnode = doc.appendChild( doc.createElement( __doc_tag__ ) )
69 molnode = doc.createElement( __mol_tag__ )
70 molnode.setAttribute( __name_attr__, mol.name )
71 for atom in mol.atoms:
72 atomnode = doc.createElement( __atom_tag__ )
73 atomnode.setAttribute( __name_attr__, atom.name )
74 atomnode.setAttribute( __x_attr__, str( atom.x ) )
75 atomnode.setAttribute( __y_attr__, str( atom.y ) )
76 atomnode.setAttribute( __z_attr__, str( atom.z ) )
77 molnode.appendChild( atomnode )
78 docnode.appendChild( molnode )
79 file = open( filename, "w" )
80 file.write( doc.toprettyxml() )