Author: bugman Date: Thu Aug 28 16:46:23 2014 New Revision: 25390 URL: http://svn.gna.org/viewcvs/relax?rev=25390&view=rev Log: Created the lib.periodic_table.process_symbol() function. This will take an atomic symbol and return a copy of it with an uppercase first letter and lowercase second letter. This is used by the Periodic_table methods atomic_mass() and atomic_weight() to allow for non-standard symbol input, for example if the element name comes directly from the all uppercase PDB file format without translation. 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=25390&r1=25389&r2=25390&view=diff ============================================================================== --- trunk/lib/periodic_table.py (original) +++ trunk/lib/periodic_table.py Thu Aug 28 16:46:23 2014 @@ -34,6 +34,7 @@ # Python module imports. from numpy import array, average, float64 from re import search, split +from string import lower, upper # relax module imports. from lib.errors import RelaxError @@ -63,6 +64,24 @@ # Convert to a float and return the value. return float(val) + + +def process_symbol(symbol): + """Make sure the symbol is in the correct format. + + @param symbol: The atomic symbol. + @type symbol: str + @return: The corrected atomic symbol. + @rtype: str + """ + + # The format is uppercase first letter, lowercase second. + new_symbol = upper(symbol[0]) + if len(symbol) == 2: + new_symbol += lower(symbol[1]) + + # Return the corrected atomic symbol. + return new_symbol @@ -198,7 +217,7 @@ A = int(split('[A-Z]', id)[0]) # The atomic symbol. - symbol = split('[0-9]', id)[-1] + symbol = process_symbol(split('[0-9]', id)[-1]) # Get the isotope container. isotope = self._get_isotope(symbol=symbol, A=A) @@ -220,6 +239,9 @@ @rtype: float """ + # Process the symbol. + symbol = process_symbol(symbol) + # Checks. if symbol not in self: raise RelaxError("The atomic symbol '%s' cannot be found in the periodic table." % symbol)