Using Quippy to compute descriptors of atomic environments

This tutorial shows how to use quippy to calculate various descriptors for a given atomic structure, contained in an Atoms object.

In [2]:
import quippy
In [4]:
from quippy import descriptors

Create a configuration:

In [32]:
at = quippy.diamond(3.5, 6)
at.positions
Out[32]:
array([[ 0.   ,  0.   ,  0.   ],
       [ 0.875,  0.875,  0.875],
       [ 1.75 ,  1.75 ,  0.   ],
       [ 2.625,  2.625,  0.875],
       [ 1.75 ,  0.   ,  1.75 ],
       [ 2.625,  0.875,  2.625],
       [ 0.   ,  1.75 ,  1.75 ],
       [ 0.875,  2.625,  2.625]])
In [33]:
at.Z
Out[33]:
FortranArray([6, 6, 6, 6, 6, 6, 6, 6], dtype=int32)

All descriptors are instantiated by a call to Descriptor(), which takes the descriptor initialisation string as its only argument. For a list of available descriptors and their parameters, see the following list, auto-generated using the following command: quip descriptor_str="--help"

bispectrum_so4 bispectrum_so3 behler distance_2b coordination angle_3b co_angle_3b co_distance_2b cosnx trihis water_monomer water_dimer A2_dimer AB_dimer bond_real_space atom_real_space power_so3 power_so4 soap AN_monomer general_monomer general_dimer general_trimer rdf as_distance_2b molecule_lo_d alex com_dimer distance_Nb

A simple descriptor: pairwise distances

Here we use a simple pair distance between carbon atoms, with a cutoff of 1.5 Angstrom. There are several descriptors that can do this, one is distance_2b, which takes a cutoff argument, and two Z values to specify the atom types. Alternatively, the distance_Nb descriptor could also do this, with order=2, and it takes a string of Zs to specify the atom types. This is more general, order=3 is a triangle-like three-body descriptor of the three sides of a triangle of 3 atoms.

In [9]:
desc = descriptors.Descriptor("distance_2b Z1=6 Z2=6 cutoff=4")

The descriptor dimension is the length of the descriptor vector. For the scalar distance this is 1.

In [10]:
desc.n_dim # number of dimensions
Out[10]:
1

This descriptor is very simple: it is scalar (dimension 1), and hence only has a single permutation.

In [11]:
desc.n_perm # number of permutations
Out[11]:
1
In [12]:
desc.permutations() # array of permutation arrays
Out[12]:
array([[1]], dtype=int32)

Many descriptors rely on the neighbour connectivity, so we need to call calc_connect, after setting the Atoms cutoff with a skin of 1 A:

In [13]:
at.set_cutoff(desc.cutoff()+1.0)
at.calc_connect()

We can now calculate how many instances of this descriptor are found in an Atoms (or ASEAtoms) object:

In [39]:
desc.count(at)
Out[39]:
368

This also works transparently for iterables (such as lists), returning a list of the counts.

We can also calculate the actual descriptor values – in this case, the list of pairwise distances:

