JASON Document Module
Module contents
- class beautifuljason.document.Document(file_name: str, is_temporary=False, mode='a')
Bases:
object
Represents a JASON document, providing methods to manipulate and extract data from it.
- Parameters:
file_name (str) – The file name of the JASON document.
is_temporary (bool) – Whether the document is temporary. If True, the document will be deleted when the Document object is destroyed.
mode (str) – The mode in which the file should be opened. Defaults to ‘a’ (append mode).
- close()
Closes the document file.
- copy(file_name: str | bytes)
Copies the JASON document to a new file.
Note
Starting from h5py v3.4, it’s essential to close the h5py.File object before using the ‘copy’ method. This constraint diminishes the utility of the ‘copy’ method. Intentionally, the self.close() line is omitted in this method, delegating the responsibility of calling ‘close’ to the programmer.
- Parameters:
file_name (str | bytes) – The destination file name.
- create_image_data(image_file: str) Image
Creates a new image data in the document. The image data is created from the specified image file. It’s necessary to create graphics.ImageGraphicsItem items in the document to display the image data. Multiple image items can be linked to the same image data.
- Parameters:
image_file (
str
) – The path to the image file.- Returns:
The created image data object.
- Return type:
Image
- create_image_item(data_id: str) ImageGraphicsItem
Creates a new image item in the document.
- Parameters:
data_id (
str
) – The ID of the image data object.- Returns:
The created image graphics item.
- Return type:
graphics.ImageGraphicsItem
- create_nmrassignments_table(mol_item: MoleculeGraphicsItem, mol_data: Molecule) AssignmentTableGraphicsItem
Creates a new NMR assignments table in the document.
- Parameters:
mol_item (
MoleculeGraphicsItem
) – The molecule graphics item to which the table is linked.mol_data (
data.Molecule
) – The molecule data for the table.
- Returns:
The created NMR assignments table graphics item.
- Return type:
graphics.AssignmentTableGraphicsItem
New in version 1.1.0.
- create_nmrmultiplet_report(spec_item: NMRSpectrumGraphicsItem, spec_data: NMRSpectrum) NMRMultipletReportGraphicsItem
Creates a new NMR multiplet report in the document.
- Parameters:
spec_item (
graphics.NMRSpectrumGraphicsItem
) – The spectrum graphics item to which the report is linked.spec_data (
data.NMRSpectrum
) – The NMR spectrum data for the report.
- Returns:
The created NMR multiplet report graphics item.
- Return type:
graphics.NMRMultipletReportGraphicsItem
- create_nmrmultiplets_table(spec_item: NMRSpectrumGraphicsItem, spec_data: NMRSpectrum) NMRMultipletTableGraphicsItem
Creates a new NMR multiplets table in the document.
- Parameters:
spec_item (
NMRSpectrumGraphicsItem
) – The spectrum graphics item to which the table is linked.spec_data (
data.NMRSpectrum
) – The NMR spectrum data for the table.
- Returns:
The created NMR multiplets table graphics item.
- Return type:
graphics.NMRMultipletTableGraphicsItem
- create_nmrparams_table(spec_item: NMRSpectrumGraphicsItem, spec_data: NMRSpectrum) NMRParamTableGraphicsItem
Creates a new NMR parameters table in the document.
- Parameters:
spec_item (
graphics.NMRSpectrumGraphicsItem
) – The spectrum graphics item to which the table is linked.spec_data (
data.NMRSpectrum
) – The NMR spectrum data for the table.
- Returns:
The created NMR parameters table graphics item.
- Return type:
graphics.NMRParamTableGraphicsItem
- create_nmrpeaks_table(spec_item: NMRSpectrumGraphicsItem, spec_data: NMRSpectrum) NMRPeakTableGraphicsItem
Creates a new NMR peaks table in the document.
- Parameters:
spec_item (
NMRSpectrumGraphicsItem
) – The spectrum graphics item to which the table is linked.spec_data (
data.NMRSpectrum
) – The NMR spectrum data for the table.
- Returns:
The created NMR peaks table graphics item.
- Return type:
graphics.NMRPeakTableGraphicsItem
- create_text_item(html_str: str = '') TextGraphicsItem
Creates a new text item in the document.
- Parameters:
html_str (
str
) – The HTML text to be added.- Returns:
The created text graphics item.
- Return type:
graphics.TextGraphicsItem
- property image_data: Iterable[Image]
- Returns:
A list of all image data objects in the document.
- Return type:
Iterable
ofdata.Image
- property items: list[GraphicsItem]
- Returns:
A list of all graphics items in the document.
- Return type:
list
ofgraphics.GraphicsItem
- items_by_type(item_type: Type | GraphicsItem) list
Returns a list of graphics items of the specified type.
- Parameters:
item_type (
GraphicsItem.Type
) – The type of graphics item to filter by.- Returns:
A list of graphics items of the specified type.
- Return type:
list
New in version 1.1.0.
- load(mode='a')
Loads the JASON document file.
- Parameters:
mode (str) – The mode in which the file should be opened. Defaults to ‘a’ (append mode).
- property mol_data: Iterable[Molecule]
- Returns:
A list of all molecule data objects in the document.
- Return type:
Iterable
ofdata.Molecule
New in version 1.1.0.
- property mol_items: list[MoleculeGraphicsItem]
A convenience property to get all molecule graphics items in the document.
- Returns:
A list of all molecule graphics items in the document.
- Return type:
list
ofgraphics.MoleculeGraphicsItem
New in version 1.1.0.
- property nmr_data: Iterable[NMRSpectrum]
- Returns:
A list of all NMR data objects in the document.
- Return type:
Iterable
ofNMRSpectrum
- property nmr_items: list[NMRSpectrumGraphicsItem]
A convenience property to get all NMR spectrum graphics items in the document.
- Returns:
A list of all NMR spectrum graphics items in the document.
- Return type:
list
ofgraphics.NMRSpectrumGraphicsItem
- remove()
Closes and removes the document file if it’s marked as temporary.