pychemia.utils package

Utilery definitions

Submodules

pychemia.utils.computing module

pychemia.utils.computing.convert_color(s)[source]

Convert a string hexadecimal representation of a color into a tuple RBG where each element of the tuple is between 0.0 to 1.0

Parameters:s – (str)
Returns:(tuple) With 3 floats representing the color in RGB

:rtype : tuple

Examples: >>> convert_color(‘FF5500’) (1.0, 0.3333333333333333, 0.0)

pychemia.utils.computing.deep_unicode(value)[source]

Recursively convert to unicode all string-like elements of a complex object. Use with care for objects that could not be converted properly to string This is safe for things like Atom names and symbols

Parameters:value – (unicode, list, dict)
Returns:(str, list, dict) The string, list or dictionary where all string-like elements are converted into strings

:rtype : (str, list, dict)

Examples: >>> deep_unicode(u’abc’) u’abc’ >>> deep_unicode([u’abc’]) [u’abc’] >>> deep_unicode({u’abc’: u’def’}) {u’abc’: u’def’} >>> deep_unicode(‘abc’) u’abc’

pychemia.utils.computing.get_float(value)[source]

Convert a string to a float number

Parameters:value – (str)
Returns:(float)

Example: >>> get_float(‘3.0’) 3.0

pychemia.utils.computing.get_int(value)[source]

Convert a string to an integer

Parameters:value – (str)
Returns:(int)

Example: >>> get_int(‘3’) 3

pychemia.utils.computing.hashfile(filename)[source]

Get the MD5 hash sum of a given file

Parameters:filename – (str)
Returns:(str)
>>> import tempfile
>>> a = tempfile.NamedTemporaryFile()
>>> hashfile(a.name)
'd41d8cd98f00b204e9800998ecf8427e'
>>> a = tempfile.NamedTemporaryFile('w')
>>> tmp= a.file.write(128000*'GAF')
>>> a.file.flush()
>>> hashfile(a.name)
'7b8a4f8a3ce222580765d577df78b782'
pychemia.utils.computing.only_ascii(string)[source]

Remove non-ascii characters, from monty

Parameters:string
Returns:

Example: >>> only_ascii(u’lmnopq’) u’lmnopq’

pychemia.utils.computing.read_file(filename)[source]

General function to open files even if they are compressed

Parameters:filename
Returns:

Example: >>> import tempfile >>> a = tempfile.NamedTemporaryFile() >>> read_file(a.name) ‘’

pychemia.utils.constants module

pychemia.utils.constants.Avogadro = 6.02214179e+23

Avogadro number

pychemia.utils.constants.BField_Tesla = 2.1271915e-06

Atomic unit of induction field (in Tesla) * mu_B (in atomic units).

pychemia.utils.constants.HaBohr3_GPa = 29421.010803194917

1 Ha/Bohr^3, in GPa

pychemia.utils.constants.Ha_J = 4.35974394e-18

1 Hartree, in J

pychemia.utils.constants.Ha_K = 315774.65

1 Hartree, in Kelvin

pychemia.utils.constants.Ha_cmm1 = 219474.6313705

1 Hartree, in cm^-1

pychemia.utils.constants.Ha_eV = 27.21138386

1 Hartree, in eV

pychemia.utils.constants.Ha_meV = 27211.38386

1 Hartree, in meV

pychemia.utils.constants.InvFineStruct = 137.035999679

Inverse of fine structure constant

pychemia.utils.constants.Sp_Lt = 137.03599910518506

Speed of light in atomic units

pychemia.utils.constants.Time_Sec = 2.418884326505e-17

Atomic unit of time, in seconds

pychemia.utils.constants.amu_emass = 1822.888484264545

1 atomic mass unit, in electronic mass

pychemia.utils.constants.bohr_angstrom = 0.52917720859

1 Bohr, in Angstrom

pychemia.utils.constants.e_Cb = 1.602176487e-19
Minus the electron charge, in Coulomb
pychemia.utils.constants.kb_HaK = 3.1668154197285284e-06