In [40]:
d = desc.calc(at)
d
Out[40]:
{'cutoff': array([ 0.30420743,  0.30420743,  1.        ,  1.        ,  1.        ,
         0.30420743,  0.30420743,  0.30420743,  1.        ,  1.        ,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         0.30420743,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  0.30420743,  0.30420743,  1.        ,  0.30420743,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  0.30420743,  1.        ,  1.        ,  0.30420743,
         1.        ,  1.        ,  0.30420743,  0.30420743,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  0.30420743,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  0.30420743,
         1.        ,  1.        ,  1.        ,  1.        ,  0.30420743,
         0.30420743,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         0.30420743,  1.        ,  1.        ,  0.30420743,  0.30420743,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         0.30420743,  0.30420743,  1.        ,  1.        ,  1.        ,
         0.30420743,  1.        ,  1.        ,  0.30420743,  1.        ,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  0.30420743,  1.        ,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         0.30420743,  1.        ,  0.30420743,  1.        ,  1.        ,
         0.30420743,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  0.30420743,  1.        ,  0.30420743,  0.30420743,
         1.        ,  1.        ,  0.30420743,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         0.30420743,  0.30420743,  1.        ,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         0.30420743,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         1.        ,  0.30420743,  1.        ,  0.30420743,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         0.30420743,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  0.30420743,  1.        ,
         0.30420743,  1.        ,  0.30420743,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  0.30420743,
         0.30420743,  1.        ,  1.        ,  0.30420743,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  0.30420743,  1.        ,
         0.30420743,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ,  1.        ,  0.30420743,
         0.30420743,  1.        ,  1.        ,  1.        ,  0.30420743,
         1.        ,  1.        ,  1.        ,  1.        ,  1.        ,
         0.30420743,  1.        ,  1.        ,  0.30420743,  1.        ,
         0.30420743,  1.        ,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  0.30420743,  1.        ,  0.30420743,
         1.        ,  0.30420743,  1.        ,  1.        ,  1.        ,
         1.        ,  1.        ,  1.        ]),
 'descriptor': array([[ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.5       ],
        [ 1.51554446],
        [ 2.47487373],
        [ 1.51554446],
        [ 2.47487373],
        [ 1.51554446],
        [ 2.47487373],
        [ 1.51554446],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.47487373],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.81403658],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 1.51554446],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.5       ],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.5       ],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.5       ],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.5       ],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 1.51554446],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.5       ],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.90204669],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.5       ],
        [ 2.90204669],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.47487373],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.5       ],
        [ 3.5       ],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.5       ],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.47487373],
        [ 2.90204669],
        [ 2.47487373],
        [ 1.51554446],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.5       ],
        [ 2.90204669],
        [ 3.5       ],
        [ 1.51554446],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.81403658],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 2.90204669],
        [ 1.51554446],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 3.81403658],
        [ 1.51554446],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.47487373],
        [ 2.90204669],
        [ 1.51554446],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 2.90204669],
        [ 3.81403658],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ],
        [ 3.5       ]])}

Notice that the first array is called cutoff, and it supplies the value of a cutoff function, implicit in all descriptors, which takes the descriptor value to zero as the atoms approach the cutoff, i.e. in this case as the distance between the two atoms approaches the cutoff. It is more complicated for three-body and higher-body descriptors, but the end result is always a descriptor which changes smoothly with atomic positions.

Here is a histogram of the resulting descriptor array, i.e. of the interatomic distances

In [41]:
import matplotlib.pyplot as plt
plt.hist(d.descriptor)
plt.show()
../_images/Tutorials_quippy-descriptor-tutorial_24_0.png

Calculate size of descriptor data:

In [42]:
n_desc, n_cross = desc.descriptor_sizes(at)
print("n_desc=%d n_cross=%d" % (n_desc,n_cross))
n_desc=368 n_cross=736

n_desc is number of descriptors, n_cross is number of gradients

Gradients are returned in a DescriptorCalcResult object ( if the grad=True option is set ) which has the following elements: - descriptor = the descriptor values (equivalent to desc.calc(at)) - grad = the gradients - index = the indices (i_desc, i_atom, i_coord)

In [43]:
res = desc.calc(at, grad=True)
list(res)
Out[43]:
['descriptor', 'cutoff_grad', 'grad', 'index', 'cutoff']
In [44]:
res.descriptor[:,:10]
Out[44]:
array([[ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.5       ],
       [ 1.51554446],
       [ 2.47487373],
       [ 1.51554446],
       [ 2.47487373],
       [ 1.51554446],
       [ 2.47487373],
       [ 1.51554446],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.47487373],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.81403658],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 1.51554446],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.5       ],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.5       ],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.5       ],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.5       ],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 1.51554446],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.5       ],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.90204669],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.5       ],
       [ 2.90204669],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.47487373],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.5       ],
       [ 3.5       ],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.5       ],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.47487373],
       [ 2.90204669],
       [ 2.47487373],
       [ 1.51554446],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.5       ],
       [ 2.90204669],
       [ 3.5       ],
       [ 1.51554446],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.81403658],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 2.90204669],
       [ 1.51554446],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 3.81403658],
       [ 1.51554446],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.47487373],
       [ 2.90204669],
       [ 1.51554446],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 2.90204669],
       [ 3.81403658],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ],
       [ 3.5       ]])
