chemfp.fpb_io module¶
I/O routines for the FPB format.
This is an internal chemfp module. It should not be imported by programs which use the public API. (Let me know if anything else should be part of the public API.)
This module contains class definitions for a few objects which are
returned as part of the public API. The FPBError
exception is raised if an input file is not in FPB format. The
function chemfp.open_fingerprint_writer()
returns an
OrderedFPBWriter
or InputOrderFPBWriter
instance
to write an FPB file when using reorder=True
and
reorder=False
, respectively.
FPB files are opened as a FPBFingerprintArena
, which is a
subclass of FingerprintArena
.
- exception chemfp.fpb_io.FPBError¶
Bases:
ChemFPError
Exception raised when the input file does not appear to be in FPB format
- class chemfp.fpb_io.FPBFingerprintArena(metadata, alignment, start_padding, end_padding, storage_size, arena, popcount_indices, arena_ids, start=0, end=None, id_lookup=None, close=None, license_key=None)¶
Bases:
FingerprintArena
A
FingerprintArena
from an FPB fileThe functions
chemfp.open()
andchemfp.load_fingerprints()
return an FPBFingerprintArena when used to open a fingerprint file in FPB format.The underlying file may be memory-mapped. Use this object as a context manger, or explicitly call
FPBFingerprintArena.close()
to ensure it it closed.- close()¶
Close any resources associated with this arena
More specifically, close the memory-map connection to the FPB file.
- class chemfp.fpb_io.InputOrderFPBWriter(output, metadata=None, alignment: int = 8, include_popc: bool = True, include_hash: bool = True, max_spool_size: _typing.OptionalInt = None, num_entries=None, tmpdir=None, close: _typing.OptionalCloseType = None, location: _typing.OptionalLocation = None)¶
Bases:
FingerprintWriter
Fingerprint writer for FPB files which preserves the input fingerprint order
This is a subclass of
chemfp.FingerprintWriter
.The public attributes are:
- metadata¶
A
chemfp.Metadata
instance describing the output location, primarily the current record number.
- closed: bool¶
False when the file is open, else True
Other attributes (like “alignment”, “include_hash”, “include_popc”, “max_spool_size”, and “tmpdir”) are undocumented and subject to change in the future. Let me know if they are useful.
An InputOrderFPBWriter is also is own context manager, and will close the writer on context exit.
- close()¶
Close the output writer
This will set self.closed to False
- write_fingerprint(id: str, fp: bytes)¶
Write a single fingerprint record with the given id and fp to the destination
- Parameters:
id (string) – the record identifier
fp (bytes) – the fingerprint
- write_fingerprints(id_fp_iter: Iterable[Tuple[str, bytes]])¶
Write a sequence of (id, fingerprint) pairs to the destination
- Parameters:
id_fp_pairs – An iterable of (id, fingerprint) pairs.
- class chemfp.fpb_io.OrderedFPBWriter(output, metadata: _typing.OptionalMetadata = None, alignment: int = 8, include_popc: bool = True, include_hash: bool = True, max_spool_size: _typing.Optional[int] = None, tmpdir: _typing.OptionalStr = None, close: _typing.OptionalCloseType = None, location: _typing.OptionalLocation = None)¶
Bases:
FingerprintWriter
Fingerprint writer for FPB files where the input fingerprint order is preserved
This is a subclass of
chemfp.FingerprintWriter
.The public attributes are:
- metadata¶
A
chemfp.Metadata
instance describing the output location, primarily the current record number.
- closed: bool¶
False when the file is open, else True
Other attributes (like “alignment”, “include_hash”, “include_popc”, “max_spool_size”, and “tmpdir”) are undocumented and subject to change in the future. Let me know if they are useful.
An OrderedFPBWriter is also is own context manager, and will close the writer on context exit.
- close()¶
Close the output writer
- write_fingerprint(id: str, fp: bytes)¶
Write a single fingerprint record with the given id and fp to the destination
- Parameters:
id (string) – the record identifier
fp (bytes) – the fingerprint
- write_fingerprints(id_fp_iter: Iterable[Tuple[str, bytes]])¶
Write a sequence of (id, fingerprint) pairs to the destination
- Parameters:
id_fp_pairs – An iterable of (id, fingerprint) pairs.