emmet.core.utils

Define utility functions used across the emmet namespace packages.

Functions

arrow_incompatible

Simple decorator to mark a Pydantic model as being incompatible with serialization using pyarrow.

confirm_molecule

Check that something that we expect to be a molecule is actually a Molecule object, and not a dictionary representation.

convert_datetime

Validate datetime-like objects.

dynamic_import

Import arbitrary module or object.

generate_robocrys_condensed_struct_and_description

Get robocrystallographer description of a structure.

get_flat_models_from_model

Get all sub-models from a pydantic model.

get_graph_hash

Return the Weisfeiler Lehman (WL) graph hash of the MoleculeGraph described by this molecule, using the OpenBabelNN strategy with extension for metal coordinate bonds

get_hash_blocked

Get the hash of a file in byte chunks.

get_molecule_id

Return an MPculeID for a molecule, with the hash component based on a particular attribute of the molecule graph representation.

get_num_formula_units

Get the number of formula units in a dict-like composition.

get_sg

helper function to get spacegroup with a loose tolerance

group_molecules

Groups molecules according to composition, charge, and equality

group_structures

Groups structures according to space group and structure matching

jsanitize

This method cleans an input json-like object, either a list or a dict or some sequence, nested or otherwise, by converting all non-string dictionary keys (such as int and float) to strings, and also recursively encodes all objects using Monty's as_dict() protocol. Args: obj: input json-like object. strict (bool): This parameters sets the behavior when jsanitize encounters an object it does not understand. If strict is True, jsanitize will try to get the as_dict() attribute of the object. If no such attribute is found, an attribute error will be thrown. If strict is False, jsanitize will simply call str(object) to convert the object to a string representation. allow_bson (bool): This parameters sets the behavior when jsanitize encounters an bson supported type such as objectid and datetime. If True, such bson types will be ignored, allowing for proper insertion into MongoDb databases. Returns: Sanitized dict that can be json serialized.

make_mol_graph

Construct a MoleculeGraph using OpenBabelNN with metal_edge_extender and (optionally) Critic2 bonding information.

requires_arrow

Decorator for pyarrow-dependent functionality.

set_msonable_type_adapter

Decorator for MSONables defined in emmet with arrow compatible type hints.

type_override

Pydantic model decorator for declaring a field should be serialized as a type that does not match the type hint for the field.

undeform_structure

Get an undeformed structure by applying transformations in a reverse order.

utcnow

Get UTC time right now.

Classes

TYPE_CHECKING

bool(x) -> bool