In [45]:
res.grad[:,:10]
Out[45]:
array([[[-0.22941573],
        [ 0.6882472 ],
        [ 0.6882472 ]],

       [[ 0.22941573],
        [-0.6882472 ],
        [-0.6882472 ]],

       [[ 0.6882472 ],
        [-0.22941573],
        [ 0.6882472 ]],

       ...,
       [[ 0.        ],
        [ 1.        ],
        [ 0.        ]],

       [[-0.        ],
        [-0.        ],
        [-1.        ]],

       [[ 0.        ],
        [ 0.        ],
        [ 1.        ]]])
In [46]:
res.index[:,:10]
Out[46]:
array([[  1,   1],
       [  1,   2],
       [  2,   1],
       ...,
       [367,   8],
       [368,   8],
       [368,   8]], dtype=int32)

A many-body descriptor: SOAP

In [16]:
desc = descriptors.Descriptor("soap cutoff=3 l_max=4 n_max=4 atom_sigma=0.5 n_Z=1 Z={6} ")
In [35]:
at.set_cutoff(desc.cutoff())
at.calc_connect()

There are now only 8 descriptors, because SOAP produces one for each atom in the structure

In [18]:
desc.descriptor_sizes(at)
Out[18]:
(8, 258)

But each descriptor now is a long vector, because it encodes the entire environment of the atom up to the cutoff. The length of the vector depends on l_max and n_max and also on the number of atom types.

