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
orccdc
, yieldingperiodicset.PeriodicSet
objects which can be passed tocalculate.AMD()
orcalculate.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 tocalculate.AMD()
orcalculate.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.
- class amd.io.SetReader(filename: str)
Bases:
object
Read
periodicset.PeriodicSet
objects from a .hdf5 file written withSetWriter
. Acts like a read-only dict that can be iterated over (preserves write order).- family(refcode: str) Iterable[amd.periodicset.PeriodicSet]
Yield any :class:`.periodicset.PeriodicSet`s whose name starts with input refcode.
- extract_tags() dict
Return
dict
with scalar data in the tags of items inSetReader
.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)