Using AMDs¶
Calculation¶
The average minimum distance (AMD) of a crystal is given by amd.AMD()
.
It accepts a crystal and an integer k, returning \(\text{AMD}_k\) as a 1D NumPy array.
If you have a .cif file, use amd.CifReader
to read the crystals
(see Reading cifs). If csd-python-api is installed, amd.CSDReader
accepts CSD refcodes (see Reading from the CSD).
# get AMDs of crystals in a .cif
crystals = list(amd.CifReader('file.cif'))
amds = [amd.AMD(crystal, 100) for crystal in crystals]
# get AMDs of crystals in DEBXIT family
csd_reader = amd.CSDReader('DEBXIT', families=True)
amds = [amd.AMD(crystal, 100) for crystal in csd_reader]
You can also give the coordinates of motif points and unit cell as a tuple of numpy arrays, in Cartesian form:
# AMD (k=10) of 3D cubic lattice
motif = np.array([[0,0,0]])
cell = np.identity(3)
cubic_lattice = (motif, cell)
cubic_amd = amd.AMD(cubic_lattice, 10)
The object returned by amd.AMD(crystal, k)
is a vector with k elements.
Note: The AMD of a crystal can be calculated from its PDD with amd.PDD_to_AMD()
,
which is faster if both are needed.
Comparison¶
AMDs are just vectors that can be compared with any metric, but the amd.compare
module has functions to compare collections of AMDs for you.
amd.AMD_pdist()
and amd.AMD_cdist()
are like SciPy’s functions pdist
and cdist
. pdist
takes a set and compares all elements pairwise,
whereas cdist
takes two sets and compares elements in one with the other.
cdist
returns a 2D distance matrix, but pdist
returns a condensed distance matrix
(see SciPy’s pdist).
The default metric for AMD comparisons is L-infinity (aka Chebyshev), but it can be changed to any metric
accepted by SciPy’s pdist/cdist.
# compare crystals in file1.cif with those in file2.cif by AMD, k=100
amds1 = [amd.AMD(crystal, 100) for crystal in amd.CifReader('file1.cif')]
amds2 = [amd.AMD(crystal, 100) for crystal in amd.CifReader('file2.cif')]
distance_matrix = amd.AMD_cdist(amds1, amds2)
# compare everything in file1.cif with each other (using L-infinity)
condensed_dm = amd.AMD_pdist(amds1)
Comparison options¶
amd.AMD_pdist()
and amd.AMD_cdist()
share the following optional arguments:
metric
(defaultchebyshev
) chooses the metric used for comparison, see SciPy’s cdist/pdist for a list of accepted metrics.low_memory
(defaultFalse
, requiresmetric='chebyshev'
) uses a slower algorithm with a smaller memory footprint, for larger inputs.