Boltzmann constant in Ha/K

pychemia.utils.mathematics module

pychemia.utils.mathematics.angle_between_vectors(a, b)[source]
pychemia.utils.mathematics.angle_vector(v1, v2, units='rad')[source]

Returns the angle in radians (default) or degrees between vectors ‘v1’ and ‘v2’:

:param v1: (list, numpy.ndarray)
:param v2: (list, numpy.ndarray)
:param units: (str) : 'rad' (default) Radians, 'deg' Degrees

:rtype : float

Examples: >>> angle_vector([1, 0, 0], [0, 1, 0]) 1.5707963267948966 >>> angle_vector([1, 0, 0], [1, 0, 0]) 0.0 >>> angle_vector([1, 0, 0], [-1, 0, 0]) 3.1415926535897931 >>> angle_vector([1, 0, 0], [0, 1, 0], units=’deg’) 90.0 >>> angle_vector([1, 0, 0], [-1, 0, 0], units=’deg’) 180.0

pychemia.utils.mathematics.angle_vectors(m, units='rad')[source]

Returns all the angles for all the vectors arranged as rows in matrix ‘m’

Parameters:
  • m – (numpy.ndarray)
  • units – (str) : ‘rad’ Radians, ‘deg’ Degrees

:rtype : numpy.ndarray

Examples: >>> import pprint

>>> a = angle_vectors([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 0, 0], [0, 0, 2]])
>>> pprint.pprint(a)
{(0, 1): 0.22572612855273419,
 (0, 2): 0.2858867976945072,
 (0, 3): 1.3002465638163236,
 (0, 4): 0.6405223126794245,
 (1, 2): 0.060160669141772885,
 (1, 3): 1.0974779950809703,
 (1, 4): 0.8178885561654512,
 (2, 3): 1.0442265974045177,
 (2, 4): 0.86825103780276369,
 (3, 4): 1.5707963267948966}
>>> a = angle_vectors([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 0, 0], [0, 0, 2]], units='deg')
>>> pprint.pprint(a)
{(0, 1): 12.933154491899135,
 (0, 2): 16.380106926405656,
 (0, 3): 74.498640433063002,
 (0, 4): 36.699225200489877,
 (1, 2): 3.4469524345065143,
 (1, 3): 62.880857226618922,
 (1, 4): 46.861562380328941,
 (2, 3): 59.829776886585428,
 (2, 4): 49.747120023952057,
 (3, 4): 90.0}
pychemia.utils.mathematics.apply_rotation(vector, theta_x, theta_y, theta_z)[source]

Apply a rotation matrix to a vector by succesive rotations around the three axis ‘x’, ‘y’ and ‘z’

param vector:
param theta_x:(float) Angle in radians
param theta_y:(float) Angle in radians
param theta_z:(float) Angle in radians
return:(numpy.ndarray)
Example:
>>> a = apply_rotation([0.1, 0.2, 0.3], 3.1415/3, 3.1415/4, 3.1415/5)
>>> b = apply_rotation(a, -3.1415/3, 0, 0)
>>> c = apply_rotation(b, 0, -3.1415/4, 0)
>>> d = apply_rotation(c, 0, 0, -3.1415/5)
>>> d
array([ 0.1,  0.2,  0.3])
pychemia.utils.mathematics.cartesian_to_spherical(xyz)[source]

Convert a numpy array (Nx3) into a numpy array (Nx3) where the first column is the magnitude of the vector and second and third are spherical angles

We use the mathematical notation (radial, azimuthal, polar)

Parameters:xyz – numpy.array
Returns:numpy.array
pychemia.utils.mathematics.distance(v1, v2)[source]

Return the vector v2-v1, the vector going from v1 to v2 and the magnitude of that vector.

Parameters:
  • v1 – (list, numpy.ndarray)
  • v2 – (list, numpy.ndarray)

:rtype : tuple

