3.8. Utilities

Presented here is a small set of useful utility tools that can come handy in various contexts in your scripts. They are simple, standalone objects always present in the main namespace.

What is characteristic for objects described below is that they are meant to be used in a bit different way than all other PLAMS classes. Usually one takes a class (like DiracJob), creates an instance of it (myjob = DiracJob(...)) and executes some of its methods (r = myjob.run()). In contrast, utility classes are designed in a way similar to so called singleton design pattern. That means it is not possible to create any instances of these classes. The class itself serves for “one and only instance” and all methods should be called using the class as the calling object:

>>> x = PeriodicTable()
PTError: Instances of PeriodicTable cannot be created
>>> s = PeriodicTable.get_symbol(20)
>>> print(s)

3.8.1. Periodic Table

class PeriodicTable[source]

Singleton class for periodic table of elements.

For each element the following properties are stores: atomic symbol, atomic mass, atomic radius and number of connectors.

Atomic mass is, strictly speaking, atomic weight, as present in Mathematica’s ElementData function.

Atomic radius and number of connectors are used by guess_bonds(). Note that values or radii are neither atomic radii nor covalent radii. They are someway “emprically optimized” for bond guessing algorithm.


This class is visible in the main namespace as both PeriodicTable and PT.

classmethod get_atomic_number(symbol)[source]

Convert atomic symbol to atomic number.

classmethod get_symbol(atnum)[source]

Convert atomic number to atomic symbol.

classmethod get_mass(arg)[source]

Convert atomic symbol or atomic number to atomic mass.

classmethod get_radius(arg)[source]

Convert atomic symbol or atomic number to radius.

classmethod get_connectors(arg)[source]

Convert atomic symbol or atomic number to number of connectors.

classmethod _get_property(arg, prop)[source]

Get property of element described by either symbol or atomic number. Skeleton method for :meth`get_radius`, :meth`get_mass` and :meth`get_connectors`.

3.8.2. Units

class Units[source]

Singleton class for units converter.

All values are based on 2014 CODATA recommended values.

The following constants and units are supported:

  • constants:
    • speed_of_light (also c)
    • elementary_charge (also e and electron_charge)
    • avogadro_constant (also NA)
    • bohr_radius
  • distance:
    • Angstrom, angstrom, A
    • bohr, a0, au
    • nm
    • pm
  • angle:
    • degree, deg,
    • radian, rad,
    • grad
    • circle
  • energy:
    • au, hartree, Hartree
    • ev, eV
    • kcal/mol
    • kJ/mol
    • cm^-1
  • dipole moment:
    • au
    • Cm
    • D, Debye, debye


>>> print(Units.constants['speed_of_light'])
>>> print(Units.constants['e'])
>>> print(Units.convert(123, 'angstrom', 'bohr'))
>>> print(Units.convert(23.32, 'kJ/mol', 'kcal/mol'))
>>> print(Units.conversion_ratio('kcal/mol', 'kJ/mol'))
classmethod conversion_ratio(inp, out)[source]

Return conversion ratio from unit inp to out.

classmethod convert(value, inp, out)[source]

Convert value from unit inp to out.

value can be a single number or a container (list, tuple, numpy.array etc.). In the latter case a container of the same type and length is returned. Conversion happens recursively, so this method can be used to convert, for example, a list of lists of numbers, or any other hierarchical container structure. Conversion is applied on all levels, to all values that are numbers (also numpy number types). All other values (strings, bools etc.) remain unchanged.

3.8.3. Geometry tools

rotation_matrix(vec1, vec2)[source]

Calculates the rotation matrix rotating vec1 to vec2. Vectors can be any containers with 3 numerical values. They don’t need to be normalized. Returns 3x3 numpy array.