pymatgen.io.cif module¶
Wrapper classes for Cif input and output from Structures.
-
class
CifBlock(data, loops, header)[source]¶ Bases:
objectObject for storing cif data. All data is stored in a single dictionary. Data inside loops are stored in lists in the data dictionary, and information on which keys are grouped together are stored in the loops attribute.
- Parameters
data – dict or OrderedDict of data to go into the cif. Values should be convertible to string, or lists of these if the key is in a loop
loops – list of lists of keys, grouped by which loop they should appear in
header – name of the block (appears after the data_ on the first line)
-
classmethod
from_string(string)[source]¶ Reads CifBlock from string.
- Parameters
string – String representation.
- Returns
CifBlock
-
maxlen= 70¶
-
class
CifFile(data, orig_string=None, comment=None)[source]¶ Bases:
objectReads and parses CifBlocks from a .cif file or string
- Parameters
data (OrderedDict) – Of CifBlock objects.å
orig_string (str) – The original cif string.
comment (str) – Comment string.
-
class
CifParser(filename, occupancy_tolerance=1.0, site_tolerance=0.0001)[source]¶ Bases:
objectParses a CIF file. Attempts to fix CIFs that are out-of-spec, but will issue warnings if corrections applied. These are also stored in the CifParser’s errors attribute.
- Parameters
filename (str) – CIF filename, bzipped or gzipped CIF files are fine too.
occupancy_tolerance (float) – If total occupancy of a site is between 1 and occupancy_tolerance, the occupancies will be scaled down to 1.
site_tolerance (float) – This tolerance is used to determine if two sites are sitting in the same position, in which case they will be combined to a single disordered site. Defaults to 1e-4.
-
static
from_string(cif_string, occupancy_tolerance=1.0)[source]¶ Creates a CifParser from a string.
- Parameters
cif_string (str) – String representation of a CIF.
occupancy_tolerance (float) – If total occupancy of a site is between 1 and occupancy_tolerance, the occupancies will be scaled down to 1.
- Returns
CifParser
-
get_bibtex_string()[source]¶ Get BibTeX reference from CIF file. :param data: :return: BibTeX string
-
get_lattice(data, length_strings=('a', 'b', 'c'), angle_strings=('alpha', 'beta', 'gamma'), lattice_type=None)[source]¶ Generate the lattice from the provided lattice parameters. In the absence of all six lattice parameters, the crystal system and necessary parameters are parsed
-
get_magsymops(data)[source]¶ Equivalent to get_symops except for magnetic symmetry groups. Separate function since additional operation for time reversal symmetry (which changes magnetic moments on sites) needs to be returned.
-
get_structures(primitive=True)[source]¶ Return list of structures in CIF file. primitive boolean sets whether a conventional cell structure or primitive cell structure is returned.
- Parameters
primitive (bool) – Set to False to return conventional unit cells. Defaults to True. With magnetic CIF files, will return primitive magnetic cell which may be larger than nuclear primitive cell.
- Returns
List of Structures.
-
get_symops(data)[source]¶ In order to generate symmetry equivalent positions, the symmetry operations are parsed. If the symops are not present, the space group symbol is parsed, and symops are generated.
-
property
has_errors¶ Whether there are errors/warnings detected in CIF parsing.
- Type
return
-
class
CifWriter(struct, symprec=None, write_magmoms=False, significant_figures=8)[source]¶ Bases:
objectA wrapper around CifFile to write CIF files from pymatgen structures.
- Parameters
struct (Structure) – structure to write
symprec (float) – If not none, finds the symmetry of the structure and writes the cif with symmetry information. Passes symprec to the SpacegroupAnalyzer
write_magmoms (bool) – If True, will write magCIF file. Incompatible with symprec
significant_figures (int) – Specifies precision for formatting of floats. Defaults to 8.
-
sub_spgrp(string, count=0, flags=0)¶ Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. repl can be either a string or a callable; if a string, backslash escapes in it are processed. If it is a callable, it’s passed the Match object and must return a replacement string to be used.