amd.io module

Contains I/O tools, including a .CIF reader and CSD reader (csd-python-api only) to extract periodic set representations of crystals which can be passed to calculate.AMD() and calculate.PDD().

The CifReader and CSDReader return periodicset.PeriodicSet objects, which can be given to calculate.AMD() and calculate.PDD() to calculate the AMD/PDD of a crystal.

These intermediate periodicset.PeriodicSet representations can be written to a .hdf5 file with SetWriter (along with their metadata), which can be read back with SetReader. This is much faster than rereading a .CIF or recomputing invariants.

class amd.io.CifReader(filename, reader='ase', remove_hydrogens=False, disorder='skip', heaviest_component=False, extract_data=None, include_if=None, show_warnings=True)

Bases: amd.io._Reader

Read all structures in a .CIF with ase or ccdc, yielding periodicset.PeriodicSet objects which can be passed to calculate.AMD() or calculate.PDD().

Examples

Put all crystals in mycif.cif in a list:

structures = list(amd.CifReader('mycif.cif'))

Reads just one, convinient when the .CIF has one crystal:

periodic_set = amd.CifReader('mycif.cif').read_one()

If the folder ‘cifs’ has many .CIFs each with one crystal:

import os
folder = 'cifs'
structures = []
for filename in os.listdir(folder):
    p_set = amd.CifReader(os.path.join(folder, filename)).read_one()
    structures.append(p_set)

Make list of AMD (with k=100) for crystals in mycif.cif:

amds = []
for periodic_set in amd.CifReader('mycif.cif'):
    amds.append(amd.AMD(periodic_set, 100))
class amd.io.CSDReader(refcodes=None, families=False, remove_hydrogens=False, disorder='skip', heaviest_component=False, extract_data=None, include_if=None, show_warnings=True)

Bases: amd.io._Reader

Read Entries from the CSD, yielding periodicset.PeriodicSet objects.

The CSDReader returns periodicset.PeriodicSet objects which can be passed to calculate.AMD() or calculate.PDD().

Examples

Get crystals with refcodes in a list:

refcodes = ['DEBXIT01', 'DEBXIT05', 'HXACAN01']
structures = list(amd.CSDReader(refcodes))

Read refcode families (any whose refcode starts with strings in the list):

refcodes = ['ACSALA', 'HXACAN']
structures = list(amd.CSDReader(refcodes, families=True))

Create a generic reader, read crystals ‘on demand’ with CSDReader.entry():

reader = amd.CSDReader()
debxit01 = reader.entry('DEBXIT01')

# looping over this generic reader will yield all CSD entries
for periodic_set in reader:
    ...

Make list of AMD (with k=100) for crystals in these families:

refcodes = ['ACSALA', 'HXACAN']
amds = []
for periodic_set in amd.CSDReader(refcodes, families=True):
    amds.append(amd.AMD(periodic_set, 100))
entry(refcode: str) amd.periodicset.PeriodicSet

Read a PeriodicSet given any CSD refcode.

class amd.io.SetWriter(filename: str)

Bases: object

Write several periodicset.PeriodicSet objects to a .hdf5 file. Reading the .hdf5 is much faster than parsing a .CIF file.

write(periodic_set: amd.periodicset.PeriodicSet, name: Optional[str] = None)

Write a PeriodicSet object to file.

iwrite(periodic_sets: Iterable[amd.periodicset.PeriodicSet])

Write periodicset.PeriodicSet objects from an iterable to file.

close()

Close the SetWriter.

class amd.io.SetReader(filename: str)

Bases: object

Read periodicset.PeriodicSet objects from a .hdf5 file written with SetWriter. Acts like a read-only dict that can be iterated over (preserves write order).

close()

Close the SetReader.

family(refcode: str) Iterable[amd.periodicset.PeriodicSet]

Yield any :class:`.periodicset.PeriodicSet`s whose name starts with input refcode.

keys()

Yield names of items in the SetReader.

extract_tags() dict

Return dict with scalar data in the tags of items in SetReader.

Dict is in format easily passable to pandas.DataFrame, as in:

reader = amd.SetReader('periodic_sets.hdf5')
data = reader.extract_tags()
df = pd.DataFrame(data, index=reader.keys(), columns=data.keys())

Format of returned dict is for example:

{
    'density': [1.231, 2.532, ...],
    'family':  ['CBMZPN', 'SEMFAU', ...],
    ...
}

where the inner lists have the same order as the items in the SetReader.

amd.io.crystal_to_periodicset(crystal)
amd.io.cifblock_to_periodicset(block)