Salome HOME
Copyright update 2022
[samples/atomgen.git] / src / ATOMGEN / ATOMGEN_Data.py
1 # Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
2 #
3 # This library is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU Lesser General Public
5 # License as published by the Free Software Foundation; either
6 # version 2.1 of the License, or (at your option) any later version.
7 #
8 # This library is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 # Lesser General Public License for more details.
12 #
13 # You should have received a copy of the GNU Lesser General Public
14 # License along with this library; if not, write to the Free Software
15 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 #
17 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 #
19
20 import ATOMGEN_ORB__POA
21
22 class Atom(ATOMGEN_ORB__POA.Atom):
23     """
24     Atom interface implementation
25     """
26     def __init__(self, name, x, y, z):
27         """
28         Constructor
29         """
30         self.name = name
31         self.x = x
32         self.y = y
33         self.z = z
34
35     def getName(self):
36         """
37         Gets the name of the atom
38         """
39         return self.name
40
41     def getX(self):
42         """
43         Gets x coordinate of the atom
44         """
45         return self.x
46
47     def getY(self):
48         """
49         Gets y coordinate of the atom
50         """
51         return self.y
52
53     def getZ(self):
54         """
55         Gets z coordinate of the atom
56         """
57         return self.z
58
59 class Molecule(ATOMGEN_ORB__POA.Molecule):
60     """
61     Atomic configuration interface implementatio
62     """
63     def __init__(self, name):
64         """
65         Constructor
66         """
67         self.name = name
68         self.atoms = []
69         pass
70
71     def getName(self):
72         """
73         Gets the name of the configuration
74         """
75         return self.name
76
77     def getNbAtoms(self):
78         """
79         GEts the number of the atoms
80         """
81         return len(self.atoms)
82
83     def addAtom( self, atom ):
84         """
85         Adds an atom
86         """
87         self.atoms.append( atom )
88         pass
89         
90     def getAtom(self, index):
91         """
92         Gets the atom by index
93         """
94         if index < 0 or index > len(self.atoms)-1:
95             raise Exception( "Bad index" )
96         return self.atoms[ index ]._this()