pymatgen¶
Convert an OPTIMADE structure, in the format of StructureResource to a pymatgen Molecule or Structure object.
This conversion function relies on the pymatgen package.
For more information on the pymatgen code see their documentation.
get_pymatgen(optimade_structure) ¶
Get pymatgen Structure or Molecule from OPTIMADE structure.
This function will return either a pymatgen Structure or Molecule based on the periodicity or periodic dimensionality of OPTIMADE structure.
For bulk, three-dimensional structures, a pymatgen Structure is returned. This means, if the dimension_types attribute is comprised of all 1s (or Periodicity.PERIODICs).
Otherwise, a pymatgen Molecule is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
optimade_structure | StructureResource | OPTIMADE structure. | required |
Returns:
| Type | Description |
|---|---|
Union[pymatgen.core.structure.Structure, pymatgen.core.structure.Molecule] | A pymatgen |
Source code in optimade/adapters/structures/pymatgen.py
def get_pymatgen(optimade_structure: OptimadeStructure) -> Union[Structure, Molecule]:
"""Get pymatgen `Structure` or `Molecule` from OPTIMADE structure.
This function will return either a pymatgen `Structure` or `Molecule` based
on the periodicity or periodic dimensionality of OPTIMADE structure.
For bulk, three-dimensional structures, a pymatgen `Structure` is returned.
This means, if the [`dimension_types`][optimade.models.structures.StructureResourceAttributes.dimension_types]
attribute is comprised of all `1`s (or [`Periodicity.PERIODIC`][optimade.models.structures.Periodicity.PERIODIC]s).
Otherwise, a pymatgen `Molecule` is returned.
Parameters:
optimade_structure: OPTIMADE structure.
Returns:
A pymatgen `Structure` or `Molecule` based on the periodicity of the
OPTIMADE structure.
"""
if "optimade.adapters" in repr(globals().get("Structure")):
warn(PYMATGEN_NOT_FOUND, AdapterPackageNotFound)
return None
if all(optimade_structure.attributes.dimension_types):
return _get_structure(optimade_structure)
return _get_molecule(optimade_structure)