scippneutron.io.cif.Block#

class scippneutron.io.cif.Block(name, content=None, *, comment='', schema=None)[source]#

A CIF data block.

A block contains an ordered sequence of loops and chunks (groups of key-value-pairs). The contents are written to file in the order specified in the block.

__init__(name, content=None, *, comment='', schema=None)[source]#

Create a new CIF data block.

Parameters:
  • name (str) – Name of the block. Can contain any non-whitespace characters. Can be at most 75 characters long.

  • content (Optional[Iterable[Mapping[str, Any] | Loop | Chunk]], default: None) – Initial loops and chunks. dicts are converted to scippneutron.io.cif.Chunk.

  • comment (str, default: '') – Optional comment that can be written above the block in the file.

  • schema (Union[CIFSchema, Iterable[CIFSchema], None], default: None) – CIF schemas used for the block. Content is not checked against the schema, but the schema is written to the file.

Methods

__init__(name[, content, comment, schema])

Create a new CIF data block.

add(content, /[, comment])

Add a chunk or loop to the end of the block.

copy()

Return a shallow copy of the block.

write(f)

Write this block to a file.

Attributes

comment

Optional comment that can be written above the object in the file.

name

Name of the block.

schema

CIF schemas used for the block.

add(content, /, comment='')[source]#

Add a chunk or loop to the end of the block.

Parameters:
  • content (Mapping[str, Any] | Iterable[tuple[str, Any]] | Chunk | Loop) – A loop, chunk, or mapping to add. Mappings get converted to chunks.

  • comment (str, default: '') – Optional comment that can be written above the chunk or loop in the file.

Return type:

None

copy()[source]#

Return a shallow copy of the block.

Return type:

Block

property name: str#

Name of the block.

property schema: set[CIFSchema]#

CIF schemas used for the block.

write(f)[source]#

Write this block to a file.

Used mainly internally, use scippneutron.io.cif.save_cif() instead.

Parameters:

f (TextIOBase) – File handle.

Return type:

None