In [19]:
desc.n_dim
Out[19]:
51
In [20]:
desc.calc(at)
Out[20]:
{'cutoff': array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.]),
 'descriptor': array([[  4.73572570e-01,   5.11159766e-06,   1.01308559e-06,
           1.60812107e-03,   5.47553526e-04,   6.27690415e-01,
           4.95953867e-05,   9.82948612e-06,   1.54957207e-02,
           5.47660232e-03,   4.15981924e-01,   2.40600155e-04,
           4.76854071e-05,   7.46577370e-02,   2.73883482e-02,
           3.18341025e-01,  -5.92864850e-07,  -1.17486739e-07,
          -1.41512045e-03,   1.81695390e-03,   2.98357233e-01,
          -4.06747903e-06,  -8.06043591e-07,  -9.64209426e-03,
           1.28503115e-02,   1.06996282e-01,   3.43814942e-08,
           6.81242239e-09,   6.22655008e-04,   3.01463911e-03,
          -2.81631715e-03,   5.36228874e-09,   1.06263310e-09,
           1.15339605e-05,  -1.66628637e-05,  -2.63952342e-03,
           3.67891552e-08,   7.29042791e-09,   7.85880344e-05,
          -1.17847232e-04,  -1.33866723e-03,  -4.39778747e-10,
          -8.71386960e-11,  -7.17707326e-06,  -3.90981365e-05,
           8.37426278e-06,   2.81263730e-12,   5.57301933e-13,
           4.13635000e-08,   2.53540179e-07,   0.00000000e+00],
        [  2.49140590e-01,   3.06897443e-04,   2.24691086e-04,
           2.63645993e-03,   8.44257436e-04,   5.55127085e-01,
           2.97737414e-03,   2.17965866e-03,   2.54342326e-02,
           8.40520121e-03,   6.18458197e-01,   1.44425393e-02,
           1.05720969e-02,   1.22683598e-01,   4.18410093e-02,
           2.47745044e-01,  -3.90932807e-05,  -3.07806268e-05,
          -1.98138033e-03,   2.35398492e-03,   3.90335370e-01,
          -2.68180541e-04,  -2.11137369e-04,  -1.35142491e-02,
           1.65884021e-02,   1.23178658e-01,   2.48989464e-06,
           2.10833239e-06,   7.59273692e-04,   3.41878216e-03,
          -2.19112484e-03,   3.46295943e-07,   2.69352586e-07,
           1.61901122e-05,  -2.16062298e-05,  -3.45223263e-03,
           2.37559580e-06,   1.84760358e-06,   1.10427087e-04,
          -1.52258473e-04,  -1.54068059e-03,  -3.11918586e-08,
          -2.60914232e-08,  -8.76903344e-06,  -4.43838310e-05,
           9.63517840e-06,   1.95376148e-10,   1.61445692e-10,
           5.06386375e-08,   2.88103389e-07,   0.00000000e+00],
        [  2.23838398e-01,   3.78089923e-05,   4.06539273e-05,
           1.92860775e-03,   7.66122563e-04,   5.09433866e-01,
           3.53632752e-04,   4.29949407e-04,   1.85669919e-02,
           7.76143527e-03,   5.79710332e-01,   1.65484402e-03,
           2.28688255e-03,   8.93771594e-02,   3.93431430e-02,
           2.92339646e-01,  -1.55904376e-04,   4.02508059e-04,
          -1.89111550e-03,   3.67450327e-03,   4.70463509e-01,
          -1.01397193e-03,   3.22651119e-03,  -1.28156879e-02,
           2.67826166e-02,   1.90902163e-01,   4.60348034e-04,
           3.74809897e-03,   1.39702795e-03,   1.25434798e-02,
          -2.58972445e-03,   1.32417523e-06,  -3.56120051e-06,
           1.55903764e-05,  -3.32865245e-05,  -4.16765521e-03,
           8.60690247e-06,  -2.85979893e-05,   1.05611567e-04,
          -2.42520968e-04,  -2.39161731e-03,  -5.59006314e-06,
          -4.74862442e-05,  -1.67590764e-05,  -1.59583514e-04,
           1.49810595e-05,   3.39496223e-08,   3.00874317e-07,
           1.00726608e-07,   1.01530792e-06,   0.00000000e+00],
        [  2.21912827e-01,   3.22794357e-04,   2.74608154e-04,
           2.71347565e-03,   9.21261052e-04,   5.22685782e-01,
           3.10761607e-03,   2.61564838e-03,   2.61192465e-02,
           9.15687879e-03,   6.15557988e-01,   1.49623108e-02,
           1.24681640e-02,   1.25730679e-01,   4.55125688e-02,
           2.60247510e-01,  -3.16196242e-04,  -5.90933824e-04,
          -2.70412292e-03,   2.39722324e-03,   4.33440876e-01,
          -2.09668723e-03,  -3.79982381e-03,  -1.80490450e-02,
           1.69318863e-02,   1.52602189e-01,   6.07534416e-04,
           2.09763755e-03,   4.23793685e-03,   3.79617175e-03,
          -2.29869885e-03,   2.76019211e-06,   5.15137054e-06,
           2.24848968e-05,  -2.19757551e-05,  -3.82847099e-03,
           1.83031786e-05,   3.31247321e-05,   1.49959011e-04,
          -1.55178180e-04,  -1.90621225e-03,  -7.49516446e-06,
          -2.58557011e-05,  -5.12063357e-05,  -4.87638925e-05,
           1.19056128e-05,   4.62340053e-08,   1.59350048e-07,
           3.09463332e-07,   3.13393204e-07,   0.00000000e+00],
        [  2.23838398e-01,   3.78089923e-05,   4.06539273e-05,
           1.92860775e-03,   7.66122563e-04,   5.09433866e-01,
           3.53632752e-04,   4.29949407e-04,   1.85669919e-02,
           7.76143527e-03,   5.79710332e-01,   1.65484402e-03,
           2.28688255e-03,   8.93771594e-02,   3.93431430e-02,
           2.92339646e-01,  -1.55904376e-04,   4.02508059e-04,
          -1.89111550e-03,   3.67450327e-03,   4.70463509e-01,
          -1.01397193e-03,   3.22651119e-03,  -1.28156879e-02,
           2.67826166e-02,   1.90902163e-01,   4.60348034e-04,
           3.74809897e-03,   1.39702795e-03,   1.25434798e-02,
          -2.58972445e-03,   1.32417523e-06,  -3.56120051e-06,
           1.55903764e-05,  -3.32865245e-05,  -4.16765521e-03,
           8.60690247e-06,  -2.85979893e-05,   1.05611567e-04,
          -2.42520968e-04,  -2.39161731e-03,  -5.59006314e-06,
          -4.74862442e-05,  -1.67590764e-05,  -1.59583514e-04,
           1.49810595e-05,   3.39496223e-08,   3.00874317e-07,
           1.00726608e-07,   1.01530792e-06,   0.00000000e+00],
        [  2.21912827e-01,   3.22794357e-04,   2.74608154e-04,
           2.71347565e-03,   9.21261052e-04,   5.22685782e-01,
           3.10761607e-03,   2.61564838e-03,   2.61192465e-02,
           9.15687879e-03,   6.15557988e-01,   1.49623108e-02,
           1.24681640e-02,   1.25730679e-01,   4.55125688e-02,
           2.60247510e-01,  -3.16196242e-04,  -5.90933824e-04,
          -2.70412292e-03,   2.39722324e-03,   4.33440876e-01,
          -2.09668723e-03,  -3.79982381e-03,  -1.80490450e-02,
           1.69318863e-02,   1.52602189e-01,   6.07534416e-04,
           2.09763755e-03,   4.23793685e-03,   3.79617175e-03,
          -2.29869885e-03,   2.76019211e-06,   5.15137054e-06,
           2.24848968e-05,  -2.19757551e-05,  -3.82847099e-03,
           1.83031786e-05,   3.31247321e-05,   1.49959011e-04,
          -1.55178180e-04,  -1.90621225e-03,  -7.49516446e-06,
          -2.58557011e-05,  -5.12063357e-05,  -4.87638925e-05,
           1.19056128e-05,   4.62340053e-08,   1.59350048e-07,
           3.09463332e-07,   3.13393204e-07,   0.00000000e+00],
        [  2.23838398e-01,   3.78089923e-05,   4.06539273e-05,
           1.92860775e-03,   7.66122563e-04,   5.09433866e-01,
           3.53632752e-04,   4.29949407e-04,   1.85669919e-02,
           7.76143527e-03,   5.79710332e-01,   1.65484402e-03,
           2.28688255e-03,   8.93771594e-02,   3.93431430e-02,
           2.92339646e-01,  -1.55904376e-04,   4.02508059e-04,
          -1.89111550e-03,   3.67450327e-03,   4.70463509e-01,
          -1.01397193e-03,   3.22651119e-03,  -1.28156879e-02,
           2.67826166e-02,   1.90902163e-01,   4.60348034e-04,
           3.74809897e-03,   1.39702795e-03,   1.25434798e-02,
          -2.58972445e-03,   1.32417523e-06,  -3.56120051e-06,
           1.55903764e-05,  -3.32865245e-05,  -4.16765521e-03,
           8.60690247e-06,  -2.85979893e-05,   1.05611567e-04,
          -2.42520968e-04,  -2.39161731e-03,  -5.59006314e-06,
          -4.74862442e-05,  -1.67590764e-05,  -1.59583514e-04,
           1.49810595e-05,   3.39496223e-08,   3.00874317e-07,
           1.00726608e-07,   1.01530792e-06,   0.00000000e+00],
        [  2.21912827e-01,   3.22794357e-04,   2.74608154e-04,
           2.71347565e-03,   9.21261052e-04,   5.22685782e-01,
           3.10761607e-03,   2.61564838e-03,   2.61192465e-02,
           9.15687879e-03,   6.15557988e-01,   1.49623108e-02,
           1.24681640e-02,   1.25730679e-01,   4.55125688e-02,
           2.60247510e-01,  -3.16196242e-04,  -5.90933824e-04,
          -2.70412292e-03,   2.39722324e-03,   4.33440876e-01,
          -2.09668723e-03,  -3.79982381e-03,  -1.80490450e-02,
           1.69318863e-02,   1.52602189e-01,   6.07534416e-04,
           2.09763755e-03,   4.23793685e-03,   3.79617175e-03,
          -2.29869885e-03,   2.76019211e-06,   5.15137054e-06,
           2.24848968e-05,  -2.19757551e-05,  -3.82847099e-03,
           1.83031786e-05,   3.31247321e-05,   1.49959011e-04,
          -1.55178180e-04,  -1.90621225e-03,  -7.49516446e-06,
          -2.58557011e-05,  -5.12063357e-05,  -4.87638925e-05,
           1.19056128e-05,   4.62340053e-08,   1.59350048e-07,
           3.09463332e-07,   3.13393204e-07,   0.00000000e+00]])}

