mailr25388 - /trunk/lib/periodic_table.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on August 28, 2014 - 16:33:
Author: bugman
Date: Thu Aug 28 16:33:37 2014
New Revision: 25388

URL: http://svn.gna.org/viewcvs/relax?rev=25388&view=rev
Log:
Fix for the Periodic_table.lookup_symbol() method.

The __init__() method of the Periodic_table has been reintroduced to 
initialise a fast atomic symbol
lookup table.  The _add() method then updates this table.  And the 
lookup_symbol() method now uses
this lookup table to correctly return the symbol.


Modified:
    trunk/lib/periodic_table.py

Modified: trunk/lib/periodic_table.py
URL: 
http://svn.gna.org/viewcvs/relax/trunk/lib/periodic_table.py?rev=25388&r1=25387&r2=25388&view=diff
==============================================================================
--- trunk/lib/periodic_table.py (original)
+++ trunk/lib/periodic_table.py Thu Aug 28 16:33:37 2014
@@ -129,10 +129,17 @@
 class Periodic_table(dict):
     """The periodic table object."""
 
+    def __init__(self):
+        """Set up the periodic table object."""
+
+        # Initialise a fast lookup table.
+        self._lookup_symbol = {}
+
+
     def _add(self, atomic_number=None, symbol=None, name=None, 
atomic_weight=None):
         """Add an element to the table.
 
-        @keyword atomic_number:     The atomic number.
+        @keyword atomic_number:     The atomic number Z.
         @type atomic_number:        int
         @keyword symbol:            The atomic symbol.
         @type symbol:               str
@@ -147,6 +154,9 @@
         # Add the element container.
         self[symbol] = Element(atomic_number=atomic_number, name=name, 
atomic_weight=atomic_weight)
 
+        # Update the fast lookup tables.
+        self._lookup_symbol[atomic_number] = symbol
+
         # Return the container.
         return self[symbol]
 
@@ -219,16 +229,16 @@
 
 
     def lookup_symbol(self, atomic_number=None):
-        """Return the atomic symbol corresponding to the atomic number.
-
-        @keyword atomic_number: The atomic number.
+        """Return the atomic symbol corresponding to the atomic number Z.
+
+        @keyword atomic_number: The atomic number Z.
         @type atomic_number:    int
         @return:                The atomic symbol.
         @rtype:                 str
         """
 
         # Direct lookup.
-        return self.symbol[atomic_number-1]
+        return self._lookup_symbol[atomic_number]
 
 
 




Related Messages


Powered by MHonArc, Updated Thu Aug 28 16:40:02 2014