Examples: >>> distance([0, 0, 0, 1], [1, 0, 0, 0]) (array([ 1, 0, 0, -1]), 1.4142135623730951) >>> distance([-1, 0, 0], [1, 0, 0]) (array([2, 0, 0]), 2.0)

pychemia.utils.mathematics.distances(m)[source]

Return all the distances for all possible combinations of the row vectors in matrix m

Parameters:m – (list, numpy.ndarray)

:rtype : dict

Example: >>> import pprint

>>> pprint.pprint(distances([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 0, 0], [0, 0, 2]]))
{(0, 1): (array([3, 3, 3]), 5.196152422706632),
 (0, 2): (array([6, 6, 6]), 10.392304845413264),
 (0, 3): (array([ 0, -2, -3]), 3.6055512754639891),
 (0, 4): (array([-1, -2, -1]), 2.4494897427831779),
 (1, 2): (array([3, 3, 3]), 5.196152422706632),
 (1, 3): (array([-3, -5, -6]), 8.3666002653407556),
 (1, 4): (array([-4, -5, -4]), 7.5498344352707498),
 (2, 3): (array([-6, -8, -9]), 13.45362404707371),
 (2, 4): (array([-7, -8, -7]), 12.727922061357855),
 (3, 4): (array([-1,  0,  2]), 2.2360679774997898)}
pychemia.utils.mathematics.frexp10(x)[source]
pychemia.utils.mathematics.gea_all_angles(ortho_matrix)[source]

Generalized Euler Angles Return the generalized angles described from the paper

Generalization of Euler Angles to N-Dimensional Orthogonal Matrices David K. Hoffman, Richard C. Raffenetti, and Klaus Ruedenberg Journal of Mathematical Physics 13, 528 (1972) doi: 10.1063/1.1666011

Parameters:ortho_matrix – Orthogonal Matrix
pychemia.utils.mathematics.gea_angles(uvector)[source]

Generalized Euler Angles Return the parametric angles decribed on Eq. 1 from the paper

Generalization of Euler Angles to N-Dimensional Orthogonal Matrices David K. Hoffman, Richard C. Raffenetti, and Klaus Ruedenberg Journal of Mathematical Physics 13, 528 (1972) doi: 10.1063/1.1666011

Parameters:uvector – A n-dimensional vector
Returns:n dimensional list of angles, the last one is pi/2
pychemia.utils.mathematics.gea_matrix_a(angles)[source]

Generalized Euler Angles Return the parametric angles described on Eqs. 15-19 from the paper:

Generalization of Euler Angles to N-Dimensional Orthogonal Matrices David K. Hoffman, Richard C. Raffenetti, and Klaus Ruedenberg Journal of Mathematical Physics 13, 528 (1972) doi: 10.1063/1.1666011

pychemia.utils.mathematics.gea_orthogonal_from_angles(angles_list)[source]

Generalized Euler Angles Return the orthogonal matrix from its generalized angles

Generalization of Euler Angles to N-Dimensional Orthogonal Matrices David K. Hoffman, Richard C. Raffenetti, and Klaus Ruedenberg Journal of Mathematical Physics 13, 528 (1972) doi: 10.1063/1.1666011

Parameters:angles_list – List of angles, for a n-dimensional space the total number of angles is k*(k-1)/2
pychemia.utils.mathematics.gram_smith(m)[source]

Create a Gram-Smith ortoganalized matrix, using the first vector of matrix ‘m’ to build the ortogonal set of vectors

Parameters:m
Returns:

Example: >>> import numpy as np >>> o = gram_smith(np.random.rand(3, 3))

>>> np.round(np.abs(np.linalg.det(o)), 10) == 1.0
True
pychemia.utils.mathematics.gram_smith_qr(ndim=3)[source]

Create a Gram-Smith orthoganalized matrix. The argument is the dimension of the matrix and uses a random matrix and QR decomposition to build the orthogonal matrix

Parameters:ndim – Dimension of the matrix
Returns:

Example: >>> import numpy as np >>> o = gram_smith_qr(3) >>> np.round(np.abs(np.linalg.det(o)), 10)==1.0 True