Note that the cutoff array is now all 1, because SOAP takes the cutoff into account when it computes the descriptor vector

We now add a hydrogen atom to the structure

In [34]:
at.add_atoms((0.2,0.2,0.2),(1))
In [36]:
at.calc_connect()
desc.descriptor_sizes(at)
Out[36]:
(9, 285)

The descriptor sizes did not change! This is because the descriptor was set up above to only look at carbon atoms (Z=6). We need a new descriptor that takes account of H atoms.

In [23]:
desc = descriptors.Descriptor("soap cutoff=3 l_max=4 n_max=4 atom_sigma=0.5 n_Z=2 Z={1 6} n_species=2 species_Z={1 6}")

The specification of which atoms are used as SOAP centers is separate to the specification of which atoms are taken into account in the environment. The n_Z=2 Z={1 6} options specify that both H and C are to be taken as SOAP centers. The n_species=2 species_Z={1 6} options specify the atom types to be taken into account in the environment.

Now the dimensionality of the SOAP descriptor goes up:

In [24]:
desc.n_dim
Out[24]:
181

And the size also increases to 9 (and the cross terms go up too), reflecting the fact that there are 9 atoms altogether.

In [39]:
desc.descriptor_sizes(at)
Out[39]:
(9, 285)
In [38]:
desc.calc(at)
Out[38]:
{'cutoff': array([ 1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.,  1.]),
 'descriptor': array([[  8.77557915e-02,   6.67877090e-06,   1.32368918e-06, ...,
           5.39505036e-08,   3.31313515e-07,   0.00000000e+00],
        [  1.77188829e-03,   3.74461483e-04,   2.74157244e-04, ...,
           5.81842224e-08,   3.57313054e-07,   0.00000000e+00],
        [  1.24011279e-04,   4.57421978e-05,   4.91840662e-05, ...,
           5.81830007e-08,   3.57305552e-07,   0.00000000e+00],
        ...,
        [  1.24011279e-04,   4.57421978e-05,   4.91840662e-05, ...,
           5.81830007e-08,   3.57305552e-07,   0.00000000e+00],
        [  3.76907877e-04,   4.04885591e-04,   3.44444944e-04, ...,
           5.79365059e-08,   3.55791811e-07,   0.00000000e+00],
        [  1.35807048e-01,   0.00000000e+00,   0.00000000e+00, ...,
           3.44738745e-07,   1.39187207e-07,   0.00000000e+00]])}

