def test_composition(structure): meta_doc = StructureMetadata.from_structure(structure) comp_meta_doc = StructureMetadata.from_composition(structure.composition) assert meta_doc.elements == comp_meta_doc.elements assert meta_doc.nelements == comp_meta_doc.nelements assert meta_doc.formula_pretty == comp_meta_doc.formula_pretty assert meta_doc.formula_anonymous == comp_meta_doc.formula_anonymous assert meta_doc.chemsys == comp_meta_doc.chemsys
def test_structure_metadata_fewer_fields(structure): meta_doc = StructureMetadata.from_structure( structure, fields=["nsites", "nelements", "volume"]) assert meta_doc.nsites == 1 assert meta_doc.nelements == 1 assert meta_doc.volume == 27.0
def test_structure_metadata(structure): meta_doc = StructureMetadata.from_structure(structure) assert meta_doc.nsites == 1 assert meta_doc.elements == ["Fe"] assert meta_doc.nelements == 1 assert meta_doc.formula_pretty == "Fe" assert meta_doc.formula_anonymous == "A" assert meta_doc.chemsys == "Fe" assert meta_doc.volume == 27.0 assert meta_doc.density == 3.4345483027509993 assert meta_doc.density_atomic == 27.0
def from_structure( # type: ignore[override] structure: Structure, material_id: str, fields: Optional[List[str]] = None, **kwargs) -> "MaterialsDoc": """ Builds a materials document using the minimal amount of information """ meta = StructureMetadata.from_structure(structure, fields=fields) ordering = CollinearMagneticStructureAnalyzer(structure).ordering kwargs.update(**meta.dict()) if "last_updated" not in kwargs: kwargs["last_updated"] = datetime.utcnow() if "created_at" not in kwargs: kwargs["created_at"] = datetime.utcnow() return MaterialsDoc(structure=structure, material_id=material_id, ordering=ordering, **kwargs)
def test_schema(): StructureMetadata.schema()