pychemia.utils.mathematics.integral_gaussian(a, b, mu, sigma)[source]

Computes the integral of a gaussian centered in mu with a given sigma :param a: :param b: :param mu: :param sigma: :return:

pychemia.utils.mathematics.iterative_rotation_angles(m, nrounds=1)[source]
pychemia.utils.mathematics.lcm(a, b)[source]

Return the Least Common Multiple the smallest positive integer that is divisible by both a and b :param a: (int) :param b: (int) :return: (int)

:rtype : (int)

pychemia.utils.mathematics.length_vector(v)[source]

Returns the length of a vector ‘v’ in arbitrary number of dimensions

Parameters:v – (list, numpy.ndarray) Vector to compute length

:rtype : (float) The lenght of the vector

Examples

>>> length_vector([1, 2, 3])
3.7416573867739413
pychemia.utils.mathematics.length_vectors(m)[source]

Returns the lengths of several vectors arranged as rows in a MxN matrix

Parameters:m – numpy.ndarray

:rtype : numpy.ndarray

Examples >>> length_vectors([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 0, 0], [0, 0, 2]]) array([ 3.74165739, 8.77496439, 13.92838828, 1. , 2. ])

pychemia.utils.mathematics.matrix_from_eig(v1, v2, v3, lam1, lam2, lam3)[source]

Given 3 eigenvectors and 3 eigenvalues, returns the matrix A that has those eigenvectors and eigenvalues.

The matrix $A = P.D.P^{-1}$

Where P is the column stack of eigenvectors and D is a diagonal matrix of eigevalues

Parameters:
  • v1 – First eigenvector
  • v2 – Second eigenvector
  • v3 – Third eigenvector
  • lam1 – First eigenvalue
  • lam2 – Second eigenvalue
  • lam3 – Third eigenvalue
Returns:

(numpy.ndarray) The matrix

pychemia.utils.mathematics.projector(u, v)[source]

Computes the projector of ‘v’ over ‘u’ A vector in the direction of ‘u’ with a magnitude of the projection of ‘v’ over ‘u’

Parameters:
  • u
  • v
Returns:

Example: >>> projector([0.1, 0.2, 0.3], [0.3, 0.2, 0.1]) array([ 0.07142857, 0.14285714, 0.21428571]) >>> projector([1, 0, 0], [0, 2, 0]) array([ 0., 0., 0.])

pychemia.utils.mathematics.rotate_towards_axis(vector, axis, theta=None, fraction=None)[source]
pychemia.utils.mathematics.rotation_matrix_around_axis_angle(axis, theta)[source]

Return the rotation matrix needed to rotate any vector around the ‘axis’ an angle of ‘theta’ radians

pychemia.utils.mathematics.rotation_matrix_ndim(ndim, rotation_list)[source]
pychemia.utils.mathematics.rotation_matrix_numpy(axis, theta)[source]
Parameters:
  • axis
  • theta
Returns:

Example:

>>> rotation_matrix_numpy([1, 1, 1], 3.1415926/4.0)
array([[ 0.80473786,  0.50587935, -0.31061722],
       [-0.31061722,  0.80473786,  0.50587935],
       [ 0.50587935, -0.31061722,  0.80473786]])
pychemia.utils.mathematics.rotation_matrix_weave(axis, theta, mat=None)[source]
pychemia.utils.mathematics.rotation_ndim(ndim, theta, indices)[source]

Return a rotation matrix for the Euclidean space in ndim dimensions. The angle ‘theta’ is in radians and the indices should be a list of two values where defining the plane of rotation

Parameters:
  • ndim – Dimension of the matrix
  • theta – Angle of rotation in radians
  • indices – Indices of the plane where the rotation takes place.
Returns:

pychemia.utils.mathematics.rotation_x(theta)[source]

Create a rotation matrix around the ‘x’ axis

Parameters:theta – (float) Angle in radians
Returns:(numpy.ndarray)