Note that the same descriptor can be obtained not via python, but from the unix command line, using the quip program. The input needs to be an extended XYZ file, and the descriptor specification is identical to the above.

So let’s write out an xyz file:

In [37]:
at.write("diamondH.xyz")

The following command will print all the descriptor vectors, each vector on a line, which starts with the string DESC

quip atoms_filename=diamondH.xyz descriptor_str="soap cutoff=3 l_max=4 n_max=4 atom_sigma=0.5 n_Z=2 Z={1 6} n_species=2 species_Z={1 6}"

General_monomer example: benzene

Now for a more interesting descriptor: a three-site benzene monomer

In [47]:
desc_monomer = descriptors.Descriptor('general_monomer signature={6 6 6} atom_ordercheck=F')

Three intramolecular distances = dimensionality 3:

In [48]:
desc_monomer.n_dim
Out[48]:
3

And a lot more permutations now:

In [49]:
desc_monomer.n_perm
Out[49]:
6
In [50]:
desc_monomer.permutations()
Out[50]:
array([[1, 2, 3],
       [2, 1, 3],
       [1, 3, 2],
       [3, 1, 2],
       [2, 3, 1],
       [3, 2, 1]], dtype=int32)

Load some test configurations

In [51]:
benzat = quippy.AtomsList('benzene_frames.xyz')
In [52]:
benzat.pos.shape
Out[52]:
(40, 3, 648)
In [53]:
for i in range(len(benzat)):
    benzat[i].set_cutoff(desc_monomer.cutoff()+0.5)
    benzat[i].calc_connect()

Calling calc or any of the other methods on an AtomsList returns a list of results. Here we look at the results for the first configuration:

In [54]:
res = desc_monomer.calc(benzat, grad=True)[0]
In [55]:
res.grad.shape
Out[55]:
(648, 3, 3)