Examples: >>> import numpy as np

>>> m = rotation_x(np.pi/3)
>>> np.max(np.dot(m.T, m) - np.eye(3)) < 1E-10
True
pychemia.utils.mathematics.rotation_y(theta)[source]

Create a rotation matrix around the ‘y’ axis

Parameters:theta – (float) Angle in radians
Returns:(numpy.ndarray)

Example: >>> import numpy as np

>>> m = rotation_y(np.pi/3)
>>> np.max(np.dot(m.T, m) - np.eye(3)) < 1E-10
True
pychemia.utils.mathematics.rotation_z(theta)[source]

Create a rotation matrix around the ‘z’ axis

Parameters:theta – (float) Angle in radians
Returns:(numpy.ndarray)

Examples: >>> import numpy as np >>> m = rotation_z(np.pi/3)

>>> np.max(np.dot(m.T, m) - np.eye(3)) < 1E-10
True
pychemia.utils.mathematics.round_small(number, ndigits=0)[source]
pychemia.utils.mathematics.shortest_triple_set(n)[source]

Return the smallest three numbers (a,b,c) such as a*b*c=n And a+b+c is as small as possible

Parameters:n
Returns:
pychemia.utils.mathematics.sieve_atkin(limit)[source]

Computes all prime numbers up to a ‘limit’ using the Sieve of Atkin

Parameters:limit
Returns:

Example: >>> p=sieve_atkin(300)

>>> len(p)
63
>>> p[-1]
293
pychemia.utils.mathematics.spherical_to_cartesian(spherical)[source]

Convert a numpy array (Nx3) from spherical coordinates to cartesian coordinates

We use the mathematical notation (radial, azimuthal, polar)

Parameters:spherical – numpy.array
Returns:numpy.array
pychemia.utils.mathematics.trial_division(n)[source]

Return a list of the prime factors for a natural number uses the Sieve of Atkin as a list of primes

Parameters:n – (int) A natural number

:rtype : (list)

pychemia.utils.mathematics.unit_vector(v)[source]

Returns the unit vector of the vector. Arbitrary number of dimensions

Parameters:v – list, numpy.array

:rtype : numpy.ndarray

Examples >>> a = unit_vector([1, 2, 3])

>>> a
array([ 0.26726124,  0.53452248,  0.80178373])
>>> length_vector(a)
1.0
pychemia.utils.mathematics.unit_vectors(m)[source]

Returns the unit vectors of a set of vectors arranged as rows in MxN matrix

Parameters:m – numpy.ndarray

:rtype : numpy.ndarray

Example >>> from pychemia.utils.mathematics import *

>>> b = unit_vectors([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 0, 0], [0, 0, 2]])
>>> b
array([[ 0.26726124,  0.53452248,  0.80178373],
       [ 0.45584231,  0.56980288,  0.68376346],
       [ 0.50257071,  0.57436653,  0.64616234],
       [ 1.        ,  0.        ,  0.        ],
       [ 0.        ,  0.        ,  1.        ]])
>>> length_vectors(b)
array([ 1.,  1.,  1.,  1.,  1.])
pychemia.utils.mathematics.vector_set_perpendicular(vector3)[source]

Produces a set of three mutually perpendicular vectors The two other vectors will be unitary

Returns:(tuple) Two numpy arrays
pychemia.utils.mathematics.wrap2_pmhalf(x)[source]

Wraps a number or array in the interval ]-1/2, 1/2] values = -1/2 will be wrapped to 1/2

Parameters:x – (float) The number to be wrapped in the interval (-1/2, 1/2]

Examples:

>>> wrap2_pmhalf(-0.5)
0.5
>>> wrap2_pmhalf(0.0)
0.0
>>> wrap2_pmhalf([-0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75])
array([ 0.25,  0.5 , -0.25,  0.  ,  0.25,  0.5 , -0.25])
>>> wrap2_pmhalf([[-0.75, -0.5, -0.25], [0.25, 0.5, 0.75]])
array([[ 0.25,  0.5 , -0.25],
       [ 0.25,  0.5 , -0.25]])

pychemia.utils.metaheuristics module

class pychemia.utils.metaheuristics.Ackley[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Beale[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Booth[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.BukinN6[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.CrossInTray[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Easom[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Eggholder[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.GoldsteinPrice[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.HolderTable[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.LeviN13[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Matyas[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.McCormick[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.OptimizationTestFunction(mindim=1, maxdim=None, domain=array([-1, 1]))[source]

Bases: object

fminimum(ndim)[source]
static function(x)[source]
get_plot_matrices(shape=None)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Rosenbrock[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.SchafferN2[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.SchafferN4[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.Sphere[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.StyblinskiTang[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
class pychemia.utils.metaheuristics.ThreeHump[source]

Bases: pychemia.utils.metaheuristics.OptimizationTestFunction

static function(x)[source]
minimum(ndim)[source]
pychemia.utils.metaheuristics.all_tests_functions()[source]

pychemia.utils.periodic module

pychemia.utils.periodic.atomic_number(arg)[source]

Atomic number(s) of a symbol or list of atomic symbols

Parameters:arg – Atomic number or list of atomic numbers
Returns:Atomic number(s) for the atom(s)
Return type:int, list

Examples: >>> atomic_number(‘C’) 6 >>> atomic_number([‘Au’, ‘Sb’]) [79, 51] >>> atomic_number([‘Na’, ‘O’, ‘Ag’, ‘La’]) [11, 8, 47, 57]

pychemia.utils.periodic.atomic_symbol(value=None)[source]

Atomic symbol for a atom or atoms given by atomic number Float values will be rounded to the lowest integer

Parameters:value – Atomic number or list of atomic number
Returns:Atomic symbol(s) for the atom(s)
Return type:(str, list)

Examples: >>> atomic_symbol(6) ‘C’ >>> atomic_symbol(6.9) ‘C’ >>> atomic_symbol([79, 51]) [‘Au’, ‘Sb’] >>> atomic_symbol([11, 8, 47, 57]) [‘Na’, ‘O’, ‘Ag’, ‘La’] >>> atomic_symbol(range(1, 12)) [‘H’, ‘He’, ‘Li’, ‘Be’, ‘B’, ‘C’, ‘N’, ‘O’, ‘F’, ‘Ne’, ‘Na’]

pychemia.utils.periodic.block(value=None)[source]

Return the orbital block of the element(s) For example, elements on group 1 and 2 are s-block. Transition metals are on the d-block,

Parameters:value – Atom symbol, atom number or list of atoms
Returns:The block of the atom or atoms
Return type:(str, list)

Examples: >>> block(‘C’) ‘p’ >>> block(6) ‘p’ >>> block([‘Au’, ‘Sb’]) [‘d’, ‘p’] >>> block([‘Na’, ‘O’, ‘Ag’, ‘La’]) [‘s’, ‘p’, ‘d’, ‘f’] >>> block(range(1, 12)) [‘s’, ‘p’, ‘s’, ‘s’, ‘p’, ‘p’, ‘p’, ‘p’, ‘p’, ‘p’, ‘s’]

pychemia.utils.periodic.covalent_radius(value=None)[source]

Covalent radius in Angstrom of an atom or list of atoms. The atoms could be given as symbols or by atomic number

Parameters:value – Atom symbol, atom number or list of atoms
Returns:Covalent radius in angstrom for the atom or atoms
Return type:float

Examples: >>> covalent_radius(‘C’) 0.76 >>> covalent_radius(6) 0.76 >>> covalent_radius([‘Au’, ‘Sb’]) [1.36, 1.39] >>> covalent_radius([‘Na’, ‘O’, ‘Ag’, ‘La’]) [1.66, 0.66, 1.45, 2.07] >>> covalent_radius(range(1, 12)) [0.31, 0.28, 1.28, 0.96, 0.84, 0.76, 0.71, 0.66, 0.57, 0.58, 1.66]

pychemia.utils.periodic.cpk_color(arg)[source]
pychemia.utils.periodic.electronegativity(value=None)[source]

Electronegativity of the atom or atoms

Parameters:value – Atom symbol, atom number or list of atoms
Returns:The value of electronegativity for the atom or atoms
Return type:(float, list)

Examples: >>> electronegativity(‘C’) 2.55 >>> electronegativity(6) 2.55 >>> electronegativity([‘Au’, ‘Sb’]) [2.54, 2.05] >>> electronegativity([‘Na’, ‘O’, ‘Ag’, ‘La’]) [0.93, 3.44, 1.93, 1.1] >>> electronegativity(range(1, 12)) [2.2, 0, 0.98, 1.57, 2.04, 2.55, 3.04, 3.44, 3.98, 0, 0.93]

pychemia.utils.periodic.group(value=None)[source]

Return the group of the element(s) The group for lanctanides and actinides is identified with -3

Parameters:value – Atom symbol, atom number or list of atoms
Returns:The group of the atom or atoms
Return type:(int, list)

Examples: >>> group(‘C’) 14 >>> group(6) 14 >>> group([‘Au’, ‘Sb’]) [11, 15] >>> group([‘Na’, ‘O’, ‘Ag’, ‘La’]) [1, 16, 11, -3] >>> group(range(1, 12)) [1, 18, 1, 2, 13, 14, 15, 16, 17, 18, 1]

pychemia.utils.periodic.mass(value=None)[source]

Atomic mass for a atom or atoms given by atomic number Float values will be rounded to the lowest integer Atomic masses are returned in Standard Atomic weight

Parameters:value – Atomic mass or list of atomic masses
Returns:Atomic mass(es) for the atom(s)
Return type:float

Examples: >>> mass(6) 12.011 >>> mass(6.9) 12.011 >>> mass([‘Au’, ‘Sb’]) [196.96654, 121.753] >>> mass([‘Na’, ‘O’, ‘Ag’, ‘La’]) [22.989768, 15.9994, 107.8682, 138.9055] >>> mass(range(1, 12)) [1.00794, 4.002602, 6.941, 9.012182, 10.811, 12.011, 14.00674, 15.9994, 18.9984032, 20.1797, 22.989768]

pychemia.utils.periodic.period(value=None)[source]

Return the period of the element(s)

Parameters:value – atom symbol, atom number or list of atoms
Returns:The period of the atom or atoms
Return type:(int, list)

Examples: >>> period(‘C’) 2 >>> period(6) 2 >>> period([‘Au’, ‘Sb’]) [6, 5] >>> period([‘Na’, ‘O’, ‘Ag’, ‘La’]) [3, 2, 5, 6] >>> period(range(1, 12)) [1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3]

pychemia.utils.periodic.valence(value=None)[source]

Return the ‘valences’ as taken from http://www.ptable.com/#Property/Valence

Args:
value: (int,float,str,list) The value/s
for which the valence will be evaluated Float values will be cast into integer
Return:
The valence of the element/s

Examples: >>> valence(1) 1 >>> valence([1, 2]) [1, 0] >>> valence([‘H’, ‘He’]) [1, 0]

pychemia.utils.serializer module

class pychemia.utils.serializer.PyChemiaJsonable[source]

Bases: object

Abstract base class specifying how to convert objects from/to dictionaries. PyChemiaJsonable objects must implement a to_dict property and a from_dict static method.

classmethod from_dict(json_dict)[source]

This implements a default from_dict method which supports all classes that simply try to recreate an object using the keys as arguments for the creation of the new object.

Parameters:json_dict – Recreate an object from its serialize form
Returns:
save_to_file(filename)[source]

Writes the json representation to a file.

Parameters:filename – (str) Filename for the json that will be created
to_dict

A JSON representation of an object.

to_json

Returns a json string representation of the object.

pychemia.utils.serializer.generic_serializer(value)[source]

A generic serializer for very common values

Parameters:value
Returns: